From 612bbd0102d0090b753de4ccc10147461e4a3932 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 15 Mar 2016 13:45:53 +0000 Subject: [PATCH] [Feature] Allow iterating over upstreams --- src/libutil/upstream.c | 15 +++++++++++++++ src/libutil/upstream.h | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c index 3d0121572..a49a8a222 100644 --- a/src/libutil/upstream.c +++ b/src/libutil/upstream.c @@ -889,3 +889,18 @@ rspamd_upstream_get_data (struct upstream *up) { return up->data; } + + +void +rspamd_upstreams_foreach (struct upstream_list *ups, + rspamd_upstream_traverse_func cb, void *ud) +{ + struct upstream *up; + guint i; + + for (i = 0; i < ups->ups->len; i ++) { + up = g_ptr_array_index (ups->ups, i); + + cb (up, ud); + } +} diff --git a/src/libutil/upstream.h b/src/libutil/upstream.h index 79d88802d..c3cbf685a 100644 --- a/src/libutil/upstream.h +++ b/src/libutil/upstream.h @@ -130,6 +130,19 @@ gboolean rspamd_upstreams_parse_line (struct upstream_list *ups, gboolean rspamd_upstreams_from_ucl (struct upstream_list *ups, const ucl_object_t *in, guint16 def_port, void *data); + +typedef void (*rspamd_upstream_traverse_func) (struct upstream *up, + void *ud); + +/** + * Traverse upstreams list calling the function specified + * @param ups + * @param cb + * @param ud + */ +void rspamd_upstreams_foreach (struct upstream_list *ups, + rspamd_upstream_traverse_func cb, void *ud); + /** * Returns the current IP address of the upstream * @param up -- 2.39.5