diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-05-15 14:21:41 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-05-15 14:21:41 +0100 |
commit | f57c6e2c50e05aebbc9020fc9fe58b647b15b9dd (patch) | |
tree | 53f4d90ce06efaabf776586bdd8e038744b33a5f /src/lua/lua_config.c | |
parent | 1d2cb297a1cd882e6b0ea75ca5c081f844742c18 (diff) | |
download | rspamd-f57c6e2c50e05aebbc9020fc9fe58b647b15b9dd.tar.gz rspamd-f57c6e2c50e05aebbc9020fc9fe58b647b15b9dd.zip |
[Feature] Allow multiple groups for symbols
Diffstat (limited to 'src/lua/lua_config.c')
-rw-r--r-- | src/lua/lua_config.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index a42f33b37..6e502d6e7 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -1641,6 +1641,23 @@ lua_config_register_symbol (lua_State * L) rspamd_config_add_symbol (cfg, name, score, description, group, flags, (guint) priority, nshots); + + lua_pushstring (L, "groups"); + lua_gettable (L, 2); + + if (lua_istable (L, -1)) { + for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) { + if (lua_isstring (L, -1)) { + rspamd_config_add_symbol_group (cfg, name, + lua_tostring (L, -1)); + } + else { + return luaL_error (L, "invalid groups element"); + } + } + } + + lua_pop (L, 1); } } else { @@ -1997,6 +2014,25 @@ lua_config_set_metric_symbol (lua_State * L) rspamd_config_add_symbol (cfg, name, weight, description, group, flags, (guint) priority, nshots); + + + if (lua_type (L, 2) == LUA_TTABLE) { + lua_pushstring (L, "groups"); + lua_gettable (L, 2); + + if (lua_istable (L, -1)) { + for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) { + if (lua_isstring (L, -1)) { + rspamd_config_add_symbol_group (cfg, name, + lua_tostring (L, -1)); + } else { + return luaL_error (L, "invalid groups element"); + } + } + } + + lua_pop (L, 1); + } } else { return luaL_error (L, "invalid arguments, rspamd_config expected"); @@ -2011,6 +2047,8 @@ lua_config_get_metric_symbol (lua_State * L) struct rspamd_config *cfg = lua_check_config (L, 1); const gchar *sym_name = luaL_checkstring (L, 2); struct rspamd_symbol *sym_def; + struct rspamd_symbols_group *sym_group; + guint i; if (cfg && sym_name) { sym_def = g_hash_table_lookup (cfg->symbols, sym_name); @@ -2035,6 +2073,16 @@ lua_config_get_metric_symbol (lua_State * L) lua_pushstring (L, sym_def->gr->name); lua_settable (L, -3); } + + lua_pushstring (L, "groups"); + lua_createtable (L, sym_def->groups->len, 0); + + PTR_ARRAY_FOREACH (sym_def->groups, i, sym_group) { + lua_pushstring (L, sym_group->name); + lua_rawseti (L, -2, i + 1); + } + + lua_settable (L, -3); } } else { @@ -2376,6 +2424,23 @@ lua_config_newindex (lua_State *L) */ rspamd_config_add_symbol (cfg, name, score, description, group, flags, 0, nshots); + + lua_pushstring (L, "groups"); + lua_gettable (L, -2); + + if (lua_istable (L, -1)) { + for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) { + if (lua_isstring (L, -1)) { + rspamd_config_add_symbol_group (cfg, name, + lua_tostring (L, -1)); + } + else { + return luaL_error (L, "invalid groups element"); + } + } + } + + lua_pop (L, 1); } else { lua_pop (L, 1); |