aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_task.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-25 17:43:58 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-25 17:43:58 +0000
commit28835c572041145b038bbfd12822595a0083d7e3 (patch)
tree4a9a3f2a45557d0f06ce5d3165ebeeb7bd267344 /src/lua/lua_task.c
parente096fa2531250b2331c1d9d45971270c4b826b0c (diff)
downloadrspamd-28835c572041145b038bbfd12822595a0083d7e3.tar.gz
rspamd-28835c572041145b038bbfd12822595a0083d7e3.zip
Add lua interfaces to re cache.
Diffstat (limited to 'src/lua/lua_task.c')
-rw-r--r--src/lua/lua_task.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 703043599..2293c55ce 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -421,6 +421,22 @@ LUA_FUNCTION_DEF (task, learn);
*/
LUA_FUNCTION_DEF (task, set_settings);
+/***
+ * @method task:cache_get(str)
+ * Return cached value for the specified string. Returns value less than 0 if str is not in the cache
+ * @param {string} str key to get from the cache
+ * @return {number} value of key or value less than 0 if a key has not been found
+ */
+LUA_FUNCTION_DEF (task, cache_get);
+
+/***
+ * @method task:cache_set(str, value)
+ * Write new or rewrite existing value of the cached key 'str'
+ * @param {string} str key to set in the cache
+ * @return {number} previous value of the key or value less than zero
+ */
+LUA_FUNCTION_DEF (task, cache_set);
+
static const struct luaL_reg tasklib_f[] = {
LUA_INTERFACE_DEF (task, create_empty),
LUA_INTERFACE_DEF (task, create_from_buffer),
@@ -471,6 +487,8 @@ static const struct luaL_reg tasklib_m[] = {
LUA_INTERFACE_DEF (task, get_metric_action),
LUA_INTERFACE_DEF (task, learn),
LUA_INTERFACE_DEF (task, set_settings),
+ LUA_INTERFACE_DEF (task, cache_get),
+ LUA_INTERFACE_DEF (task, cache_set),
{"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
@@ -1894,6 +1912,40 @@ lua_task_set_settings (lua_State *L)
}
static gint
+lua_task_cache_get (lua_State *L)
+{
+ struct rspamd_task *task = lua_check_task (L, 1);
+ const gchar *k = luaL_checkstring (L, 2);
+ gint res = RSPAMD_TASK_CACHE_NO_VALUE;
+
+ if (task && k) {
+ res = rspamd_task_re_cache_check (task, k);
+ }
+
+ lua_pushnumber (L, res);
+
+ return 1;
+}
+
+static gint
+lua_task_cache_set (lua_State *L)
+{
+ struct rspamd_task *task = lua_check_task (L, 1);
+ const gchar *k = luaL_checkstring (L, 2);
+ gint res = RSPAMD_TASK_CACHE_NO_VALUE, param = RSPAMD_TASK_CACHE_NO_VALUE;;
+
+ param = lua_tonumber (L, 3);
+ if (task && k && param > 0) {
+ res = rspamd_task_re_cache_check (task, k);
+ rspamd_task_re_cache_add (task, k, param);
+ }
+
+ lua_pushnumber (L, res);
+
+ return 1;
+}
+
+static gint
lua_task_get_metric_score (lua_State *L)
{
struct rspamd_task *task = lua_check_task (L, 1);