aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-07-25 08:10:33 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-07-25 08:10:33 +0100
commit8928b8b830eb596369e7a6297a299c047970b4dd (patch)
tree328365d4ad6f657127b002ce734fb7cc2d5428a8
parentae66be67da3b3f4d90fc4a6f8499183d715238bf (diff)
downloadrspamd-8928b8b830eb596369e7a6297a299c047970b4dd.tar.gz
rspamd-8928b8b830eb596369e7a6297a299c047970b4dd.zip
[Minor] Allow to get worker object from a task
-rw-r--r--src/lua/lua_task.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 26f3da5ad..68d21cf3f 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -75,6 +75,12 @@ LUA_FUNCTION_DEF (task, get_session);
*/
LUA_FUNCTION_DEF (task, get_ev_base);
/***
+ * @method task:get_worker()
+ * Returns a worker object associated with the task
+ * @return {rspamd_worker} worker object
+ */
+LUA_FUNCTION_DEF (task, get_worker);
+/***
* @method task:insert_result(symbol, weight[, option1, ...])
* Insert specific symbol to the tasks scanning results assigning the initial
* weight to it.
@@ -802,6 +808,7 @@ static const struct luaL_reg tasklib_m[] = {
LUA_INTERFACE_DEF (task, get_mempool),
LUA_INTERFACE_DEF (task, get_session),
LUA_INTERFACE_DEF (task, get_ev_base),
+ LUA_INTERFACE_DEF (task, get_worker),
LUA_INTERFACE_DEF (task, insert_result),
LUA_INTERFACE_DEF (task, set_pre_result),
LUA_INTERFACE_DEF (task, append_message),
@@ -1146,6 +1153,29 @@ lua_task_get_ev_base (lua_State * L)
return 1;
}
+static int
+lua_task_get_worker (lua_State * L)
+{
+ struct rspamd_worker **pworker;
+ struct rspamd_task *task = lua_check_task (L, 1);
+
+ if (task != NULL) {
+ if (task->worker) {
+ pworker = lua_newuserdata (L, sizeof (struct rspamd_worker *));
+ rspamd_lua_setclass (L, "rspamd{worker}", -1);
+ *pworker = task->worker;
+ }
+ else {
+ lua_pushnil (L);
+ }
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+ return 1;
+}
+
+
static gint
lua_task_insert_result (lua_State * L)
{