From e7be81dd66bc4d19ff8552b81aa38821eeb9f457 Mon Sep 17 00:00:00 2001 From: yaworsky Date: Mon, 28 Nov 2005 14:03:41 +0000 Subject: Implemented charset conversion in each log path. Fixed bugs in configuration reader. --- daemon/syslogd.c | 75 ++++++++++++++++++++------------------------------------ 1 file changed, 27 insertions(+), 48 deletions(-) (limited to 'daemon/syslogd.c') diff --git a/daemon/syslogd.c b/daemon/syslogd.c index 99e9a92..e4467b3 100644 --- a/daemon/syslogd.c +++ b/daemon/syslogd.c @@ -46,8 +46,6 @@ static GList *hostnames = NULL; #define HOSTNAME_LIFETIME 60 /* seconds */ /* FIXME: is this value correct? maybe we should make it configurable? */ -static GIConv conversion_descriptor = (GIConv) -1; - char *str_month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; @@ -150,36 +148,6 @@ void release_message( struct message* msg ) TRACE_LEAVE( "done\n" ); } -/****************************************************************************** - * convert_message_encoding - */ -static void convert_message_encoding( struct message* msg ) -{ - gchar *converted_msg; - - TRACE_ENTER( "message=%p\n", msg ); - - if( conversion_descriptor == (GIConv) -1 ) - { - TRACE_LEAVE( "nothing to do\n" ); - return; - } - - converted_msg = g_convert_with_iconv( msg->message->gstr->str, -1, - conversion_descriptor, NULL, NULL, NULL ); - if( !converted_msg ) - { - TRACE_LEAVE( "conversion error\n" ); - return; - } - - string_release( msg->message ); - msg->message = string_new( converted_msg ); - g_free( converted_msg ); - - TRACE_LEAVE( "done; %s\n", msg->message->gstr->str ); -} - /****************************************************************************** * filter_message * @@ -223,11 +191,10 @@ static void mux_message( struct message* msg ) TRACE_ENTER( "message=%p\n", msg ); - convert_message_encoding( msg ); - for( item = logpaths; item; item = item->next ) { struct logpath *logpath = item->data; + struct message *converted_msg; if( logpath->source != msg->source ) continue; @@ -235,7 +202,32 @@ static void mux_message( struct message* msg ) if( !filter_message( msg, logpath->filter ) ) continue; - logpath->destination->put( logpath->destination, msg ); + /* convert message encoding if needed */ + if( logpath->message_cd == (GIConv) -1 ) + { + converted_msg = msg; + reference_message( msg ); + } + else + { + gchar *c_message = g_convert_with_iconv( msg->message->gstr->str, -1, + logpath->message_cd, + NULL, NULL, NULL ); + if( !c_message ) + { + TRACE( "conversion error\n" ); + c_message = g_strdup( msg->message->gstr->str ); + } + + converted_msg = duplicate_message( msg ); + string_release( converted_msg->message ); + converted_msg->message = string_new( c_message ); + g_free( c_message ); + } + + /* put message to destination */ + logpath->destination->put( logpath->destination, converted_msg ); + release_message( converted_msg ); } release_message( msg ); @@ -825,16 +817,6 @@ void syslogd_main() if( !init_udp_listener() ) goto done; - if( source_encoding && destination_encoding ) - { - conversion_descriptor = g_iconv_open( destination_encoding, source_encoding ); - if( conversion_descriptor == (GIConv) -1 ) - { - ERR( "Cannot convert messages from %s to %s\n", - source_encoding, destination_encoding ); - } - } - log_internal( LOG_NOTICE, "Syslog daemon started" ); /* get messages from queues */ @@ -959,8 +941,5 @@ done: fini_purger(); free_hostnames(); - if( conversion_descriptor != (GIConv) -1 ) - g_iconv_close( conversion_descriptor ); - TRACE_LEAVE( "done\n" ); } -- cgit v1.2.3