aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/symbols_cache.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-08-11 13:49:24 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-08-11 13:49:24 +0100
commit676a1c60b868cca417c11e51cc62d7df5e62f825 (patch)
treeedafeba3437dde164bbaa742d0c998c1d9ec2ab0 /src/libserver/symbols_cache.c
parent0ba8904e51fc7f13e4548df7cbfc5ff5b98df24f (diff)
downloadrspamd-676a1c60b868cca417c11e51cc62d7df5e62f825.tar.gz
rspamd-676a1c60b868cca417c11e51cc62d7df5e62f825.zip
[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.
Diffstat (limited to 'src/libserver/symbols_cache.c')
-rw-r--r--src/libserver/symbols_cache.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c
index a01b95d42..c69a59383 100644
--- a/src/libserver/symbols_cache.c
+++ b/src/libserver/symbols_cache.c
@@ -210,6 +210,46 @@ rspamd_symbols_cache_order_new (gsize nelts)
}
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)
{
const struct cache_item *i1 = *(struct cache_item **)p1,
@@ -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