From: Vsevolod Stakhov Date: Tue, 8 Dec 2015 21:48:57 +0000 (+0000) Subject: More rework of hyperscan matching X-Git-Tag: 1.1.0~366 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=60da1e02c949c491552644b29c3e7b0e3d36da93;p=rspamd.git More rework of hyperscan matching --- diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c index 4c0801948..44eadd385 100644 --- a/src/libserver/re_cache.c +++ b/src/libserver/re_cache.c @@ -444,27 +444,29 @@ rspamd_re_cache_hyperscan_cb (unsigned int id, { struct rspamd_re_hyperscan_cbdata *cbdata = ud; struct rspamd_re_runtime *rt; + struct rspamd_re_cache_elt *pcre_elt; guint ret; - rspamd_regexp_t *re; rt = cbdata->rt; - re = cbdata->re; - - if (flags & HS_FLAG_PREFILTER) { - /* We need to match the corresponding pcre first */ - ret = rspamd_re_cache_process_pcre (rt, - re, - cbdata->in + from, - to - from, - FALSE, - TRUE); - } - else { - ret = 1; - } - setbit (rt->checked, id); - rt->results[id] += ret; + if (!isset (rt->checked, id)) { + if (flags & HS_FLAG_PREFILTER) { + /* We need to match the corresponding pcre first */ + pcre_elt = g_ptr_array_index (rt->cache->re, id); + ret = rspamd_re_cache_process_pcre (rt, + pcre_elt->re, + cbdata->in + from, + to - from, + FALSE, + TRUE); + } + else { + ret = 1; + } + + setbit (rt->checked, id); + rt->results[id] += ret; + } return 0; } @@ -479,11 +481,11 @@ rspamd_re_cache_process_regexp_data (struct rspamd_re_runtime *rt, struct rspamd_re_cache_elt *elt; struct rspamd_re_class *re_class; guint64 re_id; - guint ret, i; + guint ret; re_id = rspamd_regexp_get_cache_id (re); elt = g_ptr_array_index (rt->cache->re, re_id); - (void)i; + re_class = rspamd_regexp_get_class (re); #ifndef WITH_HYPERSCAN ret = rspamd_re_cache_process_pcre (rt, re, in, len, is_raw, is_multiple); @@ -506,7 +508,6 @@ rspamd_re_cache_process_regexp_data (struct rspamd_re_runtime *rt, len = rt->cache->max_re_data; } - re_class = rspamd_regexp_get_class (re); g_assert (re_class->hs_scratch != NULL); g_assert (re_class->hs_db != NULL); @@ -522,21 +523,32 @@ rspamd_re_cache_process_regexp_data (struct rspamd_re_runtime *rt, else { ret = rt->results[re_id]; } + } +#endif - /* Set all bits unchecked */ - for (i = 0; i < re_class->nhs; i++) { - re_id = re_class->hs_ids[i]; + return ret; +} - if (!isset (rt->checked, re_id)) { - rt->results[re_id] = 0; - setbit (rt->checked, re_id); - } +static void +rspamd_re_cache_finish_class (struct rspamd_re_runtime *rt, + struct rspamd_re_class *re_class) +{ +#ifdef WITH_HYPERSCAN + guint i; + guint64 re_id; + + /* Set all bits unchecked */ + for (i = 0; i < re_class->nhs; i++) { + re_id = re_class->hs_ids[i]; + + if (!isset (rt->checked, re_id)) { + rt->results[re_id] = 0; + setbit (rt->checked, re_id); } } #endif - - return ret; } + /* * Calculates the specified regexp for the specified class if it's not calculated */ @@ -684,6 +696,8 @@ rspamd_re_cache_exec_re (struct rspamd_task *task, break; } + rspamd_re_cache_finish_class (rt, re_class); + return ret; }