]> source.dussan.org Git - rspamd.git/commitdiff
Allow metric registration for composite expressions.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 24 Sep 2015 17:39:46 +0000 (18:39 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 24 Sep 2015 17:39:46 +0000 (18:39 +0100)
src/libserver/cfg_rcl.c

index d5cfc0298bbdf4f5473cf80f7cbfccb6f5713256..f50b37010a32d51ddb1938f5549eec1e7c593a00 100644 (file)
@@ -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;
 }