]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Lua_task: Add enable/disable symbols methods
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 15 Dec 2018 09:29:38 +0000 (09:29 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 15 Dec 2018 09:29:38 +0000 (09:29 +0000)
src/lua/lua_task.c

index 87893ac6bd0456daa3b8677f6a76155cccd7ade0..737f86802d6bfc90a2fe0332b3ad6d619fbe40a6 100644 (file)
@@ -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)
 {