aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/composites.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-08-05 23:08:18 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-08-05 23:08:18 +0100
commit9632c62a868e9086c5a016eb6b259ffe6f233770 (patch)
tree6bc77bac35d7a78c7573ae010a0c47b4045f5662 /src/libserver/composites.c
parent76a11f2feb1be9d7f8940ab6a77be04a222ee81d (diff)
downloadrspamd-9632c62a868e9086c5a016eb6b259ffe6f233770.tar.gz
rspamd-9632c62a868e9086c5a016eb6b259ffe6f233770.zip
[Feature] Allow to use postfilters in composites
We actually process composites twice now so it somehow slows down processing by extra hash lookup. Additional logic to regenerate metric reply if something is changed by this extra run of composites is also added. Issue: #1726
Diffstat (limited to 'src/libserver/composites.c')
-rw-r--r--src/libserver/composites.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/libserver/composites.c b/src/libserver/composites.c
index 89281b117..7aee6a230 100644
--- a/src/libserver/composites.c
+++ b/src/libserver/composites.c
@@ -279,6 +279,14 @@ composites_foreach_callback (gpointer key, gpointer value, void *data)
clrbit (cd->checked, comp->id * 2 + 1);
}
else {
+ if (g_hash_table_lookup (cd->metric_res->symbols, key) != NULL) {
+ /* Already set, no need to check */
+ setbit (cd->checked, comp->id * 2);
+ clrbit (cd->checked, comp->id * 2 + 1);
+
+ return;
+ }
+
rc = rspamd_process_expression (comp->expr,
RSPAMD_EXPRESSION_FLAG_NOOPT, cd);
@@ -358,10 +366,13 @@ composites_remove_symbols (gpointer key, gpointer value, gpointer data)
if (want_remove_symbol || want_forced) {
g_hash_table_remove (cd->metric_res->symbols, key);
}
+
if (want_remove_score || want_forced) {
cd->metric_res->score -= rd->ms->score;
rd->ms->score = 0.0;
}
+
+ cd->metric_res->changes ++;
}
}
@@ -373,7 +384,7 @@ composites_metric_callback (struct rspamd_metric_result *metric_res,
rspamd_mempool_alloc (task->task_pool, sizeof (struct composites_data));
cd->task = task;
- cd->metric_res = (struct rspamd_metric_result *)metric_res;
+ cd->metric_res = metric_res;
cd->symbols_to_remove = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
cd->checked =
rspamd_mempool_alloc0 (task->task_pool,