From efaf25c90f01b79c8c6b83abc291334e61af37d1 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 7 Apr 2015 11:54:11 +0100 Subject: [PATCH] Allow caseless trie search. --- contrib/aho-corasick/acism.c | 6 ++++-- contrib/aho-corasick/acism.h | 2 +- src/libserver/url.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/contrib/aho-corasick/acism.c b/contrib/aho-corasick/acism.c index a4c678154..64e1eb956 100644 --- a/contrib/aho-corasick/acism.c +++ b/contrib/aho-corasick/acism.c @@ -24,15 +24,17 @@ int acism_lookup(ac_trie_t const *psp, const char *text, size_t len, - ACISM_ACTION *cb, void *context, int *statep) + ACISM_ACTION *cb, void *context, int *statep, bool caseless) { ac_trie_t const ps = *psp; char const *cp = text, *endp = cp + len; + uint8_t s; STATE state = *statep; int ret = 0; while (cp < endp) { - _SYMBOL sym = ps.symv[(uint8_t)*cp++]; + s = caseless ? g_ascii_tolower (*cp++) : *cp++; + _SYMBOL sym = ps.symv[s]; if (!sym) { // Input byte is not in any pattern string. state = ROOT; diff --git a/contrib/aho-corasick/acism.h b/contrib/aho-corasick/acism.h index 3886b149e..d942fd413 100644 --- a/contrib/aho-corasick/acism.h +++ b/contrib/aho-corasick/acism.h @@ -46,6 +46,6 @@ typedef int (ACISM_ACTION)(int strnum, int textpos, void *context); // *state should initially be (0). int acism_lookup(ac_trie_t const *psp, const char *text, size_t len, - ACISM_ACTION *cb, void *context, int *statep); + ACISM_ACTION *cb, void *context, int *statep, bool caseless); #endif//ACISM_H diff --git a/src/libserver/url.c b/src/libserver/url.c index b29fcfc1f..41ecb7dd2 100644 --- a/src/libserver/url.c +++ b/src/libserver/url.c @@ -1430,7 +1430,7 @@ rspamd_url_find (rspamd_mempool_t *pool, cb.is_html = is_html; cb.pool = pool; ret = acism_lookup (url_scanner->search_trie, begin, len, - rspamd_url_trie_callback, &cb, statep); + rspamd_url_trie_callback, &cb, statep, true); if (ret) { if (start) { -- 2.39.5