aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2011-02-18 18:04:01 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2011-02-18 18:04:01 +0300
commit474b4f809c7321c47c0ddc68b563dd69cbf2cef9 (patch)
tree2bcd42f4f19b72ea9c958a16e169a556716453a8 /src
parentf0eafb45ef94088c91ec552d8dbd7c30e37c1bb1 (diff)
downloadrspamd-474b4f809c7321c47c0ddc68b563dd69cbf2cef9.tar.gz
rspamd-474b4f809c7321c47c0ddc68b563dd69cbf2cef9.zip
Remove symbols that are included into a composite when all composites are processed.
Diffstat (limited to 'src')
-rw-r--r--src/filter.c25
-rw-r--r--src/filter.h1
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 {