From: Vsevolod Stakhov Date: Wed, 29 Oct 2014 14:54:18 +0000 (+0000) Subject: Some more auxiliary functions. X-Git-Tag: 0.7.3~28 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=91b1e25aededed37871c7327b916ddd648f7caaf;p=rspamd.git Some more auxiliary functions. --- diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c index 5b86628b2..fb469242f 100644 --- a/src/libutil/upstream.c +++ b/src/libutil/upstream.c @@ -274,6 +274,12 @@ rspamd_upstreams_create (void) return ls; } +gsize +rspamd_upstreams_count (struct upstream_list *ups) +{ + return ups->ups->len; +} + static void rspamd_upstream_dtor (struct upstream *up) { @@ -356,6 +362,29 @@ rspamd_upstreams_parse_line (struct upstream_list *ups, return ret; } +gboolean +rspamd_upstreams_from_ucl (struct upstream_list *ups, + const ucl_object_t *in, guint16 def_port, void *data) +{ + gboolean ret = FALSE; + const ucl_object_t *cur; + ucl_object_iter_t it = NULL; + + if (ucl_object_type (in) == UCL_ARRAY) { + while ((cur = ucl_iterate_object (in, &it, true)) != NULL) { + if (rspamd_upstreams_from_ucl (ups, cur, def_port, data)) { + ret = TRUE; + } + } + } + else if (ucl_object_type (in) == UCL_STRING) { + ret = rspamd_upstreams_parse_line (ups, ucl_object_tostring (in), + def_port, data); + } + + return ret; +} + void rspamd_upstreams_destroy (struct upstream_list *ups) { diff --git a/src/libutil/upstream.h b/src/libutil/upstream.h index a5e3715f9..f6f711034 100644 --- a/src/libutil/upstream.h +++ b/src/libutil/upstream.h @@ -4,6 +4,7 @@ #include "config.h" #include "util.h" #include "rdns.h" +#include "ucl.h" enum rspamd_upstream_rotation { RSPAMD_UPSTREAM_RANDOM, @@ -52,6 +53,13 @@ struct upstream_list* rspamd_upstreams_create (void); */ void rspamd_upstreams_destroy (struct upstream_list *ups); +/** + * Returns count of upstreams in a list + * @param ups + * @return + */ +gsize rspamd_upstreams_count (struct upstream_list *ups); + /** * Add upstream from the string * @param ups upstream list @@ -74,6 +82,18 @@ gboolean rspamd_upstreams_add_upstream (struct upstream_list *ups, gboolean rspamd_upstreams_parse_line (struct upstream_list *ups, const gchar *str, guint16 def_port, void *data); + +/** + * Parse upstreams list from the UCL object + * @param ups + * @param in + * @param def_port + * @param data + * @return + */ +gboolean rspamd_upstreams_from_ucl (struct upstream_list *ups, + const ucl_object_t *in, guint16 def_port, void *data); + /** * Returns the current IP address of the upstream * @param up