diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-10-26 17:24:52 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-10-26 17:24:52 +0000 |
commit | e74409e4f5f504d4647af72098ddfa1aa2228e53 (patch) | |
tree | 8ca9c8108b0863053b8da4f5a138311adfaa93e2 /src/libutil/expression.c | |
parent | b294e38a47f4a4526954be71cf3f267a450097b3 (diff) | |
download | rspamd-e74409e4f5f504d4647af72098ddfa1aa2228e53.tar.gz rspamd-e74409e4f5f504d4647af72098ddfa1aa2228e53.zip |
Add function to traverse AST atoms
Diffstat (limited to 'src/libutil/expression.c')
-rw-r--r-- | src/libutil/expression.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/libutil/expression.c b/src/libutil/expression.c index 6e58fa40d..2f05c98a3 100644 --- a/src/libutil/expression.c +++ b/src/libutil/expression.c @@ -1091,3 +1091,39 @@ rspamd_expression_tostring (struct rspamd_expression *expr) return res; } + +struct atom_foreach_cbdata { + rspamd_expression_atom_foreach_cb cb; + gpointer cbdata; +}; + +static gboolean +rspamd_ast_atom_traverse (GNode *n, gpointer d) +{ + struct atom_foreach_cbdata *data = d; + struct rspamd_expression_elt *elt = n->data; + rspamd_ftok_t tok; + + if (elt->type == ELT_ATOM) { + tok.begin = elt->p.atom->str; + tok.len = elt->p.atom->len; + + data->cb (&tok, data->cbdata); + } + + return FALSE; +} + +void +rspamd_expression_atom_foreach (struct rspamd_expression *expr, + rspamd_expression_atom_foreach_cb cb, gpointer cbdata) +{ + struct atom_foreach_cbdata data; + + g_assert (expr != NULL); + + data.cb = cb; + data.cbdata = cbdata; + g_node_traverse (expr->ast, G_POST_ORDER, G_TRAVERSE_ALL, -1, + rspamd_ast_atom_traverse, &data); +} |