]> source.dussan.org Git - rspamd.git/commitdiff
* Make modules disableable from config
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 23 Jul 2009 16:02:33 +0000 (20:02 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 23 Jul 2009 16:02:33 +0000 (20:02 +0400)
src/cfg_utils.c
src/filter.h
src/main.c

index 7307db8030e90455e3ab51c57bee76a46327a5a9..30318ffda08eb2a72f523cdc80cf21aa326d2770 100644 (file)
@@ -418,6 +418,7 @@ parse_filters_str (struct config_file *cfg, const char *str)
                                cur->type = C_FILTER;
                                msg_debug ("parse_filters_str: found C filter %s", *p);
                                cur->func_name = memory_pool_strdup (cfg->cfg_pool, *p);
+                cur->module = &modules[i];
                                cfg->filters = g_list_prepend (cfg->filters, cur);
 
                                break;
index 56a70fdf7c56bc1c7991c2be8e105f090b9ec610..6ff3ae1d0c72c0771cf2502e91bdb94c90e1bfab 100644 (file)
@@ -22,6 +22,7 @@ enum filter_type { C_FILTER, PERL_FILTER };
 struct filter {
        char *func_name;                                                                /**< function name                                                      */
        enum filter_type type;                                                  /**< filter type (c or perl)                            */
+    module_t *module;
 };
 
 /**
index c9c0fdfa6203a5e124df2747192860c8dbd34de5..2ff31ecfc43a252a27261cfd8597f3ac3ab88ff3 100644 (file)
@@ -442,6 +442,7 @@ main (int argc, char **argv, char **env)
        struct rlimit rlim;
        struct metric *metric;
        struct cache_item *item;
+       struct filter *filt;
        FILE *f;
        pid_t wrk;
        GList *l;
@@ -519,11 +520,17 @@ main (int argc, char **argv, char **env)
        counters = rspamd_hash_new_shared (rspamd->server_pool, g_str_hash, g_str_equal, 64);
 
        /* Init C modules */
-       for (i = 0; i < MODULES_NUM; i ++) {
-               cur_module = memory_pool_alloc (rspamd->cfg->cfg_pool, sizeof (struct module_ctx));
-               if (modules[i].module_init_func(cfg, &cur_module) == 0) {
-                       g_hash_table_insert (cfg->c_modules, (gpointer)modules[i].name, cur_module);
+    l = g_list_first (rspamd->cfg->filters);
+
+       while (l) {
+               filt = l->data;
+               if (filt->module) {
+                       cur_module = memory_pool_alloc (rspamd->cfg->cfg_pool, sizeof (struct module_ctx));
+                       if (filt->module->module_init_func(cfg, &cur_module) == 0) {
+                               g_hash_table_insert (cfg->c_modules, (gpointer)filt->module->name, cur_module);
+                       }
                }
+               l = g_list_next (l);
        }
 
        if (cfg->config_test || dump_vars || dump_cache) {
@@ -531,10 +538,16 @@ main (int argc, char **argv, char **env)
                event_init ();
                res = TRUE;
                /* Perform modules configuring */
-               for (i = 0; i < MODULES_NUM; i ++) {
-                       if (!modules[i].module_config_func (cfg)) {
-                               res = FALSE;
+               l = g_list_first (rspamd->cfg->filters);
+
+               while (l) {
+                       filt = l->data;
+                       if (filt->module) {
+                               if (filt->module->module_config_func (cfg)) {
+                                       res = FALSE;
+                               }
                        }
+                       l = g_list_next (l);
                }
                if (dump_vars) {
                        dump_cfg_vars ();
@@ -637,8 +650,16 @@ main (int argc, char **argv, char **env)
        g_mime_init (0);
 
        /* Perform modules configuring */
-       for (i = 0; i < MODULES_NUM; i ++) {
-               modules[i].module_config_func (cfg);
+       l = g_list_first (rspamd->cfg->filters);
+
+       while (l) {
+               filt = l->data;
+               if (filt->module) {
+                       if (filt->module->module_config_func (cfg)) {
+                               res = FALSE;
+                       }
+               }
+               l = g_list_next (l);
        }
 
        /* Init symbols cache for each metric */