From d24160c5e5c92cbe8c6ca31ff1ce7d79058de23d Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 11 Mar 2016 17:20:17 +0000 Subject: [PATCH] [Feature] Add task:get_dns_req method --- src/lua/lua_task.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index b177f168c..e5214a321 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -276,6 +276,12 @@ LUA_FUNCTION_DEF (task, get_resolver); * Increment number of DNS requests for the task. Is used just for logging purposes. */ LUA_FUNCTION_DEF (task, inc_dns_req); +/*** + * @method task:get_dns_req() + * Get number of dns requests being sent in the task + * @return {number} number of DNS requests + */ +LUA_FUNCTION_DEF (task, get_dns_req); /*** * @method task:has_recipients([type]) @@ -570,6 +576,7 @@ static const struct luaL_reg tasklib_m[] = { LUA_INTERFACE_DEF (task, get_queue_id), LUA_INTERFACE_DEF (task, get_resolver), LUA_INTERFACE_DEF (task, inc_dns_req), + LUA_INTERFACE_DEF (task, get_dns_req), LUA_INTERFACE_DEF (task, has_recipients), LUA_INTERFACE_DEF (task, get_recipients), LUA_INTERFACE_DEF (task, has_from), @@ -1391,6 +1398,21 @@ lua_task_inc_dns_req (lua_State *L) return 0; } +static gint +lua_task_get_dns_req (lua_State *L) +{ + struct rspamd_task *task = lua_check_task (L, 1); + + if (task != NULL) { + lua_pushnumber (L, task->dns_requests); + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + /* * Convert element at the specified position to the type * for get_from/get_recipients -- 2.39.5