diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-11-23 18:36:41 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-11-23 18:36:41 +0000 |
commit | 3280d0a385cc84c4f2b44a556c26a73291d59820 (patch) | |
tree | 7354c0d009e8df9166aa7d379c4ff03fcf1569a0 /src/libstat/stat_process.c | |
parent | 171031923755ae89ed2672130b3fb3665c5c8796 (diff) | |
download | rspamd-3280d0a385cc84c4f2b44a556c26a73291d59820.tar.gz rspamd-3280d0a385cc84c4f2b44a556c26a73291d59820.zip |
Restore multiple classifiers support
Diffstat (limited to 'src/libstat/stat_process.c')
-rw-r--r-- | src/libstat/stat_process.c | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c index b19663893..952330b49 100644 --- a/src/libstat/stat_process.c +++ b/src/libstat/stat_process.c @@ -353,7 +353,11 @@ preprocess_init_stat_token (gpointer k, gpointer v, gpointer d) static GList* rspamd_stat_preprocess (struct rspamd_stat_ctx *st_ctx, struct rspamd_task *task, - lua_State *L, gint op, gboolean spam, GError **err) + lua_State *L, + gint op, + gboolean spam, + const gchar *classifier, + GError **err) { struct rspamd_classifier_config *clcf; struct rspamd_statfile_config *stcf; @@ -373,6 +377,15 @@ rspamd_stat_preprocess (struct rspamd_stat_ctx *st_ctx, clcf = (struct rspamd_classifier_config *)cur->data; st_list = NULL; + if (classifier != NULL && + (clcf->name == NULL || strcmp (clcf->name, classifier) != 0)) { + /* Skip this classifier */ + msg_debug_task ("skip classifier %s, as we are requested to check %s only", + clcf->name, classifier); + cur = g_list_next (cur); + continue; + } + if (clcf->pre_callbacks != NULL) { st_list = rspamd_lua_call_cls_pre_callbacks (clcf, task, FALSE, FALSE, L); @@ -518,6 +531,11 @@ rspamd_stat_preprocess (struct rspamd_stat_ctx *st_ctx, g_tree_foreach (cbdata.tok->tokens, preprocess_init_stat_token, &cbdata); } + else if (classifier != NULL) { + /* We likely cannot find any classifier with this name */ + g_set_error (err, rspamd_stat_quark (), 404, + "cannot find classifier %s", classifier); + } return cl_runtimes; } @@ -538,7 +556,7 @@ rspamd_stat_classify (struct rspamd_task *task, lua_State *L, GError **err) /* Initialize classifiers and statfiles runtime */ if ((cl_runtimes = rspamd_stat_preprocess (st_ctx, task, L, - RSPAMD_CLASSIFY_OP, FALSE, err)) == NULL) { + RSPAMD_CLASSIFY_OP, FALSE, NULL, err)) == NULL) { return RSPAMD_STAT_PROCESS_OK; } @@ -659,7 +677,10 @@ rspamd_stat_learn_token (gpointer k, gpointer v, gpointer d) } rspamd_stat_result_t -rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L, +rspamd_stat_learn (struct rspamd_task *task, + gboolean spam, + lua_State *L, + const gchar *classifier, GError **err) { struct rspamd_stat_ctx *st_ctx; @@ -669,7 +690,8 @@ rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L, struct preprocess_cb_data cbdata; GList *cl_runtimes; GList *cur, *curst; - gboolean ret = RSPAMD_STAT_PROCESS_ERROR, unlearn = FALSE; + gboolean unlearn = FALSE; + rspamd_stat_result_t ret = RSPAMD_STAT_PROCESS_ERROR; gulong nrev; rspamd_learn_t learn_res = RSPAMD_LEARN_OK; guint i; @@ -698,8 +720,13 @@ rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L, } /* Initialize classifiers and statfiles runtime */ - if ((cl_runtimes = rspamd_stat_preprocess (st_ctx, task, L, - unlearn ? RSPAMD_UNLEARN_OP : RSPAMD_LEARN_OP, spam, err)) == NULL) { + if ((cl_runtimes = rspamd_stat_preprocess (st_ctx, + task, + L, + unlearn ? RSPAMD_UNLEARN_OP : RSPAMD_LEARN_OP, + spam, + classifier, + err)) == NULL) { return RSPAMD_STAT_PROCESS_ERROR; } |