From 474b4f809c7321c47c0ddc68b563dd69cbf2cef9 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 18 Feb 2011 18:04:01 +0300 Subject: [PATCH] Remove symbols that are included into a composite when all composites are processed. --- src/filter.c | 25 +++++++++++++++++++++++-- src/filter.h | 1 + 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/filter.c b/src/filter.c index e0c4e89b8..5a9bbaf49 100644 --- a/src/filter.c +++ b/src/filter.c @@ -107,6 +107,7 @@ insert_metric_result (struct worker_task *task, struct metric *metric, const gch s = memory_pool_alloc (task->task_pool, sizeof (struct symbol)); s->score = w; s->options = opts; + s->name = symbol; metric_res->score += w; if (opts) { @@ -328,6 +329,7 @@ process_filters (struct worker_task *task) struct composites_data { struct worker_task *task; struct metric_result *metric_res; + GList *symbols_to_remove; }; static void @@ -392,8 +394,10 @@ composites_foreach_callback (gpointer key, gpointer value, void *data) r = rspamd_snprintf (logbuf, sizeof (logbuf), "<%s>, insert symbol %s instead of symbols: ", cd->task->message_id, key); while (s) { ms = g_hash_table_lookup (cd->metric_res->symbols, s->data); - g_hash_table_remove (cd->metric_res->symbols, s->data); - cd->metric_res->score -= ms->score; + if (ms != NULL && g_list_find (cd->symbols_to_remove, ms) == NULL) { + cd->symbols_to_remove = g_list_prepend (cd->symbols_to_remove, ms); + } + if (s->next) { r += rspamd_snprintf (logbuf + r, sizeof (logbuf) -r, "%s, ", s->data); } @@ -489,11 +493,28 @@ composites_metric_callback (gpointer key, gpointer value, void *data) struct worker_task *task = (struct worker_task *)data; struct composites_data *cd = memory_pool_alloc (task->task_pool, sizeof (struct composites_data)); struct metric_result *metric_res = (struct metric_result *)value; + struct symbol *ms; + GList *cur; cd->task = task; cd->metric_res = (struct metric_result *)metric_res; + cd->symbols_to_remove = NULL; + /* Process hash table */ g_hash_table_foreach (task->cfg->composite_symbols, composites_foreach_callback, cd); + + /* Remove symbols that are in composites */ + cur = cd->symbols_to_remove; + while (cur) { + ms = cur->data; + g_hash_table_remove (cd->metric_res->symbols, ms->name); + cd->metric_res->score -= ms->score; + cur = g_list_next (cur); + } + /* Free list */ + if (cd->symbols_to_remove) { + g_list_free (cd->symbols_to_remove); + } } void diff --git a/src/filter.h b/src/filter.h index 924e1eac9..cea49893b 100644 --- a/src/filter.h +++ b/src/filter.h @@ -31,6 +31,7 @@ struct filter { struct symbol { double score; /**< symbol's score */ GList *options; /**< list of symbol's options */ + const gchar *name; }; enum rspamd_metric_action { -- 2.39.5