diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-06-24 17:21:18 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-06-24 17:21:18 +0100 |
commit | e3a61120f831ca275f95b0edf9e3fc94a384955f (patch) | |
tree | 99bbd5295eb1209e7cb9d1c0e5645862412bb1f6 /src/libstat | |
parent | 090643295a7e48d969adad833276e7a283d7f503 (diff) | |
download | rspamd-e3a61120f831ca275f95b0edf9e3fc94a384955f.tar.gz rspamd-e3a61120f831ca275f95b0edf9e3fc94a384955f.zip |
Pass task structure to classifier functions.
Diffstat (limited to 'src/libstat')
-rw-r--r-- | src/libstat/backends/backends.h | 41 | ||||
-rw-r--r-- | src/libstat/backends/mmaped_file.c | 12 | ||||
-rw-r--r-- | src/libstat/backends/sqlite3_backend.c | 14 | ||||
-rw-r--r-- | src/libstat/stat_process.c | 19 |
4 files changed, 50 insertions, 36 deletions
diff --git a/src/libstat/backends/backends.h b/src/libstat/backends/backends.h index f970a297b..e40bb6c9c 100644 --- a/src/libstat/backends/backends.h +++ b/src/libstat/backends/backends.h @@ -45,15 +45,19 @@ struct rspamd_stat_backend { gpointer (*init)(struct rspamd_stat_ctx *ctx, struct rspamd_config *cfg); gpointer (*runtime)(struct rspamd_task *task, struct rspamd_statfile_config *stcf, gboolean learn, gpointer ctx); - gboolean (*process_token)(struct token_node_s *tok, + gboolean (*process_token)(struct rspamd_task *task, struct token_node_s *tok, struct rspamd_token_result *res, gpointer ctx); - gboolean (*learn_token)(struct token_node_s *tok, + gboolean (*learn_token)(struct rspamd_task *task, struct token_node_s *tok, struct rspamd_token_result *res, gpointer ctx); - gulong (*total_learns)(struct rspamd_statfile_runtime *runtime, gpointer ctx); - void (*finalize_learn)(struct rspamd_statfile_runtime *runtime, gpointer ctx); - gulong (*inc_learns)(struct rspamd_statfile_runtime *runtime, gpointer ctx); - gulong (*dec_learns)(struct rspamd_statfile_runtime *runtime, gpointer ctx); - ucl_object_t* (*get_stat)(struct rspamd_statfile_runtime *runtime, gpointer ctx); + gulong (*total_learns)(struct rspamd_task *task, + gpointer runtime, gpointer ctx); + void (*finalize_learn)(struct rspamd_task *task, + gpointer runtime, gpointer ctx); + gulong (*inc_learns)(struct rspamd_task *task, + gpointer runtime, gpointer ctx); + gulong (*dec_learns)(struct rspamd_task *task, + gpointer runtime, gpointer ctx); + ucl_object_t* (*get_stat)(gpointer runtime, gpointer ctx); void (*close)(gpointer ctx); gpointer ctx; }; @@ -63,21 +67,28 @@ struct rspamd_stat_backend { gpointer rspamd_##name##_runtime (struct rspamd_task *task, \ struct rspamd_statfile_config *stcf, \ gboolean learn, gpointer ctx); \ - gboolean rspamd_##name##_process_token (struct token_node_s *tok, \ + gboolean rspamd_##name##_process_token (struct rspamd_task *task, \ + struct token_node_s *tok, \ struct rspamd_token_result *res, \ gpointer ctx); \ - gboolean rspamd_##name##_learn_token (struct token_node_s *tok, \ + gboolean rspamd_##name##_learn_token (struct rspamd_task *task, \ + struct token_node_s *tok, \ struct rspamd_token_result *res, \ gpointer ctx); \ - void rspamd_##name##_finalize_learn (gpointer runtime, \ + void rspamd_##name##_finalize_learn (struct rspamd_task *task, \ + gpointer runtime, \ gpointer ctx); \ - gulong rspamd_##name##_total_learns (gpointer runtime, \ + gulong rspamd_##name##_total_learns (struct rspamd_task *task, \ + gpointer runtime, \ gpointer ctx); \ - gulong rspamd_##name##_inc_learns (gpointer runtime, \ + gulong rspamd_##name##_inc_learns (struct rspamd_task *task, \ + gpointer runtime, \ gpointer ctx); \ - gulong rspamd_##name##_dec_learns (gpointer runtime, \ - gpointer ctx); \ - gulong rspamd_##name##_learns (gpointer runtime, \ + gulong rspamd_##name##_dec_learns (struct rspamd_task *task, \ + gpointer runtime, \ + gpointer ctx); \ + gulong rspamd_##name##_learns (struct rspamd_task *task, \ + gpointer runtime, \ gpointer ctx); \ ucl_object_t * rspamd_##name##_get_stat (gpointer runtime, \ gpointer ctx); \ diff --git a/src/libstat/backends/mmaped_file.c b/src/libstat/backends/mmaped_file.c index 7c12e092d..b7e5650d3 100644 --- a/src/libstat/backends/mmaped_file.c +++ b/src/libstat/backends/mmaped_file.c @@ -937,7 +937,7 @@ rspamd_mmaped_file_runtime (struct rspamd_task *task, } gboolean -rspamd_mmaped_file_process_token (rspamd_token_t *tok, +rspamd_mmaped_file_process_token (struct rspamd_task *task, rspamd_token_t *tok, struct rspamd_token_result *res, gpointer p) { @@ -971,7 +971,7 @@ rspamd_mmaped_file_process_token (rspamd_token_t *tok, } gboolean -rspamd_mmaped_file_learn_token (rspamd_token_t *tok, +rspamd_mmaped_file_learn_token (struct rspamd_task *task, rspamd_token_t *tok, struct rspamd_token_result *res, gpointer p) { @@ -1001,7 +1001,7 @@ rspamd_mmaped_file_learn_token (rspamd_token_t *tok, } gulong -rspamd_mmaped_file_total_learns (gpointer runtime, +rspamd_mmaped_file_total_learns (struct rspamd_task *task, gpointer runtime, gpointer ctx) { rspamd_mmaped_file_t *mf = (rspamd_mmaped_file_t *)runtime; @@ -1016,7 +1016,7 @@ rspamd_mmaped_file_total_learns (gpointer runtime, } gulong -rspamd_mmaped_file_inc_learns (gpointer runtime, +rspamd_mmaped_file_inc_learns (struct rspamd_task *task, gpointer runtime, gpointer ctx) { rspamd_mmaped_file_t *mf = (rspamd_mmaped_file_t *)runtime; @@ -1032,7 +1032,7 @@ rspamd_mmaped_file_inc_learns (gpointer runtime, } gulong -rspamd_mmaped_file_dec_learns (gpointer runtime, +rspamd_mmaped_file_dec_learns (struct rspamd_task *task, gpointer runtime, gpointer ctx) { rspamd_mmaped_file_t *mf = (rspamd_mmaped_file_t *)runtime; @@ -1080,7 +1080,7 @@ rspamd_mmaped_file_get_stat (gpointer runtime, } void -rspamd_mmaped_file_finalize_learn (gpointer runtime, +rspamd_mmaped_file_finalize_learn (struct rspamd_task *task, gpointer runtime, gpointer ctx) { rspamd_mmaped_file_t *mf = (rspamd_mmaped_file_t *)runtime; diff --git a/src/libstat/backends/sqlite3_backend.c b/src/libstat/backends/sqlite3_backend.c index ea52314fc..9eee2c614 100644 --- a/src/libstat/backends/sqlite3_backend.c +++ b/src/libstat/backends/sqlite3_backend.c @@ -476,7 +476,7 @@ rspamd_sqlite3_runtime (struct rspamd_task *task, } gboolean -rspamd_sqlite3_process_token (struct token_node_s *tok, +rspamd_sqlite3_process_token (struct rspamd_task *task, struct token_node_s *tok, struct rspamd_token_result *res, gpointer p) { struct rspamd_stat_sqlite3_db *bk; @@ -513,7 +513,7 @@ rspamd_sqlite3_process_token (struct token_node_s *tok, } gboolean -rspamd_sqlite3_learn_token (struct token_node_s *tok, +rspamd_sqlite3_learn_token (struct rspamd_task *task, struct token_node_s *tok, struct rspamd_token_result *res, gpointer p) { struct rspamd_stat_sqlite3_db *bk; @@ -549,7 +549,7 @@ rspamd_sqlite3_learn_token (struct token_node_s *tok, } void -rspamd_sqlite3_finalize_learn (gpointer runtime, +rspamd_sqlite3_finalize_learn (struct rspamd_task *task, gpointer runtime, gpointer ctx) { struct rspamd_stat_sqlite3_db *bk = runtime; @@ -565,7 +565,7 @@ rspamd_sqlite3_finalize_learn (gpointer runtime, } gulong -rspamd_sqlite3_total_learns (gpointer runtime, +rspamd_sqlite3_total_learns (struct rspamd_task *task, gpointer runtime, gpointer ctx) { struct rspamd_stat_sqlite3_db *bk = runtime; @@ -579,7 +579,7 @@ rspamd_sqlite3_total_learns (gpointer runtime, } gulong -rspamd_sqlite3_inc_learns (gpointer runtime, +rspamd_sqlite3_inc_learns (struct rspamd_task *task, gpointer runtime, gpointer ctx) { struct rspamd_stat_sqlite3_db *bk = runtime; @@ -594,7 +594,7 @@ rspamd_sqlite3_inc_learns (gpointer runtime, } gulong -rspamd_sqlite3_dec_learns (gpointer runtime, +rspamd_sqlite3_dec_learns (struct rspamd_task *task, gpointer runtime, gpointer ctx) { struct rspamd_stat_sqlite3_db *bk = runtime; @@ -609,7 +609,7 @@ rspamd_sqlite3_dec_learns (gpointer runtime, } gulong -rspamd_sqlite3_learns (gpointer runtime, +rspamd_sqlite3_learns (struct rspamd_task *task, gpointer runtime, gpointer ctx) { struct rspamd_stat_sqlite3_db *bk = runtime; diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c index f13ccc96e..93692a621 100644 --- a/src/libstat/stat_process.c +++ b/src/libstat/stat_process.c @@ -124,7 +124,7 @@ preprocess_init_stat_token (gpointer k, gpointer v, gpointer d) res->cl_runtime = cl_runtime; res->st_runtime = st_runtime; - if (st_runtime->backend->process_token (t, res, + if (st_runtime->backend->process_token (cbdata->task, t, res, st_runtime->backend->ctx)) { if (cl_runtime->clcf->max_tokens > 0 && @@ -226,11 +226,11 @@ rspamd_stat_preprocess (struct rspamd_stat_ctx *st_ctx, st_runtime->backend = bk; if (stcf->is_spam) { - cl_runtime->total_spam += bk->total_learns (backend_runtime, + cl_runtime->total_spam += bk->total_learns (task, backend_runtime, bk->ctx); } else { - cl_runtime->total_ham += bk->total_learns (backend_runtime, + cl_runtime->total_ham += bk->total_learns (task, backend_runtime, bk->ctx); } @@ -461,7 +461,7 @@ rspamd_stat_learn_token (gpointer k, gpointer v, gpointer d) res = &g_array_index (t->results, struct rspamd_token_result, i); st_runtime = (struct rspamd_statfile_runtime *)curst->data; - if (st_runtime->backend->learn_token (t, res, + if (st_runtime->backend->learn_token (cbdata->task, t, res, st_runtime->backend->ctx)) { cl_runtime->processed_tokens ++; @@ -596,19 +596,22 @@ rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L, st_run = (struct rspamd_statfile_runtime *)curst->data; if (unlearn && spam != st_run->st->is_spam) { - nrev = st_run->backend->dec_learns (st_run->backend_runtime, + nrev = st_run->backend->dec_learns (task, + st_run->backend_runtime, st_run->backend->ctx); msg_debug ("unlearned %s, new revision: %ul", st_run->st->symbol, nrev); } else { - nrev = st_run->backend->inc_learns (st_run->backend_runtime, + nrev = st_run->backend->inc_learns (task, + st_run->backend_runtime, st_run->backend->ctx); msg_debug ("learned %s, new revision: %ul", st_run->st->symbol, nrev); } - st_run->backend->finalize_learn (st_run->backend_runtime, + st_run->backend->finalize_learn (task, + st_run->backend_runtime, st_run->backend->ctx); curst = g_list_next (curst); @@ -662,7 +665,7 @@ rspamd_stat_statistics (struct rspamd_config *cfg, guint64 *total_learns) backend_runtime = bk->runtime (NULL, stcf, FALSE, bk->ctx); - learns += bk->total_learns (backend_runtime, bk->ctx); + learns += bk->total_learns (NULL, backend_runtime, bk->ctx); elt = bk->get_stat (backend_runtime, bk->ctx); if (elt != NULL) { |