/* Initialise worker if needed, note the shared area must be initialized by the balancer logic */
if (balancer) {
- ap_proxy_initialize_worker(worker, r->server, conf->pool);
+ ap_proxy_initialize_worker(worker, r->server, conf->pool);
}
if (balancer && balancer->max_attempts_set && !max_attempts)
const char *err;
err = ap_check_cmd_context(cmd, NOT_IN_DIRECTORY|NOT_IN_FILES);
- if (err) {
+ if (err) {
return err;
}
const char *err;
err = ap_check_cmd_context(cmd, NOT_IN_DIRECTORY|NOT_IN_FILES);
- if (err) {
+ if (err) {
return err;
}
PROXY_STRNCPY(conf->forward->s->name, "proxy:forward");
PROXY_STRNCPY(conf->forward->s->hostname, "*");
PROXY_STRNCPY(conf->forward->s->scheme, "*");
- conf->forward->hash = conf->forward->s->hash =
+ conf->forward->hash = conf->forward->s->hash =
ap_proxy_hashfunc(conf->forward->s->name, PROXY_HASHFUNC_DEFAULT);
/* Do not disable worker in case of errors */
conf->forward->s->status |= PROXY_WORKER_IGNORE_ERRORS;
PROXY_STRNCPY(reverse->s->name, "proxy:reverse");
PROXY_STRNCPY(reverse->s->hostname, "*");
PROXY_STRNCPY(reverse->s->scheme, "*");
- reverse->hash = reverse->s->hash =
+ reverse->hash = reverse->s->hash =
ap_proxy_hashfunc(reverse->s->name, PROXY_HASHFUNC_DEFAULT);
/* Do not disable worker in case of errors */
reverse->s->status |= PROXY_WORKER_IGNORE_ERRORS;
*/
#ifndef MOD_PROXY_H
-#define MOD_PROXY_H
+#define MOD_PROXY_H
/**
* @file mod_proxy.h
} proxy_status; /* Status display options */
apr_sockaddr_t *source_address;
apr_global_mutex_t *mutex; /* global lock (needed??) */
-
+
int req_set:1;
int viaopt_set:1;
int recv_buffer_size_set:1;
void *context; /* general purpose storage */
apr_status_t (*reset)(proxy_balancer *balancer, server_rec *s);
apr_status_t (*age)(proxy_balancer *balancer, server_rec *s);
- apr_status_t (*updatelbstatus)(proxy_balancer *balancer, proxy_worker *elected, server_rec *s);
+ apr_status_t (*updatelbstatus)(proxy_balancer *balancer, proxy_worker *elected, server_rec *s);
};
#define PROXY_THREAD_LOCK(x) apr_thread_mutex_lock((x)->mutex)
/* hooks */
-/* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and
+/* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and
* PROXY_DECLARE_DATA with appropriate export and import tags for the platform
*/
#if !defined(WIN32)
#define PROXY_OPTIONAL_HOOK(name,fn,pre,succ,order) \
APR_OPTIONAL_HOOK(proxy,name,fn,pre,succ,order)
-APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, scheme_handler, (request_rec *r,
- proxy_worker *worker, proxy_server_conf *conf, char *url,
+APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, scheme_handler, (request_rec *r,
+ proxy_worker *worker, proxy_server_conf *conf, char *url,
const char *proxyhost, apr_port_t proxyport))
-APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, canon_handler, (request_rec *r,
+APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, canon_handler, (request_rec *r,
char *url))
APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, create_req, (request_rec *r, request_rec *pr))
-APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, fixups, (request_rec *r))
+APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, fixups, (request_rec *r))
/**
* pre request hook.
APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, pre_request, (proxy_worker **worker,
proxy_balancer **balancer,
request_rec *r,
- proxy_server_conf *conf, char **url))
+ proxy_server_conf *conf, char **url))
/**
* post request hook.
* It is called after request for updating runtime balancer status.
const char *url);
/**
* Define and Allocate space for the worker to proxy configuration
- * @param p memory pool to allocate worker from
+ * @param p memory pool to allocate worker from
* @param worker the new worker
* @param balancer the balancer that the worker belongs to
* @param conf current proxy server configuration
/**
* Share a defined proxy worker via shm
- * @param worker worker to be shared
+ * @param worker worker to be shared
* @param shm location of shared info
* @param i index into shm
* @return APR_SUCCESS or error code
/**
* Define and Allocate space for the balancer to proxy configuration
- * @param p memory pool to allocate balancer from
+ * @param p memory pool to allocate balancer from
* @param balancer the new balancer
* @param conf current proxy server configuration
* @param url url containing balancer name
* @param r current request
* @param conf current proxy server configuration
* @param url request url that balancer can rewrite.
- * @return OK or HTTP_XXX error
+ * @return OK or HTTP_XXX error
* @note It calls balancer pre_request hook if the url starts with balancer://
* The balancer then rewrites the url to particular worker, like http://host:port
*/
* @param conf current proxy server configuration
* @return OK or HTTP_XXX error
* @note Whenever the pre_request is called, the post_request has to be
- * called too.
+ * called too.
*/
PROXY_DECLARE(int) ap_proxy_post_request(proxy_worker *worker,
proxy_balancer *balancer,
* @param server_portstr Via headers server port
* @param server_portstr_size size of the server_portstr buffer
* @return OK or HTTP_XXX error
- */
+ */
PROXY_DECLARE(int) ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
proxy_server_conf *conf,
proxy_worker *worker,
* @param s current server record
* @return OK or HTTP_XXX error
* @note The connection will be closed if conn->close_on_release is set
- */
+ */
PROXY_DECLARE(int) ap_proxy_release_connection(const char *proxy_function,
proxy_conn_rec *conn,
server_rec *s);
* @return OK or HTTP_XXX error
* @note In case the socket already exists for conn, just check the link
* status.
- */
+ */
PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
proxy_conn_rec *conn,
proxy_worker *worker,
* Register our mutex type before the config is read so we
* can adjust the mutex settings using the Mutex directive.
*/
-static int balancer_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
+static int balancer_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
apr_pool_t *ptemp)
{
apr_status_t rv;
-
+
rv = ap_mutex_register(pconf, balancer_mutex_type, NULL,
APR_LOCK_DEFAULT, 0);
if (rv != APR_SUCCESS) {
return rv;
}
-
+
return OK;
}
int i;
int checking_standby;
int checked_standby;
-
+
proxy_worker **workers;
checking_standby = checked_standby = 0;
/* Step 3: force recovery */
force_recovery(*balancer, r->server);
-
+
/* Step 3.5: Update member list for the balancer */
/* TODO: Implement as provider! */
/* proxy_update_members(balancer, r, conf); */
* the process. */
apr_uuid_get(&uuid);
apr_uuid_format(balancer_nonce, &uuid);
-
-
+
/*
* Get worker slotmem setup
*/
proxy_balancer *balancer;
sconf = s->module_config;
conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
-
+
/* Initialize shared scoreboard data */
balancer = (proxy_balancer *)conf->balancers->elts;
for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
proxy_worker **workers;
proxy_worker *worker;
ap_slotmem_instance_t *new = NULL;
-
+
balancer->max_workers = balancer->workers->nelts + balancer->growth;
balancer->sname = ap_md5(pconf, (const unsigned char *)balancer->name);
balancer->sname);
return HTTP_INTERNAL_SERVER_ERROR;
}
-
+
apr_pool_cleanup_register(pconf, (void *)s, lock_remove,
apr_pool_cleanup_null);
-
+
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "Doing create: %s (%s), %d, %d",
balancer->name, balancer->sname,
(int)sizeof(proxy_worker_shared),
if ((rv = storage->grab(balancer->slot, &index)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, "slotmem_grab failed");
return !OK;
-
+
}
if ((rv = storage->dptr(balancer->slot, index, (void *)&shm)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, "slotmem_dptr failed");
}
s = s->next;
}
-
+
return OK;
}
return HTTP_BAD_REQUEST;
}
}
-
+
/* Check that the supplied nonce matches this server's nonce;
* otherwise ignore all parameters, to prevent a CSRF attack. */
if (*balancer_nonce &&
- ((name = apr_table_get(params, "nonce")) == NULL
+ ((name = apr_table_get(params, "nonce")) == NULL
|| strcmp(balancer_nonce, name) != 0)) {
apr_table_clear(params);
}
ap_rvputs(r, "<tr>\n<td><a href=\"", r->uri, "?b=",
balancer->name + sizeof(BALANCER_PREFIX) - 1, "&w=",
ap_escape_uri(r->pool, worker->s->name),
- "&nonce=", balancer_nonce,
+ "&nonce=", balancer_nonce,
"\">", NULL);
ap_rvputs(r, worker->s->name, "</a></td>", NULL);
ap_rvputs(r, "<td>", ap_escape_html(r->pool, worker->s->route),
ap_rvputs(r, "<input type=hidden name=\"b\" ", NULL);
ap_rvputs(r, "value=\"", bsel->name + sizeof(BALANCER_PREFIX) - 1,
"\">\n", NULL);
- ap_rvputs(r, "<input type=hidden name=\"nonce\" value=\"",
+ ap_rvputs(r, "<input type=hidden name=\"nonce\" value=\"",
balancer_nonce, "\">\n", NULL);
ap_rvputs(r, "</form>\n", NULL);
ap_rputs("<hr />\n", r);
void *sconf = s->module_config;
proxy_server_conf *conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
apr_status_t rv;
-
+
balancer = (proxy_balancer *)conf->balancers->elts;
for (i = 0; i < conf->balancers->nelts; i++) {
apr_size_t size;
}
/* Re-open the mutex for the child. */
- rv = apr_global_mutex_child_init(&(balancer->mutex),
+ rv = apr_global_mutex_child_init(&(balancer->mutex),
apr_global_mutex_lockfile(balancer->mutex),
p);
if (rv != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
- "Failed to reopen mutex %: %s in child",
+ ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
+ "Failed to reopen mutex %: %s in child",
balancer->name, balancer_mutex_type);
exit(1); /* Ugly, but what else? */
- }
+ }
/* now attach */
storage->attach(&(balancer->slot), balancer->sname, &size, &num, p);
/* urlpart (l3) assuredly starts with its own '/' */
if ((*worker)->s->name[l2 - 1] == '/')
--l2;
- if (l1 >= l2 + l3
+ if (l1 >= l2 + l3
&& strncasecmp((*worker)->s->name, url, l2) == 0
&& strncmp(urlpart, url + l2, l3) == 0) {
u = apr_pstrcat(r->pool, ent[i].fake, &url[l2 + l3],
proxy_balancer *balancer;
char *c, *uri = apr_pstrdup(p, url);
int i;
-
+
c = strchr(uri, ':');
if (c == NULL || c[1] != '/' || c[2] != '/' || c[3] == '\0') {
return NULL;
/* remove path from uri */
if ((q = strchr(c + 3, '/')))
*q = '\0';
-
+
ap_str_tolower(uri);
*balancer = apr_array_push(conf->balancers);
memset(*balancer, 0, sizeof(proxy_balancer));
const char *c;
char *url_copy;
int i;
-
+
c = ap_strchr_c(url, ':');
if (c == NULL || c[1] != '/' || c[2] != '/' || c[3] == '\0') {
return NULL;
}
-
+
url_copy = apr_pstrdup(p, url);
url_length = strlen(url);
-
+
/*
* We need to find the start of the path and
* therefore we know the length of the scheme://hostname/
* a minimum matching of length min_match such that
* scheme://hostname[:port] matches between worker and url.
*/
-
+
if (balancer) {
proxy_worker **workers = (proxy_worker **)balancer->workers->elts;
for (i = 0; i < balancer->workers->nelts; i++, workers++) {
max_worker = worker;
max_match = worker_name_length;
}
-
+
}
} else {
worker = (proxy_worker *)conf->workers->elts;
}
}
}
-
+
return max_worker;
}
int rv;
apr_uri_t uri;
proxy_worker_shared *wstatus;
-
+
rv = apr_uri_parse(p, url, &uri);
-
+
if (rv != APR_SUCCESS) {
return "Unable to parse URL";
}
if (!uri.hostname || !uri.scheme) {
return "URL must be absolute!";
}
-
+
ap_str_tolower(uri.hostname);
ap_str_tolower(uri.scheme);
/*
* Workers can be associated w/ balancers or on their
* own; ie: the generic reverse-proxy or a worker
- * in a simple ProxyPass statement. eg:
+ * in a simple ProxyPass statement. eg:
*
* ProxyPass / http://www.example.com
*
/* we need to allocate space here */
*worker = apr_palloc(p, sizeof(proxy_worker));
}
-
+
memset(*worker, 0, sizeof(proxy_worker));
/* right here we just want to tuck away the worker info.
* if called during config, we don't have shm setup yet,
wstatus = apr_palloc(p, sizeof(proxy_worker_shared));
#endif
memset(wstatus, 0, sizeof(proxy_worker_shared));
-
-
+
PROXY_STRNCPY(wstatus->name, apr_uri_unparse(p, &uri, APR_URI_UNP_REVEALPASSWORD));
PROXY_STRNCPY(wstatus->scheme, uri.scheme);
PROXY_STRNCPY(wstatus->hostname, uri.hostname);
wstatus->flush_wait = PROXY_FLUSH_WAIT;
wstatus->smax = -1;
wstatus->hash = ap_proxy_hashfunc(wstatus->name, PROXY_HASHFUNC_DEFAULT);
-
+
(*worker)->hash = wstatus->hash;
(*worker)->context = NULL;
(*worker)->cp = NULL;
(*worker)->mutex = NULL;
(*worker)->balancer = balancer;
(*worker)->s = wstatus;
-
+
return NULL;
}
/* What if local is init'ed and shm isn't?? Even possible? */
if (worker->local_status & PROXY_WORKER_INITIALIZED) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
- "worker %s local already initialized", worker->s->name);
+ "worker %s local already initialized", worker->s->name);
}
else {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
"can not create connection pool");
return APR_EGENERAL;
- }
+ }
if (worker->mutex == NULL) {
rv = apr_thread_mutex_create(&(worker->mutex), APR_THREAD_MUTEX_DEFAULT, p);
proxy_server_conf *conf, char **url)
{
int access_status;
-
+
access_status = proxy_run_pre_request(worker, balancer, r, conf, url);
if (access_status == DECLINED && *balancer == NULL) {
*worker = ap_proxy_get_worker(r->pool, NULL, conf, *url);
ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
"proxy: %s: found worker %s for %s",
(*worker)->s->scheme, (*worker)->s->name, *url);
-
+
*balancer = NULL;
access_status = OK;
}
/* TODO: recycle direct worker */
}
}
-
+
return access_status;
}
apr_status_t rv;
int connected = 0;
int loglevel;
-
+
while (backend_addr && !connected) {
if ((rv = apr_socket_create(newsock, backend_addr->family,
SOCK_STREAM, 0, r->pool)) != APR_SUCCESS) {
backend_addr = backend_addr->next;
continue;
}
-
+
if (conf->recv_buffer_size > 0 &&
(rv = apr_socket_opt_set(*newsock, APR_SO_RCVBUF,
conf->recv_buffer_size))) {
"apr_socket_opt_set(SO_RCVBUF): Failed to set "
"ProxyReceiveBufferSize, using default");
}
-
+
rv = apr_socket_opt_set(*newsock, APR_TCP_NODELAY, 1);
if (rv != APR_SUCCESS && rv != APR_ENOTIMPL) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
"apr_socket_opt_set(APR_TCP_NODELAY): "
"Failed to set");
}
-
+
/* Set a timeout on the socket */
if (conf->timeout_set) {
apr_socket_timeout_set(*newsock, conf->timeout);
else {
apr_socket_timeout_set(*newsock, r->server->timeout);
}
-
+
ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
"proxy: %s: fam %d socket created to connect to %s",
proxy_function, backend_addr->family, backend_name);
-
+
if (conf->source_address) {
rv = apr_socket_bind(*newsock, conf->source_address);
if (rv != APR_SUCCESS) {
proxy_function);
}
}
-
+
/* make the connection out of the socket */
rv = apr_socket_connect(*newsock, backend_addr);
-
+
/* if an error occurred, loop round and try again */
if (rv != APR_SUCCESS) {
apr_socket_close(*newsock);
*
* TODO: Handle this much better...
*/
- if (!conn->hostname || !worker->s->is_address_reusable ||
+ if (!conn->hostname || !worker->s->is_address_reusable ||
worker->s->disablereuse ||
(r->connection->keepalives &&
(r->proxyreq == PROXYREQ_PROXY || r->proxyreq == PROXYREQ_REVERSE) &&
rv = apr_socket_bind(newsock, local_addr);
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
- "proxy: %s: failed to bind socket to local address",
+ "proxy: %s: failed to bind socket to local address",
proxy_function);
}
}
{
if (!sbh)
return -1;
-
+
return update_child_status_internal(sbh->child_num, sbh->thread_num,
status, c, NULL);
}