diff options
author | Michael Adam <obnox@samba.org> | 2009-12-06 12:09:54 +0100 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2009-12-06 13:17:18 +0100 |
commit | 56ba3d45bd415d1b949032c312bb188126feb205 (patch) | |
tree | 33e29a35e4cfee4efd29a0e9270f8c99f1adc2e7 | |
parent | 34dbeb3626745ac2798e4606e59539155e17049e (diff) | |
download | tinyproxy-56ba3d45bd415d1b949032c312bb188126feb205.tar.gz tinyproxy-56ba3d45bd415d1b949032c312bb188126feb205.zip |
upstream: refactor assembly of upstream out of upstream_add
Michael
Diffstat (limited to '')
-rw-r--r-- | src/reqs.c | 42 |
1 files changed, 32 insertions, 10 deletions
@@ -301,19 +301,19 @@ static int extract_ssl_url (const char *url, struct request_s *request) } #ifdef UPSTREAM_SUPPORT -/* - * Add an entry to the upstream list +/** + * Construct an upstream struct from input data. */ -void upstream_add (const char *host, int port, const char *domain) +static struct upstream *upstream_build (const char *host, int port, const char *domain) { char *ptr; - struct upstream *up = - (struct upstream *) safemalloc (sizeof (struct upstream)); + struct upstream *up; + up = (struct upstream *) safemalloc (sizeof (struct upstream)); if (!up) { log_message (LOG_ERR, - "Unable to allocate memory in upstream_add()"); - return; + "Unable to allocate memory in upstream_build()"); + return NULL; } up->host = up->domain = NULL; @@ -323,7 +323,7 @@ void upstream_add (const char *host, int port, const char *domain) if (!host || host[0] == '\0' || port < 1) { log_message (LOG_WARNING, "Nonsense upstream rule: invalid host or port"); - goto upstream_cleanup; + goto fail; } up->host = safestrdup (host); @@ -335,7 +335,7 @@ void upstream_add (const char *host, int port, const char *domain) if (!domain || domain[0] == '\0') { log_message (LOG_WARNING, "Nonsense no-upstream rule: empty domain"); - goto upstream_cleanup; + goto fail; } ptr = strchr (domain, '/'); @@ -366,7 +366,7 @@ void upstream_add (const char *host, int port, const char *domain) || domain == '\0') { log_message (LOG_WARNING, "Nonsense upstream rule: invalid parameters"); - goto upstream_cleanup; + goto fail; } up->host = safestrdup (host); @@ -377,6 +377,28 @@ void upstream_add (const char *host, int port, const char *domain) host, port, domain); } + return up; + +fail: + safefree (up->host); + safefree (up->domain); + safefree (up); + + return NULL; +} + +/* + * Add an entry to the upstream list + */ +void upstream_add (const char *host, int port, const char *domain) +{ + struct upstream *up; + + up = upstream_build (host, port, domain); + if (up == NULL) { + return; + } + if (!up->domain && !up->ip) { /* always add default to end */ struct upstream *tmp = config.upstream_list; |