diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-26 15:13:08 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-26 15:13:08 +0000 |
commit | f7e2dfac62c5ecee3103f037e9f2be01094a3f70 (patch) | |
tree | 875be016d8ae74c684ac028f58ccddc6e1376320 /src | |
parent | b5f65acbd6a62aa60431e3b8b19aeb6d3b56821a (diff) | |
download | rspamd-f7e2dfac62c5ecee3103f037e9f2be01094a3f70.tar.gz rspamd-f7e2dfac62c5ecee3103f037e9f2be01094a3f70.zip |
Add helper functions.
Diffstat (limited to 'src')
-rw-r--r-- | src/libutil/expression.c | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/libutil/expression.c b/src/libutil/expression.c index b7604615e..a46f46d16 100644 --- a/src/libutil/expression.c +++ b/src/libutil/expression.c @@ -68,6 +68,7 @@ struct rspamd_expression { const struct rspamd_atom_subr *subr; GArray *expressions; GArray *expression_stack; + GNode *ast; }; static GQuark @@ -77,29 +78,42 @@ rspamd_expr_quark (void) } static void -rspamd_expr_stack_push (struct rspamd_expression *expr, +rspamd_expr_stack_elt_push (GArray *stack, gpointer elt) { - g_array_append_val (expr->expression_stack, elt); + g_array_append_val (stack, elt); } static gpointer -rspamd_expr_stack_pop (struct rspamd_expression *expr) +rspamd_expr_stack_elt_pop (GArray *stack) { gpointer e; gint idx; - if (expr->expression_stack->len == 0) { + if (stack->len == 0) { return NULL; } - idx = expr->expression_stack->len - 1; - e = g_array_index (expr->expression_stack, gpointer, idx); - g_array_remove_index_fast (expr->expression_stack, idx); + idx = stack->len - 1; + e = g_array_index (stack, gpointer, idx); + g_array_remove_index_fast (stack, idx); return e; } +static void +rspamd_expr_stack_push (struct rspamd_expression *expr, + gpointer elt) +{ + rspamd_expr_stack_elt_push (expr->expression_stack, elt); +} + +static gpointer +rspamd_expr_stack_pop (struct rspamd_expression *expr) +{ + return rspamd_expr_stack_elt_pop (expr->expression_stack); +} + /* * Return operation priority */ @@ -294,6 +308,7 @@ rspamd_expression_destroy (struct rspamd_expression *expr) g_array_free (expr->expressions, TRUE); g_array_free (expr->expression_stack, TRUE); + g_node_destroy (expr->ast); } } @@ -333,6 +348,7 @@ rspamd_parse_expression (const gchar *line, gsize len, e = g_slice_alloc (sizeof (*e)); e->expressions = g_array_new (FALSE, FALSE, sizeof (struct rspamd_expression_elt)); + e->ast = NULL; e->expression_stack = g_array_sized_new (FALSE, FALSE, sizeof (gpointer), 32); e->subr = subr; |