]> source.dussan.org Git - rspamd.git/commitdiff
Rework lua trie API, allow raw message search.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Apr 2015 14:30:28 +0000 (15:30 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Apr 2015 14:30:28 +0000 (15:30 +0100)
src/lua/lua_trie.c
test/lua/unit/trie.lua

index 7c7021bd1e1e8881955d459b03fa4fdb794e278b..3a07fa3b191a7bd24a4f5d3ce9d80a67ca57edd9 100644 (file)
 
 /* 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);
@@ -245,6 +247,29 @@ lua_trie_search_task (lua_State *L)
        return 1;
 }
 
+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)
 {
index cff933d615b5af1d5c90f5a62578a46f23eaad2e..6fa7573f93802e35a0992680e823c9191f99156b 100644 (file)
@@ -43,7 +43,7 @@ context("Trie search functions", function()
         return 0
       end
       
-      ret = trie:search_text(c[1], cb)
+      ret = trie:match(c[1], cb)
       
       assert_equal(c[2], ret, tostring(c[2]) .. ' while matching ' .. c[1])