diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-03 16:39:55 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-03 17:13:24 +0000 |
commit | 12baac84a70768643647ca23fa5932894b58b3ae (patch) | |
tree | 0e8b5a1f21f75c8add431e32a362cdc9d000e12f | |
parent | 863b59fc5168d48d4ec0800c7ad218c79f95754a (diff) | |
download | rspamd-12baac84a70768643647ca23fa5932894b58b3ae.tar.gz rspamd-12baac84a70768643647ca23fa5932894b58b3ae.zip |
Add ip:is_local method to lua API
-rw-r--r-- | src/lua/lua_ip.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/lua/lua_ip.c b/src/lua/lua_ip.c index 1f4ae03f6..0326aeb6f 100644 --- a/src/lua/lua_ip.c +++ b/src/lua/lua_ip.c @@ -164,6 +164,12 @@ LUA_FUNCTION_DEF (ip, copy); * @return {number} port number or nil */ LUA_FUNCTION_DEF (ip, get_port); +/*** + * @method ip:is_local() + * Returns true if address is local one + * @return {boolean} `true` if address is local + */ +LUA_FUNCTION_DEF (ip, is_local); static const struct luaL_reg iplib_m[] = { LUA_INTERFACE_DEF (ip, to_string), @@ -176,6 +182,7 @@ static const struct luaL_reg iplib_m[] = { LUA_INTERFACE_DEF (ip, is_valid), LUA_INTERFACE_DEF (ip, apply_mask), LUA_INTERFACE_DEF (ip, copy), + LUA_INTERFACE_DEF (ip, is_local), {"__tostring", lua_ip_to_string}, {"__eq", lua_ip_equal}, {"__gc", lua_ip_destroy}, @@ -489,6 +496,21 @@ lua_ip_copy (lua_State *L) return 1; } +static gint +lua_ip_is_local (lua_State *L) +{ + struct rspamd_lua_ip *ip = lua_check_ip (L, 1); + + if (ip && ip->addr) { + lua_pushboolean (L, rspamd_inet_address_is_local (ip->addr)); + } + else { + lua_pushnil (L); + } + + return 1; +} + void rspamd_lua_ip_push (lua_State *L, rspamd_inet_addr_t *addr) { @@ -543,5 +565,5 @@ luaopen_ip (lua_State * L) luaL_register (L, NULL, iplib_m); rspamd_lua_add_preload (L, "rspamd_ip", lua_load_ip); - lua_pop (L, 1); /* remove metatable from stack */ + lua_pop (L, 1); } |