]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow to disable composite rules from settings
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 12 Jul 2016 16:36:58 +0000 (17:36 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 12 Jul 2016 16:36:58 +0000 (17:36 +0100)
src/libserver/composites.c
src/libserver/symbols_cache.c
src/libserver/symbols_cache.h

index 8e2df32f7b705b2939cebf32773d72470063ff30..917d1d0c322abf6e7d482fd404b7d661b54f0007 100644 (file)
@@ -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);
+                       }
+               }
        }
 }
 
index f74982ff62692761af39af9c05104150f4d8e530..c38496ecc885c828c01584777a6bea2773c9bfac 100644 (file)
@@ -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;
+}
index 1a4c0c3edd251cf7a8b29fbc3f707f5031036afb..290e754d09ba0bca52ca17333fb5794e3625c673 100644 (file)
@@ -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