From: Vsevolod Stakhov Date: Sat, 29 Jul 2017 14:31:44 +0000 (+0100) Subject: [Feature] Skip certain symbols from ANN classify X-Git-Tag: 1.7.0~790 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=48c027506d6cf9496975f405f64f3c143a4c4290;p=thirdparty%2Frspamd.git [Feature] Skip certain symbols from ANN classify --- diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 7bc8994b49..7e410559ff 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -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 diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c index 46f1b3fc62..1c18c55593 100644 --- a/src/libserver/symbols_cache.c +++ b/src/libserver/symbols_cache.c @@ -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, diff --git a/src/libserver/symbols_cache.h b/src/libserver/symbols_cache.h index f717b39b9e..ade8d95b93 100644 --- a/src/libserver/symbols_cache.h +++ b/src/libserver/symbols_cache.h @@ -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 */ }; /** diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 398c9ed34e..7423bdaeb1 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -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; diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 78d78c9541..6bc6a0e299 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -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; } diff --git a/src/plugins/lua/asn.lua b/src/plugins/lua/asn.lua index e58f1be3b2..0d103fc102 100644 --- a/src/plugins/lua/asn.lua +++ b/src/plugins/lua/asn.lua @@ -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, }) diff --git a/src/plugins/lua/fann_redis.lua b/src/plugins/lua/fann_redis.lua index dbb4955eff..a710ae2647 100644 --- a/src/plugins/lua/fann_redis.lua +++ b/src/plugins/lua/fann_redis.lua @@ -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 }) diff --git a/src/plugins/lua/history_redis.lua b/src/plugins/lua/history_redis.lua index ad65184b92..002c74e553 100644 --- a/src/plugins/lua/history_redis.lua +++ b/src/plugins/lua/history_redis.lua @@ -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 }) diff --git a/src/plugins/lua/mime_types.lua b/src/plugins/lua/mime_types.lua index 469e0c72a6..b90bcad011 100644 --- a/src/plugins/lua/mime_types.lua +++ b/src/plugins/lua/mime_types.lua @@ -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({ diff --git a/src/plugins/lua/ratelimit.lua b/src/plugins/lua/ratelimit.lua index 2c42c28769..c1d98d4aa0 100644 --- a/src/plugins/lua/ratelimit.lua +++ b/src/plugins/lua/ratelimit.lua @@ -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, }) diff --git a/src/plugins/lua/replies.lua b/src/plugins/lua/replies.lua index 2f24f67e9e..39dfa11130 100644 --- a/src/plugins/lua/replies.lua +++ b/src/plugins/lua/replies.lua @@ -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 }) diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua index 3e8b6d2af8..8f75d15c3d 100644 --- a/src/plugins/lua/settings.lua +++ b/src/plugins/lua/settings.lua @@ -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 })