@@ -52,17 +52,64 @@ static inline int pack_line(struct flb_syslog *ctx,
5252 return 0 ;
5353}
5454
55+
56+ int syslog_prot_process_msg (struct flb_syslog * ctx , char * p , size_t len )
57+ {
58+ int ret ;
59+ void * out_buf ;
60+ size_t out_size ;
61+ struct flb_time out_time ;
62+ #ifdef FLB_HAVE_UTF8_ENCODER
63+ char * decoded = NULL ;
64+ size_t decoded_size ;
65+ #endif
66+
67+ #ifdef FLB_HAVE_UTF8_ENCODER
68+ if (ctx -> encoding ) {
69+ ret = flb_encoding_decode (ctx -> encoding , p , len , & decoded , & decoded_size );
70+ if (ret != FLB_ENCODING_SUCCESS ) {
71+ flb_plg_error (ctx -> ins , "decoding failed '%.*s'" , p , len );
72+ goto finish ;
73+ }
74+ p = decoded ;
75+ len = decoded_size ;
76+ }
77+ #endif
78+
79+ /* Process the string */
80+ ret = flb_parser_do (ctx -> parser , p , len ,
81+ & out_buf , & out_size , & out_time );
82+ if (ret < 0 ) {
83+ flb_plg_warn (ctx -> ins , "error parsing log message with parser '%s'" ,
84+ ctx -> parser -> name );
85+ flb_plg_debug (ctx -> ins , "unparsed log message: %.*s" , len , p );
86+ goto finish ;
87+ }
88+
89+ if (flb_time_to_double (& out_time ) == 0.0 ) {
90+ flb_time_get (& out_time );
91+ }
92+
93+ pack_line (ctx , & out_time , out_buf , out_size );
94+ ret = 0 ;
95+
96+ finish :
97+
98+ #ifdef FLB_HAVE_UTF8_ENCODER
99+ if (decoded ) {
100+ flb_free (decoded );
101+ }
102+ #endif
103+ return ret ;
104+
105+ }
106+
55107int syslog_prot_process (struct syslog_conn * conn )
56108{
57109 int len ;
58- int ret ;
59110 char * p ;
60111 char * eof ;
61112 char * end ;
62- void * out_buf ;
63- size_t out_size ;
64- struct flb_time out_time ;
65- struct flb_syslog * ctx = conn -> ctx ;
66113
67114 eof = conn -> buf_data ;
68115 end = conn -> buf_data + conn -> buf_len ;
@@ -96,21 +143,7 @@ int syslog_prot_process(struct syslog_conn *conn)
96143 continue ;
97144 }
98145
99- /* Process the string */
100- ret = flb_parser_do (ctx -> parser , p , len ,
101- & out_buf , & out_size , & out_time );
102- if (ret >= 0 ) {
103- if (flb_time_to_double (& out_time ) == 0.0 ) {
104- flb_time_get (& out_time );
105- }
106- pack_line (ctx , & out_time , out_buf , out_size );
107- flb_free (out_buf );
108- }
109- else {
110- flb_plg_warn (ctx -> ins , "error parsing log message with parser '%s'" ,
111- ctx -> parser -> name );
112- flb_plg_debug (ctx -> ins , "unparsed log message: %.*s" , len , p );
113- }
146+ syslog_prot_process_msg (conn -> ctx , p , len );
114147
115148 conn -> buf_parsed += len + 1 ;
116149 end = conn -> buf_data + conn -> buf_len ;
@@ -129,27 +162,5 @@ int syslog_prot_process(struct syslog_conn *conn)
129162
130163int syslog_prot_process_udp (char * buf , size_t size , struct flb_syslog * ctx )
131164{
132- int ret ;
133- void * out_buf ;
134- size_t out_size ;
135- struct flb_time out_time = {0 };
136-
137- ret = flb_parser_do (ctx -> parser , buf , size ,
138- & out_buf , & out_size , & out_time );
139- if (ret >= 0 ) {
140- if (flb_time_to_double (& out_time ) == 0 ) {
141- flb_time_get (& out_time );
142- }
143- pack_line (ctx , & out_time , out_buf , out_size );
144- flb_free (out_buf );
145- }
146- else {
147- flb_plg_warn (ctx -> ins , "error parsing log message with parser '%s'" ,
148- ctx -> parser -> name );
149- flb_plg_debug (ctx -> ins , "unparsed log message: %.*s" ,
150- (int ) size , buf );
151- return -1 ;
152- }
153-
154- return 0 ;
165+ return syslog_prot_process_msg (ctx , buf , size );
155166}
0 commit comments