Skip to content

Commit e97dc53

Browse files
committed
build: FLB_UTF8_ENCODER to enable UTF8 encoding, FLB_HAVE_UTF8_ENCODER preprocessor
Signed-off-by: Nigel Stewart <[email protected]>
1 parent de0915c commit e97dc53

File tree

8 files changed

+36
-21
lines changed

8 files changed

+36
-21
lines changed

include/fluent-bit/flb_encode.h renamed to include/fluent-bit/flb_encoder.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@
1818
* limitations under the License.
1919
*/
2020

21-
#ifndef FLB_ENCODE_H
22-
#define FLB_ENCODE_H
21+
#ifndef FLB_ENCODER_H
22+
#define FLB_ENCODER_H
2323

2424
#include <msgpack.h>
2525

2626
typedef void *flb_encoder;
2727

28-
#ifdef FLB_HAVE_ENCODE
28+
#ifdef FLB_HAVE_UTF8_ENCODER
2929
flb_encoder flb_get_encoder(const char *encoding);
30-
void flb_msgpack_encode_utf8(flb_encoder enc, msgpack_packer* pk, const void* b, size_t l);
30+
void flb_msgpack_encode_utf8(flb_encoder encoder, const char *module, msgpack_packer *pk, const void *b, size_t l);
3131
#else
3232
static inline flb_encoder flb_get_encoder(const char *encoding)
3333
{
3434
return NULL;
3535
}
3636

37-
static inline void flb_msgpack_encode_utf8(flb_encoder enc, msgpack_packer* pk, const void* b, size_t l)
37+
static inline void flb_msgpack_encode_utf8(flb_encoder encoder, const char *module, msgpack_packer *pk, const void *b, size_t l)
3838
{
3939
msgpack_pack_str(pk, l);
4040
msgpack_pack_str_body(pk, b, l);
4141
}
4242
#endif
4343

44-
#endif /* FLB_ENCODE_H */
44+
#endif /* FLB_ENCODER_H */

plugins/in_syslog/syslog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include <fluent-bit/flb_info.h>
2525
#include <fluent-bit/flb_input.h>
26-
#include <fluent-bit/flb_encode.h>
26+
#include <fluent-bit/flb_encoder.h>
2727

2828
/* Syslog modes */
2929
#define FLB_SYSLOG_UNIX_TCP 1

plugins/in_syslog/syslog_prot.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <fluent-bit/flb_info.h>
2424
#include <fluent-bit/flb_parser.h>
2525
#include <fluent-bit/flb_time.h>
26-
#include <fluent-bit/flb_encode.h>
26+
#include <fluent-bit/flb_encoder.h>
2727

2828
#include "syslog.h"
2929
#include "syslog_conn.h"
@@ -45,7 +45,7 @@ static inline int pack_line(struct flb_syslog *ctx,
4545

4646
msgpack_pack_array(&mp_pck, 2);
4747
flb_time_append_to_msgpack(time, &mp_pck, 0);
48-
flb_msgpack_encode_utf8(ctx->encoding, &mp_pck, data, data_size);
48+
flb_msgpack_encode_utf8(ctx->encoding, "in_syslog", &mp_pck, data, data_size);
4949

5050
flb_input_chunk_append_raw(ctx->i_ins, NULL, 0, mp_sbuf.data, mp_sbuf.size);
5151
msgpack_sbuffer_destroy(&mp_sbuf);

plugins/in_tail/tail_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <fluent-bit/flb_input.h>
2626
#include <fluent-bit/flb_parser.h>
2727
#include <fluent-bit/flb_macros.h>
28-
#include <fluent-bit/flb_encode.h>
28+
#include <fluent-bit/flb_encoder.h>
2929
#ifdef FLB_HAVE_REGEX
3030
#include <fluent-bit/flb_regex.h>
3131
#endif

plugins/in_tail/tail_file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <fluent-bit/flb_info.h>
2828
#include <fluent-bit/flb_input.h>
2929
#include <fluent-bit/flb_parser.h>
30-
#include <fluent-bit/flb_encode.h>
30+
#include <fluent-bit/flb_encoder.h>
3131
#ifdef FLB_HAVE_REGEX
3232
#include <fluent-bit/flb_regex.h>
3333
#include <fluent-bit/flb_hash.h>
@@ -208,7 +208,7 @@ int flb_tail_file_pack_line(msgpack_sbuffer *mp_sbuf, msgpack_packer *mp_pck,
208208

209209
msgpack_pack_str(mp_pck, ctx->key_len);
210210
msgpack_pack_str_body(mp_pck, ctx->key, ctx->key_len);
211-
flb_msgpack_encode_utf8(ctx->encoding, mp_pck, data, data_size);
211+
flb_msgpack_encode_utf8(ctx->encoding, "in_tail", mp_pck, data, data_size);
212212

213213
return 0;
214214
}

plugins/in_tail/tail_multiline.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include <fluent-bit/flb_info.h>
2222
#include <fluent-bit/flb_config.h>
23-
#include <fluent-bit/flb_encode.h>
23+
#include <fluent-bit/flb_encoder.h>
2424
#include <fluent-bit/flb_kv.h>
2525

2626
#include "tail_config.h"
@@ -239,7 +239,7 @@ static inline void flb_tail_mult_append_raw(char *buf, int size,
239239
struct flb_tail_config *config)
240240
{
241241
/* Append the raw string */
242-
flb_msgpack_encode_utf8(config->encoding, &file->mult_pck, buf, size);
242+
flb_msgpack_encode_utf8(config->encoding, "in_tail", &file->mult_pck, buf, size);
243243
}
244244

245245
/* Check if the last key value type of a map is string or not */

src/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ if(FLB_METRICS)
9696
)
9797
endif()
9898

99+
if(FLB_UTF8_ENCODER)
100+
set(src
101+
${src}
102+
"flb_encoder.c"
103+
)
104+
endif()
105+
99106
if(FLB_LUAJIT)
100107
set(src
101108
${src}

src/flb_encode.c renamed to src/flb_encoder.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
* limitations under the License.
1919
*/
2020

21-
#include <fluent-bit/flb_encode.h>
21+
#include <fluent-bit/flb_encoder.h>
22+
#include <fluent-bit/flb_log.h>
2223
#include <fluent-bit/flb_mem.h>
2324

24-
#ifdef FLB_HAVE_ENCODE
25+
#ifdef FLB_HAVE_UTF8_ENCODER
2526
#include <tutf8e.h>
2627

2728
#define TUTF8_BUFFER_SIZE 256
@@ -31,35 +32,42 @@ flb_encoder flb_get_encoder(const char *encoding)
3132
return tutf8e_encoder(encoding);
3233
}
3334

34-
void flb_msgpack_encode_utf8(flb_encoder enc, msgpack_packer* pk, const void* b, size_t l)
35+
void flb_msgpack_encode_utf8(flb_encoder encoder, const char *module, msgpack_packer *pk, const void *b, size_t l)
3536
{
36-
if (enc) {
37+
if (encoder) {
3738
size_t size = 0;
38-
if (!tutf8e_encoder_buffer_length(enc, b, l, &size) && size) {
39+
if (!tutf8e_encoder_buffer_length(encoder, b, l, &size) && size) {
3940
/* Already UTF8 encoded? */
4041
if (size == l) {
4142
}
4243
/* Small enough for encoding to stack? */
4344
else if (size<=TUTF8_BUFFER_SIZE) {
4445
char buffer[TUTF8_BUFFER_SIZE];
45-
if (!tutf8e_encoder_buffer_encode(enc, b, l, buffer, &size) && size) {
46+
if (!tutf8e_encoder_buffer_encode(encoder, b, l, buffer, &size) && size) {
4647
msgpack_pack_str(pk, size);
4748
msgpack_pack_str_body(pk, buffer, size);
4849
return;
4950
}
51+
/* Not expecting to get here ordinarily */
52+
flb_warn("[%s] failed to encode to UTF8", module);
5053
}
5154
/* malloc/free the encoded copy */
5255
else {
5356
char *buffer = (char *) flb_malloc(size);
54-
if (buffer && !tutf8e_encoder_buffer_encode(enc, b, l, buffer, &size) && size) {
57+
if (buffer && !tutf8e_encoder_buffer_encode(encoder, b, l, buffer, &size) && size) {
5558
msgpack_pack_str(pk, size);
5659
msgpack_pack_str_body(pk, buffer, size);
5760
free(buffer);
5861
return;
5962
}
63+
/* Not expecting to get here ordinarily */
6064
free(buffer);
65+
flb_warn("[%s] failed to encode to UTF8", module);
6166
}
6267
}
68+
else {
69+
flb_warn("[%s] failed to encode to UTF8", module);
70+
}
6371
}
6472

6573
/* Could not or need not encode to UTF8 */

0 commit comments

Comments
 (0)