summaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-02-10 16:33:07 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-02-10 18:03:35 +0000
commitc7367cc48e9b63bd6c71fbbcdedacac6930bab3b (patch)
tree3f130111cb972db2c4dda37dcff3fbacfc4ea065 /src/lua
parentf0bcd2b8fe56860f4d555b570d09476f16c12e83 (diff)
downloadrspamd-c7367cc48e9b63bd6c71fbbcdedacac6930bab3b.tar.gz
rspamd-c7367cc48e9b63bd6c71fbbcdedacac6930bab3b.zip
[Minor] Allow to cache values for task from Lua API
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_task.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index eb9ddbc02..2c2e77678 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -598,11 +598,19 @@ LUA_FUNCTION_DEF (task, set_rmilter_reply);
*/
LUA_FUNCTION_DEF (task, process_regexp);
-/*
- * Deprecated functions!
+/***
+ * @method task:cache_set(key, value)
+ * Store some value to the task cache
+ * @param {string} key key to use
+ * @param {any} value any value (including functions and tables)
*/
LUA_FUNCTION_DEF (task, cache_set);
-
+/***
+ * @method task:cache_get(key)
+ * Returns cached value or nil if nothing is cached
+ * @param {string} key key to use
+ * @return {any} cached value
+ */
LUA_FUNCTION_DEF (task, cache_get);
/***
@@ -3143,12 +3151,16 @@ static gint
lua_task_cache_get (lua_State *L)
{
struct rspamd_task *task = lua_check_task (L, 1);
+ const gchar *key = luaL_checkstring (L, 2);
- if (task) {
- msg_err_task ("this function is deprecated and will return nothing");
+ if (task && key) {
+ if (!lua_task_get_cached (L, task, key)) {
+ lua_pushnil (L);
+ }
+ }
+ else {
+ luaL_error (L, "invalid arguments");
}
-
- lua_pushnumber (L, -1);
return 1;
}
@@ -3157,14 +3169,16 @@ static gint
lua_task_cache_set (lua_State *L)
{
struct rspamd_task *task = lua_check_task (L, 1);
+ const gchar *key = luaL_checkstring (L, 2);
- if (task) {
- msg_err_task ("this function is deprecated and will return nothing");
+ if (task && key && lua_gettop (L) >= 3) {
+ lua_task_set_cached (L, task, key, 3);
+ }
+ else {
+ luaL_error (L, "invalid arguments");
}
- lua_pushnumber (L, 0);
-
- return 1;
+ return 0;
}
static gint