aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-02-05 09:46:43 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-02-05 09:46:43 +0000
commitcf7e2640c46b34a55df8248d33f7b372aa11089b (patch)
treec17e8b928354a65bc2e38c61c497cf6b10f5fa7b /src/lua
parentee09cae67b567c84df99f14de827f8d1053eed9f (diff)
downloadrspamd-cf7e2640c46b34a55df8248d33f7b372aa11089b.tar.gz
rspamd-cf7e2640c46b34a55df8248d33f7b372aa11089b.zip
[Fix] Allow to reset settings id from Lua (e.g. because of the priority)
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_task.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 16aa15624..58fbc1932 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -810,7 +810,7 @@ LUA_FUNCTION_DEF (task, set_settings);
* Set users settings id for a task (must be registered previously)
* @available 2.0+
* @param {number} id numeric id
- * @return {boolean} true if settings id has been set
+ * @return {boolean} true if settings id has been replaced from the existing one
*/
LUA_FUNCTION_DEF (task, set_settings_id);
@@ -5591,25 +5591,23 @@ lua_task_set_settings_id (lua_State *L)
if (task != NULL && id != 0) {
+ struct rspamd_config_settings_elt *selt =
+ rspamd_config_find_settings_id_ref (task->cfg, id);
+
+ if (selt == NULL) {
+ return luaL_error (L, "settings id %u is unknown", id);
+ }
if (task->settings_elt) {
- if (task->settings_elt->id != id) {
- return luaL_error (L, "settings id has been already set to %d (%s); "
- "trying to set it to %d",
- task->settings_elt->id,
- task->settings_elt->name,
- id);
- }
+ /* Overwrite existing settings from Lua */
+ REF_RELEASE (task->settings_elt);
+ lua_pushboolean (L, true);
}
else {
- task->settings_elt = rspamd_config_find_settings_id_ref (task->cfg,
- id);
-
- if (!task->settings_elt) {
- return luaL_error (L, "settings id %u is unknown", id);
- }
+ lua_pushboolean (L, false);
}
- lua_pushboolean (L, true);
+ task->settings_elt = selt;
+
}
else {
return luaL_error (L, "invalid arguments");