aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstat
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-22 17:02:10 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-22 17:02:10 +0100
commitbc235cf8d945e58b9fe13d5d17973457f45b8480 (patch)
tree8ef44a1e1552881129d6708adf92a52e093c6340 /src/libstat
parentdd3b11704d96d23c5c41641c53657367282b45f1 (diff)
downloadrspamd-bc235cf8d945e58b9fe13d5d17973457f45b8480.tar.gz
rspamd-bc235cf8d945e58b9fe13d5d17973457f45b8480.zip
Another iteration on #331.
Diffstat (limited to 'src/libstat')
-rw-r--r--src/libstat/classifiers/bayes.c26
-rw-r--r--src/libstat/stat_internal.h1
-rw-r--r--src/libstat/stat_process.c11
3 files changed, 25 insertions, 13 deletions
diff --git a/src/libstat/classifiers/bayes.c b/src/libstat/classifiers/bayes.c
index 03512f771..e248fd6e6 100644
--- a/src/libstat/classifiers/bayes.c
+++ b/src/libstat/classifiers/bayes.c
@@ -256,12 +256,14 @@ bayes_learn_spam_callback (gpointer key, gpointer value, gpointer data)
for (i = rt->start_pos; i < rt->end_pos; i++) {
res = &g_array_index (node->results, struct rspamd_token_result, i);
- if (res->st_runtime->st->is_spam) {
- res->value ++;
- }
- else if (res->value > 0) {
- /* Unlearning */
- res->value --;
+ if (res->st_runtime) {
+ if (res->st_runtime->st->is_spam) {
+ res->value ++;
+ }
+ else if (res->value > 0) {
+ /* Unlearning */
+ res->value --;
+ }
}
}
@@ -280,11 +282,13 @@ bayes_learn_ham_callback (gpointer key, gpointer value, gpointer data)
for (i = rt->start_pos; i < rt->end_pos; i++) {
res = &g_array_index (node->results, struct rspamd_token_result, i);
- if (!res->st_runtime->st->is_spam) {
- res->value ++;
- }
- else if (res->value > 0) {
- res->value --;
+ if (res->st_runtime) {
+ if (!res->st_runtime->st->is_spam) {
+ res->value ++;
+ }
+ else if (res->value > 0) {
+ res->value --;
+ }
}
}
diff --git a/src/libstat/stat_internal.h b/src/libstat/stat_internal.h
index cb2a365c4..076714411 100644
--- a/src/libstat/stat_internal.h
+++ b/src/libstat/stat_internal.h
@@ -63,6 +63,7 @@ struct rspamd_classifier_runtime {
GList *st_runtime;
guint start_pos;
guint end_pos;
+ gboolean skipped;
};
struct rspamd_token_result {
diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c
index 5318ab144..b5293f8ac 100644
--- a/src/libstat/stat_process.c
+++ b/src/libstat/stat_process.c
@@ -112,6 +112,8 @@ preprocess_init_stat_token (gpointer k, gpointer v, gpointer d)
g_tree_nnodes (cbdata->tok->tokens),
cl_runtime->clcf->min_tokens);
cur = g_list_next (cur);
+ cl_runtime->skipped = TRUE;
+
continue;
}
@@ -429,6 +431,11 @@ rspamd_stat_classify (struct rspamd_task *task, lua_State *L, GError **err)
cl_run = (struct rspamd_classifier_runtime *)cur->data;
cl_run->stage = RSPAMD_STAT_STAGE_POST;
+ if (cl_run->skipped) {
+ cur = g_list_next (cur);
+ continue;
+ }
+
if (cl_run->cl) {
if (cl_ctx != NULL) {
if (cl_run->cl->classify_func (cl_ctx, cl_run->tok->tokens,
@@ -442,7 +449,7 @@ rspamd_stat_classify (struct rspamd_task *task, lua_State *L, GError **err)
while (curst) {
st_run = curst->data;
- st_run->backend->finalize_learn (task,
+ st_run->backend->finalize_process (task,
st_run->backend_runtime,
st_run->backend->ctx);
curst = g_list_next (curst);
@@ -598,7 +605,7 @@ rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L,
while (cur) {
cl_run = (struct rspamd_classifier_runtime *)cur->data;
- if (cl_run->cl) {
+ if (cl_run->cl && !cl_run->skipped) {
cl_ctx = cl_run->cl->init_func (task->task_pool, cl_run->clcf);
if (cl_ctx != NULL) {