20 #include <winpr/config.h>
22 #include "CallbackAppender.h"
26 WLOG_APPENDER_COMMON();
29 } wLogCallbackAppender;
31 static BOOL WLog_CallbackAppender_Open(wLog* log, wLogAppender* appender)
36 static BOOL WLog_CallbackAppender_Close(wLog* log, wLogAppender* appender)
41 static BOOL WLog_CallbackAppender_WriteMessage(wLog* log, wLogAppender* appender,
44 char prefix[WLOG_MAX_PREFIX_SIZE] = { 0 };
45 wLogCallbackAppender* callbackAppender = NULL;
50 message->PrefixString = prefix;
51 WLog_Layout_GetMessagePrefix(log, appender->Layout, message);
53 callbackAppender = (wLogCallbackAppender*)appender;
55 if (callbackAppender->callbacks && callbackAppender->callbacks->message)
56 return callbackAppender->callbacks->message(message);
61 static BOOL WLog_CallbackAppender_WriteDataMessage(wLog* log, wLogAppender* appender,
64 char prefix[WLOG_MAX_PREFIX_SIZE] = { 0 };
65 wLogCallbackAppender* callbackAppender = NULL;
70 message->PrefixString = prefix;
71 WLog_Layout_GetMessagePrefix(log, appender->Layout, message);
73 callbackAppender = (wLogCallbackAppender*)appender;
74 if (callbackAppender->callbacks && callbackAppender->callbacks->data)
75 return callbackAppender->callbacks->data(message);
80 static BOOL WLog_CallbackAppender_WriteImageMessage(wLog* log, wLogAppender* appender,
83 char prefix[WLOG_MAX_PREFIX_SIZE] = { 0 };
84 wLogCallbackAppender* callbackAppender = NULL;
89 message->PrefixString = prefix;
90 WLog_Layout_GetMessagePrefix(log, appender->Layout, message);
92 callbackAppender = (wLogCallbackAppender*)appender;
93 if (callbackAppender->callbacks && callbackAppender->callbacks->image)
94 return callbackAppender->callbacks->image(message);
99 static BOOL WLog_CallbackAppender_WritePacketMessage(wLog* log, wLogAppender* appender,
102 char prefix[WLOG_MAX_PREFIX_SIZE] = { 0 };
103 wLogCallbackAppender* callbackAppender = NULL;
108 message->PrefixString = prefix;
109 WLog_Layout_GetMessagePrefix(log, appender->Layout, message);
111 callbackAppender = (wLogCallbackAppender*)appender;
112 if (callbackAppender->callbacks && callbackAppender->callbacks->package)
113 return callbackAppender->callbacks->package(message);
118 static BOOL WLog_CallbackAppender_Set(wLogAppender* appender,
const char* setting,
void* value)
120 wLogCallbackAppender* callbackAppender = (wLogCallbackAppender*)appender;
122 if (!value || (strcmp(setting,
"callbacks") != 0))
125 if (!(callbackAppender->callbacks = calloc(1,
sizeof(
wLogCallbacks))))
130 callbackAppender->callbacks = memcpy(callbackAppender->callbacks, value,
sizeof(
wLogCallbacks));
134 static void WLog_CallbackAppender_Free(wLogAppender* appender)
136 wLogCallbackAppender* callbackAppender = NULL;
142 callbackAppender = (wLogCallbackAppender*)appender;
144 free(callbackAppender->callbacks);
148 wLogAppender* WLog_CallbackAppender_New(wLog* log)
150 wLogCallbackAppender* CallbackAppender = NULL;
152 CallbackAppender = (wLogCallbackAppender*)calloc(1,
sizeof(wLogCallbackAppender));
153 if (!CallbackAppender)
156 CallbackAppender->Type = WLOG_APPENDER_CALLBACK;
158 CallbackAppender->Open = WLog_CallbackAppender_Open;
159 CallbackAppender->Close = WLog_CallbackAppender_Close;
160 CallbackAppender->WriteMessage = WLog_CallbackAppender_WriteMessage;
161 CallbackAppender->WriteDataMessage = WLog_CallbackAppender_WriteDataMessage;
162 CallbackAppender->WriteImageMessage = WLog_CallbackAppender_WriteImageMessage;
163 CallbackAppender->WritePacketMessage = WLog_CallbackAppender_WritePacketMessage;
164 CallbackAppender->Free = WLog_CallbackAppender_Free;
165 CallbackAppender->Set = WLog_CallbackAppender_Set;
167 return (wLogAppender*)CallbackAppender;