diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-02-08 00:10:04 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-02-08 00:22:38 +0000 |
commit | 9cb4f26bd048aaa3a292d7a1ac8161288cbf7bf9 (patch) | |
tree | 89b8858d169a293321c18cb27e4ea796c5592042 /src/lua/lua_task.c | |
parent | ee6d9a408653d6932dfa425dfe7b516d43df782d (diff) | |
download | rspamd-9cb4f26bd048aaa3a292d7a1ac8161288cbf7bf9.tar.gz rspamd-9cb4f26bd048aaa3a292d7a1ac8161288cbf7bf9.zip |
Add fast path for checking symbols
Diffstat (limited to 'src/lua/lua_task.c')
-rw-r--r-- | src/lua/lua_task.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 6e644b0da..3f2b0723d 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -373,6 +373,13 @@ LUA_FUNCTION_DEF (task, get_images); */ LUA_FUNCTION_DEF (task, get_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, has_symbol); +/*** * @method task:get_date(type[, gmt]) * Returns timestamp for a connection or for a MIME message. This function can be called with a * single table arguments with the following fields: @@ -570,6 +577,7 @@ static const struct luaL_reg tasklib_m[] = { LUA_INTERFACE_DEF (task, set_hostname), LUA_INTERFACE_DEF (task, get_images), LUA_INTERFACE_DEF (task, get_symbol), + LUA_INTERFACE_DEF (task, has_symbol), LUA_INTERFACE_DEF (task, get_date), LUA_INTERFACE_DEF (task, get_message_id), LUA_INTERFACE_DEF (task, get_timeval), @@ -1785,6 +1793,29 @@ lua_task_get_symbol (lua_State *L) return 1; } +static gint +lua_task_has_symbol (lua_State *L) +{ + struct rspamd_task *task = lua_check_task (L, 1); + const gchar *symbol; + struct metric_result *mres; + gboolean found = FALSE; + + symbol = luaL_checkstring (L, 2); + + if (task && symbol) { + mres = g_hash_table_lookup (task->results, DEFAULT_METRIC); + + if (mres) { + found = g_hash_table_lookup (mres->symbols, symbol) != NULL; + } + } + + lua_pushboolean (L, found); + + return 1; +} + enum lua_date_type { DATE_CONNECT = 0, DATE_MESSAGE, |