aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_ip.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-10-30 22:29:28 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-10-30 22:29:28 +0000
commitff8a6010e8798bf1242246705b88176538e626ff (patch)
tree057826d8877e77798ade77326298a323dd6403b7 /src/lua/lua_ip.c
parent08d2fa41695932bfaf199362a0dac27002ffa922 (diff)
downloadrspamd-ff8a6010e8798bf1242246705b88176538e626ff.tar.gz
rspamd-ff8a6010e8798bf1242246705b88176538e626ff.zip
Fix upstreams in ratelimit.
Diffstat (limited to 'src/lua/lua_ip.c')
-rw-r--r--src/lua/lua_ip.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/lua/lua_ip.c b/src/lua/lua_ip.c
index ea4862e93..b541727b2 100644
--- a/src/lua/lua_ip.c
+++ b/src/lua/lua_ip.c
@@ -163,6 +163,13 @@ LUA_FUNCTION_DEF (ip, equal);
*/
LUA_FUNCTION_DEF (ip, copy);
+/**
+ * @method ip:get_port()
+ * Returns associated port for this IP address
+ * @return {number} port number or nil
+ */
+LUA_FUNCTION_DEF (ip, get_port);
+
static const struct luaL_reg iplib_m[] = {
LUA_INTERFACE_DEF (ip, to_string),
LUA_INTERFACE_DEF (ip, to_table),
@@ -170,6 +177,7 @@ static const struct luaL_reg iplib_m[] = {
LUA_INTERFACE_DEF (ip, str_octets),
LUA_INTERFACE_DEF (ip, inversed_str_octets),
LUA_INTERFACE_DEF (ip, get_version),
+ LUA_INTERFACE_DEF (ip, get_port),
LUA_INTERFACE_DEF (ip, is_valid),
LUA_INTERFACE_DEF (ip, apply_mask),
LUA_INTERFACE_DEF (ip, copy),
@@ -350,6 +358,21 @@ lua_ip_to_string (lua_State *L)
}
static gint
+lua_ip_get_port (lua_State *L)
+{
+ struct rspamd_lua_ip *ip = lua_check_ip (L, 1);
+
+ if (ip != NULL && ip->is_valid) {
+ lua_pushnumber (L, rspamd_inet_address_get_port (&ip->addr));
+ }
+ else {
+ lua_pushnil (L);
+ }
+
+ return 1;
+}
+
+static gint
lua_ip_from_string (lua_State *L)
{
struct rspamd_lua_ip *ip;