From: Vsevolod Stakhov Date: Thu, 11 Aug 2016 12:49:24 +0000 (+0100) Subject: [Feature] Fix order of pre and postfilters X-Git-Tag: 1.3.3~30 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=676a1c60b868cca417c11e51cc62d7df5e62f825;p=thirdparty%2Frspamd.git [Feature] Fix order of pre and postfilters Prefilters are executed in order inverse to their priorities, e.g. prefilter with priority 10 will be called before prefilter witj priority 0. Postfilters are executed in the opposite order: so postfilter with priority 10 will be executed after postfilter with priority 0. It is also possible to specify negative priorities for pre and post filters to inverse this logic. --- diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c index a01b95d427..c69a593837 100644 --- a/src/libserver/symbols_cache.c +++ b/src/libserver/symbols_cache.c @@ -209,6 +209,46 @@ rspamd_symbols_cache_order_new (gsize nelts) return ord; } +static gint +postfilters_cmp (const void *p1, const void *p2, gpointer ud) +{ + const struct cache_item *i1 = *(struct cache_item **)p1, + *i2 = *(struct cache_item **)p2; + double w1, w2; + + w1 = i1->priority; + w2 = i2->priority; + + if (w1 > w2) { + return 1; + } + else if (w1 < w2) { + return -1; + } + + return 0; +} + +static gint +prefilters_cmp (const void *p1, const void *p2, gpointer ud) +{ + const struct cache_item *i1 = *(struct cache_item **)p1, + *i2 = *(struct cache_item **)p2; + double w1, w2; + + w1 = i1->priority; + w2 = i2->priority; + + if (w1 < w2) { + return 1; + } + else if (w1 > w2) { + return -1; + } + + return 0; +} + static gint cache_logic_cmp (const void *p1, const void *p2, gpointer ud) { @@ -404,8 +444,8 @@ rspamd_symbols_cache_post_init (struct symbols_cache *cache) } } - g_ptr_array_sort_with_data (cache->prefilters, cache_logic_cmp, cache); - g_ptr_array_sort_with_data (cache->postfilters, cache_logic_cmp, cache); + g_ptr_array_sort_with_data (cache->prefilters, prefilters_cmp, cache); + g_ptr_array_sort_with_data (cache->postfilters, postfilters_cmp, cache); } static gboolean