diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-02-16 18:44:28 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-02-16 18:44:28 +0000 |
commit | cf098592a93ff6b1dccde63398b2288738fddc94 (patch) | |
tree | 2dac20e55ef2829acef1a969d3dc2409c3c9de9f /src/lua | |
parent | 77d6faa3917c58e9f50a2a929f9504989eb8b376 (diff) | |
parent | f239a10d2ecdf959ef0b8e4151af3aa49419eaeb (diff) | |
download | rspamd-cf098592a93ff6b1dccde63398b2288738fddc94.tar.gz rspamd-cf098592a93ff6b1dccde63398b2288738fddc94.zip |
Merge pull request #174 from fatalbanana/master
Fixes & improvements for RBL module
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_config.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 089a4b1bd..4fdf4a236 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -109,6 +109,24 @@ end */ LUA_FUNCTION_DEF (config, add_radix_map); /*** + * @method rspamd_config:radix_from_config(mname, optname) + * Creates new static map of IP/mask addresses from config. + * @param {string} mname name of module + * @param {string} optname option to get + * @return {radix} radix tree object + * @example +local ip_map = rspamd_config:radix_from_config ('mymodule', 'ips') +... +local function foo(task) + local ip = task:get_from_ip() + if ip_map:get_key(ip) then + return true + end + return false +end + */ +LUA_FUNCTION_DEF (config, radix_from_config); +/*** * @method rspamd_config:add_hash_map(mapline[, description]) * Creates new dynamic map string objects. * @param {string} mapline URL for a map @@ -298,6 +316,7 @@ static const struct luaL_reg configlib_m[] = { LUA_INTERFACE_DEF (config, get_all_opt), LUA_INTERFACE_DEF (config, register_function), LUA_INTERFACE_DEF (config, add_radix_map), + LUA_INTERFACE_DEF (config, radix_from_config), LUA_INTERFACE_DEF (config, add_hash_map), LUA_INTERFACE_DEF (config, add_kv_map), LUA_INTERFACE_DEF (config, add_map), @@ -755,6 +774,44 @@ lua_config_add_radix_map (lua_State *L) } static gint +lua_config_radix_from_config (lua_State *L) +{ + struct rspamd_config *cfg = lua_check_config (L); + const gchar *mname, *optname; + const ucl_object_t *obj; + radix_compressed_t **r, ***ud; + + if (!cfg) { + lua_pushnil (L); + return 1; + } + + mname = luaL_checkstring (L, 2); + optname = luaL_checkstring (L, 3); + + if (mname && optname) { + obj = rspamd_config_get_module_opt (cfg, mname, optname); + if (obj) { + r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (radix_compressed_t *)); + *r = radix_create_compressed (); + radix_add_generic_iplist (ucl_obj_tostring (obj), r); + ud = lua_newuserdata (L, sizeof (radix_compressed_t *)); + *ud = r; + rspamd_lua_setclass (L, "rspamd{radix}", -1); + return 1; + } else { + msg_warn ("Couldnt find config option [%s][%s]", mname, optname); + lua_pushnil (L); + return 1; + } + } else { + msg_warn ("Couldnt find config option"); + lua_pushnil (L); + return 1; + } +} + +static gint lua_config_add_hash_map (lua_State *L) { struct rspamd_config *cfg = lua_check_config (L); |