diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-05-24 13:32:34 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-05-24 13:32:34 +0100 |
commit | df0b6cd825ad79f2390cae82f57efef2fef399f1 (patch) | |
tree | 06b248cb5ef9d6c89ee085978ef9a6193d057dd4 /src/lua/lua_trie.c | |
parent | 2da5a85bb66919a6db3f8148b1f29c9bbeab89a9 (diff) | |
download | rspamd-df0b6cd825ad79f2390cae82f57efef2fef399f1.tar.gz rspamd-df0b6cd825ad79f2390cae82f57efef2fef399f1.zip |
[Feature] Implement body rules for the trie plugin
Diffstat (limited to 'src/lua/lua_trie.c')
-rw-r--r-- | src/lua/lua_trie.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/lua/lua_trie.c b/src/lua/lua_trie.c index ac6ebb559..a0bf3afd4 100644 --- a/src/lua/lua_trie.c +++ b/src/lua/lua_trie.c @@ -42,12 +42,14 @@ LUA_FUNCTION_DEF (trie, create); LUA_FUNCTION_DEF (trie, match); LUA_FUNCTION_DEF (trie, search_mime); LUA_FUNCTION_DEF (trie, search_rawmsg); +LUA_FUNCTION_DEF (trie, search_rawbody); LUA_FUNCTION_DEF (trie, destroy); static const struct luaL_reg trielib_m[] = { LUA_INTERFACE_DEF (trie, match), LUA_INTERFACE_DEF (trie, search_mime), LUA_INTERFACE_DEF (trie, search_rawmsg), + LUA_INTERFACE_DEF (trie, search_rawbody), {"__tostring", rspamd_lua_class_tostring}, {"__gc", lua_trie_destroy}, {NULL, NULL} @@ -303,6 +305,43 @@ lua_trie_search_rawmsg (lua_State *L) return 1; } +/*** + * @method trie:search_rawbody(task, cb[, caseless]) + * This is a helper mehthod to search pattern within the whole undecoded content of task's body (not including headers) + * @param {task} task object + * @param {function} cb callback called on each pattern match @see trie:match + * @param {boolean} caseless if `true` then match ignores symbols case (ASCII only) + * @return {boolean} `true` if any pattern has been found (`cb` might be called multiple times however) + */ +static gint +lua_trie_search_rawbody (lua_State *L) +{ + struct rspamd_multipattern *trie = lua_check_trie (L, 1); + struct rspamd_task *task = lua_check_task (L, 2); + const gchar *text; + gsize len; + gboolean found = FALSE; + + if (trie) { + if (task->raw_headers_content.len > 0) { + text = task->msg.begin + task->raw_headers_content.len; + len = task->msg.len - task->raw_headers_content.len; + } + else { + /* Treat as raw message */ + text = task->msg.begin; + len = task->msg.len; + } + + if (lua_trie_search_str (L, trie, text, len) != 0) { + found = TRUE; + } + } + + lua_pushboolean (L, found); + return 1; +} + static gint lua_load_trie (lua_State *L) { |