aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-11-27 14:25:23 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-11-27 14:25:23 +0000
commit7f5617f2257fbe763a21d451fdc5e679f14836a0 (patch)
treed9e1039a36e4c9ff68805a745bf9998e2858ce02 /src
parenta2db37f731c4002899788b91770e01d225863d9b (diff)
downloadrspamd-7f5617f2257fbe763a21d451fdc5e679f14836a0.tar.gz
rspamd-7f5617f2257fbe763a21d451fdc5e679f14836a0.zip
[Minor] Lua_config: Add get_groups method
Diffstat (limited to 'src')
-rw-r--r--src/lua/lua_config.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 34bba5836..b50949bdd 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -454,6 +454,15 @@ LUA_FUNCTION_DEF (config, get_symbol_parent);
LUA_FUNCTION_DEF (config, get_group_symbols);
/***
+ * @method rspamd_config:get_groups([need_private])
+ * Returns list of all groups defined
+ * @param {boolean} need_private optional flag to include private groups
+ * @available 2.3+
+ * @return {list|table} list of all groups
+ */
+LUA_FUNCTION_DEF (config, get_groups);
+
+/***
* @method rspamd_config:register_settings_id(name, symbols_enabled, symbols_disabled)
* Register new static settings id in config
* @param {string} name id name (not numeric!)
@@ -871,6 +880,7 @@ static const struct luaL_reg configlib_m[] = {
LUA_INTERFACE_DEF (config, get_symbols_counters),
{"get_symbols_scores", lua_config_get_symbols},
LUA_INTERFACE_DEF (config, get_symbols),
+ LUA_INTERFACE_DEF (config, get_groups),
LUA_INTERFACE_DEF (config, get_symbol_callback),
LUA_INTERFACE_DEF (config, set_symbol_callback),
LUA_INTERFACE_DEF (config, get_symbol_stat),
@@ -3658,6 +3668,53 @@ lua_config_get_group_symbols (lua_State *L)
}
static gint
+lua_config_get_groups (lua_State *L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_config *cfg = lua_check_config (L, 1);
+ gboolean need_private;
+ struct rspamd_symbols_group *gr;
+ GHashTableIter it;
+ gpointer k, v;
+
+ if (cfg) {
+ if (lua_isboolean (L, 2)) {
+ need_private = lua_toboolean (L, 2);
+ }
+ else {
+ need_private = !(cfg->public_groups_only);
+ }
+
+ lua_createtable (L, 0, g_hash_table_size (cfg->groups));
+ g_hash_table_iter_init (&it, cfg->groups);
+
+ while (g_hash_table_iter_next (&it, &k, &v)) {
+ gr = (struct rspamd_symbols_group *)v;
+
+ if (need_private || (gr->flags & RSPAMD_SYMBOL_GROUP_PUBLIC)) {
+ lua_createtable (L, 0, 4);
+
+ lua_pushstring (L, gr->description);
+ lua_setfield (L, -2, "description");
+ lua_pushnumber (L, gr->max_score);
+ lua_setfield (L, -2, "max_score");
+ lua_pushboolean (L, (gr->flags & RSPAMD_SYMBOL_GROUP_PUBLIC) != 0);
+ lua_setfield (L, -2, "is_public");
+ /* TODO: maybe push symbols as well */
+
+ /* Parent table indexed by group name */
+ lua_setfield (L, -2, gr->name);
+ }
+ }
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 1;
+}
+
+static gint
lua_config_register_finish_script (lua_State *L)
{
LUA_TRACE_POINT;