Skip to content

Commit

Permalink
[Minor] Composites: Another try to deal properly with shadow results
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Dec 14, 2020
1 parent 5ce6a2d commit 7453142
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions src/libserver/composites.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 7453142

Please sign in to comment.