From: Vsevolod Stakhov Date: Sun, 17 Aug 2014 14:57:51 +0000 (+0100) Subject: Add configuration option `unknown_weight` for metrics. X-Git-Tag: 0.7.0~170 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd4ce0b8093c0b49c841ffdf43e72570dc70ca33;p=thirdparty%2Frspamd.git Add configuration option `unknown_weight` for metrics. If this option is specified, then all filters add symbols to this metric with the specified weight even if they are not specified in symbols list explicitly. --- diff --git a/conf/metrics.conf b/conf/metrics.conf index 7a735f8391..0d41ed96ba 100644 --- a/conf/metrics.conf +++ b/conf/metrics.conf @@ -2,6 +2,10 @@ metric { name = "default"; + # If this param is set to non-zero + # then a metric would accept all symbols + # unknown_weight = 1.0 + actions { reject = 15; add_header = 6; diff --git a/src/libmime/filter.h b/src/libmime/filter.h index f0a3434837..c7ac439518 100644 --- a/src/libmime/filter.h +++ b/src/libmime/filter.h @@ -50,7 +50,9 @@ struct metric { const gchar *name; /**< name of metric */ gchar *func_name; /**< name of consolidation function */ metric_cons_func func; /**< c consolidation function */ - double grow_factor; /**< grow factor for metric */ + gboolean accept_unknown_symbols; /**< if true unknown symbols are registered here */ + gdouble unknown_weight; /**< weight of unknown symbols */ + gdouble grow_factor; /**< grow factor for metric */ GHashTable *symbols; /**< weights of symbols in metric */ GHashTable *descriptions; /**< descriptions of symbols in metric */ struct metric_action actions[METRIC_ACTION_MAX]; /**< all actions of the metric */ diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index 1cfcf25604..d8f70de07c 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -329,6 +329,7 @@ rspamd_rcl_metric_handler (struct rspamd_config *cfg, const ucl_object_t *obj, gdouble action_score, grow_factor; gint action_value; gboolean new = TRUE, have_actions = FALSE; + gdouble unknown_weight; ucl_object_iter_t it = NULL; val = ucl_object_find_key (obj, "name"); @@ -463,10 +464,20 @@ rspamd_rcl_metric_handler (struct rspamd_config *cfg, const ucl_object_t *obj, metric->subject = (gchar *)subject_name; } + val = ucl_object_find_key (obj, "unknown_weight"); + if (val && ucl_object_todouble_safe (val, &unknown_weight) && + unknown_weight != 0.) { + metric->unknown_weight = unknown_weight; + metric->accept_unknown_symbols = TRUE; + } + /* 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/symbols_cache.h b/src/libserver/symbols_cache.h index e1fd3286f2..36128460d5 100644 --- a/src/libserver/symbols_cache.h +++ b/src/libserver/symbols_cache.h @@ -33,6 +33,8 @@ struct cache_item { guint32 networks_number; gboolean is_dynamic; + gboolean is_skipped; + /* Callback data */ symbol_func_t func; gpointer user_data; @@ -41,6 +43,7 @@ struct cache_item { gboolean is_virtual; gboolean is_callback; + /* Priority */ gint priority; gdouble metric_weight;