]> source.dussan.org Git - rspamd.git/commitdiff
More fixes to dynamic settings.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 1 Sep 2014 14:15:36 +0000 (15:15 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 1 Sep 2014 14:15:36 +0000 (15:15 +0100)
src/controller.c
src/libserver/dynamic_cfg.c

index 8a821aa43aacf3b96a1d713ff85b33f29dca2095..0d95889f55069e4c37afe62a3c512bc0482879b9 100644 (file)
@@ -375,7 +375,7 @@ rspamd_controller_handle_actions (struct rspamd_http_connection_entry *conn_ent,
        if (metric != NULL) {
                for (i = METRIC_ACTION_REJECT; i < METRIC_ACTION_MAX; i++) {
                        act = &metric->actions[i];
-                       if (act->score > 0) {
+                       if (act->score >= 0) {
                                obj = ucl_object_typed_new (UCL_OBJECT);
                                ucl_object_insert_key (obj,
                                        ucl_object_fromstring (str_action_metric (
index 4fbddb2b19391c15a60ab2cde221824d71c7d1a6..27635f4be371a1f74ac8335d7751c805d0266ad6 100644 (file)
@@ -358,13 +358,15 @@ new_dynamic_metric (const gchar *metric_name, ucl_object_t *top)
 
        metric = ucl_object_typed_new (UCL_OBJECT);
 
-       ucl_object_insert_key (top, metric,
-                       metric_name, strlen (metric_name), true);
+       ucl_object_insert_key (metric, ucl_object_fromstring (metric_name),
+                       "metric", sizeof ("metric") - 1, true);
        ucl_object_insert_key (metric, ucl_object_typed_new (UCL_ARRAY),
                        "actions", sizeof ("actions") - 1, false);
        ucl_object_insert_key (metric, ucl_object_typed_new (UCL_ARRAY),
                        "symbols", sizeof ("symbols") - 1, false);
 
+       ucl_array_append (top, metric);
+
        return metric;
 }
 
@@ -387,6 +389,25 @@ dynamic_metric_find_elt (const ucl_object_t *arr, const gchar *name)
        return NULL;
 }
 
+static ucl_object_t *
+dynamic_metric_find_metric (const ucl_object_t *arr, const gchar *metric)
+{
+       ucl_object_iter_t it = NULL;
+       const ucl_object_t *cur, *n;
+
+       while ((cur = ucl_iterate_object (arr, &it, true)) != NULL) {
+               if (cur->type == UCL_OBJECT) {
+                       n = ucl_object_find_key (cur, "metric");
+                       if (n && n->type == UCL_STRING &&
+                               strcmp (metric, ucl_object_tostring (n)) == 0) {
+                               return (ucl_object_t *)cur;
+                       }
+               }
+       }
+
+       return NULL;
+}
+
 static ucl_object_t *
 new_dynamic_elt (ucl_object_t *arr, const gchar *name, gdouble value)
 {
@@ -424,14 +445,13 @@ add_dynamic_symbol (struct rspamd_config *cfg,
                return FALSE;
        }
 
-       metric = (ucl_object_t *)ucl_object_find_key (cfg->current_dynamic_conf,
+       metric = dynamic_metric_find_metric (cfg->current_dynamic_conf,
                        metric_name);
        if (metric == NULL) {
                metric = new_dynamic_metric (metric_name, cfg->current_dynamic_conf);
        }
 
-       syms = (ucl_object_t *)ucl_object_find_key (cfg->current_dynamic_conf,
-                       "symbols");
+       syms = (ucl_object_t *)ucl_object_find_key (metric, "symbols");
        if (syms != NULL) {
                ucl_object_t *sym;
 
@@ -472,14 +492,13 @@ add_dynamic_action (struct rspamd_config *cfg,
                return FALSE;
        }
 
-       metric = (ucl_object_t *)ucl_object_find_key (cfg->current_dynamic_conf,
+       metric = dynamic_metric_find_metric (cfg->current_dynamic_conf,
                        metric_name);
        if (metric == NULL) {
                metric = new_dynamic_metric (metric_name, cfg->current_dynamic_conf);
        }
 
-       acts = (ucl_object_t *)ucl_object_find_key (cfg->current_dynamic_conf,
-                       "actions");
+       acts = (ucl_object_t *)ucl_object_find_key (metric, "actions");
        if (acts != NULL) {
                ucl_object_t *act;