@@ -52,17 +52,64 @@ static inline int pack_line(struct flb_syslog *ctx,
52
52
return 0 ;
53
53
}
54
54
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
+
55
107
int syslog_prot_process (struct syslog_conn * conn )
56
108
{
57
109
int len ;
58
- int ret ;
59
110
char * p ;
60
111
char * eof ;
61
112
char * end ;
62
- void * out_buf ;
63
- size_t out_size ;
64
- struct flb_time out_time ;
65
- struct flb_syslog * ctx = conn -> ctx ;
66
113
67
114
eof = conn -> buf_data ;
68
115
end = conn -> buf_data + conn -> buf_len ;
@@ -96,21 +143,7 @@ int syslog_prot_process(struct syslog_conn *conn)
96
143
continue ;
97
144
}
98
145
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 );
114
147
115
148
conn -> buf_parsed += len + 1 ;
116
149
end = conn -> buf_data + conn -> buf_len ;
@@ -129,27 +162,5 @@ int syslog_prot_process(struct syslog_conn *conn)
129
162
130
163
int syslog_prot_process_udp (char * buf , size_t size , struct flb_syslog * ctx )
131
164
{
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 );
155
166
}
0 commit comments