From: Vsevolod Stakhov Date: Tue, 12 Jul 2016 16:36:58 +0000 (+0100) Subject: [Feature] Allow to disable composite rules from settings X-Git-Tag: 1.3.0~101 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2785fadecc3d0a2a849ba17bc0ab14a48bee7e4c;p=rspamd.git [Feature] Allow to disable composite rules from settings --- diff --git a/src/libserver/composites.c b/src/libserver/composites.c index 8e2df32f7..917d1d0c3 100644 --- a/src/libserver/composites.c +++ b/src/libserver/composites.c @@ -258,18 +258,28 @@ composites_foreach_callback (gpointer key, gpointer value, void *data) cd->composite = comp; - rc = rspamd_process_expression (comp->expr, RSPAMD_EXPRESSION_FLAG_NOOPT, cd); + if (!isset (cd->checked, cd->composite->id * 2)) { + if (rspamd_symbols_cache_is_checked (cd->task, cd->task->cfg->cache, + key)) { + setbit (cd->checked, comp->id * 2); + clrbit (cd->checked, comp->id * 2 + 1); + } + else { + rc = rspamd_process_expression (comp->expr, + RSPAMD_EXPRESSION_FLAG_NOOPT, cd); - /* Checked bit */ - setbit (cd->checked, comp->id * 2); + /* Checked bit */ + setbit (cd->checked, comp->id * 2); - /* Result bit */ - if (rc) { - setbit (cd->checked, comp->id * 2 + 1); - rspamd_task_insert_result_single (cd->task, key, 1.0, NULL); - } - else { - clrbit (cd->checked, comp->id * 2 + 1); + /* Result bit */ + if (rc) { + setbit (cd->checked, comp->id * 2 + 1); + rspamd_task_insert_result_single (cd->task, key, 1.0, NULL); + } + else { + clrbit (cd->checked, comp->id * 2 + 1); + } + } } } diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c index f74982ff6..c38496ecc 100644 --- a/src/libserver/symbols_cache.c +++ b/src/libserver/symbols_cache.c @@ -2003,3 +2003,28 @@ rspamd_symbols_cache_set_cbdata (struct symbols_cache *cache, return TRUE; } + +gboolean +rspamd_symbols_cache_is_checked (struct rspamd_task *task, + struct symbols_cache *cache, const gchar *symbol) +{ + gint id; + struct cache_savepoint *checkpoint; + + g_assert (cache != NULL); + g_assert (symbol != NULL); + + id = rspamd_symbols_cache_find_symbol_parent (cache, symbol); + + if (id < 0) { + return FALSE; + } + + checkpoint = task->checkpoint; + + if (checkpoint) { + return isset (checkpoint->processed_bits, id * 2); + } + + return FALSE; +} diff --git a/src/libserver/symbols_cache.h b/src/libserver/symbols_cache.h index 1a4c0c3ed..290e754d0 100644 --- a/src/libserver/symbols_cache.h +++ b/src/libserver/symbols_cache.h @@ -231,4 +231,14 @@ gboolean rspamd_symbols_cache_set_cbdata (struct symbols_cache *cache, gboolean rspamd_symbols_cache_process_settings (struct rspamd_task *task, struct symbols_cache *cache); + +/** + * Checks if a symbol specified has been checked (or disabled) + * @param task + * @param cache + * @param symbol + * @return + */ +gboolean rspamd_symbols_cache_is_checked (struct rspamd_task *task, + struct symbols_cache *cache, const gchar *symbol); #endif