From e31ed502be8b5109ad10f6e7bc078ecceb0c9a4d Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 7 Apr 2020 21:37:47 +0100 Subject: [PATCH] [Minor] Add a small helper function --- src/libmime/scan_result.c | 19 +++++++++++++++++++ src/libmime/scan_result.h | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/src/libmime/scan_result.c b/src/libmime/scan_result.c index 1af2905e7a..8599053863 100644 --- a/src/libmime/scan_result.c +++ b/src/libmime/scan_result.c @@ -886,4 +886,23 @@ rspamd_task_symbol_result_foreach (struct rspamd_task *task, func ((gpointer)kk, (gpointer)&res, ud); }); } +} + +struct rspamd_scan_result * +rspamd_find_metric_result (struct rspamd_task *task, + const gchar *name) +{ + struct rspamd_scan_result *res; + + if (name == NULL) { + return task->result; + } + + DL_FOREACH (task->result, res) { + if (res->name && strcmp (res->name, name) == 0) { + return res; + } + } + + return NULL; } \ No newline at end of file diff --git a/src/libmime/scan_result.h b/src/libmime/scan_result.h index fd3b8f896f..dcae2609c1 100644 --- a/src/libmime/scan_result.h +++ b/src/libmime/scan_result.h @@ -99,6 +99,15 @@ struct rspamd_scan_result { struct rspamd_scan_result *rspamd_create_metric_result (struct rspamd_task *task, const gchar *name, gint lua_sym_cbref); +/** + * Find result with a specific name (NULL means the default result) + * @param task + * @param name + * @return + */ +struct rspamd_scan_result *rspamd_find_metric_result (struct rspamd_task *task, + const gchar *name); + /** * Adds a new passthrough result to a task * @param task -- 2.47.3