diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-05 15:20:28 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-05 15:20:28 +0000 |
commit | 603f3664584a2942b718a16a2c303212fdc4871a (patch) | |
tree | 4989a602effc84988e1bd378918e615aa02a1108 /src/libstat/stat_config.c | |
parent | 57a464ab523700fc7f2ab3f116724cd198799da8 (diff) | |
download | rspamd-603f3664584a2942b718a16a2c303212fdc4871a.tar.gz rspamd-603f3664584a2942b718a16a2c303212fdc4871a.zip |
Start rework
Diffstat (limited to 'src/libstat/stat_config.c')
-rw-r--r-- | src/libstat/stat_config.c | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c index dbfe16c27..a8afc1358 100644 --- a/src/libstat/stat_config.c +++ b/src/libstat/stat_config.c @@ -93,6 +93,11 @@ void rspamd_stat_init (struct rspamd_config *cfg) { guint i; + GList *cur, *curst; + struct rspamd_classifier_config *clf; + struct rspamd_statfile_config *stf; + struct rspamd_stat_backend *bk; + struct rspamd_statfile *st; if (stat_ctx == NULL) { stat_ctx = g_slice_alloc0 (sizeof (*stat_ctx)); @@ -107,11 +112,52 @@ rspamd_stat_init (struct rspamd_config *cfg) stat_ctx->caches = stat_caches; stat_ctx->caches_count = G_N_ELEMENTS (stat_caches); stat_ctx->cfg = cfg; + REF_RETAIN (stat_ctx->cfg); + + /* Create statfiles from the classifiers */ + cur = cfg->classifiers; + + while (cur) { + clf = cur->data; + bk = rspamd_stat_get_backend (clf->backend); + g_assert (bk != NULL); + + /* XXX: + * Here we get the first classifier tokenizer config as the only one + * We NO LONGER support multiple tokenizers per rspamd instance + */ + if (stat_ctx->tkcf == NULL) { + stat_ctx->tokenizer = rspamd_stat_get_tokenizer (clf->tokenizer); + g_assert (stat_ctx->tokenizer != NULL); + stat_ctx->tkcf = stat_ctx->tokenizer->get_config (cfg->cfg_pool, + clf->tokenizer, NULL); + } - /* Init backends */ - for (i = 0; i < stat_ctx->backends_count; i ++) { - stat_ctx->backends[i].ctx = stat_ctx->backends[i].init (stat_ctx, cfg); - msg_debug_config ("added backend %s", stat_ctx->backends[i].name); + curst = clf->statfiles; + + while (curst) { + stf = curst->data; + st = g_slice_alloc0 (sizeof (*st)); + st->clcf = clf; + st->stcf = stf; + st->tkcf = stat_ctx->tkcf; + st->bkcf = stat_ctx->backends[i].init (stat_ctx, cfg, st); + msg_debug_config ("added backend %s", stat_ctx->backends[i].name); + + if (st->bkcf == NULL) { + msg_err_config ("cannot init backend %s for statfile %s", + clf->backend, stf->symbol); + + g_slice_free1 (sizeof (*st), st); + } + else { + g_ptr_array_add (stat_ctx->statfiles, st); + } + + curst = curst->next; + } + + cur = cur->next; } /* Init caches */ @@ -135,6 +181,8 @@ rspamd_stat_close (void) msg_debug_config ("closed backend %s", stat_ctx->backends[i].name); } } + + REF_RELEASE (stat_ctx->cfg); } struct rspamd_stat_ctx * |