]> source.dussan.org Git - rspamd.git/commitdiff
Improve mime expressions processing.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 23 Mar 2015 16:32:34 +0000 (16:32 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 23 Mar 2015 16:32:34 +0000 (16:32 +0000)
src/plugins/regexp.c

index 53049656a1674a104e47ce348884d3a797b48325..159399dfd08b82d562145608cdd63581ddca066f 100644 (file)
@@ -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) {