Merge pull request #2927 from MartinHaimberger/mh-log-returnvalues

wlog: fixed return values
This commit is contained in:
Hardening 2015-10-22 10:35:43 +02:00
commit 94d107c75f
16 changed files with 223 additions and 195 deletions

View File

@ -117,12 +117,12 @@ struct _wLogLayout
#define WLOG_PACKET_INBOUND 1 #define WLOG_PACKET_INBOUND 1
#define WLOG_PACKET_OUTBOUND 2 #define WLOG_PACKET_OUTBOUND 2
typedef int (*WLOG_APPENDER_OPEN_FN)(wLog* log, wLogAppender* appender); typedef BOOL (*WLOG_APPENDER_OPEN_FN)(wLog* log, wLogAppender* appender);
typedef int (*WLOG_APPENDER_CLOSE_FN)(wLog* log, wLogAppender* appender); typedef BOOL (*WLOG_APPENDER_CLOSE_FN)(wLog* log, wLogAppender* appender);
typedef int (*WLOG_APPENDER_WRITE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); typedef BOOL (*WLOG_APPENDER_WRITE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
typedef int (*WLOG_APPENDER_WRITE_DATA_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); typedef BOOL (*WLOG_APPENDER_WRITE_DATA_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
typedef int (*WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); typedef BOOL (*WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
typedef int (*WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); typedef BOOL (*WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
#define WLOG_APPENDER_COMMON() \ #define WLOG_APPENDER_COMMON() \
DWORD Type; \ DWORD Type; \
@ -181,10 +181,10 @@ struct _wLogBinaryAppender
}; };
typedef struct _wLogBinaryAppender wLogBinaryAppender; typedef struct _wLogBinaryAppender wLogBinaryAppender;
typedef void (*CallbackAppenderMessage_t)(const wLogMessage *msg); typedef BOOL (*CallbackAppenderMessage_t)(const wLogMessage *msg);
typedef void (*CallbackAppenderData_t)(const wLogMessage *msg); typedef BOOL (*CallbackAppenderData_t)(const wLogMessage *msg);
typedef void (*CallbackAppenderImage_t)(const wLogMessage *msg); typedef BOOL (*CallbackAppenderImage_t)(const wLogMessage *msg);
typedef void (*CallbackAppenderPackage_t)(const wLogMessage *msg); typedef BOOL (*CallbackAppenderPackage_t)(const wLogMessage *msg);
struct _wLogCallbackAppender struct _wLogCallbackAppender
{ {
@ -229,8 +229,8 @@ struct _wLog
DWORD ChildrenSize; DWORD ChildrenSize;
}; };
WINPR_API void WLog_PrintMessage(wLog* log, wLogMessage* message, ...); WINPR_API BOOL WLog_PrintMessage(wLog* log, wLogMessage* message, ...);
WINPR_API int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args); WINPR_API BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args);
#define WLog_Print(_log, _log_level, _fmt, ...) \ #define WLog_Print(_log, _log_level, _fmt, ...) \
do { \ do { \
@ -314,20 +314,20 @@ WINPR_API int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args)
#define WLog_FATAL(tag, fmt, ...) WLog_Print(WLog_Get(tag), WLOG_FATAL, fmt, ## __VA_ARGS__) #define WLog_FATAL(tag, fmt, ...) WLog_Print(WLog_Get(tag), WLOG_FATAL, fmt, ## __VA_ARGS__)
WINPR_API DWORD WLog_GetLogLevel(wLog* log); WINPR_API DWORD WLog_GetLogLevel(wLog* log);
WINPR_API void WLog_SetLogLevel(wLog* log, DWORD logLevel); WINPR_API BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel);
WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log); WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log);
WINPR_API BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType); WINPR_API BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType);
WINPR_API int WLog_OpenAppender(wLog* log); WINPR_API BOOL WLog_OpenAppender(wLog* log);
WINPR_API int WLog_CloseAppender(wLog* log); WINPR_API BOOL WLog_CloseAppender(wLog* log);
WINPR_API void WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream); WINPR_API BOOL WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream);
WINPR_API BOOL WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename); WINPR_API BOOL WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename);
WINPR_API BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath); WINPR_API BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath);
WINPR_API void WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender, WINPR_API BOOL WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender,
CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg, CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg,
CallbackAppenderData_t data); CallbackAppenderData_t data);
@ -338,7 +338,7 @@ WINPR_API wLog* WLog_GetRoot(void);
WINPR_API wLog* WLog_Get(LPCSTR name); WINPR_API wLog* WLog_Get(LPCSTR name);
WINPR_API BOOL WLog_Init(void); WINPR_API BOOL WLog_Init(void);
WINPR_API void WLog_Uninit(void); WINPR_API BOOL WLog_Uninit(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -59,24 +59,28 @@ static BOOL check(const wLogMessage *msg)
return rc; return rc;
} }
void CallbackAppenderMessage(const wLogMessage *msg) BOOL CallbackAppenderMessage(const wLogMessage *msg)
{ {
check(msg); check(msg);
return TRUE;
} }
void CallbackAppenderData(const wLogMessage *msg) BOOL CallbackAppenderData(const wLogMessage *msg)
{ {
fprintf(stdout, "%s\n", __FUNCTION__); fprintf(stdout, "%s\n", __FUNCTION__);
return TRUE;
} }
void CallbackAppenderImage(const wLogMessage *msg) BOOL CallbackAppenderImage(const wLogMessage *msg)
{ {
fprintf(stdout, "%s\n", __FUNCTION__); fprintf(stdout, "%s\n", __FUNCTION__);
return TRUE;
} }
void CallbackAppenderPackage(const wLogMessage *msg) BOOL CallbackAppenderPackage(const wLogMessage *msg)
{ {
fprintf(stdout, "%s\n", __FUNCTION__); fprintf(stdout, "%s\n", __FUNCTION__);
return TRUE;
} }
int TestWLogCallback(int argc, char* argv[]) int TestWLogCallback(int argc, char* argv[])

View File

@ -121,7 +121,7 @@ BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType)
return log->Appender != NULL; return log->Appender != NULL;
} }
int WLog_OpenAppender(wLog* log) BOOL WLog_OpenAppender(wLog* log)
{ {
int status = 0; int status = 0;
wLogAppender* appender; wLogAppender* appender;
@ -129,10 +129,10 @@ int WLog_OpenAppender(wLog* log)
appender = WLog_GetLogAppender(log); appender = WLog_GetLogAppender(log);
if (!appender) if (!appender)
return -1; return FALSE;
if (!appender->Open) if (!appender->Open)
return 0; return TRUE;
if (!appender->State) if (!appender->State)
{ {
@ -143,7 +143,7 @@ int WLog_OpenAppender(wLog* log)
return status; return status;
} }
int WLog_CloseAppender(wLog* log) BOOL WLog_CloseAppender(wLog* log)
{ {
int status = 0; int status = 0;
wLogAppender* appender; wLogAppender* appender;
@ -151,10 +151,10 @@ int WLog_CloseAppender(wLog* log)
appender = WLog_GetLogAppender(log); appender = WLog_GetLogAppender(log);
if (!appender) if (!appender)
return -1; return FALSE;
if (!appender->Close) if (!appender->Close)
return 0; return TRUE;
if (appender->State) if (appender->State)
{ {

View File

@ -69,16 +69,16 @@ BOOL WLog_BinaryAppender_SetOutputFilePath(wLog* log, wLogBinaryAppender* append
return TRUE; return TRUE;
} }
int WLog_BinaryAppender_Open(wLog* log, wLogBinaryAppender* appender) BOOL WLog_BinaryAppender_Open(wLog* log, wLogBinaryAppender* appender)
{ {
if (!log || !appender) if (!log || !appender)
return -1; return FALSE;
if (!appender->FileName) if (!appender->FileName)
{ {
appender->FileName = (char*) malloc(MAX_PATH); appender->FileName = (char*) malloc(MAX_PATH);
if (!appender->FileName) if (!appender->FileName)
return -1; return FALSE;
sprintf_s(appender->FileName, MAX_PATH, "%u.wlog", (unsigned int) GetCurrentProcessId()); sprintf_s(appender->FileName, MAX_PATH, "%u.wlog", (unsigned int) GetCurrentProcessId());
} }
@ -86,44 +86,44 @@ int WLog_BinaryAppender_Open(wLog* log, wLogBinaryAppender* appender)
{ {
appender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog"); appender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog");
if (!appender->FilePath) if (!appender->FilePath)
return -1; return FALSE;
} }
if (!appender->FullFileName) if (!appender->FullFileName)
{ {
appender->FullFileName = GetCombinedPath(appender->FilePath, appender->FileName); appender->FullFileName = GetCombinedPath(appender->FilePath, appender->FileName);
if (!appender->FullFileName) if (!appender->FullFileName)
return -1; return FALSE;
} }
if (!PathFileExistsA(appender->FilePath)) if (!PathFileExistsA(appender->FilePath))
{ {
if (!PathMakePathA(appender->FilePath, 0)) if (!PathMakePathA(appender->FilePath, 0))
return -1; return FALSE;
UnixChangeFileMode(appender->FilePath, 0xFFFF); UnixChangeFileMode(appender->FilePath, 0xFFFF);
} }
appender->FileDescriptor = fopen(appender->FullFileName, "a+"); appender->FileDescriptor = fopen(appender->FullFileName, "a+");
if (!appender->FileDescriptor) if (!appender->FileDescriptor)
return -1; return FALSE;
return 0; return TRUE;
} }
int WLog_BinaryAppender_Close(wLog* log, wLogBinaryAppender* appender) BOOL WLog_BinaryAppender_Close(wLog* log, wLogBinaryAppender* appender)
{ {
if (!appender->FileDescriptor) if (!appender->FileDescriptor)
return 0; return TRUE;
fclose(appender->FileDescriptor); fclose(appender->FileDescriptor);
appender->FileDescriptor = NULL; appender->FileDescriptor = NULL;
return 0; return TRUE;
} }
int WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message) BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message)
{ {
FILE* fp; FILE* fp;
wStream* s; wStream* s;
@ -131,15 +131,15 @@ int WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, wL
int FileNameLength; int FileNameLength;
int FunctionNameLength; int FunctionNameLength;
int TextStringLength; int TextStringLength;
int ret = 1; BOOL ret = TRUE;
if (!log || !appender || !message) if (!log || !appender || !message)
return -1; return FALSE;
fp = appender->FileDescriptor; fp = appender->FileDescriptor;
if (!fp) if (!fp)
return -1; return FALSE;
FileNameLength = strlen(message->FileName); FileNameLength = strlen(message->FileName);
FunctionNameLength = strlen(message->FunctionName); FunctionNameLength = strlen(message->FunctionName);
@ -152,7 +152,7 @@ int WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, wL
s = Stream_New(NULL, MessageLength); s = Stream_New(NULL, MessageLength);
if (!s) if (!s)
return -1; return FALSE;
Stream_Write_UINT32(s, MessageLength); Stream_Write_UINT32(s, MessageLength);
@ -173,21 +173,21 @@ int WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, wL
Stream_SealLength(s); Stream_SealLength(s);
if (fwrite(Stream_Buffer(s), MessageLength, 1, fp) != 1) if (fwrite(Stream_Buffer(s), MessageLength, 1, fp) != 1)
ret = -1; ret = FALSE;
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
return ret; return ret;
} }
int WLog_BinaryAppender_WriteDataMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message) BOOL WLog_BinaryAppender_WriteDataMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message)
{ {
return 1; return TRUE;
} }
int WLog_BinaryAppender_WriteImageMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message) BOOL WLog_BinaryAppender_WriteImageMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message)
{ {
return 1; return TRUE;
} }
wLogBinaryAppender* WLog_BinaryAppender_New(wLog* log) wLogBinaryAppender* WLog_BinaryAppender_New(wLog* log)

View File

@ -34,33 +34,34 @@
* Callback Appender * Callback Appender
*/ */
WINPR_API void WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender, WINPR_API BOOL WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender,
CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg, CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg,
CallbackAppenderData_t data) CallbackAppenderData_t data)
{ {
if (!appender) if (!appender)
return; return FALSE;
if (appender->Type != WLOG_APPENDER_CALLBACK) if (appender->Type != WLOG_APPENDER_CALLBACK)
return; return FALSE;
appender->message = msg; appender->message = msg;
appender->image = img; appender->image = img;
appender->package = pkg; appender->package = pkg;
appender->data = data; appender->data = data;
return TRUE;
} }
int WLog_CallbackAppender_Open(wLog* log, wLogCallbackAppender* appender) BOOL WLog_CallbackAppender_Open(wLog* log, wLogCallbackAppender* appender)
{ {
return 0; return TRUE;
} }
int WLog_CallbackAppender_Close(wLog* log, wLogCallbackAppender* appender) BOOL WLog_CallbackAppender_Close(wLog* log, wLogCallbackAppender* appender)
{ {
return 0; return TRUE;
} }
int WLog_CallbackAppender_WriteMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) BOOL WLog_CallbackAppender_WriteMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message)
{ {
char prefix[WLOG_MAX_PREFIX_SIZE]; char prefix[WLOG_MAX_PREFIX_SIZE];
@ -69,56 +70,48 @@ int WLog_CallbackAppender_WriteMessage(wLog* log, wLogCallbackAppender* appender
if (appender->message) if (appender->message)
{ {
appender->message(message); return appender->message(message);
} }
else else
{ {
return -1; return FALSE;
} }
return 1;
} }
int WLog_CallbackAppender_WriteDataMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) BOOL WLog_CallbackAppender_WriteDataMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message)
{ {
if (appender->data) if (appender->data)
{ {
appender->data(message); return appender->data(message);
} }
else else
{ {
return -1; return FALSE;
} }
return 1;
} }
int WLog_CallbackAppender_WriteImageMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) BOOL WLog_CallbackAppender_WriteImageMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message)
{ {
if (appender->image) if (appender->image)
{ {
appender->image(message); return appender->image(message);
} }
else else
{ {
return -1; return FALSE;
} }
return 1;
} }
int WLog_CallbackAppender_WritePacketMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) BOOL WLog_CallbackAppender_WritePacketMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message)
{ {
if (appender->package) if (appender->package)
{ {
appender->package(message); return appender->package(message);
} }
else else
{ {
return -1; return FALSE;
} }
return 1;
} }
wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log) wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log)

View File

@ -38,13 +38,13 @@
* Console Appender * Console Appender
*/ */
void WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream) BOOL WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream)
{ {
if (!appender) if (!appender)
return; return FALSE;
if (appender->Type != WLOG_APPENDER_CONSOLE) if (appender->Type != WLOG_APPENDER_CONSOLE)
return; return FALSE;
if (outputStream < 0) if (outputStream < 0)
outputStream = WLOG_CONSOLE_DEFAULT; outputStream = WLOG_CONSOLE_DEFAULT;
@ -55,19 +55,20 @@ void WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* append
appender->outputStream = WLOG_CONSOLE_STDERR; appender->outputStream = WLOG_CONSOLE_STDERR;
else else
appender->outputStream = WLOG_CONSOLE_DEFAULT; appender->outputStream = WLOG_CONSOLE_DEFAULT;
return TRUE;
} }
int WLog_ConsoleAppender_Open(wLog* log, wLogConsoleAppender* appender) BOOL WLog_ConsoleAppender_Open(wLog* log, wLogConsoleAppender* appender)
{ {
return 0; return TRUE;
} }
int WLog_ConsoleAppender_Close(wLog* log, wLogConsoleAppender* appender) BOOL WLog_ConsoleAppender_Close(wLog* log, wLogConsoleAppender* appender)
{ {
return 0; return TRUE;
} }
int WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message)
{ {
FILE* fp; FILE* fp;
char prefix[WLOG_MAX_PREFIX_SIZE]; char prefix[WLOG_MAX_PREFIX_SIZE];
@ -85,7 +86,7 @@ int WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender,
OutputDebugStringA(MessageString); OutputDebugStringA(MessageString);
return 1; return TRUE;
} }
#endif #endif
#ifdef ANDROID #ifdef ANDROID
@ -149,12 +150,12 @@ int WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender,
if (message->Level != WLOG_OFF) if (message->Level != WLOG_OFF)
fprintf(fp, "%s%s\n", message->PrefixString, message->TextString); fprintf(fp, "%s%s\n", message->PrefixString, message->TextString);
#endif #endif
return 1; return TRUE;
} }
static int g_DataId = 0; static int g_DataId = 0;
int WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) BOOL WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message)
{ {
int DataId; int DataId;
char* FullFileName; char* FullFileName;
@ -166,12 +167,12 @@ int WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogConsoleAppender* append
free(FullFileName); free(FullFileName);
return DataId; return TRUE;
} }
static int g_ImageId = 0; static int g_ImageId = 0;
int WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) BOOL WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message)
{ {
int ImageId; int ImageId;
char* FullFileName; char* FullFileName;
@ -184,12 +185,12 @@ int WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogConsoleAppender* appen
free(FullFileName); free(FullFileName);
return ImageId; return TRUE;
} }
static int g_PacketId = 0; static int g_PacketId = 0;
int WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) BOOL WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message)
{ {
int PacketId; int PacketId;
char* FullFileName; char* FullFileName;
@ -204,10 +205,10 @@ int WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogConsoleAppender* appe
} }
if (appender->PacketMessageContext) if (appender->PacketMessageContext)
WLog_PacketMessage_Write((wPcap*) appender->PacketMessageContext, return WLog_PacketMessage_Write((wPcap*) appender->PacketMessageContext,
message->PacketData, message->PacketLength, message->PacketFlags); message->PacketData, message->PacketLength, message->PacketFlags);
return PacketId; return TRUE;
} }
wLogConsoleAppender* WLog_ConsoleAppender_New(wLog* log) wLogConsoleAppender* WLog_ConsoleAppender_New(wLog* log)

View File

@ -28,21 +28,21 @@
#include "../../log.h" #include "../../log.h"
#define TAG WINPR_TAG("utils.wlog") #define TAG WINPR_TAG("utils.wlog")
int WLog_DataMessage_Write(char* filename, void* data, int length) BOOL WLog_DataMessage_Write(char* filename, void* data, int length)
{ {
FILE* fp; FILE* fp;
int ret = 0; BOOL ret = TRUE;
fp = fopen(filename, "w+b"); fp = fopen(filename, "w+b");
if (!fp) if (!fp)
{ {
WLog_ERR(TAG, "failed to open file %s", filename); //WLog_ERR(TAG, "failed to open file %s", filename);
return -1; return FALSE;
} }
if (fwrite(data, length, 1, fp) != 1) if (fwrite(data, length, 1, fp) != 1)
ret = -1; ret = FALSE;
fclose(fp); fclose(fp);
return ret; return ret;
} }

View File

@ -24,6 +24,6 @@
#include "wlog/wlog.h" #include "wlog/wlog.h"
int WLog_DataMessage_Write(char* filename, void* data, int length); BOOL WLog_DataMessage_Write(char* filename, void* data, int length);
#endif /* WINPR_WLOG_DATA_MESSAGE_PRIVATE_H */ #endif /* WINPR_WLOG_DATA_MESSAGE_PRIVATE_H */

View File

@ -67,23 +67,23 @@ BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender,
return TRUE; return TRUE;
} }
int WLog_FileAppender_Open(wLog* log, wLogFileAppender* appender) BOOL WLog_FileAppender_Open(wLog* log, wLogFileAppender* appender)
{ {
if (!log || !appender) if (!log || !appender)
return -1; return FALSE;
if (!appender->FilePath) if (!appender->FilePath)
{ {
appender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog"); appender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog");
if (!appender->FilePath) if (!appender->FilePath)
return -1; return FALSE;
} }
if (!appender->FileName) if (!appender->FileName)
{ {
appender->FileName = (char*) malloc(MAX_PATH); appender->FileName = (char*) malloc(MAX_PATH);
if (!appender->FileName) if (!appender->FileName)
return -1; return FALSE;
sprintf_s(appender->FileName, MAX_PATH, "%u.log", (unsigned int) GetCurrentProcessId()); sprintf_s(appender->FileName, MAX_PATH, "%u.log", (unsigned int) GetCurrentProcessId());
} }
@ -92,51 +92,51 @@ int WLog_FileAppender_Open(wLog* log, wLogFileAppender* appender)
{ {
appender->FullFileName = GetCombinedPath(appender->FilePath, appender->FileName); appender->FullFileName = GetCombinedPath(appender->FilePath, appender->FileName);
if (!appender->FullFileName) if (!appender->FullFileName)
return -1; return FALSE;
} }
if (!PathFileExistsA(appender->FilePath)) if (!PathFileExistsA(appender->FilePath))
{ {
if (!PathMakePathA(appender->FilePath, 0)) if (!PathMakePathA(appender->FilePath, 0))
return -1; return FALSE;
UnixChangeFileMode(appender->FilePath, 0xFFFF); UnixChangeFileMode(appender->FilePath, 0xFFFF);
} }
appender->FileDescriptor = fopen(appender->FullFileName, "a+"); appender->FileDescriptor = fopen(appender->FullFileName, "a+");
if (!appender->FileDescriptor) if (!appender->FileDescriptor)
return -1; return FALSE;
return 0; return TRUE;
} }
int WLog_FileAppender_Close(wLog* log, wLogFileAppender* appender) BOOL WLog_FileAppender_Close(wLog* log, wLogFileAppender* appender)
{ {
if (!log || !appender) if (!log || !appender)
return -1; return FALSE;
if (!appender->FileDescriptor) if (!appender->FileDescriptor)
return 0; return TRUE;
fclose(appender->FileDescriptor); fclose(appender->FileDescriptor);
appender->FileDescriptor = NULL; appender->FileDescriptor = NULL;
return 0; return TRUE;
} }
int WLog_FileAppender_WriteMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message) BOOL WLog_FileAppender_WriteMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message)
{ {
FILE* fp; FILE* fp;
char prefix[WLOG_MAX_PREFIX_SIZE]; char prefix[WLOG_MAX_PREFIX_SIZE];
if (!log || !appender || !message) if (!log || !appender || !message)
return -1; return FALSE;
fp = appender->FileDescriptor; fp = appender->FileDescriptor;
if (!fp) if (!fp)
return -1; return FALSE;
message->PrefixString = prefix; message->PrefixString = prefix;
WLog_Layout_GetMessagePrefix(log, appender->Layout, message); WLog_Layout_GetMessagePrefix(log, appender->Layout, message);
@ -145,18 +145,18 @@ int WLog_FileAppender_WriteMessage(wLog* log, wLogFileAppender* appender, wLogMe
fflush(fp); /* slow! */ fflush(fp); /* slow! */
return 1; return TRUE;
} }
static int g_DataId = 0; static int g_DataId = 0;
int WLog_FileAppender_WriteDataMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message) BOOL WLog_FileAppender_WriteDataMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message)
{ {
int DataId; int DataId;
char* FullFileName; char* FullFileName;
if (!log || !appender || !message) if (!log || !appender || !message)
return -1; return FALSE;
DataId = g_DataId++; DataId = g_DataId++;
FullFileName = WLog_Message_GetOutputFileName(DataId, "dat"); FullFileName = WLog_Message_GetOutputFileName(DataId, "dat");
@ -165,7 +165,7 @@ int WLog_FileAppender_WriteDataMessage(wLog* log, wLogFileAppender* appender, wL
free(FullFileName); free(FullFileName);
return DataId; return TRUE;
} }
static int g_ImageId = 0; static int g_ImageId = 0;
@ -176,7 +176,7 @@ int WLog_FileAppender_WriteImageMessage(wLog* log, wLogFileAppender* appender, w
char* FullFileName; char* FullFileName;
if (!log || !appender || !message) if (!log || !appender || !message)
return -1; return FALSE;
ImageId = g_ImageId++; ImageId = g_ImageId++;
FullFileName = WLog_Message_GetOutputFileName(ImageId, "bmp"); FullFileName = WLog_Message_GetOutputFileName(ImageId, "bmp");
@ -186,7 +186,7 @@ int WLog_FileAppender_WriteImageMessage(wLog* log, wLogFileAppender* appender, w
free(FullFileName); free(FullFileName);
return ImageId; return TRUE;
} }
wLogFileAppender* WLog_FileAppender_New(wLog* log) wLogFileAppender* WLog_FileAppender_New(wLog* log)

View File

@ -26,14 +26,14 @@
#include "wlog/ImageMessage.h" #include "wlog/ImageMessage.h"
int WLog_ImageMessage_Write(char* filename, void* data, int width, int height, int bpp) BOOL WLog_ImageMessage_Write(char* filename, void* data, int width, int height, int bpp)
{ {
int status; int status;
status = winpr_bitmap_write(filename, data, width, height, bpp); status = winpr_bitmap_write(filename, data, width, height, bpp);
if (status < 0) if (status < 0)
return -1; return FALSE;
return 1; return TRUE;
} }

View File

@ -24,6 +24,6 @@
#include "wlog/wlog.h" #include "wlog/wlog.h"
int WLog_ImageMessage_Write(char* filename, void* data, int width, int height, int bpp); BOOL WLog_ImageMessage_Write(char* filename, void* data, int width, int height, int bpp);
#endif /* WINPR_WLOG_IMAGE_MESSAGE_PRIVATE_H */ #endif /* WINPR_WLOG_IMAGE_MESSAGE_PRIVATE_H */

View File

@ -65,7 +65,7 @@ void WLog_PrintMessagePrefix(wLog* log, wLogMessage* message, const char* format
va_end(args); va_end(args);
} }
void WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* message) BOOL WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* message)
{ {
char* p; char* p;
int index; int index;
@ -327,6 +327,7 @@ void WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* me
args[11], args[12], args[13], args[14], args[15]); args[11], args[12], args[13], args[14], args[15]);
break; break;
} }
return TRUE;
} }
wLogLayout* WLog_GetLogLayout(wLog* log) wLogLayout* WLog_GetLogLayout(wLog* log)

View File

@ -375,7 +375,7 @@ static BOOL WLog_PacketMessage_Write_TcpHeader(wPcap* pcap, wTcpHeader* tcp)
static UINT32 g_InboundSequenceNumber = 0; static UINT32 g_InboundSequenceNumber = 0;
static UINT32 g_OutboundSequenceNumber = 0; static UINT32 g_OutboundSequenceNumber = 0;
int WLog_PacketMessage_Write(wPcap* pcap, void* data, DWORD length, DWORD flags) BOOL WLog_PacketMessage_Write(wPcap* pcap, void* data, DWORD length, DWORD flags)
{ {
wTcpHeader tcp; wTcpHeader tcp;
wIPv4Header ipv4; wIPv4Header ipv4;
@ -385,7 +385,7 @@ int WLog_PacketMessage_Write(wPcap* pcap, void* data, DWORD length, DWORD flags)
ethernet.Type = 0x0800; ethernet.Type = 0x0800;
if (!pcap || !pcap->fp) if (!pcap || !pcap->fp)
return -1; return FALSE;
if (flags & WLOG_PACKET_OUTBOUND) if (flags & WLOG_PACKET_OUTBOUND)
{ {
@ -479,7 +479,7 @@ int WLog_PacketMessage_Write(wPcap* pcap, void* data, DWORD length, DWORD flags)
!WLog_PacketMessage_Write_IPv4Header(pcap, &ipv4) || !WLog_PacketMessage_Write_IPv4Header(pcap, &ipv4) ||
!WLog_PacketMessage_Write_TcpHeader(pcap, &tcp) || !WLog_PacketMessage_Write_TcpHeader(pcap, &tcp) ||
!Pcap_Write_RecordContent(pcap, &record)) !Pcap_Write_RecordContent(pcap, &record))
return -1; return FALSE;
fflush(pcap->fp); fflush(pcap->fp);
return 0; return TRUE;
} }

View File

@ -116,7 +116,7 @@ struct _wTcpHeader
}; };
typedef struct _wTcpHeader wTcpHeader; typedef struct _wTcpHeader wTcpHeader;
int WLog_PacketMessage_Write(wPcap* pcap, void* data, DWORD length, DWORD flags); BOOL WLog_PacketMessage_Write(wPcap* pcap, void* data, DWORD length, DWORD flags);
#endif /* WINPR_WLOG_PACKET_MESSAGE_PRIVATE_H */ #endif /* WINPR_WLOG_PACKET_MESSAGE_PRIVATE_H */

View File

@ -63,52 +63,64 @@ const char* WLOG_LEVELS[7] =
static DWORD g_FilterCount = 0; static DWORD g_FilterCount = 0;
static wLogFilter* g_Filters = NULL; static wLogFilter* g_Filters = NULL;
static void log_recursion(const char* file, const char* fkt, int line) static BOOL log_recursion(const char* file, const char* fkt, int line)
{ {
size_t used, i; size_t used, i;
void* bt = winpr_backtrace(20); void* bt = winpr_backtrace(20);
if (!bt)
return FALSE;
char** msg = winpr_backtrace_symbols(bt, &used); char** msg = winpr_backtrace_symbols(bt, &used);
if (!msg)
return FALSE;
#if defined(ANDROID) #if defined(ANDROID)
const char* tag = WINPR_TAG("utils.wlog"); const char* tag = WINPR_TAG("utils.wlog");
__android_log_print(ANDROID_LOG_FATAL, tag, "Recursion detected!!!"); if (__android_log_print(ANDROID_LOG_FATAL, tag, "Recursion detected!!!") < 0)
__android_log_print(ANDROID_LOG_FATAL, tag, "Check %s [%s:%d]", fkt, file, line); return FALSE;
if (__android_log_print(ANDROID_LOG_FATAL, tag, "Check %s [%s:%d]", fkt, file, line) < 0)
return FALSE;
for (i=0; i<used; i++) for (i=0; i<used; i++)
__android_log_print(ANDROID_LOG_FATAL, tag, "%d: %s", i, msg[i]); if (__android_log_print(ANDROID_LOG_FATAL, tag, "%d: %s", i, msg[i]) < 0)
return FALSE;
#else #else
fprintf(stderr, "[%s]: Recursion detected!\n", fkt); if (fprintf(stderr, "[%s]: Recursion detected!\n", fkt) < 0)
fprintf(stderr, "[%s]: Check %s:%d\n", fkt, file, line); return FALSE;
if (fprintf(stderr, "[%s]: Check %s:%d\n", fkt, file, line) < 0)
return FALSE;
for (i=0; i<used; i++) for (i=0; i<used; i++)
fprintf(stderr, "%s: %zd: %s\n", fkt, i, msg[i]); if (fprintf(stderr, "%s: %zd: %s\n", fkt, i, msg[i]) < 0)
return FALSE;
#endif #endif
free(msg); free(msg);
winpr_backtrace_free(bt); winpr_backtrace_free(bt);
return TRUE;
} }
int WLog_Write(wLog* log, wLogMessage* message) BOOL WLog_Write(wLog* log, wLogMessage* message)
{ {
int status = -1; BOOL status;
wLogAppender* appender; wLogAppender* appender;
appender = WLog_GetLogAppender(log); appender = WLog_GetLogAppender(log);
if (!appender) if (!appender)
return -1; return FALSE;
if (!appender->State) if (!appender->State)
WLog_OpenAppender(log); if (!WLog_OpenAppender(log))
return FALSE;
if (!appender->WriteMessage) if (!appender->WriteMessage)
return -1; return FALSE;
EnterCriticalSection(&appender->lock); EnterCriticalSection(&appender->lock);
if (appender->recursive) if (appender->recursive)
log_recursion(message->FileName, message->FunctionName, message->LineNumber); status = log_recursion(message->FileName, message->FunctionName, message->LineNumber);
else else
{ {
appender->recursive = TRUE; appender->recursive = TRUE;
@ -120,25 +132,26 @@ int WLog_Write(wLog* log, wLogMessage* message)
return status; return status;
} }
int WLog_WriteData(wLog* log, wLogMessage* message) BOOL WLog_WriteData(wLog* log, wLogMessage* message)
{ {
int status = -1; BOOL status;
wLogAppender* appender; wLogAppender* appender;
appender = WLog_GetLogAppender(log); appender = WLog_GetLogAppender(log);
if (!appender) if (!appender)
return -1; return FALSE;
if (!appender->State) if (!appender->State)
WLog_OpenAppender(log); if (!WLog_OpenAppender(log))
return FALSE;
if (!appender->WriteDataMessage) if (!appender->WriteDataMessage)
return -1; return FALSE;
EnterCriticalSection(&appender->lock); EnterCriticalSection(&appender->lock);
if (appender->recursive) if (appender->recursive)
log_recursion(message->FileName, message->FunctionName, message->LineNumber); status = log_recursion(message->FileName, message->FunctionName, message->LineNumber);
else else
{ {
appender->recursive = TRUE; appender->recursive = TRUE;
@ -150,25 +163,26 @@ int WLog_WriteData(wLog* log, wLogMessage* message)
return status; return status;
} }
int WLog_WriteImage(wLog* log, wLogMessage* message) BOOL WLog_WriteImage(wLog* log, wLogMessage* message)
{ {
int status = -1; BOOL status;
wLogAppender* appender; wLogAppender* appender;
appender = WLog_GetLogAppender(log); appender = WLog_GetLogAppender(log);
if (!appender) if (!appender)
return -1; return FALSE;
if (!appender->State) if (!appender->State)
WLog_OpenAppender(log); if (!WLog_OpenAppender(log))
return FALSE;
if (!appender->WriteImageMessage) if (!appender->WriteImageMessage)
return -1; return FALSE;
EnterCriticalSection(&appender->lock); EnterCriticalSection(&appender->lock);
if (appender->recursive) if (appender->recursive)
log_recursion(message->FileName, message->FunctionName, message->LineNumber); status = log_recursion(message->FileName, message->FunctionName, message->LineNumber);
else else
{ {
appender->recursive = TRUE; appender->recursive = TRUE;
@ -180,25 +194,26 @@ int WLog_WriteImage(wLog* log, wLogMessage* message)
return status; return status;
} }
int WLog_WritePacket(wLog* log, wLogMessage* message) BOOL WLog_WritePacket(wLog* log, wLogMessage* message)
{ {
int status = -1; BOOL status;
wLogAppender* appender; wLogAppender* appender;
appender = WLog_GetLogAppender(log); appender = WLog_GetLogAppender(log);
if (!appender) if (!appender)
return -1; return FALSE;
if (!appender->State) if (!appender->State)
WLog_OpenAppender(log); if (!WLog_OpenAppender(log))
return FALSE;
if (!appender->WritePacketMessage) if (!appender->WritePacketMessage)
return -1; return FALSE;
EnterCriticalSection(&appender->lock); EnterCriticalSection(&appender->lock);
if (appender->recursive) if (appender->recursive)
log_recursion(message->FileName, message->FunctionName, message->LineNumber); status = log_recursion(message->FileName, message->FunctionName, message->LineNumber);
else else
{ {
appender->recursive = TRUE; appender->recursive = TRUE;
@ -210,9 +225,9 @@ int WLog_WritePacket(wLog* log, wLogMessage* message)
return status; return status;
} }
int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args) BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args)
{ {
int status = -1; BOOL status;
if (message->Type == WLOG_MESSAGE_TEXT) if (message->Type == WLOG_MESSAGE_TEXT)
{ {
@ -224,7 +239,8 @@ int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args)
else else
{ {
char formattedLogMessage[WLOG_MAX_STRING_SIZE]; char formattedLogMessage[WLOG_MAX_STRING_SIZE];
wvsnprintfx(formattedLogMessage, WLOG_MAX_STRING_SIZE - 1, message->FormatString, args); if (wvsnprintfx(formattedLogMessage, WLOG_MAX_STRING_SIZE - 1, message->FormatString, args) < 0)
return FALSE;
message->TextString = formattedLogMessage; message->TextString = formattedLogMessage;
status = WLog_Write(log, message); status = WLog_Write(log, message);
} }
@ -254,13 +270,14 @@ int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args)
return status; return status;
} }
void WLog_PrintMessage(wLog* log, wLogMessage* message, ...) BOOL WLog_PrintMessage(wLog* log, wLogMessage* message, ...)
{ {
int status; BOOL status;
va_list args; va_list args;
va_start(args, message); va_start(args, message);
status = WLog_PrintMessageVA(log, message, args); status = WLog_PrintMessageVA(log, message, args);
va_end(args); va_end(args);
return status;
} }
DWORD WLog_GetLogLevel(wLog* log) DWORD WLog_GetLogLevel(wLog* log)
@ -275,14 +292,18 @@ DWORD WLog_GetLogLevel(wLog* log)
} }
} }
void WLog_SetLogLevel(wLog* log, DWORD logLevel) BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel)
{ {
if (!log)
return FALSE;
if ((logLevel > WLOG_OFF) && (logLevel != WLOG_LEVEL_INHERIT)) if ((logLevel > WLOG_OFF) && (logLevel != WLOG_LEVEL_INHERIT))
{ {
logLevel = WLOG_OFF; logLevel = WLOG_OFF;
} }
log->Level = logLevel; log->Level = logLevel;
return TRUE;
} }
int WLog_ParseLogLevel(const char* level) int WLog_ParseLogLevel(const char* level)
@ -310,7 +331,7 @@ int WLog_ParseLogLevel(const char* level)
return iLevel; return iLevel;
} }
int WLog_ParseFilter(wLogFilter* filter, LPCSTR name) BOOL WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
{ {
char* p; char* p;
char* q; char* q;
@ -320,7 +341,7 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
count = 1; count = 1;
if(!name) if(!name)
return -1; return FALSE;
p = (char*) name; p = (char*) name;
@ -335,14 +356,14 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
names = _strdup(name); names = _strdup(name);
if (!names) if (!names)
return -1; return FALSE;
filter->NameCount = count; filter->NameCount = count;
filter->Names = (LPSTR*) calloc((count + 1UL), sizeof(LPSTR)); filter->Names = (LPSTR*) calloc((count + 1UL), sizeof(LPSTR));
if(!filter->Names) if(!filter->Names)
{ {
free(names); free(names);
filter->NameCount = 0; filter->NameCount = 0;
return -1; return FALSE;
} }
filter->Names[count] = NULL; filter->Names[count] = NULL;
count = 0; count = 0;
@ -356,7 +377,7 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
free(filter->Names); free(filter->Names);
filter->Names = NULL; filter->Names = NULL;
filter->NameCount = 0; filter->NameCount = 0;
return -1; return FALSE;
} }
*q = '\0'; *q = '\0';
@ -369,7 +390,7 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
free(filter->Names); free(filter->Names);
filter->Names = NULL; filter->Names = NULL;
filter->NameCount = 0; filter->NameCount = 0;
return -1; return FALSE;
} }
filter->Level = (DWORD) iLevel; filter->Level = (DWORD) iLevel;
@ -382,10 +403,10 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
p++; p++;
} }
return 0; return TRUE;
} }
int WLog_ParseFilters() BOOL WLog_ParseFilters()
{ {
char* p; char* p;
char* env; char* env;
@ -397,15 +418,15 @@ int WLog_ParseFilters()
nSize = GetEnvironmentVariableA("WLOG_FILTER", NULL, 0); nSize = GetEnvironmentVariableA("WLOG_FILTER", NULL, 0);
if (nSize < 1) if (nSize < 1)
return 0; return TRUE;
env = (LPSTR) malloc(nSize); env = (LPSTR) malloc(nSize);
if (!env) if (!env)
return -1; return FALSE;
if (!GetEnvironmentVariableA("WLOG_FILTER", env, nSize)) if (!GetEnvironmentVariableA("WLOG_FILTER", env, nSize))
return -1; return FALSE;
count = 1; count = 1;
p = env; p = env;
@ -425,7 +446,7 @@ int WLog_ParseFilters()
if (!strs) if (!strs)
{ {
free(env); free(env);
return -1; return FALSE;
} }
strs[count++] = p; strs[count++] = p;
@ -444,7 +465,7 @@ int WLog_ParseFilters()
{ {
free(strs); free(strs);
free(env); free(env);
return -1; return FALSE;
} }
for (count = 0; count < g_FilterCount; count++) for (count = 0; count < g_FilterCount; count++)
@ -455,14 +476,14 @@ int WLog_ParseFilters()
{ {
free(strs); free(strs);
free(env); free(env);
return -1; return FALSE;
} }
} }
free(strs); free(strs);
free(env); free(env);
return 0; return TRUE;
} }
int WLog_GetFilterLogLevel(wLog* log) int WLog_GetFilterLogLevel(wLog* log)
@ -506,7 +527,7 @@ int WLog_GetFilterLogLevel(wLog* log)
return iLevel; return iLevel;
} }
int WLog_ParseName(wLog* log, LPCSTR name) BOOL WLog_ParseName(wLog* log, LPCSTR name)
{ {
char* p; char* p;
int count; int count;
@ -522,13 +543,13 @@ int WLog_ParseName(wLog* log, LPCSTR name)
names = _strdup(name); names = _strdup(name);
if (!names) if (!names)
return -1; return FALSE;
log->NameCount = count; log->NameCount = count;
log->Names = (LPSTR*) calloc((count + 1UL), sizeof(LPSTR)); log->Names = (LPSTR*) calloc((count + 1UL), sizeof(LPSTR));
if(!log->Names) if(!log->Names)
{ {
free(names); free(names);
return -1; return FALSE;
} }
log->Names[count] = NULL; log->Names[count] = NULL;
count = 0; count = 0;
@ -543,7 +564,7 @@ int WLog_ParseName(wLog* log, LPCSTR name)
p++; p++;
} }
return 0; return TRUE;
} }
wLog* WLog_New(LPCSTR name, wLog* rootLogger) wLog* WLog_New(LPCSTR name, wLog* rootLogger)
@ -562,7 +583,7 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
if (!log->Name) if (!log->Name)
goto out_fail; goto out_fail;
if (WLog_ParseName(log, name) != 0) if (!WLog_ParseName(log, name))
goto out_fail; goto out_fail;
log->Parent = rootLogger; log->Parent = rootLogger;
@ -689,7 +710,7 @@ fail:
return NULL; return NULL;
} }
int WLog_AddChild(wLog* parent, wLog* child) BOOL WLog_AddChild(wLog* parent, wLog* child)
{ {
if (parent->ChildrenCount >= parent->ChildrenSize) if (parent->ChildrenCount >= parent->ChildrenSize)
{ {
@ -710,18 +731,18 @@ int WLog_AddChild(wLog* parent, wLog* child)
if (parent->Children) if (parent->Children)
free (parent->Children); free (parent->Children);
parent->Children = NULL; parent->Children = NULL;
return -1; return FALSE;
} }
parent->Children = tmp; parent->Children = tmp;
} }
} }
if (!parent->Children) if (!parent->Children)
return -1; return FALSE;
parent->Children[parent->ChildrenCount++] = child; parent->Children[parent->ChildrenCount++] = child;
child->Parent = parent; child->Parent = parent;
return 0; return TRUE;
} }
wLog* WLog_FindChild(LPCSTR name) wLog* WLog_FindChild(LPCSTR name)
@ -732,6 +753,9 @@ wLog* WLog_FindChild(LPCSTR name)
BOOL found = FALSE; BOOL found = FALSE;
root = WLog_GetRoot(); root = WLog_GetRoot();
if (!root)
return NULL;
for (index = 0; index < root->ChildrenCount; index++) for (index = 0; index < root->ChildrenCount; index++)
{ {
child = root->Children[index]; child = root->Children[index];
@ -756,7 +780,11 @@ wLog* WLog_Get(LPCSTR name)
return NULL; return NULL;
if (!(log = WLog_New(name, root))) if (!(log = WLog_New(name, root)))
return NULL; return NULL;
WLog_AddChild(root, log); if (!WLog_AddChild(root, log))
{
WLog_Free(log);
return NULL;
}
} }
return log; return log;
} }
@ -766,14 +794,14 @@ BOOL WLog_Init()
return WLog_GetRoot() != NULL; return WLog_GetRoot() != NULL;
} }
void WLog_Uninit() BOOL WLog_Uninit()
{ {
DWORD index; DWORD index;
wLog* child = NULL; wLog* child = NULL;
wLog* root = g_RootLog; wLog* root = g_RootLog;
if (!root) if (!root)
return; return FALSE;
for (index = 0; index < root->ChildrenCount; index++) for (index = 0; index < root->ChildrenCount; index++)
{ {
@ -783,4 +811,5 @@ void WLog_Uninit()
WLog_Free(root); WLog_Free(root);
g_RootLog = NULL; g_RootLog = NULL;
return TRUE;
} }

View File

@ -25,7 +25,7 @@
#define WLOG_MAX_PREFIX_SIZE 512 #define WLOG_MAX_PREFIX_SIZE 512
#define WLOG_MAX_STRING_SIZE 8192 #define WLOG_MAX_STRING_SIZE 8192
void WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* message); BOOL WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* message);
#include "wlog/Layout.h" #include "wlog/Layout.h"
#include "wlog/Appender.h" #include "wlog/Appender.h"