* @return TRUE if symbol has been inserted or FALSE if symbol already exists with higher priority
*/
gboolean rspamd_config_add_metric_symbol (struct rspamd_config *cfg,
- const gchar *metric,
const gchar *symbol, gdouble score, const gchar *description,
const gchar *group, guint flags,
guint priority,
struct rspamd_rcl_section *section, GError **err)
{
struct rspamd_rcl_symbol_data *sd = ud;
- struct rspamd_metric *metric;
struct rspamd_config *cfg;
const ucl_object_t *elt;
const gchar *description = NULL;
gint nshots;
g_assert (key != NULL);
- metric = sd->metric;
- g_assert (metric != NULL);
cfg = sd->cfg;
nshots = cfg->default_max_shots;
}
if (sd->gr) {
- rspamd_config_add_metric_symbol (cfg, metric->name, key, score,
+ rspamd_config_add_metric_symbol (cfg, key, score,
description, sd->gr->name, flags, priority, nshots);
}
else {
- rspamd_config_add_metric_symbol (cfg, metric->name, key, score,
+ rspamd_config_add_metric_symbol (cfg, key, score,
description, NULL, flags, priority, nshots);
}
struct rspamd_expression *expr;
struct rspamd_config *cfg = ud;
struct rspamd_composite *composite;
- const gchar *composite_name, *composite_expression, *group, *metric,
+ const gchar *composite_name, *composite_expression, *group,
*description;
gdouble score;
gboolean new = TRUE;
group = "composite";
}
- val = ucl_object_lookup (obj, "metric");
- if (val != NULL) {
- metric = ucl_object_tostring (val);
- }
- else {
- metric = DEFAULT_METRIC;
- }
-
val = ucl_object_lookup (obj, "description");
if (val != NULL) {
description = ucl_object_tostring (val);
description = composite_expression;
}
- rspamd_config_add_metric_symbol (cfg, metric, composite_name, score,
+ rspamd_config_add_metric_symbol (cfg, composite_name, score,
description, group, FALSE, FALSE,
1);
}
cfg->max_diff = 20480;
cfg->metrics = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
+ rspamd_config_new_metric (cfg, NULL, DEFAULT_METRIC);
cfg->c_modules = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
cfg->composite_symbols =
g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
#endif
- struct rspamd_metric *def_metric;
gboolean ret = TRUE;
#ifdef HAVE_CLOCK_GETTIME
}
#endif
- if ((def_metric =
- g_hash_table_lookup (cfg->metrics, DEFAULT_METRIC)) == NULL) {
- def_metric = rspamd_config_new_metric (cfg, NULL, DEFAULT_METRIC);
- def_metric->actions[METRIC_ACTION_REJECT].score = DEFAULT_SCORE;
- }
-
if (opts & RSPAMD_CONFIG_INIT_URL) {
if (cfg->tld_file == NULL) {
/* Try to guess tld file */
gboolean
rspamd_config_add_metric_symbol (struct rspamd_config *cfg,
- const gchar *metric_name, const gchar *symbol,
+ const gchar *symbol,
gdouble score, const gchar *description, const gchar *group,
guint flags, guint priority, gint nshots)
{
g_assert (cfg != NULL);
g_assert (symbol != NULL);
- if (metric_name == NULL) {
- metric_name = DEFAULT_METRIC;
- }
-
- metric = g_hash_table_lookup (cfg->metrics, metric_name);
-
- if (metric == NULL) {
- msg_err_config ("metric %s has not been found", metric_name);
- return FALSE;
- }
-
+ metric = cfg->default_metric;
sym_def = g_hash_table_lookup (metric->symbols, symbol);
if (sym_def != NULL) {
/*
* We use priority = 3 here
*/
- rspamd_config_add_metric_symbol (cfg, real_metric->name,
+ rspamd_config_add_metric_symbol (cfg,
ucl_object_tostring (n), nscore, NULL, NULL,
0, priority, cfg->default_max_shots);
}
nshots = 1;
}
- rspamd_config_add_metric_symbol (cfg, DEFAULT_METRIC, name,
+ rspamd_config_add_metric_symbol (cfg, name,
score, description, group, flags, (guint)priority, nshots);
}
}
msg_err_config ("metric named %s is not defined", metric_name);
}
else if (name != NULL && weight != 0) {
- rspamd_config_add_metric_symbol (cfg, metric_name, name,
+ rspamd_config_add_metric_symbol (cfg, name,
weight, description, group, flags, (guint)priority, nshots);
}
}
* Do not override the existing symbols (using zero priority),
* since we are defining default values here
*/
- rspamd_config_add_metric_symbol (cfg, NULL, name, score,
+ rspamd_config_add_metric_symbol (cfg, name, score,
description, group, flags, 0, nshots);
}
else {
"DKIM_SIGN", dkim_module_ctx->symbol_reject);
}
- rspamd_config_add_metric_symbol (cfg, DEFAULT_METRIC,
+ rspamd_config_add_metric_symbol (cfg,
"DKIM_SIGN", 0.0, "DKIM signature fake symbol",
"dkim", RSPAMD_SYMBOL_FLAG_IGNORE, 1, 1);
nlua ++;
}
else if (value->type == UCL_OBJECT) {
- const gchar *description = NULL, *group = NULL,
- *metric = DEFAULT_METRIC;
+ const gchar *description = NULL, *group = NULL;
gdouble score = 0.0;
guint flags = 0, priority = 0;
gboolean is_lua = FALSE, valid_expression = TRUE;
conddata->L, conddata->idx);
}
- elt = ucl_object_lookup (value, "metric");
-
- if (elt) {
- metric = ucl_object_tostring (elt);
- }
-
elt = ucl_object_lookup (value, "description");
if (elt) {
priority = ucl_object_toint (elt);
}
- rspamd_config_add_metric_symbol (cfg, metric, cur_item->symbol,
+ rspamd_config_add_metric_symbol (cfg, cur_item->symbol,
score, description, group, flags, priority, nshots);
}
}