From eb6f4e38d80f53bdc9f0d4baa8210218b975aeaf Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 14 Jun 2019 14:41:58 +0100 Subject: [PATCH] [Minor] Lua_config: Add get_group_symbols method --- src/libserver/rspamd_symcache.c | 1 + src/lua/lua_config.c | 47 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/libserver/rspamd_symcache.c b/src/libserver/rspamd_symcache.c index 767ecc2c9..deb1cfadd 100644 --- a/src/libserver/rspamd_symcache.c +++ b/src/libserver/rspamd_symcache.c @@ -3224,6 +3224,7 @@ rspamd_symcache_process_settings_elt (struct rspamd_symcache *cache, } } } + if (elt->symbols_enabled) { iter = NULL; diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index f2e9abd01..e54ecce42 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -444,6 +444,15 @@ LUA_FUNCTION_DEF (config, disable_symbol); */ LUA_FUNCTION_DEF (config, get_symbol_parent); +/*** + * @method rspamd_config:get_group_symbols(group) + * Returns list of symbols for a specific group + * @param {string} group group's name + * @available 2.0+ + * @return {list|string} list of all symbols in a specific group + */ +LUA_FUNCTION_DEF (config, get_group_symbols); + /*** * @method rspamd_config:__newindex(name, callback) * This metamethod is called if new indicies are added to the `rspamd_config` object. @@ -821,6 +830,7 @@ static const struct luaL_reg configlib_m[] = { LUA_INTERFACE_DEF (config, set_symbol_callback), LUA_INTERFACE_DEF (config, get_symbol_stat), LUA_INTERFACE_DEF (config, get_symbol_parent), + LUA_INTERFACE_DEF (config, get_group_symbols), LUA_INTERFACE_DEF (config, register_finish_script), LUA_INTERFACE_DEF (config, register_monitored), LUA_INTERFACE_DEF (config, add_doc), @@ -3244,6 +3254,43 @@ lua_config_get_symbol_parent (lua_State *L) return 1; } +static gint +lua_config_get_group_symbols (lua_State *L) +{ + LUA_TRACE_POINT; + struct rspamd_config *cfg = lua_check_config (L, 1); + const gchar *gr_name = luaL_checkstring (L, 2); + + if (cfg != NULL && gr_name != NULL) { + struct rspamd_symbols_group *group; + + group = g_hash_table_lookup (cfg->groups, gr_name); + + if (group == NULL) { + lua_pushnil (L); + } + else { + guint i = 1; + gpointer k, v; + GHashTableIter it; + + lua_createtable (L, g_hash_table_size (group->symbols), 0); + g_hash_table_iter_init (&it, group->symbols); + + while (g_hash_table_iter_next (&it, &k, &v)) { + lua_pushstring (L, k); + lua_rawseti (L, -1, i); + i ++; + } + } + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + static gint lua_config_register_finish_script (lua_State *L) { -- 2.39.5