]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Rework settings to work properly in metric-less configuration
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 19 Apr 2016 14:03:11 +0000 (15:03 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 19 Apr 2016 14:03:11 +0000 (15:03 +0100)
src/libmime/filter.c
src/lua/lua_task.c

index 7ed6ea01080b7bfdf1334ab86e882e5e30caa71d..b0f93ec4b8ac30bf6649f42ea4c9e53c8fa2deea 100644 (file)
@@ -106,16 +106,14 @@ insert_metric_result (struct rspamd_task *task,
        }
 
        if (task->settings) {
-               mobj = ucl_object_lookup (task->settings, metric->name);
-               if (mobj) {
-                       gdouble corr;
-
-                       sobj = ucl_object_lookup (mobj, symbol);
-                       if (sobj != NULL && ucl_object_todouble_safe (sobj, &corr)) {
-                               msg_debug ("settings: changed weight of symbol %s from %.2f to %.2f",
-                                               symbol, w, corr);
-                               w = corr * flag;
-                       }
+               mobj = task->settings;
+               gdouble corr;
+
+               sobj = ucl_object_lookup (mobj, symbol);
+               if (sobj != NULL && ucl_object_todouble_safe (sobj, &corr)) {
+                       msg_debug ("settings: changed weight of symbol %s from %.2f to %.2f",
+                                       symbol, w, corr);
+                       w = corr * flag;
                }
        }
 
index e522110e18f9abc70926991bde52b49eb3c469f7..6d86d316e44cebb274352d2613d97a656f73e183 100644 (file)
@@ -2471,29 +2471,34 @@ lua_task_set_settings (lua_State *L)
        settings = ucl_object_lua_import (L, 2);
 
        if (settings != NULL && task != NULL) {
-               task->settings = settings;
 
                metric_elt = ucl_object_lookup (settings, DEFAULT_METRIC);
 
                if (metric_elt) {
-                       act = ucl_object_lookup (metric_elt, "actions");
+                       task->settings = ucl_object_ref (metric_elt);
+                       ucl_object_unref (settings);
+               }
+               else {
+                       task->settings = settings;
+               }
 
-                       if (act) {
-                               /* Adjust desired actions */
-                               mres = g_hash_table_lookup (task->results, DEFAULT_METRIC);
+               act = ucl_object_lookup (task->settings, "actions");
 
-                               if (mres == NULL) {
-                                       mres = rspamd_create_metric_result (task, DEFAULT_METRIC);
-                               }
+               if (act) {
+                       /* Adjust desired actions */
+                       mres = g_hash_table_lookup (task->results, DEFAULT_METRIC);
+
+                       if (mres == NULL) {
+                               mres = rspamd_create_metric_result (task, DEFAULT_METRIC);
+                       }
 
-                               for (i = 0; i < METRIC_ACTION_MAX; i++) {
-                                       elt = ucl_object_lookup (act, rspamd_action_to_str (i));
+                       for (i = 0; i < METRIC_ACTION_MAX; i++) {
+                               elt = ucl_object_lookup (act, rspamd_action_to_str (i));
 
-                                       if (elt) {
-                                               mres->actions_limits[i] = ucl_object_todouble (elt);
-                                               msg_debug_task ("adjusted action %s to %.2f",
-                                                               ucl_object_key (elt), mres->actions_limits[i]);
-                                       }
+                               if (elt) {
+                                       mres->actions_limits[i] = ucl_object_todouble (elt);
+                                       msg_debug_task ("adjusted action %s to %.2f",
+                                                       ucl_object_key (elt), mres->actions_limits[i]);
                                }
                        }
                }