From 522fbb157aa8fbf36fe5fa5afd3700965c3a0cb5 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 15 Dec 2018 09:29:38 +0000 Subject: [PATCH] [Minor] Lua_task: Add enable/disable symbols methods --- src/lua/lua_task.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 87893ac6b..737f86802 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -617,6 +617,20 @@ LUA_FUNCTION_DEF (task, get_symbols_tokens); * @return {boolean} `true` if symbol has been found */ LUA_FUNCTION_DEF (task, has_symbol); +/*** + * @method task:has_symbol(name) + * Fast path to check if a specified symbol is in the task's results + * @param {string} name symbol's name + * @return {boolean} `true` if symbol has been found + */ +LUA_FUNCTION_DEF (task, enable_symbol); +/*** + * @method task:has_symbol(name) + * Fast path to check if a specified symbol is in the task's results + * @param {string} name symbol's name + * @return {boolean} `true` if symbol has been found + */ +LUA_FUNCTION_DEF (task, disable_symbol); /*** * @method task:get_date(type[, gmt]) * Returns timestamp for a connection or for a MIME message. This function can be called with a @@ -1042,6 +1056,8 @@ static const struct luaL_reg tasklib_m[] = { LUA_INTERFACE_DEF (task, get_symbols_numeric), LUA_INTERFACE_DEF (task, get_symbols_tokens), LUA_INTERFACE_DEF (task, has_symbol), + LUA_INTERFACE_DEF (task, enable_symbol), + LUA_INTERFACE_DEF (task, disable_symbol), LUA_INTERFACE_DEF (task, get_date), LUA_INTERFACE_DEF (task, get_message_id), LUA_INTERFACE_DEF (task, get_timeval), @@ -3654,6 +3670,48 @@ lua_task_has_symbol (lua_State *L) return 1; } +static gint +lua_task_enable_symbol (lua_State *L) +{ + LUA_TRACE_POINT; + struct rspamd_task *task = lua_check_task (L, 1); + const gchar *symbol; + gboolean found = FALSE; + + symbol = luaL_checkstring (L, 2); + + if (task && symbol) { + found = rspamd_symcache_enable_symbol (task, task->cfg->cache, symbol); + lua_pushboolean (L, found); + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + +static gint +lua_task_disable_symbol (lua_State *L) +{ + LUA_TRACE_POINT; + struct rspamd_task *task = lua_check_task (L, 1); + const gchar *symbol; + gboolean found = FALSE; + + symbol = luaL_checkstring (L, 2); + + if (task && symbol) { + found = rspamd_symcache_disable_symbol (task, task->cfg->cache, symbol); + lua_pushboolean (L, found); + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + static gint lua_task_get_symbols (lua_State *L) { -- 2.39.5