From 012b099a308711da7982c8dfe39dd89c55e1de14 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 23 Mar 2015 16:32:34 +0000 Subject: [PATCH] Improve mime expressions processing. --- src/plugins/regexp.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 53049656a..159399dfd 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -138,11 +138,13 @@ regexp_module_config (struct rspamd_config *cfg) ucl_obj_tostring (value), cfg->raw_mode)) { res = FALSE; } - register_symbol (&cfg->cache, - cur_item->symbol, - 1, - process_regexp_item, - cur_item); + else { + register_symbol (&cfg->cache, + cur_item->symbol, + 1, + process_regexp_item, + cur_item); + } } else if (value->type == UCL_USERDATA) { cur_item = rspamd_mempool_alloc0 (regexp_module_ctx->regexp_pool, @@ -176,7 +178,7 @@ regexp_module_reconfig (struct rspamd_config *cfg) static gboolean rspamd_lua_call_expression_func( struct ucl_lua_funcdata *lua_data, struct rspamd_task *task, - GArray *args, gboolean *res) + GArray *args, gint *res) { lua_State *L = lua_data->L; struct rspamd_task **ptask; @@ -213,12 +215,16 @@ static gboolean rspamd_lua_call_expression_func( } pop++; - if (!lua_isboolean (L, -1)) { - lua_pop (L, pop); + if (lua_type (L, -1) == LUA_TNUMBER) { + *res = lua_tonumber (L, -1); + } + else if (lua_type (L, -1) == LUA_TBOOLEAN) { + *res = lua_toboolean (L, -1); + } + else { msg_info("lua function must return a boolean"); - return FALSE; } - *res = lua_toboolean (L, -1); + lua_pop (L, pop); return TRUE; @@ -229,7 +235,7 @@ static void process_regexp_item (struct rspamd_task *task, void *user_data) { struct regexp_module_item *item = user_data; - gboolean res = FALSE; + gint res = FALSE; /* Non-threaded version */ if (item->lua_function) { @@ -242,7 +248,13 @@ process_regexp_item (struct rspamd_task *task, void *user_data) } else { /* Process expression */ - res = rspamd_process_expression (item->expr, task); + if (item->expr) { + res = rspamd_process_expression (item->expr, task); + } + else { + msg_warn ("FIXME: %s symbol is broken with new expressions", + item->symbol); + } } if (res) { -- 2.39.5