commit 6ead927: [Fix] Allow to enable or add new actions via settings
Vsevolod Stakhov
vsevolod at highsecure.ru
Fri Aug 16 17:28:03 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-08-16 18:24:13 +0100
URL: https://github.com/rspamd/rspamd/commit/6ead92784f0e5852410140feb220d60ec7970dee (HEAD -> master)
[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)) {
More information about the Commits
mailing list