@@ -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) | |||
{ |
@@ -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 |