diff options
-rw-r--r-- | src/log/log.c | 54 | ||||
-rw-r--r-- | tests/log/testmsg.mc | 2 |
2 files changed, 38 insertions, 18 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 */ } diff --git a/tests/log/testmsg.mc b/tests/log/testmsg.mc index 4d40944..606138c 100644 --- a/tests/log/testmsg.mc +++ b/tests/log/testmsg.mc @@ -57,7 +57,7 @@ Severity = Error Facility = Application SymbolicName = WOLF_CATEGORY_TEST_LOG_MSG1 Language = English -This is error %d +This is error %1 . MessageId = 3002 |