summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-06-14 17:12:00 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-06-14 17:12:00 +0100
commitcf19d0adb550db8e6f3989550e2ce0a13917f567 (patch)
treeab4e8f55eb9ef1c5b64c8f7ec3ee82ccd381d208 /src
parentf426088b6a9c0d49bf2c9bf11583c1b36ac019b2 (diff)
downloadrspamd-cf19d0adb550db8e6f3989550e2ce0a13917f567.tar.gz
rspamd-cf19d0adb550db8e6f3989550e2ce0a13917f567.zip
[Minor] Lua_task: Allow to set settings id
Diffstat (limited to 'src')
-rw-r--r--src/lua/lua_task.c42
1 files changed, 42 insertions, 0 deletions
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
@@ -770,6 +770,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
* [here](https://rspamd.com/doc/configuration/settings.html).
@@ -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),
@@ -4887,6 +4897,38 @@ lua_task_get_settings_id (lua_State *L)
}
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)
{
LUA_TRACE_POINT;