Added recursion detection to WLog.

Dump functions now expect TAG and level as arguments.
This commit is contained in:
Armin Novak 2014-08-18 17:11:40 +02:00
parent c32c48fbb6
commit 3e21e570b8
8 changed files with 219 additions and 175 deletions

View File

@ -33,14 +33,14 @@
extern "C" {
#endif
WINPR_API void winpr_HexDump(const BYTE* data, int length);
WINPR_API void winpr_CArrayDump(const BYTE* data, int length, int width);
WINPR_API void winpr_HexDump(const char *tag, int lvl, const BYTE *data, int length);
WINPR_API void winpr_CArrayDump(const char *tag, int lvl, const BYTE *data, int length, int width);
WINPR_API char* winpr_BinToHexString(const BYTE* data, int length, BOOL space);
WINPR_API char *winpr_BinToHexString(const BYTE *data, int length, BOOL space);
WINPR_API int wprintfx(const char *fmt, ...);
WINPR_API int wvprintfx(const char *fmt, va_list args);
WINPR_API int wvsnprintfx(char *buffer, size_t bufferSize, const char* fmt, va_list args);
WINPR_API int wprintfx(const char *fmt, ...);
WINPR_API int wvprintfx(const char *fmt, va_list args);
WINPR_API int wvsnprintfx(char *buffer, size_t bufferSize, const char *fmt, va_list args);
#ifdef __cplusplus
}

View File

@ -77,19 +77,19 @@ extern "C" {
/* Data Message */
void* Data;
void *Data;
int Length;
/* Image Message */
void* ImageData;
void *ImageData;
int ImageWidth;
int ImageHeight;
int ImageBpp;
/* Packet Message */
void* PacketData;
void *PacketData;
int PacketLength;
DWORD PacketFlags;
};
@ -116,12 +116,12 @@ extern "C" {
#define WLOG_PACKET_INBOUND 1
#define WLOG_PACKET_OUTBOUND 2
typedef int (*WLOG_APPENDER_OPEN_FN)(wLog* log, wLogAppender* appender);
typedef int (*WLOG_APPENDER_CLOSE_FN)(wLog* log, wLogAppender* appender);
typedef int (*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 int (*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 int (*WLOG_APPENDER_OPEN_FN)(wLog *log, wLogAppender *appender);
typedef int (*WLOG_APPENDER_CLOSE_FN)(wLog *log, wLogAppender *appender);
typedef int (*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 int (*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);
#define WLOG_APPENDER_COMMON() \
DWORD Type; \
@ -161,10 +161,10 @@ extern "C" {
{
WLOG_APPENDER_COMMON();
char* FileName;
char* FilePath;
char* FullFileName;
FILE* FileDescriptor;
char *FileName;
char *FilePath;
char *FullFileName;
FILE *FileDescriptor;
};
typedef struct _wLogFileAppender wLogFileAppender;
@ -172,10 +172,10 @@ extern "C" {
{
WLOG_APPENDER_COMMON();
char* FileName;
char* FilePath;
char* FullFileName;
FILE* FileDescriptor;
char *FileName;
char *FilePath;
char *FullFileName;
FILE *FileDescriptor;
};
typedef struct _wLogBinaryAppender wLogBinaryAppender;
@ -186,7 +186,7 @@ extern "C" {
struct _wLogFilter
{
DWORD Level;
LPSTR* Names;
LPSTR *Names;
DWORD NameCount;
};
typedef struct _wLogFilter wLogFilter;
@ -201,18 +201,18 @@ extern "C" {
DWORD Level;
BOOL IsRoot;
LPSTR* Names;
LPSTR *Names;
DWORD NameCount;
wLogAppender* Appender;
wLogAppender *Appender;
wLog* Parent;
wLog** Children;
wLog *Parent;
wLog **Children;
DWORD ChildrenCount;
DWORD ChildrenSize;
};
WINPR_API void WLog_PrintMessage(wLog* log, wLogMessage* message, ...);
WINPR_API int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args);
WINPR_API void WLog_PrintMessage(wLog *log, wLogMessage *message, ...);
WINPR_API int WLog_PrintMessageVA(wLog *log, wLogMessage *message, va_list args);
#define WLog_Print(_log, _log_level, _fmt, ...) \
if (_log_level >= WLog_GetLogLevel(_log)) { \
@ -277,25 +277,25 @@ extern "C" {
#define WLog_IsLevelActive(_log, _log_level) \
(_log_level >= WLog_GetLogLevel(_log))
WINPR_API DWORD WLog_GetLogLevel(wLog* log);
WINPR_API void WLog_SetLogLevel(wLog* log, DWORD logLevel);
WINPR_API DWORD WLog_GetLogLevel(wLog *log);
WINPR_API void WLog_SetLogLevel(wLog *log, DWORD logLevel);
WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log);
WINPR_API void WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType);
WINPR_API wLogAppender *WLog_GetLogAppender(wLog *log);
WINPR_API void WLog_SetLogAppenderType(wLog *log, DWORD logAppenderType);
WINPR_API int WLog_OpenAppender(wLog* log);
WINPR_API int WLog_CloseAppender(wLog* log);
WINPR_API int WLog_OpenAppender(wLog *log);
WINPR_API int WLog_CloseAppender(wLog *log);
WINPR_API void WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream);
WINPR_API void WLog_ConsoleAppender_SetOutputStream(wLog *log, wLogConsoleAppender *appender, int outputStream);
WINPR_API void WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename);
WINPR_API void WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath);
WINPR_API void WLog_FileAppender_SetOutputFileName(wLog *log, wLogFileAppender *appender, const char *filename);
WINPR_API void WLog_FileAppender_SetOutputFilePath(wLog *log, wLogFileAppender *appender, const char *filepath);
WINPR_API wLogLayout* WLog_GetLogLayout(wLog* log);
WINPR_API void WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format);
WINPR_API wLogLayout *WLog_GetLogLayout(wLog *log);
WINPR_API void WLog_Layout_SetPrefixFormat(wLog *log, wLogLayout *layout, const char *format);
WINPR_API wLog* WLog_GetRoot(void);
WINPR_API wLog* WLog_Get(LPCSTR name);
WINPR_API wLog *WLog_GetRoot(void);
WINPR_API wLog *WLog_Get(LPCSTR name);
WINPR_API void WLog_Init(void);
WINPR_API void WLog_Uninit(void);

View File

@ -24,46 +24,71 @@
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>
#include <winpr/crt.h>
#include <winpr/print.h>
#include "trio.h"
void winpr_HexDump(const BYTE* data, int length)
#include "../log.h"
void winpr_HexDump(const char *tag, int level, const BYTE *data, int length)
{
const BYTE* p = data;
const BYTE *p = data;
int i, line, offset = 0;
const size_t llen = (length > WINPR_HEXDUMP_LINE_LENGTH) ? WINPR_HEXDUMP_LINE_LENGTH : length;
size_t blen = 5 + llen * 5;
size_t pos = 0;
char *buffer = malloc(blen);
if (!buffer)
{
WLog_ERR(tag, "malloc(%zd) failed with [%d] %s", blen, errno, strerror(errno));
return;
}
while (offset < length)
{
fprintf(stderr, "%04x ", offset);
pos += snprintf(&buffer[pos], blen - pos, "%04x ", offset);
line = length - offset;
if (line > WINPR_HEXDUMP_LINE_LENGTH)
line = WINPR_HEXDUMP_LINE_LENGTH;
for (i = 0; i < line; i++)
fprintf(stderr, "%02x ", p[i]);
pos += snprintf(&buffer[pos], blen - pos, "%02x ", p[i]);
for (; i < WINPR_HEXDUMP_LINE_LENGTH; i++)
fprintf(stderr, " ");
pos += snprintf(&buffer[pos], blen - pos, " ");
for (i = 0; i < line; i++)
fprintf(stderr, "%c", (p[i] >= 0x20 && p[i] < 0x7F) ? p[i] : '.');
fprintf(stderr, "\n");
pos += snprintf(&buffer[pos], blen - pos, "%c",
(p[i] >= 0x20 && p[i] < 0x7F) ? p[i] : '.');
pos += snprintf(&buffer[pos], blen - pos, "\n");
WLog_LVL(tag, level, "%s", buffer);
offset += line;
p += line;
pos = 0;
}
free(buffer);
}
void winpr_CArrayDump(const BYTE* data, int length, int width)
void winpr_CArrayDump(const char *tag, int level, const BYTE *data, int length, int width)
{
const BYTE* p = data;
const BYTE *p = data;
int i, line, offset = 0;
const size_t llen = ((length > width) ? width : length) * 4 + 1;
size_t pos;
char *buffer = malloc(llen);
if (!buffer)
{
WLog_ERR(tag, "malloc(%zd) failed with [%d] %s", llen, errno, strerror(errno));
return;
}
while (offset < length)
{
@ -72,37 +97,33 @@ void winpr_CArrayDump(const BYTE* data, int length, int width)
if (line > width)
line = width;
printf("\t\"");
pos = 0;
for (i = 0; i < line; i++)
printf("\\x%02X", p[i]);
printf("\"\n");
pos += snprintf(&buffer[pos], llen - pos, "\\x%02X", p[i]);
WLog_LVL(tag, level, "%s", buffer);
offset += line;
p += line;
}
printf("\n");
free(buffer);
}
char* winpr_BinToHexString(const BYTE* data, int length, BOOL space)
char *winpr_BinToHexString(const BYTE *data, int length, BOOL space)
{
int i;
int n;
char* p;
char *p;
int ln, hn;
char bin2hex[] = "0123456789ABCDEF";
n = space ? 3 : 2;
p = (char*) malloc((length + 1) * n);
p = (char *) malloc((length + 1) * n);
for (i = 0; i < length; i++)
{
ln = data[i] & 0xF;
hn = (data[i] >> 4) & 0xF;
p[i * n] = bin2hex[hn];
p[(i * n) + 1] = bin2hex[ln];
@ -111,7 +132,6 @@ char* winpr_BinToHexString(const BYTE* data, int length, BOOL space)
}
p[length * n] = '\0';
return p;
}
@ -124,15 +144,13 @@ int wprintfx(const char *fmt, ...)
{
va_list args;
int status;
va_start(args, fmt);
status = trio_vprintf(fmt, args);
va_end(args);
return status;
}
int wvsnprintfx(char *buffer, size_t bufferSize, const char* fmt, va_list args)
int wvsnprintfx(char *buffer, size_t bufferSize, const char *fmt, va_list args)
{
return trio_vsnprintf(buffer, bufferSize, fmt, args);
}

View File

@ -26,8 +26,11 @@
#include <openssl/ssl.h>
#include <openssl/err.h>
#include "../log.h"
#define TAG "utils.ssl"
static int g_winpr_openssl_num_locks = 0;
static HANDLE* g_winpr_openssl_locks = NULL;
static HANDLE *g_winpr_openssl_locks = NULL;
static BOOL g_winpr_openssl_initialized_by_winpr = FALSE;
struct CRYPTO_dynlock_value
@ -58,9 +61,10 @@ static void _winpr_openssl_locking(int mode, int type, const char *file, int lin
static struct CRYPTO_dynlock_value *_winpr_openssl_dynlock_create(const char *file, int line)
{
struct CRYPTO_dynlock_value *dynlock = (struct CRYPTO_dynlock_value *)
malloc(sizeof(struct CRYPTO_dynlock_value));
malloc(sizeof(struct CRYPTO_dynlock_value));
if (dynlock) {
if (dynlock)
{
dynlock->mutex = CreateMutex(NULL, FALSE, NULL);
}
@ -93,16 +97,17 @@ static BOOL _winpr_openssl_initialize_locking(void)
if (CRYPTO_get_locking_callback())
{
fprintf(stderr, "%s: warning: OpenSSL static locking callback is already set\n", __FUNCTION__);
WLog_WARN(TAG, "OpenSSL static locking callback is already set");
}
else
{
if ((count = CRYPTO_num_locks()) > 0)
{
HANDLE *locks;
if (!(locks = calloc(count, sizeof(HANDLE))))
{
fprintf(stderr, "%s: error allocating lock table\n", __FUNCTION__);
WLog_ERR(TAG, "error allocating lock table");
return FALSE;
}
@ -110,11 +115,13 @@ static BOOL _winpr_openssl_initialize_locking(void)
{
if (!(locks[i] = CreateMutex(NULL, FALSE, NULL)))
{
fprintf(stderr, "%s: error creating lock #%d\n", __FUNCTION__, i);
WLog_ERR(TAG, "error creating lock #%d", i);
while (i--)
{
CloseHandle(g_winpr_openssl_locks[i]);
}
free(locks);
return FALSE;
}
@ -122,19 +129,17 @@ static BOOL _winpr_openssl_initialize_locking(void)
g_winpr_openssl_locks = locks;
g_winpr_openssl_num_locks = count;
CRYPTO_set_locking_callback(_winpr_openssl_locking);
}
}
/* OpenSSL dynamic locking */
if (CRYPTO_get_dynlock_create_callback() ||
CRYPTO_get_dynlock_lock_callback() ||
CRYPTO_get_dynlock_destroy_callback())
CRYPTO_get_dynlock_lock_callback() ||
CRYPTO_get_dynlock_destroy_callback())
{
fprintf(stderr, "%s: warning: dynamic locking callbacks are already set\n", __FUNCTION__);
WLog_WARN(TAG, "dynamic locking callbacks are already set");
}
else
{
@ -143,31 +148,28 @@ static BOOL _winpr_openssl_initialize_locking(void)
CRYPTO_set_dynlock_destroy_callback(_winpr_openssl_dynlock_destroy);
}
/* Use the deprecated CRYPTO_get_id_callback() if building against OpenSSL < 1.0.0 */
#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
if (CRYPTO_get_id_callback())
{
fprintf(stderr, "%s: warning OpenSSL id_callback is already set\n", __FUNCTION__);
WLog_WARN(TAG, "OpenSSL id_callback is already set");
}
else
{
CRYPTO_set_id_callback(_winpr_openssl_id);
}
#endif
#endif
return TRUE;
}
static BOOL _winpr_openssl_cleanup_locking(void)
{
/* undo our static locking modifications */
if (CRYPTO_get_locking_callback() == _winpr_openssl_locking)
{
int i;
CRYPTO_set_locking_callback(NULL);
for (i = 0; i < g_winpr_openssl_num_locks; i++)
@ -180,7 +182,6 @@ static BOOL _winpr_openssl_cleanup_locking(void)
g_winpr_openssl_locks = NULL;
}
/* unset our dynamic locking callbacks */
if (CRYPTO_get_dynlock_create_callback() == _winpr_openssl_dynlock_create)
@ -198,14 +199,14 @@ static BOOL _winpr_openssl_cleanup_locking(void)
CRYPTO_set_dynlock_destroy_callback(NULL);
}
#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
if (CRYPTO_get_id_callback() == _winpr_openssl_id)
{
CRYPTO_set_id_callback(NULL);
}
#endif
#endif
return TRUE;
}
@ -228,12 +229,9 @@ static BOOL CALLBACK _winpr_openssl_initialize(PINIT_ONCE once, PVOID param, PVO
/* SSL_load_error_strings() is void */
SSL_load_error_strings();
/* SSL_library_init() always returns "1" */
SSL_library_init();
g_winpr_openssl_initialized_by_winpr = TRUE;
return TRUE;
}
@ -252,9 +250,10 @@ BOOL winpr_CleanupSSL(DWORD flags)
{
if (!g_winpr_openssl_initialized_by_winpr)
{
fprintf(stderr, "%s: warning: ssl was not initialized by winpr\n", __FUNCTION__);
WLog_WARN(TAG, "ssl was not initialized by winpr");
return FALSE;
}
g_winpr_openssl_initialized_by_winpr = FALSE;
_winpr_openssl_cleanup_locking();
CRYPTO_cleanup_all_ex_data();

View File

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

View File

@ -23,8 +23,6 @@
#include <winpr/wlog.h>
#include <winpr/image.h>
#include "wlog/ImageMessage.h"
int WLog_ImageMessage_Write(char* filename, void* data, int width, int height, int bpp)

View File

@ -28,6 +28,9 @@
#include <winpr/crt.h>
#include <winpr/stream.h>
#include "../../log.h"
#define TAG WINPR_TAG("utils.wlog")
#ifndef _WIN32
#include <sys/time.h>
#else
@ -175,7 +178,7 @@ wPcap* Pcap_Open(char* name, BOOL write)
if (!pcap_fp)
{
perror("opening pcap file");
WLog_ERR(TAG,"opening pcap file");
return NULL;
}

View File

@ -42,7 +42,7 @@
* http://docs.python.org/2/library/logging.html
*/
const char* WLOG_LEVELS[7] =
const char *WLOG_LEVELS[7] =
{
"TRACE",
"DEBUG",
@ -54,12 +54,26 @@ const char* WLOG_LEVELS[7] =
};
static DWORD g_FilterCount = 0;
static wLogFilter* g_Filters = NULL;
static wLogFilter *g_Filters = NULL;
int WLog_Write(wLog* log, wLogMessage* message)
static void log_recursion(const char *file, const char *fkt, int line)
{
int status;
wLogAppender* appender;
/* TODO: Stack trace here! */
#if defined(ANDROID)
const char *tag = "com.winpr.utils.wlog";
level = ANDROID_LOG_FATAL;
__android_log_print(ANDROID_LOG_FATAL, tag, "Recursion detected!!!");
__android_log_print(ANDROID_LOG_FATAL, tag, "Check %s [%s:%d]", fkt, file, line);
#else
fprintf(stderr, "[%s]: Recursion detected!\n", fkt);
fprintf(stderr, "[%s]: Check %s:%d\n", fkt, file, line);
#endif
}
int WLog_Write(wLog *log, wLogMessage *message)
{
int status = -1;
wLogAppender *appender;
appender = WLog_GetLogAppender(log);
if (!appender)
@ -74,19 +88,22 @@ int WLog_Write(wLog* log, wLogMessage* message)
EnterCriticalSection(&appender->lock);
if (appender->recursive)
fprintf(stderr, "%s: Recursion detected!!!!", __FUNCTION__);
log_recursion(message->FileName, message->FunctionName, message->LineNumber);
else
{
appender->recursive = TRUE;
status = appender->WriteMessage(log, appender, message);
appender->recursive = FALSE;
}
appender->recursive = TRUE;
status = appender->WriteMessage(log, appender, message);
appender->recursive = FALSE;
LeaveCriticalSection(&appender->lock);
return status;
}
int WLog_WriteData(wLog* log, wLogMessage* message)
int WLog_WriteData(wLog *log, wLogMessage *message)
{
int status;
wLogAppender* appender;
int status = -1;
wLogAppender *appender;
appender = WLog_GetLogAppender(log);
if (!appender)
@ -101,19 +118,22 @@ int WLog_WriteData(wLog* log, wLogMessage* message)
EnterCriticalSection(&appender->lock);
if (appender->recursive)
fprintf(stderr, "%s: Recursion detected!!!!", __FUNCTION__);
log_recursion(message->FileName, message->FunctionName, message->LineNumber);
else
{
appender->recursive = TRUE;
status = appender->WriteDataMessage(log, appender, message);
appender->recursive = FALSE;
}
appender->recursive = TRUE;
status = appender->WriteDataMessage(log, appender, message);
appender->recursive = FALSE;
LeaveCriticalSection(&appender->lock);
return status;
}
int WLog_WriteImage(wLog* log, wLogMessage* message)
int WLog_WriteImage(wLog *log, wLogMessage *message)
{
int status;
wLogAppender* appender;
int status = -1;
wLogAppender *appender;
appender = WLog_GetLogAppender(log);
if (!appender)
@ -128,19 +148,22 @@ int WLog_WriteImage(wLog* log, wLogMessage* message)
EnterCriticalSection(&appender->lock);
if (appender->recursive)
fprintf(stderr, "%s: Recursion detected!!!!", __FUNCTION__);
log_recursion(message->FileName, message->FunctionName, message->LineNumber);
else
{
appender->recursive = TRUE;
status = appender->WriteImageMessage(log, appender, message);
appender->recursive = FALSE;
}
appender->recursive = TRUE;
status = appender->WriteImageMessage(log, appender, message);
appender->recursive = FALSE;
LeaveCriticalSection(&appender->lock);
return status;
}
int WLog_WritePacket(wLog* log, wLogMessage* message)
int WLog_WritePacket(wLog *log, wLogMessage *message)
{
int status;
wLogAppender* appender;
int status = -1;
wLogAppender *appender;
appender = WLog_GetLogAppender(log);
if (!appender)
@ -155,16 +178,19 @@ int WLog_WritePacket(wLog* log, wLogMessage* message)
EnterCriticalSection(&appender->lock);
if (appender->recursive)
fprintf(stderr, "%s: Recursion detected!!!!", __FUNCTION__);
log_recursion(message->FileName, message->FunctionName, message->LineNumber);
else
{
appender->recursive = TRUE;
status = appender->WritePacketMessage(log, appender, message);
appender->recursive = FALSE;
}
appender->recursive = TRUE;
status = appender->WritePacketMessage(log, appender, message);
appender->recursive = FALSE;
LeaveCriticalSection(&appender->lock);
return status;
}
int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args)
int WLog_PrintMessageVA(wLog *log, wLogMessage *message, va_list args)
{
int status = -1;
@ -185,13 +211,13 @@ int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args)
}
else if (message->Type == WLOG_MESSAGE_DATA)
{
message->Data = va_arg(args, void*);
message->Data = va_arg(args, void *);
message->Length = va_arg(args, int);
status = WLog_WriteData(log, message);
}
else if (message->Type == WLOG_MESSAGE_IMAGE)
{
message->ImageData = va_arg(args, void*);
message->ImageData = va_arg(args, void *);
message->ImageWidth = va_arg(args, int);
message->ImageHeight = va_arg(args, int);
message->ImageBpp = va_arg(args, int);
@ -199,7 +225,7 @@ int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args)
}
else if (message->Type == WLOG_MESSAGE_PACKET)
{
message->PacketData = va_arg(args, void*);
message->PacketData = va_arg(args, void *);
message->PacketLength = va_arg(args, int);
message->PacketFlags = va_arg(args, int);
status = WLog_WritePacket(log, message);
@ -208,7 +234,7 @@ int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args)
return status;
}
void WLog_PrintMessage(wLog* log, wLogMessage* message, ...)
void WLog_PrintMessage(wLog *log, wLogMessage *message, ...)
{
int status;
va_list args;
@ -217,7 +243,7 @@ void WLog_PrintMessage(wLog* log, wLogMessage* message, ...)
va_end(args);
}
DWORD WLog_GetLogLevel(wLog* log)
DWORD WLog_GetLogLevel(wLog *log)
{
if (log->Level == WLOG_LEVEL_INHERIT)
{
@ -229,7 +255,7 @@ DWORD WLog_GetLogLevel(wLog* log)
}
}
void WLog_SetLogLevel(wLog* log, DWORD logLevel)
void WLog_SetLogLevel(wLog *log, DWORD logLevel)
{
if ((logLevel > WLOG_OFF) && (logLevel != WLOG_LEVEL_INHERIT))
{
@ -239,7 +265,7 @@ void WLog_SetLogLevel(wLog* log, DWORD logLevel)
log->Level = logLevel;
}
int WLog_ParseLogLevel(const char* level)
int WLog_ParseLogLevel(const char *level)
{
int iLevel = -1;
@ -264,15 +290,15 @@ int WLog_ParseLogLevel(const char* level)
return iLevel;
}
int WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
int WLog_ParseFilter(wLogFilter *filter, LPCSTR name)
{
char* p;
char* q;
char *p;
char *q;
int count;
LPSTR names;
int iLevel;
count = 1;
p = (char*) name;
p = (char *) name;
while ((p = strchr(p, '.')) != NULL)
{
@ -282,10 +308,10 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
names = _strdup(name);
filter->NameCount = count;
filter->Names = (LPSTR*) malloc(sizeof(LPSTR) * (count + 1));
filter->Names = (LPSTR *) malloc(sizeof(LPSTR) * (count + 1));
filter->Names[count] = NULL;
count = 0;
p = (char*) names;
p = (char *) names;
filter->Names[count++] = p;
q = strrchr(p, ':');
@ -313,12 +339,12 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
int WLog_ParseFilters()
{
char* p;
char* env;
char *p;
char *env;
DWORD count;
DWORD nSize;
int status;
char** strs;
char **strs;
nSize = GetEnvironmentVariableA("WLOG_FILTER", NULL, 0);
if (nSize < 1)
@ -342,7 +368,7 @@ int WLog_ParseFilters()
g_FilterCount = count;
p = env;
count = 0;
strs = (char**) calloc(g_FilterCount, sizeof(char*));
strs = (char **) calloc(g_FilterCount, sizeof(char *));
strs[count++] = p;
while ((p = strchr(p, ',')) != NULL)
@ -369,7 +395,7 @@ int WLog_ParseFilters()
return 0;
}
int WLog_GetFilterLogLevel(wLog* log)
int WLog_GetFilterLogLevel(wLog *log)
{
DWORD i, j;
int iLevel = -1;
@ -410,13 +436,13 @@ int WLog_GetFilterLogLevel(wLog* log)
return iLevel;
}
int WLog_ParseName(wLog* log, LPCSTR name)
int WLog_ParseName(wLog *log, LPCSTR name)
{
char* p;
char *p;
int count;
LPSTR names;
count = 1;
p = (char*) name;
p = (char *) name;
while ((p = strchr(p, '.')) != NULL)
{
@ -426,10 +452,10 @@ int WLog_ParseName(wLog* log, LPCSTR name)
names = _strdup(name);
log->NameCount = count;
log->Names = (LPSTR*) malloc(sizeof(LPSTR) * (count + 1));
log->Names = (LPSTR *) malloc(sizeof(LPSTR) * (count + 1));
log->Names[count] = NULL;
count = 0;
p = (char*) names;
p = (char *) names;
log->Names[count++] = p;
while ((p = strchr(p, '.')) != NULL)
@ -442,13 +468,13 @@ int WLog_ParseName(wLog* log, LPCSTR name)
return 0;
}
wLog* WLog_New(LPCSTR name, wLog* rootLogger)
wLog *WLog_New(LPCSTR name, wLog *rootLogger)
{
wLog* log;
char* env;
wLog *log;
char *env;
DWORD nSize;
int iLevel;
log = (wLog*) calloc(1, sizeof(wLog));
log = (wLog *) calloc(1, sizeof(wLog));
if (log)
{
@ -461,7 +487,7 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
log->Parent = rootLogger;
log->ChildrenCount = 0;
log->ChildrenSize = 16;
log->Children = (wLog**) calloc(log->ChildrenSize, sizeof(wLog*));
log->Children = (wLog **) calloc(log->ChildrenSize, sizeof(wLog *));
if (!log->Children)
return NULL;
@ -499,7 +525,7 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
return log;
}
void WLog_Free(wLog* log)
void WLog_Free(wLog *log)
{
if (log)
{
@ -517,11 +543,11 @@ void WLog_Free(wLog* log)
}
}
static wLog* g_RootLog = NULL;
static wLog *g_RootLog = NULL;
wLog* WLog_GetRoot()
wLog *WLog_GetRoot()
{
char* env;
char *env;
DWORD nSize;
DWORD logAppenderType;
@ -557,12 +583,12 @@ wLog* WLog_GetRoot()
return g_RootLog;
}
int WLog_AddChild(wLog* parent, wLog* child)
int WLog_AddChild(wLog *parent, wLog *child)
{
if (parent->ChildrenCount >= parent->ChildrenSize)
{
parent->ChildrenSize *= 2;
parent->Children = (wLog**) realloc(parent->Children, sizeof(wLog*) * parent->ChildrenSize);
parent->Children = (wLog **) realloc(parent->Children, sizeof(wLog *) * parent->ChildrenSize);
}
parent->Children[parent->ChildrenCount++] = child;
@ -570,11 +596,11 @@ int WLog_AddChild(wLog* parent, wLog* child)
return 0;
}
wLog* WLog_FindChild(LPCSTR name)
wLog *WLog_FindChild(LPCSTR name)
{
DWORD index;
wLog* root;
wLog* child = NULL;
wLog *root;
wLog *child = NULL;
BOOL found = FALSE;
root = WLog_GetRoot();
@ -592,10 +618,10 @@ wLog* WLog_FindChild(LPCSTR name)
return (found) ? child : NULL;
}
wLog* WLog_Get(LPCSTR name)
wLog *WLog_Get(LPCSTR name)
{
wLog* log;
wLog* root;
wLog *log;
wLog *root;
root = WLog_GetRoot();
log = WLog_FindChild(name);
@ -615,9 +641,9 @@ void WLog_Init()
void WLog_Uninit()
{
wLog* root = WLog_GetRoot();
wLog *root = WLog_GetRoot();
DWORD index;
wLog* child = NULL;
wLog *child = NULL;
for (index = 0; index < root->ChildrenCount; index++)
{