From: Vsevolod Stakhov Date: Sat, 16 Aug 2014 17:52:22 +0000 (+0100) Subject: Add method to get any configuration key in lua. X-Git-Tag: 0.7.0~173 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0923c3e30007cf5aa1f09e335c77f74c2fce9223;p=rspamd.git Add method to get any configuration key in lua. --- diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index cd9512991..57c1031c5 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -50,6 +50,7 @@ LUA_FUNCTION_DEF (config, register_pre_filter); LUA_FUNCTION_DEF (config, register_post_filter); LUA_FUNCTION_DEF (config, register_module_option); LUA_FUNCTION_DEF (config, get_api_version); +LUA_FUNCTION_DEF (config, get_key); static const struct luaL_reg configlib_m[] = { LUA_INTERFACE_DEF (config, get_module_opt), @@ -70,6 +71,7 @@ static const struct luaL_reg configlib_m[] = { LUA_INTERFACE_DEF (config, register_pre_filter), LUA_INTERFACE_DEF (config, register_post_filter), LUA_INTERFACE_DEF (config, get_api_version), + LUA_INTERFACE_DEF (config, get_key), {"__tostring", lua_class_tostring}, {NULL, NULL} }; @@ -577,6 +579,31 @@ lua_config_add_kv_map (lua_State *L) } +static gint +lua_config_get_key (lua_State *L) +{ + struct rspamd_config *cfg = lua_check_config (L); + const char *name; + size_t namelen; + const ucl_object_t *val; + + name = luaL_checklstring(L, 2, &namelen); + if (name && cfg) { + val = ucl_object_find_keyl(cfg->rcl_obj, name, namelen); + if (val != NULL) { + ucl_object_push_lua (L, val, val->type != UCL_ARRAY); + } + else { + lua_pushnil (L); + } + } + else { + lua_pushnil (L); + } + + return 1; +} + struct lua_map_callback_data { lua_State *L; gint ref;