]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Skip certain symbols from ANN classify
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 29 Jul 2017 14:31:44 +0000 (15:31 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 29 Jul 2017 14:31:44 +0000 (15:31 +0100)
12 files changed:
src/libserver/cfg_utils.c
src/libserver/symbols_cache.c
src/libserver/symbols_cache.h
src/lua/lua_config.c
src/lua/lua_task.c
src/plugins/lua/asn.lua
src/plugins/lua/fann_redis.lua
src/plugins/lua/history_redis.lua
src/plugins/lua/mime_types.lua
src/plugins/lua/ratelimit.lua
src/plugins/lua/replies.lua
src/plugins/lua/settings.lua

index 7bc8994b495dc2ec3affdfb3b1645155741d649b..7e410559ff0e283bf749471f8f82bd839da24802 100644 (file)
@@ -1118,7 +1118,7 @@ symbols_classifiers_callback (gpointer key, gpointer value, gpointer ud)
 
        /* Actually, statistics should act like any ordinary symbol */
        rspamd_symbols_cache_add_symbol (cfg->cache, key, 0, NULL, NULL,
-                       SYMBOL_TYPE_CLASSIFIER, -1);
+                       SYMBOL_TYPE_CLASSIFIER|SYMBOL_TYPE_NOSTAT, -1);
 }
 
 void
index 46f1b3fc62624e2ac6a3fb48bc1fe0e4b6852e86..1c18c5559325109eb43e836d6032984287d94aa4 100644 (file)
@@ -730,6 +730,11 @@ rspamd_symbols_cache_add_symbol (struct symbols_cache *cache,
                }
        }
 
+       if (type & (SYMBOL_TYPE_CLASSIFIER|SYMBOL_TYPE_CALLBACK|
+                       SYMBOL_TYPE_PREFILTER|SYMBOL_TYPE_POSTFILTER)) {
+               type |= SYMBOL_TYPE_NOSTAT;
+       }
+
        item = rspamd_mempool_alloc0 (cache->static_pool,
                        sizeof (struct cache_item));
        item->st = rspamd_mempool_alloc0_shared (cache->static_pool,
index f717b39b9ed8be2a5f1425d084482f394159ba5a..ade8d95b933367770f6c36d0f523ca9907cc35ce 100644 (file)
@@ -40,7 +40,7 @@ enum rspamd_symbol_type {
        SYMBOL_TYPE_EMPTY = (1 << 8), /* Allow execution on empty tasks */
        SYMBOL_TYPE_PREFILTER = (1 << 9),
        SYMBOL_TYPE_POSTFILTER = (1 << 10),
-       SYMBOL_TYPE_NONSTAT = (1 << 11), /* Skip as statistical symbol */
+       SYMBOL_TYPE_NOSTAT = (1 << 11), /* Skip as statistical symbol */
 };
 
 /**
index 398c9ed34ec3d6419f7fc7e66aa3b41105178e72..7423bdaeb16f1a60e06a2dc06d4598ca56ace768 100644 (file)
@@ -191,6 +191,7 @@ LUA_FUNCTION_DEF (config, get_classifier);
  *     + `nice` if symbol can produce negative score;
  *     + `empty` if symbol can be called for empty messages
  *     + `skip` if symbol should be skipped now
+ *     + `nostat` if symbol should be excluded from stat tokens
  * - `parent`: id of parent symbol (useful for virtual symbols)
  *
  * @return {number} id of symbol registered
@@ -1421,6 +1422,9 @@ lua_parse_symbol_flags (const gchar *str)
                if (strstr (str, "skip") != NULL) {
                        ret |= SYMBOL_TYPE_SKIPPED;
                }
+               if (strstr (str, "nostat") != NULL) {
+                       ret |= SYMBOL_TYPE_NOSTAT;
+               }
        }
 
        return ret;
index 78d78c9541dcdedcc26b652acf363399cc4044f9..6bc6a0e29972d5a45567f948cd22db0298da909d 100644 (file)
@@ -3108,7 +3108,7 @@ tokens_foreach_cb (gint id, const gchar *sym, gint flags, gpointer ud)
        struct tokens_foreach_cbdata *cbd = ud;
        struct rspamd_symbol_result *s;
 
-       if (flags & SYMBOL_TYPE_NONSTAT) {
+       if (flags & SYMBOL_TYPE_NOSTAT) {
                return;
        }
 
index e58f1be3b2156bc91983d146eac59c48f9a1caec..0d103fc1022a88133efd694115ce6fc6f548dacb 100644 (file)
@@ -103,7 +103,7 @@ end
 if configure_asn_module() then
   local id = rspamd_config:register_symbol({
     name = 'ASN_CHECK',
-    type = 'prefilter',
+    type = 'prefilter,nostat',
     callback = asn_check,
     priority = 5,
   })
index dbb4955effda6b36f4b251fc3b8602adcb72afdd..a710ae26470dc303775cb8c817d6f337e46f4ddc 100644 (file)
@@ -879,7 +879,7 @@ else
   })
   local id = rspamd_config:register_symbol({
     name = fann_symbol_spam,
-    type = 'postfilter',
+    type = 'postfilter,nostat',
     priority = 6,
     callback = fann_scores_filter
   })
@@ -891,7 +891,7 @@ else
   })
   rspamd_config:register_symbol({
     name = fann_symbol_ham,
-    type = 'virtual',
+    type = 'virtual,nostat',
     parent = id
   })
   if opts['train'] then
@@ -909,7 +909,7 @@ else
     end
     rspamd_config:register_symbol({
       name = 'FANN_VECTOR_PUSH',
-      type = 'postfilter',
+      type = 'postfilter,nostat',
       priority = 5,
       callback = ann_push_vector
     })
index ad65184b927626043d3bfb8ce0a2a4d5e1f290e7..002c74e553d24ffe6a62f66ed8f8faf5d6c719e0 100644 (file)
@@ -219,7 +219,7 @@ if opts then
   else
     rspamd_config:register_symbol({
       name = 'HISTORY_SAVE',
-      type = 'postfilter',
+      type = 'postfilter,nostat',
       callback = history_save,
       priority = 150
     })
index 469e0c72a6ec70af26e432f8df4240e568b6d7a9..b90bcad011aa734d6c6bf0d49a8e4c13493cd880 100644 (file)
@@ -248,7 +248,7 @@ if opts then
   if map then
     local id = rspamd_config:register_symbol({
       callback = check_mime_type,
-      type = 'callback'
+      type = 'callback,nostat'
     })
 
     rspamd_config:register_symbol({
index 2c42c28769973a4c15cc94f8acdedcac86625098..c1d98d4aa0b8352369dcccbd9fe42a15608e4231 100644 (file)
@@ -682,7 +682,7 @@ if opts then
       rspamd_config:register_symbol({
         name = 'RATELIMIT_CHECK',
         callback = rate_test,
-        type = 'prefilter',
+        type = 'prefilter,nostat',
         priority = 4,
       })
     else
@@ -695,6 +695,7 @@ if opts then
       local id = rspamd_config:register_symbol({
         name = symbol,
         callback = rate_test,
+        type = 'normal,nostat'
       })
       if use_ip_score then
         rspamd_config:register_dependency(id, 'IP_SCORE')
@@ -702,7 +703,7 @@ if opts then
     end
     rspamd_config:register_symbol({
       name = 'RATELIMIT_SET',
-      type = 'postfilter',
+      type = 'postfilter,nostat',
       priority = 5,
       callback = rate_set,
     })
index 2f24f67e9e99614d68fdf30ab9b44d0e56035257..39dfa11130bebc28cc8d0ee8359a16bf40d1e17b 100644 (file)
@@ -128,13 +128,13 @@ if opts then
   else
     rspamd_config:register_symbol({
       name = 'REPLIES_SET',
-      type = 'postfilter',
+      type = 'postfilter,nostat',
       callback = replies_set,
       priority = 5
     })
     local id = rspamd_config:register_symbol({
       name = 'REPLIES_CHECK',
-      type = 'prefilter',
+      type = 'prefilter,nostat',
       callback = replies_check,
       priority = 10
     })
index 3e8b6d2af8fdcc64ef6326e8c1a74605cfc6067d..8f75d15c3d7253e95057b4e35d0b109db2a3979f 100644 (file)
@@ -644,7 +644,7 @@ if redis_section then
   fun.each(function(id, h)
     rspamd_config:register_symbol({
       name = 'REDIS_SETTINGS' .. tostring(id),
-      type = 'prefilter',
+      type = 'prefilter,nostat',
       callback = gen_redis_callback(h, id),
       priority = 10
     })
@@ -664,7 +664,7 @@ end
 
 rspamd_config:register_symbol({
   name = 'SETTINGS_CHECK',
-  type = 'prefilter',
+  type = 'prefilter,nostat',
   callback = check_settings,
   priority = 10
 })