diff options
-rw-r--r-- | src/controller.c | 22 | ||||
-rw-r--r-- | src/libserver/cfg_utils.c | 29 | ||||
-rw-r--r-- | src/main.h | 2 | ||||
-rw-r--r-- | src/plugins/chartable.c | 10 | ||||
-rw-r--r-- | src/plugins/dkim_check.c | 2 | ||||
-rw-r--r-- | src/plugins/fuzzy_check.c | 2 | ||||
-rw-r--r-- | src/plugins/regexp.c | 1 | ||||
-rw-r--r-- | src/plugins/spf.c | 2 | ||||
-rw-r--r-- | src/plugins/surbl.h | 2 |
9 files changed, 32 insertions, 40 deletions
diff --git a/src/controller.c b/src/controller.c index 2c29336f5..be2225167 100644 --- a/src/controller.c +++ b/src/controller.c @@ -1587,7 +1587,6 @@ start_controller_worker (struct rspamd_worker *worker) { struct rspamd_controller_worker_ctx *ctx = worker->ctx; GList *cur; - struct filter *f; struct module_ctx *mctx; GHashTableIter iter; gpointer key, value; @@ -1688,18 +1687,6 @@ start_controller_worker (struct rspamd_worker *worker) rspamd_http_router_set_key (ctx->http, ctx->key); } - /* Attach plugins */ - cur = g_list_first (ctx->cfg->filters); - while (cur) { - f = cur->data; - mctx = g_hash_table_lookup (ctx->cfg->c_modules, f->module->name); - if (mctx != NULL && f->module->module_attach_controller_func != NULL) { - f->module->module_attach_controller_func (mctx, - ctx->custom_commands); - } - cur = g_list_next (cur); - } - g_hash_table_iter_init (&iter, ctx->custom_commands); while (g_hash_table_iter_next (&iter, &key, &value)) { rspamd_http_router_add_path (ctx->http, @@ -1707,6 +1694,15 @@ start_controller_worker (struct rspamd_worker *worker) rspamd_controller_handle_custom); } + g_hash_table_iter_init (&iter, ctx->cfg->c_modules); + while (g_hash_table_iter_next (&iter, &key, &value)) { + mctx = value; + if (mctx->mod->module_attach_controller_func != NULL) { + mctx->mod->module_attach_controller_func (mctx, + ctx->custom_commands); + } + } + ctx->resolver = dns_resolver_init (worker->srv->logger, ctx->ev_base, worker->srv->cfg); diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 444ad9a11..0094907a7 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -838,6 +838,7 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig) g_hash_table_insert (cfg->c_modules, (gpointer) mod->name, mod_ctx); + mod_ctx->mod = mod; } } @@ -845,23 +846,23 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig) while (cur) { /* Perform modules configuring */ - mod = NULL; - for (pmod = modules; *pmod != NULL; pmod ++) { - if ((*pmod)->name && g_ascii_strcasecmp ((*pmod)->name, - cur->data) == 0) { - mod = *pmod; - - if (reconfig) { - (void)mod->module_reconfig_func (cfg); - msg_debug ("reconfig of %s", mod->name); - } - else { - (void)mod->module_config_func (cfg); - } + mod_ctx = NULL; + mod_ctx = g_hash_table_lookup (cfg->c_modules, cur->data); + + if (mod_ctx) { + mod = mod_ctx->mod; + mod_ctx->enabled = TRUE; + + if (reconfig) { + (void)mod->module_reconfig_func (cfg); + msg_debug ("reconfig of %s", mod->name); + } + else { + (void)mod->module_config_func (cfg); } } - if (mod == NULL) { + if (mod_ctx == NULL) { msg_warn ("requested unknown module %s", cur->data); } diff --git a/src/main.h b/src/main.h index 14ed7281e..d33e4ed1a 100644 --- a/src/main.h +++ b/src/main.h @@ -179,6 +179,8 @@ struct controller_session { */ struct module_ctx { gint (*filter)(struct rspamd_task *task); /**< pointer to headers process function */ + module_t *mod; /**< module pointer */ + gboolean enabled; /**< true if module is enabled in configuration */ }; /** diff --git a/src/plugins/chartable.c b/src/plugins/chartable.c index 002a1d05b..f8ad15be9 100644 --- a/src/plugins/chartable.c +++ b/src/plugins/chartable.c @@ -52,7 +52,7 @@ module_t chartable_module = { }; struct chartable_ctx { - gint (*filter) (struct rspamd_task * task); + struct module_ctx ctx; const gchar *symbol; double threshold; @@ -69,7 +69,6 @@ chartable_module_init (struct rspamd_config *cfg, struct module_ctx **ctx) { chartable_module_ctx = g_malloc (sizeof (struct chartable_ctx)); - chartable_module_ctx->filter = chartable_mime_filter; chartable_module_ctx->chartable_pool = rspamd_mempool_new ( rspamd_mempool_suggest_size ()); @@ -221,10 +220,3 @@ chartable_symbol_callback (struct rspamd_task *task, void *unused) } } - -static gint -chartable_mime_filter (struct rspamd_task *task) -{ - /* XXX: remove it */ - return 0; -} diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index b8e709d99..3f7a2ae9a 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -52,7 +52,7 @@ #define DEFAULT_TIME_JITTER 60 struct dkim_ctx { - gint (*filter) (struct rspamd_task * task); + struct module_ctx ctx; const gchar *symbol_reject; const gchar *symbol_tempfail; const gchar *symbol_allow; diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 69739b9f8..54e58ed04 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -82,7 +82,7 @@ struct fuzzy_rule { }; struct fuzzy_ctx { - gint (*filter) (struct rspamd_task * task); + struct module_ctx ctx; rspamd_mempool_t *fuzzy_pool; GList *fuzzy_rules; struct rspamd_config *cfg; diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index f98f341a3..2bf88ac93 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -42,6 +42,7 @@ struct regexp_module_item { }; struct regexp_ctx { + struct module_ctx ctx; rspamd_mempool_t *regexp_pool; gsize max_size; }; diff --git a/src/plugins/spf.c b/src/plugins/spf.c index 14c9e0b42..3c397fb31 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -47,7 +47,7 @@ #define DEFAULT_CACHE_MAXAGE 86400 struct spf_ctx { - gint (*filter) (struct rspamd_task * task); + struct module_ctx ctx; const gchar *symbol_fail; const gchar *symbol_softfail; const gchar *symbol_neutral; diff --git a/src/plugins/surbl.h b/src/plugins/surbl.h index b75bf991b..abaa3c196 100644 --- a/src/plugins/surbl.h +++ b/src/plugins/surbl.h @@ -17,7 +17,7 @@ #define MAX_LEVELS 10 struct surbl_ctx { - gint (*filter)(struct rspamd_task *task); + struct module_ctx ctx; guint16 weight; gdouble connect_timeout; gdouble read_timeout; |