aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstat/stat_process.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-07-14 12:29:54 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-07-14 12:29:54 +0100
commit0c4806f821e563a2b208daf9cf5ebf2e86509638 (patch)
tree2b11abffe61c00829fa4f8f0c32db5461a368766 /src/libstat/stat_process.c
parent18b2d65f76df3f75d9217db4d3dc3df32f3cceb6 (diff)
downloadrspamd-0c4806f821e563a2b208daf9cf5ebf2e86509638.tar.gz
rspamd-0c4806f821e563a2b208daf9cf5ebf2e86509638.zip
[Minor] Fix errors reporting on learn errors
Diffstat (limited to 'src/libstat/stat_process.c')
-rw-r--r--src/libstat/stat_process.c52
1 files changed, 47 insertions, 5 deletions
diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c
index cca676288..49585af66 100644
--- a/src/libstat/stat_process.c
+++ b/src/libstat/stat_process.c
@@ -389,7 +389,7 @@ rspamd_stat_cache_check (struct rspamd_stat_ctx *st_ctx,
GError **err)
{
rspamd_learn_t learn_res = RSPAMD_LEARN_OK;
- struct rspamd_classifier *cl;
+ struct rspamd_classifier *cl, *sel = NULL;
gpointer rt;
guint i;
@@ -403,8 +403,10 @@ rspamd_stat_cache_check (struct rspamd_stat_ctx *st_ctx,
continue;
}
- if (cl->cache && cl->cachecf) {
- rt = cl->cache->runtime (task, cl->cachecf, FALSE);
+ sel = cl;
+
+ if (sel->cache && sel->cachecf) {
+ rt = cl->cache->runtime (task, sel->cachecf, FALSE);
learn_res = cl->cache->check (task, spam, rt);
}
@@ -423,6 +425,18 @@ rspamd_stat_cache_check (struct rspamd_stat_ctx *st_ctx,
}
}
+ if (sel == NULL) {
+ if (classifier) {
+ g_set_error (err, rspamd_stat_quark (), 404, "cannot find classifier "
+ "with name %s", classifier);
+ }
+ else {
+ g_set_error (err, rspamd_stat_quark (), 404, "no classifiers defined");
+ }
+
+ return FALSE;
+ }
+
return TRUE;
}
@@ -433,7 +447,7 @@ rspamd_stat_classifiers_learn (struct rspamd_stat_ctx *st_ctx,
gboolean spam,
GError **err)
{
- struct rspamd_classifier *cl;
+ struct rspamd_classifier *cl, *sel = NULL;
guint i;
gboolean learned = FALSE, too_small = FALSE, too_large = FALSE,
conditionally_skipped = FALSE;
@@ -453,6 +467,8 @@ rspamd_stat_classifiers_learn (struct rspamd_stat_ctx *st_ctx,
continue;
}
+ sel = cl;
+
/* Now check max and min tokens */
if (cl->cfg->min_tokens > 0 && task->tokens->len < cl->cfg->min_tokens) {
msg_info_task (
@@ -529,6 +545,18 @@ rspamd_stat_classifiers_learn (struct rspamd_stat_ctx *st_ctx,
}
}
+ if (sel == NULL) {
+ if (classifier) {
+ g_set_error (err, rspamd_stat_quark (), 404, "cannot find classifier "
+ "with name %s", classifier);
+ }
+ else {
+ g_set_error (err, rspamd_stat_quark (), 404, "no classifiers defined");
+ }
+
+ return FALSE;
+ }
+
if (!learned && err && *err == NULL) {
if (too_large) {
g_set_error (err, rspamd_stat_quark (), 400,
@@ -568,7 +596,7 @@ rspamd_stat_backends_learn (struct rspamd_stat_ctx *st_ctx,
gboolean spam,
GError **err)
{
- struct rspamd_classifier *cl;
+ struct rspamd_classifier *cl, *sel = NULL;
struct rspamd_statfile *st;
gpointer bk_run;
guint i, j;
@@ -584,6 +612,8 @@ rspamd_stat_backends_learn (struct rspamd_stat_ctx *st_ctx,
continue;
}
+ sel = cl;
+
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);
@@ -622,6 +652,18 @@ rspamd_stat_backends_learn (struct rspamd_stat_ctx *st_ctx,
}
}
+ if (sel == NULL) {
+ if (classifier) {
+ g_set_error (err, rspamd_stat_quark (), 404, "cannot find classifier "
+ "with name %s", classifier);
+ }
+ else {
+ g_set_error (err, rspamd_stat_quark (), 404, "no classifiers defined");
+ }
+
+ return FALSE;
+ }
+
return res;
}