2323#include <fluent-bit/flb_info.h>
2424#include <fluent-bit/flb_log.h>
2525#include <fluent-bit/flb_input.h>
26-
26+ #ifdef FLB_HAVE_ICONV
27+ #include <fluent-bit/flb_iconv.h>
28+ #endif
2729#include <stdlib.h>
2830#include <fcntl.h>
2931
@@ -46,6 +48,9 @@ struct flb_tail_config *flb_tail_config_create(struct flb_input_instance *i_ins,
4648 long nsec ;
4749 ssize_t bytes ;
4850 const char * tmp ;
51+ #ifdef FLB_HAVE_ICONV
52+ char * tmp2 ;
53+ #endif
4954 struct flb_tail_config * ctx ;
5055
5156 ctx = flb_calloc (1 , sizeof (struct flb_tail_config ));
@@ -321,6 +326,27 @@ struct flb_tail_config *flb_tail_config_create(struct flb_input_instance *i_ins,
321326 }
322327#endif
323328
329+ #ifdef FLB_HAVE_ICONV
330+ tmp = flb_input_get_property ("from_encoding" , i_ins );
331+ tmp2 = flb_input_get_property ("encoding" , i_ins );
332+ if (tmp ) {
333+ if (!tmp2 ) {
334+ tmp2 = "UTF8" ;
335+ } else if (!strcasecmp (tmp2 ,"default" )) {
336+ tmp2 = "" ;
337+ }
338+ if (!strcasecmp (tmp ,"default" )) {
339+ tmp = "" ;
340+ }
341+ ctx -> iconvert = flb_iconv_open (tmp2 ,tmp );
342+ if (ctx -> iconvert == NULL ) {
343+ flb_error ("[in_tail] cannot init iconv: '%s'=>'%s'" , tmp , tmp2 );
344+ }
345+ } else {
346+ ctx -> iconvert = NULL ;
347+ }
348+ #endif
349+
324350#ifdef FLB_HAVE_METRICS
325351 flb_metrics_add (FLB_TAIL_METRIC_F_OPENED ,
326352 "files_opened" , ctx -> i_ins -> metrics );
@@ -352,7 +378,12 @@ int flb_tail_config_destroy(struct flb_tail_config *config)
352378 }
353379#endif
354380
355- #ifdef FLB_HAVE_SQLDB
381+ #ifdef FLB_HAVE_ICONV
382+ if (config -> iconvert ) {
383+ iconv_close (config -> iconvert );
384+ }
385+ #endif
386+ #ifdef FLB_HAVE_SQLDB
356387 if (config -> db != NULL ) {
357388 flb_tail_db_close (config -> db );
358389 }
0 commit comments