aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-08-16 12:17:10 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-08-16 12:17:10 +0100
commit5cf3a74fbd1d0ba0c59d50bfec91777fe4853dd2 (patch)
tree0859a46b6af9e062fcb5ebb7af7df78b8607e527 /src/lua
parent92a519277eab48c3f624157045e88b3d02c97f86 (diff)
downloadrspamd-5cf3a74fbd1d0ba0c59d50bfec91777fe4853dd2.tar.gz
rspamd-5cf3a74fbd1d0ba0c59d50bfec91777fe4853dd2.zip
[Feature] Add task:get_digest method
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_task.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 1f3620b43..baba3a001 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -655,6 +655,13 @@ LUA_FUNCTION_DEF (task, has_flag);
*/
LUA_FUNCTION_DEF (task, get_flags);
+/***
+ * @method task:get_digest()
+ * Returns message's unique digest (32 hex symbols)
+ * @return {string} hex digest
+ */
+LUA_FUNCTION_DEF (task, get_digest);
+
static const struct luaL_reg tasklib_f[] = {
{NULL, NULL}
};
@@ -730,6 +737,7 @@ static const struct luaL_reg tasklib_m[] = {
LUA_INTERFACE_DEF (task, get_flags),
LUA_INTERFACE_DEF (task, has_flag),
LUA_INTERFACE_DEF (task, set_rmilter_reply),
+ LUA_INTERFACE_DEF (task, get_digest),
{"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
@@ -2754,6 +2762,33 @@ lua_task_get_flags (lua_State *L)
}
static gint
+lua_task_get_digest (lua_State *L)
+{
+ struct rspamd_task *task = lua_check_task (L, 1);
+ gchar hexbuf[33];
+ gint r;
+
+ if (task) {
+ r = rspamd_encode_hex_buf (task->digest, sizeof (task->digest),
+ hexbuf, sizeof (hexbuf) - 1);
+
+ if (r > 0) {
+ hexbuf[r] = '\0';
+ lua_pushstring (L, hexbuf);
+ }
+ else {
+ lua_pushnil (L);
+ }
+
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 1;
+}
+
+static gint
lua_task_learn (lua_State *L)
{
struct rspamd_task *task = lua_check_task (L, 1);