From a2b303b148a5cb927b62e6af136c4e13cd8abfe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ralph=20K=C3=BChnert?= Date: Tue, 21 Apr 2020 22:45:12 +0200 Subject: [PATCH] type adjustments to replace_character plugin iterator & register plugin --- CMakeLists.txt | 2 +- plugins/filter_replace_character/replace.c | 46 +++++++++++----------- plugins/filter_replace_character/replace.h | 4 +- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a67a48f2c2..f36302e1974 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,7 +155,7 @@ option(FLB_OUT_KAFKA "Enable Kafka output plugin" No) option(FLB_OUT_KAFKA_REST "Enable Kafka Rest output plugin" Yes) option(FLB_FILTER_AWS "Enable aws filter" Yes) option(FLB_FILTER_EXPECT "Enable expect filter" Yes) -option(FLB_FILTER_REPLACE_CHAR "Enable replace_character filter" Yes) +option(FLB_FILTER_REPLACE_CHARACTER "Enable replace_character filter" Yes) option(FLB_FILTER_GREP "Enable grep filter" Yes) option(FLB_FILTER_MODIFY "Enable modify filter" Yes) option(FLB_FILTER_STDOUT "Enable stdout filter" Yes) diff --git a/plugins/filter_replace_character/replace.c b/plugins/filter_replace_character/replace.c index f56d25bef25..5e8607bf1ad 100644 --- a/plugins/filter_replace_character/replace.c +++ b/plugins/filter_replace_character/replace.c @@ -41,8 +41,8 @@ static int cb_replace_init(struct flb_filter_instance *f_ins, struct mk_list *head; struct flb_kv *kv; char *tmp; - char find; - char replace; + char old; + char new; (void) data; /* Iterate all filter properties */ @@ -50,23 +50,23 @@ static int cb_replace_init(struct flb_filter_instance *f_ins, kv = mk_list_entry(head, struct flb_kv, _head); // TODO: better names for these options... - if (strcasecmp(kv->key, "find") == 0) { + if (strcasecmp(kv->key, "old") == 0) { tmp = kv->val; if (strlen(tmp) != 1) { - flb_error("[filter_replace_character] 'find' should be a single" + flb_error("[filter_replace_character] 'old' should be a single" " character"); return -1; } - find = tmp[0]; + old = tmp[0]; } - if (strcasecmp(kv->key, "replace") == 0) { + if (strcasecmp(kv->key, "new") == 0) { tmp = kv->val; if (strlen(tmp) != 1) { - flb_error("[filter_replace_character] 'replace' should be a " + flb_error("[filter_replace_character] 'new' should be a " "single character"); return -1; } - replace = tmp[0]; + new = tmp[0]; } } @@ -77,8 +77,8 @@ static int cb_replace_init(struct flb_filter_instance *f_ins, return -1; } - ctx->find = find; - ctx->replace = replace; + ctx->old = old; + ctx->new = new; flb_filter_set_context(f_ins, ctx); @@ -104,7 +104,7 @@ static int cb_replace_filter(const void *data, size_t bytes, msgpack_packer tmp_pck; msgpack_unpacked result; msgpack_object *obj; - msgpack_object key; + msgpack_object *key; msgpack_object_kv *kv; char *key_str = NULL; size_t key_str_size = 0; @@ -155,15 +155,15 @@ static int cb_replace_filter(const void *data, size_t bytes, kv = obj->via.map.ptr; for(i=0; i < obj->via.map.size; i++) { modify = FLB_FALSE; - key = (kv+i)->key - if (k->type == MSGPACK_OBJECT_BIN) { - key_str = (char *) k->via.bin.ptr; - key_str_size = k->via.bin.size; + key = &(kv+i)->key; + if (key->type == MSGPACK_OBJECT_BIN) { + key_str = (char *) key->via.bin.ptr; + key_str_size = key->via.bin.size; modify = FLB_TRUE; } - else if (k->type == MSGPACK_OBJECT_STR) { - key_str = (char *) k->via.str.ptr; - key_str_size = k->via.str.size; + else if (key->type == MSGPACK_OBJECT_STR) { + key_str = (char *) key->via.str.ptr; + key_str_size = key->via.str.size; modify = FLB_TRUE; } if (modify == FLB_TRUE) { @@ -183,13 +183,13 @@ static int cb_replace_filter(const void *data, size_t bytes, memcpy(key_buf, key_str, key_str_size); key_buf[key_str_size] = '\0'; for (j=0; jfind) { - key_buf[j] = ctx->replace; + if (key_buf[j] == ctx->old) { + key_buf[j] = ctx->new; } } /* Append the new key */ - msgpack_pack_str(tmp_pck, key_str_size); - msgpack_pack_str_body(tmp_pck, key_buf, key_str_size); + msgpack_pack_str(&tmp_pck, key_str_size); + msgpack_pack_str_body(&tmp_pck, key_buf, key_str_size); } else { msgpack_pack_object(&tmp_pck, (kv+i)->key); } @@ -223,7 +223,7 @@ static int cb_replace_exit(void *data, struct flb_config *config) return 0; } -struct flb_filter_plugin filter_aws_plugin = { +struct flb_filter_plugin filter_replace_character_plugin = { .name = "replace_character", .description = "Replace characters in key names", .cb_init = cb_replace_init, diff --git a/plugins/filter_replace_character/replace.h b/plugins/filter_replace_character/replace.h index 6cc0c6e1747..f0ea987fe35 100644 --- a/plugins/filter_replace_character/replace.h +++ b/plugins/filter_replace_character/replace.h @@ -21,8 +21,8 @@ #define FLB_FILTER_REPLACE_H struct flb_filter_replace_char { - char find; - char replace; + char old; + char new; }; #endif