From eb38f643f3b26d552fb4503dcc8528e3388c9b99 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 24 Sep 2015 18:39:46 +0100 Subject: [PATCH] Allow metric registration for composite expressions. --- src/libserver/cfg_rcl.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index d5cfc0298..f50b37010 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -1050,7 +1050,9 @@ rspamd_rcl_composite_handler (rspamd_mempool_t *pool, struct rspamd_expression *expr; struct rspamd_config *cfg = ud; struct rspamd_composite *composite; - const gchar *composite_name, *composite_expression; + const gchar *composite_name, *composite_expression, *group, *metric, + *description; + gdouble score; gboolean new = TRUE; g_assert (key != NULL); @@ -1098,6 +1100,38 @@ rspamd_rcl_composite_handler (rspamd_mempool_t *pool, NULL, NULL, SYMBOL_TYPE_COMPOSITE, -1); } + val = ucl_object_find_key (obj, "score"); + if (val != NULL && ucl_object_todouble_safe (val, &score)) { + /* Also set score in the metric */ + + val = ucl_object_find_key (obj, "group"); + if (val != NULL) { + group = ucl_object_tostring (val); + } + else { + group = "composite"; + } + + val = ucl_object_find_key (obj, "metric"); + if (val != NULL) { + metric = ucl_object_tostring (val); + } + else { + metric = DEFAULT_METRIC; + } + + val = ucl_object_find_key (obj, "description"); + if (val != NULL) { + description = ucl_object_tostring (val); + } + else { + description = composite_expression; + } + + rspamd_config_add_metric_symbol (cfg, metric, composite_name, score, + description, group, FALSE, FALSE); + } + return TRUE; } -- 2.39.5