]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Fix modules initialization.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 17 Apr 2015 15:38:19 +0000 (16:38 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 17 Apr 2015 15:38:19 +0000 (16:38 +0100)
src/controller.c
src/libserver/cfg_utils.c
src/main.h
src/plugins/chartable.c
src/plugins/dkim_check.c
src/plugins/fuzzy_check.c
src/plugins/regexp.c
src/plugins/spf.c
src/plugins/surbl.h

index 2c29336f5c1fed43fda7c4a600bcd2a16758cfb0..be2225167d3a3ed500b1bbb06050c51f8109233c 100644 (file)
@@ -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);
index 444ad9a115ca219a4e80742d318e2f45b5064ebe..0094907a7754e925eb26f0b62fcb330d28500b53 100644 (file)
@@ -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);
                }
 
index 14ed7281e90c886778405d7407b43108ec30cc4e..d33e4ed1a74f6ff60768fbcb0633321de7b5756d 100644 (file)
@@ -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         */
 };
 
 /**
index 002a1d05b97f5724200b029ca35b783adfebdb69..f8ad15be9b9ca6f217994d966fd932a691ef158f 100644 (file)
@@ -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;
-}
index b8e709d990e77b01fe54754ca43d96e400dca665..3f7a2ae9a3a194fa82fd1ec3893b3324d6dddb26 100644 (file)
@@ -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;
index 69739b9f8444e0be30b31df9c91f29c3235bcea8..54e58ed04ee8e7aa6bf1d4fa18bdb7a5198d65ca 100644 (file)
@@ -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;
index f98f341a34670ae6805f03a1b957cec83491b43d..2bf88ac930e421da0697d8f8217bb7d9e6f2cd32 100644 (file)
@@ -42,6 +42,7 @@ struct regexp_module_item {
 };
 
 struct regexp_ctx {
+       struct module_ctx ctx;
        rspamd_mempool_t *regexp_pool;
        gsize max_size;
 };
index 14c9e0b422938cd12ec96ce81aa43a171901d571..3c397fb31563334b0329ef755343e89ceb74bd1b 100644 (file)
@@ -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;
index b75bf991ba5d116100177c87480dc413d2178e5b..abaa3c1969ead1405bf6ef22c8a5bee6154cb3c6 100644 (file)
@@ -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;