From 6ead92784f0e5852410140feb220d60ec7970dee Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 16 Aug 2019 18:24:13 +0100 Subject: [PATCH] [Fix] Allow to enable or add new actions via settings --- src/lua/lua_task.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 316e91bdd..afc741af9 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -5067,8 +5067,45 @@ lua_task_set_settings (lua_State *L) } if (!found) { - msg_warn_task ("cannot set custom score %.2f for unknown action %s", - act_score, act_name); + + if (!isnan (act_score)) { + struct rspamd_action *new_act; + + HASH_FIND_PTR (task->cfg->actions, act_name, new_act); + + if (new_act == NULL) { + /* New action! */ + msg_info_task ("added new action %s with threshold %.2f " + "due to settings", + act_name, + act_score); + new_act = rspamd_mempool_alloc0 (task->task_pool, + sizeof (*new_act)); + new_act->name = rspamd_mempool_strdup (task->task_pool, act_name); + new_act->action_type = METRIC_ACTION_CUSTOM; + new_act->threshold = act_score; + } + else { + /* A disabled action that is enabled */ + msg_info_task ("enabled disabled action %s with threshold %.2f " + "due to settings", + act_name, + act_score); + } + + /* Insert it to the mres structure */ + gsize new_actions_cnt = mres->nactions + 1; + struct rspamd_action_result *old_actions = mres->actions_limits; + + mres->actions_limits = rspamd_mempool_alloc (task->task_pool, + sizeof (struct rspamd_action_result) * new_actions_cnt); + memcpy (mres->actions_limits, old_actions, + sizeof (struct rspamd_action_result) * mres->nactions); + mres->actions_limits[mres->nactions].action = new_act; + mres->actions_limits[mres->nactions].cur_limit = act_score; + mres->nactions ++; + } + /* Disabled/missing action is disabled one more time, not an error */ } else { if (isnan (act_score)) { -- 2.39.5