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, 41 insertions, 12 deletions
diff --git a/daemon/syslogd.c b/daemon/syslogd.c
index 5ff5401..6f981f1 100644
--- a/daemon/syslogd.c
+++ b/daemon/syslogd.c
@@ -83,8 +83,11 @@ struct message* create_message( struct source* source,
g_free( ts );
msg->hostname = string_addref( hostname );
+ msg->hostname_in_locale = string_addref( hostname );
msg->program = string_addref( program );
msg->message = string_addref( message );
+ msg->separator = string_addref( space );
+ msg->end_of_line = string_addref( line_feed );
TRACE_LEAVE( "message=%p\n", msg );
return msg;
@@ -109,8 +112,11 @@ struct message* duplicate_message( struct message* msg )
new_msg->priority = msg->priority;
new_msg->timestamp = string_addref( msg->timestamp );
new_msg->hostname = string_addref( msg->hostname );
+ new_msg->hostname_in_locale = string_addref( msg->hostname_in_locale );
new_msg->program = string_addref( msg->program );
new_msg->message = string_addref( msg->message );
+ new_msg->separator = string_addref( msg->separator );
+ new_msg->end_of_line = string_addref( msg->end_of_line );
TRACE_LEAVE( "new message=%p\n", new_msg );
return new_msg;
@@ -143,8 +149,11 @@ void release_message( struct message* msg )
string_release( msg->sender );
string_release( msg->timestamp );
string_release( msg->hostname );
+ string_release( msg->hostname_in_locale );
string_release( msg->program );
string_release( msg->message );
+ string_release( msg->separator );
+ string_release( msg->end_of_line );
g_free( msg );
TRACE_LEAVE( "done\n" );
}
@@ -223,10 +232,14 @@ static struct string* try_convert_string( struct string* s, GIConv cd )
{
case E2BIG:
/* guess the right output length */
- outbytes = inbytes_left *
- /* average size of destination char: */
- converted_str_len / (s->gstr->len - inbytes_left)
- + 16; /* if the result of above expression too small */
+ if( s->gstr->len > inbytes_left )
+ outbytes = inbytes_left *
+ /* average size of destination char: */
+ converted_str_len / (s->gstr->len - inbytes_left)
+ + 16; /* if the result of above expression too small */
+ else
+ /* cannot convert the first character; choose some initial value */
+ outbytes = 32;
converted_str_allocated += outbytes;
converted_str = g_realloc( converted_str, converted_str_allocated );
outbuf = converted_str + converted_str_len;
@@ -269,7 +282,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;
+ gboolean need_dest_iconv, need_locale_iconv;
struct message *converted_msg;
if( logpath->source != msg->source )
@@ -279,10 +292,10 @@ static void mux_message( struct message* msg )
continue;
/* convert encoding if needed */
- need_message_iconv = logpath->message_cd != (GIConv) -1;
- need_program_iconv = logpath->program_cd != (GIConv) -1;
+ need_dest_iconv = (logpath->src2dest_cd != (GIConv) -1) && (logpath->ascii2dest_cd != (GIConv) -1);
+ need_locale_iconv = logpath->src2locale_cd != (GIConv) -1;
- if( (!need_message_iconv) && (!need_program_iconv) )
+ if( (!need_dest_iconv) && (!need_locale_iconv) )
{
converted_msg = msg;
reference_message( msg );
@@ -291,15 +304,31 @@ static void mux_message( struct message* msg )
{
converted_msg = duplicate_message( msg );
- if( need_message_iconv )
+ if( need_dest_iconv )
{
+ string_release( converted_msg->timestamp );
+ converted_msg->timestamp = try_convert_string( msg->timestamp, logpath->ascii2dest_cd );
+
+ string_release( converted_msg->hostname );
+ converted_msg->hostname = try_convert_string( msg->hostname, logpath->src2dest_cd );
+
string_release( converted_msg->message );
- converted_msg->message = try_convert_string( msg->message, logpath->message_cd );
+ converted_msg->message = try_convert_string( msg->message, logpath->src2dest_cd );
+
+ string_release( converted_msg->separator );
+ converted_msg->separator = try_convert_string( msg->separator, logpath->ascii2dest_cd );
+
+ string_release( converted_msg->end_of_line );
+ converted_msg->end_of_line = try_convert_string( msg->end_of_line, logpath->ascii2dest_cd );
}
- if( need_program_iconv )
+ if( need_locale_iconv )
{
+ string_release( converted_msg->hostname_in_locale );
+ converted_msg->hostname_in_locale = try_convert_string( msg->hostname_in_locale,
+ logpath->src2locale_cd );
+
string_release( converted_msg->program );
- converted_msg->program = try_convert_string( msg->program, logpath->program_cd );
+ converted_msg->program = try_convert_string( msg->program, logpath->src2locale_cd );
}
}