diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-10-29 13:58:33 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-10-29 13:58:33 +0000 |
commit | db0e114862cdac564756485f9d5c9102e73d81ab (patch) | |
tree | 010416fac5f370c5b63b37aa1a4799c9bf1e60c6 /src | |
parent | 8c9cf87f25a81677b52ed1a309fea505d1c2174f (diff) | |
download | rspamd-db0e114862cdac564756485f9d5c9102e73d81ab.tar.gz rspamd-db0e114862cdac564756485f9d5c9102e73d81ab.zip |
Add parsing of multiple upstreams string.
Diffstat (limited to 'src')
-rw-r--r-- | src/libutil/upstream.c | 27 | ||||
-rw-r--r-- | src/libutil/upstream.h | 14 |
2 files changed, 40 insertions, 1 deletions
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c index 43f2bcfcc..5b86628b2 100644 --- a/src/libutil/upstream.c +++ b/src/libutil/upstream.c @@ -329,6 +329,33 @@ rspamd_upstreams_add_upstream (struct upstream_list *ups, return TRUE; } +gboolean +rspamd_upstreams_parse_line (struct upstream_list *ups, + const gchar *str, guint16 def_port, void *data) +{ + const gchar *end = str + strlen (str), *p = str; + const gchar *separators = ";, \n\r\t"; + gchar *tmp; + guint len; + gboolean ret = FALSE; + + while (p < end) { + len = strcspn (p, separators); + if (len > 0) { + tmp = g_malloc (len + 1); + rspamd_strlcpy (tmp, p, len + 1); + if (rspamd_upstreams_add_upstream (ups, tmp, def_port, data)) { + ret = TRUE; + } + } + p += len + 1; + /* Skip separators */ + p += strspn (p, separators) + 1; + } + + return ret; +} + void rspamd_upstreams_destroy (struct upstream_list *ups) { diff --git a/src/libutil/upstream.h b/src/libutil/upstream.h index cc4462878..a5e3715f9 100644 --- a/src/libutil/upstream.h +++ b/src/libutil/upstream.h @@ -51,10 +51,11 @@ struct upstream_list* rspamd_upstreams_create (void); * @param ups */ void rspamd_upstreams_destroy (struct upstream_list *ups); + /** * Add upstream from the string * @param ups upstream list - * @param str string in format "name[:port[:priority]] + * @param str string in format "name[:port[:priority]]" * @param def_port default port number * @param data optional userdata * @return TRUE if upstream has been added @@ -63,6 +64,17 @@ gboolean rspamd_upstreams_add_upstream (struct upstream_list *ups, const gchar *str, guint16 def_port, void *data); /** + * Add multiple upstreams from comma, semicolon or space separated line + * @param ups upstream list + * @param str string in format "(<ups>([<sep>+]<ups>)*)+" + * @param def_port default port number + * @param data optional userdata + * @return TRUE if **any** of upstreams has been added + */ +gboolean rspamd_upstreams_parse_line (struct upstream_list *ups, + const gchar *str, guint16 def_port, void *data); + +/** * Returns the current IP address of the upstream * @param up * @return |