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 /src/lua | |
parent | d517ff598510688f2b4b0ff4619c95467a742e29 (diff) | |
download | rspamd-c0e7b579a46a74bb6617eb331783f59123afad52.tar.gz rspamd-c0e7b579a46a74bb6617eb331783f59123afad52.zip |
[Feature] Add `one_param` flag for metric symbols
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_config.c | 27 |
1 files changed, 23 insertions, 4 deletions
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 |