aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-17 10:10:33 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-17 10:10:33 +0100
commitd4ad6ac19dbe2d1896e0fb47ee1fb9c6bba9f391 (patch)
tree7009629f70d357419d75b548a197c4fbd3b36048 /src
parent86c9af08233e9892312d573e8e35084093b40679 (diff)
downloadrspamd-d4ad6ac19dbe2d1896e0fb47ee1fb9c6bba9f391.tar.gz
rspamd-d4ad6ac19dbe2d1896e0fb47ee1fb9c6bba9f391.zip
[Minor] Slightly improve and document task:set_user method
Diffstat (limited to 'src')
-rw-r--r--src/lua/lua_task.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 2ce489e9c..cffaa269c 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -453,6 +453,11 @@ LUA_FUNCTION_DEF (task, set_from);
* @return {string} username or nil
*/
LUA_FUNCTION_DEF (task, get_user);
+/***
+ * @method task:set_user([username])
+ * Sets or resets (if username is not specified) authenticated user name for this task.
+ * @return {string} the previously set username or nil
+ */
LUA_FUNCTION_DEF (task, set_user);
/***
* @method task:get_from_ip()
@@ -2910,16 +2915,38 @@ lua_task_set_user (lua_State *L)
const gchar *new_user;
if (task) {
- new_user = luaL_checkstring (L, 2);
- if (new_user) {
+
+ if (lua_type (L, 2) == LUA_TSTRING) {
+ new_user = lua_tostring (L, 2);
+
+ if (task->user) {
+ /* Push old user */
+ lua_pushstring (L, task->user);
+ }
+ else {
+ lua_pushnil (L);
+ }
+
task->user = rspamd_mempool_strdup (task->task_pool, new_user);
}
+ else {
+ /* Reset user */
+ if (task->user) {
+ /* Push old user */
+ lua_pushstring (L, task->user);
+ }
+ else {
+ lua_pushnil (L);
+ }
+
+ task->user = NULL;
+ }
}
else {
return luaL_error (L, "invalid arguments");
}
- return 0;
+ return 1;
}
static gint