]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] More fixes to backend-less classifiers
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 8 Oct 2016 15:27:15 +0000 (16:27 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 8 Oct 2016 15:35:42 +0000 (16:35 +0100)
src/libstat/stat_config.c
src/libstat/stat_process.c

index f153be73745c758f6b96d12664633eded19071e1..8a953f47bc57d830fd46a86ec23605d3348eb6e4 100644 (file)
@@ -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) {
index 7eeac00c17c9349d1437c2073e4041c19071e95d..ea0fcd601f2f2913eb820f4c9bc4004811ad55c5 100644 (file)
@@ -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);