From: Vsevolod Stakhov Date: Sat, 8 Oct 2016 15:27:15 +0000 (+0100) Subject: [Minor] More fixes to backend-less classifiers X-Git-Tag: 1.4.0~297 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be2828419394df4339c793ce8526b5327da388d9;p=thirdparty%2Frspamd.git [Minor] More fixes to backend-less classifiers --- diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c index f153be7374..8a953f47bc 100644 --- a/src/libstat/stat_config.c +++ b/src/libstat/stat_config.c @@ -238,9 +238,13 @@ rspamd_stat_init (struct rspamd_config *cfg, struct event_base *ev_base) if (!(cl->cfg->flags & RSPAMD_FLAG_CLASSIFIER_NO_BACKEND)) { st->backend = bk; st->bkcf = bk->init (stat_ctx, cfg, st); + msg_debug_config ("added backend %s for symbol %s", + bk->name, stf->symbol); + } + else { + msg_debug_config ("added backend-less statfile for symbol %s", + stf->symbol); } - msg_debug_config ("added backend %s for symbol %s", - bk->name, stf->symbol); /* XXX: bad hack to pass statfiles configuration to cache */ if (cl->cache == NULL) { diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c index 7eeac00c17..ea0fcd601f 100644 --- a/src/libstat/stat_process.c +++ b/src/libstat/stat_process.c @@ -275,6 +275,7 @@ rspamd_stat_preprocess (struct rspamd_stat_ctx *st_ctx, rspamd_stat_process_tokenize (st_ctx, task); task->stat_runtimes = g_ptr_array_sized_new (st_ctx->statfiles->len); + g_ptr_array_set_size (task->stat_runtimes, st_ctx->statfiles->len); rspamd_mempool_add_destructor (task->task_pool, rspamd_ptr_array_free_hard, task->stat_runtimes); @@ -282,6 +283,11 @@ rspamd_stat_preprocess (struct rspamd_stat_ctx *st_ctx, st = g_ptr_array_index (st_ctx->statfiles, i); g_assert (st != NULL); + if (st->classifier->cfg->flags & RSPAMD_FLAG_CLASSIFIER_NO_BACKEND) { + g_ptr_array_index (task->stat_runtimes, i) = NULL; + continue; + } + bk_run = st->backend->runtime (task, st->stcf, learn, st->bkcf); if (bk_run == NULL) { @@ -289,7 +295,7 @@ rspamd_stat_preprocess (struct rspamd_stat_ctx *st_ctx, st->backend->name, st->stcf->symbol); } - g_ptr_array_add (task->stat_runtimes, bk_run); + g_ptr_array_index (task->stat_runtimes, i) = bk_run; } } @@ -728,7 +734,7 @@ rspamd_stat_backends_learn (struct rspamd_stat_ctx *st_ctx, } end: - if (sel == NULL) { + if (!res && sel == NULL) { if (classifier) { g_set_error (err, rspamd_stat_quark (), 404, "cannot find classifier " "with name %s", classifier);