diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-02-14 22:22:55 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-02-14 22:22:55 +0000 |
commit | 137349a07625326251e8a090b4bc84398f766968 (patch) | |
tree | b71dac539a712d67e4bbf9c229e2fed16dba56e2 | |
parent | 160fbf87d40f343f15aa1186135e34decc6cdf03 (diff) | |
download | rspamd-137349a07625326251e8a090b4bc84398f766968.tar.gz rspamd-137349a07625326251e8a090b4bc84398f766968.zip |
Add error codes for statistics.
-rw-r--r-- | src/controller.c | 3 | ||||
-rw-r--r-- | src/libstat/stat_api.h | 18 | ||||
-rw-r--r-- | src/libstat/stat_process.c | 32 |
3 files changed, 35 insertions, 18 deletions
diff --git a/src/controller.c b/src/controller.c index a0677f49e..e1fa3cb82 100644 --- a/src/controller.c +++ b/src/controller.c @@ -730,7 +730,8 @@ rspamd_controller_learn_fin_task (void *ud) conn_ent = task->fin_arg; session = conn_ent->ud; - if (!rspamd_learn_task_spam (session->cl, task, session->is_spam, &err)) { + if (rspamd_learn_task_spam (session->cl, task, session->is_spam, &err) == + RSPAMD_STAT_PROCESS_ERROR) { rspamd_controller_send_error (conn_ent, 500 + err->code, err->message); return TRUE; } diff --git a/src/libstat/stat_api.h b/src/libstat/stat_api.h index c0023ffbd..48c7c53c6 100644 --- a/src/libstat/stat_api.h +++ b/src/libstat/stat_api.h @@ -33,6 +33,18 @@ */ /** + * The results of statistics processing: + * - error + * - need to do additional job for processing + * - all processed + */ +typedef enum rspamd_stat_result_e { + RSPAMD_STAT_PROCESS_ERROR = 0, + RSPAMD_STAT_PROCESS_DELAYED = 1, + RSPAMD_STAT_PROCESS_OK +} rspamd_stat_result_t; + +/** * Initialise statistics modules * @param cfg */ @@ -43,7 +55,8 @@ void rspamd_stat_init (struct rspamd_config *cfg); * @param task * @return TRUE if task has been classified */ -gboolean rspamd_stat_classify (struct rspamd_task *task, lua_State *L, GError **err); +rspamd_stat_result_t rspamd_stat_classify (struct rspamd_task *task, + lua_State *L, GError **err); /** @@ -52,7 +65,8 @@ gboolean rspamd_stat_classify (struct rspamd_task *task, lua_State *L, GError ** * @param spam if TRUE learn spam, otherwise learn ham * @return TRUE if task has been learned */ -gboolean rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L, +rspamd_stat_result_t rspamd_stat_learn (struct rspamd_task *task, + gboolean spam, lua_State *L, GError **err); /** diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c index 8492349a4..8b2a19429 100644 --- a/src/libstat/stat_process.c +++ b/src/libstat/stat_process.c @@ -309,7 +309,7 @@ rspamd_stat_process_tokenize (struct rspamd_stat_ctx *st_ctx, } -gboolean +rspamd_stat_result_t rspamd_stat_classify (struct rspamd_task *task, lua_State *L, GError **err) { struct rspamd_stat_classifier *cls; @@ -320,7 +320,7 @@ rspamd_stat_classify (struct rspamd_task *task, lua_State *L, GError **err) struct classifier_ctx *cl_ctx; GList *cl_runtimes; GList *cur; - gboolean ret = FALSE; + gboolean ret = RSPAMD_STAT_PROCESS_ERROR; st_ctx = rspamd_stat_get_ctx (); g_assert (st_ctx != NULL); @@ -335,7 +335,7 @@ rspamd_stat_classify (struct rspamd_task *task, lua_State *L, GError **err) if (cls == NULL) { g_set_error (err, rspamd_stat_quark (), 500, "type %s is not defined" "for classifiers", clcf->classifier); - return FALSE; + return RSPAMD_STAT_PROCESS_ERROR; } tok = rspamd_stat_get_tokenizer_runtime (clcf->tokenizer, task->task_pool, @@ -344,7 +344,7 @@ rspamd_stat_classify (struct rspamd_task *task, lua_State *L, GError **err) if (tok == NULL) { g_set_error (err, rspamd_stat_quark (), 500, "type %s is not defined" "for tokenizers", clcf->tokenizer); - return FALSE; + return RSPAMD_STAT_PROCESS_ERROR; } rspamd_stat_process_tokenize (st_ctx, task, tok); @@ -355,7 +355,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, tklist, L, FALSE, FALSE, err)) == NULL) { - return FALSE; + return RSPAMD_STAT_PROCESS_ERROR; } cur = cl_runtimes; @@ -367,8 +367,10 @@ rspamd_stat_classify (struct rspamd_task *task, lua_State *L, GError **err) cl_ctx = cl_run->cl->init_func (task->task_pool, cl_run->clcf); if (cl_ctx != NULL) { - ret |= cl_run->cl->classify_func (cl_ctx, cl_run->tok->tokens, - cl_run, task); + if (cl_run->cl->classify_func (cl_ctx, cl_run->tok->tokens, + cl_run, task)) { + ret = RSPAMD_STAT_PROCESS_OK; + } } } @@ -437,7 +439,7 @@ rspamd_stat_learn_token (gpointer k, gpointer v, gpointer d) return FALSE; } -gboolean +rspamd_stat_result_t rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L, GError **err) { @@ -451,7 +453,7 @@ 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 = FALSE, unlearn = FALSE; + gboolean ret = RSPAMD_STAT_PROCESS_ERROR, unlearn = FALSE; gulong nrev; rspamd_learn_t learn_res = RSPAMD_LEARN_OK; guint i; @@ -469,7 +471,7 @@ rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L, if (cls == NULL) { g_set_error (err, rspamd_stat_quark (), 500, "type %s is not defined" "for classifiers", clcf->classifier); - return FALSE; + return RSPAMD_STAT_PROCESS_ERROR; } tok = rspamd_stat_get_tokenizer_runtime (clcf->tokenizer, task->task_pool, @@ -478,7 +480,7 @@ rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L, if (tok == NULL) { g_set_error (err, rspamd_stat_quark (), 500, "type %s is not defined" "for tokenizers", clcf->tokenizer); - return FALSE; + return RSPAMD_STAT_PROCESS_ERROR; } rspamd_stat_process_tokenize (st_ctx, task, tok); @@ -496,7 +498,7 @@ rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L, g_set_error (err, rspamd_stat_quark (), 404, "<%s> has been already " "learned as %s, ignore it", task->message_id, spam ? "spam" : "ham"); - return FALSE; + return RSPAMD_STAT_PROCESS_ERROR; } else if (learn_res == RSPAMD_LEARN_UNLEARN) { unlearn = TRUE; @@ -506,7 +508,7 @@ 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, tklist, L, TRUE, spam, err)) == NULL) { - return FALSE; + return RSPAMD_STAT_PROCESS_ERROR; } cur = cl_runtimes; @@ -522,7 +524,7 @@ rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L, cl_run, task, spam, err)) { msg_debug ("learned %s classifier %s", spam ? "spam" : "ham", cl_run->clcf->name); - ret = TRUE; + ret = RSPAMD_STAT_PROCESS_OK; cbdata.classifier_runtimes = cur; cbdata.task = task; @@ -546,7 +548,7 @@ rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L, } } else { - return FALSE; + return RSPAMD_STAT_PROCESS_ERROR; } } |