]> source.dussan.org Git - rspamd.git/commitdiff
Fix + expressions optimizations.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 19 Mar 2015 13:33:37 +0000 (13:33 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 19 Mar 2015 13:47:55 +0000 (13:47 +0000)
src/libutil/expression.c

index 2b52e29235b5437a5ad18981fd3f4771a845a293..ca3983df5361baeee76c11d7def7d45fc4dbdad7 100644 (file)
@@ -322,7 +322,7 @@ rspamd_parse_expression (const gchar *line, gsize len,
                len = strlen (line);
        }
 
-       num_re = rspamd_regexp_cache_create (NULL, "/^\\d+(\\s+|$)/", NULL, NULL);
+       num_re = rspamd_regexp_cache_create (NULL, "/^\\d+(\\s+|[)]|$)/", NULL, NULL);
 
        p = line;
        c = line;
@@ -670,43 +670,54 @@ rspamd_process_expression (struct rspamd_expression *expr, gpointer data)
                                case OP_LT:
                                        if (cur_value >= lim->p.lim.val) {
                                                ev->value = 0;
-                                               rspamd_expr_stack_push (expr, ev);
                                                done = TRUE;
                                        }
                                        break;
                                case OP_LE:
                                        if (cur_value > lim->p.lim.val) {
                                                ev->value = 0;
-                                               rspamd_expr_stack_push (expr, ev);
                                                done = TRUE;
                                        }
                                        break;
                                case OP_GT:
                                        if (cur_value > lim->p.lim.val) {
                                                ev->value = 1;
-                                               rspamd_expr_stack_push (expr, ev);
                                                done = TRUE;
                                        }
                                        break;
                                case OP_GE:
                                        if (cur_value >= lim->p.lim.val) {
                                                ev->value = 1;
-                                               rspamd_expr_stack_push (expr, ev);
                                                done = TRUE;
                                        }
                                        break;
                                default:
-                                       rspamd_expr_stack_push (expr, ev);
+                                       g_assert (0);
                                        break;
                                }
+
                                /* If we done, then we go forward and skip remaining items */
                                if (done) {
-                                       i = cmp_pos + 1;
+                                       /* Remove extra elements left on the stack */
+                                       for (j = i; j < cmp_pos; j ++) {
+                                               check = &g_array_index (expr->expressions,
+                                                               struct rspamd_expression_elt, j);
+                                               if (check->type == ELT_OP && check->p.op == OP_PLUS) {
+                                                       rspamd_expr_stack_pop (expr);
+                                               }
+                                       }
+
+                                       /* Push the final result */
+                                       rspamd_expr_stack_push (expr, ev);
+                                       i = cmp_pos;
                                        done = FALSE;
                                        lim = NULL;
                                        cur_value = 0;
                                        cmp_op = NULL;
                                }
+                               else {
+                                       rspamd_expr_stack_push (expr, ev);
+                               }
                                break;
                        }
                        case OP_LT: