aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libserver/cfg_file.h2
-rw-r--r--src/libserver/cfg_rcl.c25
-rw-r--r--src/libserver/cfg_utils.c19
-rw-r--r--src/lua/lua_cfg_file.c3
4 files changed, 26 insertions, 23 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index da401834a..94db0de1b 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -353,7 +353,7 @@ struct rspamd_worker_conf * rspamd_config_new_worker (struct rspamd_config *cfg,
* Return a new metric structure, setting default and non-conflicting attributes
*/
struct metric * rspamd_config_new_metric (struct rspamd_config *cfg,
- struct metric *c);
+ struct metric *c, const gchar *name);
/*
* Return a new statfile structure, setting default and non-conflicting attributes
*/
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index beb74050a..a14a43146 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -320,8 +320,17 @@ rspamd_rcl_insert_symbol (struct rspamd_config *cfg, struct metric *metric,
return FALSE;
}
- return rspamd_config_add_metric_symbol (cfg, metric->name, sym_name,
- symbol_score, description, group, one_shot, TRUE);
+ if (!rspamd_config_add_metric_symbol (cfg, metric->name, sym_name,
+ symbol_score, description, group, one_shot, TRUE)) {
+ g_set_error (err,
+ CFG_RCL_ERROR,
+ EINVAL,
+ "cannot add symbol: %s to metric %s",
+ sym_name, metric->name);
+ return FALSE;
+ }
+
+ return TRUE;
}
static gboolean
@@ -402,8 +411,7 @@ rspamd_rcl_metric_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
metric = g_hash_table_lookup (cfg->metrics, metric_name);
if (metric == NULL) {
- metric = rspamd_config_new_metric (cfg, metric);
- metric->name = metric_name;
+ metric = rspamd_config_new_metric (cfg, metric, metric_name);
}
else {
new = FALSE;
@@ -524,15 +532,6 @@ rspamd_rcl_metric_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
return FALSE;
}
- /* Insert the resulting metric */
- if (new) {
- g_hash_table_insert (cfg->metrics, (void *)metric->name, metric);
- cfg->metrics_list = g_list_prepend (cfg->metrics_list, metric);
- if (strcmp (metric->name, DEFAULT_METRIC) == 0) {
- cfg->default_metric = metric;
- }
- }
-
return TRUE;
}
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index 65e6ea9a7..94fe962bc 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -378,15 +378,10 @@ rspamd_config_post_load (struct rspamd_config *cfg)
if ((def_metric =
g_hash_table_lookup (cfg->metrics, DEFAULT_METRIC)) == NULL) {
- def_metric = rspamd_config_new_metric (cfg, NULL);
- def_metric->name = DEFAULT_METRIC;
+ def_metric = rspamd_config_new_metric (cfg, NULL, DEFAULT_METRIC);
def_metric->actions[METRIC_ACTION_REJECT].score = DEFAULT_SCORE;
- cfg->metrics_list = g_list_prepend (cfg->metrics_list, def_metric);
- g_hash_table_insert (cfg->metrics, DEFAULT_METRIC, def_metric);
}
- cfg->default_metric = def_metric;
-
if (cfg->tld_file == NULL) {
/* Try to guess tld file */
GString *fpath = g_string_new (NULL);
@@ -546,9 +541,11 @@ rspamd_config_new_statfile (struct rspamd_config *cfg,
}
struct metric *
-rspamd_config_new_metric (struct rspamd_config *cfg, struct metric *c)
+rspamd_config_new_metric (struct rspamd_config *cfg, struct metric *c,
+ const gchar *name)
{
int i;
+
if (c == NULL) {
c = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct metric));
c->grow_factor = 1.0;
@@ -558,12 +555,20 @@ rspamd_config_new_metric (struct rspamd_config *cfg, struct metric *c)
c->actions[i].score = -1.0;
}
c->subject = SPAM_SUBJECT;
+ c->name = rspamd_mempool_strdup (cfg->cfg_pool, name);
rspamd_mempool_add_destructor (cfg->cfg_pool,
(rspamd_mempool_destruct_t) g_hash_table_destroy,
c->symbols);
rspamd_mempool_add_destructor (cfg->cfg_pool,
(rspamd_mempool_destruct_t) g_hash_table_destroy,
c->descriptions);
+
+ g_hash_table_insert (cfg->metrics, (void *)c->name, c);
+ cfg->metrics_list = g_list_prepend (cfg->metrics_list, c);
+
+ if (strcmp (c->name, DEFAULT_METRIC) == 0) {
+ cfg->default_metric = c;
+ }
}
return c;
diff --git a/src/lua/lua_cfg_file.c b/src/lua/lua_cfg_file.c
index 6e49d9512..563fbb77b 100644
--- a/src/lua/lua_cfg_file.c
+++ b/src/lua/lua_cfg_file.c
@@ -48,8 +48,7 @@ lua_process_metric (lua_State *L, const gchar *name, struct rspamd_config *cfg)
/* Get module opt structure */
if ((metric = g_hash_table_lookup (cfg->metrics, name)) == NULL) {
- metric = rspamd_config_new_metric (cfg, metric);
- metric->name = rspamd_mempool_strdup (cfg->cfg_pool, name);
+ metric = rspamd_config_new_metric (cfg, metric, name);
}
/* Now iterate throught module table */