Project

General

Profile

Feature #1545 » lighttpd-1.4.18-extforward.patch

spillgroup, 2008-01-31 09:25

View differences:

./src/mod_extforward.c 2007-12-21 15:09:35.000000000 +0100
typedef struct {
array *forwarder;
array *headers;
} plugin_config;
typedef struct {
......
if (!s) continue;
array_free(s->forwarder);
array_free(s->headers);
free(s);
}
......
size_t i = 0;
config_values_t cv[] = {
{ "extforward.forwarder", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 0 */
{ "extforward.forwarder", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 0 */
{ "extforward.headers", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 1 */
{ NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
};
......
plugin_config *s;
s = calloc(1, sizeof(plugin_config));
s->forwarder = array_init();
s->forwarder = array_init();
s->headers = array_init();
cv[0].destination = s->forwarder;
cv[1].destination = s->headers;
p->config_storage[i] = s;
......
plugin_config *s = p->config_storage[0];
PATCH(forwarder);
PATCH(headers);
/* skip the first, the global context */
for (i = 1; i < srv->config_context->used; i++) {
......
if (buffer_is_equal_string(du->key, CONST_STR_LEN("extforward.forwarder"))) {
PATCH(forwarder);
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("extforward.headers"))) {
PATCH(headers);
}
}
}
......
URIHANDLER_FUNC(mod_extforward_uri_handler) {
plugin_data *p = p_d;
data_string *forwarded = NULL;
data_string *ds;
size_t k;
#ifdef HAVE_IPV6
char b2[INET6_ADDRSTRLEN + 1];
struct addrinfo *addrlist = NULL;
......
#ifdef HAVE_IPV6
#endif
if (!con->request.headers) return HANDLER_GO_ON;
mod_extforward_patch_connection(srv, con, p);
......
"-- mod_extforward_uri_handler called");
}
/*************************************************************************************************/
// p->conf.headers
forwarded = NULL;
for(k=0; k<p->conf.headers->used; k++) {
ds = (data_string *)p->conf.headers->data[k];
forwarded = (data_string*)array_get_element(con->request.headers, ds->value->ptr);
if(NULL != forwarded) {
break;
}
}
if(NULL == forwarded) {
if ((NULL == (forwarded = (data_string *) array_get_element(con->request.headers,"X-Forwarded-For")) &&
NULL == (forwarded = (data_string *) array_get_element(con->request.headers, "Forwarded-For"))) ||
(p->conf.headers->used > 0)) {
if (con->conf.log_request_handling) {
log_error_write(srv, __FILE__, __LINE__, "s", "no forward header found, skipping");
}
return HANDLER_GO_ON;
}
}
/*************************************************************************************************/
/*
if ((NULL == (forwarded = (data_string *) array_get_element(con->request.headers,"X-Forwarded-For")) &&
NULL == (forwarded = (data_string *) array_get_element(con->request.headers, "Forwarded-For")))) {
......
return HANDLER_GO_ON;
}
*/
/* if the remote ip itself is not trusted , then do nothing */
#ifdef HAVE_IPV6
dst_addr_str = inet_ntop(con->dst_addr.plain.sa_family,
......
/* Testing shows that multiple headers and multiple values in one header
come in _reverse_ order. So the first one we get is the last one in the request. */
for (i = forward_array->used - 1; i >= 0; i--) {
data_string *ds = (data_string *) forward_array->data[i];
ds = (data_string *) forward_array->data[i];
if (ds) {
real_remote_addr = ds->value->ptr;
break;
./src/response.c 2007-12-31 15:22:56.000000000 +0100
if (con->mode == DIRECT && con->physical.path->used == 0) {
char *qstr;
size_t i;
for(i = 0; i < COMP_LAST_ELEMENT; ++i) {
con->conditional_is_valid[i] = 0;
}
/* we only come here when we have the parse the full request again
*
* a HANDLER_COMEBACK from mod_rewrite and mod_fastcgi might be a
(1-1/2)