summaryrefslogtreecommitdiff
path: root/src/log
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2009-03-21 22:03:40 +0100
committerAndreas Baumann <abaumann@yahoo.com>2009-03-21 22:03:40 +0100
commitf03c11b4d7767a70ea2e2bd5c4e6598ae48136b1 (patch)
tree8b036e977a18f40e0da92c2d1164ce86112558f5 /src/log
parent1f813417045b0417b3ed7a18a1f9433c06865b2d (diff)
downloadwolfbones-f03c11b4d7767a70ea2e2bd5c4e6598ae48136b1.tar.gz
wolfbones-f03c11b4d7767a70ea2e2bd5c4e6598ae48136b1.tar.bz2
started to handle the error log parameters
Diffstat (limited to 'src/log')
-rw-r--r--src/log/log.c54
1 files changed, 37 insertions, 17 deletions
diff --git a/src/log/log.c b/src/log/log.c
index 383e14d..eac60e1 100644
--- a/src/log/log.c
+++ b/src/log/log.c
@@ -560,6 +560,28 @@ static PSID get_current_sid( void ) {
return sid;
}
+static int compute_nof_placeholders( const char *format ) {
+ char *c;
+ int nof_placeholders;
+
+ for( c = format, nof_placeholders = 0; *c != '\0'; c++ )
+ if( *c == '%' )
+ nof_placeholders++;
+
+ return nof_placeholders;
+}
+
+static void map_placeholders_to_strings( const char *format,
+ int nof_placeholders,
+ LPSTR *msg_arr,
+ va_list ap ) {
+ int i;
+
+ for( i = 0; i < nof_placeholders; i++ ) {
+ msg_arr[i] = "Param 1";
+ }
+}
+
void wolf_log_openlogtoeventlog( const char *server,
const char *log,
const char *source,
@@ -698,20 +720,16 @@ void wolf_log( wolf_log_level_t level, int category_id, int message_id, const ch
#if defined HAVE_EVENTLOG
if( level <= eventlog_level && event_source != 0 ) {
- /* for now we map the snprintf-like format directly
- * to one message string for event ID 0 (actually as
- * most others like the .NET guys are doing! This
- * is a bit TODO!)
+ /* parse C-snprintf-like format string, map the placeholders
+ * there to normal strings, then add them to a string array
*/
- LPCTSTR msg_arr[2];
-
- /* compose the message and the parameters */
- msg_arr[0] = wolf_log_level_to_str( level );
- msg_arr[1] = s;
+ va_list ap;
+ int nof_placeholders = compute_nof_placeholders( format );
+ LPSTR *msg_arr = (LPSTR *)malloc( sizeof( LPCTSTR ) * nof_placeholders );
+ va_start( ap, format );
+ va_end( ap );
+ map_placeholders_to_strings( format, nof_placeholders, msg_arr, ap );
- /* TODO: event categories and type, message numbers,
- * resources for message DLLs etc. etc. etc.
- */
if( !ReportEvent(
event_source, /* event source handle */
wolf_log_level_to_eventlog_type( level ),
@@ -719,16 +737,18 @@ void wolf_log( wolf_log_level_t level, int category_id, int message_id, const ch
wolf_log_event_id_to_eventlog_event_id(
wolf_log_level_to_eventlog_type( level ),
message_id ),
- sid, /* the security identifier */
- 2, /* at the moment only one string */
- 0, /* no binary raw data */
- msg_arr, /* the array of strings */
- NULL /* no binary raw data */
+ sid, /* the security identifier */
+ nof_placeholders, /* at the moment only one string */
+ 0, /* no binary raw data */
+ msg_arr, /* the array of strings */
+ NULL /* no binary raw data */
) ) {
/* TODO: add GetLastError here! */
fprintf( stderr, "%s: Unable to log to event log\n",
wolf_log_level_to_str( WOLF_LOG_ALERT ) );
}
+
+ free( (LPSTR *)msg_arr );
}
#endif /* defined HAVE_EVENTLOG */
}