From 6de22298d0db48dd7e7f9e8a5879bfb29d2d9e5d Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Sun, 16 Nov 2014 12:20:48 +0100 Subject: [PATCH 1/6] Added callback appender for wlog. --- winpr/include/winpr/wlog.h | 21 +++ winpr/libwinpr/utils/CMakeLists.txt | 2 + winpr/libwinpr/utils/wlog/Appender.c | 8 + winpr/libwinpr/utils/wlog/Appender.h | 1 + winpr/libwinpr/utils/wlog/CallbackAppender.c | 161 +++++++++++++++++++ winpr/libwinpr/utils/wlog/CallbackAppender.h | 30 ++++ 6 files changed, 223 insertions(+) create mode 100644 winpr/libwinpr/utils/wlog/CallbackAppender.c create mode 100644 winpr/libwinpr/utils/wlog/CallbackAppender.h diff --git a/winpr/include/winpr/wlog.h b/winpr/include/winpr/wlog.h index f50baf41b..1421af26e 100644 --- a/winpr/include/winpr/wlog.h +++ b/winpr/include/winpr/wlog.h @@ -112,6 +112,7 @@ struct _wLogLayout #define WLOG_APPENDER_CONSOLE 0 #define WLOG_APPENDER_FILE 1 #define WLOG_APPENDER_BINARY 2 +#define WLOG_APPENDER_CALLBACK 3 #define WLOG_PACKET_INBOUND 1 #define WLOG_PACKET_OUTBOUND 2 @@ -179,6 +180,22 @@ struct _wLogBinaryAppender }; typedef struct _wLogBinaryAppender wLogBinaryAppender; +typedef void (*CallbackAppenderMessage_t)(const wLogMessage *msg); +typedef void (*CallbackAppenderData_t)(const wLogMessage *msg); +typedef void (*CallbackAppenderImage_t)(const wLogMessage *msg); +typedef void (*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; + /** * Filter */ @@ -309,6 +326,10 @@ WINPR_API void WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppend WINPR_API void WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename); WINPR_API void WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath); +WINPR_API void WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender, + CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg, + CallbackAppenderData_t data); + WINPR_API wLogLayout* WLog_GetLogLayout(wLog* log); WINPR_API void WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format); diff --git a/winpr/libwinpr/utils/CMakeLists.txt b/winpr/libwinpr/utils/CMakeLists.txt index 3e75355a5..26fbd7842 100644 --- a/winpr/libwinpr/utils/CMakeLists.txt +++ b/winpr/libwinpr/utils/CMakeLists.txt @@ -72,6 +72,8 @@ set(${MODULE_PREFIX}_WLOG_SRCS wlog/FileAppender.h wlog/BinaryAppender.c wlog/BinaryAppender.h + wlog/CallbackAppender.c + wlog/CallbackAppender.h wlog/ConsoleAppender.c wlog/ConsoleAppender.h) diff --git a/winpr/libwinpr/utils/wlog/Appender.c b/winpr/libwinpr/utils/wlog/Appender.c index d323235b3..5638e0034 100644 --- a/winpr/libwinpr/utils/wlog/Appender.c +++ b/winpr/libwinpr/utils/wlog/Appender.c @@ -43,6 +43,10 @@ wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType) { appender = (wLogAppender*) WLog_BinaryAppender_New(log); } + else if (logAppenderType == WLOG_APPENDER_CALLBACK) + { + appender = (wLogAppender*) WLog_CallbackAppender_New(log); + } if (!appender) appender = (wLogAppender*) WLog_ConsoleAppender_New(log); @@ -78,6 +82,10 @@ void WLog_Appender_Free(wLog* log, wLogAppender* appender) { WLog_BinaryAppender_Free(log, (wLogBinaryAppender*) appender); } + else if (appender->Type == WLOG_APPENDER_CALLBACK) + { + WLog_CallbackAppender_Free(log, (wLogCallbackAppender*) appender); + } } } diff --git a/winpr/libwinpr/utils/wlog/Appender.h b/winpr/libwinpr/utils/wlog/Appender.h index 1ca4886f1..4be3306a0 100644 --- a/winpr/libwinpr/utils/wlog/Appender.h +++ b/winpr/libwinpr/utils/wlog/Appender.h @@ -25,6 +25,7 @@ #include "wlog/FileAppender.h" #include "wlog/BinaryAppender.h" #include "wlog/ConsoleAppender.h" +#include "wlog/CallbackAppender.h" void WLog_Appender_Free(wLog* log, wLogAppender* appender); diff --git a/winpr/libwinpr/utils/wlog/CallbackAppender.c b/winpr/libwinpr/utils/wlog/CallbackAppender.c new file mode 100644 index 000000000..3c0cce7e9 --- /dev/null +++ b/winpr/libwinpr/utils/wlog/CallbackAppender.c @@ -0,0 +1,161 @@ +/** + * WinPR: Windows Portable Runtime + * WinPR Logger + * + * Copyright 2014 Armin Novak + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include + +#include "wlog/Message.h" + +#include "wlog/CallbackAppender.h" + +/** + * Callback Appender + */ + +WINPR_API void WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender, + CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg, + CallbackAppenderData_t data) +{ + if (!appender) + return; + + if (appender->Type != WLOG_APPENDER_CALLBACK) + return; + + appender->message = msg; + appender->image = img; + appender->package = pkg; +} + +int WLog_CallbackAppender_Open(wLog* log, wLogCallbackAppender* appender) +{ + return 0; +} + +int WLog_CallbackAppender_Close(wLog* log, wLogCallbackAppender* appender) +{ + return 0; +} + +int WLog_CallbackAppender_WriteMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) +{ + char prefix[WLOG_MAX_PREFIX_SIZE]; + + message->PrefixString = prefix; + WLog_Layout_GetMessagePrefix(log, appender->Layout, message); + + if (appender->message) + { + appender->message(message); + } + else + { + return -1; + } + + return 1; +} + +int WLog_CallbackAppender_WriteDataMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) +{ + if (appender->data) + { + appender->data(message); + } + else + { + return -1; + } + + return 1; +} + +int WLog_CallbackAppender_WriteImageMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) +{ + if (appender->image) + { + appender->image(message); + } + else + { + return -1; + } + + return 1; +} + +int WLog_CallbackAppender_WritePacketMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) +{ + if (!appender->package) + { + appender->package(message); + } + else + { + return -1; + } + + return 1; +} + +wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log) +{ + wLogCallbackAppender* CallbackAppender; + + CallbackAppender = (wLogCallbackAppender*) malloc(sizeof(wLogCallbackAppender)); + + if (CallbackAppender) + { + ZeroMemory(CallbackAppender, sizeof(wLogCallbackAppender)); + + CallbackAppender->Type = WLOG_APPENDER_CONSOLE; + + 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->message = NULL; + CallbackAppender->image = NULL; + CallbackAppender->package = NULL; + } + + return CallbackAppender; +} + +void WLog_CallbackAppender_Free(wLog* log, wLogCallbackAppender* appender) +{ + if (appender) + { + free(appender); + } +} diff --git a/winpr/libwinpr/utils/wlog/CallbackAppender.h b/winpr/libwinpr/utils/wlog/CallbackAppender.h new file mode 100644 index 000000000..a23153c44 --- /dev/null +++ b/winpr/libwinpr/utils/wlog/CallbackAppender.h @@ -0,0 +1,30 @@ +/** + * WinPR: Windows Portable Runtime + * WinPR Logger + * + * Copyright 2014 Armin Novak + * + * 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_CALLBACK_APPENDER_PRIVATE_H +#define WINPR_WLOG_CALLBACK_APPENDER_PRIVATE_H + +#include + +#include "wlog/wlog.h" + +WINPR_API wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log); +WINPR_API void WLog_CallbackAppender_Free(wLog* log, wLogCallbackAppender* appender); + +#endif /* WINPR_WLOG_CALLBACK_APPENDER_PRIVATE_H */ From 8d4589b1e114d652afa9756448a5bce68ffa8b55 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Sun, 16 Nov 2014 12:21:38 +0100 Subject: [PATCH 2/6] Replaced fprintf error messages with WLog. --- client/Wayland/wlfreerdp.c | 13 ++-- client/Windows/wf_rail.c | 101 ++++++++++++++------------- libfreerdp/codec/color.c | 9 ++- libfreerdp/codec/interleaved.c | 7 +- libfreerdp/core/capabilities.c | 2 +- libfreerdp/core/tcp.c | 4 +- rdtk/sample/rdtk_x11.c | 5 +- server/shadow/X11/x11_shadow.c | 8 +-- winpr/libwinpr/wtsapi/wtsapi_win32.c | 6 +- 9 files changed, 85 insertions(+), 70 deletions(-) diff --git a/client/Wayland/wlfreerdp.c b/client/Wayland/wlfreerdp.c index 64221c55d..19be6f31e 100644 --- a/client/Wayland/wlfreerdp.c +++ b/client/Wayland/wlfreerdp.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -30,6 +31,8 @@ #include +#define TAG CLIENT_TAG("wayland") + struct display { struct wl_display* display; @@ -101,7 +104,7 @@ static void window_redraw(void* data, struct wl_callback* callback, uint32_t tim fdt = ftruncate(fd, window->width * window->height * 4); if (fdt != 0) { - fprintf(stderr, "window_redraw: could not allocate memory\n"); + WLog_ERR(TAG, "window_redraw: could not allocate memory"); close(fd); return; } @@ -109,7 +112,7 @@ static void window_redraw(void* data, struct wl_callback* callback, uint32_t tim buffer->shm_data = mmap(0, window->width * window->height * 4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (buffer->shm_data == MAP_FAILED) { - fprintf(stderr, "window_redraw: failed to memory map buffer\n"); + WLog_ERR(TAG, "window_redraw: failed to memory map buffer"); close(fd); return; } @@ -220,8 +223,8 @@ BOOL wl_pre_connect(freerdp* instance) if (!display->display) { - fprintf(stderr, "wl_pre_connect: failed to connect to Wayland compositor\n"); - fprintf(stderr, "Please check that the XDG_RUNTIME_DIR environment variable is properly set.\n"); + WLog_ERR(TAG, "wl_pre_connect: failed to connect to Wayland compositor"); + WLog_ERR(TAG, "Please check that the XDG_RUNTIME_DIR environment variable is properly set."); free(display); return FALSE; } @@ -232,7 +235,7 @@ BOOL wl_pre_connect(freerdp* instance) if (!display->compositor || !display->shell || !display->shm) { - fprintf(stderr, "wl_pre_connect: failed to find needed compositor interfaces\n"); + WLog_ERR(TAG, "wl_pre_connect: failed to find needed compositor interfaces"); free(display); return FALSE; } diff --git a/client/Windows/wf_rail.c b/client/Windows/wf_rail.c index 40a26ab0b..c88d3557a 100644 --- a/client/Windows/wf_rail.c +++ b/client/Windows/wf_rail.c @@ -20,11 +20,14 @@ #include "config.h" #endif +#include #include #include #include "wf_rail.h" +#define TAG CLIENT_TAG("windows") + #define GET_X_LPARAM(lParam) ((UINT16) (lParam & 0xFFFF)) #define GET_Y_LPARAM(lParam) ((UINT16) ((lParam >> 16) & 0xFFFF)) @@ -99,7 +102,7 @@ void PrintWindowStyles(UINT32 style) { int i; - fprintf(stderr, "\tWindow Styles:\n\t{\n"); + WLog_INFO(TAG, "\tWindow Styles:\t{"); for (i = 0; i < ARRAYSIZE(WINDOW_STYLES); i++) { if (style & WINDOW_STYLES[i].style) @@ -110,17 +113,16 @@ void PrintWindowStyles(UINT32 style) continue; } - fprintf(stderr, "\t\t%s\n", WINDOW_STYLES[i].name); + WLog_INFO(TAG, "\t\t%s", WINDOW_STYLES[i].name); } } - fprintf(stderr, "\t}\n"); } void PrintExtendedWindowStyles(UINT32 style) { int i; - fprintf(stderr, "\tExtended Window Styles:\n\t{\n"); + WLog_INFO(TAG, "\tExtended Window Styles:\t{"); for (i = 0; i < ARRAYSIZE(EXTENDED_WINDOW_STYLES); i++) { if (style & EXTENDED_WINDOW_STYLES[i].style) @@ -131,29 +133,28 @@ void PrintExtendedWindowStyles(UINT32 style) continue; } - fprintf(stderr, "\t\t%s\n", EXTENDED_WINDOW_STYLES[i].name); + WLog_INFO(TAG, "\t\t%s", EXTENDED_WINDOW_STYLES[i].name); } } - fprintf(stderr, "\t}\n"); } void PrintRailWindowState(WINDOW_ORDER_INFO* orderInfo, WINDOW_STATE_ORDER* windowState) { if (orderInfo->fieldFlags & WINDOW_ORDER_STATE_NEW) - fprintf(stderr, "WindowCreate: WindowId: 0x%04X\n", orderInfo->windowId); + WLog_INFO(TAG, "WindowCreate: WindowId: 0x%04X", orderInfo->windowId); else - fprintf(stderr, "WindowUpdate: WindowId: 0x%04X\n", orderInfo->windowId); + WLog_INFO(TAG, "WindowUpdate: WindowId: 0x%04X", orderInfo->windowId); - fprintf(stderr, "{\n"); + WLog_INFO(TAG, "{"); if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_OWNER) { - fprintf(stderr, "\tOwnerWindowId: 0x%04X\n", windowState->ownerWindowId); + WLog_INFO(TAG, "\tOwnerWindowId: 0x%04X", windowState->ownerWindowId); } if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_STYLE) { - fprintf(stderr, "\tStyle: 0x%04X ExtendedStyle: 0x%04X\n", + WLog_INFO(TAG, "\tStyle: 0x%04X ExtendedStyle: 0x%04X", windowState->style, windowState->extendedStyle); PrintWindowStyles(windowState->style); @@ -162,7 +163,7 @@ void PrintRailWindowState(WINDOW_ORDER_INFO* orderInfo, WINDOW_STATE_ORDER* wind if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_SHOW) { - fprintf(stderr, "\tShowState: %d\n", windowState->showState); + WLog_INFO(TAG, "\tShowState: %d", windowState->showState); } if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_TITLE) @@ -172,7 +173,7 @@ void PrintRailWindowState(WINDOW_ORDER_INFO* orderInfo, WINDOW_STATE_ORDER* wind ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) windowState->titleInfo.string, windowState->titleInfo.length / 2, &title, 0, NULL, NULL); - fprintf(stderr, "\tTitleInfo: %s (length = %d)\n", title, + WLog_INFO(TAG, "\tTitleInfo: %s (length = %d)", title, windowState->titleInfo.length); free(title); @@ -180,41 +181,41 @@ void PrintRailWindowState(WINDOW_ORDER_INFO* orderInfo, WINDOW_STATE_ORDER* wind if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET) { - fprintf(stderr, "\tClientOffsetX: %d ClientOffsetY: %d\n", + WLog_INFO(TAG, "\tClientOffsetX: %d ClientOffsetY: %d", windowState->clientOffsetX, windowState->clientOffsetY); } if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE) { - fprintf(stderr, "\tClientAreaWidth: %d ClientAreaHeight: %d\n", + WLog_INFO(TAG, "\tClientAreaWidth: %d ClientAreaHeight: %d", windowState->clientAreaWidth, windowState->clientAreaHeight); } if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_RP_CONTENT) { - fprintf(stderr, "\tRPContent: %d\n", windowState->RPContent); + WLog_INFO(TAG, "\tRPContent: %d", windowState->RPContent); } if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ROOT_PARENT) { - fprintf(stderr, "\tRootParentHandle: 0x%04X\n", windowState->rootParentHandle); + WLog_INFO(TAG, "\tRootParentHandle: 0x%04X", windowState->rootParentHandle); } if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET) { - fprintf(stderr, "\tWindowOffsetX: %d WindowOffsetY: %d\n", + WLog_INFO(TAG, "\tWindowOffsetX: %d WindowOffsetY: %d", windowState->windowOffsetX, windowState->windowOffsetY); } if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_CLIENT_DELTA) { - fprintf(stderr, "\tWindowClientDeltaX: %d WindowClientDeltaY: %d\n", + WLog_INFO(TAG, "\tWindowClientDeltaX: %d WindowClientDeltaY: %d", windowState->windowClientDeltaX, windowState->windowClientDeltaY); } if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE) { - fprintf(stderr, "\tWindowWidth: %d WindowHeight: %d\n", + WLog_INFO(TAG, "\tWindowWidth: %d WindowHeight: %d", windowState->windowWidth, windowState->windowHeight); } @@ -223,20 +224,20 @@ void PrintRailWindowState(WINDOW_ORDER_INFO* orderInfo, WINDOW_STATE_ORDER* wind UINT32 index; RECTANGLE_16* rect; - fprintf(stderr, "\tnumWindowRects: %d\n", windowState->numWindowRects); + WLog_INFO(TAG, "\tnumWindowRects: %d", windowState->numWindowRects); for (index = 0; index < windowState->numWindowRects; index++) { rect = &windowState->windowRects[index]; - fprintf(stderr, "\twindowRect[%d]: left: %d top: %d right: %d bottom: %d\n", + WLog_INFO(TAG, "\twindowRect[%d]: left: %d top: %d right: %d bottom: %d", index, rect->left, rect->top, rect->right, rect->bottom); } } if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VIS_OFFSET) { - fprintf(stderr, "\tvisibileOffsetX: %d visibleOffsetY: %d\n", + WLog_INFO(TAG, "\tvisibileOffsetX: %d visibleOffsetY: %d", windowState->visibleOffsetX, windowState->visibleOffsetY); } @@ -245,39 +246,39 @@ void PrintRailWindowState(WINDOW_ORDER_INFO* orderInfo, WINDOW_STATE_ORDER* wind UINT32 index; RECTANGLE_16* rect; - fprintf(stderr, "\tnumVisibilityRects: %d\n", windowState->numVisibilityRects); + WLog_INFO(TAG, "\tnumVisibilityRects: %d", windowState->numVisibilityRects); for (index = 0; index < windowState->numVisibilityRects; index++) { rect = &windowState->visibilityRects[index]; - fprintf(stderr, "\tvisibilityRect[%d]: left: %d top: %d right: %d bottom: %d\n", + WLog_INFO(TAG, "\tvisibilityRect[%d]: left: %d top: %d right: %d bottom: %d", index, rect->left, rect->top, rect->right, rect->bottom); } } - fprintf(stderr, "}\n"); + WLog_INFO(TAG, "}"); } static void PrintRailIconInfo(WINDOW_ORDER_INFO* orderInfo, ICON_INFO* iconInfo) { - fprintf(stderr, "ICON_INFO\n"); - fprintf(stderr, "{\n"); + WLog_INFO(TAG, "ICON_INFO"); + WLog_INFO(TAG, "{"); - fprintf(stderr, "\tbigIcon: %s\n", (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ICON_BIG) ? "true" : "false"); - fprintf(stderr, "\tcacheEntry; 0x%04X\n", iconInfo->cacheEntry); - fprintf(stderr, "\tcacheId: 0x%04X\n", iconInfo->cacheId); - fprintf(stderr, "\tbpp: %d\n", iconInfo->bpp); - fprintf(stderr, "\twidth: %d\n", iconInfo->width); - fprintf(stderr, "\theight: %d\n", iconInfo->height); - fprintf(stderr, "\tcbColorTable: %d\n", iconInfo->cbColorTable); - fprintf(stderr, "\tcbBitsMask: %d\n", iconInfo->cbBitsMask); - fprintf(stderr, "\tcbBitsColor: %d\n", iconInfo->cbBitsColor); - fprintf(stderr, "\tcolorTable: %p\n", iconInfo->colorTable); - fprintf(stderr, "\tbitsMask: %p\n", iconInfo->bitsMask); - fprintf(stderr, "\tbitsColor: %p\n", iconInfo->bitsColor); + WLog_INFO(TAG, "\tbigIcon: %s", (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ICON_BIG) ? "true" : "false"); + WLog_INFO(TAG, "\tcacheEntry; 0x%04X", iconInfo->cacheEntry); + WLog_INFO(TAG, "\tcacheId: 0x%04X", iconInfo->cacheId); + WLog_INFO(TAG, "\tbpp: %d", iconInfo->bpp); + WLog_INFO(TAG, "\twidth: %d", iconInfo->width); + WLog_INFO(TAG, "\theight: %d", iconInfo->height); + WLog_INFO(TAG, "\tcbColorTable: %d", iconInfo->cbColorTable); + WLog_INFO(TAG, "\tcbBitsMask: %d", iconInfo->cbBitsMask); + WLog_INFO(TAG, "\tcbBitsColor: %d", iconInfo->cbBitsColor); + WLog_INFO(TAG, "\tcolorTable: %p", iconInfo->colorTable); + WLog_INFO(TAG, "\tbitsMask: %p", iconInfo->bitsMask); + WLog_INFO(TAG, "\tbitsColor: %p", iconInfo->bitsColor); - fprintf(stderr, "}\n"); + WLog_INFO(TAG, "}"); } LRESULT CALLBACK wf_RailWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) @@ -650,7 +651,7 @@ static void wf_rail_window_delete(rdpContext* context, WINDOW_ORDER_INFO* orderI wfContext* wfc = (wfContext*) context; RailClientContext* rail = wfc->rail; - fprintf(stderr, "RailWindowDelete\n"); + WLog_DBG(TAG, "RailWindowDelete"); railWindow = (wfRailWindow*) HashTable_GetItemValue(wfc->railWindows, (void*) (UINT_PTR) orderInfo->windowId); @@ -680,7 +681,7 @@ static void wf_rail_window_icon(rdpContext* context, WINDOW_ORDER_INFO* orderInf wfContext* wfc = (wfContext*) context; RailClientContext* rail = wfc->rail; - fprintf(stderr, "RailWindowIcon\n"); + WLog_DBG(TAG, "RailWindowIcon"); PrintRailIconInfo(orderInfo, windowIcon->iconInfo); @@ -750,7 +751,7 @@ static void wf_rail_window_icon(rdpContext* context, WINDOW_ORDER_INFO* orderInf static void wf_rail_window_cached_icon(rdpContext* context, WINDOW_ORDER_INFO* orderInfo, WINDOW_CACHED_ICON_ORDER* windowCachedIcon) { - fprintf(stderr, "RailWindowCachedIcon\n"); + WLog_DBG(TAG, "RailWindowCachedIcon"); } static void wf_rail_notify_icon_common(rdpContext* context, WINDOW_ORDER_INFO* orderInfo, NOTIFY_ICON_STATE_ORDER* notifyIconState) @@ -793,7 +794,7 @@ static void wf_rail_notify_icon_create(rdpContext* context, WINDOW_ORDER_INFO* o wfContext* wfc = (wfContext*) context; RailClientContext* rail = wfc->rail; - fprintf(stderr, "RailNotifyIconCreate\n"); + WLog_DBG(TAG, "RailNotifyIconCreate"); wf_rail_notify_icon_common(context, orderInfo, notifyIconState); } @@ -803,7 +804,7 @@ static void wf_rail_notify_icon_update(rdpContext* context, WINDOW_ORDER_INFO* o wfContext* wfc = (wfContext*) context; RailClientContext* rail = wfc->rail; - fprintf(stderr, "RailNotifyIconUpdate\n"); + WLog_DBG(TAG, "RailNotifyIconUpdate"); wf_rail_notify_icon_common(context, orderInfo, notifyIconState); } @@ -813,7 +814,7 @@ static void wf_rail_notify_icon_delete(rdpContext* context, WINDOW_ORDER_INFO* o wfContext* wfc = (wfContext*) context; RailClientContext* rail = wfc->rail; - fprintf(stderr, "RailNotifyIconDelete\n"); + WLog_DBG(TAG, "RailNotifyIconDelete"); } static void wf_rail_monitored_desktop(rdpContext* context, WINDOW_ORDER_INFO* orderInfo, MONITORED_DESKTOP_ORDER* monitoredDesktop) @@ -821,7 +822,7 @@ static void wf_rail_monitored_desktop(rdpContext* context, WINDOW_ORDER_INFO* or wfContext* wfc = (wfContext*) context; RailClientContext* rail = wfc->rail; - fprintf(stderr, "RailMonitorDesktop\n"); + WLog_DBG(TAG, "RailMonitorDesktop"); } static void wf_rail_non_monitored_desktop(rdpContext* context, WINDOW_ORDER_INFO* orderInfo) @@ -829,7 +830,7 @@ static void wf_rail_non_monitored_desktop(rdpContext* context, WINDOW_ORDER_INFO wfContext* wfc = (wfContext*) context; RailClientContext* rail = wfc->rail; - fprintf(stderr, "RailNonMonitorDesktop\n"); + WLog_DBG(TAG, "RailNonMonitorDesktop"); } void wf_rail_register_update_callbacks(rdpUpdate* update) @@ -852,7 +853,7 @@ void wf_rail_register_update_callbacks(rdpUpdate* update) static int wf_rail_server_execute_result(RailClientContext* context, RAIL_EXEC_RESULT_ORDER* execResult) { - fprintf(stderr, "RailServerExecuteResult: 0x%04X\n", execResult->rawResult); + WLog_DBG(TAG, "RailServerExecuteResult: 0x%04X", execResult->rawResult); return 1; } diff --git a/libfreerdp/codec/color.c b/libfreerdp/codec/color.c index d8d565cc4..c663a25a2 100644 --- a/libfreerdp/codec/color.c +++ b/libfreerdp/codec/color.c @@ -28,10 +28,13 @@ #include #include +#include #include #include #include +#define TAG FREERDP_TAG("color") + int freerdp_get_pixel(BYTE* data, int x, int y, int width, int height, int bpp) { int start; @@ -1372,7 +1375,7 @@ int freerdp_image_copy_from_monochrome(BYTE* pDstData, UINT32 DstFormat, int nDs return 1; } - fprintf(stderr, "freerdp_image_copy_from_monochrome failure: dstBytesPerPixel: %d dstBitsPerPixel: %d\n", + WLog_ERR(TAG, "failure: dstBytesPerPixel: %d dstBitsPerPixel: %d", dstBytesPerPixel, dstBitsPerPixel); return -1; @@ -1563,7 +1566,7 @@ int freerdp_image_copy_from_pointer_data(BYTE* pDstData, UINT32 DstFormat, int n } } - fprintf(stderr, "freerdp_image_copy_from_pointer_data: failed to convert from %d bpp to %d bpp\n", + WLog_ERR(TAG, "failed to convert from %d bpp to %d bpp", xorBpp, dstBitsPerPixel); return -1; @@ -3312,7 +3315,7 @@ int freerdp_image_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(DstFormat); dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(DstFormat) / 8); - fprintf(stderr, "freerdp_image_copy failure: src: %d/%d dst: %d/%d\n", + WLog_ERR(TAG, "failure: src: %d/%d dst: %d/%d", srcBitsPerPixel, srcBytesPerPixel, dstBitsPerPixel, dstBytesPerPixel); } diff --git a/libfreerdp/codec/interleaved.c b/libfreerdp/codec/interleaved.c index 58b69f68d..499386771 100644 --- a/libfreerdp/codec/interleaved.c +++ b/libfreerdp/codec/interleaved.c @@ -22,6 +22,9 @@ #endif #include +#include + +#define TAG FREERDP_TAG("codec") /* RLE Compressed Bitmap Stream (RLE_BITMAP_STREAM) @@ -363,13 +366,13 @@ int interleaved_compress(BITMAP_INTERLEAVED_CONTEXT* interleaved, BYTE* pDstData if (nWidth % 4) { - fprintf(stderr, "interleaved_compress: width is not a multiple of 4\n"); + WLog_ERR(TAG, "interleaved_compress: width is not a multiple of 4"); return -1; } if ((nWidth > 64) || (nHeight > 64)) { - fprintf(stderr, "interleaved_compress: width (%d) or height (%d) is greater than 64\n", nWidth, nHeight); + WLog_ERR(TAG, "interleaved_compress: width (%d) or height (%d) is greater than 64", nWidth, nHeight); return -1; } diff --git a/libfreerdp/core/capabilities.c b/libfreerdp/core/capabilities.c index 11336c8c3..726ab5a5f 100644 --- a/libfreerdp/core/capabilities.c +++ b/libfreerdp/core/capabilities.c @@ -2731,7 +2731,7 @@ BOOL rdp_read_bitmap_codecs_capability_set(wStream* s, UINT16 length, rdpSetting if (Stream_GetPosition(s) != end) { - fprintf(stderr, "error while reading codec properties: actual offset: %d expected offset: %d\n", + WLog_ERR(TAG, "error while reading codec properties: actual offset: %d expected offset: %d", (int) Stream_GetPosition(s), end); Stream_SetPosition(s, end); } diff --git a/libfreerdp/core/tcp.c b/libfreerdp/core/tcp.c index ee3331031..dd6f1d5c9 100644 --- a/libfreerdp/core/tcp.c +++ b/libfreerdp/core/tcp.c @@ -603,7 +603,7 @@ BOOL tcp_connect(rdpTcp* tcp, const char* hostname, int port, int timeout) status = getaddrinfo(hostname, port_str, &hints, &result); if (status) { - fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status)); + WLog_ERR(TAG, "getaddrinfo: %s", gai_strerror(status)); return FALSE; } @@ -627,7 +627,7 @@ BOOL tcp_connect(rdpTcp* tcp, const char* hostname, int port, int timeout) } if (connect(tcp->sockfd, tmp->ai_addr, tmp->ai_addrlen) < 0) { - fprintf(stderr, "connect: %s\n", strerror(errno)); + WLog_ERR(TAG, "connect: %s", strerror(errno)); freeaddrinfo(result); return FALSE; } diff --git a/rdtk/sample/rdtk_x11.c b/rdtk/sample/rdtk_x11.c index 27c81fe40..2e115ee94 100644 --- a/rdtk/sample/rdtk_x11.c +++ b/rdtk/sample/rdtk_x11.c @@ -20,10 +20,13 @@ #include "config.h" #endif +#include #include #include +#define TAG "rdtk.sample" + int main(int argc, char** argv) { GC gc; @@ -56,7 +59,7 @@ int main(int argc, char** argv) if (!display) { - fprintf(stderr, "Cannot open display\n"); + WLog_ERR(TAG, "Cannot open display"); exit(1); } diff --git a/server/shadow/X11/x11_shadow.c b/server/shadow/X11/x11_shadow.c index 3f1a96408..2029ca940 100644 --- a/server/shadow/X11/x11_shadow.c +++ b/server/shadow/X11/x11_shadow.c @@ -171,7 +171,7 @@ int x11_shadow_pam_authenticate(x11ShadowSubsystem* subsystem, const char* user, if (pam_status != PAM_SUCCESS) { - fprintf(stderr, "pam_start failure: %s\n", pam_strerror(info->handle, pam_status)); + WLog_ERR(TAG, "pam_start failure: %s", pam_strerror(info->handle, pam_status)); free(info); return -1; } @@ -180,7 +180,7 @@ int x11_shadow_pam_authenticate(x11ShadowSubsystem* subsystem, const char* user, if (pam_status != PAM_SUCCESS) { - fprintf(stderr, "pam_authenticate failure: %s\n", pam_strerror(info->handle, pam_status)); + WLog_ERR(TAG, "pam_authenticate failure: %s", pam_strerror(info->handle, pam_status)); free(info); return -1; } @@ -189,7 +189,7 @@ int x11_shadow_pam_authenticate(x11ShadowSubsystem* subsystem, const char* user, if (pam_status != PAM_SUCCESS) { - fprintf(stderr, "pam_acct_mgmt failure: %s\n", pam_strerror(info->handle, pam_status)); + WLog_ERR(TAG, "pam_acct_mgmt failure: %s", pam_strerror(info->handle, pam_status)); free(info); return -1; } @@ -1133,7 +1133,7 @@ int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem) if ((subsystem->depth != 24) && (subsystem->depth != 32)) { - fprintf(stderr, "x11_shadow_subsystem_init: unsupported X11 server color depth: %d\n", subsystem->depth); + WLog_ERR(TAG, "unsupported X11 server color depth: %d", subsystem->depth); return -1; } diff --git a/winpr/libwinpr/wtsapi/wtsapi_win32.c b/winpr/libwinpr/wtsapi/wtsapi_win32.c index 9a0adc697..767620c09 100644 --- a/winpr/libwinpr/wtsapi/wtsapi_win32.c +++ b/winpr/libwinpr/wtsapi/wtsapi_win32.c @@ -22,6 +22,7 @@ #endif #include +#include #include #include #include @@ -33,6 +34,7 @@ #include "wtsapi.h" #define WTSAPI_CHANNEL_MAGIC 0x44484356 +#define TAG WINPR_TAG("wtsapi") struct _WTSAPI_CHANNEL { @@ -108,13 +110,13 @@ BOOL Win32_WTSVirtualChannelReadAsync(WTSAPI_CHANNEL* pChannel) if (status) { - fprintf(stderr, "Unexpected ReadFile status: %d numBytes: %d\n", status, numBytes); + WLog_ERR(TAG, "Unexpected ReadFile status: %d numBytes: %d", status, numBytes); return FALSE; /* ReadFile should return FALSE and set ERROR_IO_PENDING */ } if (GetLastError() != ERROR_IO_PENDING) { - fprintf(stderr, "ReadFile: GetLastError() = %d\n", GetLastError()); + WLog_ERR(TAG, "ReadFile: GetLastError() = %d", GetLastError()); return FALSE; } From 7697eafa022c9b4ca46f95bbdb730db268cf81b2 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Sun, 16 Nov 2014 13:59:04 +0100 Subject: [PATCH 3/6] Fixed callback appender setup. --- winpr/libwinpr/utils/wlog/CallbackAppender.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/winpr/libwinpr/utils/wlog/CallbackAppender.c b/winpr/libwinpr/utils/wlog/CallbackAppender.c index 3c0cce7e9..1e6a60792 100644 --- a/winpr/libwinpr/utils/wlog/CallbackAppender.c +++ b/winpr/libwinpr/utils/wlog/CallbackAppender.c @@ -47,6 +47,7 @@ WINPR_API void WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppende appender->message = msg; appender->image = img; appender->package = pkg; + appender->data = data; } int WLog_CallbackAppender_Open(wLog* log, wLogCallbackAppender* appender) @@ -130,7 +131,7 @@ wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log) { ZeroMemory(CallbackAppender, sizeof(wLogCallbackAppender)); - CallbackAppender->Type = WLOG_APPENDER_CONSOLE; + CallbackAppender->Type = WLOG_APPENDER_CALLBACK; CallbackAppender->Open = (WLOG_APPENDER_OPEN_FN) WLog_CallbackAppender_Open; CallbackAppender->Close = (WLOG_APPENDER_OPEN_FN) WLog_CallbackAppender_Close; @@ -147,6 +148,7 @@ wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log) CallbackAppender->message = NULL; CallbackAppender->image = NULL; CallbackAppender->package = NULL; + CallbackAppender->data = NULL; } return CallbackAppender; From 1b6cb6349e1b7db3c52f1674dda830a717d440d8 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Sun, 16 Nov 2014 13:59:12 +0100 Subject: [PATCH 4/6] Added unit test for callback wlog appender. --- winpr/libwinpr/utils/test/CMakeLists.txt | 1 + winpr/libwinpr/utils/test/TestWLogCallback.c | 129 +++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 winpr/libwinpr/utils/test/TestWLogCallback.c diff --git a/winpr/libwinpr/utils/test/CMakeLists.txt b/winpr/libwinpr/utils/test/CMakeLists.txt index 199780d9b..739d7126b 100644 --- a/winpr/libwinpr/utils/test/CMakeLists.txt +++ b/winpr/libwinpr/utils/test/CMakeLists.txt @@ -16,6 +16,7 @@ set(${MODULE_PREFIX}_TESTS TestListDictionary.c TestCmdLine.c TestWLog.c + TestWLogCallback.c TestHashTable.c TestBufferPool.c TestStreamPool.c diff --git a/winpr/libwinpr/utils/test/TestWLogCallback.c b/winpr/libwinpr/utils/test/TestWLogCallback.c new file mode 100644 index 000000000..2a6f8bb30 --- /dev/null +++ b/winpr/libwinpr/utils/test/TestWLogCallback.c @@ -0,0 +1,129 @@ + +#include +#include +#include +#include + +typedef struct +{ + int level; + char *msg; + char *channel; +} test_t; + + +static const char *function = NULL; +static const char *channels[] = +{ + "com.test.channelA", + "com.test.channelB" +}; + +static const test_t messages[] = +{ + {WLOG_INFO, "this is a test", "com.test.channelA"}, + {WLOG_INFO, "Just some info", "com.test.channelB"}, + {WLOG_WARN, "this is a %dnd %s", "com.test.channelA"}, + {WLOG_WARN, "we're warning a %dnd %s", "com.test.channelB"}, + {WLOG_ERROR, "this is an error", "com.test.channelA"}, + {WLOG_ERROR, "we've got an error", "com.test.channelB"}, + {WLOG_TRACE, "this is a trace output", "com.test.channelA"}, + {WLOG_TRACE, "leaving a trace behind", "com.test.channelB"} +}; + +static BOOL success = TRUE; +static int pos = 0; + +static BOOL check(const wLogMessage *msg) +{ + BOOL rc = TRUE; + if (!msg) + rc = FALSE; + else if (strcmp(msg->FileName, __FILE__)) + rc = FALSE; + else if (strcmp(msg->FunctionName, function)) + rc = FALSE; + else if (strcmp(msg->PrefixString, messages[pos].channel)) + rc = FALSE; + else if (msg->Level != messages[pos].level) + rc = FALSE; + else if (strcmp(msg->FormatString, messages[pos].msg)) + rc = FALSE; + pos++; + + if (!rc) + { + fprintf(stderr, "Test failed!\n"); + success = FALSE; + } + return rc; +} + +void CallbackAppenderMessage(const wLogMessage *msg) +{ + check(msg); +} + +void CallbackAppenderData(const wLogMessage *msg) +{ + fprintf(stdout, "%s\n", __FUNCTION__); +} + +void CallbackAppenderImage(const wLogMessage *msg) +{ + fprintf(stdout, "%s\n", __FUNCTION__); +} + +void CallbackAppenderPackage(const wLogMessage *msg) +{ + fprintf(stdout, "%s\n", __FUNCTION__); +} + +int TestWLogCallback(int argc, char* argv[]) +{ + wLog* root; + wLog* logA; + wLog* logB; + wLogLayout* layout; + wLogAppender* appender; + + function = __FUNCTION__; + WLog_Init(); + + root = WLog_GetRoot(); + + WLog_SetLogAppenderType(root, WLOG_APPENDER_CALLBACK); + + appender = WLog_GetLogAppender(root); + + WLog_CallbackAppender_SetCallbacks(root, (wLogCallbackAppender*) appender, + CallbackAppenderMessage, CallbackAppenderImage, CallbackAppenderPackage, + CallbackAppenderData); + + layout = WLog_GetLogLayout(root); + WLog_Layout_SetPrefixFormat(root, layout, "%mn"); + + WLog_OpenAppender(root); + + logA = WLog_Get(channels[0]); + logB = WLog_Get(channels[1]); + + WLog_SetLogLevel(logA, WLOG_TRACE); + WLog_SetLogLevel(logB, WLOG_TRACE); + + WLog_Print(logA, messages[0].level, messages[0].msg); + WLog_Print(logB, messages[1].level, messages[1].msg); + WLog_Print(logA, messages[2].level, messages[2].msg, 2, "test"); + WLog_Print(logB, messages[3].level, messages[3].msg, 2, "time"); + WLog_Print(logA, messages[4].level, messages[4].msg); + WLog_Print(logB, messages[5].level, messages[5].msg); + WLog_Print(logA, messages[6].level, messages[6].msg); + WLog_Print(logB, messages[7].level, messages[7].msg); + + WLog_CloseAppender(root); + + WLog_Uninit(); + + return success ? 0 : -1; +} + From 643a309537c888495c6e931f2d7ed5e6d0f769f8 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Sun, 16 Nov 2014 14:40:30 +0100 Subject: [PATCH 5/6] Fixed memory leak. --- winpr/libwinpr/utils/wlog/wlog.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/winpr/libwinpr/utils/wlog/wlog.c b/winpr/libwinpr/utils/wlog/wlog.c index 34dc579a0..ca7d52be1 100644 --- a/winpr/libwinpr/utils/wlog/wlog.c +++ b/winpr/libwinpr/utils/wlog/wlog.c @@ -402,14 +402,20 @@ int WLog_ParseFilters() g_Filters = calloc(g_FilterCount, sizeof(wLogFilter)); if (!g_Filters) + { + free(strs); return -1; + } for (count = 0; count < g_FilterCount; count++) { status = WLog_ParseFilter(&g_Filters[count], strs[count]); if (status < 0) + { + free(strs); return -1; + } } free(strs); From c3f47128db5e2f9de786b4abb29afdfa2356db64 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 17 Nov 2014 01:39:45 +0100 Subject: [PATCH 6/6] Fixed header include. --- winpr/libwinpr/wtsapi/wtsapi_win32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winpr/libwinpr/wtsapi/wtsapi_win32.c b/winpr/libwinpr/wtsapi/wtsapi_win32.c index 767620c09..b114b41bb 100644 --- a/winpr/libwinpr/wtsapi/wtsapi_win32.c +++ b/winpr/libwinpr/wtsapi/wtsapi_win32.c @@ -22,7 +22,6 @@ #endif #include -#include #include #include #include @@ -32,6 +31,7 @@ #include "wtsapi_win32.h" #include "wtsapi.h" +#include "../log.h" #define WTSAPI_CHANNEL_MAGIC 0x44484356 #define TAG WINPR_TAG("wtsapi")