From: Vsevolod Stakhov Date: Tue, 16 Aug 2016 11:17:10 +0000 (+0100) Subject: [Feature] Add task:get_digest method X-Git-Tag: 1.3.4~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5cf3a74fbd1d0ba0c59d50bfec91777fe4853dd2;p=thirdparty%2Frspamd.git [Feature] Add task:get_digest method --- diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 1f3620b437..baba3a001e 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} }; @@ -2753,6 +2761,33 @@ lua_task_get_flags (lua_State *L) return 1; } +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) {