]> source.dussan.org Git - rspamd.git/commitdiff
Add configuration option `unknown_weight` for metrics.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 17 Aug 2014 14:57:51 +0000 (15:57 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 17 Aug 2014 14:57:51 +0000 (15:57 +0100)
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.

conf/metrics.conf
src/libmime/filter.h
src/libserver/cfg_rcl.c
src/libserver/symbols_cache.h

index 7a735f83913cdfe130e0de60768ff4ba6a10ded1..0d41ed96ba369b6337dc1203cb3f9d4cd321087a 100644 (file)
@@ -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;
index f0a3434837ceffe5fe7a6b4d309127c10bc0bcab..c7ac43951818f3ea183ee3ce7a32563fb9679ff2 100644 (file)
@@ -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                                 */
index 1cfcf25604828a347cad1d9f6c3c27bb1790f050..d8f70de07c5f83bb1a75b2a5879f38e7232e7176 100644 (file)
@@ -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;
index e1fd3286f2cf0d2676623c10264c9c29d8df2b68..36128460d53e98a1fc5439005151f340e54b7882 100644 (file)
@@ -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;