commit a5deb43: [Project] Add missing methods to lua_config

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Jun 14 19:00:17 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-06-14 17:44:59 +0100
URL: https://github.com/rspamd/rspamd/commit/a5deb4344638b72841ac276d75977d78ce0bac4a

[Project] Add missing methods to lua_config

---
 src/libserver/cfg_file.h |  6 +++---
 src/lua/lua_config.c     | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 3 deletions(-)

diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index a3cf93d63..ed5e1325b 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -730,8 +730,8 @@ gboolean rspamd_config_radix_from_ucl (struct rspamd_config *cfg,
  * Adds new settings id to be preprocessed
  * @param cfg
  * @param name
- * @param symbols_enabled
- * @param symbols_disabled
+ * @param symbols_enabled (ownership is transferred to callee)
+ * @param symbols_disabled (ownership is transferred to callee)
  */
 void rspamd_config_register_settings_id (struct rspamd_config *cfg,
 										 const gchar *name,
@@ -739,7 +739,7 @@ void rspamd_config_register_settings_id (struct rspamd_config *cfg,
 										 ucl_object_t *symbols_disabled);
 
 /**
- * Finds settings id element and obtain reference count (must be unrefed by callee)
+ * Finds settings id element and obtain reference count (must be unrefed by caller)
  * @param cfg
  * @param id
  * @return
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 802fab1a6..4eac4a0e4 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -453,6 +453,16 @@ LUA_FUNCTION_DEF (config, get_symbol_parent);
  */
 LUA_FUNCTION_DEF (config, get_group_symbols);
 
+/***
+ * @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!)
+ * @param {map|string->string} symbols_enabled map from symbol's name to boolean (currently)
+ * @param {map|string->string} symbols_disabled map from symbol's name to boolean (currently)
+ * @available 2.0+
+ */
+LUA_FUNCTION_DEF (config, register_settings_id);
+
 /***
  * @method rspamd_config:__newindex(name, callback)
  * This metamethod is called if new indicies are added to the `rspamd_config` object.
@@ -796,6 +806,7 @@ static const struct luaL_reg configlib_m[] = {
 	LUA_INTERFACE_DEF (config, register_callback_symbol),
 	LUA_INTERFACE_DEF (config, register_callback_symbol_priority),
 	LUA_INTERFACE_DEF (config, register_dependency),
+	LUA_INTERFACE_DEF (config, register_settings_id),
 	LUA_INTERFACE_DEF (config, get_symbol_flags),
 	LUA_INTERFACE_DEF (config, add_symbol_flags),
 	LUA_INTERFACE_DEF (config, set_metric_symbol),
@@ -3319,6 +3330,43 @@ lua_config_register_finish_script (lua_State *L)
 	return 0;
 }
 
+static gint
+lua_config_register_settings_id (lua_State *L)
+{
+	LUA_TRACE_POINT;
+	struct rspamd_config *cfg = lua_check_config (L, 1);
+	const gchar *settings_name = luaL_checkstring (L, 2);
+
+	if (cfg != NULL && settings_name) {
+		ucl_object_t *sym_enabled, *sym_disabled;
+
+		sym_enabled = ucl_object_lua_import (L, 3);
+
+		if (sym_enabled == NULL || ucl_object_type (sym_enabled) != UCL_ARRAY) {
+			ucl_object_unref (sym_enabled);
+
+			return luaL_error (L, "invalid symbols enabled");
+		}
+
+		sym_disabled = ucl_object_lua_import (L, 3);
+
+		if (sym_disabled == NULL || ucl_object_type (sym_disabled) != UCL_ARRAY) {
+			ucl_object_unref (sym_enabled);
+			ucl_object_unref (sym_disabled);
+
+			return luaL_error (L, "invalid symbols enabled");
+		}
+
+		rspamd_config_register_settings_id (cfg, settings_name, sym_enabled,
+				sym_disabled);
+	}
+	else {
+		return luaL_error (L, "invalid arguments");
+	}
+
+	return 0;
+}
+
 static gint
 lua_config_register_monitored (lua_State *L)
 {


More information about the Commits mailing list