aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-06-14 17:44:59 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-06-14 17:44:59 +0100
commita5deb4344638b72841ac276d75977d78ce0bac4a (patch)
tree097425711641a7c814580c88fce51c70be5baaea
parent5a35f2e53577a45deb541318c2502de1e1392537 (diff)
downloadrspamd-a5deb4344638b72841ac276d75977d78ce0bac4a.tar.gz
rspamd-a5deb4344638b72841ac276d75977d78ce0bac4a.zip
[Project] Add missing methods to lua_config
-rw-r--r--src/libserver/cfg_file.h6
-rw-r--r--src/lua/lua_config.c48
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
@@ -454,6 +454,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.
* Technically, it is the equivalent of @see rspamd_config:register_symbol where `weight` is 1.0.
@@ -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),
@@ -3320,6 +3331,43 @@ lua_config_register_finish_script (lua_State *L)
}
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)
{
LUA_TRACE_POINT;