Skip to content

Commit

Permalink
lib: remove mangle_callback
Browse files Browse the repository at this point in the history
Signed-off-by: László Várady <laszlo.varady@anno.io>
  • Loading branch information
MrAnno committed May 22, 2024
1 parent 37dda66 commit c638816
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 112 deletions.
18 changes: 0 additions & 18 deletions lib/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,6 @@ cfg_free(GlobalConfig *self)
if (self->bad_hostname_compiled)
regfree(&self->bad_hostname);
g_free(self->recv_time_zone);
if (self->source_mangle_callback_list)
g_list_free(self->source_mangle_callback_list);
g_free(self->bad_hostname_re);
dns_cache_options_destroy(&self->dns_cache_options);
g_free(self->custom_domain);
Expand Down Expand Up @@ -766,22 +764,6 @@ cfg_get_user_version(const GlobalConfig *cfg)
return cfg->user_version;
}

void register_source_mangle_callback(GlobalConfig *src, mangle_callback cb)
{
src->source_mangle_callback_list = g_list_append(src->source_mangle_callback_list, cb);
}

gboolean
is_source_mangle_callback_registered(GlobalConfig *src, mangle_callback cb)
{
return !!g_list_find(src->source_mangle_callback_list, cb);
}

void uregister_source_mangle_callback(GlobalConfig *src, mangle_callback cb)
{
src->source_mangle_callback_list = g_list_remove(src->source_mangle_callback_list, cb);
}

const gchar *
cfg_get_filename(const GlobalConfig *cfg)
{
Expand Down
7 changes: 0 additions & 7 deletions lib/cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ struct _GlobalConfig

gboolean create_dirs;
FilePermOptions file_perm_options;
GList *source_mangle_callback_list;
gboolean use_uniqid;

gboolean keep_timestamp;
Expand Down Expand Up @@ -174,12 +173,6 @@ void cfg_persist_config_move(GlobalConfig *src, GlobalConfig *dest);
void cfg_persist_config_add(GlobalConfig *cfg, const gchar *name, gpointer value, GDestroyNotify destroy);
gpointer cfg_persist_config_fetch(GlobalConfig *cfg, const gchar *name);

typedef gboolean(* mangle_callback)(GlobalConfig *cfg, LogMessage *msg, gpointer user_data);

void register_source_mangle_callback(GlobalConfig *src, mangle_callback cb);
gboolean is_source_mangle_callback_registered(GlobalConfig *src, mangle_callback cb);
void uregister_source_mangle_callback(GlobalConfig *src, mangle_callback cb);

static inline gboolean
__cfg_is_config_version_older(GlobalConfig *cfg, gint req)
{
Expand Down
27 changes: 0 additions & 27 deletions lib/logsource.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,27 +594,6 @@ log_source_post(LogSource *self, LogMessage *msg)
scratch_buffers_reclaim_marked(mark);
}

static gboolean
_invoke_mangle_callbacks(LogPipe *s, LogMessage *msg, const LogPathOptions *path_options)
{
LogSource *self = (LogSource *) s;
GList *next_item = g_list_first(self->options->source_queue_callbacks);

while(next_item)
{
if(next_item->data)
{
if(!((mangle_callback) (next_item->data))(log_pipe_get_config(s), msg, self))
{
log_msg_drop(msg, path_options, AT_PROCESSED);
return FALSE;
}
}
next_item = next_item->next;
}
return TRUE;
}

static void
log_source_override_host(LogSource *self, LogMessage *msg)
{
Expand Down Expand Up @@ -679,10 +658,6 @@ log_source_queue(LogPipe *s, LogMessage *msg, const LogPathOptions *path_options

log_msg_set_tag_by_id(msg, self->options->source_group_tag);


if (!_invoke_mangle_callbacks(s, msg, path_options))
return;

if (self->options->host_override)
log_source_override_host(self, msg);

Expand Down Expand Up @@ -862,8 +837,6 @@ log_source_options_init(LogSourceOptions *options, GlobalConfig *cfg, const gcha
{
gchar *source_group_name;

options->source_queue_callbacks = cfg->source_mangle_callback_list;

if (options->init_window_size == -1)
options->init_window_size = 100;
if (options->keep_hostname == -1)
Expand Down
1 change: 0 additions & 1 deletion lib/logsource.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ typedef struct _LogSourceOptions
gboolean read_old_records;
gboolean use_syslogng_pid;
GArray *tags;
GList *source_queue_callbacks;
gint stats_level;
gint stats_source;
} LogSourceOptions;
Expand Down
59 changes: 0 additions & 59 deletions lib/tests/test_logsource.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,65 +352,6 @@ Test(log_source, test_forced_suspend_and_wakeup)
test_source_destroy(source);
}


static gboolean
test_mangle_callback_forbidden(GlobalConfig *config, LogMessage *msg, gpointer user_data)
{
return strstr(log_msg_get_value(msg, LM_V_MESSAGE, NULL), "forbidden") == NULL;
}

static gboolean
test_mangle_callback_tag(GlobalConfig *config, LogMessage *msg, gpointer user_data)
{
log_msg_set_tag_by_name(msg, "tagged");
return TRUE;
}

static void
expect_forbidden_message_dropped(LogSource *source)
{
LogMessage *msg = log_msg_new_internal(LOG_INFO | LOG_SYSLOG, "This is a forbidden message");
log_msg_ref(msg);
log_source_post(source, msg);

cr_expect_not(log_msg_is_tag_by_name(msg, "tagged"),
"Message should not be tagged, the message should have been dropped in test_mangle_callback_forbidden");
log_msg_unref(msg);
}

static void
expect_regular_message_forwarded(LogSource *source)
{
LogMessage *msg = log_msg_new_internal(LOG_INFO | LOG_SYSLOG, "Message");
log_msg_ref(msg);
log_source_post(source, msg);

cr_expect(log_msg_is_tag_by_name(msg, "tagged"));
log_msg_unref(msg);
}

Test(log_source, test_mangle_callback)
{
register_source_mangle_callback(cfg, test_mangle_callback_forbidden);
register_source_mangle_callback(cfg, test_mangle_callback_tag);

LogSource *source = test_source_init(&source_options);
TestPipe *next_pipe = test_pipe_init();
log_pipe_append(&source->super, &next_pipe->super);

expect_forbidden_message_dropped(source);
cr_assert_eq(next_pipe->messages_count, 0);

expect_regular_message_forwarded(source);
cr_assert_eq(next_pipe->messages_count, 1);

test_pipe_ack_messages(next_pipe, 1);

test_pipe_destroy(next_pipe);
test_source_destroy(source);
}


static DynamicWindowPool *
test_dynamic_window_pool_init(gsize pool_size)
{
Expand Down

0 comments on commit c638816

Please sign in to comment.