]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Try to deal with squeezed symbols with a special care
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 16 Mar 2018 17:27:09 +0000 (17:27 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 16 Mar 2018 17:27:09 +0000 (17:27 +0000)
lualib/lua_squeeze_rules.lua
src/libserver/symbols_cache.c
src/libserver/symbols_cache.h
src/lua/lua_config.c

index e310986d609901e717d3009f711b17ae4b29ad4d..f43d7383a84476e2e392b4e16a8a2b906cb673a0 100644 (file)
@@ -230,6 +230,7 @@ exports.squeeze_init = function()
     rspamd_config:register_symbol{
       type = 'virtual',
       name = k,
+      flags = 'squeezed',
       parent = squeeze_function_ids[v.order],
       no_squeeze = true, -- to avoid infinite recursion
     }
index 5db23bd66715b573bfb495a79224e1d626fe5b86..8d63b578ba063f29bbc157bd8e00d23e40953b74 100644 (file)
@@ -626,7 +626,8 @@ rspamd_symbols_cache_load_items (struct symbols_cache *cache, const gchar *name)
                                }
                        }
 
-                       if ((item->type & SYMBOL_TYPE_VIRTUAL) && item->parent != -1) {
+                       if ((item->type & SYMBOL_TYPE_VIRTUAL) &&
+                                       !(item->type & SYMBOL_TYPE_SQUEEZED) && item->parent != -1) {
                                g_assert (item->parent < (gint)cache->items_by_id->len);
                                parent = g_ptr_array_index (cache->items_by_id, item->parent);
 
@@ -1077,7 +1078,8 @@ rspamd_symbols_cache_validate_cb (gpointer k, gpointer v, gpointer ud)
                item->priority ++;
        }
 
-       if ((item->type & SYMBOL_TYPE_VIRTUAL) && item->parent != -1) {
+       if ((item->type & SYMBOL_TYPE_VIRTUAL) &&
+                       !(item->type & SYMBOL_TYPE_SQUEEZED) && item->parent != -1) {
                g_assert (item->parent < (gint)cache->items_by_id->len);
                parent = g_ptr_array_index (cache->items_by_id, item->parent);
 
@@ -1269,6 +1271,7 @@ rspamd_symbols_cache_check_symbol (struct rspamd_task *task,
                setbit (checkpoint->processed_bits, item->id * 2);
 
                if (!item->enabled ||
+                               (item->type & SYMBOL_TYPE_SQUEEZED) ||
                                (RSPAMD_TASK_IS_EMPTY (task) && !(item->type & SYMBOL_TYPE_EMPTY))) {
                        check = FALSE;
                }
@@ -1942,7 +1945,8 @@ rspamd_symbols_cache_counters_cb (gpointer v, gpointer ud)
                ucl_object_insert_key (obj, ucl_object_fromstring (item->symbol),
                                "symbol", 0, false);
 
-               if ((item->type & SYMBOL_TYPE_VIRTUAL) && item->parent != -1) {
+               if ((item->type & SYMBOL_TYPE_VIRTUAL) &&
+                               !(item->type & SYMBOL_TYPE_SQUEEZED) && item->parent != -1) {
                        g_assert (item->parent < (gint)cbd->cache->items_by_id->len);
                        parent = g_ptr_array_index (cbd->cache->items_by_id,
                                        item->parent);
index d959f905eb58b9c185b4c4089560b1ffd3f9362f..4e1c10dc54c8c8a089923adf95becc5e4bd1b5d4 100644 (file)
@@ -42,6 +42,7 @@ enum rspamd_symbol_type {
        SYMBOL_TYPE_POSTFILTER = (1 << 10),
        SYMBOL_TYPE_NOSTAT = (1 << 11), /* Skip as statistical symbol */
        SYMBOL_TYPE_IDEMPOTENT = (1 << 12), /* Symbol cannot change metric */
+       SYMBOL_TYPE_SQUEEZED = (1 << 13), /* Symbol is squeezed inside Lua */
 };
 
 /**
index 0941c0aa3dbf17a225a3f66140e072df2a62a2c8..d6397efe69520612c12397fa6285cee4466bbe78 100644 (file)
@@ -1508,6 +1508,9 @@ lua_parse_symbol_flags (const gchar *str)
                if (strstr (str, "idempotent") != NULL) {
                        ret |= SYMBOL_TYPE_IDEMPOTENT;
                }
+               if (strstr (str, "squeezed") != NULL) {
+                       ret |= SYMBOL_TYPE_SQUEEZED;
+               }
        }
 
        return ret;