From: Vsevolod Stakhov Date: Tue, 19 Apr 2016 14:03:11 +0000 (+0100) Subject: [Fix] Rework settings to work properly in metric-less configuration X-Git-Tag: 1.2.4~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=808a8d2f49e77b4339a4140b865ee9a671b209ef;p=rspamd.git [Fix] Rework settings to work properly in metric-less configuration --- diff --git a/src/libmime/filter.c b/src/libmime/filter.c index 7ed6ea010..b0f93ec4b 100644 --- a/src/libmime/filter.c +++ b/src/libmime/filter.c @@ -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; } } diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index e522110e1..6d86d316e 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -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]); } } }