diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-09-07 16:12:44 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-09-07 16:12:44 +0100 |
commit | 2b78f5350a903a10d03f1efde8e9de35cd41f7a1 (patch) | |
tree | 6fbcd5b1d789688c8a14f0e009aa91fa51d4834f | |
parent | df2389900f12cd82d1246490339ef99e62ba13a1 (diff) | |
download | rspamd-2b78f5350a903a10d03f1efde8e9de35cd41f7a1.tar.gz rspamd-2b78f5350a903a10d03f1efde8e9de35cd41f7a1.zip |
[Minor] Sort lua modules and use GPtrArray instead of GList
-rw-r--r-- | src/libserver/cfg_file.h | 2 | ||||
-rw-r--r-- | src/libserver/cfg_rcl.cxx | 24 | ||||
-rw-r--r-- | src/libserver/cfg_utils.cxx | 2 | ||||
-rw-r--r-- | src/lua/lua_common.c | 16 |
4 files changed, 18 insertions, 26 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 1415fd865..4e432af60 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -390,7 +390,7 @@ struct rspamd_config { gboolean compat_messages; /**< use old messages in the protocol (array) */ - GList *script_modules; /**< linked list of script modules to load */ + GPtrArray *script_modules; /**< a list of script modules to load */ GHashTable *explicit_modules; /**< modules that should be always loaded */ GList *filters; /**< linked list of all filters */ diff --git a/src/libserver/cfg_rcl.cxx b/src/libserver/cfg_rcl.cxx index 26b799cdf..e7828ff90 100644 --- a/src/libserver/cfg_rcl.cxx +++ b/src/libserver/cfg_rcl.cxx @@ -920,6 +920,15 @@ rspamd_rcl_lua_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, return TRUE; } +static int +rspamd_lua_mod_sort_fn(gconstpointer a, gconstpointer b) +{ + auto *m1 = *(const script_module **) a; + auto *m2 = *(const script_module **) b; + + return strcmp(m1->name, m2->name); +} + gboolean rspamd_rcl_add_lua_plugins_path(struct rspamd_rcl_sections_map *sections, struct rspamd_config *cfg, @@ -949,18 +958,7 @@ rspamd_rcl_add_lua_plugins_path(struct rspamd_rcl_sections_map *sections, return false; } - if (cfg->script_modules == nullptr) { - cfg->script_modules = g_list_append(cfg->script_modules, - cur_mod); - rspamd_mempool_add_destructor(cfg->cfg_pool, - (rspamd_mempool_destruct_t) g_list_free, - cfg->script_modules); - } - else { - cfg->script_modules = g_list_append(cfg->script_modules, - cur_mod); - } - + g_ptr_array_add(cfg->script_modules, cur_mod); sections->lua_modules_seen.insert(fname.string()); return true; @@ -994,6 +992,8 @@ rspamd_rcl_add_lua_plugins_path(struct rspamd_rcl_sections_map *sections, } } + g_ptr_array_sort(cfg->script_modules, rspamd_lua_mod_sort_fn); + return TRUE; } diff --git a/src/libserver/cfg_utils.cxx b/src/libserver/cfg_utils.cxx index 12074a83a..416d52e05 100644 --- a/src/libserver/cfg_utils.cxx +++ b/src/libserver/cfg_utils.cxx @@ -339,6 +339,7 @@ rspamd_config_new(enum rspamd_config_init_flags flags) cfg->heartbeat_interval = 10.0; cfg->enable_css_parser = true; + cfg->script_modules = g_ptr_array_new(); REF_INIT_RETAIN(cfg, rspamd_config_free); @@ -398,6 +399,7 @@ void rspamd_config_free(struct rspamd_config *cfg) rspamd_re_cache_unref(cfg->re_cache); g_ptr_array_free(cfg->c_modules, TRUE); + g_ptr_array_free(cfg->script_modules, TRUE); if (cfg->monitored_ctx) { rspamd_monitored_ctx_destroy(cfg->monitored_ctx); diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 5991af656..bafe8ea93 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -1109,25 +1109,20 @@ gboolean rspamd_init_lua_filters(struct rspamd_config *cfg, bool force_load, bool strict) { struct rspamd_config **pcfg; - GList *cur; struct script_module *module; lua_State *L = cfg->lua_state; - gint err_idx; + gint err_idx, i; pcfg = lua_newuserdata(L, sizeof(struct rspamd_config *)); rspamd_lua_setclass(L, "rspamd{config}", -1); *pcfg = cfg; lua_setglobal(L, "rspamd_config"); - cur = g_list_first(cfg->script_modules); - - while (cur) { - module = cur->data; - + PTR_ARRAY_FOREACH(cfg->script_modules, i, module) + { if (module->path) { if (!force_load) { if (!rspamd_config_is_module_enabled(cfg, module->name)) { - cur = g_list_next(cur); continue; } } @@ -1154,7 +1149,6 @@ rspamd_init_lua_filters(struct rspamd_config *cfg, bool force_load, bool strict) return FALSE; } - cur = g_list_next(cur); continue; } @@ -1182,7 +1176,6 @@ rspamd_init_lua_filters(struct rspamd_config *cfg, bool force_load, bool strict) return FALSE; } - cur = g_list_next(cur); continue; } @@ -1202,7 +1195,6 @@ rspamd_init_lua_filters(struct rspamd_config *cfg, bool force_load, bool strict) return FALSE; } - cur = g_list_next(cur); continue; } @@ -1215,8 +1207,6 @@ rspamd_init_lua_filters(struct rspamd_config *cfg, bool force_load, bool strict) lua_pop(L, 1); /* Error function */ } - - cur = g_list_next(cur); } return TRUE; |