]> source.dussan.org Git - rspamd.git/commitdiff
Add default metric results prior to message processing.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 22 Sep 2014 20:03:07 +0000 (21:03 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 22 Sep 2014 20:03:07 +0000 (21:03 +0100)
src/libmime/filter.c

index 61f7c0cbc4382ff0ba1c5885682cf6a22b1bb00e..bdddffb595f7690f2e3215489128f417bf0da163 100644 (file)
@@ -62,6 +62,35 @@ filter_error_quark (void)
        return g_quark_from_static_string ("g-filter-error-quark");
 }
 
+static struct metric_result *
+create_metric_result (struct rspamd_task *task, const gchar *name)
+{
+       struct metric_result *metric_res;
+       struct metric *metric;
+
+       metric = g_hash_table_lookup (task->cfg->metrics, name);
+       if (metric == NULL) {
+               return NULL;
+       }
+
+       metric_res =
+                       rspamd_mempool_alloc (task->task_pool,
+                                       sizeof (struct metric_result));
+       metric_res->symbols = g_hash_table_new (rspamd_str_hash,
+                       rspamd_str_equal);
+       metric_res->checked = FALSE;
+       rspamd_mempool_add_destructor (task->task_pool,
+                       (rspamd_mempool_destruct_t) g_hash_table_unref,
+                       metric_res->symbols);
+       metric_res->metric = metric;
+       metric_res->grow_factor = 0;
+       metric_res->score = 0;
+       g_hash_table_insert (task->results, (gpointer) metric->name,
+                       metric_res);
+
+       return metric_res;
+}
+
 static void
 insert_metric_result (struct rspamd_task *task,
        struct metric *metric,
@@ -79,20 +108,7 @@ insert_metric_result (struct rspamd_task *task,
 
        if (metric_res == NULL) {
                /* Create new metric chain */
-               metric_res =
-                       rspamd_mempool_alloc (task->task_pool,
-                               sizeof (struct metric_result));
-               metric_res->symbols = g_hash_table_new (rspamd_str_hash,
-                               rspamd_str_equal);
-               metric_res->checked = FALSE;
-               rspamd_mempool_add_destructor (task->task_pool,
-                       (rspamd_mempool_destruct_t) g_hash_table_unref,
-                       metric_res->symbols);
-               metric_res->metric = metric;
-               metric_res->grow_factor = 0;
-               metric_res->score = 0;
-               g_hash_table_insert (task->results, (gpointer) metric->name,
-                       metric_res);
+               metric_res = create_metric_result (task, metric->name);
        }
 
        weight = g_hash_table_lookup (metric->symbols, symbol);
@@ -335,6 +351,8 @@ process_filters (struct rspamd_task *task)
        struct metric *metric;
        gpointer item = NULL;
 
+       /* Insert default metric to be sure that it exists all the time */
+       create_metric_result (task, DEFAULT_METRIC);
        if (task->settings) {
                const ucl_object_t *wl;