aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/dynamic_cfg.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-18 10:54:51 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-18 10:54:51 +0000
commite8fab1263b5a4ea21a93967f85f1827c289c5467 (patch)
tree53052d067e73adcaaff93c96dd50d7545fd2b6c8 /src/libserver/dynamic_cfg.c
parentaa5ebcb8b9d42000aa141adbfef87012aeb18c77 (diff)
downloadrspamd-e8fab1263b5a4ea21a93967f85f1827c289c5467.tar.gz
rspamd-e8fab1263b5a4ea21a93967f85f1827c289c5467.zip
[Fix] Fix resetting symbols to their default values in WebUI
Diffstat (limited to 'src/libserver/dynamic_cfg.c')
-rw-r--r--src/libserver/dynamic_cfg.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/libserver/dynamic_cfg.c b/src/libserver/dynamic_cfg.c
index 48ce0725a..8845032f5 100644
--- a/src/libserver/dynamic_cfg.c
+++ b/src/libserver/dynamic_cfg.c
@@ -439,6 +439,47 @@ add_dynamic_symbol (struct rspamd_config *cfg,
return TRUE;
}
+gboolean
+remove_dynamic_symbol (struct rspamd_config *cfg,
+ const gchar *metric_name,
+ const gchar *symbol)
+{
+ ucl_object_t *metric, *syms;
+ gboolean ret = FALSE;
+
+ if (cfg->dynamic_conf == NULL) {
+ msg_info ("dynamic conf is disabled");
+ return FALSE;
+ }
+
+ metric = dynamic_metric_find_metric (cfg->current_dynamic_conf,
+ metric_name);
+ if (metric == NULL) {
+ return FALSE;
+ }
+
+ syms = (ucl_object_t *)ucl_object_lookup (metric, "symbols");
+ if (syms != NULL) {
+ ucl_object_t *sym;
+
+ sym = dynamic_metric_find_elt (syms, symbol);
+
+ if (sym) {
+ ret = ucl_array_delete ((ucl_object_t *)syms, sym) != NULL;
+
+ if (ret) {
+ ucl_object_unref (sym);
+ }
+ }
+ }
+
+ if (ret) {
+ apply_dynamic_conf (cfg->current_dynamic_conf, cfg);
+ }
+
+ return TRUE;
+}
+
/**
* Add action for specified metric
@@ -485,3 +526,45 @@ add_dynamic_action (struct rspamd_config *cfg,
return TRUE;
}
+
+gboolean
+remove_dynamic_action (struct rspamd_config *cfg,
+ const gchar *metric_name,
+ guint action)
+{
+ ucl_object_t *metric, *acts;
+ const gchar *action_name = rspamd_action_to_str (action);
+ gboolean ret = FALSE;
+
+ if (cfg->dynamic_conf == NULL) {
+ msg_info ("dynamic conf is disabled");
+ return FALSE;
+ }
+
+ metric = dynamic_metric_find_metric (cfg->current_dynamic_conf,
+ metric_name);
+ if (metric == NULL) {
+ return FALSE;
+ }
+
+ acts = (ucl_object_t *)ucl_object_lookup (metric, "actions");
+
+ if (acts != NULL) {
+ ucl_object_t *act;
+
+ act = dynamic_metric_find_elt (acts, action_name);
+
+ if (act) {
+ ret = ucl_array_delete (acts, act) != NULL;
+ }
+ if (ret) {
+ ucl_object_unref (act);
+ }
+ }
+
+ if (ret) {
+ apply_dynamic_conf (cfg->current_dynamic_conf, cfg);
+ }
+
+ return ret;
+}