RSPAMD_TASK_STAGE_READ_MESSAGE = (1 << 2),
RSPAMD_TASK_STAGE_PRE_FILTERS = (1 << 3),
RSPAMD_TASK_STAGE_FILTERS = (1 << 4),
- RSPAMD_TASK_STAGE_CLASSIFIERS = (1 << 5),
- RSPAMD_TASK_STAGE_COMPOSITES = (1 << 6),
- RSPAMD_TASK_STAGE_POST_FILTERS = (1 << 7),
- RSPAMD_TASK_STAGE_DONE = (1 << 8),
- RSPAMD_TASK_STAGE_REPLIED = (1 << 9)
+ RSPAMD_TASK_STAGE_CLASSIFIERS_PRE = (1 << 5),
+ RSPAMD_TASK_STAGE_CLASSIFIERS = (1 << 6),
+ RSPAMD_TASK_STAGE_CLASSIFIERS_POST = (1 << 7),
+ RSPAMD_TASK_STAGE_COMPOSITES = (1 << 8),
+ RSPAMD_TASK_STAGE_POST_FILTERS = (1 << 9),
+ RSPAMD_TASK_STAGE_DONE = (1 << 10),
+ RSPAMD_TASK_STAGE_REPLIED = (1 << 11)
};
#define RSPAMD_TASK_PROCESS_ALL (RSPAMD_TASK_STAGE_CONNECT | \
RSPAMD_TASK_STAGE_READ_MESSAGE | \
RSPAMD_TASK_STAGE_PRE_FILTERS | \
RSPAMD_TASK_STAGE_FILTERS | \
+ RSPAMD_TASK_STAGE_CLASSIFIERS_PRE | \
RSPAMD_TASK_STAGE_CLASSIFIERS | \
+ RSPAMD_TASK_STAGE_CLASSIFIERS_POST | \
RSPAMD_TASK_STAGE_COMPOSITES | \
RSPAMD_TASK_STAGE_POST_FILTERS | \
RSPAMD_TASK_STAGE_DONE)
GList *messages; /**< list of messages that would be reported */
struct rspamd_re_runtime *re_rt; /**< regexp runtime */
+ GList *cl_runtimes; /**< classifiers runtime */
struct rspamd_config *cfg; /**< pointer to config object */
GError *err;
rspamd_mempool_t *task_pool; /**< memory pool for task */
}
rspamd_stat_result_t
-rspamd_stat_classify (struct rspamd_task *task, lua_State *L, GError **err)
+rspamd_stat_classify (struct rspamd_task *task, lua_State *L, guint stage,
+ GError **err)
{
struct rspamd_stat_ctx *st_ctx;
struct rspamd_statfile_runtime *st_run;
st_ctx = rspamd_stat_get_ctx ();
g_assert (st_ctx != NULL);
+ cl_runtimes = task->cl_runtimes;
+
+ if (stage == RSPAMD_TASK_STAGE_CLASSIFIERS_PRE) {
+ /* Initialize classifiers and statfiles runtime */
+ if (task->cl_runtimes == NULL) {
+ if ((cl_runtimes = rspamd_stat_preprocess (st_ctx, task, L,
+ RSPAMD_CLASSIFY_OP, FALSE, NULL, err)) == NULL) {
+ return RSPAMD_STAT_PROCESS_OK;
+ }
- /* Initialize classifiers and statfiles runtime */
- if ((cl_runtimes = rspamd_stat_preprocess (st_ctx, task, L,
- RSPAMD_CLASSIFY_OP, FALSE, NULL, err)) == NULL) {
- return RSPAMD_STAT_PROCESS_OK;
- }
+ task->cl_runtimes = cl_runtimes;
+ }
- cur = cl_runtimes;
+ cur = cl_runtimes;
- while (cur) {
- cl_run = (struct rspamd_classifier_runtime *)cur->data;
- cl_run->stage = RSPAMD_STAT_STAGE_PRE;
+ while (cur) {
+ cl_run = (struct rspamd_classifier_runtime *) cur->data;
+ cl_run->stage = RSPAMD_STAT_STAGE_PRE;
- if (cl_run->cl) {
- cl_ctx = cl_run->cl->init_func (task->task_pool, cl_run->clcf);
+ if (cl_run->cl) {
+ cl_ctx = cl_run->cl->init_func (task->task_pool, cl_run->clcf);
- if (cl_ctx != NULL) {
- cl_run->cl->classify_func (cl_ctx, cl_run->tok->tokens,
- cl_run, task);
+ if (cl_ctx != NULL) {
+ cl_run->cl->classify_func (cl_ctx, cl_run->tok->tokens,
+ cl_run, task);
+ }
}
- }
- cur = g_list_next (cur);
+ cur = g_list_next (cur);
+ }
}
+ else if (stage == RSPAMD_TASK_STAGE_CLASSIFIERS) {
+ cur = cl_runtimes;
+ while (cur) {
+ cl_run = (struct rspamd_classifier_runtime *) cur->data;
+ cl_run->stage = RSPAMD_STAT_STAGE_POST;
- /* XXX: backend runtime post-processing */
- /* Post-processing */
- cur = cl_runtimes;
- while (cur) {
- 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,
+ cl_run, task)) {
+ ret = RSPAMD_STAT_PROCESS_OK;
+ }
+ }
+ }
- if (cl_run->skipped) {
cur = g_list_next (cur);
- continue;
}
+ }
+ else if (stage == RSPAMD_TASK_STAGE_CLASSIFIERS_POST) {
+ cur = cl_runtimes;
+ while (cur) {
+ cl_run = (struct rspamd_classifier_runtime *) cur->data;
+ cl_run->stage = RSPAMD_STAT_STAGE_POST;
- if (cl_run->cl) {
- if (cl_ctx != NULL) {
- if (cl_run->cl->classify_func (cl_ctx, cl_run->tok->tokens,
- cl_run, task)) {
- ret = RSPAMD_STAT_PROCESS_OK;
- }
+ if (cl_run->skipped) {
+ cur = g_list_next (cur);
+ continue;
}
- }
- curst = cl_run->st_runtime;
+ curst = cl_run->st_runtime;
- while (curst) {
- st_run = curst->data;
- cl_run->backend->finalize_process (task,
- st_run->backend_runtime,
- cl_run->backend->ctx);
- curst = g_list_next (curst);
- }
+ while (curst) {
+ st_run = curst->data;
+ cl_run->backend->finalize_process (task,
+ st_run->backend_runtime,
+ cl_run->backend->ctx);
+ curst = g_list_next (curst);
+ }
- cur = g_list_next (cur);
+ cur = g_list_next (cur);
+ }
}
return ret;