Skip to content

Commit

Permalink
lib: add new library API for filter plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Takahiro YAMASHITA <[email protected]>
  • Loading branch information
nokute78 committed Feb 2, 2017
1 parent f64b791 commit 05fc0fe
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/fluent-bit/flb_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ FLB_EXPORT flb_ctx_t *flb_create();
FLB_EXPORT void flb_destroy(flb_ctx_t *ctx);
FLB_EXPORT int flb_input(flb_ctx_t *ctx, char *input, void *data);
FLB_EXPORT int flb_output(flb_ctx_t *ctx, char *output, void *data);
FLB_EXPORT int flb_filter(flb_ctx_t *ctx, char *filter, void *data);
FLB_EXPORT int flb_input_set(flb_ctx_t *ctx, int ffd, ...);
FLB_EXPORT int flb_output_set(flb_ctx_t *ctx, int ffd, ...);
FLB_EXPORT int flb_filter_set(flb_ctx_t *ctx, int ffd, ...);
FLB_EXPORT int flb_service_set(flb_ctx_t *ctx, ...);

/* start stop the engine */
Expand Down
65 changes: 64 additions & 1 deletion src/flb_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <fluent-bit/flb_engine.h>
#include <fluent-bit/flb_input.h>
#include <fluent-bit/flb_output.h>
#include <fluent-bit/flb_filter.h>
#include <fluent-bit/flb_utils.h>

#ifdef FLB_HAVE_MTRACE
Expand Down Expand Up @@ -73,6 +74,22 @@ static inline struct flb_output_instance *out_instance_get(flb_ctx_t *ctx,
return NULL;
}

static inline struct flb_filter_instance *filter_instance_get(flb_ctx_t *ctx,
int ffd)
{
struct mk_list *head;
struct flb_filter_instance *f_ins;

mk_list_foreach(head, &ctx->config->filters) {
f_ins = mk_list_entry(head, struct flb_filter_instance, _head);
if (f_ins->id == ffd) {
return f_ins;
}
}

return NULL;
}

flb_ctx_t *flb_create()
{
int ret;
Expand Down Expand Up @@ -175,6 +192,19 @@ int flb_output(flb_ctx_t *ctx, char *output, void *data)
return o_ins->mask_id;
}

/* Defines a new filter instance */
int flb_filter(flb_ctx_t *ctx, char *filter, void *data)
{
struct flb_filter_instance *f_ins;

f_ins = flb_filter_new(ctx->config, filter, data);
if (!f_ins) {
return -1;
}

return f_ins->id;
}

/* Set an input interface property */
int flb_input_set(flb_ctx_t *ctx, int ffd, ...)
{
Expand Down Expand Up @@ -207,7 +237,7 @@ int flb_input_set(flb_ctx_t *ctx, int ffd, ...)
return 0;
}

/* Set an input interface property */
/* Set an output interface property */
int flb_output_set(flb_ctx_t *ctx, int ffd, ...)
{
int ret;
Expand Down Expand Up @@ -240,6 +270,39 @@ int flb_output_set(flb_ctx_t *ctx, int ffd, ...)
return 0;
}

/* Set an filter interface property */
int flb_filter_set(flb_ctx_t *ctx, int ffd, ...)
{
int ret;
char *key;
char *value;
va_list va;
struct flb_filter_instance *f_ins;

f_ins = filter_instance_get(ctx, ffd);
if (!f_ins) {
return -1;
}

va_start(va, ffd);
while ((key = va_arg(va, char *))) {
value = va_arg(va, char *);
if (!value) {
/* Wrong parameter */
return -1;
}

ret = flb_filter_set_property(f_ins, key, value);
if (ret != 0) {
va_end(va);
return -1;
}
}

va_end(va);
return 0;
}

/* Set a service property */
int flb_service_set(flb_ctx_t *ctx, ...)
{
Expand Down

0 comments on commit 05fc0fe

Please sign in to comment.