aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-12-14 12:32:12 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-12-14 12:32:12 +0000
commit7453142b863aab9cbfebaa43eaeb3d2f497fde24 (patch)
tree1f5718557346971ffbc7b55e23791f49eef78bdc
parent5ce6a2d97ff655651e4bba7737b834d866b94c94 (diff)
downloadrspamd-7453142b863aab9cbfebaa43eaeb3d2f497fde24.tar.gz
rspamd-7453142b863aab9cbfebaa43eaeb3d2f497fde24.zip
[Minor] Composites: Another try to deal properly with shadow results
-rw-r--r--src/libserver/composites.c58
1 files changed, 31 insertions, 27 deletions
diff --git a/src/libserver/composites.c b/src/libserver/composites.c
index 8e8f37ee5..ba3e64547 100644
--- a/src/libserver/composites.c
+++ b/src/libserver/composites.c
@@ -49,6 +49,7 @@ struct composites_data {
struct rspamd_scan_result *metric_res;
GHashTable *symbols_to_remove;
guint8 *checked;
+ struct composites_data *next;
};
struct rspamd_composite_option_match {
@@ -923,40 +924,43 @@ composites_remove_symbols (gpointer key, gpointer value, gpointer data)
}
static void
-composites_metric_callback (struct rspamd_scan_result *metric_res,
- struct rspamd_task *task)
+composites_metric_callback (struct rspamd_task *task)
{
- struct composites_data *cd =
- rspamd_mempool_alloc (task->task_pool, sizeof (struct composites_data));
-
- cd->task = task;
- 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,
- NBYTES (g_hash_table_size (task->cfg->composite_symbols) * 2));
-
- /* Process hash table */
- rspamd_symcache_composites_foreach (task,
- task->cfg->cache,
- composites_foreach_callback,
- cd);
-
- /* Remove symbols that are in composites */
- g_hash_table_foreach (cd->symbols_to_remove, composites_remove_symbols, cd);
- /* Free list */
- g_hash_table_unref (cd->symbols_to_remove);
+ struct composites_data *cd, *first_cd = NULL;
+ struct rspamd_scan_result *mres;
+
+ DL_FOREACH (task->result, mres) {
+ cd = rspamd_mempool_alloc (task->task_pool, sizeof (struct composites_data));
+ cd->task = task;
+ cd->metric_res = mres;
+ cd->symbols_to_remove = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
+ cd->checked =
+ rspamd_mempool_alloc0 (task->task_pool,
+ NBYTES (g_hash_table_size (task->cfg->composite_symbols) * 2));
+
+ /* Process hash table */
+ rspamd_symcache_composites_foreach (task,
+ task->cfg->cache,
+ composites_foreach_callback,
+ cd);
+ LL_PREPEND (first_cd, cd);
+ }
+
+ LL_REVERSE (first_cd);
+
+ LL_FOREACH (first_cd, cd) {
+ /* Remove symbols that are in composites */
+ g_hash_table_foreach (cd->symbols_to_remove, composites_remove_symbols, cd);
+ /* Free list */
+ g_hash_table_unref (cd->symbols_to_remove);
+ }
}
void
rspamd_composites_process_task (struct rspamd_task *task)
{
if (task->result && !RSPAMD_TASK_IS_SKIPPED (task)) {
- struct rspamd_scan_result *mres;
-
- DL_FOREACH (task->result, mres) {
- composites_metric_callback (mres, task);
- }
+ composites_metric_callback (task);
}
}