aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-28 14:20:39 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-28 14:20:39 +0100
commit54781dd54db908d90b7d1e4acee46c89cbd6aeb0 (patch)
tree2a8e1527dc45be61fafa5dce9348e7b4c744b3c2 /src/libutil
parent007242e0c37731ea0b4015bfb66dd9a71ba81bbb (diff)
downloadrspamd-54781dd54db908d90b7d1e4acee46c89cbd6aeb0.tar.gz
rspamd-54781dd54db908d90b7d1e4acee46c89cbd6aeb0.zip
[Feature] Add tracking for rspamd expressions
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/expression.c21
-rw-r--r--src/libutil/expression.h11
2 files changed, 27 insertions, 5 deletions
diff --git a/src/libutil/expression.c b/src/libutil/expression.c
index 782ad2371..5b31ef27d 100644
--- a/src/libutil/expression.c
+++ b/src/libutil/expression.c
@@ -920,7 +920,7 @@ rspamd_ast_do_op (struct rspamd_expression_elt *elt, gint val, gint acc, gint li
static gint
rspamd_ast_process_node (struct rspamd_expression *expr, gint flags, GNode *node,
- gpointer data)
+ gpointer data, GPtrArray *track)
{
struct rspamd_expression_elt *elt, *celt, *parelt = NULL;
GNode *cld;
@@ -949,6 +949,10 @@ rspamd_ast_process_node (struct rspamd_expression *expr, gint flags, GNode *node
if (elt->value) {
elt->p.atom->hits ++;
+
+ if (track) {
+ g_ptr_array_add (track, elt->p.atom);
+ }
}
if (calc_ticks) {
@@ -989,7 +993,7 @@ rspamd_ast_process_node (struct rspamd_expression *expr, gint flags, GNode *node
continue;
}
- val = rspamd_ast_process_node (expr, flags, cld, data);
+ val = rspamd_ast_process_node (expr, flags, cld, data, track);
if (acc == G_MININT) {
acc = val;
@@ -1021,8 +1025,8 @@ rspamd_ast_cleanup_traverse (GNode *n, gpointer d)
}
gint
-rspamd_process_expression (struct rspamd_expression *expr, gint flags,
- gpointer data)
+rspamd_process_expression_track (struct rspamd_expression *expr, gint flags,
+ gpointer data, GPtrArray *track)
{
gint ret = 0;
@@ -1030,7 +1034,7 @@ rspamd_process_expression (struct rspamd_expression *expr, gint flags,
/* Ensure that stack is empty at this point */
g_assert (expr->expression_stack->len == 0);
- ret = rspamd_ast_process_node (expr, flags, expr->ast, data);
+ ret = rspamd_ast_process_node (expr, flags, expr->ast, data, track);
/* Cleanup */
g_node_traverse (expr->ast, G_IN_ORDER, G_TRAVERSE_ALL, -1,
@@ -1054,6 +1058,13 @@ rspamd_process_expression (struct rspamd_expression *expr, gint flags,
return ret;
}
+gint
+rspamd_process_expression (struct rspamd_expression *expr, gint flags,
+ gpointer data)
+{
+ return rspamd_process_expression_track (expr, flags, data, NULL);
+}
+
static gboolean
rspamd_ast_string_traverse (GNode *n, gpointer d)
{
diff --git a/src/libutil/expression.h b/src/libutil/expression.h
index 82c0c60c1..2c0ec7497 100644
--- a/src/libutil/expression.h
+++ b/src/libutil/expression.h
@@ -96,6 +96,17 @@ gint rspamd_process_expression (struct rspamd_expression *expr, gint flags,
gpointer data);
/**
+ * Process the expression and return its value using atom 'process' functions with the specified data pointer.
+ * This function also accepts `track` argument where it writes matched atoms (those whose value is more than 0)
+ * @param expr expression to process
+ * @param data opaque data pointer for all the atoms
+ * @param track pointer array to atoms tracking
+ * @return the value of expression
+ */
+gint rspamd_process_expression_track (struct rspamd_expression *expr, gint flags,
+ gpointer data, GPtrArray *track);
+
+/**
* Shows string representation of an expression
* @param expr expression to show
* @return freshly allocated string with expression