From: Vsevolod Stakhov Date: Mon, 1 Sep 2014 14:15:36 +0000 (+0100) Subject: More fixes to dynamic settings. X-Git-Tag: 0.7.0~52 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=110e204fd1f5bfe36b08961a746a76b30f7f57eb;p=rspamd.git More fixes to dynamic settings. --- diff --git a/src/controller.c b/src/controller.c index 8a821aa43..0d95889f5 100644 --- a/src/controller.c +++ b/src/controller.c @@ -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 ( diff --git a/src/libserver/dynamic_cfg.c b/src/libserver/dynamic_cfg.c index 4fbddb2b1..27635f4be 100644 --- a/src/libserver/dynamic_cfg.c +++ b/src/libserver/dynamic_cfg.c @@ -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;