]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Add preliminary lua task process routine.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 17 Apr 2015 16:06:39 +0000 (17:06 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 17 Apr 2015 16:06:39 +0000 (17:06 +0100)
src/lua/lua_util.c

index 3a91634dbb8c17d61903f939735a91decc694076..dda51cbd9c33b7962ec51f75e9ff753e7f9396b3 100644 (file)
@@ -126,10 +126,60 @@ lua_util_config_from_ucl (lua_State *L)
        return 1;
 }
 
+static gboolean
+lua_util_task_fin (struct rspamd_task *task, void *ud)
+{
+       ucl_object_t **target = ud;
+
+       *target = rspamd_protocol_write_ucl (task, NULL);
+
+       return TRUE;
+}
+
 static gint
 lua_util_process_message (lua_State *L)
 {
-       return 0;
+       struct rspamd_config *cfg = lua_check_config (L, 1);
+       const gchar *message;
+       gsize mlen;
+       struct rspamd_task *task;
+       struct event_base *base;
+       ucl_object_t *res = NULL;
+
+       message = luaL_checklstring (L, 2, &mlen);
+
+       if (cfg != NULL && message != NULL) {
+               base = event_init ();
+               task = rspamd_task_new (NULL);
+               task->cfg = cfg;
+               task->ev_base = base;
+               task->msg.start = rspamd_mempool_alloc (task->task_pool, mlen + 1);
+               rspamd_strlcpy ((gpointer)task->msg.start, message, mlen + 1);
+               task->msg.len = mlen;
+               task->fin_callback = lua_util_task_fin;
+               task->fin_arg = &res;
+
+               if (rspamd_task_process (task, NULL, message, mlen, NULL, TRUE)) {
+                       event_base_loop (base, 0);
+
+                       if (res != NULL) {
+                               ucl_object_push_lua (L, res, true);
+
+                               ucl_object_unref (res);
+                       }
+               }
+               else {
+                       lua_pushnil (L);
+               }
+
+               rspamd_task_free_hard (task);
+               event_base_free (base);
+       }
+       else {
+               lua_pushnil (L);
+       }
+
+       return 1;
 }
 
 static gint