summaryrefslogtreecommitdiffstats
path: root/src/lua/lua_task.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-09-06 19:55:23 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-09-06 19:55:23 +0400
commitd1b63d4cff12936a5ea4380bccadcc77b7c3ed3f (patch)
tree33ea284a3c1f5e4c8366fc7eff545cd05c1448d9 /src/lua/lua_task.c
parentab946cd1efd6b2ffcf1080d2a4f4c66dda811ef3 (diff)
downloadrspamd-d1b63d4cff12936a5ea4380bccadcc77b7c3ed3f.tar.gz
rspamd-d1b63d4cff12936a5ea4380bccadcc77b7c3ed3f.zip
* Add ability to call rspamd fucntions from lua api
* Make logging adaptive based on log speed (buffered vs unbuffered IO) * Fix lua API docs * Now lua modules can be loaded with glob patterns
Diffstat (limited to 'src/lua/lua_task.c')
-rw-r--r--src/lua/lua_task.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index c688c7c00..07edcb044 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -25,6 +25,7 @@
#include "lua_common.h"
#include "../message.h"
+#include "../expressions.h"
#include <evdns.h>
/* Task methods */
@@ -36,6 +37,7 @@ LUA_FUNCTION_DEF(task, get_raw_headers);
LUA_FUNCTION_DEF(task, get_received_headers);
LUA_FUNCTION_DEF(task, resolve_dns_a);
LUA_FUNCTION_DEF(task, resolve_dns_ptr);
+LUA_FUNCTION_DEF(task, call_rspamd_function);
static const struct luaL_reg tasklib_m[] = {
LUA_INTERFACE_DEF(task, get_message),
@@ -46,6 +48,7 @@ static const struct luaL_reg tasklib_m[] = {
LUA_INTERFACE_DEF(task, get_received_headers),
LUA_INTERFACE_DEF(task, resolve_dns_a),
LUA_INTERFACE_DEF(task, resolve_dns_ptr),
+ LUA_INTERFACE_DEF(task, call_rspamd_function),
{"__tostring", lua_class_tostring},
{NULL, NULL}
};
@@ -320,6 +323,43 @@ lua_task_resolve_dns_ptr (lua_State *L)
return 0;
}
+static int
+lua_task_call_rspamd_function (lua_State *L)
+{
+ struct worker_task *task = lua_check_task (L);
+ struct expression_function f;
+ int i, top;
+ gboolean res;
+ char *arg;
+
+ if (task) {
+ f.name = (char *)luaL_checkstring (L, 2);
+ if (f.name) {
+ f.args = NULL;
+ top = lua_gettop (L);
+ /* Get arguments after function name */
+ for (i = 3; i <= top; i ++) {
+ arg = (char *)luaL_checkstring (L, i);
+ if (arg != NULL) {
+ f.args = g_list_prepend (f.args, arg);
+ }
+ }
+ res = call_expression_function (&f, task);
+ lua_pushboolean (L, res);
+ if (f.args) {
+ g_list_free (f.args);
+ }
+
+ return 1;
+ }
+ }
+
+ lua_pushnil (L);
+
+ return 1;
+
+}
+
/**** Textpart implementation *****/