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;
if (elt->value) {
elt->p.atom->hits ++;
+
+ if (track) {
+ g_ptr_array_add (track, elt->p.atom);
+ }
}
if (calc_ticks) {
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;
}
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;
/* 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,
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)
{
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