diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-10-27 10:32:45 +0200 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-10-27 10:32:45 +0200 |
commit | c0e7b579a46a74bb6617eb331783f59123afad52 (patch) | |
tree | 1ff98ef23bc9a01ba6ceb989ef9baf3dd8d1fd4f | |
parent | d517ff598510688f2b4b0ff4619c95467a742e29 (diff) | |
download | rspamd-c0e7b579a46a74bb6617eb331783f59123afad52.tar.gz rspamd-c0e7b579a46a74bb6617eb331783f59123afad52.zip |
[Feature] Add `one_param` flag for metric symbols
-rw-r--r-- | src/libmime/filter.c | 3 | ||||
-rw-r--r-- | src/libserver/cfg_file.h | 1 | ||||
-rw-r--r-- | src/libserver/cfg_rcl.c | 6 | ||||
-rw-r--r-- | src/lua/lua_config.c | 27 | ||||
-rw-r--r-- | src/plugins/regexp.c | 8 |
5 files changed, 40 insertions, 5 deletions
diff --git a/src/libmime/filter.c b/src/libmime/filter.c index 5b998406f..a1dae9f5c 100644 --- a/src/libmime/filter.c +++ b/src/libmime/filter.c @@ -142,7 +142,8 @@ insert_metric_result (struct rspamd_task *task, */ single = TRUE; } - if (s->options && opts && opts != s->options) { + if (s->options && opts && opts != s->options && + !(sdef->flags & RSPAMD_SYMBOL_FLAG_ONEPARAM)) { /* Append new options */ s->options = g_list_concat (s->options, g_list_copy (opts)); /* diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index d10ce235d..1ca6118a5 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -96,6 +96,7 @@ struct rspamd_symbols_group { #define RSPAMD_SYMBOL_FLAG_ONESHOT (1 << 0) #define RSPAMD_SYMBOL_FLAG_IGNORE (1 << 1) +#define RSPAMD_SYMBOL_FLAG_ONEPARAM (1 << 2) /** * Symbol definition diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index 5cfd73ee3..a260ca99a 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -349,6 +349,12 @@ rspamd_rcl_symbol_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, } } + if ((elt = ucl_object_lookup (obj, "one_param")) != NULL) { + if (ucl_object_toboolean (elt)) { + flags |= RSPAMD_SYMBOL_FLAG_ONEPARAM; + } + } + if ((elt = ucl_object_lookup (obj, "ignore")) != NULL) { if (ucl_object_toboolean (elt)) { flags |= RSPAMD_SYMBOL_FLAG_IGNORE; diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 915666a7d..b9a727efa 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -242,9 +242,11 @@ LUA_FUNCTION_DEF (config, register_dependency); * - `description`: description of symbol (string, optional) * - `group`: name of group for symbol (string, optional) * - `one_shot`: turn off multiple hits for a symbol (boolean, optional) + * - `one_param`: turn off multiple options for a symbol (boolean, optional) * - `flags`: comma separated string of flags: * + `ignore`: do not strictly check validity of symbol and corresponding rule * + `one_shot`: turn off multiple hits for a symbol + * + `one_param`: allow only one parameter for a symbol * - `priority`: priority of symbol's definition */ LUA_FUNCTION_DEF (config, set_metric_symbol); @@ -1376,7 +1378,7 @@ lua_config_set_metric_symbol (lua_State * L) *group = NULL, *name = NULL, *flags_str = NULL; double weight; struct metric *metric; - gboolean one_shot = FALSE; + gboolean one_shot = FALSE, one_param = FALSE; GError *err = NULL; gdouble priority = 0.0; guint flags = 0; @@ -1386,9 +1388,10 @@ lua_config_set_metric_symbol (lua_State * L) if (lua_type (L, 2) == LUA_TTABLE) { if (!rspamd_lua_parse_table_arguments (L, 2, &err, "*name=S;score=N;description=S;" - "group=S;one_shot=B;metric=S;priority=N;flags=S", + "group=S;one_shot=B;one_param=B;metric=S;priority=N;flags=S", &name, &weight, &description, - &group, &one_shot, &metric_name, &priority, &flags_str)) { + &group, &one_shot, &one_param, + &metric_name, &priority, &flags_str)) { msg_err_config ("bad arguments: %e", err); g_error_free (err); @@ -1421,14 +1424,20 @@ lua_config_set_metric_symbol (lua_State * L) if (one_shot) { flags |= RSPAMD_SYMBOL_FLAG_ONESHOT; } + if (one_param) { + flags |= RSPAMD_SYMBOL_FLAG_ONEPARAM; + } if (flags_str) { if (strstr (flags_str, "one_shot") != NULL) { flags |= RSPAMD_SYMBOL_FLAG_ONESHOT; } - else if (strstr (flags_str, "ignore") != NULL) { + if (strstr (flags_str, "ignore") != NULL) { flags |= RSPAMD_SYMBOL_FLAG_IGNORE; } + if (strstr (flags_str, "one_param") != NULL) { + flags |= RSPAMD_SYMBOL_FLAG_ONEPARAM; + } } if (metric == NULL) { @@ -1787,6 +1796,16 @@ lua_config_newindex (lua_State *L) } lua_pop (L, 1); + lua_pushstring (L, "one_param"); + lua_gettable (L, -2); + + if (lua_type (L, -1) == LUA_TBOOLEAN) { + if (lua_toboolean (L, -1)) { + flags |= RSPAMD_SYMBOL_FLAG_ONEPARAM; + } + } + lua_pop (L, 1); + /* * Do not override the existing symbols (using zero priority), * since we are defining default values here diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index deb5adab5..a88bde21b 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -285,6 +285,14 @@ regexp_module_config (struct rspamd_config *cfg) } } + elt = ucl_object_lookup (value, "one_param"); + + if (elt) { + if (ucl_object_toboolean (elt)) { + flags |= RSPAMD_SYMBOL_FLAG_ONEPARAM; + } + } + elt = ucl_object_lookup (value, "priority"); if (elt) { |