aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-07 15:03:44 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-07 15:04:29 +0100
commitb02707fb59f7c83d91be69d16b8ac7bcc85f67b1 (patch)
treec31325721ce6e617ab6d6449142abf43e7e4db38
parentf606fef31c6f94a3a7568a1c1cbfa50872810c7d (diff)
downloadrspamd-b02707fb59f7c83d91be69d16b8ac7bcc85f67b1.tar.gz
rspamd-b02707fb59f7c83d91be69d16b8ac7bcc85f67b1.zip
Fix logic of lua_trie search.
-rw-r--r--src/lua/lua_trie.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/lua/lua_trie.c b/src/lua/lua_trie.c
index 5d2ed2428..7c7021bd1 100644
--- a/src/lua/lua_trie.c
+++ b/src/lua/lua_trie.c
@@ -115,12 +115,21 @@ lua_trie_create (lua_State *L)
return 1;
}
+struct lua_trie_cbdata {
+ gboolean found;
+ lua_State *L;
+};
+
static gint
lua_trie_callback (int strnum, int textpos, void *context)
{
- lua_State *L = context;
+ struct lua_trie_cbdata *cb = context;
+ lua_State *L;
gint ret;
+ L = cb->L;
+ cb->found = TRUE;
+
/* Function */
lua_pushvalue (L, 3);
lua_pushnumber (L, strnum);
@@ -146,17 +155,19 @@ static gint
lua_trie_search_str (lua_State *L, ac_trie_t *trie, const gchar *str, gsize len,
gint *statep)
{
+ struct lua_trie_cbdata cb;
gboolean icase = FALSE;
- gint ret;
if (lua_gettop (L) == 4) {
icase = lua_toboolean (L, 4);
}
- ret = acism_lookup (trie, str, len,
- lua_trie_callback, L, statep, icase);
+ cb.L = L;
+ cb.found = FALSE;
+ acism_lookup (trie, str, len,
+ lua_trie_callback, &cb, statep, icase);
- return ret;
+ return cb.found;
}
static gint
@@ -177,9 +188,8 @@ lua_trie_search_text (lua_State *L)
if (lua_isstring (L, -1)) {
text = lua_tolstring (L, -1, &len);
- if (lua_trie_search_str (L, trie, text, len, &state) != 0) {
+ if (lua_trie_search_str (L, trie, text, len, &state)) {
found = TRUE;
- break;
}
}
lua_pop (L, 1);
@@ -188,9 +198,9 @@ lua_trie_search_text (lua_State *L)
lua_pop (L, 1); /* table */
}
else if (lua_type (L, 2) == LUA_TSTRING) {
- text = lua_tolstring (L, -1, &len);
+ text = lua_tolstring (L, 2, &len);
- if (lua_trie_search_str (L, trie, text, len, &state) != 0) {
+ if (lua_trie_search_str (L, trie, text, len, &state)) {
found = TRUE;
}
}