diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-03-15 14:56:41 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-03-15 14:56:41 +0000 |
commit | 6151a4b7f85f6d62353d69b602db1fb0bade9402 (patch) | |
tree | 89950d942b6d3bac64af6517e8e85b05ab2cb6cf /src/libutil/upstream.c | |
parent | addeca94a989343bc4339dd7fffac4bb3329aaa1 (diff) | |
download | rspamd-6151a4b7f85f6d62353d69b602db1fb0bade9402.tar.gz rspamd-6151a4b7f85f6d62353d69b602db1fb0bade9402.zip |
[Feature] Allow forced and non-forced upstreams selection
Diffstat (limited to 'src/libutil/upstream.c')
-rw-r--r-- | src/libutil/upstream.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c index 9187ba9b9..f22092289 100644 --- a/src/libutil/upstream.c +++ b/src/libutil/upstream.c @@ -786,10 +786,10 @@ rspamd_upstream_get_hashed (struct upstream_list *ups, const guint8 *key, guint return g_ptr_array_index (ups->alive, idx); } -struct upstream* -rspamd_upstream_get (struct upstream_list *ups, +static struct upstream* +rspamd_upstream_get_common (struct upstream_list *ups, enum rspamd_upstream_rotation default_type, - const guchar *key, gsize keylen) + const guchar *key, gsize keylen, gboolean forced) { enum rspamd_upstream_rotation type; @@ -800,7 +800,12 @@ rspamd_upstream_get (struct upstream_list *ups, } rspamd_mutex_unlock (ups->lock); - type = ups->rot_alg != RSPAMD_UPSTREAM_UNDEF ? ups->rot_alg : default_type; + if (!forced) { + type = ups->rot_alg != RSPAMD_UPSTREAM_UNDEF ? ups->rot_alg : default_type; + } + else { + type = default_type != RSPAMD_UPSTREAM_UNDEF ? default_type : ups->rot_alg; + } if (type == RSPAMD_UPSTREAM_HASHED && (keylen == 0 || key == NULL)) { /* Cannot use hashed rotation when no key is specified, switch to random */ @@ -830,6 +835,22 @@ rspamd_upstream_get (struct upstream_list *ups, return NULL; } +struct upstream* +rspamd_upstream_get (struct upstream_list *ups, + enum rspamd_upstream_rotation default_type, + const guchar *key, gsize keylen) +{ + return rspamd_upstream_get_common (ups, default_type, key, keylen, FALSE); +} + +struct upstream* +rspamd_upstream_get_forced (struct upstream_list *ups, + enum rspamd_upstream_rotation forced_type, + const guchar *key, gsize keylen) +{ + return rspamd_upstream_get_common (ups, forced_type, key, keylen, TRUE); +} + void rspamd_upstream_reresolve (struct upstream_ctx *ctx) { |