diff options
author | Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com> | 2013-06-14 10:24:42 +0300 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2013-06-17 12:10:30 +0300 |
commit | 1d7739477355c0c6ab3a670541347df30cc093a5 (patch) | |
tree | 741615d4b7315345fe6fc1ea33c3cd275f395a44 | |
parent | 5e2d25966ea531b0c3d97c8e71c69d28d30a9ea6 (diff) | |
download | pacrunner-1d7739477355c0c6ab3a670541347df30cc093a5.tar.gz |
manual: Support lists of result separated by a semicolon
-rw-r--r-- | src/manual.c | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/src/manual.c b/src/manual.c index 322b89b..2deb987 100644 --- a/src/manual.c +++ b/src/manual.c @@ -536,6 +536,55 @@ static gboolean is_url_excluded(GList **excludes, return FALSE; } +static inline char *append_server(char *prev_result, const char *proxy) +{ + char *result; + + if (prev_result == NULL) + return g_strdup(proxy); + + result = g_strjoin("; ", prev_result, proxy, NULL); + if (result == NULL) + return prev_result; + + g_free(prev_result); + + return result; +} + +static inline char *append_servers_to_proxy_string(char *prev_result, + GList *proxies) +{ + char *result = prev_result; + GList *list, *prev; + + prev = NULL; + for (list = proxies; list != NULL && list != prev; + prev = list, list = list->next) + result = append_server(result, (const char *) list->data); + + return result; +} + +static char *generate_proxy_string(GList **servers, + enum pacrunner_manual_protocol proto) +{ + char *result = NULL; + + if (proto >= PACRUNNER_PROTOCOL_HTTP && + proto < PACRUNNER_PROTOCOL_MAXIMUM_NUMBER) { + if (servers[proto] != NULL) + result = append_servers_to_proxy_string(result, + servers[proto]); + } + + if (servers[PACRUNNER_PROTOCOL_ALL] != NULL) + result = append_servers_to_proxy_string(result, + servers[PACRUNNER_PROTOCOL_ALL]); + + return result; +} + char *__pacrunner_manual_execute(const char *url, const char *host, GList **servers, GList **excludes) { @@ -560,18 +609,13 @@ char *__pacrunner_manual_execute(const char *url, const char *host, if (is_url_excluded(excludes, host_p, proto) == TRUE) goto direct; - if (servers[PACRUNNER_PROTOCOL_ALL] != NULL) - result = (char *)servers[PACRUNNER_PROTOCOL_ALL]->data; - else if (proto >= PACRUNNER_PROTOCOL_HTTP && - proto < PACRUNNER_PROTOCOL_MAXIMUM_NUMBER) - if (servers[proto] != NULL) - result = (char *)servers[proto]->data; + result = generate_proxy_string(servers, proto); direct: g_free(protocol); g_free(host_p); - return g_strdup(result); + return result; } int __pacrunner_manual_init(void) |