]> source.dussan.org Git - rspamd.git/commitdiff
Pass task structure to classifier functions.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 24 Jun 2015 16:21:18 +0000 (17:21 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 24 Jun 2015 16:21:18 +0000 (17:21 +0100)
src/libstat/backends/backends.h
src/libstat/backends/mmaped_file.c
src/libstat/backends/sqlite3_backend.c
src/libstat/stat_process.c

index f970a297b794c5a28137ea7c622567a0f298e5e6..e40bb6c9ccb900a48eed59c94c84072c78bbcb27 100644 (file)
@@ -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); \
index 7c12e092d16819be0ed2ff30274b432f9e80a3c4..b7e5650d3e30e36e38c9741e65f8c6f9a94dfc6a 100644 (file)
@@ -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;
index ea52314fc153c258684553c04b155d896425b632..9eee2c61411d749ac2fc219dbc69a06ead2ab992 100644 (file)
@@ -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;
index f13ccc96e39b77d43c22fb21927dfd29b03a67f4..93692a6216fa4a2907db569ee389494763883eea 100644 (file)
@@ -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) {