]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Project] Rework some more functions to work with shadow results
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 14 Apr 2020 10:35:52 +0000 (11:35 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 14 Apr 2020 10:35:52 +0000 (11:35 +0100)
src/libmime/message.c
src/libmime/scan_result.c
src/libmime/scan_result.h
src/libserver/protocol.c
src/libserver/roll_history.c
src/libserver/task.c
src/lua/lua_task.c

index 49d87909060fa1ede058ba0c13ea1d10a2cd83ef..4847c4046ed5581a6806542bbade98b7e728fbdb 100644 (file)
@@ -847,7 +847,7 @@ rspamd_message_process_text_part_maybe (struct rspamd_task *task,
 
                        rspamd_add_passthrough_result (task, action,
                                        RSPAMD_PASSTHROUGH_CRITICAL,
-                                       score, "Gtube pattern", "GTUBE", 0);
+                                       score, "Gtube pattern", "GTUBE", 0, NULL);
                }
 
                rspamd_task_insert_result (task, GTUBE_SYMBOL, 0, NULL);
index 8599053863a4ec2d96f0aa96f08e6090039601aa..d299aa2eed19cf84619a2e2f6941674db4e1e8ea 100644 (file)
@@ -123,18 +123,15 @@ rspamd_pr_sort (const struct rspamd_passthrough_result *pra,
 }
 
 void
-rspamd_add_passthrough_result (struct rspamd_task *task,
-                                                                       struct rspamd_action *action,
-                                                                       guint priority,
-                                                                       double target_score,
-                                                                       const gchar *message,
-                                                                       const gchar *module,
-                                                                       guint flags)
+rspamd_add_passthrough_result (struct rspamd_task *task, struct rspamd_action *action, guint priority,
+                                                          double target_score, const gchar *message, const gchar *module, guint flags,
+                                                          struct rspamd_scan_result *scan_result)
 {
-       struct rspamd_scan_result *metric_res;
        struct rspamd_passthrough_result *pr;
 
-       metric_res = task->result;
+       if (scan_result == NULL) {
+               scan_result = task->result;
+       }
 
        pr = rspamd_mempool_alloc (task->task_pool, sizeof (*pr));
        pr->action = action;
@@ -144,8 +141,8 @@ rspamd_add_passthrough_result (struct rspamd_task *task,
        pr->target_score = target_score;
        pr->flags = flags;
 
-       DL_APPEND (metric_res->passthrough_result, pr);
-       DL_SORT (metric_res->passthrough_result, rspamd_pr_sort);
+       DL_APPEND (scan_result->passthrough_result, pr);
+       DL_SORT (scan_result->passthrough_result, rspamd_pr_sort);
 
        if (!isnan (target_score)) {
 
@@ -713,9 +710,10 @@ rspamd_task_add_result_option (struct rspamd_task *task,
        return ret;
 }
 
-struct rspamd_action*
+struct rspamd_action *
 rspamd_check_action_metric (struct rspamd_task *task,
-                                                       struct rspamd_passthrough_result **ppr)
+                                                       struct rspamd_passthrough_result **ppr,
+                                                       struct rspamd_scan_result *scan_result)
 {
        struct rspamd_action_result *action_lim,
                        *noaction = NULL;
@@ -723,11 +721,14 @@ rspamd_check_action_metric (struct rspamd_task *task,
        struct rspamd_passthrough_result *pr, *sel_pr = NULL;
        double max_score = -(G_MAXDOUBLE), sc;
        int i;
-       struct rspamd_scan_result *mres = task->result;
        gboolean seen_least = FALSE;
 
-       if (mres->passthrough_result != NULL)  {
-               DL_FOREACH (mres->passthrough_result, pr) {
+       if (scan_result == NULL) {
+               scan_result = task->result;
+       }
+
+       if (scan_result->passthrough_result != NULL)  {
+               DL_FOREACH (scan_result->passthrough_result, pr) {
                        if (!seen_least || !(pr->flags & RSPAMD_PASSTHROUGH_LEAST)) {
                                sc = pr->target_score;
                                selected_action = pr->action;
@@ -735,10 +736,10 @@ rspamd_check_action_metric (struct rspamd_task *task,
                                if (!(pr->flags & RSPAMD_PASSTHROUGH_LEAST)) {
                                        if (!isnan (sc)) {
                                                if (pr->action->action_type == METRIC_ACTION_NOACTION) {
-                                                       mres->score = MIN (sc, mres->score);
+                                                       scan_result->score = MIN (sc, scan_result->score);
                                                }
                                                else {
-                                                       mres->score = sc;
+                                                       scan_result->score = sc;
                                                }
                                        }
 
@@ -782,13 +783,12 @@ rspamd_check_action_metric (struct rspamd_task *task,
                        }
                }
        }
-       /* We are not certain about the results during processing */
 
        /*
         * Select result by score
         */
-       for (i = mres->nactions - 1; i >= 0; i--) {
-               action_lim = &mres->actions_limits[i];
+       for (i = scan_result->nactions - 1; i >= 0; i--) {
+               action_lim = &scan_result->actions_limits[i];
                sc = action_lim->cur_limit;
 
                if (action_lim->action->action_type == METRIC_ACTION_NOACTION) {
@@ -800,7 +800,7 @@ rspamd_check_action_metric (struct rspamd_task *task,
                        continue;
                }
 
-               if (mres->score >= sc && sc > max_score) {
+               if (scan_result->score >= sc && sc > max_score) {
                        selected_action = action_lim->action;
                        max_score = sc;
                }
@@ -813,7 +813,7 @@ rspamd_check_action_metric (struct rspamd_task *task,
        if (selected_action) {
 
                if (seen_least) {
-
+                       /* Adjust least action */
                        if (least_action->flags & RSPAMD_ACTION_NO_THRESHOLD) {
                                if (selected_action->action_type != METRIC_ACTION_REJECT &&
                                                selected_action->action_type != METRIC_ACTION_DISCARD) {
@@ -827,12 +827,12 @@ rspamd_check_action_metric (struct rspamd_task *task,
                        }
                        else {
                                /* Adjust score if needed */
-                               if (max_score > mres->score) {
+                               if (max_score > scan_result->score) {
                                        if (ppr) {
                                                *ppr = sel_pr;
                                        }
 
-                                       mres->score = max_score;
+                                       scan_result->score = max_score;
                                }
                        }
                }
index dcae2609c17910689e76e9b2a613ebe91f7c844a..3dee11dddfe8afbcd8dd143cb28d111efbc4e8d3 100644 (file)
@@ -118,12 +118,10 @@ struct rspamd_scan_result *rspamd_find_metric_result (struct rspamd_task *task,
  * @param module
  */
 void rspamd_add_passthrough_result (struct rspamd_task *task,
-                                                                       struct rspamd_action *action,
-                                                                       guint priority,
-                                                                       double target_score,
-                                                                       const gchar *message,
-                                                                       const gchar *module,
-                                                                       guint flags);
+                                                                       struct rspamd_action *action, guint priority,
+                                                                       double target_score, const gchar *message,
+                                                                       const gchar *module, guint flags,
+                                                                       struct rspamd_scan_result *scan_result);
 
 enum rspamd_symbol_insert_flags {
        RSPAMD_SYMBOL_INSERT_DEFAULT = 0,
@@ -178,7 +176,9 @@ rspamd_task_find_symbol_result (struct rspamd_task *task, const char *sym,
  * @param func
  * @param ud
  */
-void rspamd_task_symbol_result_foreach (struct rspamd_task *task, struct rspamd_scan_result *result, GHFunc func,
+void rspamd_task_symbol_result_foreach (struct rspamd_task *task,
+                                                                               struct rspamd_scan_result *result,
+                                                                               GHFunc func,
                                                                                gpointer ud);
 
 /**
@@ -199,7 +199,8 @@ double rspamd_factor_consolidation_func (struct rspamd_task *task,
  * @return
  */
 struct rspamd_action *rspamd_check_action_metric (struct rspamd_task *task,
-                                                                                                 struct rspamd_passthrough_result **ppr);
+                                                                                                 struct rspamd_passthrough_result **ppr,
+                                                                                                 struct rspamd_scan_result *scan_result);
 
 #ifdef  __cplusplus
 }
index 35d50b909ef300d17b71c9e8092fad4569128643..9d127606409fb20d76c4ec480eb4acd53f372faa 100644 (file)
@@ -1182,7 +1182,7 @@ rspamd_scan_result_ucl (struct rspamd_task *task,
        const gchar *subject;
        struct rspamd_passthrough_result *pr = NULL;
 
-       action = rspamd_check_action_metric (task, &pr);
+       action = rspamd_check_action_metric (task, &pr, NULL);
        is_spam = !(action->flags & RSPAMD_ACTION_HAM);
 
        if (task->cmd == CMD_CHECK) {
@@ -1761,7 +1761,7 @@ end:
 
                if (metric_res != NULL) {
 
-                       action = rspamd_check_action_metric (task, NULL);
+                       action = rspamd_check_action_metric (task, NULL, NULL);
                        /* TODO: handle custom actions in stats */
                        if (action->action_type == METRIC_ACTION_SOFT_REJECT &&
                                        (task->flags & RSPAMD_TASK_FLAG_GREYLISTED)) {
index 6add06e62552e475f86b53dc0e48337364f90169..8f50de693f6d01e15d94843cd23d8d01c97deb6c 100644 (file)
@@ -160,7 +160,7 @@ rspamd_roll_history_update (struct roll_history *history,
        }
        else {
                row->score = metric_res->score;
-               action = rspamd_check_action_metric (task, NULL);
+               action = rspamd_check_action_metric (task, NULL, NULL);
                row->action = action->action_type;
                row->required_score = rspamd_task_get_required_score (task, metric_res);
                cbdata.pos = row->symbols;
index 30ba0f195bbcf8751a83bfe86531f8c6baa47b40..12f20f39378ae717d9e07ed0a814dd46c11629b6 100644 (file)
@@ -1077,7 +1077,7 @@ rspamd_task_log_metric_res (struct rspamd_task *task,
        khiter_t k;
 
        mres = task->result;
-       act = rspamd_check_action_metric (task, NULL);
+       act = rspamd_check_action_metric (task, NULL, NULL);
 
        if (mres != NULL) {
                switch (lf->type) {
@@ -1876,7 +1876,7 @@ rspamd_task_timeout (EV_P_ ev_timer *w, int revents)
                if (task->cfg->soft_reject_on_timeout) {
                        struct rspamd_action *action, *soft_reject;
 
-                       action = rspamd_check_action_metric (task, NULL);
+                       action = rspamd_check_action_metric (task, NULL, NULL);
 
                        if (action->action_type != METRIC_ACTION_REJECT) {
                                soft_reject = rspamd_config_get_action_by_type (task->cfg,
@@ -1887,7 +1887,7 @@ rspamd_task_timeout (EV_P_ ev_timer *w, int revents)
                                                NAN,
                                                "timeout processing message",
                                                "task timeout",
-                                               0);
+                                               0, NULL);
                        }
                }
 
@@ -1905,7 +1905,7 @@ rspamd_task_timeout (EV_P_ ev_timer *w, int revents)
                if (task->cfg->soft_reject_on_timeout) {
                        struct rspamd_action *action, *soft_reject;
 
-                       action = rspamd_check_action_metric (task, NULL);
+                       action = rspamd_check_action_metric (task, NULL, NULL);
 
                        if (action->action_type != METRIC_ACTION_REJECT) {
                                soft_reject = rspamd_config_get_action_by_type (task->cfg,
@@ -1916,7 +1916,7 @@ rspamd_task_timeout (EV_P_ ev_timer *w, int revents)
                                                NAN,
                                                "timeout post-processing message",
                                                "task timeout",
-                                               0);
+                                               0, NULL);
                        }
                }
 
index 6f1eeaf3f33e87f82c369a72c798cf8ceedb8a15..5285e108772f78a3b47aa25363d1b6d7e93303b6 100644 (file)
@@ -2141,7 +2141,7 @@ lua_task_set_pre_result (lua_State * L)
                                score,
                                rspamd_mempool_strdup (task->task_pool, message),
                                rspamd_mempool_strdup (task->task_pool, module),
-                               flags);
+                               flags, NULL);
 
                /* Don't classify or filter message if pre-filter sets results */
 
@@ -5906,7 +5906,7 @@ lua_task_get_metric_result (lua_State *L)
                lua_pushnumber (L, metric_res->score);
                lua_settable (L, -3);
 
-               action = rspamd_check_action_metric (task, NULL);
+               action = rspamd_check_action_metric (task, NULL, NULL);
 
                if (action) {
                        lua_pushstring (L, "action");
@@ -5977,7 +5977,7 @@ lua_task_get_metric_action (lua_State *L)
        struct rspamd_action *action;
 
        if (task) {
-               action = rspamd_check_action_metric (task, NULL);
+               action = rspamd_check_action_metric (task, NULL, NULL);
                lua_pushstring (L, action->name);
        }
        else {