]> source.dussan.org Git - rspamd.git/commitdiff
Distinguish between logic and arithmetic ops.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 17 Mar 2015 17:28:11 +0000 (17:28 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 17 Mar 2015 17:28:11 +0000 (17:28 +0000)
src/libutil/expression.c
src/lua/lua_expression.c

index 0016893551b3966f830ad277527eeb51af552619..23398510e557fda1ab1593ec3fa0cc89c25b2b97 100644 (file)
@@ -31,6 +31,8 @@ enum rspamd_expression_op {
        OP_INVALID = 0,
        OP_PLUS, /* || or + */
        OP_MULT, /* && or * */
+       OP_OR, /* || or | */
+       OP_AND, /* && or & */
        OP_NOT, /* ! */
        OP_LT, /* < */
        OP_GT, /* > */
@@ -106,9 +108,11 @@ rspamd_expr_logic_priority (enum rspamd_expression_op op)
                ret = 5;
                break;
        case OP_MULT:
+       case OP_AND:
                ret = 4;
                break;
        case OP_PLUS:
+       case OP_OR:
                ret = 3;
                break;
        case OP_GE:
@@ -181,10 +185,14 @@ rspamd_expr_str_to_op (const gchar *a, const gchar *end, const gchar **next)
                        op = OP_NOT;
                        break;
                case '&':
+                       op = OP_AND;
+                       break;
                case '*':
                        op = OP_MULT;
                        break;
                case '|':
+                       op = OP_OR;
+                       break;
                case '+':
                        op = OP_PLUS;
                        break;
@@ -205,7 +213,7 @@ rspamd_expr_str_to_op (const gchar *a, const gchar *end, const gchar **next)
                if ((gulong)(end - a) >= sizeof ("or") &&
                                g_ascii_strncasecmp (a, "or", sizeof ("or") - 1) == 0) {
                        *next = a + sizeof ("or") - 1;
-                       op = OP_PLUS;
+                       op = OP_OR;
                }
                break;
        case 'A':
@@ -213,7 +221,7 @@ rspamd_expr_str_to_op (const gchar *a, const gchar *end, const gchar **next)
                if ((gulong)(end - a) >= sizeof ("and") &&
                                g_ascii_strncasecmp (a, "and", sizeof ("and") - 1) == 0) {
                        *next = a + sizeof ("and") - 1;
-                       op = OP_MULT;
+                       op = OP_AND;
                }
                break;
        case 'N':
@@ -542,6 +550,12 @@ rspamd_expression_tostring (struct rspamd_expression *expr)
                }
                else {
                        switch (elt->p.op) {
+                       case OP_AND:
+                               op_str = "&";
+                               break;
+                       case OP_OR:
+                               op_str = "|";
+                               break;
                        case OP_MULT:
                                op_str = "*";
                                break;
index 7c166cc681f0f31a58de99c82d3a67524bed1f6c..55b0c1556e9b99666865532033feb71fd1669d7e 100644 (file)
@@ -37,14 +37,14 @@ require "fun" ()
 local rspamd_expression = require "rspamd_expression"
 local rspamd_mempool = require "rspamd_mempool"
 
-local parse_func(str)
+local function parse_func(str)
        -- extract token till the first space character
-       local token = table.join('', take_while(function(s) return s <> ' ' end, str)
+       local token = table.join('', take_while(function(s) return s ~= ' ' end, str))
        -- Return token name
        return token
 end
 
-local process_func(token, task)
+local function process_func(token, task)
        -- Do something using token and task
 end