aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorAndrew Lewis <nerf@judo.za.org>2016-10-18 08:49:00 +0200
committerAndrew Lewis <nerf@judo.za.org>2016-10-18 09:13:55 +0200
commit271ce3e599b2330c235e5da293576ae02029cfe0 (patch)
tree297724eefcd5a90621fb98c746faf6d9f0f7866b /src/lua
parentbe3414a88cc7dbd8b34f24b4121ccab5fc9aff7c (diff)
downloadrspamd-271ce3e599b2330c235e5da293576ae02029cfe0.tar.gz
rspamd-271ce3e599b2330c235e5da293576ae02029cfe0.zip
[Feature] Support setting task message from Lua
- Issue: #1046
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_task.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 44a6a6d40..679e7b002 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -119,6 +119,16 @@ end
*/
LUA_FUNCTION_DEF (task, set_pre_result);
/***
+ * @method task:append_message(message)
+ * Adds a message to scanning output.
+ * @param {string} message
+@example
+local function cb(task)
+ task:append_message('Example message')
+end
+ */
+LUA_FUNCTION_DEF (task, append_message);
+/***
* @method task:get_urls([need_emails])
* Get all URLs found in a message.
* @param {boolean} need_emails if `true` then reutrn also email urls
@@ -694,6 +704,7 @@ static const struct luaL_reg tasklib_m[] = {
LUA_INTERFACE_DEF (task, get_ev_base),
LUA_INTERFACE_DEF (task, insert_result),
LUA_INTERFACE_DEF (task, set_pre_result),
+ LUA_INTERFACE_DEF (task, append_message),
LUA_INTERFACE_DEF (task, has_urls),
LUA_INTERFACE_DEF (task, get_urls),
LUA_INTERFACE_DEF (task, get_content),
@@ -1108,6 +1119,24 @@ lua_task_set_pre_result (lua_State * L)
return 0;
}
+static gint
+lua_task_append_message (lua_State * L)
+{
+ struct rspamd_task *task = lua_check_task (L, 1);
+ gchar *message;
+
+ if (task != NULL) {
+ message= rspamd_mempool_strdup (task->task_pool,
+ luaL_checkstring (L, 2));
+ task->messages = g_list_prepend (task->messages, message);
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 0;
+}
+
struct lua_tree_cb_data {
lua_State *L;
int i;