Added new field to upstream struct; added new function for registering an upstream proxy with basic auth
This commit is contained in:
parent
e541456ee7
commit
9fac3ef792
@ -30,9 +30,12 @@
|
||||
|
||||
#ifdef UPSTREAM_SUPPORT
|
||||
/**
|
||||
* Construct an upstream struct from input data.
|
||||
* Construct an upstream struct from input data, with basic auth credentials.
|
||||
* 'basic_auth' can be NULL.
|
||||
*/
|
||||
static struct upstream *upstream_build (const char *host, int port, const char *domain)
|
||||
static struct upstream *upstream_build (const char *host, int port,
|
||||
const char *basic_auth,
|
||||
const char *domain)
|
||||
{
|
||||
char *ptr;
|
||||
struct upstream *up;
|
||||
@ -44,7 +47,7 @@ static struct upstream *upstream_build (const char *host, int port, const char *
|
||||
return NULL;
|
||||
}
|
||||
|
||||
up->host = up->domain = NULL;
|
||||
up->host = up->domain = up->basic_auth = NULL;
|
||||
up->ip = up->mask = 0;
|
||||
|
||||
if (domain == NULL) {
|
||||
@ -57,6 +60,9 @@ static struct upstream *upstream_build (const char *host, int port, const char *
|
||||
up->host = safestrdup (host);
|
||||
up->port = port;
|
||||
|
||||
if (basic_auth != NULL)
|
||||
up->basic_auth = safestrdup (basic_auth);
|
||||
|
||||
log_message (LOG_INFO, "Added upstream %s:%d for [default]",
|
||||
host, port);
|
||||
} else if (host == NULL) {
|
||||
@ -101,6 +107,9 @@ static struct upstream *upstream_build (const char *host, int port, const char *
|
||||
up->port = port;
|
||||
up->domain = safestrdup (domain);
|
||||
|
||||
if (basic_auth != NULL)
|
||||
up->basic_auth = safestrdup (basic_auth);
|
||||
|
||||
log_message (LOG_INFO, "Added upstream %s:%d for %s",
|
||||
host, port, domain);
|
||||
}
|
||||
@ -109,6 +118,7 @@ static struct upstream *upstream_build (const char *host, int port, const char *
|
||||
|
||||
fail:
|
||||
safefree (up->host);
|
||||
safefree (up->basic_auth);
|
||||
safefree (up->domain);
|
||||
safefree (up);
|
||||
|
||||
@ -116,14 +126,15 @@ fail:
|
||||
}
|
||||
|
||||
/*
|
||||
* Add an entry to the upstream list
|
||||
* Add an entry to the upstream list, with basic auth credentials.
|
||||
* 'basic_auth' can be NULL.
|
||||
*/
|
||||
void upstream_add (const char *host, int port, const char *domain,
|
||||
struct upstream **upstream_list)
|
||||
void upstream_bauth_add (const char *host, int port, const char *basic_auth,
|
||||
const char *domain, struct upstream **upstream_list)
|
||||
{
|
||||
struct upstream *up;
|
||||
|
||||
up = upstream_build (host, port, domain);
|
||||
up = upstream_build (host, port, basic_auth, domain);
|
||||
if (up == NULL) {
|
||||
return;
|
||||
}
|
||||
@ -155,12 +166,22 @@ void upstream_add (const char *host, int port, const char *domain,
|
||||
|
||||
upstream_cleanup:
|
||||
safefree (up->host);
|
||||
safefree (up->basic_auth);
|
||||
safefree (up->domain);
|
||||
safefree (up);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add an entry to the upstream list
|
||||
*/
|
||||
void upstream_add (const char *host, int port, const char *domain,
|
||||
struct upstream **upstream_list)
|
||||
{
|
||||
upstream_bauth_add (host, port, NULL, domain, upstream_list);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if a host is in the upstream list
|
||||
*/
|
||||
@ -216,6 +237,7 @@ void free_upstream_list (struct upstream *up)
|
||||
struct upstream *tmp = up;
|
||||
up = up->next;
|
||||
safefree (tmp->domain);
|
||||
safefree (tmp->basic_auth);
|
||||
safefree (tmp->host);
|
||||
safefree (tmp);
|
||||
}
|
||||
|
@ -36,12 +36,16 @@ struct upstream {
|
||||
char *domain; /* optional */
|
||||
char *host;
|
||||
int port;
|
||||
char *basic_auth; /* optional, Base64 basic auth */
|
||||
in_addr_t ip, mask;
|
||||
};
|
||||
|
||||
#ifdef UPSTREAM_SUPPORT
|
||||
extern void upstream_add (const char *host, int port, const char *domain,
|
||||
struct upstream **upstream_list);
|
||||
extern void upstream_bauth_add (const char *host, int port,
|
||||
const char *basic_auth, const char *domain,
|
||||
struct upstream **upstream_list);
|
||||
extern struct upstream *upstream_get (char *host, struct upstream *up);
|
||||
extern void free_upstream_list (struct upstream *up);
|
||||
#endif /* UPSTREAM_SUPPORT */
|
||||
|
Loading…
Reference in New Issue
Block a user