diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-04-07 15:30:28 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-04-07 15:30:28 +0100 |
commit | 125f1805175b7760930f404578642066d0981eb5 (patch) | |
tree | ff4ba44637ab0d198fd66e0075b0884f8b780b81 /src/lua/lua_trie.c | |
parent | 224c69e485d7cd589bfdb07a3a31cecd68697986 (diff) | |
download | rspamd-125f1805175b7760930f404578642066d0981eb5.tar.gz rspamd-125f1805175b7760930f404578642066d0981eb5.zip |
Rework lua trie API, allow raw message search.
Diffstat (limited to 'src/lua/lua_trie.c')
-rw-r--r-- | src/lua/lua_trie.c | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/src/lua/lua_trie.c b/src/lua/lua_trie.c index 7c7021bd1..3a07fa3b1 100644 --- a/src/lua/lua_trie.c +++ b/src/lua/lua_trie.c @@ -29,13 +29,15 @@ /* Suffix trie */ LUA_FUNCTION_DEF (trie, create); -LUA_FUNCTION_DEF (trie, search_text); -LUA_FUNCTION_DEF (trie, search_task); +LUA_FUNCTION_DEF (trie, match); +LUA_FUNCTION_DEF (trie, search_mime); +LUA_FUNCTION_DEF (trie, search_rawmsg); LUA_FUNCTION_DEF (trie, destroy); static const struct luaL_reg trielib_m[] = { - LUA_INTERFACE_DEF (trie, search_text), - LUA_INTERFACE_DEF (trie, search_task), + LUA_INTERFACE_DEF (trie, match), + LUA_INTERFACE_DEF (trie, search_mime), + LUA_INTERFACE_DEF (trie, search_rawmsg), {"__tostring", rspamd_lua_class_tostring}, {"__gc", lua_trie_destroy}, {NULL, NULL} @@ -171,7 +173,7 @@ lua_trie_search_str (lua_State *L, ac_trie_t *trie, const gchar *str, gsize len, } static gint -lua_trie_search_text (lua_State *L) +lua_trie_match (lua_State *L) { ac_trie_t *trie = lua_check_trie (L, 1); const gchar *text; @@ -211,7 +213,7 @@ lua_trie_search_text (lua_State *L) } static gint -lua_trie_search_task (lua_State *L) +lua_trie_search_mime (lua_State *L) { ac_trie_t *trie = lua_check_trie (L, 1); struct rspamd_task *task = lua_check_task (L, 2); @@ -246,6 +248,29 @@ lua_trie_search_task (lua_State *L) } static gint +lua_trie_search_rawmsg (lua_State *L) +{ + ac_trie_t *trie = lua_check_trie (L, 1); + struct rspamd_task *task = lua_check_task (L, 2); + const gchar *text; + gint state = 0; + gsize len; + gboolean found = FALSE; + + if (trie) { + text = task->msg.start; + len = task->msg.len; + + if (lua_trie_search_str (L, trie, text, len, &state) != 0) { + found = TRUE; + } + } + + lua_pushboolean (L, found); + return 1; +} + +static gint lua_load_trie (lua_State *L) { lua_newtable (L); |