]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Add missing methods to lua_config
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 14 Jun 2019 16:44:59 +0000 (17:44 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 14 Jun 2019 16:44:59 +0000 (17:44 +0100)
src/libserver/cfg_file.h
src/lua/lua_config.c

index a3cf93d63db21ffdf6d180d16b379acc2b2aad93..ed5e1325b9073244b24164357cd134d060fa2b3b 100644 (file)
@@ -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
index 802fab1a63fd711edd298b7f64ea524d176a44c7..4eac4a0e4c3699fd6d4eb6799449b061d99a077a 100644 (file)
@@ -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)
 {