From c638816d1b793f2a4473d9dfc0e89deeb61c5c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20V=C3=A1rady?= Date: Tue, 21 May 2024 21:50:01 +0200 Subject: [PATCH] lib: remove mangle_callback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: László Várady --- lib/cfg.c | 18 ------------ lib/cfg.h | 7 ----- lib/logsource.c | 27 ----------------- lib/logsource.h | 1 - lib/tests/test_logsource.c | 59 -------------------------------------- 5 files changed, 112 deletions(-) diff --git a/lib/cfg.c b/lib/cfg.c index 8ddfa3e5fb..980c9e9a2a 100644 --- a/lib/cfg.c +++ b/lib/cfg.c @@ -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); @@ -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) { diff --git a/lib/cfg.h b/lib/cfg.h index 85f3c7bebe..6a563d725d 100644 --- a/lib/cfg.h +++ b/lib/cfg.h @@ -99,7 +99,6 @@ struct _GlobalConfig gboolean create_dirs; FilePermOptions file_perm_options; - GList *source_mangle_callback_list; gboolean use_uniqid; gboolean keep_timestamp; @@ -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) { diff --git a/lib/logsource.c b/lib/logsource.c index 336efae0ae..1366f647e5 100644 --- a/lib/logsource.c +++ b/lib/logsource.c @@ -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) { @@ -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); @@ -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) diff --git a/lib/logsource.h b/lib/logsource.h index 561904f698..8d67ebedb1 100644 --- a/lib/logsource.h +++ b/lib/logsource.h @@ -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; diff --git a/lib/tests/test_logsource.c b/lib/tests/test_logsource.c index 1b52de4156..51f31f76de 100644 --- a/lib/tests/test_logsource.c +++ b/lib/tests/test_logsource.c @@ -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) {