commit cf19d0a: [Minor] Lua_task: Allow to set settings id
Vsevolod Stakhov
vsevolod at highsecure.ru
Fri Jun 14 19:00:13 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-06-14 17:12:00 +0100
URL: https://github.com/rspamd/rspamd/commit/cf19d0adb550db8e6f3989550e2ce0a13917f567
[Minor] Lua_task: Allow to set settings id
---
src/lua/lua_task.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index f562d1ca6..850eabf2e 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -769,6 +769,15 @@ LUA_FUNCTION_DEF (task, learn);
*/
LUA_FUNCTION_DEF (task, set_settings);
+/***
+ * @method task:set_settings_id(id)
+ * 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
+ */
+LUA_FUNCTION_DEF (task, set_settings_id);
+
/***
* @method task:get_settings()
* Gets users settings object for a task. The format of this object is described
@@ -1126,6 +1135,7 @@ static const struct luaL_reg tasklib_m[] = {
LUA_INTERFACE_DEF (task, get_settings),
LUA_INTERFACE_DEF (task, lookup_settings),
LUA_INTERFACE_DEF (task, get_settings_id),
+ LUA_INTERFACE_DEF (task, set_settings_id),
LUA_INTERFACE_DEF (task, cache_get),
LUA_INTERFACE_DEF (task, cache_set),
LUA_INTERFACE_DEF (task, process_regexp),
@@ -4886,6 +4896,38 @@ lua_task_get_settings_id (lua_State *L)
return 1;
}
+static gint
+lua_task_set_settings_id (lua_State *L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_task *task = lua_check_task (L, 1);
+ guint32 id = luaL_checknumber (L, 2);
+
+ if (task != NULL && id != 0) {
+
+ if (task->settings_elt) {
+ return luaL_error (L, "settings id has been already set to %d (%s)",
+ task->settings_elt->id, task->settings_elt->name);
+
+ }
+ else {
+ task->settings_elt = rspamd_config_find_settings_id_ref (task->cfg,
+ id);
+
+ if (!task->settings_elt) {
+ return luaL_error (L, "settings id %d is unknown", id);
+ }
+ }
+
+ lua_pushboolean (L, true);
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 1;
+}
+
static gint
lua_task_cache_get (lua_State *L)
{
More information about the Commits
mailing list