commit cf7e264: [Fix] Allow to reset settings id from Lua (e.g. because of the priority)
Vsevolod Stakhov
vsevolod at highsecure.ru
Wed Feb 5 09:49:07 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-02-05 09:46:43 +0000
URL: https://github.com/rspamd/rspamd/commit/cf7e2640c46b34a55df8248d33f7b372aa11089b (HEAD -> master)
[Fix] Allow to reset settings id from Lua (e.g. because of the priority)
---
src/lua/lua_task.c | 28 +++++++++++++---------------
1 file 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");
More information about the Commits
mailing list