]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Allow to create empty tasks
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 11 Apr 2019 11:54:43 +0000 (12:54 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 11 Apr 2019 11:54:43 +0000 (12:54 +0100)
src/lua/lua_task.c

index ad11f2b416d29e52552a5ffeb82f1b2cdae70824..d809c6ab10f1554dfa9061230784d16ca9934926 100644 (file)
@@ -51,6 +51,13 @@ end
  */
 
 /* Task methods */
+
+/***
+ * @function rspamd_task.create([cfg])
+ * Create a new empty task
+ * @return {rspamd_task} new task
+ */
+LUA_FUNCTION_DEF (task, create);
 /***
  * @function rspamd_task.load_from_file(filename[, cfg])
  * Loads a message from specific file
@@ -1005,6 +1012,7 @@ LUA_FUNCTION_DEF (task, lookup_words);
 LUA_FUNCTION_DEF (task, topointer);
 
 static const struct luaL_reg tasklib_f[] = {
+       LUA_INTERFACE_DEF (task, create),
        LUA_INTERFACE_DEF (task, load_from_file),
        LUA_INTERFACE_DEF (task, load_from_string),
        {NULL, NULL}
@@ -1500,6 +1508,32 @@ lua_task_load_from_string (lua_State * L)
        return 2;
 }
 
+static gint
+lua_task_create (lua_State * L)
+{
+       LUA_TRACE_POINT;
+       struct rspamd_task *task = NULL, **ptask;
+       struct rspamd_config *cfg = NULL;
+
+       if (lua_type (L, 1) == LUA_TUSERDATA) {
+               gpointer p;
+               p = rspamd_lua_check_udata_maybe (L, 2, "rspamd{config}");
+
+               if (p) {
+                       cfg = *(struct rspamd_config **)p;
+               }
+       }
+
+       task = rspamd_task_new (NULL, cfg, NULL, NULL, NULL);
+       task->flags |= RSPAMD_TASK_FLAG_EMPTY;
+
+       ptask = lua_newuserdata (L, sizeof (*ptask));
+       *ptask = task;
+       rspamd_lua_setclass (L, "rspamd{task}", -1);
+
+       return 1;
+}
+
 static int
 lua_task_get_mempool (lua_State * L)
 {