]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Process composites separately for each shadow result
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 8 Apr 2020 13:09:12 +0000 (14:09 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 8 Apr 2020 13:09:12 +0000 (14:09 +0100)
src/libserver/composites.c
src/libserver/composites.h
src/libserver/task.c

index c35ba24311a0d5e1358fe8c844c5dcd4af5c9a24..04b0a4ef8d351512141e65264cf6b99dca7609b5 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)) == NULL) {
+       if ((ms = rspamd_task_find_symbol_result (cd->task, sym, cd->metric_res)) == NULL) {
                msg_debug_composites ("not found symbol %s in composite %s", sym,
                                cd->composite->sym);
                if ((ncomp =
@@ -225,14 +225,16 @@ 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, NULL);
+                               ms = rspamd_task_find_symbol_result (cd->task, sym,
+                                               cd->metric_res);
                        }
                        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, NULL);
+                                       ms = rspamd_task_find_symbol_result (cd->task, sym,
+                                                       cd->metric_res);
                                }
                        }
                }
@@ -396,7 +398,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, NULL);
+                       ms = rspamd_task_find_symbol_result (cd->task, sym, cd->metric_res);
                }
 
                if (ms) {
@@ -563,7 +565,8 @@ 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) != NULL) {
+                       if (rspamd_task_find_symbol_result (cd->task, key,
+                                       cd->metric_res) != NULL) {
                                /* Already set, no need to check */
                                msg_debug_composites ("composite %s is already in metric "
                                                "in composites bitfield", cd->composite->sym);
@@ -652,7 +655,7 @@ composites_remove_symbols (gpointer key, gpointer value, gpointer data)
                }
        }
 
-       ms = rspamd_task_find_symbol_result (task, rd->sym, NULL);
+       ms = rspamd_task_find_symbol_result (task, rd->sym, cd->metric_res);
 
        if (has_valid_op && ms && !(ms->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) {
 
@@ -697,10 +700,14 @@ composites_metric_callback (struct rspamd_scan_result *metric_res,
 }
 
 void
-rspamd_make_composites (struct rspamd_task *task)
+rspamd_composites_process_task (struct rspamd_task *task)
 {
        if (task->result && !RSPAMD_TASK_IS_SKIPPED (task)) {
-               composites_metric_callback (task->result, task);
+               struct rspamd_scan_result *mres;
+
+               DL_FOREACH (task->result, mres) {
+                       composites_metric_callback (mres, task);
+               }
        }
 }
 
index d9947a7ddad50a7a5c7a53ff0b8682a3cb4c3d98..bb7eb899407516f753a12a6f0fe5572f218a56bf 100644 (file)
@@ -52,7 +52,7 @@ struct rspamd_composite {
  * Process all results and form composite metrics from existent metrics as it is defined in config
  * @param task worker's task that present message from user
  */
-void rspamd_make_composites (struct rspamd_task *task);
+void rspamd_composites_process_task (struct rspamd_task *task);
 
 enum rspamd_composite_policy rspamd_composite_policy_from_str (const gchar *string);
 
index a0d7bb12a969c72c0c75b7555d1756d8ee17eb9f..30ba0f195bbcf8751a83bfe86531f8c6baa47b40 100644 (file)
@@ -748,7 +748,7 @@ rspamd_task_process (struct rspamd_task *task, guint stages)
                break;
 
        case RSPAMD_TASK_STAGE_COMPOSITES:
-               rspamd_make_composites (task);
+               rspamd_composites_process_task (task);
                break;
 
        case RSPAMD_TASK_STAGE_POST_FILTERS:
@@ -807,7 +807,7 @@ rspamd_task_process (struct rspamd_task *task, guint stages)
                break;
        case RSPAMD_TASK_STAGE_COMPOSITES_POST:
                /* Second run of composites processing before idempotent filters */
-               rspamd_make_composites (task);
+               rspamd_composites_process_task (task);
                break;
 
        case RSPAMD_TASK_STAGE_IDEMPOTENT: