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 */
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,
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;
}
}
+ g_ptr_array_sort(cfg->script_modules, rspamd_lua_mod_sort_fn);
+
return TRUE;
}
cfg->heartbeat_interval = 10.0;
cfg->enable_css_parser = true;
+ cfg->script_modules = g_ptr_array_new();
REF_INIT_RETAIN(cfg, rspamd_config_free);
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);
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;
}
}
return FALSE;
}
- cur = g_list_next(cur);
continue;
}
return FALSE;
}
- cur = g_list_next(cur);
continue;
}
return FALSE;
}
- cur = g_list_next(cur);
continue;
}
lua_pop(L, 1); /* Error function */
}
-
- cur = g_list_next(cur);
}
return TRUE;