diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-10-10 13:18:19 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-10-10 13:18:19 +0100 |
commit | fa554083457bd6b2328f85e4b8c5d0453e49879e (patch) | |
tree | ec2424518e4841b90427f798d23cadb50496b6f9 /src/lua | |
parent | 842d2c4164dad1d8539eb2ecf114f9220b23970d (diff) | |
download | rspamd-fa554083457bd6b2328f85e4b8c5d0453e49879e.tar.gz rspamd-fa554083457bd6b2328f85e4b8c5d0453e49879e.zip |
Fix call of expression functions.
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_common.c | 40 | ||||
-rw-r--r-- | src/lua/lua_common.h | 2 |
2 files changed, 5 insertions, 37 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 960b73f91..8017cd086 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -604,7 +604,7 @@ lua_call_chain_filter (const gchar *function, struct worker_task *task, gint *ma /* Call custom lua function in rspamd expression */ gboolean -lua_call_expression_func (const gchar *module, const gchar *function, +lua_call_expression_func (gpointer lua_data, struct worker_task *task, GList *args, gboolean *res) { lua_State *L = task->cfg->lua_state; @@ -613,39 +613,7 @@ lua_call_expression_func (const gchar *module, const gchar *function, struct expression_argument *arg; int nargs = 1, pop = 0; - /* Call specified function and expect result of given expected_type */ - /* First check function in config table */ - lua_getglobal (L, "config"); - if (module != NULL && lua_istable (L, -1)) { - lua_pushstring (L, module); - lua_gettable (L, -2); - if (lua_isnil (L, -1)) { - /* Try to get global variable */ - lua_pop (L, 1); - lua_getglobal (L, function); - } - else if (lua_istable (L, -1)) { - /* Call local function in table */ - lua_pushstring (L, function); - lua_gettable (L, -2); - pop += 2; - } - else { - msg_err ("Bad type: %s for function: %s for module: %s", lua_typename (L, lua_type (L, -1)), function, module); - } - } - else { - /* Try to get global variable */ - lua_pop (L, 1); - lua_getglobal (L, function); - } - if (lua_isnil (L, -1)) { - if (pop > 0) { - lua_pop (L, pop); - } - msg_err ("function with name %s is not defined", function); - return FALSE; - } + lua_rawgeti (L, LUA_REGISTRYINDEX, GPOINTER_TO_INT (lua_data)); /* Now we got function in top of stack */ ptask = lua_newuserdata (L, sizeof (struct worker_task *)); lua_setclass (L, "rspamd{task}", -1); @@ -673,14 +641,14 @@ lua_call_expression_func (const gchar *module, const gchar *function, } if (lua_pcall (L, nargs, 1, 0) != 0) { - msg_info ("call to %s failed: %s", function, lua_tostring (L, -1)); + msg_info ("call to lua function failed: %s", lua_tostring (L, -1)); return FALSE; } pop ++; if (!lua_isboolean (L, -1)) { lua_pop (L, pop); - msg_info ("function %s must return a boolean", function); + msg_info ("lua function must return a boolean"); return FALSE; } *res = lua_toboolean (L, -1); diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index 526c20f6f..c6ba06160 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -147,7 +147,7 @@ gint luaopen_rsa (lua_State * L); gint lua_call_filter (const gchar *function, struct worker_task *task); gint lua_call_chain_filter (const gchar *function, struct worker_task *task, gint *marks, guint number); double lua_consolidation_func (struct worker_task *task, const gchar *metric_name, const gchar *function_name); -gboolean lua_call_expression_func (const gchar *module, const gchar *symbol, struct worker_task *task, GList *args, gboolean *res); +gboolean lua_call_expression_func (gpointer lua_data, struct worker_task *task, GList *args, gboolean *res); void lua_call_post_filters (struct worker_task *task); void lua_call_pre_filters (struct worker_task *task); void add_luabuf (const gchar *line); |