aboutsummaryrefslogtreecommitdiffstats
path: root/daemon/syslogd.c
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/syslogd.c')
-rw-r--r--daemon/syslogd.c53
1 files changed, 40 insertions, 13 deletions
diff --git a/daemon/syslogd.c b/daemon/syslogd.c
index e4467b3..0a3b2b6 100644
--- a/daemon/syslogd.c
+++ b/daemon/syslogd.c
@@ -180,6 +180,30 @@ done:
}
/******************************************************************************
+ * try_convert_string
+ *
+ * helper function for mux_message;
+ * try to convert encoding, return reference to the original string in case
+ * of failure
+ */
+static struct string* try_convert_string( struct string* s, GIConv cd )
+{
+ struct string *ret;
+ gchar *converted_str;
+
+ converted_str = g_convert_with_iconv( s->gstr->str, -1, cd, NULL, NULL, NULL );
+ if( !converted_str )
+ {
+ TRACE( "conversion error\n" );
+ return string_addref( s );
+ }
+
+ ret = string_new( converted_str );
+ g_free( converted_str );
+ return ret;
+}
+
+/******************************************************************************
* mux_message
*
* filter and multiplex message to destinations;
@@ -194,6 +218,7 @@ static void mux_message( struct message* msg )
for( item = logpaths; item; item = item->next )
{
struct logpath *logpath = item->data;
+ gboolean need_message_iconv, need_program_iconv;
struct message *converted_msg;
if( logpath->source != msg->source )
@@ -202,27 +227,29 @@ static void mux_message( struct message* msg )
if( !filter_message( msg, logpath->filter ) )
continue;
- /* convert message encoding if needed */
- if( logpath->message_cd == (GIConv) -1 )
+ /* convert encoding if needed */
+ need_message_iconv = logpath->message_cd != (GIConv) -1;
+ need_program_iconv = logpath->program_cd != (GIConv) -1;
+
+ if( (!need_message_iconv) && (!need_program_iconv) )
{
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 )
+ converted_msg = duplicate_message( msg );
+
+ if( need_message_iconv )
{
- TRACE( "conversion error\n" );
- c_message = g_strdup( msg->message->gstr->str );
+ string_release( converted_msg->message );
+ converted_msg->message = try_convert_string( msg->message, logpath->message_cd );
+ }
+ if( need_program_iconv )
+ {
+ string_release( converted_msg->program );
+ converted_msg->program = try_convert_string( msg->program, logpath->program_cd );
}
-
- 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 */