aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/expression.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-05-17 14:30:03 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-05-17 14:30:03 +0100
commit29a3b94f4dc310b1f8b77ec982b9062f80192424 (patch)
tree6716ed6a3a94a07670db4f8b8d8f3862bb587d4f /src/libutil/expression.c
parentc912d5d7daaf3ba8c4d419b5f32138077dea980a (diff)
downloadrspamd-29a3b94f4dc310b1f8b77ec982b9062f80192424.tar.gz
rspamd-29a3b94f4dc310b1f8b77ec982b9062f80192424.zip
[Minor] Allow to execute expressions with process closures
Diffstat (limited to 'src/libutil/expression.c')
-rw-r--r--src/libutil/expression.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/libutil/expression.c b/src/libutil/expression.c
index bf5bb467c..ecdb2e87a 100644
--- a/src/libutil/expression.c
+++ b/src/libutil/expression.c
@@ -1021,7 +1021,7 @@ rspamd_ast_process_node (struct rspamd_expression *expr, GNode *node,
t1 = rspamd_get_ticks (TRUE);
}
- elt->value = expr->subr->process (process_data, elt->p.atom);
+ elt->value = process_data->process_closure (process_data, elt->p.atom);
if (fabs (elt->value) > 1e-9) {
elt->p.atom->hits ++;
@@ -1101,7 +1101,9 @@ rspamd_ast_cleanup_traverse (GNode *n, gpointer d)
}
gdouble
-rspamd_process_expression_track (struct rspamd_expression *expr, struct rspamd_expr_process_data *process_data)
+rspamd_process_expression_closure (struct rspamd_expression *expr,
+ rspamd_expression_process_cb cb,
+ struct rspamd_expr_process_data *process_data)
{
gdouble ret = 0;
@@ -1110,6 +1112,8 @@ rspamd_process_expression_track (struct rspamd_expression *expr, struct rspamd_e
g_assert (expr->expression_stack->len == 0);
expr->evals ++;
+
+ process_data->process_closure = cb;
ret = rspamd_ast_process_node (expr, expr->ast, process_data);
/* Cleanup */
@@ -1133,9 +1137,19 @@ rspamd_process_expression_track (struct rspamd_expression *expr, struct rspamd_e
}
gdouble
-rspamd_process_expression (struct rspamd_expression *expr, struct rspamd_expr_process_data *process_data)
+rspamd_process_expression_track (struct rspamd_expression *expr,
+ struct rspamd_expr_process_data *process_data)
+{
+ return rspamd_process_expression_closure (expr,
+ expr->subr->process, process_data);
+}
+
+gdouble
+rspamd_process_expression (struct rspamd_expression *expr,
+ struct rspamd_expr_process_data *process_data)
{
- return rspamd_process_expression_track (expr, process_data);
+ return rspamd_process_expression_closure (expr,
+ expr->subr->process, process_data);
}
static gboolean