diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-12-22 18:21:49 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-12-22 18:21:49 +0000 |
commit | 5d12d7827f3f526b85ac6da2757242de0f644fc8 (patch) | |
tree | 8aeb38b6935798895ee48e4303728783088fe93a /src/lua/lua_ip.c | |
parent | f454cbd033200bc0a3933c934444d0b588a634c8 (diff) | |
download | rspamd-5d12d7827f3f526b85ac6da2757242de0f644fc8.tar.gz rspamd-5d12d7827f3f526b85ac6da2757242de0f644fc8.zip |
[Minor] Allow to print IP and port from Lua...
Diffstat (limited to 'src/lua/lua_ip.c')
-rw-r--r-- | src/lua/lua_ip.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/lua/lua_ip.c b/src/lua/lua_ip.c index 31b74ab12..b0f17e5c3 100644 --- a/src/lua/lua_ip.c +++ b/src/lua/lua_ip.c @@ -51,8 +51,9 @@ print_octets(ip6) */ /*** - * @method ip:to_string() + * @method ip:to_string([pretty=false]) * Converts valid IP address to string + * @param {bool} pretty print IP address with port and braces (for IPv6) * @return {string or nil} string representation of IP or `nil` if IP is invalid */ LUA_FUNCTION_DEF (ip, to_string); @@ -325,10 +326,15 @@ lua_ip_to_string (lua_State *L) struct rspamd_lua_ip *ip = lua_check_ip (L, 1); if (ip != NULL && ip->addr) { - lua_pushstring (L, rspamd_inet_address_to_string (ip->addr)); + if (lua_isboolean (L, 2) && lua_toboolean (L, 2) == true) { + lua_pushstring (L, rspamd_inet_address_to_string_pretty (ip->addr)); + } + else { + lua_pushstring (L, rspamd_inet_address_to_string (ip->addr)); + } } else { - lua_pushnil (L); + luaL_error (L, "invalid arguments"); } return 1; |