]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Allow to check if we have set some pre-result
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 11 Jul 2018 20:21:41 +0000 (21:21 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 11 Jul 2018 20:29:38 +0000 (21:29 +0100)
src/lua/lua_task.c

index db5bd090a9a0e5d834fd693097c8225f986898a9..2ce489e9cfcbd95976b257e2ac2521621ad7ac9f 100644 (file)
@@ -24,6 +24,7 @@
 #include "libserver/task.h"
 #include "libstat/stat_api.h"
 #include <math.h>
+#include <src/libserver/task.h>
 
 /***
  * @module rspamd_task
@@ -144,6 +145,14 @@ local function cb(task)
 end
  */
 LUA_FUNCTION_DEF (task, set_pre_result);
+
+/***
+ * @method task:has_pre_result()
+ * Returns true if task has some pre-result being set
+ *
+ * @return {boolean} true if task has some pre-result being set
+ */
+LUA_FUNCTION_DEF (task, has_pre_result);
 /***
  * @method task:append_message(message)
  * Adds a message to scanning output.
@@ -902,6 +911,7 @@ static const struct luaL_reg tasklib_m[] = {
        LUA_INTERFACE_DEF (task, insert_result),
        LUA_INTERFACE_DEF (task, adjust_result),
        LUA_INTERFACE_DEF (task, set_pre_result),
+       LUA_INTERFACE_DEF (task, has_pre_result),
        LUA_INTERFACE_DEF (task, append_message),
        LUA_INTERFACE_DEF (task, has_urls),
        LUA_INTERFACE_DEF (task, get_urls),
@@ -1524,6 +1534,21 @@ lua_task_set_pre_result (lua_State * L)
        return 0;
 }
 
+static gint
+lua_task_has_pre_result (lua_State * L)
+{
+       struct rspamd_task *task = lua_check_task (L, 1);
+
+       if (task) {
+               lua_pushboolean (L, task->pre_result.action != METRIC_ACTION_MAX);
+       }
+       else {
+               return luaL_error (L, "invalid arguments");
+       }
+
+       return 1;
+}
+
 static gint
 lua_task_append_message (lua_State * L)
 {