aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-07-23 20:02:33 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-07-23 20:02:33 +0400
commit3035b4fcc174228d058a0c4cc6871a01340326d0 (patch)
treed754ce1d7da6074eb02c375b3f324504576d740b
parent6e59414a267e239bb42edc35b9fecd5ba2992067 (diff)
downloadrspamd-3035b4fcc174228d058a0c4cc6871a01340326d0.tar.gz
rspamd-3035b4fcc174228d058a0c4cc6871a01340326d0.zip
* Make modules disableable from config
-rw-r--r--src/cfg_utils.c1
-rw-r--r--src/filter.h1
-rw-r--r--src/main.c39
3 files changed, 32 insertions, 9 deletions
diff --git a/src/cfg_utils.c b/src/cfg_utils.c
index 7307db803..30318ffda 100644
--- a/src/cfg_utils.c
+++ b/src/cfg_utils.c
@@ -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;
diff --git a/src/filter.h b/src/filter.h
index 56a70fdf7..6ff3ae1d0 100644
--- a/src/filter.h
+++ b/src/filter.h
@@ -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;
};
/**
diff --git a/src/main.c b/src/main.c
index c9c0fdfa6..2ff31ecfc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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 */