diff --git a/.gitignore b/.gitignore index 98ca450a2..6853f6825 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ LICENSE.txt *Config.cmake *ConfigVersion.cmake include/freerdp/version.h +include/freerdp/build-config.h *.a.objlist.cmake *.a.objlist diff --git a/CMakeLists.txt b/CMakeLists.txt index 718f9ff70..411bdef73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,9 +68,9 @@ if ($ENV{BUILD_NUMBER}) set(BUILD_NUMBER $ENV{BUILD_NUMBER}) endif() set(WITH_LIBRARY_VERSIONING "ON") -set(FREERDP_VERSION_MAJOR "1") -set(FREERDP_VERSION_MINOR "2") -set(FREERDP_VERSION_REVISION "5") +set(FREERDP_VERSION_MAJOR "2") +set(FREERDP_VERSION_MINOR "0") +set(FREERDP_VERSION_REVISION "0") set(FREERDP_VERSION_SUFFIX "dev") set(FREERDP_API_VERSION "${FREERDP_VERSION_MAJOR}.${FREERDP_VERSION_MINOR}") set(FREERDP_VERSION "${FREERDP_API_VERSION}.${FREERDP_VERSION_REVISION}") diff --git a/channels/client/addin.c b/channels/client/addin.c index 8f4d54bc3..a2d688006 100644 --- a/channels/client/addin.c +++ b/channels/client/addin.c @@ -31,6 +31,7 @@ #include #include +#include #include #include "tables.h" @@ -181,22 +182,22 @@ FREERDP_ADDIN** freerdp_channels_list_dynamic_addins(LPSTR pszName, LPSTR pszSub if (pszName && pszSubsystem && pszType) { - sprintf_s(pszPattern, cchPattern, CMAKE_SHARED_LIBRARY_PREFIX"%s-client-%s-%s.%s", + sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX"%s-client-%s-%s.%s", pszName, pszSubsystem, pszType, pszExtension); } else if (pszName && pszType) { - sprintf_s(pszPattern, cchPattern, CMAKE_SHARED_LIBRARY_PREFIX"%s-client-?-%s.%s", + sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX"%s-client-?-%s.%s", pszName, pszType, pszExtension); } else if (pszName) { - sprintf_s(pszPattern, cchPattern, CMAKE_SHARED_LIBRARY_PREFIX"%s-client*.%s", + sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX"%s-client*.%s", pszName, pszExtension); } else { - sprintf_s(pszPattern, cchPattern, CMAKE_SHARED_LIBRARY_PREFIX"?-client*.%s", + sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX"?-client*.%s", pszExtension); } diff --git a/channels/cliprdr/server/cliprdr_main.c b/channels/cliprdr/server/cliprdr_main.c index b082c830e..a73b2b98c 100644 --- a/channels/cliprdr/server/cliprdr_main.c +++ b/channels/cliprdr/server/cliprdr_main.c @@ -633,7 +633,6 @@ static UINT cliprdr_server_receive_format_list(CliprdrServerContext* context, wS WCHAR* wszFormatName; CLIPRDR_FORMAT* formats = NULL; CLIPRDR_FORMAT_LIST formatList; - CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle; UINT error = CHANNEL_RC_OK; dataLen = header->dataLen; @@ -1094,7 +1093,6 @@ static UINT cliprdr_server_init(CliprdrServerContext* context) CLIPRDR_CAPABILITIES capabilities; CLIPRDR_MONITOR_READY monitorReady; CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet; - CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle; UINT error; ZeroMemory(&capabilities, sizeof(capabilities)); diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index 28f8bc8f1..95c29a066 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -239,7 +239,7 @@ BOOL xf_GetWindowProperty(xfContext* xfc, Window window, Atom property, int leng if (actual_type == None) { - WLog_ERR(TAG, "Property %lu does not exist", property); + WLog_INFO(TAG, "Property %lu does not exist", property); return FALSE; } diff --git a/config.h.in b/config.h.in index e25162dd1..0f39545f2 100644 --- a/config.h.in +++ b/config.h.in @@ -1,22 +1,6 @@ #ifndef __CONFIG_H #define __CONFIG_H -#define FREERDP_DATA_PATH "${FREERDP_DATA_PATH}" -#define FREERDP_KEYMAP_PATH "${FREERDP_KEYMAP_PATH}" -#define FREERDP_PLUGIN_PATH "${FREERDP_PLUGIN_PATH}" - -#define FREERDP_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" - -#define FREERDP_LIBRARY_PATH "${FREERDP_LIBRARY_PATH}" - -#define FREERDP_ADDIN_PATH "${FREERDP_ADDIN_PATH}" - -#define CMAKE_SHARED_LIBRARY_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}" -#define CMAKE_SHARED_LIBRARY_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}" - -#define FREERDP_VENDOR_STRING "${VENDOR}" -#define FREERDP_PRODUCT_STRING "${PRODUCT}" - /* Include files */ #cmakedefine HAVE_FCNTL_H #cmakedefine HAVE_UNISTD_H diff --git a/docs/wlog.md b/docs/wlog.md new file mode 100644 index 000000000..e6d1286ae --- /dev/null +++ b/docs/wlog.md @@ -0,0 +1,151 @@ +# Overview + +WLog is a configurable and flexible logging system used throughout winpr and +FreeRDP. + +The primary concept is to have a hierarchy of loggers that can be be configured +independently. + +TODO add more details and configuration examples. + + + +# Environment variables + +* WLOG_APPENDER - the appender to use possible values below also see the Appender section. + * CONSOLE + * FILE + * BINARY + * SYSLOG + * JOURNALD + * UDP +* WLOG_PREFIX - configure the prefix used for outputting the message (see + Format for more details and examples) +* WLOG_LEVEL - the level to output messages for +* WLOG_FILTER - sets a filter for WLog messages. Only the filtered messages are +printed +* WLOG_FILEAPPENDER_OUTPUT_FILE_PATH - set the output file path for the file +file appender +* WLOG_FILEAPPENDER_OUTPUT_FILE_NAME - set the output file name for the output +appender +* WLOG_JOURNALD_ID - identifier used by the journal appender +* WLOG_UDP_TARGET - target to use for the UDP appender in the format host:port + +# Levels + +The WLog are complementary the higher level always includes the lower ones. +The level list below is top down. Top the highest level. + +* WLOG_TRACE - print everything including package dumps +* WLOG_DEBUG - debug messages +* WLOG_INFO - general informations +* WLOG_WARN - warnings +* WLOG_ERROR - errors +* WLOG_FATAL - fatal problems +* WLOG_OFF - completely disable the wlog output + + +# Format + +The format a logger prints in has the following possible options: + +* "lv" - log level +* "mn" - module name +* "fl" - file name +* "fn" - function +* "ln" - line number +* "pid" - process id +* "tid" - thread id +* "yr" - year +* "mo" - month +* "dw" - day of week +* "hr" - hour +* "mi" - minute +* "se" - second +* "ml" - millisecond + +A maximum of 16 options can be used per format string. + +An example that generally sets the WLOG_PREFIX for xfreerdp would look like: +``` +WLOG_PREFIX="pid=%pid:tid=%tid:fn=%fn -" xfreerdp /v:xxx +``` + +# Appenders + +WLog uses different appenders that define where the log output should be written +to. If the application doesn't explicitly configure the appenders the above +described variable WLOG_APPENDER can be used to choose one appender. + +The following represents an overview about all appenders and their possible +configuration values. + +### Binary + +Write the log data into a binary format file. + +Options: +* "outputfilename", value const char* - file to write the data to +* "outputfilepath", value const char* - location of the output file + +### Callback +The callback appender can be used from an application to get all log messages +back the application. For example if an application wants to handle the log +output itself. + +Options: + +* "callbacks", value struct wLogCallbacks*, callbacks to use + +### Console + +The console appender writes to the console. Depending of the operating system +the application runs on the output might be handled differently. For example +on android log print would be used. + +Options: + + +* "outputstream", value const char * - output stream to write to + * "stdout" - write everything to stdout + * "stderr" - write everything to stderr + * "default" - use the default settings - in this case errors and fatal would + go to stderr everything else to stdout + * debug - use the debug output. Only used on windows on all operating systems + this behaves as as if default was set. + +### File +The file appender writes the textual output to a file. + +Options: + +* "outputfilename", value const char*, filename to use +* "outputfilepath", value const char*, location of the file + +### Udp + +This appender sends the logging messages to a pre-defined remote host via UDP. + +Options: + +* "target", value const char*, target to send the data too in the format +host:port + +If no target is set the default one 127.0.0.1:20000 is used. To receive the +log messages one can use netcat. To receive the default target the following +command could be used. +``` +nc -u 127.0.0.1 -p 20000 -l +``` + +### Syslog (optional) + +Use syslog for outputting the debug messages. No options available. + +### Journald (optional) + +For outputting the log messages to journald this appender can be used. +The available options are: + +* "identifier", value const char*, the identifier to use for journald (default + is winpr) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 06e2b77bd..8995688e3 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -18,10 +18,12 @@ # limitations under the License. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/freerdp/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/freerdp/version.h) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/freerdp/build-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/freerdp/build-config.h) file(GLOB FREERDP_HEADERS "freerdp/*.h") install(FILES ${FREERDP_HEADERS} DESTINATION include/freerdp COMPONENT headers) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/freerdp/version.h DESTINATION include/freerdp COMPONENT headers) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/freerdp/build-config.h DESTINATION include/freerdp COMPONENT headers) install(DIRECTORY freerdp/cache DESTINATION include/freerdp COMPONENT headers FILES_MATCHING PATTERN "*.h") install(DIRECTORY freerdp/codec DESTINATION include/freerdp COMPONENT headers FILES_MATCHING PATTERN "*.h") diff --git a/include/freerdp/build-config.h.in b/include/freerdp/build-config.h.in new file mode 100644 index 000000000..788e27f2f --- /dev/null +++ b/include/freerdp/build-config.h.in @@ -0,0 +1,20 @@ +#ifndef FREERDP_BUILD_CONFIG_H +#define FREERDP_BUILD_CONFIG_H + +#define FREERDP_DATA_PATH "${FREERDP_DATA_PATH}" +#define FREERDP_KEYMAP_PATH "${FREERDP_KEYMAP_PATH}" +#define FREERDP_PLUGIN_PATH "${FREERDP_PLUGIN_PATH}" + +#define FREERDP_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" + +#define FREERDP_LIBRARY_PATH "${FREERDP_LIBRARY_PATH}" + +#define FREERDP_ADDIN_PATH "${FREERDP_ADDIN_PATH}" + +#define FREERDP_SHARED_LIBRARY_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}" +#define FREERDP_SHARED_LIBRARY_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}" + +#define FREERDP_VENDOR_STRING "${VENDOR}" +#define FREERDP_PRODUCT_STRING "${PRODUCT}" + +#endif /* FREERDP_BUILD_CONFIG_H */ diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c index 7886daea4..cc8a61c38 100644 --- a/libfreerdp/codec/rfx.c +++ b/libfreerdp/codec/rfx.c @@ -43,6 +43,7 @@ #include #include #include +#include #include "rfx_constants.h" #include "rfx_types.h" diff --git a/libfreerdp/codec/test/TestFreeRDPRegion.c b/libfreerdp/codec/test/TestFreeRDPRegion.c index 1694baa59..5530d96bf 100644 --- a/libfreerdp/codec/test/TestFreeRDPRegion.c +++ b/libfreerdp/codec/test/TestFreeRDPRegion.c @@ -694,7 +694,6 @@ static int test_norbert2_case() { int retCode = -1; const RECTANGLE_16 *rects; int nbRects = 0; - int i; RECTANGLE_16 rect1 = { 464, 696, 476, 709 }; RECTANGLE_16 rect2 = { 0, 0, 1024, 32 }; diff --git a/libfreerdp/common/addin.c b/libfreerdp/common/addin.c index 52197b418..ce7cf7b9e 100644 --- a/libfreerdp/common/addin.c +++ b/libfreerdp/common/addin.c @@ -30,6 +30,7 @@ #include #include +#include LPSTR freerdp_get_library_install_path() @@ -143,7 +144,7 @@ void* freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPath, LPCSTR pszE } else { - cchAddinFile = cchFileName + cchExt + 2 + sizeof(CMAKE_SHARED_LIBRARY_PREFIX); + cchAddinFile = cchFileName + cchExt + 2 + sizeof(FREERDP_SHARED_LIBRARY_PREFIX); pszAddinFile = (LPSTR) malloc(cchAddinFile + 1); if (!pszAddinFile) { @@ -151,7 +152,7 @@ void* freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPath, LPCSTR pszE free(pszFilePath); return NULL; } - sprintf_s(pszAddinFile, cchAddinFile, CMAKE_SHARED_LIBRARY_PREFIX"%s%s", pszFileName, pszExt); + sprintf_s(pszAddinFile, cchAddinFile, FREERDP_SHARED_LIBRARY_PREFIX"%s%s", pszFileName, pszExt); cchAddinFile = strlen(pszAddinFile); } @@ -182,9 +183,9 @@ void* freerdp_load_dynamic_channel_addin_entry(LPCSTR pszName, LPSTR pszSubsyste { void* entry; LPSTR pszFileName; - size_t cchFileName = sizeof(CMAKE_SHARED_LIBRARY_PREFIX) + 32; + size_t cchFileName = sizeof(FREERDP_SHARED_LIBRARY_PREFIX) + 32; LPCSTR pszExtension; - LPCSTR pszPrefix = CMAKE_SHARED_LIBRARY_PREFIX; + LPCSTR pszPrefix = FREERDP_SHARED_LIBRARY_PREFIX; pszExtension = PathGetSharedLibraryExtensionA(0); diff --git a/libfreerdp/core/nla.c b/libfreerdp/core/nla.c index 0fcbaa56f..22c013834 100644 --- a/libfreerdp/core/nla.c +++ b/libfreerdp/core/nla.c @@ -31,6 +31,7 @@ #include #include +#include #include #include diff --git a/libfreerdp/core/settings.c b/libfreerdp/core/settings.c index a89198ce4..2fb632fac 100644 --- a/libfreerdp/core/settings.c +++ b/libfreerdp/core/settings.c @@ -37,6 +37,7 @@ #include #include +#include #include diff --git a/server/Windows/wf_info.c b/server/Windows/wf_info.c index 460154bb7..a582bc835 100644 --- a/server/Windows/wf_info.c +++ b/server/Windows/wf_info.c @@ -23,6 +23,8 @@ #include +#include + #include #include diff --git a/server/Windows/wf_interface.c b/server/Windows/wf_interface.c index 216d3cae5..0dc8defd0 100644 --- a/server/Windows/wf_interface.c +++ b/server/Windows/wf_interface.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "wf_peer.h" #include "wf_settings.h" diff --git a/server/Windows/wf_peer.c b/server/Windows/wf_peer.c index 4a4c493c9..ecb3a21bf 100644 --- a/server/Windows/wf_peer.c +++ b/server/Windows/wf_peer.c @@ -28,6 +28,7 @@ #include #include +#include #include "wf_info.h" #include "wf_input.h" diff --git a/winpr/include/winpr/wlog.h b/winpr/include/winpr/wlog.h index f7c0efd17..f7d7ec0c1 100644 --- a/winpr/include/winpr/wlog.h +++ b/winpr/include/winpr/wlog.h @@ -3,6 +3,9 @@ * WinPR Logger * * Copyright 2013 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 Bernhard Miklautz + * * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,42 +27,40 @@ extern "C" { #endif -#include -#include - -#include #include - #include #include -#include - -typedef struct _wLog wLog; -typedef struct _wLogMessage wLogMessage; -typedef struct _wLogLayout wLogLayout; -typedef struct _wLogAppender wLogAppender; /** * Log Levels */ - -#define WLOG_TRACE 0 -#define WLOG_DEBUG 1 -#define WLOG_INFO 2 -#define WLOG_WARN 3 -#define WLOG_ERROR 4 -#define WLOG_FATAL 5 -#define WLOG_OFF 6 +#define WLOG_TRACE 0 +#define WLOG_DEBUG 1 +#define WLOG_INFO 2 +#define WLOG_WARN 3 +#define WLOG_ERROR 4 +#define WLOG_FATAL 5 +#define WLOG_OFF 6 #define WLOG_LEVEL_INHERIT 0xFFFF /** * Log Message */ +#define WLOG_MESSAGE_TEXT 0 +#define WLOG_MESSAGE_DATA 1 +#define WLOG_MESSAGE_IMAGE 2 +#define WLOG_MESSAGE_PACKET 3 -#define WLOG_MESSAGE_TEXT 0 -#define WLOG_MESSAGE_DATA 1 -#define WLOG_MESSAGE_IMAGE 2 -#define WLOG_MESSAGE_PACKET 3 +/** + * Log Appenders + */ +#define WLOG_APPENDER_CONSOLE 0 +#define WLOG_APPENDER_FILE 1 +#define WLOG_APPENDER_BINARY 2 +#define WLOG_APPENDER_CALLBACK 3 +#define WLOG_APPENDER_SYSLOG 4 +#define WLOG_APPENDER_JOURNALD 5 +#define WLOG_APPENDER_UDP 6 struct _wLogMessage { @@ -94,169 +95,13 @@ struct _wLogMessage int PacketLength; DWORD PacketFlags; }; +typedef struct _wLogMessage wLogMessage; +typedef struct _wLogLayout wLogLayout; +typedef struct _wLogAppender wLogAppender; +typedef struct _wLog wLog; -/** - * Log Layout - */ - -struct _wLogLayout -{ - DWORD Type; - - LPSTR FormatString; -}; - -/** - * Log Appenders - */ - -#define WLOG_APPENDER_CONSOLE 0 -#define WLOG_APPENDER_FILE 1 -#define WLOG_APPENDER_BINARY 2 -#define WLOG_APPENDER_CALLBACK 3 -#define WLOG_APPENDER_SYSLOG 4 -#define WLOG_APPENDER_JOURNALD 5 -#define WLOG_APPENDER_UDP 6 - -#define WLOG_PACKET_INBOUND 1 -#define WLOG_PACKET_OUTBOUND 2 - -typedef BOOL (*WLOG_APPENDER_OPEN_FN)(wLog* log, wLogAppender* appender); -typedef BOOL (*WLOG_APPENDER_CLOSE_FN)(wLog* log, wLogAppender* appender); -typedef BOOL (*WLOG_APPENDER_WRITE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); -typedef BOOL (*WLOG_APPENDER_WRITE_DATA_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); -typedef BOOL (*WLOG_APPENDER_WRITE_IMAGE_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() \ - DWORD Type; \ - DWORD State; \ - wLogLayout* Layout; \ - CRITICAL_SECTION lock; \ - BOOL recursive; \ - void* TextMessageContext; \ - void* DataMessageContext; \ - void* ImageMessageContext; \ - void* PacketMessageContext; \ - WLOG_APPENDER_OPEN_FN Open; \ - WLOG_APPENDER_CLOSE_FN Close; \ - WLOG_APPENDER_WRITE_MESSAGE_FN WriteMessage; \ - WLOG_APPENDER_WRITE_DATA_MESSAGE_FN WriteDataMessage; \ - WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN WriteImageMessage; \ - WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN WritePacketMessage - -struct _wLogAppender -{ - WLOG_APPENDER_COMMON(); -}; - -#define WLOG_CONSOLE_DEFAULT 0 -#define WLOG_CONSOLE_STDOUT 1 -#define WLOG_CONSOLE_STDERR 2 -#define WLOG_CONSOLE_DEBUG 4 - -struct _wLogConsoleAppender -{ - WLOG_APPENDER_COMMON(); - - int outputStream; -}; -typedef struct _wLogConsoleAppender wLogConsoleAppender; - -struct _wLogFileAppender -{ - WLOG_APPENDER_COMMON(); - - char* FileName; - char* FilePath; - char* FullFileName; - FILE* FileDescriptor; -}; -typedef struct _wLogFileAppender wLogFileAppender; - -struct _wLogBinaryAppender -{ - WLOG_APPENDER_COMMON(); - - char* FileName; - char* FilePath; - char* FullFileName; - FILE* FileDescriptor; -}; -typedef struct _wLogBinaryAppender wLogBinaryAppender; - -typedef BOOL (*CallbackAppenderMessage_t)(const wLogMessage *msg); -typedef BOOL (*CallbackAppenderData_t)(const wLogMessage *msg); -typedef BOOL (*CallbackAppenderImage_t)(const wLogMessage *msg); -typedef BOOL (*CallbackAppenderPackage_t)(const wLogMessage *msg); - -struct _wLogCallbackAppender -{ - WLOG_APPENDER_COMMON(); - - CallbackAppenderMessage_t message; - CallbackAppenderData_t data; - CallbackAppenderImage_t image; - CallbackAppenderPackage_t package; -}; -typedef struct _wLogCallbackAppender wLogCallbackAppender; - -struct _wLogSyslogAppender -{ - WLOG_APPENDER_COMMON(); -}; -typedef struct _wLogSyslogAppender wLogSyslogAppender; - -struct _wLogJournaldAppender -{ - WLOG_APPENDER_COMMON(); - char *identifier; - FILE *stream; -}; -typedef struct _wLogJournaldAppender wLogJournaldAppender; - -struct _wLogUdpAppender -{ - WLOG_APPENDER_COMMON(); - char *host; - struct sockaddr targetAddr; - int targetAddrLen; - SOCKET sock; -}; -typedef struct _wLogUdpAppender wLogUdpAppender; - - -/** - * Filter - */ - -struct _wLogFilter -{ - DWORD Level; - LPSTR* Names; - DWORD NameCount; -}; -typedef struct _wLogFilter wLogFilter; - -/** - * Logger - */ - -struct _wLog -{ - LPSTR Name; - DWORD Level; - - BOOL IsRoot; - LPSTR* Names; - DWORD NameCount; - wLogAppender* Appender; - - wLog* Parent; - wLog** Children; - DWORD ChildrenCount; - DWORD ChildrenSize; -}; +#define WLOG_PACKET_INBOUND 1 +#define WLOG_PACKET_OUTBOUND 2 WINPR_API BOOL WLog_PrintMessage(wLog* log, wLogMessage* message, ...); WINPR_API BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args); @@ -345,20 +190,11 @@ WINPR_API BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args WINPR_API DWORD WLog_GetLogLevel(wLog* log); WINPR_API BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel); -WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log); WINPR_API BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType); - +WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log); WINPR_API BOOL WLog_OpenAppender(wLog* log); WINPR_API BOOL WLog_CloseAppender(wLog* log); - -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_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath); - -WINPR_API BOOL WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender, - CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg, - CallbackAppenderData_t data); +WINPR_API BOOL WLog_ConfigureAppender(wLogAppender *appender, const char *setting, void *value); WINPR_API wLogLayout* WLog_GetLogLayout(wLog* log); WINPR_API BOOL WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format); @@ -369,6 +205,19 @@ WINPR_API wLog* WLog_Get(LPCSTR name); WINPR_API BOOL WLog_Init(void); WINPR_API BOOL WLog_Uninit(void); +typedef BOOL (*wLogCallbackMessage_t)(const wLogMessage *msg); +typedef BOOL (*wLogCallbackData_t)(const wLogMessage *msg); +typedef BOOL (*wLogCallbackImage_t)(const wLogMessage *msg); +typedef BOOL (*wLogCallbackPackage_t)(const wLogMessage *msg); + +struct _wLogCallbacks { + wLogCallbackData_t data; + wLogCallbackImage_t image; + wLogCallbackMessage_t message; + wLogCallbackPackage_t package; +}; +typedef struct _wLogCallbacks wLogCallbacks; + #ifdef __cplusplus } #endif diff --git a/winpr/libwinpr/file/test/TestFileGetStdHandle.c b/winpr/libwinpr/file/test/TestFileGetStdHandle.c index 07d00f8c3..225434f29 100644 --- a/winpr/libwinpr/file/test/TestFileGetStdHandle.c +++ b/winpr/libwinpr/file/test/TestFileGetStdHandle.c @@ -20,6 +20,7 @@ */ #include +#include #include #include @@ -44,4 +45,4 @@ int TestFileGetStdHandle(int argc, char* argv[]) CloseHandle(stdout); return 0; -} \ No newline at end of file +} diff --git a/winpr/libwinpr/smartcard/smartcard_inspect.c b/winpr/libwinpr/smartcard/smartcard_inspect.c index c36fc87e5..9b872f11c 100644 --- a/winpr/libwinpr/smartcard/smartcard_inspect.c +++ b/winpr/libwinpr/smartcard/smartcard_inspect.c @@ -1269,7 +1269,7 @@ SCardApiFunctionTable Inspect_SCardApiFunctionTable = void Inspect_InitLog() { wLogLayout* layout; - wLogFileAppender* appender; + wLogAppender* appender; const char* filepath = SMARTCARD_INSPECT_FILEPATH; if (g_Log) @@ -1284,10 +1284,12 @@ void Inspect_InitLog() WLog_SetLogLevel(g_Log, WLOG_DEBUG); WLog_SetLogAppenderType(g_Log, WLOG_APPENDER_FILE); - appender = (wLogFileAppender*) WLog_GetLogAppender(g_Log); + appender = WLog_GetLogAppender(g_Log); + if (!appender) + return; - WLog_FileAppender_SetOutputFileName(g_Log, appender, "WinSCard.txt"); - WLog_FileAppender_SetOutputFilePath(g_Log, appender, filepath); + WLog_ConfigureAppender(appender, "outputfilename", "WinSCard.txt"); + WLog_ConfigureAppender(appender, "outputfilepath", (void *)filepath); layout = WLog_GetLogLayout(g_Log); WLog_Layout_SetPrefixFormat(g_Log, layout, "[%mn] "); diff --git a/winpr/libwinpr/sspi/NTLM/ntlm.c b/winpr/libwinpr/sspi/NTLM/ntlm.c index a210e45cc..9b732a8e2 100644 --- a/winpr/libwinpr/sspi/NTLM/ntlm.c +++ b/winpr/libwinpr/sspi/NTLM/ntlm.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "ntlm.h" #include "../sspi.h" diff --git a/winpr/libwinpr/thread/argv.c b/winpr/libwinpr/thread/argv.c index ad96da236..6ca2ab527 100644 --- a/winpr/libwinpr/thread/argv.c +++ b/winpr/libwinpr/thread/argv.c @@ -91,7 +91,6 @@ LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs) { char* p; - int index; int length; char* pBeg; char* pEnd; diff --git a/winpr/libwinpr/utils/CMakeLists.txt b/winpr/libwinpr/utils/CMakeLists.txt index 2a8411966..e305d0627 100644 --- a/winpr/libwinpr/utils/CMakeLists.txt +++ b/winpr/libwinpr/utils/CMakeLists.txt @@ -77,7 +77,6 @@ set(${MODULE_PREFIX}_WLOG_SRCS wlog/Message.c wlog/Message.h wlog/TextMessage.c - wlog/TextMessage.h wlog/DataMessage.c wlog/DataMessage.h wlog/ImageMessage.c diff --git a/winpr/libwinpr/utils/sam.c b/winpr/libwinpr/utils/sam.c index 08c5b1441..d097c0a26 100644 --- a/winpr/libwinpr/utils/sam.c +++ b/winpr/libwinpr/utils/sam.c @@ -70,7 +70,7 @@ WINPR_SAM* SamOpen(BOOL read_only) sam->fp = fp; } else - WLog_ERR(TAG, "Could not open SAM file!"); + WLog_DBG(TAG, "Could not open SAM file!"); return sam; } diff --git a/winpr/libwinpr/utils/test/TestWLog.c b/winpr/libwinpr/utils/test/TestWLog.c index 34008003d..74e1c15a7 100644 --- a/winpr/libwinpr/utils/test/TestWLog.c +++ b/winpr/libwinpr/utils/test/TestWLog.c @@ -19,7 +19,10 @@ int TestWLog(int argc, char* argv[]) WLog_SetLogAppenderType(root, WLOG_APPENDER_BINARY); appender = WLog_GetLogAppender(root); - WLog_ConsoleAppender_SetOutputStream(root, (wLogConsoleAppender*) appender, WLOG_CONSOLE_STDERR); + if(!WLog_ConfigureAppender(appender, "outputfilename", "test_w.log")) + return 1; + if(!WLog_ConfigureAppender(appender, "outputfilepath", "/tmp/")) + return 1; layout = WLog_GetLogLayout(root); WLog_Layout_SetPrefixFormat(root, layout, "[%lv:%mn] [%fl|%fn|%ln] - "); diff --git a/winpr/libwinpr/utils/test/TestWLogCallback.c b/winpr/libwinpr/utils/test/TestWLogCallback.c index 8cccbe52a..25330057b 100644 --- a/winpr/libwinpr/utils/test/TestWLogCallback.c +++ b/winpr/libwinpr/utils/test/TestWLogCallback.c @@ -90,6 +90,7 @@ int TestWLogCallback(int argc, char* argv[]) wLog* logB; wLogLayout* layout; wLogAppender* appender; + wLogCallbacks callbacks; function = __FUNCTION__; WLog_Init(); @@ -100,9 +101,13 @@ int TestWLogCallback(int argc, char* argv[]) appender = WLog_GetLogAppender(root); - WLog_CallbackAppender_SetCallbacks(root, (wLogCallbackAppender*) appender, - CallbackAppenderMessage, CallbackAppenderImage, CallbackAppenderPackage, - CallbackAppenderData); + callbacks.data = CallbackAppenderData; + callbacks.image = CallbackAppenderImage; + callbacks.message = CallbackAppenderMessage; + callbacks.package = CallbackAppenderPackage; + + if (!WLog_ConfigureAppender(appender, "callbacks", (void *)&callbacks)) + return -1; layout = WLog_GetLogLayout(root); WLog_Layout_SetPrefixFormat(root, layout, "%mn"); diff --git a/winpr/libwinpr/utils/wlog/Appender.c b/winpr/libwinpr/utils/wlog/Appender.c index a9c4d566f..461023fea 100644 --- a/winpr/libwinpr/utils/wlog/Appender.c +++ b/winpr/libwinpr/utils/wlog/Appender.c @@ -21,11 +21,77 @@ #include "config.h" #endif -#include +#include "Appender.h" -#include "wlog/Layout.h" +void WLog_Appender_Free(wLog* log, wLogAppender* appender) +{ + if (!appender) + return; -#include "wlog/Appender.h" + if (appender->Layout) + { + WLog_Layout_Free(log, appender->Layout); + appender->Layout = NULL; + } + + DeleteCriticalSection(&appender->lock); + appender->Free(appender); +} + +wLogAppender* WLog_GetLogAppender(wLog* log) +{ + if (!log) + return NULL; + + if (!log->Appender) + return WLog_GetLogAppender(log->Parent); + + return log->Appender; +} + +BOOL WLog_OpenAppender(wLog* log) +{ + int status = 0; + wLogAppender* appender; + + appender = WLog_GetLogAppender(log); + + if (!appender) + return FALSE; + + if (!appender->Open) + return TRUE; + + if (!appender->active) + { + status = appender->Open(log, appender); + appender->active = TRUE; + } + + return status; +} + +BOOL WLog_CloseAppender(wLog* log) +{ + int status = 0; + wLogAppender* appender; + + appender = WLog_GetLogAppender(log); + + if (!appender) + return FALSE; + + if (!appender->Close) + return TRUE; + + if (appender->active) + { + status = appender->Close(log, appender); + appender->active = FALSE; + } + + return status; +} wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType) { @@ -37,25 +103,25 @@ wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType) switch (logAppenderType) { case WLOG_APPENDER_CONSOLE: - appender = (wLogAppender*) WLog_ConsoleAppender_New(log); + appender = WLog_ConsoleAppender_New(log); break; case WLOG_APPENDER_FILE: - appender = (wLogAppender*) WLog_FileAppender_New(log); + appender = WLog_FileAppender_New(log); break; case WLOG_APPENDER_BINARY: - appender = (wLogAppender*) WLog_BinaryAppender_New(log); + appender = WLog_BinaryAppender_New(log); break; case WLOG_APPENDER_CALLBACK: - appender = (wLogAppender*) WLog_CallbackAppender_New(log); + appender = WLog_CallbackAppender_New(log); break; #ifdef HAVE_SYSLOG_H case WLOG_APPENDER_SYSLOG: - appender = (wLogAppender*) WLog_SyslogAppender_New(log); + appender = WLog_SyslogAppender_New(log); break; #endif #ifdef HAVE_JOURNALD_H case WLOG_APPENDER_JOURNALD: - appender = (wLogAppender*) WLog_JournaldAppender_New(log); + appender = WLog_JournaldAppender_New(log); break; #endif case WLOG_APPENDER_UDP: @@ -84,65 +150,11 @@ wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType) return appender; } -void WLog_Appender_Free(wLog* log, wLogAppender* appender) -{ - if (!appender) - return; - - if (appender->Layout) - { - WLog_Layout_Free(log, appender->Layout); - appender->Layout = NULL; - } - - DeleteCriticalSection(&appender->lock); - - switch (appender->Type) - { - case WLOG_APPENDER_CONSOLE: - WLog_ConsoleAppender_Free(log, (wLogConsoleAppender*) appender); - break; - case WLOG_APPENDER_FILE: - WLog_FileAppender_Free(log, (wLogFileAppender*) appender); - break; - case WLOG_APPENDER_BINARY: - WLog_BinaryAppender_Free(log, (wLogBinaryAppender*) appender); - break; - case WLOG_APPENDER_CALLBACK: - WLog_CallbackAppender_Free(log, (wLogCallbackAppender*) appender); - break; -#ifdef HAVE_SYSLOG_H - case WLOG_APPENDER_SYSLOG: - WLog_SyslogAppender_Free(log, (wLogSyslogAppender *) appender); - break; -#endif -#ifdef HAVE_JOURNALD_H - case WLOG_APPENDER_JOURNALD: - WLog_JournaldAppender_Free(log, (wLogJournaldAppender *) appender); - break; -#endif - case WLOG_APPENDER_UDP: - WLog_UdpAppender_Free(log, (wLogUdpAppender *) appender); - break; - default: - fprintf(stderr, "%s: don't know how to free appender type %d\n", __FUNCTION__, appender->Type); - break; - } -} - -wLogAppender* WLog_GetLogAppender(wLog* log) -{ - if (!log) - return NULL; - - if (!log->Appender) - return WLog_GetLogAppender(log->Parent); - - return log->Appender; -} - BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType) { + if (!log) + return FALSE; + if (log->Appender) { WLog_Appender_Free(log, log->Appender); @@ -153,46 +165,14 @@ BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType) return log->Appender != NULL; } -BOOL WLog_OpenAppender(wLog* log) +BOOL WLog_ConfigureAppender(wLogAppender *appender, const char *setting, void *value) { - int status = 0; - wLogAppender* appender; - - appender = WLog_GetLogAppender(log); - - if (!appender) + if (!appender || !setting || !strlen(setting)) return FALSE; - if (!appender->Open) - return TRUE; - - if (!appender->State) - { - status = appender->Open(log, appender); - appender->State = 1; - } - - return status; -} - -BOOL WLog_CloseAppender(wLog* log) -{ - int status = 0; - wLogAppender* appender; - - appender = WLog_GetLogAppender(log); - - if (!appender) + if (appender->Set) + return appender->Set(appender, setting, value); + else return FALSE; - if (!appender->Close) - return TRUE; - - if (appender->State) - { - status = appender->Close(log, appender); - appender->State = 0; - } - - return status; } diff --git a/winpr/libwinpr/utils/wlog/Appender.h b/winpr/libwinpr/utils/wlog/Appender.h index 6b9b8ee21..45aac3601 100644 --- a/winpr/libwinpr/utils/wlog/Appender.h +++ b/winpr/libwinpr/utils/wlog/Appender.h @@ -20,25 +20,21 @@ #ifndef WINPR_WLOG_APPENDER_PRIVATE_H #define WINPR_WLOG_APPENDER_PRIVATE_H -#include - -#include "wlog/FileAppender.h" -#include "wlog/BinaryAppender.h" -#include "wlog/ConsoleAppender.h" -#include "wlog/CallbackAppender.h" -#include "wlog/UdpAppender.h" - -#ifdef HAVE_SYSLOG_H -#include "wlog/SyslogAppender.h" -#endif +#include "wlog.h" +#include "FileAppender.h" +#include "ConsoleAppender.h" +#include "BinaryAppender.h" +#include "CallbackAppender.h" #ifdef HAVE_JOURNALD_H -#include "wlog/JournaldAppender.h" +#include "JournaldAppender.h" #endif +#ifdef HAVE_SYSLOG_H +#include "SyslogAppender.h" +#endif +#include "UdpAppender.h" void WLog_Appender_Free(wLog* log, wLogAppender* appender); -#include "wlog/wlog.h" - #endif /* WINPR_WLOG_APPENDER_PRIVATE_H */ diff --git a/winpr/libwinpr/utils/wlog/BinaryAppender.c b/winpr/libwinpr/utils/wlog/BinaryAppender.c index 0e9241e4d..74d998bbc 100644 --- a/winpr/libwinpr/utils/wlog/BinaryAppender.c +++ b/winpr/libwinpr/utils/wlog/BinaryAppender.c @@ -23,107 +23,87 @@ #include "config.h" #endif -#include - +#include "BinaryAppender.h" #include #include #include -#include #include -#include -#include "wlog/Message.h" - -#include "wlog/BinaryAppender.h" - -/** - * Binary Appender - */ - -BOOL WLog_BinaryAppender_SetOutputFileName(wLog* log, wLogBinaryAppender* appender, const char* filename) +struct _wLogBinaryAppender { - if (!appender || !filename) - return FALSE; + WLOG_APPENDER_COMMON(); - if (appender->Type != WLOG_APPENDER_BINARY) - return FALSE; + char* FileName; + char* FilePath; + char* FullFileName; + FILE* FileDescriptor; +}; +typedef struct _wLogBinaryAppender wLogBinaryAppender; - appender->FileName = _strdup(filename); - if (!appender->FileName) - return FALSE; - return TRUE; -} - -BOOL WLog_BinaryAppender_SetOutputFilePath(wLog* log, wLogBinaryAppender* appender, const char* filepath) -{ - if (!appender || !filepath) - return FALSE; - - if (appender->Type != WLOG_APPENDER_BINARY) - return FALSE; - - appender->FilePath = _strdup(filepath); - if (!appender->FilePath) - return FALSE; - return TRUE; -} - -BOOL WLog_BinaryAppender_Open(wLog* log, wLogBinaryAppender* appender) +static BOOL WLog_BinaryAppender_Open(wLog* log, wLogAppender* appender) { + wLogBinaryAppender* binaryAppender; if (!log || !appender) return FALSE; - if (!appender->FileName) + binaryAppender = (wLogBinaryAppender *)appender; + if (!binaryAppender->FileName) { - appender->FileName = (char*) malloc(MAX_PATH); - if (!appender->FileName) + binaryAppender->FileName = (char*) malloc(MAX_PATH); + if (!binaryAppender->FileName) return FALSE; - sprintf_s(appender->FileName, MAX_PATH, "%u.wlog", (unsigned int) GetCurrentProcessId()); + sprintf_s(binaryAppender->FileName, MAX_PATH, "%u.wlog", (unsigned int) GetCurrentProcessId()); } - if (!appender->FilePath) + if (!binaryAppender->FilePath) { - appender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog"); - if (!appender->FilePath) + binaryAppender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog"); + if (!binaryAppender->FilePath) return FALSE; } - if (!appender->FullFileName) + if (!binaryAppender->FullFileName) { - appender->FullFileName = GetCombinedPath(appender->FilePath, appender->FileName); - if (!appender->FullFileName) + binaryAppender->FullFileName = GetCombinedPath(binaryAppender->FilePath, binaryAppender->FileName); + if (!binaryAppender->FullFileName) return FALSE; } - if (!PathFileExistsA(appender->FilePath)) + if (!PathFileExistsA(binaryAppender->FilePath)) { - if (!PathMakePathA(appender->FilePath, 0)) + if (!PathMakePathA(binaryAppender->FilePath, 0)) return FALSE; - UnixChangeFileMode(appender->FilePath, 0xFFFF); + UnixChangeFileMode(binaryAppender->FilePath, 0xFFFF); } - appender->FileDescriptor = fopen(appender->FullFileName, "a+"); + binaryAppender->FileDescriptor = fopen(binaryAppender->FullFileName, "a+"); - if (!appender->FileDescriptor) + if (!binaryAppender->FileDescriptor) return FALSE; return TRUE; } -BOOL WLog_BinaryAppender_Close(wLog* log, wLogBinaryAppender* appender) +static BOOL WLog_BinaryAppender_Close(wLog* log, wLogAppender* appender) { - if (!appender->FileDescriptor) + wLogBinaryAppender* binaryAppender; + + if (!appender) + return FALSE; + + binaryAppender = (wLogBinaryAppender *)appender; + if (!binaryAppender->FileDescriptor) return TRUE; - fclose(appender->FileDescriptor); + fclose(binaryAppender->FileDescriptor); - appender->FileDescriptor = NULL; + binaryAppender->FileDescriptor = NULL; return TRUE; } -BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message) +static BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { FILE* fp; wStream* s; @@ -132,11 +112,14 @@ BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, w int FunctionNameLength; int TextStringLength; BOOL ret = TRUE; + wLogBinaryAppender* binaryAppender; if (!log || !appender || !message) return FALSE; - fp = appender->FileDescriptor; + binaryAppender = (wLogBinaryAppender *)appender; + + fp = binaryAppender->FileDescriptor; if (!fp) return FALSE; @@ -180,17 +163,55 @@ BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, w return ret; } -BOOL WLog_BinaryAppender_WriteDataMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message) +static BOOL WLog_BinaryAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { return TRUE; } -BOOL WLog_BinaryAppender_WriteImageMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message) +static BOOL WLog_BinaryAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { return TRUE; } -wLogBinaryAppender* WLog_BinaryAppender_New(wLog* log) +static BOOL WLog_BinaryAppender_Set(wLogAppender* appender, const char *setting, void *value) +{ + wLogBinaryAppender *binaryAppender = (wLogBinaryAppender *) appender; + + if (!value || !strlen(value)) + return FALSE; + + if (!strcmp("outputfilename", setting)) + { + binaryAppender->FileName = _strdup((const char *)value); + if (!binaryAppender->FileName) + return FALSE; + } + else if (!strcmp("outputfilepath", setting)) + { + binaryAppender->FilePath = _strdup((const char *)value); + if (!binaryAppender->FilePath) + return FALSE; + } + else + return FALSE; + + return TRUE; +} + +static void WLog_BinaryAppender_Free(wLogAppender* appender) +{ + wLogBinaryAppender *binaryAppender; + if (appender) + { + binaryAppender = (wLogBinaryAppender *)appender; + free(binaryAppender->FileName); + free(binaryAppender->FilePath); + free(binaryAppender->FullFileName); + free(binaryAppender); + } +} + +wLogAppender* WLog_BinaryAppender_New(wLog* log) { wLogBinaryAppender* BinaryAppender; @@ -199,25 +220,13 @@ wLogBinaryAppender* WLog_BinaryAppender_New(wLog* log) return NULL; BinaryAppender->Type = WLOG_APPENDER_BINARY; - BinaryAppender->Open = (WLOG_APPENDER_OPEN_FN) WLog_BinaryAppender_Open; - BinaryAppender->Close = (WLOG_APPENDER_OPEN_FN) WLog_BinaryAppender_Close; - BinaryAppender->WriteMessage = - (WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_BinaryAppender_WriteMessage; - BinaryAppender->WriteDataMessage = - (WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_BinaryAppender_WriteDataMessage; - BinaryAppender->WriteImageMessage = - (WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_BinaryAppender_WriteImageMessage; + BinaryAppender->Open = WLog_BinaryAppender_Open; + BinaryAppender->Close = WLog_BinaryAppender_Close; + BinaryAppender->WriteMessage = WLog_BinaryAppender_WriteMessage; + BinaryAppender->WriteDataMessage = WLog_BinaryAppender_WriteDataMessage; + BinaryAppender->WriteImageMessage = WLog_BinaryAppender_WriteImageMessage; + BinaryAppender->Free = WLog_BinaryAppender_Free; + BinaryAppender->Set = WLog_BinaryAppender_Set; - return BinaryAppender; -} - -void WLog_BinaryAppender_Free(wLog* log, wLogBinaryAppender* appender) -{ - if (appender) - { - free(appender->FileName); - free(appender->FilePath); - free(appender->FullFileName); - free(appender); - } + return (wLogAppender *)BinaryAppender; } diff --git a/winpr/libwinpr/utils/wlog/BinaryAppender.h b/winpr/libwinpr/utils/wlog/BinaryAppender.h index 09bdf47a7..22f1075df 100644 --- a/winpr/libwinpr/utils/wlog/BinaryAppender.h +++ b/winpr/libwinpr/utils/wlog/BinaryAppender.h @@ -20,11 +20,8 @@ #ifndef WINPR_WLOG_BINARY_APPENDER_PRIVATE_H #define WINPR_WLOG_BINARY_APPENDER_PRIVATE_H -#include +#include "wlog.h" -#include "wlog/wlog.h" - -WINPR_API wLogBinaryAppender* WLog_BinaryAppender_New(wLog* log); -WINPR_API void WLog_BinaryAppender_Free(wLog* log, wLogBinaryAppender* appender); +WINPR_API wLogAppender* WLog_BinaryAppender_New(wLog* log); #endif /* WINPR_WLOG_BINARY_APPENDER_PRIVATE_H */ diff --git a/winpr/libwinpr/utils/wlog/CallbackAppender.c b/winpr/libwinpr/utils/wlog/CallbackAppender.c index 593496b0f..8a1719ff4 100644 --- a/winpr/libwinpr/utils/wlog/CallbackAppender.c +++ b/winpr/libwinpr/utils/wlog/CallbackAppender.c @@ -21,100 +21,114 @@ #include "config.h" #endif -#include -#include +#include "CallbackAppender.h" -#include -#include "wlog/Message.h" - -#include "wlog/CallbackAppender.h" - -/** - * Callback Appender - */ - -WINPR_API BOOL WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender, - CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg, - CallbackAppenderData_t data) +struct _wLogCallbackAppender { - if (!appender) - return FALSE; + WLOG_APPENDER_COMMON(); - if (appender->Type != WLOG_APPENDER_CALLBACK) - return FALSE; + wLogCallbacks *callbacks; +}; +typedef struct _wLogCallbackAppender wLogCallbackAppender; - appender->message = msg; - appender->image = img; - appender->package = pkg; - appender->data = data; - return TRUE; -} - -BOOL WLog_CallbackAppender_Open(wLog* log, wLogCallbackAppender* appender) +static BOOL WLog_CallbackAppender_Open(wLog* log, wLogAppender* appender) { return TRUE; } -BOOL WLog_CallbackAppender_Close(wLog* log, wLogCallbackAppender* appender) +static BOOL WLog_CallbackAppender_Close(wLog* log, wLogAppender* appender) { return TRUE; } -BOOL WLog_CallbackAppender_WriteMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) +static BOOL WLog_CallbackAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { char prefix[WLOG_MAX_PREFIX_SIZE]; + wLogCallbackAppender* callbackAppender; + if (!appender) + return FALSE; message->PrefixString = prefix; WLog_Layout_GetMessagePrefix(log, appender->Layout, message); - if (appender->message) - { - return appender->message(message); - } + callbackAppender = (wLogCallbackAppender *)appender; + + if (callbackAppender->callbacks && callbackAppender->callbacks->message) + return callbackAppender->callbacks->message(message); else - { return FALSE; - } } -BOOL WLog_CallbackAppender_WriteDataMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) +static BOOL WLog_CallbackAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { - if (appender->data) - { - return appender->data(message); - } - else - { + + wLogCallbackAppender* callbackAppender; + if (!appender) + return FALSE; + + callbackAppender = (wLogCallbackAppender *)appender; + if (callbackAppender->callbacks && callbackAppender->callbacks->data) + return callbackAppender->callbacks->data(message); + else return FALSE; - } } -BOOL WLog_CallbackAppender_WriteImageMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) +static BOOL WLog_CallbackAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { - if (appender->image) - { - return appender->image(message); - } - else - { + wLogCallbackAppender* callbackAppender; + if (!appender) + return FALSE; + + callbackAppender = (wLogCallbackAppender *)appender; + if (callbackAppender->callbacks && callbackAppender->callbacks->image) + return callbackAppender->callbacks->image(message); + else return FALSE; - } } -BOOL WLog_CallbackAppender_WritePacketMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) +static BOOL WLog_CallbackAppender_WritePacketMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { - if (appender->package) - { - return appender->package(message); - } - else - { + wLogCallbackAppender* callbackAppender; + if (!appender) + return FALSE; + + callbackAppender = (wLogCallbackAppender *)appender; + if (callbackAppender->callbacks && callbackAppender->callbacks->package) + return callbackAppender->callbacks->package(message); + else return FALSE; - } } -wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log) +static BOOL WLog_CallbackAppender_Set(wLogAppender* appender, const char *setting, void *value) +{ + wLogCallbackAppender *callbackAppender = (wLogCallbackAppender *)appender; + + if (!value || strcmp(setting, "callbacks")) + return FALSE; + + if (!(callbackAppender->callbacks = calloc(1, sizeof(wLogCallbacks)))) { + return FALSE; + } + + callbackAppender->callbacks = memcpy(callbackAppender->callbacks, value, sizeof(wLogCallbacks)); + return TRUE; +} + +static void WLog_CallbackAppender_Free(wLogAppender* appender) +{ + wLogCallbackAppender *callbackAppender; + if (!appender) { + return; + } + + callbackAppender = (wLogCallbackAppender *)appender; + + free(callbackAppender->callbacks); + free(appender); +} + +wLogAppender* WLog_CallbackAppender_New(wLog* log) { wLogCallbackAppender* CallbackAppender; @@ -124,21 +138,14 @@ wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log) CallbackAppender->Type = WLOG_APPENDER_CALLBACK; - CallbackAppender->Open = (WLOG_APPENDER_OPEN_FN) WLog_CallbackAppender_Open; - CallbackAppender->Close = (WLOG_APPENDER_OPEN_FN) WLog_CallbackAppender_Close; - CallbackAppender->WriteMessage = - (WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_CallbackAppender_WriteMessage; - CallbackAppender->WriteDataMessage = - (WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_CallbackAppender_WriteDataMessage; - CallbackAppender->WriteImageMessage = - (WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_CallbackAppender_WriteImageMessage; - CallbackAppender->WritePacketMessage = - (WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN) WLog_CallbackAppender_WritePacketMessage; + CallbackAppender->Open = WLog_CallbackAppender_Open; + CallbackAppender->Close = WLog_CallbackAppender_Close; + CallbackAppender->WriteMessage = WLog_CallbackAppender_WriteMessage; + CallbackAppender->WriteDataMessage = WLog_CallbackAppender_WriteDataMessage; + CallbackAppender->WriteImageMessage = WLog_CallbackAppender_WriteImageMessage; + CallbackAppender->WritePacketMessage = WLog_CallbackAppender_WritePacketMessage; + CallbackAppender->Free = WLog_CallbackAppender_Free; + CallbackAppender->Set = WLog_CallbackAppender_Set; - return CallbackAppender; -} - -void WLog_CallbackAppender_Free(wLog* log, wLogCallbackAppender* appender) -{ - free(appender); + return (wLogAppender *)CallbackAppender; } diff --git a/winpr/libwinpr/utils/wlog/CallbackAppender.h b/winpr/libwinpr/utils/wlog/CallbackAppender.h index a23153c44..2a7f7822c 100644 --- a/winpr/libwinpr/utils/wlog/CallbackAppender.h +++ b/winpr/libwinpr/utils/wlog/CallbackAppender.h @@ -20,11 +20,8 @@ #ifndef WINPR_WLOG_CALLBACK_APPENDER_PRIVATE_H #define WINPR_WLOG_CALLBACK_APPENDER_PRIVATE_H -#include +#include "wlog.h" -#include "wlog/wlog.h" - -WINPR_API wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log); -WINPR_API void WLog_CallbackAppender_Free(wLog* log, wLogCallbackAppender* appender); +wLogAppender* WLog_CallbackAppender_New(wLog* log); #endif /* WINPR_WLOG_CALLBACK_APPENDER_PRIVATE_H */ diff --git a/winpr/libwinpr/utils/wlog/ConsoleAppender.c b/winpr/libwinpr/utils/wlog/ConsoleAppender.c index ba5ed71c2..49cd94f81 100644 --- a/winpr/libwinpr/utils/wlog/ConsoleAppender.c +++ b/winpr/libwinpr/utils/wlog/ConsoleAppender.c @@ -21,63 +21,51 @@ #include "config.h" #endif -#include -#include - -#include - -#include "wlog/Message.h" - -#include "wlog/ConsoleAppender.h" +#include "ConsoleAppender.h" +#include "Message.h" #ifdef ANDROID #include #endif -/** - * Console Appender - */ +#define WLOG_CONSOLE_DEFAULT 0 +#define WLOG_CONSOLE_STDOUT 1 +#define WLOG_CONSOLE_STDERR 2 +#define WLOG_CONSOLE_DEBUG 4 -BOOL WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream) +struct _wLogConsoleAppender { - if (!appender) - return FALSE; + WLOG_APPENDER_COMMON(); - if (appender->Type != WLOG_APPENDER_CONSOLE) - return FALSE; + int outputStream; +}; +typedef struct _wLogConsoleAppender wLogConsoleAppender; - if (outputStream < 0) - outputStream = WLOG_CONSOLE_DEFAULT; - - if (outputStream == WLOG_CONSOLE_STDOUT) - appender->outputStream = WLOG_CONSOLE_STDOUT; - else if (outputStream == WLOG_CONSOLE_STDERR) - appender->outputStream = WLOG_CONSOLE_STDERR; - else - appender->outputStream = WLOG_CONSOLE_DEFAULT; - return TRUE; -} - -BOOL WLog_ConsoleAppender_Open(wLog* log, wLogConsoleAppender* appender) +static BOOL WLog_ConsoleAppender_Open(wLog* log, wLogAppender* appender) { return TRUE; } -BOOL WLog_ConsoleAppender_Close(wLog* log, wLogConsoleAppender* appender) +static BOOL WLog_ConsoleAppender_Close(wLog* log, wLogAppender* appender) { return TRUE; } -BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) +static BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { FILE* fp; char prefix[WLOG_MAX_PREFIX_SIZE]; + if (!appender) + return FALSE; + + wLogConsoleAppender *consoleAppender = (wLogConsoleAppender *)appender; + message->PrefixString = prefix; WLog_Layout_GetMessagePrefix(log, appender->Layout, message); #ifdef _WIN32 - if (appender->outputStream == WLOG_CONSOLE_DEBUG) + if (consoleAppender->outputStream == WLOG_CONSOLE_DEBUG) { char MessageString[4096]; @@ -124,7 +112,7 @@ BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender, __android_log_print(level, log->Name, "%s%s", message->PrefixString, message->TextString); #else - switch(appender->outputStream) + switch(consoleAppender->outputStream) { case WLOG_CONSOLE_STDOUT: fp = stdout; @@ -155,7 +143,7 @@ BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender, static int g_DataId = 0; -BOOL WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) +static BOOL WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { int DataId; char* FullFileName; @@ -172,7 +160,7 @@ BOOL WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogConsoleAppender* appen static int g_ImageId = 0; -BOOL WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) +static BOOL WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { int ImageId; char* FullFileName; @@ -190,7 +178,7 @@ BOOL WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogConsoleAppender* appe static int g_PacketId = 0; -BOOL WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) +static BOOL WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { int PacketId; char* FullFileName; @@ -210,41 +198,31 @@ BOOL WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogConsoleAppender* app return TRUE; } - -wLogConsoleAppender* WLog_ConsoleAppender_New(wLog* log) +static BOOL WLog_ConsoleAppender_Set(wLogAppender* appender, const char *setting, void *value) { - wLogConsoleAppender* ConsoleAppender; + wLogConsoleAppender *consoleAppender = (wLogConsoleAppender *)appender; - ConsoleAppender = (wLogConsoleAppender*) calloc(1, sizeof(wLogConsoleAppender)); + if (!value || !strlen(value)) + return FALSE; - if (!ConsoleAppender) - return NULL; + if (strcmp("outputstream", setting)) + return FALSE; - ConsoleAppender->Type = WLOG_APPENDER_CONSOLE; + if (!strcmp("stdout", value)) + consoleAppender->outputStream = WLOG_CONSOLE_STDOUT; + else if (!strcmp("stderr", value)) + consoleAppender->outputStream = WLOG_CONSOLE_STDERR; + else if (!strcmp("default", value)) + consoleAppender->outputStream = WLOG_CONSOLE_DEFAULT; + else if (!strcmp("debug", value)) + consoleAppender->outputStream = WLOG_CONSOLE_DEBUG; + else + return FALSE; - ConsoleAppender->Open = (WLOG_APPENDER_OPEN_FN) WLog_ConsoleAppender_Open; - ConsoleAppender->Close = (WLOG_APPENDER_OPEN_FN) WLog_ConsoleAppender_Close; - - ConsoleAppender->WriteMessage = - (WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_ConsoleAppender_WriteMessage; - ConsoleAppender->WriteDataMessage = - (WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_ConsoleAppender_WriteDataMessage; - ConsoleAppender->WriteImageMessage = - (WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_ConsoleAppender_WriteImageMessage; - ConsoleAppender->WritePacketMessage = - (WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN) WLog_ConsoleAppender_WritePacketMessage; - - ConsoleAppender->outputStream = WLOG_CONSOLE_DEFAULT; - -#ifdef _WIN32 - if (IsDebuggerPresent()) - ConsoleAppender->outputStream = WLOG_CONSOLE_DEBUG; -#endif - - return ConsoleAppender; + return TRUE; } -void WLog_ConsoleAppender_Free(wLog* log, wLogConsoleAppender* appender) +static void WLog_ConsoleAppender_Free(wLogAppender* appender) { if (appender) { @@ -256,3 +234,34 @@ void WLog_ConsoleAppender_Free(wLog* log, wLogConsoleAppender* appender) free(appender); } } + +wLogAppender* WLog_ConsoleAppender_New(wLog* log) +{ + wLogConsoleAppender* ConsoleAppender; + + ConsoleAppender = (wLogConsoleAppender*) calloc(1, sizeof(wLogConsoleAppender)); + + if (!ConsoleAppender) + return NULL; + + ConsoleAppender->Type = WLOG_APPENDER_CONSOLE; + + ConsoleAppender->Open = WLog_ConsoleAppender_Open; + ConsoleAppender->Close = WLog_ConsoleAppender_Close; + ConsoleAppender->WriteMessage = WLog_ConsoleAppender_WriteMessage; + ConsoleAppender->WriteDataMessage = WLog_ConsoleAppender_WriteDataMessage; + ConsoleAppender->WriteImageMessage = WLog_ConsoleAppender_WriteImageMessage; + ConsoleAppender->WritePacketMessage = WLog_ConsoleAppender_WritePacketMessage; + ConsoleAppender->Set = WLog_ConsoleAppender_Set; + ConsoleAppender->Free = WLog_ConsoleAppender_Free; + + ConsoleAppender->outputStream = WLOG_CONSOLE_DEFAULT; + +#ifdef _WIN32 + if (IsDebuggerPresent()) + ConsoleAppender->outputStream = WLOG_CONSOLE_DEBUG; +#endif + + return (wLogAppender *)ConsoleAppender; +} + diff --git a/winpr/libwinpr/utils/wlog/ConsoleAppender.h b/winpr/libwinpr/utils/wlog/ConsoleAppender.h index e5871e847..e6ff1185c 100644 --- a/winpr/libwinpr/utils/wlog/ConsoleAppender.h +++ b/winpr/libwinpr/utils/wlog/ConsoleAppender.h @@ -20,11 +20,8 @@ #ifndef WINPR_WLOG_CONSOLE_APPENDER_PRIVATE_H #define WINPR_WLOG_CONSOLE_APPENDER_PRIVATE_H -#include +#include "wlog.h" -#include "wlog/wlog.h" - -WINPR_API wLogConsoleAppender* WLog_ConsoleAppender_New(wLog* log); -WINPR_API void WLog_ConsoleAppender_Free(wLog* log, wLogConsoleAppender* appender); +wLogAppender* WLog_ConsoleAppender_New(wLog* log); #endif /* WINPR_WLOG_CONSOLE_APPENDER_PRIVATE_H */ diff --git a/winpr/libwinpr/utils/wlog/DataMessage.c b/winpr/libwinpr/utils/wlog/DataMessage.c index f27bbdf77..ce4a1f60a 100644 --- a/winpr/libwinpr/utils/wlog/DataMessage.c +++ b/winpr/libwinpr/utils/wlog/DataMessage.c @@ -21,7 +21,7 @@ #include "config.h" #endif -#include +#include "wlog.h" #include "wlog/DataMessage.h" diff --git a/winpr/libwinpr/utils/wlog/DataMessage.h b/winpr/libwinpr/utils/wlog/DataMessage.h index 3b30ae9a7..f91a42c47 100644 --- a/winpr/libwinpr/utils/wlog/DataMessage.h +++ b/winpr/libwinpr/utils/wlog/DataMessage.h @@ -20,10 +20,6 @@ #ifndef WINPR_WLOG_DATA_MESSAGE_PRIVATE_H #define WINPR_WLOG_DATA_MESSAGE_PRIVATE_H -#include - -#include "wlog/wlog.h" - BOOL WLog_DataMessage_Write(char* filename, void* data, int length); #endif /* WINPR_WLOG_DATA_MESSAGE_PRIVATE_H */ diff --git a/winpr/libwinpr/utils/wlog/FileAppender.c b/winpr/libwinpr/utils/wlog/FileAppender.c index ad5a3aec4..576841611 100644 --- a/winpr/libwinpr/utils/wlog/FileAppender.c +++ b/winpr/libwinpr/utils/wlog/FileAppender.c @@ -21,30 +21,28 @@ #include "config.h" #endif +#include "FileAppender.h" +#include "Message.h" + #include #include #include #include -#include -#include - -#include "wlog/Message.h" - -#include "wlog/FileAppender.h" - -/** - * File Appender - */ - -BOOL WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename) +struct _wLogFileAppender { - if (!appender || !filename) - return FALSE; + WLOG_APPENDER_COMMON(); - if (appender->Type != WLOG_APPENDER_FILE) - return FALSE; + char* FileName; + char* FilePath; + char* FullFileName; + FILE* FileDescriptor; +}; +typedef struct _wLogFileAppender wLogFileAppender; + +static BOOL WLog_FileAppender_SetOutputFileName(wLogFileAppender* appender, const char* filename) +{ appender->FileName = _strdup(filename); if (!appender->FileName) return FALSE; @@ -52,14 +50,8 @@ BOOL WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, return TRUE; } -BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath) +static BOOL WLog_FileAppender_SetOutputFilePath(wLogFileAppender* appender, const char* filepath) { - if (!appender || !filepath) - return FALSE; - - if (appender->Type != WLOG_APPENDER_FILE) - return FALSE; - appender->FilePath = _strdup(filepath); if (!appender->FilePath) return FALSE; @@ -67,73 +59,83 @@ BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, return TRUE; } -BOOL WLog_FileAppender_Open(wLog* log, wLogFileAppender* appender) +static BOOL WLog_FileAppender_Open(wLog* log, wLogAppender* appender) { + wLogFileAppender *fileAppender; + if (!log || !appender) return FALSE; - if (!appender->FilePath) + fileAppender = (wLogFileAppender *)appender; + + if (!fileAppender->FilePath) { - appender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog"); - if (!appender->FilePath) + fileAppender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog"); + if (!fileAppender->FilePath) return FALSE; } - if (!appender->FileName) + if (!fileAppender->FileName) { - appender->FileName = (char*) malloc(MAX_PATH); - if (!appender->FileName) + fileAppender->FileName = (char*) malloc(MAX_PATH); + if (!fileAppender->FileName) return FALSE; - sprintf_s(appender->FileName, MAX_PATH, "%u.log", (unsigned int) GetCurrentProcessId()); + sprintf_s(fileAppender->FileName, MAX_PATH, "%u.log", (unsigned int) GetCurrentProcessId()); } - if (!appender->FullFileName) + if (!fileAppender->FullFileName) { - appender->FullFileName = GetCombinedPath(appender->FilePath, appender->FileName); - if (!appender->FullFileName) + fileAppender->FullFileName = GetCombinedPath(fileAppender->FilePath, fileAppender->FileName); + if (!fileAppender->FullFileName) return FALSE; } - if (!PathFileExistsA(appender->FilePath)) + if (!PathFileExistsA(fileAppender->FilePath)) { - if (!PathMakePathA(appender->FilePath, 0)) + if (!PathMakePathA(fileAppender->FilePath, 0)) return FALSE; - UnixChangeFileMode(appender->FilePath, 0xFFFF); + UnixChangeFileMode(fileAppender->FilePath, 0xFFFF); } - appender->FileDescriptor = fopen(appender->FullFileName, "a+"); + fileAppender->FileDescriptor = fopen(fileAppender->FullFileName, "a+"); - if (!appender->FileDescriptor) + if (!fileAppender->FileDescriptor) return FALSE; return TRUE; } -BOOL WLog_FileAppender_Close(wLog* log, wLogFileAppender* appender) +static BOOL WLog_FileAppender_Close(wLog* log, wLogAppender* appender) { + wLogFileAppender *fileAppender; if (!log || !appender) return FALSE; - if (!appender->FileDescriptor) + fileAppender = (wLogFileAppender *)appender; + + if (!fileAppender->FileDescriptor) return TRUE; - fclose(appender->FileDescriptor); + fclose(fileAppender->FileDescriptor); - appender->FileDescriptor = NULL; + fileAppender->FileDescriptor = NULL; return TRUE; } -BOOL WLog_FileAppender_WriteMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message) +static BOOL WLog_FileAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { FILE* fp; char prefix[WLOG_MAX_PREFIX_SIZE]; + wLogFileAppender *fileAppender; if (!log || !appender || !message) return FALSE; - fp = appender->FileDescriptor; + fileAppender = (wLogFileAppender *)appender; + + fp = fileAppender->FileDescriptor; if (!fp) return FALSE; @@ -150,7 +152,7 @@ BOOL WLog_FileAppender_WriteMessage(wLog* log, wLogFileAppender* appender, wLogM static int g_DataId = 0; -BOOL WLog_FileAppender_WriteDataMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message) +static BOOL WLog_FileAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { int DataId; char* FullFileName; @@ -170,7 +172,7 @@ BOOL WLog_FileAppender_WriteDataMessage(wLog* log, wLogFileAppender* appender, w static int g_ImageId = 0; -int WLog_FileAppender_WriteImageMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message) +static int WLog_FileAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { int ImageId; char* FullFileName; @@ -189,7 +191,38 @@ int WLog_FileAppender_WriteImageMessage(wLog* log, wLogFileAppender* appender, w return TRUE; } -wLogFileAppender* WLog_FileAppender_New(wLog* log) +static BOOL WLog_FileAppender_Set(wLogAppender* appender, const char *setting, void *value) +{ + wLogFileAppender *fileAppender = (wLogFileAppender *) appender; + + if (!value || !strlen(value)) + return FALSE; + + if (!strcmp("outputfilename", setting)) + return WLog_FileAppender_SetOutputFileName(fileAppender, (const char *)value); + else if (!strcmp("outputfilepath", setting)) + return WLog_FileAppender_SetOutputFilePath(fileAppender, (const char *)value); + else + return FALSE; + + return TRUE; +} + +static void WLog_FileAppender_Free(wLogAppender* appender) +{ + wLogFileAppender* fileAppender = NULL; + + if (appender) + { + fileAppender = (wLogFileAppender *)appender; + free(fileAppender->FileName); + free(fileAppender->FilePath); + free(fileAppender->FullFileName); + free(fileAppender); + } +} + +wLogAppender* WLog_FileAppender_New(wLog* log) { LPSTR env; LPCSTR name; @@ -203,14 +236,13 @@ wLogFileAppender* WLog_FileAppender_New(wLog* log) FileAppender->Type = WLOG_APPENDER_FILE; - FileAppender->Open = (WLOG_APPENDER_OPEN_FN) WLog_FileAppender_Open; - FileAppender->Close = (WLOG_APPENDER_OPEN_FN) WLog_FileAppender_Close; - FileAppender->WriteMessage = - (WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_FileAppender_WriteMessage; - FileAppender->WriteDataMessage = - (WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_FileAppender_WriteDataMessage; - FileAppender->WriteImageMessage = - (WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_FileAppender_WriteImageMessage; + FileAppender->Open = WLog_FileAppender_Open; + FileAppender->Close = WLog_FileAppender_Close; + FileAppender->WriteMessage = WLog_FileAppender_WriteMessage; + FileAppender->WriteDataMessage = WLog_FileAppender_WriteDataMessage; + FileAppender->WriteImageMessage = WLog_FileAppender_WriteImageMessage; + FileAppender->Free = WLog_FileAppender_Free; + FileAppender->Set = WLog_FileAppender_Set; name = "WLOG_FILEAPPENDER_OUTPUT_FILE_PATH"; nSize = GetEnvironmentVariableA(name, NULL, 0); @@ -221,7 +253,7 @@ wLogFileAppender* WLog_FileAppender_New(wLog* log) goto error_free; nSize = GetEnvironmentVariableA(name, env, nSize); - status = WLog_FileAppender_SetOutputFilePath(log, FileAppender, env); + status = WLog_FileAppender_SetOutputFilePath(FileAppender, env); free(env); if (!status) @@ -236,15 +268,15 @@ wLogFileAppender* WLog_FileAppender_New(wLog* log) if (!env) goto error_output_file_name; - nSize = GetEnvironmentVariableA(name, env, nSize); - status = WLog_FileAppender_SetOutputFileName(log, FileAppender, env); + GetEnvironmentVariableA(name, env, nSize); + status = WLog_FileAppender_SetOutputFileName(FileAppender, env); free(env); if (!status) goto error_output_file_name; } - return FileAppender; + return (wLogAppender *)FileAppender; error_output_file_name: free(FileAppender->FilePath); @@ -252,14 +284,3 @@ error_free: free(FileAppender); return NULL; } - -void WLog_FileAppender_Free(wLog* log, wLogFileAppender* appender) -{ - if (appender) - { - free(appender->FileName); - free(appender->FilePath); - free(appender->FullFileName); - free(appender); - } -} diff --git a/winpr/libwinpr/utils/wlog/FileAppender.h b/winpr/libwinpr/utils/wlog/FileAppender.h index de51249df..6f2f96eac 100644 --- a/winpr/libwinpr/utils/wlog/FileAppender.h +++ b/winpr/libwinpr/utils/wlog/FileAppender.h @@ -20,11 +20,8 @@ #ifndef WINPR_WLOG_FILE_APPENDER_PRIVATE_H #define WINPR_WLOG_FILE_APPENDER_PRIVATE_H -#include +#include "wlog.h" -#include "wlog/wlog.h" - -WINPR_API wLogFileAppender* WLog_FileAppender_New(wLog* log); -WINPR_API void WLog_FileAppender_Free(wLog* log, wLogFileAppender* appender); +wLogAppender* WLog_FileAppender_New(wLog* log); #endif /* WINPR_WLOG_FILE_APPENDER_PRIVATE_H */ diff --git a/winpr/libwinpr/utils/wlog/ImageMessage.c b/winpr/libwinpr/utils/wlog/ImageMessage.c index c09a7eb2a..94da680e3 100644 --- a/winpr/libwinpr/utils/wlog/ImageMessage.c +++ b/winpr/libwinpr/utils/wlog/ImageMessage.c @@ -21,7 +21,7 @@ #include "config.h" #endif -#include +#include "wlog.h" #include #include "wlog/ImageMessage.h" diff --git a/winpr/libwinpr/utils/wlog/ImageMessage.h b/winpr/libwinpr/utils/wlog/ImageMessage.h index 84efa0e46..11ce9e977 100644 --- a/winpr/libwinpr/utils/wlog/ImageMessage.h +++ b/winpr/libwinpr/utils/wlog/ImageMessage.h @@ -20,10 +20,6 @@ #ifndef WINPR_WLOG_IMAGE_MESSAGE_PRIVATE_H #define WINPR_WLOG_IMAGE_MESSAGE_PRIVATE_H -#include - -#include "wlog/wlog.h" - BOOL WLog_ImageMessage_Write(char* filename, void* data, int width, int height, int bpp); #endif /* WINPR_WLOG_IMAGE_MESSAGE_PRIVATE_H */ diff --git a/winpr/libwinpr/utils/wlog/JournaldAppender.c b/winpr/libwinpr/utils/wlog/JournaldAppender.c index 4b8423018..31ac150ee 100644 --- a/winpr/libwinpr/utils/wlog/JournaldAppender.c +++ b/winpr/libwinpr/utils/wlog/JournaldAppender.c @@ -22,59 +22,52 @@ #include "config.h" #endif +#include "JournaldAppender.h" + #include #include #include #include #include -#include -#include -#include "wlog/Message.h" -#include "wlog/JournaldAppender.h" - -BOOL Wlog_JournaldAppender_SetIdentifier(wLogJournaldAppender* appender, const char *id) +struct _wLogJournaldAppender { - if (appender->identifier) - free(appender->identifier); + WLOG_APPENDER_COMMON(); + char *identifier; + FILE *stream; +}; +typedef struct _wLogJournaldAppender wLogJournaldAppender; - if (appender->stream) - { - fclose(appender->stream); - appender->stream = NULL; - } - - return ((appender->identifier = _strdup(id)) != NULL); -} - -static BOOL WLog_JournaldAppender_Open(wLog* log, wLogJournaldAppender* appender) +static BOOL WLog_JournaldAppender_Open(wLog* log, wLogAppender* appender) { int fd; + wLogJournaldAppender *journaldAppender; if (!log || !appender) return FALSE; - if (appender->stream) + journaldAppender = (wLogJournaldAppender*)appender; + if (journaldAppender->stream) return TRUE; - fd = sd_journal_stream_fd(appender->identifier, LOG_INFO, 1); + fd = sd_journal_stream_fd(journaldAppender->identifier, LOG_INFO, 1); if (fd < 0) return FALSE; - appender->stream = fdopen(fd, "w"); - if (!appender->stream) + journaldAppender->stream = fdopen(fd, "w"); + if (!journaldAppender->stream) { close(fd); return FALSE; } - setbuffer(appender->stream, NULL, 0); + setbuffer(journaldAppender->stream, NULL, 0); return TRUE; } -static BOOL WLog_JournaldAppender_Close(wLog* log, wLogJournaldAppender* appender) +static BOOL WLog_JournaldAppender_Close(wLog* log, wLogAppender* appender) { if (!log || !appender) return FALSE; @@ -82,13 +75,16 @@ static BOOL WLog_JournaldAppender_Close(wLog* log, wLogJournaldAppender* appende return TRUE; } -static BOOL WLog_JournaldAppender_WriteMessage(wLog* log, wLogJournaldAppender* appender, wLogMessage* message) +static BOOL WLog_JournaldAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { char *formatStr; + wLogJournaldAppender* journaldAppender; if (!log || !appender || !message) return FALSE; + journaldAppender = (wLogJournaldAppender *)appender; + switch (message->Level) { case WLOG_TRACE: @@ -114,11 +110,11 @@ static BOOL WLog_JournaldAppender_WriteMessage(wLog* log, wLogJournaldAppender* return FALSE; } - fprintf(appender->stream, formatStr, message->TextString); + fprintf(journaldAppender->stream, formatStr, message->TextString); return TRUE; } -static BOOL WLog_JournaldAppender_WriteDataMessage(wLog* log, wLogJournaldAppender* appender, wLogMessage* message) +static BOOL WLog_JournaldAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { if (!log || !appender || !message) return FALSE; @@ -126,7 +122,7 @@ static BOOL WLog_JournaldAppender_WriteDataMessage(wLog* log, wLogJournaldAppend return TRUE; } -static BOOL WLog_JournaldAppender_WriteImageMessage(wLog* log, wLogJournaldAppender* appender, wLogMessage* message) +static BOOL WLog_JournaldAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { if (!log || !appender || !message) return FALSE; @@ -135,7 +131,40 @@ static BOOL WLog_JournaldAppender_WriteImageMessage(wLog* log, wLogJournaldAppen return TRUE; } -wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log) +static BOOL WLog_JournaldAppender_Set(wLogAppender* appender, const char *setting, void *value) +{ + wLogJournaldAppender* journaldAppender = (wLogJournaldAppender *)appender; + + if (!value || !strlen(value)) + return FALSE; + + if (strcmp("identifier", setting)) + return FALSE; + + /* If the stream is already open the identifier can't be changed */ + if (journaldAppender->stream) + return FALSE; + + if (journaldAppender->identifier) + free(journaldAppender->identifier); + + return ((journaldAppender->identifier = _strdup((const char *)value)) != NULL); +} + +static void WLog_JournaldAppender_Free(wLogAppender* appender) +{ + wLogJournaldAppender *journaldAppender; + if (appender) + { + journaldAppender = (wLogJournaldAppender*)appender; + if (journaldAppender->stream) + fclose(journaldAppender->stream); + free(journaldAppender->identifier); + free(journaldAppender); + } +} + +wLogAppender* WLog_JournaldAppender_New(wLog* log) { wLogJournaldAppender* appender; DWORD nSize; @@ -146,15 +175,13 @@ wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log) return NULL; appender->Type = WLOG_APPENDER_JOURNALD; - - appender->Open = (WLOG_APPENDER_OPEN_FN) WLog_JournaldAppender_Open; - appender->Close = (WLOG_APPENDER_OPEN_FN) WLog_JournaldAppender_Close; - appender->WriteMessage = - (WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_JournaldAppender_WriteMessage; - appender->WriteDataMessage = - (WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_JournaldAppender_WriteDataMessage; - appender->WriteImageMessage = - (WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_JournaldAppender_WriteImageMessage; + appender->Open = WLog_JournaldAppender_Open; + appender->Close = WLog_JournaldAppender_Close; + appender->WriteMessage = WLog_JournaldAppender_WriteMessage; + appender->WriteDataMessage = WLog_JournaldAppender_WriteDataMessage; + appender->WriteImageMessage = WLog_JournaldAppender_WriteImageMessage; + appender->Set = WLog_JournaldAppender_Set; + appender->Free = WLog_JournaldAppender_Free; name = "WLOG_JOURNALD_ID"; nSize = GetEnvironmentVariableA(name, NULL, 0); @@ -166,17 +193,11 @@ wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log) GetEnvironmentVariableA(name, appender->identifier, nSize); - if (!WLog_JournaldAppender_Open(log, appender)) + if (!WLog_JournaldAppender_Open(log, (wLogAppender *)appender)) goto error_open; } - else - { - appender->identifier = _strdup("winpr"); - if (!appender->identifier) - goto error_env_malloc; - } - return appender; + return (wLogAppender *)appender; error_open: free(appender->identifier); @@ -184,14 +205,3 @@ error_env_malloc: free(appender); return NULL; } - -void WLog_JournaldAppender_Free(wLog* log, wLogJournaldAppender* appender) -{ - if (appender) - { - if (appender->stream) - fclose(appender->stream); - free(appender->identifier); - free(appender); - } -} diff --git a/winpr/libwinpr/utils/wlog/JournaldAppender.h b/winpr/libwinpr/utils/wlog/JournaldAppender.h index 9f2072d49..49223c516 100644 --- a/winpr/libwinpr/utils/wlog/JournaldAppender.h +++ b/winpr/libwinpr/utils/wlog/JournaldAppender.h @@ -24,13 +24,8 @@ #ifndef WINPR_LIBWINPR_UTILS_WLOG_JOURNALDAPPENDER_H_ #define WINPR_LIBWINPR_UTILS_WLOG_JOURNALDAPPENDER_H_ -#include - -#include "wlog/wlog.h" - -WINPR_API wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log); -WINPR_API void WLog_JournaldAppender_Free(wLog* log, wLogJournaldAppender* appender); -WINPR_API BOOL Wlog_JournaldAppender_SetIdentifier(wLogJournaldAppender* appender, const char *id); +#include "wlog.h" +wLogAppender* WLog_JournaldAppender_New(wLog* log); #endif /* WINPR_LIBWINPR_UTILS_WLOG_JOURNALDAPPENDER_H_ */ diff --git a/winpr/libwinpr/utils/wlog/Layout.c b/winpr/libwinpr/utils/wlog/Layout.c index 741f7cb19..ddca2133e 100644 --- a/winpr/libwinpr/utils/wlog/Layout.c +++ b/winpr/libwinpr/utils/wlog/Layout.c @@ -30,7 +30,7 @@ #include #include -#include +#include "wlog.h" #include "wlog/Layout.h" diff --git a/winpr/libwinpr/utils/wlog/Layout.h b/winpr/libwinpr/utils/wlog/Layout.h index 81683ac76..df31d4d6d 100644 --- a/winpr/libwinpr/utils/wlog/Layout.h +++ b/winpr/libwinpr/utils/wlog/Layout.h @@ -20,7 +20,18 @@ #ifndef WINPR_WLOG_LAYOUT_PRIVATE_H #define WINPR_WLOG_LAYOUT_PRIVATE_H -#include +#include "wlog.h" + +/** + * Log Layout + */ + +struct _wLogLayout +{ + DWORD Type; + + LPSTR FormatString; +}; wLogLayout* WLog_Layout_New(wLog* log); void WLog_Layout_Free(wLog* log, wLogLayout* layout); diff --git a/winpr/libwinpr/utils/wlog/Message.c b/winpr/libwinpr/utils/wlog/Message.c index c8567b92e..77f94d7df 100644 --- a/winpr/libwinpr/utils/wlog/Message.c +++ b/winpr/libwinpr/utils/wlog/Message.c @@ -25,9 +25,9 @@ #include #include -#include +#include "wlog.h" -#include "wlog/Message.h" +#include "Message.h" char* WLog_Message_GetOutputFileName(int id, const char* ext) { diff --git a/winpr/libwinpr/utils/wlog/Message.h b/winpr/libwinpr/utils/wlog/Message.h index 4ad0227c4..c65b33cf0 100644 --- a/winpr/libwinpr/utils/wlog/Message.h +++ b/winpr/libwinpr/utils/wlog/Message.h @@ -20,14 +20,9 @@ #ifndef WINPR_WLOG_MESSAGE_PRIVATE_H #define WINPR_WLOG_MESSAGE_PRIVATE_H -#include - -#include "wlog/wlog.h" - -#include "wlog/TextMessage.h" -#include "wlog/DataMessage.h" -#include "wlog/ImageMessage.h" -#include "wlog/PacketMessage.h" +#include "DataMessage.h" +#include "ImageMessage.h" +#include "PacketMessage.h" char* WLog_Message_GetOutputFileName(int id, const char* ext); diff --git a/winpr/libwinpr/utils/wlog/PacketMessage.c b/winpr/libwinpr/utils/wlog/PacketMessage.c index e3a063165..9bcddbbe1 100644 --- a/winpr/libwinpr/utils/wlog/PacketMessage.c +++ b/winpr/libwinpr/utils/wlog/PacketMessage.c @@ -23,7 +23,7 @@ #include "config.h" #endif -#include +#include "wlog.h" #include "wlog/PacketMessage.h" diff --git a/winpr/libwinpr/utils/wlog/PacketMessage.h b/winpr/libwinpr/utils/wlog/PacketMessage.h index 1ee0dc241..e0b73526a 100644 --- a/winpr/libwinpr/utils/wlog/PacketMessage.h +++ b/winpr/libwinpr/utils/wlog/PacketMessage.h @@ -20,9 +20,7 @@ #ifndef WINPR_WLOG_PACKET_MESSAGE_PRIVATE_H #define WINPR_WLOG_PACKET_MESSAGE_PRIVATE_H -#include - -#include "wlog/wlog.h" +#include "wlog.h" #define PCAP_MAGIC_NUMBER 0xA1B2C3D4 diff --git a/winpr/libwinpr/utils/wlog/SyslogAppender.c b/winpr/libwinpr/utils/wlog/SyslogAppender.c index 169c5ae9e..7b86c35d1 100644 --- a/winpr/libwinpr/utils/wlog/SyslogAppender.c +++ b/winpr/libwinpr/utils/wlog/SyslogAppender.c @@ -2,7 +2,8 @@ * WinPR: Windows Portable Runtime * WinPR Logger * - * Copyright 2013 David FORT + * Copyright © 2015 Thincast Technologies GmbH + * Copyright © 2015 David FORT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,16 +22,14 @@ #include "config.h" #endif +#include "SyslogAppender.h" #include -#include -#include -#include - -#include - -#include "wlog/Message.h" -#include "wlog/SyslogAppender.h" +struct _wLogSyslogAppender +{ + WLOG_APPENDER_COMMON(); +}; +typedef struct _wLogSyslogAppender wLogSyslogAppender; static int getSyslogLevel(DWORD level) { @@ -53,7 +52,7 @@ static int getSyslogLevel(DWORD level) } } -static BOOL WLog_SyslogAppender_Open(wLog* log, wLogSyslogAppender* appender) +static BOOL WLog_SyslogAppender_Open(wLog* log, wLogAppender* appender) { if (!log || !appender) return FALSE; @@ -61,7 +60,7 @@ static BOOL WLog_SyslogAppender_Open(wLog* log, wLogSyslogAppender* appender) return TRUE; } -static BOOL WLog_SyslogAppender_Close(wLog* log, wLogSyslogAppender* appender) +static BOOL WLog_SyslogAppender_Close(wLog* log, wLogAppender* appender) { if (!log || !appender) return FALSE; @@ -69,7 +68,7 @@ static BOOL WLog_SyslogAppender_Close(wLog* log, wLogSyslogAppender* appender) return TRUE; } -static BOOL WLog_SyslogAppender_WriteMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message) +static BOOL WLog_SyslogAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { int syslogLevel; @@ -83,7 +82,7 @@ static BOOL WLog_SyslogAppender_WriteMessage(wLog* log, wLogSyslogAppender* appe return TRUE; } -static BOOL WLog_SyslogAppender_WriteDataMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message) +static BOOL WLog_SyslogAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { int syslogLevel; @@ -97,7 +96,7 @@ static BOOL WLog_SyslogAppender_WriteDataMessage(wLog* log, wLogSyslogAppender* return TRUE; } -static BOOL WLog_SyslogAppender_WriteImageMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message) +static BOOL WLog_SyslogAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { int syslogLevel; @@ -111,7 +110,12 @@ static BOOL WLog_SyslogAppender_WriteImageMessage(wLog* log, wLogSyslogAppender* return TRUE; } -wLogSyslogAppender* WLog_SyslogAppender_New(wLog* log) +void WLog_SyslogAppender_Free(wLogAppender* appender) +{ + free(appender); +} + +wLogAppender* WLog_SyslogAppender_New(wLog* log) { wLogSyslogAppender* appender; @@ -121,20 +125,12 @@ wLogSyslogAppender* WLog_SyslogAppender_New(wLog* log) appender->Type = WLOG_APPENDER_SYSLOG; - appender->Open = (WLOG_APPENDER_OPEN_FN) WLog_SyslogAppender_Open; - appender->Close = (WLOG_APPENDER_OPEN_FN) WLog_SyslogAppender_Close; - appender->WriteMessage = - (WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_SyslogAppender_WriteMessage; - appender->WriteDataMessage = - (WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_SyslogAppender_WriteDataMessage; - appender->WriteImageMessage = - (WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_SyslogAppender_WriteImageMessage; + appender->Open = WLog_SyslogAppender_Open; + appender->Close = WLog_SyslogAppender_Close; + appender->WriteMessage = WLog_SyslogAppender_WriteMessage; + appender->WriteDataMessage = WLog_SyslogAppender_WriteDataMessage; + appender->WriteImageMessage = WLog_SyslogAppender_WriteImageMessage; + appender->Free = WLog_SyslogAppender_Free; - return appender; -} - -void WLog_SyslogAppender_Free(wLog* log, wLogSyslogAppender* appender) -{ - if (appender) - free(appender); + return (wLogAppender*)appender; } diff --git a/winpr/libwinpr/utils/wlog/SyslogAppender.h b/winpr/libwinpr/utils/wlog/SyslogAppender.h index 2ce6b527c..be6b872be 100644 --- a/winpr/libwinpr/utils/wlog/SyslogAppender.h +++ b/winpr/libwinpr/utils/wlog/SyslogAppender.h @@ -24,12 +24,8 @@ #ifndef WINPR_LIBWINPR_UTILS_WLOG_SYSLOGAPPENDER_H_ #define WINPR_LIBWINPR_UTILS_WLOG_SYSLOGAPPENDER_H_ -#include - -#include "wlog/wlog.h" - -WINPR_API wLogSyslogAppender* WLog_SyslogAppender_New(wLog* log); -WINPR_API void WLog_SyslogAppender_Free(wLog* log, wLogSyslogAppender* appender); +#include "wlog.h" +wLogAppender* WLog_SyslogAppender_New(wLog* log); #endif /* WINPR_LIBWINPR_UTILS_WLOG_SYSLOGAPPENDER_H_ */ diff --git a/winpr/libwinpr/utils/wlog/TextMessage.c b/winpr/libwinpr/utils/wlog/TextMessage.c index e5f110896..f127360d3 100644 --- a/winpr/libwinpr/utils/wlog/TextMessage.c +++ b/winpr/libwinpr/utils/wlog/TextMessage.c @@ -21,10 +21,6 @@ #include "config.h" #endif -#include - -#include "wlog/TextMessage.h" - void wlog_TextMessage_dummy() { /* avoid no symbol ranlib warning */ diff --git a/winpr/libwinpr/utils/wlog/TextMessage.h b/winpr/libwinpr/utils/wlog/TextMessage.h deleted file mode 100644 index 29b02065f..000000000 --- a/winpr/libwinpr/utils/wlog/TextMessage.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * WinPR: Windows Portable Runtime - * WinPR Logger - * - * Copyright 2013 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef WINPR_WLOG_TEXT_MESSAGE_PRIVATE_H -#define WINPR_WLOG_TEXT_MESSAGE_PRIVATE_H - -#include - -#include "wlog/wlog.h" - - - -#endif /* WINPR_WLOG_TEXT_MESSAGE_PRIVATE_H */ - diff --git a/winpr/libwinpr/utils/wlog/UdpAppender.c b/winpr/libwinpr/utils/wlog/UdpAppender.c index bc161d37b..bb173921f 100644 --- a/winpr/libwinpr/utils/wlog/UdpAppender.c +++ b/winpr/libwinpr/utils/wlog/UdpAppender.c @@ -25,39 +25,43 @@ #include #include -#include +#include -#include +#include "wlog.h" -#include "wlog/Message.h" -#include "wlog/UdpAppender.h" -#ifndef _WIN32 -#include -#include -#include -#endif - -static BOOL WLog_UdpAppender_Open(wLog* log, wLogUdpAppender* appender) +struct _wLogUdpAppender { + WLOG_APPENDER_COMMON(); + char *host; + struct sockaddr targetAddr; + int targetAddrLen; + SOCKET sock; +}; +typedef struct _wLogUdpAppender wLogUdpAppender; + +static BOOL WLog_UdpAppender_Open(wLog* log, wLogAppender* appender) +{ + wLogUdpAppender *udpAppender; char addressString[256]; struct addrinfo hints; struct addrinfo* result; int status, addrLen; char *colonPos; - if (!appender) return FALSE; - if (appender->targetAddrLen) /* already opened */ + udpAppender = (wLogUdpAppender*)appender; + + if (udpAppender->targetAddrLen) /* already opened */ return TRUE; - colonPos = strchr(appender->host, ':'); + colonPos = strchr(udpAppender->host, ':'); if (!colonPos) return FALSE; - addrLen = colonPos - appender->host; - memcpy(addressString, appender->host, addrLen); + addrLen = colonPos - udpAppender->host; + memcpy(addressString, udpAppender->host, addrLen); addressString[addrLen] = '\0'; ZeroMemory(&hints, sizeof(hints)); @@ -68,31 +72,19 @@ static BOOL WLog_UdpAppender_Open(wLog* log, wLogUdpAppender* appender) if (status != 0) return FALSE; - if (result->ai_addrlen > sizeof(appender->targetAddr)) + if (result->ai_addrlen > sizeof(udpAppender->targetAddr)) { freeaddrinfo(result); return FALSE; } - memcpy(&appender->targetAddr, result->ai_addr, result->ai_addrlen); - appender->targetAddrLen = result->ai_addrlen; - + memcpy(&udpAppender->targetAddr, result->ai_addr, result->ai_addrlen); + udpAppender->targetAddrLen = result->ai_addrlen; return TRUE; } -BOOL Wlog_UdpAppender_SetTarget(wLogUdpAppender* appender, const char *host) -{ - - appender->targetAddrLen = 0; - if (appender->host) - free(appender->host); - - appender->host = _strdup(host); - return (appender->host != NULL) && WLog_UdpAppender_Open(NULL, appender); -} - -static BOOL WLog_UdpAppender_Close(wLog* log, wLogUdpAppender* appender) +static BOOL WLog_UdpAppender_Close(wLog* log, wLogAppender* appender) { if (!log || !appender) return FALSE; @@ -100,28 +92,32 @@ static BOOL WLog_UdpAppender_Close(wLog* log, wLogUdpAppender* appender) return TRUE; } -static BOOL WLog_UdpAppender_WriteMessage(wLog* log, wLogUdpAppender* appender, wLogMessage* message) +static BOOL WLog_UdpAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { char prefix[WLOG_MAX_PREFIX_SIZE]; + wLogUdpAppender *udpAppender; + if (!log || !appender || !message) return FALSE; + udpAppender = (wLogUdpAppender *)appender; + message->PrefixString = prefix; WLog_Layout_GetMessagePrefix(log, appender->Layout, message); - _sendto(appender->sock, message->PrefixString, strlen(message->PrefixString), - 0, &appender->targetAddr, appender->targetAddrLen); + _sendto(udpAppender->sock, message->PrefixString, strlen(message->PrefixString), + 0, &udpAppender->targetAddr, udpAppender->targetAddrLen); - _sendto(appender->sock, message->TextString, strlen(message->TextString), - 0, &appender->targetAddr, appender->targetAddrLen); + _sendto(udpAppender->sock, message->TextString, strlen(message->TextString), + 0, &udpAppender->targetAddr, udpAppender->targetAddrLen); - _sendto(appender->sock, "\n", 1, 0, &appender->targetAddr, appender->targetAddrLen); + _sendto(udpAppender->sock, "\n", 1, 0, &udpAppender->targetAddr, udpAppender->targetAddrLen); return TRUE; } -static BOOL WLog_UdpAppender_WriteDataMessage(wLog* log, wLogUdpAppender* appender, wLogMessage* message) +static BOOL WLog_UdpAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { if (!log || !appender || !message) return FALSE; @@ -129,7 +125,7 @@ static BOOL WLog_UdpAppender_WriteDataMessage(wLog* log, wLogUdpAppender* append return TRUE; } -static BOOL WLog_UdpAppender_WriteImageMessage(wLog* log, wLogUdpAppender* appender, wLogMessage* message) +static BOOL WLog_UdpAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { if (!log || !appender || !message) return FALSE; @@ -138,7 +134,41 @@ static BOOL WLog_UdpAppender_WriteImageMessage(wLog* log, wLogUdpAppender* appen return TRUE; } -wLogUdpAppender* WLog_UdpAppender_New(wLog* log) +static BOOL WLog_UdpAppender_Set(wLogAppender* appender, const char *setting, void *value) +{ + wLogUdpAppender *udpAppender = (wLogUdpAppender *)appender; + + if (!value || !strlen(value)) + return FALSE; + + if (strcmp("target", setting)) + return FALSE; + + udpAppender->targetAddrLen = 0; + if (udpAppender->host) + free(udpAppender->host); + + udpAppender->host = _strdup((const char *)value); + return (udpAppender->host != NULL) && WLog_UdpAppender_Open(NULL, appender); +} + +static void WLog_UdpAppender_Free(wLogAppender* appender) +{ + wLogUdpAppender* udpAppender; + if (appender) + { + udpAppender = (wLogUdpAppender *)appender; + if (udpAppender->sock != INVALID_SOCKET) + { + closesocket(udpAppender->sock); + udpAppender->sock = INVALID_SOCKET; + } + free(udpAppender->host); + free(udpAppender); + } +} + +wLogAppender* WLog_UdpAppender_New(wLog* log) { wLogUdpAppender* appender; DWORD nSize; @@ -150,14 +180,13 @@ wLogUdpAppender* WLog_UdpAppender_New(wLog* log) appender->Type = WLOG_APPENDER_UDP; - appender->Open = (WLOG_APPENDER_OPEN_FN) WLog_UdpAppender_Open; - appender->Close = (WLOG_APPENDER_OPEN_FN) WLog_UdpAppender_Close; - appender->WriteMessage = - (WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_UdpAppender_WriteMessage; - appender->WriteDataMessage = - (WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_UdpAppender_WriteDataMessage; - appender->WriteImageMessage = - (WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_UdpAppender_WriteImageMessage; + appender->Open = WLog_UdpAppender_Open; + appender->Close = WLog_UdpAppender_Close; + appender->WriteMessage = WLog_UdpAppender_WriteMessage; + appender->WriteDataMessage = WLog_UdpAppender_WriteDataMessage; + appender->WriteImageMessage = WLog_UdpAppender_WriteImageMessage; + appender->Free = WLog_UdpAppender_Free; + appender->Set = WLog_UdpAppender_Set; appender->sock = _socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (appender->sock == INVALID_SOCKET) @@ -173,7 +202,7 @@ wLogUdpAppender* WLog_UdpAppender_New(wLog* log) GetEnvironmentVariableA(name, appender->host, nSize); - if (!WLog_UdpAppender_Open(log, appender)) + if (!WLog_UdpAppender_Open(log, (wLogAppender *)appender)) goto error_open; } else @@ -183,7 +212,7 @@ wLogUdpAppender* WLog_UdpAppender_New(wLog* log) goto error_host_alloc; } - return appender; + return (wLogAppender*)appender; error_open: free(appender->host); @@ -193,17 +222,3 @@ error_sock: free(appender); return NULL; } - -void WLog_UdpAppender_Free(wLog* log, wLogUdpAppender* appender) -{ - if (appender) - { - if (appender->sock != INVALID_SOCKET) - { - closesocket(appender->sock); - appender->sock = INVALID_SOCKET; - } - free(appender->host); - free(appender); - } -} diff --git a/winpr/libwinpr/utils/wlog/UdpAppender.h b/winpr/libwinpr/utils/wlog/UdpAppender.h index cd25345f4..c2d99a93e 100644 --- a/winpr/libwinpr/utils/wlog/UdpAppender.h +++ b/winpr/libwinpr/utils/wlog/UdpAppender.h @@ -28,8 +28,6 @@ #include "wlog/wlog.h" -WINPR_API wLogUdpAppender* WLog_UdpAppender_New(wLog* log); -WINPR_API void WLog_UdpAppender_Free(wLog* log, wLogUdpAppender* appender); -WINPR_API BOOL Wlog_UdpAppender_SetTarget(wLogUdpAppender* appender, const char *host); +wLogAppender* WLog_UdpAppender_New(wLog* log); #endif /* WINPR_LIBWINPR_UTILS_WLOG_UDPAPPENDER_H_ */ diff --git a/winpr/libwinpr/utils/wlog/wlog.c b/winpr/libwinpr/utils/wlog/wlog.c index 123fe6384..5526e693e 100644 --- a/winpr/libwinpr/utils/wlog/wlog.c +++ b/winpr/libwinpr/utils/wlog/wlog.c @@ -31,13 +31,19 @@ #if defined(ANDROID) #include +#include "../log.h" #endif -#include +#include "wlog.h" -#include "wlog/wlog.h" -#include "../../log.h" +struct _wLogFilter +{ + DWORD Level; + LPSTR* Names; + DWORD NameCount; +}; +typedef struct _wLogFilter wLogFilter; /** * References for general logging concepts: @@ -114,7 +120,7 @@ BOOL WLog_Write(wLog* log, wLogMessage* message) if (!appender) return FALSE; - if (!appender->State) + if (!appender->active) if (!WLog_OpenAppender(log)) return FALSE; @@ -145,7 +151,7 @@ BOOL WLog_WriteData(wLog* log, wLogMessage* message) if (!appender) return FALSE; - if (!appender->State) + if (!appender->active) if (!WLog_OpenAppender(log)) return FALSE; @@ -176,7 +182,7 @@ BOOL WLog_WriteImage(wLog* log, wLogMessage* message) if (!appender) return FALSE; - if (!appender->State) + if (!appender->active) if (!WLog_OpenAppender(log)) return FALSE; @@ -207,7 +213,7 @@ BOOL WLog_WritePacket(wLog* log, wLogMessage* message) if (!appender) return FALSE; - if (!appender->State) + if (!appender->active) if (!WLog_OpenAppender(log)) return FALSE; diff --git a/winpr/libwinpr/utils/wlog/wlog.h b/winpr/libwinpr/utils/wlog/wlog.h index 737a18b01..c3cc83e70 100644 --- a/winpr/libwinpr/utils/wlog/wlog.h +++ b/winpr/libwinpr/utils/wlog/wlog.h @@ -25,9 +25,62 @@ #define WLOG_MAX_PREFIX_SIZE 512 #define WLOG_MAX_STRING_SIZE 8192 + +typedef BOOL (*WLOG_APPENDER_OPEN_FN)(wLog* log, wLogAppender* appender); +typedef BOOL (*WLOG_APPENDER_CLOSE_FN)(wLog* log, wLogAppender* appender); +typedef BOOL (*WLOG_APPENDER_WRITE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); +typedef BOOL (*WLOG_APPENDER_WRITE_DATA_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); +typedef BOOL (*WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); +typedef BOOL (*WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); +typedef BOOL (*WLOG_APPENDER_SET)(wLogAppender* appender, const char *setting, void *value); +typedef void (*WLOG_APPENDER_FREE)(wLogAppender* appender); + +#define WLOG_APPENDER_COMMON() \ + DWORD Type; \ + BOOL active; \ + wLogLayout* Layout; \ + CRITICAL_SECTION lock; \ + BOOL recursive; \ + void* TextMessageContext; \ + void* DataMessageContext; \ + void* ImageMessageContext; \ + void* PacketMessageContext; \ + WLOG_APPENDER_OPEN_FN Open; \ + WLOG_APPENDER_CLOSE_FN Close; \ + WLOG_APPENDER_WRITE_MESSAGE_FN WriteMessage; \ + WLOG_APPENDER_WRITE_DATA_MESSAGE_FN WriteDataMessage; \ + WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN WriteImageMessage; \ + WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN WritePacketMessage; \ + WLOG_APPENDER_FREE Free; \ + WLOG_APPENDER_SET Set + + +struct _wLogAppender +{ + WLOG_APPENDER_COMMON(); +}; + +struct _wLog +{ + LPSTR Name; + DWORD Level; + + BOOL IsRoot; + LPSTR* Names; + DWORD NameCount; + wLogAppender* Appender; + + wLog* Parent; + wLog** Children; + DWORD ChildrenCount; + DWORD ChildrenSize; +}; + + BOOL WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* message); #include "wlog/Layout.h" #include "wlog/Appender.h" + #endif /* WINPR_WLOG_PRIVATE_H */