aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-10-29 14:54:18 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-10-29 14:54:18 +0000
commit91b1e25aededed37871c7327b916ddd648f7caaf (patch)
tree476ed055084fb11eb309a2d756e88cdcee6dd4f1 /src/libutil
parent809277294ff1f7e0887ece1c44735a203a5f5b96 (diff)
downloadrspamd-91b1e25aededed37871c7327b916ddd648f7caaf.tar.gz
rspamd-91b1e25aededed37871c7327b916ddd648f7caaf.zip
Some more auxiliary functions.
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/upstream.c29
-rw-r--r--src/libutil/upstream.h20
2 files changed, 49 insertions, 0 deletions
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,
@@ -53,6 +54,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
* @param str string in format "name[:port[:priority]]"
@@ -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