]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Rework scan result functions to support shadow results
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Apr 2020 20:22:34 +0000 (21:22 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Apr 2020 20:22:34 +0000 (21:22 +0100)
src/libmime/mime_expressions.c
src/libmime/scan_result.c
src/libmime/scan_result.h
src/libserver/composites.c
src/libserver/roll_history.c
src/libstat/stat_process.c
src/lua/lua_task.c

index a0c4998820e7bf791ad09de3fe9311afbe4d0aed..6ff656cdb6c5b12c3f83633eb3af01474e456023 100644 (file)
@@ -2328,7 +2328,7 @@ rspamd_has_symbol_expr (struct rspamd_task *task,
 
        symbol_str = (const gchar *)sym_arg->data;
 
-       if (rspamd_task_find_symbol_result (task, symbol_str)) {
+       if (rspamd_task_find_symbol_result (task, symbol_str, NULL)) {
                return TRUE;
        }
 
index a27c3b0b2de6114a0665a9e7cf2d365459ae4991..1af2905e7a4dbf2d137919a54b6d219a31cceb15 100644 (file)
@@ -847,19 +847,22 @@ rspamd_check_action_metric (struct rspamd_task *task,
        return noaction->action;
 }
 
-struct rspamd_symbol_result*
-rspamd_task_find_symbol_result (struct rspamd_task *task, const char *sym)
+struct rspamd_symbol_result *
+rspamd_task_find_symbol_result (struct rspamd_task *task, const char *sym,
+               struct rspamd_scan_result *result)
 {
        struct rspamd_symbol_result *res = NULL;
        khiter_t k;
 
+       if (result == NULL) {
+               /* Use default result */
+               result = task->result;
+       }
 
-       if (task->result) {
-               k = kh_get (rspamd_symbols_hash, task->result->symbols, sym);
+       k = kh_get (rspamd_symbols_hash, result->symbols, sym);
 
-               if (k != kh_end (task->result->symbols)) {
-                       res = &kh_value (task->result->symbols, k);
-               }
+       if (k != kh_end (result->symbols)) {
+               res = &kh_value (result->symbols, k);
        }
 
        return res;
@@ -867,14 +870,19 @@ rspamd_task_find_symbol_result (struct rspamd_task *task, const char *sym)
 
 void
 rspamd_task_symbol_result_foreach (struct rspamd_task *task,
-                                                                               GHFunc func,
-                                                                               gpointer ud)
+                                                                  struct rspamd_scan_result *result, GHFunc func,
+                                                                  gpointer ud)
 {
        const gchar *kk;
        struct rspamd_symbol_result res;
 
-       if (func && task->result) {
-               kh_foreach (task->result->symbols, kk, res, {
+       if (result == NULL) {
+               /* Use default result */
+               result = task->result;
+       }
+
+       if (func) {
+               kh_foreach (result->symbols, kk, res, {
                        func ((gpointer)kk, (gpointer)&res, ud);
                });
        }
index cdd6fe38b7796cca1a748415392f780ffe343d62..fd3b8f896f37170849dfb673911e108c2927eba6 100644 (file)
@@ -159,8 +159,9 @@ gboolean rspamd_task_add_result_option (struct rspamd_task *task,
  * @param sym
  * @return
  */
-struct rspamd_symbol_result *rspamd_task_find_symbol_result (
-               struct rspamd_task *task, const char *sym);
+struct rspamd_symbol_result *
+rspamd_task_find_symbol_result (struct rspamd_task *task, const char *sym,
+               struct rspamd_scan_result *result);
 
 /**
  * Compatibility function to iterate on symbols hash
@@ -168,8 +169,7 @@ struct rspamd_symbol_result *rspamd_task_find_symbol_result (
  * @param func
  * @param ud
  */
-void rspamd_task_symbol_result_foreach (struct rspamd_task *task,
-                                                                               GHFunc func,
+void rspamd_task_symbol_result_foreach (struct rspamd_task *task, struct rspamd_scan_result *result, GHFunc func,
                                                                                gpointer ud);
 
 /**
index 22fe4581822daa8d744d192d5017bba54a421e07..c35ba24311a0d5e1358fe8c844c5dcd4af5c9a24 100644 (file)
@@ -201,7 +201,7 @@ rspamd_composite_process_single_symbol (struct composites_data *cd,
        struct rspamd_composite *ncomp;
        struct rspamd_task *task = cd->task;
 
-       if ((ms = rspamd_task_find_symbol_result (cd->task, sym)) == NULL) {
+       if ((ms = rspamd_task_find_symbol_result (cd->task, sym, NULL)) == NULL) {
                msg_debug_composites ("not found symbol %s in composite %s", sym,
                                cd->composite->sym);
                if ((ncomp =
@@ -225,14 +225,14 @@ rspamd_composite_process_single_symbol (struct composites_data *cd,
                                cd->composite = saved;
                                clrbit (cd->checked, cd->composite->id * 2);
 
-                               ms = rspamd_task_find_symbol_result (cd->task, sym);
+                               ms = rspamd_task_find_symbol_result (cd->task, sym, NULL);
                        }
                        else {
                                /*
                                 * XXX: in case of cyclic references this would return 0
                                 */
                                if (isset (cd->checked, ncomp->id * 2 + 1)) {
-                                       ms = rspamd_task_find_symbol_result (cd->task, sym);
+                                       ms = rspamd_task_find_symbol_result (cd->task, sym, NULL);
                                }
                        }
                }
@@ -396,7 +396,7 @@ rspamd_composite_expr_process (void *ud,
        if (isset (cd->checked, cd->composite->id * 2)) {
                /* We have already checked this composite, so just return its value */
                if (isset (cd->checked, cd->composite->id * 2 + 1)) {
-                       ms = rspamd_task_find_symbol_result (cd->task, sym);
+                       ms = rspamd_task_find_symbol_result (cd->task, sym, NULL);
                }
 
                if (ms) {
@@ -563,7 +563,7 @@ composites_foreach_callback (gpointer key, gpointer value, void *data)
                        clrbit (cd->checked, comp->id * 2 + 1);
                }
                else {
-                       if (rspamd_task_find_symbol_result (cd->task, key) != NULL) {
+                       if (rspamd_task_find_symbol_result (cd->task, key, NULL) != NULL) {
                                /* Already set, no need to check */
                                msg_debug_composites ("composite %s is already in metric "
                                                "in composites bitfield", cd->composite->sym);
@@ -652,7 +652,7 @@ composites_remove_symbols (gpointer key, gpointer value, gpointer data)
                }
        }
 
-       ms = rspamd_task_find_symbol_result (task, rd->sym);
+       ms = rspamd_task_find_symbol_result (task, rd->sym, NULL);
 
        if (has_valid_op && ms && !(ms->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) {
 
index a0197a32c6cf0fc8e986ab65bb11908fd9f478fd..6add06e62552e475f86b53dc0e48337364f90169 100644 (file)
@@ -165,7 +165,7 @@ rspamd_roll_history_update (struct roll_history *history,
                row->required_score = rspamd_task_get_required_score (task, metric_res);
                cbdata.pos = row->symbols;
                cbdata.remain = sizeof (row->symbols);
-               rspamd_task_symbol_result_foreach (task,
+               rspamd_task_symbol_result_foreach (task, NULL,
                                roll_history_symbols_callback,
                                &cbdata);
                if (cbdata.remain > 0) {
index fc42cd8757873135cce3362640611267fb9a59a2..93287dc68fe1416f7de4e9868df988ec118b693c 100644 (file)
@@ -881,7 +881,7 @@ rspamd_stat_has_classifier_symbols (struct rspamd_task *task,
                id = g_array_index (cl->statfiles_ids, gint, i);
                st = g_ptr_array_index (st_ctx->statfiles, id);
 
-               if (rspamd_task_find_symbol_result (task, st->stcf->symbol)) {
+               if (rspamd_task_find_symbol_result (task, st->stcf->symbol, NULL)) {
                        if (is_spam == !!st->stcf->is_spam) {
                                msg_debug_bayes ("do not autolearn %s as symbol %s is already "
                                                "added", is_spam ? "spam" : "ham", st->stcf->symbol);
index ce15813acc059795f8e1d5ac024c0f761d8bc16d..2d62574439839f501297e0b8f1fcf847a465ec27 100644 (file)
@@ -1986,7 +1986,7 @@ lua_task_adjust_result (lua_State * L)
                metric_res = task->result;
 
                if (metric_res) {
-                       s = rspamd_task_find_symbol_result (task, symbol_name);
+                       s = rspamd_task_find_symbol_result (task, symbol_name, NULL);
                }
                else {
                        return luaL_error (L, "no metric result");
@@ -4383,7 +4383,7 @@ lua_push_symbol_result (lua_State *L,
                metric_res = task->result;
 
                if (metric_res) {
-                       s = rspamd_task_find_symbol_result (task, symbol);
+                       s = rspamd_task_find_symbol_result (task, symbol, NULL);
                }
        }
        else {
@@ -4493,7 +4493,7 @@ lua_task_has_symbol (lua_State *L)
        symbol = luaL_checkstring (L, 2);
 
        if (task && symbol) {
-               found = (rspamd_task_find_symbol_result (task, symbol) != NULL);
+               found = (rspamd_task_find_symbol_result (task, symbol, NULL) != NULL);
                lua_pushboolean (L, found);
        }
        else {
@@ -4724,7 +4724,7 @@ tokens_foreach_cb (struct rspamd_symcache_item *item, gpointer ud)
                return;
        }
 
-       if ((s = rspamd_task_find_symbol_result (cbd->task, sym)) != NULL) {
+       if ((s = rspamd_task_find_symbol_result (cbd->task, sym, NULL)) != NULL) {
                if (s->flags & RSPAMD_SYMBOL_RESULT_IGNORED) {
                        lua_pushnumber (cbd->L, 0.0);
                }
@@ -4801,7 +4801,7 @@ lua_task_process_ann_tokens (lua_State *L)
                         *
                         * That would lead to N_results lookups which is usually MUCH smaller
                         */
-                       sres = rspamd_task_find_symbol_result (task, sym);
+                       sres = rspamd_task_find_symbol_result (task, sym, NULL);
 
                        if (sres && !(sres->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) {