* High level statistics API
*/
+/**
+ * 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
* @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);
/**
* @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);
/**
}
-gboolean
+rspamd_stat_result_t
rspamd_stat_classify (struct rspamd_task *task, lua_State *L, GError **err)
{
struct rspamd_stat_classifier *cls;
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);
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,
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);
/* 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;
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;
+ }
}
}
return FALSE;
}
-gboolean
+rspamd_stat_result_t
rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L,
GError **err)
{
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;
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,
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);
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;
/* 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;
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;
}
}
else {
- return FALSE;
+ return RSPAMD_STAT_PROCESS_ERROR;
}
}