2020
2121#include <fluent-bit/flb_info.h>
2222#include <fluent-bit/flb_input_plugin.h>
23-
23+ #ifdef FLB_HAVE_ICONV
24+ #include <fluent-bit/flb_iconv.h>
25+ #endif
2426#include <stdlib.h>
2527#include <fcntl.h>
2628
@@ -42,6 +44,10 @@ struct flb_tail_config *flb_tail_config_create(struct flb_input_instance *ins,
4244 int i ;
4345 long nsec ;
4446 const char * tmp ;
47+ ssize_t bytes ;
48+ #ifdef FLB_HAVE_ICONV
49+ char * tmp2 ;
50+ #endif
4551 struct flb_tail_config * ctx ;
4652
4753 ctx = flb_calloc (1 , sizeof (struct flb_tail_config ));
@@ -237,6 +243,27 @@ struct flb_tail_config *flb_tail_config_create(struct flb_input_instance *ins,
237243 }
238244#endif
239245
246+ #ifdef FLB_HAVE_ICONV
247+ tmp = flb_input_get_property ("from_encoding" , i_ins );
248+ tmp2 = flb_input_get_property ("encoding" , i_ins );
249+ if (tmp ) {
250+ if (!tmp2 ) {
251+ tmp2 = "UTF8" ;
252+ } else if (!strcasecmp (tmp2 ,"default" )) {
253+ tmp2 = "" ;
254+ }
255+ if (!strcasecmp (tmp ,"default" )) {
256+ tmp = "" ;
257+ }
258+ ctx -> iconvert = flb_iconv_open (tmp2 ,tmp );
259+ if (ctx -> iconvert == NULL ) {
260+ flb_error ("[in_tail] cannot init iconv: '%s'=>'%s'" , tmp , tmp2 );
261+ }
262+ } else {
263+ ctx -> iconvert = NULL ;
264+ }
265+ #endif
266+
240267#ifdef FLB_HAVE_METRICS
241268 flb_metrics_add (FLB_TAIL_METRIC_F_OPENED ,
242269 "files_opened" , ctx -> ins -> metrics );
@@ -268,7 +295,13 @@ int flb_tail_config_destroy(struct flb_tail_config *config)
268295 }
269296#endif
270297
271- #ifdef FLB_HAVE_SQLDB
298+ #ifdef FLB_HAVE_ICONV
299+ if (config -> iconvert ) {
300+ iconv_close (config -> iconvert );
301+ }
302+ #endif
303+
304+ #ifdef FLB_HAVE_SQLDB
272305 if (config -> db != NULL ) {
273306 flb_tail_db_close (config -> db );
274307 }
0 commit comments