aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_task.c
diff options
context:
space:
mode:
authorMikhail Galanin <mgalanin@mimecast.com>2018-07-31 15:53:51 +0100
committerMikhail Galanin <mgalanin@mimecast.com>2018-07-31 15:53:51 +0100
commitdaa0c73eee23fea675fc733482248722657f6a56 (patch)
treecd1b224cede1b8766f865789261801a03ba875ee /src/lua/lua_task.c
parent8da3d333136e031cd4888dbd850eb60406cee5e7 (diff)
downloadrspamd-daa0c73eee23fea675fc733482248722657f6a56.tar.gz
rspamd-daa0c73eee23fea675fc733482248722657f6a56.zip
[Minor] added test parsing html/phished urls
Diffstat (limited to 'src/lua/lua_task.c')
-rw-r--r--src/lua/lua_task.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index ca10a94e7..e4fcea3a4 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -53,6 +53,12 @@ end
* @return {boolean},{rspamd_task|error} status + new task or error message
*/
LUA_FUNCTION_DEF (task, load_from_file);
+/***
+ * @function rspamd_task.load_from_string(message[, cfg])
+ * Loads a message from specific file
+ * @return {boolean},{rspamd_task|error} status + new task or error message
+ */
+LUA_FUNCTION_DEF (task, load_from_string);
LUA_FUNCTION_DEF (task, get_message);
/***
@@ -908,6 +914,7 @@ LUA_FUNCTION_DEF (task, get_stat_tokens);
static const struct luaL_reg tasklib_f[] = {
LUA_INTERFACE_DEF (task, load_from_file),
+ LUA_INTERFACE_DEF (task, load_from_string),
{NULL, NULL}
};
@@ -1237,7 +1244,7 @@ lua_task_unmap_dtor (gpointer p)
}
}
-static int
+static gint
lua_task_load_from_file (lua_State * L)
{
struct rspamd_task *task = NULL, **ptask;
@@ -1295,6 +1302,56 @@ lua_task_load_from_file (lua_State * L)
return 2;
}
+static gint
+lua_task_load_from_string (lua_State * L)
+{
+ struct rspamd_task *task = NULL, **ptask;
+ const gchar *str_message = luaL_checkstring (L, 1), *err = NULL;
+ gsize message_len = lua_strlen(L, 1);
+ struct rspamd_config *cfg = NULL;
+ gboolean res = FALSE;
+
+ if (str_message) {
+
+ if (lua_type (L, 2) == 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);
+ task->msg.begin = str_message;
+ task->msg.len = message_len;
+ rspamd_mempool_add_destructor (task->task_pool,
+ lua_task_unmap_dtor, task);
+ res = TRUE;
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ lua_pushboolean (L, res);
+
+ if (res) {
+ ptask = lua_newuserdata (L, sizeof (*ptask));
+ *ptask = task;
+ rspamd_lua_setclass (L, "rspamd{task}", -1);
+ }
+ else {
+ if (err) {
+ lua_pushstring (L, err);
+ }
+ else {
+ lua_pushnil (L);
+ }
+ }
+
+ return 2;
+}
+
static int
lua_task_get_mempool (lua_State * L)
{