]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Lua_config: Add get_group_symbols method
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 14 Jun 2019 13:41:58 +0000 (14:41 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 14 Jun 2019 13:41:58 +0000 (14:41 +0100)
src/libserver/rspamd_symcache.c
src/lua/lua_config.c

index 767ecc2c9a4aa0fc32801ac380fb79fa0a9557c4..deb1cfaddcb7dd6f4a86336512decddd6c2f33b2 100644 (file)
@@ -3224,6 +3224,7 @@ rspamd_symcache_process_settings_elt (struct rspamd_symcache *cache,
                        }
                }
        }
+
        if (elt->symbols_enabled) {
                iter = NULL;
 
index f2e9abd01211290f5fcfaebec880d085f6333aa2..e54ecce424840d2305ded2e44aac0dbcde639074 100644 (file)
@@ -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)
 {