From 5d12d7827f3f526b85ac6da2757242de0f644fc8 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 22 Dec 2017 18:21:49 +0000 Subject: [PATCH] [Minor] Allow to print IP and port from Lua... --- src/lua/lua_ip.c | 12 +++++++++--- 1 file 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; -- 2.39.5