]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] More support of backend-less classifiers
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 6 Oct 2016 17:12:38 +0000 (18:12 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 6 Oct 2016 17:13:04 +0000 (18:13 +0100)
src/libstat/stat_config.c
src/libstat/stat_process.c

index 48f57246892d0705bcf3746510ac7e00ae6285af..59159da63aeae749ef0290d00190987e18a83e98 100644 (file)
@@ -234,8 +234,11 @@ rspamd_stat_init (struct rspamd_config *cfg, struct event_base *ev_base)
                        st = g_slice_alloc0 (sizeof (*st));
                        st->classifier = cl;
                        st->stcf = stf;
-                       st->backend = bk;
-                       st->bkcf = bk->init (stat_ctx, cfg, st);
+
+                       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);
 
@@ -256,7 +259,8 @@ rspamd_stat_init (struct rspamd_config *cfg, struct event_base *ev_base)
                                }
                        }
 
-                       if (st->bkcf == NULL) {
+                       if (st->bkcf == NULL &&
+                                       !(cl->cfg->flags & RSPAMD_FLAG_CLASSIFIER_NO_BACKEND)) {
                                msg_err_config ("cannot init backend %s for statfile %s",
                                                clf->backend, stf->symbol);
 
@@ -297,7 +301,9 @@ rspamd_stat_close (void)
                for (j = 0; j < cl->statfiles_ids->len; j ++) {
                        id = g_array_index (cl->statfiles_ids, gint, j);
                        st = g_ptr_array_index (st_ctx->statfiles, id);
-                       st->backend->close (st->bkcf);
+                       if (!(st->classifier->cfg->flags & RSPAMD_FLAG_CLASSIFIER_NO_BACKEND)) {
+                               st->backend->close (st->bkcf);
+                       }
 
                        g_slice_free1 (sizeof (*st), st);
                }
index 228360fa69ae8093027de01ba2b1ca212722976b..7eeac00c17c9349d1437c2073e4041c19071e95d 100644 (file)
@@ -306,8 +306,13 @@ rspamd_stat_backends_process (struct rspamd_stat_ctx *st_ctx,
 
        for (i = 0; i < st_ctx->statfiles->len; i++) {
                st = g_ptr_array_index (st_ctx->statfiles, i);
-               bk_run = g_ptr_array_index (task->stat_runtimes, i);
                cl = st->classifier;
+
+               if (cl->cfg->flags & RSPAMD_FLAG_CLASSIFIER_NO_BACKEND) {
+                       continue;
+               }
+
+               bk_run = g_ptr_array_index (task->stat_runtimes, i);
                g_assert (st != NULL);
 
                if (bk_run != NULL) {
@@ -333,12 +338,19 @@ rspamd_stat_backends_post_process (struct rspamd_stat_ctx *st_ctx,
 {
        guint i;
        struct rspamd_statfile *st;
+       struct rspamd_classifier *cl;
        gpointer bk_run;
 
        g_assert (task->stat_runtimes != NULL);
 
        for (i = 0; i < st_ctx->statfiles->len; i++) {
                st = g_ptr_array_index (st_ctx->statfiles, i);
+               cl = st->classifier;
+
+               if (cl->cfg->flags & RSPAMD_FLAG_CLASSIFIER_NO_BACKEND) {
+                       continue;
+               }
+
                bk_run = g_ptr_array_index (task->stat_runtimes, i);
                g_assert (st != NULL);