struct module_ctx *mctx;
GHashTableIter iter;
gpointer key, value;
+ guint i;
struct rspamd_keypair_cache *cache;
struct timeval stv;
const guint save_stats_interval = 60 * 1000; /* 1 minute */
rspamd_http_router_set_key (ctx->http, ctx->key);
}
- g_hash_table_iter_init (&iter, ctx->cfg->c_modules);
- while (g_hash_table_iter_next (&iter, &key, &value)) {
- mctx = value;
+ PTR_ARRAY_FOREACH (ctx->cfg->c_modules, i, mctx) {
if (mctx->mod->module_attach_controller_func != NULL) {
mctx->mod->module_attach_controller_func (mctx,
ctx->custom_commands);
ucl_object_t *rcl_obj; /**< rcl object */
ucl_object_t *config_comments; /**< comments saved from the config */
ucl_object_t *doc_strings; /**< documentation strings for config options */
- GHashTable * c_modules; /**< hash of c modules indexed by module name */
+ GPtrArray *c_modules; /**< list of C modules */
GHashTable * composite_symbols; /**< hash of composite symbols indexed by its name */
GList *classifiers; /**< list of all classifiers defined */
GList *statfiles; /**< list of all statfiles in config file order */
cfg->max_diff = 20480;
rspamd_config_init_metric (cfg);
- cfg->c_modules = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
cfg->composite_symbols =
g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
cfg->classifiers_symbols = g_hash_table_new (rspamd_str_hash,
cfg->default_max_shots = DEFAULT_MAX_SHOTS;
cfg->max_sessions_cache = DEFAULT_MAX_SESSIONS;
cfg->maps_cache_dir = rspamd_mempool_strdup (cfg->cfg_pool, RSPAMD_DBDIR);
+ cfg->c_modules = g_ptr_array_new ();
REF_INIT_RETAIN (cfg, rspamd_config_free);
ucl_object_unref (cfg->config_comments);
ucl_object_unref (cfg->doc_strings);
ucl_object_unref (cfg->neighbours);
- g_hash_table_unref (cfg->c_modules);
g_hash_table_remove_all (cfg->composite_symbols);
g_hash_table_unref (cfg->composite_symbols);
g_hash_table_remove_all (cfg->cfg_params);
rspamd_re_cache_unref (cfg->re_cache);
rspamd_upstreams_library_unref (cfg->ups_ctx);
rspamd_mempool_delete (cfg->cfg_pool);
+ g_ptr_array_free (cfg->c_modules, TRUE);
if (cfg->lua_state && cfg->own_lua_state) {
lua_close (cfg->lua_state);
{
GList *cur;
module_t *mod, **pmod;
- struct module_ctx *mod_ctx;
+ guint i = 0;
+ struct module_ctx *mod_ctx, *cur_ctx;
/* Init all compiled modules */
- if (!reconfig) {
- for (pmod = cfg->compiled_modules; pmod != NULL && *pmod != NULL; pmod ++) {
- mod = *pmod;
-
- if (rspamd_check_module (cfg, mod)) {
- if (mod->module_init_func (cfg, &mod_ctx) == 0) {
- g_assert (mod_ctx != NULL);
- g_hash_table_insert (cfg->c_modules,
- (gpointer) mod->name,
- mod_ctx);
- mod_ctx->mod = mod;
- }
+
+ for (pmod = cfg->compiled_modules; pmod != NULL && *pmod != NULL; pmod ++) {
+ mod = *pmod;
+ if (rspamd_check_module (cfg, mod)) {
+ if (mod->module_init_func (cfg, &mod_ctx) == 0) {
+ g_assert (mod_ctx != NULL);
+ g_ptr_array_add (cfg->c_modules, mod_ctx);
+ mod_ctx->mod = mod;
+ mod->ctx_offset = i ++;
}
}
}
while (cur) {
/* Perform modules configuring */
- mod_ctx = g_hash_table_lookup (cfg->c_modules, cur->data);
+ mod_ctx = NULL;
+ PTR_ARRAY_FOREACH (cfg->c_modules, i, cur_ctx) {
+ if (g_ascii_strcasecmp (cur_ctx->mod->name,
+ (const gchar *)cur->data) == 0) {
+ mod_ctx = cur_ctx;
+ break;
+ }
+ }
if (mod_ctx) {
mod = mod_ctx->mod;
GList *cur;
struct rspamd_symbols_group *gr;
lua_State *L = cfg->lua_state;
+ struct module_ctx *cur_ctx;
+ guint i;
- if (g_hash_table_lookup (cfg->c_modules, module_name)) {
- is_c = TRUE;
+ PTR_ARRAY_FOREACH (cfg->c_modules, i, cur_ctx) {
+ if (g_ascii_strcasecmp (cur_ctx->mod->name, module_name) == 0) {
+ is_c = TRUE;
+ break;
+ }
}
if (g_hash_table_lookup (cfg->explicit_modules, module_name) != NULL) {
gint chartable_module_reconfig (struct rspamd_config *cfg);
module_t chartable_module = {
- "chartable",
- chartable_module_init,
- chartable_module_config,
- chartable_module_reconfig,
- NULL,
- RSPAMD_MODULE_VER
+ "chartable",
+ chartable_module_init,
+ chartable_module_config,
+ chartable_module_reconfig,
+ NULL,
+ RSPAMD_MODULE_VER,
+ (guint)-1,
};
struct chartable_ctx {
gint dkim_module_reconfig (struct rspamd_config *cfg);
module_t dkim_module = {
- "dkim",
- dkim_module_init,
- dkim_module_config,
- dkim_module_reconfig,
- NULL,
- RSPAMD_MODULE_VER
+ "dkim",
+ dkim_module_init,
+ dkim_module_config,
+ dkim_module_reconfig,
+ NULL,
+ RSPAMD_MODULE_VER,
+ (guint)-1,
};
static void
static gint fuzzy_lua_unlearn_handler (lua_State *L);
module_t fuzzy_check_module = {
- "fuzzy_check",
- fuzzy_check_module_init,
- fuzzy_check_module_config,
- fuzzy_check_module_reconfig,
- fuzzy_attach_controller,
- RSPAMD_MODULE_VER
+ "fuzzy_check",
+ fuzzy_check_module_init,
+ fuzzy_check_module_config,
+ fuzzy_check_module_reconfig,
+ fuzzy_attach_controller,
+ RSPAMD_MODULE_VER,
+ (guint)-1,
};
static void
gsize max_size;
};
-static struct regexp_ctx *regexp_module_ctx = NULL;
-
static void process_regexp_item (struct rspamd_task *task, void *user_data);
gint regexp_module_reconfig (struct rspamd_config *cfg);
module_t regexp_module = {
- "regexp",
- regexp_module_init,
- regexp_module_config,
- regexp_module_reconfig,
- NULL,
- RSPAMD_MODULE_VER
+ "regexp",
+ regexp_module_init,
+ regexp_module_config,
+ regexp_module_reconfig,
+ NULL,
+ RSPAMD_MODULE_VER,
+ (guint)-1,
};
+
+static inline struct regexp_ctx *
+regexp_get_context (struct rspamd_config *cfg)
+{
+ return (struct regexp_ctx *)g_ptr_array_index (cfg->c_modules,
+ regexp_module.ctx_offset);
+}
+
/* Process regexp expression */
static gboolean
read_regexp_expression (rspamd_mempool_t * pool,
gint
regexp_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
{
- if (regexp_module_ctx == NULL) {
- regexp_module_ctx = g_malloc0 (sizeof (struct regexp_ctx));
- }
+ struct regexp_ctx *regexp_module_ctx;
+
+ regexp_module_ctx = rspamd_mempool_alloc0 (cfg->cfg_pool,
+ sizeof (*regexp_module_ctx));
*ctx = (struct module_ctx *)regexp_module_ctx;
gint
regexp_module_config (struct rspamd_config *cfg)
{
+ struct regexp_ctx *regexp_module_ctx = regexp_get_context (cfg);
struct regexp_module_item *cur_item = NULL;
const ucl_object_t *sec, *value, *elt;
ucl_object_iter_t it = NULL;
gint
regexp_module_reconfig (struct rspamd_config *cfg)
{
- struct module_ctx saved_ctx;
-
- saved_ctx = regexp_module_ctx->ctx;
- memset (regexp_module_ctx, 0, sizeof (*regexp_module_ctx));
- regexp_module_ctx->ctx = saved_ctx;
-
return regexp_module_config (cfg);
}
gboolean check_authed;
};
-static inline struct spf_ctx *
-spf_get_context (struct rspamd_config *cfg)
-{
- return (struct spf_ctx *)g_hash_table_lookup (cfg->c_modules, "spf");
-}
-
-
static void spf_symbol_callback (struct rspamd_task *task, void *unused);
/* Initialization */
gint spf_module_reconfig (struct rspamd_config *cfg);
module_t spf_module = {
- "spf",
- spf_module_init,
- spf_module_config,
- spf_module_reconfig,
- NULL,
- RSPAMD_MODULE_VER
+ "spf",
+ spf_module_init,
+ spf_module_config,
+ spf_module_reconfig,
+ NULL,
+ RSPAMD_MODULE_VER,
+ (guint)-1,
};
+static inline struct spf_ctx *
+spf_get_context (struct rspamd_config *cfg)
+{
+ return (struct spf_ctx *)g_ptr_array_index (cfg->c_modules,
+ spf_module.ctx_offset);
+}
+
+
gint
spf_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
{
return g_quark_from_static_string ("surbl-error-quark");
}
-static inline struct surbl_ctx *
-surbl_get_context (struct rspamd_config *cfg)
-{
- return (struct surbl_ctx *)g_hash_table_lookup (cfg->c_modules, "surbl");
-}
-
/* Initialization */
gint surbl_module_init (struct rspamd_config *cfg, struct module_ctx **ctx);
gint surbl_module_config (struct rspamd_config *cfg);
gint surbl_module_reconfig (struct rspamd_config *cfg);
module_t surbl_module = {
- "surbl",
- surbl_module_init,
- surbl_module_config,
- surbl_module_reconfig,
- NULL,
- RSPAMD_MODULE_VER
+ "surbl",
+ surbl_module_init,
+ surbl_module_config,
+ surbl_module_reconfig,
+ NULL,
+ RSPAMD_MODULE_VER,
+ (guint)-1,
};
+static inline struct surbl_ctx *
+surbl_get_context (struct rspamd_config *cfg)
+{
+ return (struct surbl_ctx *)g_ptr_array_index (cfg->c_modules,
+ surbl_module.ctx_offset);
+}
+
static void
exceptions_free_value (gpointer v)
{
module_t *mod, **pmod;
worker_t **pworker;
struct module_ctx *mod_ctx;
- gint i = 1, ret = 0, processed_args = 0;
+ gint i, ret = 0, processed_args = 0;
context = g_option_context_new (
"confighelp - displays help for the configuration options");
rspamd_rcl_add_lua_plugins_path (cfg, plugins_path, NULL);
/* Init modules to get documentation strings */
+ i = 0;
for (pmod = cfg->compiled_modules; pmod != NULL && *pmod != NULL; pmod++) {
mod = *pmod;
mod_ctx = g_malloc0 (sizeof (struct module_ctx));
if (mod->module_init_func (cfg, &mod_ctx) == 0) {
- g_hash_table_insert (cfg->c_modules,
- (gpointer) mod->name,
- mod_ctx);
+ g_ptr_array_add (cfg->c_modules, mod_ctx);
+ mod_ctx->mod = mod;
+ mod->ctx_offset = i++;
mod_ctx->mod = mod;
}
+
+
}
/* Also init all workers */
for (pworker = cfg->compiled_workers; *pworker != NULL; pworker ++) {
rspamd_symbols_cache_save (rspamd_main->cfg->cache);
tmp_cfg = rspamd_config_new (RSPAMD_CONFIG_INIT_DEFAULT);
- g_hash_table_unref (tmp_cfg->c_modules);
- tmp_cfg->c_modules = g_hash_table_ref (rspamd_main->cfg->c_modules);
tmp_cfg->libs_ctx = rspamd_main->cfg->libs_ctx;
REF_RETAIN (tmp_cfg->libs_ctx);
cfg_file = rspamd_mempool_strdup (tmp_cfg->cfg_pool,
guint module_version;
guint64 rspamd_version;
const gchar *rspamd_features;
+ guint ctx_offset;
} module_t;
enum rspamd_worker_socket_type {