From: Vsevolod Stakhov Date: Mon, 6 Apr 2015 16:14:21 +0000 (+0100) Subject: Slightly adopt actrie for rspamd. X-Git-Tag: 0.9.0~318^2~4 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=680a2b66cbb66a52b72e18895236ccafe2791c84;p=rspamd.git Slightly adopt actrie for rspamd. --- diff --git a/contrib/aho-corasic/acism.c b/contrib/aho-corasic/acism.c index 044776613..23a5eb334 100644 --- a/contrib/aho-corasic/acism.c +++ b/contrib/aho-corasic/acism.c @@ -23,12 +23,12 @@ #define ROOT ((STATE) 0) int -acism_more(ac_trie_t const *psp, MEMREF const text, - ACISM_ACTION *cb, void *context, int *statep) +acism_lookup(ac_trie_t const *psp, const char *text, size_t len, + ACISM_ACTION *cb, void *context) { ac_trie_t const ps = *psp; - char const *cp = text.ptr, *endp = cp + text.len; - STATE state = *statep; + char const *cp = text, *endp = cp + len; + STATE state = 0; int ret = 0; while (cp < endp) { @@ -83,7 +83,7 @@ acism_more(ac_trie_t const *psp, MEMREF const text, strno = ps.hashv[i].strno; } - if ((ret = cb(strno, cp - text.ptr, context))) + if ((ret = cb(strno, cp - text, context))) goto EXIT; } @@ -102,6 +102,6 @@ acism_more(ac_trie_t const *psp, MEMREF const text, } } EXIT: - return *statep = state, ret; + return ret; } //EOF diff --git a/contrib/aho-corasic/acism.h b/contrib/aho-corasic/acism.h index 7c4398908..af6f60253 100644 --- a/contrib/aho-corasic/acism.h +++ b/contrib/aho-corasic/acism.h @@ -21,17 +21,15 @@ #ifndef ACISM_H #define ACISM_H +#include "config.h" // "acism" uses MEMREF {ptr,len} bytevec structs for "string" args, // rather than NUL-terminated "C" strings. -#ifndef MSUTIL_H -#include -typedef struct { char const *ptr; size_t len; } MEMREF; -#endif +typedef struct { char const *ptr; size_t len; } ac_trie_pat_t; typedef struct acism ac_trie_t; -ac_trie_t* acism_create(MEMREF const *strv, int nstrs); +ac_trie_t* acism_create(ac_trie_pat_t const *strv, int nstrs); void acism_destroy(ac_trie_t*); // For each match, acism_scan calls its ACISM_ACTION fn, @@ -47,14 +45,7 @@ typedef int (ACISM_ACTION)(int strnum, int textpos, void *context); // string matches can cross block boundaries. // *state should initially be (0). -int acism_more(ac_trie_t const*, MEMREF const text, - ACISM_ACTION *fn, void *fndata, int *state); - -static inline int acism_scan(ac_trie_t const*psp, MEMREF const text, - ACISM_ACTION *fn, void *fndata) -{ - int state = 0; - return acism_more(psp, text, fn, fndata, &state); -} +int acism_lookup(ac_trie_t const *psp, const char *text, size_t len, + ACISM_ACTION *cb, void *context); #endif//ACISM_H diff --git a/contrib/aho-corasic/acism_create.c b/contrib/aho-corasic/acism_create.c index 64c0dd084..b1d9b51e3 100644 --- a/contrib/aho-corasic/acism_create.c +++ b/contrib/aho-corasic/acism_create.c @@ -37,8 +37,8 @@ static inline int bitwid(unsigned u) if (u & 0x00000002) ret++; return ret; } -static void fill_symv(ac_trie_t*, MEMREF const*, int ns); -static int create_tree(TNODE*, SYMBOL const*symv, MEMREF const*strv, int nstrs); +static void fill_symv(ac_trie_t*, ac_trie_pat_t const*, int ns); +static int create_tree(TNODE*, SYMBOL const*symv, ac_trie_pat_t const*strv, int nstrs); static void add_backlinks(TNODE*, TNODE**, TNODE**); static void prune_backlinks(TNODE*); static int interleave(TNODE*, int nnodes, int nsyms, TNODE**, TNODE**); @@ -69,7 +69,7 @@ extern PSSTAT psstat[]; //--------------|--------------------------------------------- ac_trie_t* -acism_create(MEMREF const* strv, int nstrs) +acism_create(ac_trie_pat_t const* strv, int nstrs) { TNODE *tp, **v1 = NULL, **v2 = NULL; ac_trie_t *psp = calloc(1, sizeof*psp); @@ -134,7 +134,7 @@ typedef struct { int freq, rank; } FRANK; static int frcmp(FRANK*a, FRANK*b) { return a->freq - b->freq; } static void -fill_symv(ac_trie_t *psp, MEMREF const *strv, int nstrs) +fill_symv(ac_trie_t *psp, ac_trie_pat_t const *strv, int nstrs) { int i, j; FRANK frv[256]; @@ -156,7 +156,7 @@ fill_symv(ac_trie_t *psp, MEMREF const *strv, int nstrs) } static int -create_tree(TNODE *Tree, SYMBOL const *symv, MEMREF const *strv, int nstrs) +create_tree(TNODE *Tree, SYMBOL const *symv, ac_trie_pat_t const *strv, int nstrs) { int i, j; TNODE *nextp = Tree + 1;