From: Vsevolod Stakhov Date: Thu, 11 Apr 2019 11:54:43 +0000 (+0100) Subject: [Minor] Allow to create empty tasks X-Git-Tag: 1.9.2~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9437540726e6e30f4bacd350b833ed8e330cb0a;p=thirdparty%2Frspamd.git [Minor] Allow to create empty tasks --- diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index ad11f2b416..d809c6ab10 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -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) {