From 34c51207375ae61c322ca26d6ca98dc93b8bebd5 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 1 Feb 2016 11:35:27 +0000 Subject: Fix set_from_ip method --- src/lua/lua_task.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 2b0e1cfbb..c636125f3 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -332,6 +332,11 @@ LUA_FUNCTION_DEF (task, set_user); * @return {rspamd_ip} ip address object */ LUA_FUNCTION_DEF (task, get_from_ip); +/*** + * @method task:set_from_ip(str) + * Set tasks's IP address based on the passed string + * @param {string} str string representation of ip + */ LUA_FUNCTION_DEF (task, set_from_ip); LUA_FUNCTION_DEF (task, get_from_ip_num); /*** @@ -1528,8 +1533,30 @@ lua_task_get_from_ip (lua_State *L) static gint lua_task_set_from_ip (lua_State *L) { + struct rspamd_task *task = lua_check_task (L, 1); + const gchar *ip_str = luaL_checkstring (L, 2); + rspamd_inet_addr_t *addr = NULL; + + if (!task || !ip_str) { + lua_pushstring (L, "invalid parameters"); + lua_error (L); + } + else { + if (!rspamd_parse_inet_address (&addr, + ip_str, + 0)) { + msg_warn_task ("cannot get IP from received header: '%s'", + ip_str); + } + else { + if (task->from_addr) { + rspamd_inet_address_destroy (task->from_addr); + } + + task->from_addr = addr; + } + } - msg_err ("this function is deprecated and should no longer be used"); return 0; } -- cgit v1.2.3