summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/base.h13
-rw-r--r--src/connections-glue.c2
-rw-r--r--src/connections.c20
-rw-r--r--src/http-header-glue.c10
-rw-r--r--src/http_header.c24
-rw-r--r--src/mod_magnet.c4
-rw-r--r--src/mod_proxy.c4
-rw-r--r--src/mod_webdav.c7
-rw-r--r--src/response.c4
-rw-r--r--src/t/test_request.c19
10 files changed, 50 insertions, 57 deletions
diff --git a/src/base.h b/src/base.h
index 5c9efcdc..db6bdee5 100644
--- a/src/base.h
+++ b/src/base.h
@@ -36,7 +36,7 @@ typedef struct {
buffer *http_host; /* not alloced */
unsigned int htags; /* bitfield of flagged headers present in request */
- array *headers;
+ array headers;
/* CONTENT */
off_t content_length; /* returned by strtoll() */
@@ -49,7 +49,7 @@ typedef struct {
typedef struct {
off_t content_length;
unsigned int htags; /* bitfield of flagged headers present in response */
- array *headers;
+ array headers;
int send_chunked;
} response;
@@ -243,20 +243,19 @@ struct connection {
off_t bytes_read; /* used by mod_accesslog, mod_rrd */
off_t bytes_header;
- int http_status;
-
sock_addr dst_addr;
buffer *dst_addr_buf;
/* request */
+ int http_status;
+ uint32_t header_len;
+
request request;
request_uri uri;
physical physical;
response response;
- uint32_t header_len;
-
- array *environment; /* used to pass lighttpd internal stuff to the FastCGI/CGI apps, setenv does that */
+ array environment; /* used to pass lighttpd internal stuff to the FastCGI/CGI apps, setenv does that */
unsigned int mode; /* DIRECT (0) or plugin id */
int async_callback;
diff --git a/src/connections-glue.c b/src/connections-glue.c
index 60fd36fb..11c186e4 100644
--- a/src/connections-glue.c
+++ b/src/connections-glue.c
@@ -503,6 +503,6 @@ void connection_response_reset(server *srv, connection *con) {
buffer_clear(con->physical.etag);
}
con->response.htags = 0;
- array_reset_data_strings(con->response.headers);
+ array_reset_data_strings(&con->response.headers);
http_response_body_clear(con, 0);
}
diff --git a/src/connections.c b/src/connections.c
index e75b48ca..d7408542 100644
--- a/src/connections.c
+++ b/src/connections.c
@@ -263,7 +263,7 @@ static void connection_handle_errdoc_init(connection *con) {
buffer_reset(con->physical.path);
con->response.htags = 0;
- array_reset_data_strings(con->response.headers);
+ array_reset_data_strings(&con->response.headers);
http_response_body_clear(con, 0);
if (NULL != www_auth) {
@@ -575,10 +575,6 @@ static connection *connection_init(server *srv) {
con->read_queue = chunkqueue_init();
con->request_content_queue = chunkqueue_init();
- con->request.headers = array_init();
- con->response.headers = array_init();
- con->environment = array_init();
-
/* init plugin specific connection structures */
con->plugin_ctx = calloc(1, (srv->plugins.used + 1) * sizeof(void *));
@@ -601,9 +597,9 @@ void connections_free(server *srv) {
chunkqueue_free(con->write_queue);
chunkqueue_free(con->read_queue);
chunkqueue_free(con->request_content_queue);
- array_free(con->request.headers);
- array_free(con->response.headers);
- array_free(con->environment);
+ array_free_data(&con->request.headers);
+ array_free_data(&con->response.headers);
+ array_free_data(&con->environment);
#define CLEAN(x) \
buffer_free(con->x);
@@ -680,12 +676,12 @@ static int connection_reset(server *srv, connection *con) {
con->request.htags = 0;
if (con->header_len <= BUFFER_MAX_REUSE_SIZE)
- con->request.headers->used = 0;
+ con->request.headers.used = 0;
else
- array_reset_data_strings(con->request.headers);
+ array_reset_data_strings(&con->request.headers);
con->header_len = 0;
- if (0 != con->environment->used)
- array_reset_data_strings(con->environment);
+ if (0 != con->environment.used)
+ array_reset_data_strings(&con->environment);
chunkqueue_reset(con->request_content_queue);
diff --git a/src/http-header-glue.c b/src/http-header-glue.c
index 8c175c01..7e36d8dd 100644
--- a/src/http-header-glue.c
+++ b/src/http-header-glue.c
@@ -887,7 +887,7 @@ static handler_t http_response_process_local_redir(server *srv, connection *con,
&& vb->ptr[ulen] != '?'))
&& 0 == blen
&& !(con->response.htags & HTTP_HEADER_STATUS) /*no "Status" or NPH response*/
- && 1 == con->response.headers->used) {
+ && 1 == con->response.headers.used) {
if (++con->loops_per_request > 5) {
log_error_write(srv, __FILE__, __LINE__, "sb",
"too many internal loops while processing request:",
@@ -1530,8 +1530,8 @@ int http_cgi_headers (server *srv, connection *con, http_cgi_opts *opts, http_cg
li_utostrn(buf, sizeof(buf), sock_addr_get_port(&con->dst_addr));
rc |= cb(vdata, CONST_STR_LEN("REMOTE_PORT"), buf, strlen(buf));
- for (n = 0; n < con->request.headers->used; n++) {
- data_string *ds = (data_string *)con->request.headers->data[n];
+ for (n = 0; n < con->request.headers.used; n++) {
+ data_string *ds = (data_string *)con->request.headers.data[n];
if (!buffer_string_is_empty(&ds->value) && !buffer_is_empty(&ds->key)) {
/* Security: Do not emit HTTP_PROXY in environment.
* Some executables use HTTP_PROXY to configure
@@ -1549,8 +1549,8 @@ int http_cgi_headers (server *srv, connection *con, http_cgi_opts *opts, http_cg
srv->request_env(srv, con);
- for (n = 0; n < con->environment->used; n++) {
- data_string *ds = (data_string *)con->environment->data[n];
+ for (n = 0; n < con->environment.used; n++) {
+ data_string *ds = (data_string *)con->environment.data[n];
if (!buffer_is_empty(&ds->value) && !buffer_is_empty(&ds->key)) {
buffer_copy_string_encoded_cgi_varnames(srv->tmp_buf,
CONST_BUF_LEN(&ds->key), 0);
diff --git a/src/http_header.c b/src/http_header.c
index b140530f..747ed0d2 100644
--- a/src/http_header.c
+++ b/src/http_header.c
@@ -100,14 +100,14 @@ static inline buffer * http_header_generic_get_ifnotempty(const array * const a,
buffer * http_header_response_get(connection *con, enum http_header_e id, const char *k, size_t klen) {
return (id <= HTTP_HEADER_OTHER || (con->response.htags & id))
- ? http_header_generic_get_ifnotempty(con->response.headers, k, klen)
+ ? http_header_generic_get_ifnotempty(&con->response.headers, k, klen)
: NULL;
}
void http_header_response_unset(connection *con, enum http_header_e id, const char *k, size_t klen) {
if (id <= HTTP_HEADER_OTHER || (con->response.htags & id)) {
if (id > HTTP_HEADER_OTHER) con->response.htags &= ~id;
- array_set_key_value(con->response.headers, k, klen, CONST_STR_LEN(""));
+ array_set_key_value(&con->response.headers, k, klen, CONST_STR_LEN(""));
}
}
@@ -118,20 +118,20 @@ void http_header_response_set(connection *con, enum http_header_e id, const char
*/
if (id > HTTP_HEADER_OTHER)
(vlen) ? (con->response.htags |= id) : (con->response.htags &= ~id);
- array_set_key_value(con->response.headers, k, klen, v, vlen);
+ array_set_key_value(&con->response.headers, k, klen, v, vlen);
}
void http_header_response_append(connection *con, enum http_header_e id, const char *k, size_t klen, const char *v, size_t vlen) {
if (0 == vlen) return;
if (id > HTTP_HEADER_OTHER) con->response.htags |= id;
- buffer * const vb = array_get_buf_ptr(con->response.headers, k, klen);
+ buffer * const vb = array_get_buf_ptr(&con->response.headers, k, klen);
http_header_token_append(vb, v, vlen);
}
void http_header_response_insert(connection *con, enum http_header_e id, const char *k, size_t klen, const char *v, size_t vlen) {
if (0 == vlen) return;
if (id > HTTP_HEADER_OTHER) con->response.htags |= id;
- buffer * const vb = array_get_buf_ptr(con->response.headers, k, klen);
+ buffer * const vb = array_get_buf_ptr(&con->response.headers, k, klen);
if (!buffer_string_is_empty(vb)) { /* append value */
buffer_append_string_len(vb, CONST_STR_LEN("\r\n"));
buffer_append_string_len(vb, k, klen);
@@ -143,14 +143,14 @@ void http_header_response_insert(connection *con, enum http_header_e id, const c
buffer * http_header_request_get(connection *con, enum http_header_e id, const char *k, size_t klen) {
return (id <= HTTP_HEADER_OTHER || (con->request.htags & id))
- ? http_header_generic_get_ifnotempty(con->request.headers, k, klen)
+ ? http_header_generic_get_ifnotempty(&con->request.headers, k, klen)
: NULL;
}
void http_header_request_unset(connection *con, enum http_header_e id, const char *k, size_t klen) {
if (id <= HTTP_HEADER_OTHER || (con->request.htags & id)) {
if (id > HTTP_HEADER_OTHER) con->request.htags &= ~id;
- array_set_key_value(con->request.headers, k, klen, CONST_STR_LEN(""));
+ array_set_key_value(&con->request.headers, k, klen, CONST_STR_LEN(""));
}
}
@@ -161,28 +161,28 @@ void http_header_request_set(connection *con, enum http_header_e id, const char
*/
if (id > HTTP_HEADER_OTHER)
(vlen) ? (con->request.htags |= id) : (con->request.htags &= ~id);
- array_set_key_value(con->request.headers, k, klen, v, vlen);
+ array_set_key_value(&con->request.headers, k, klen, v, vlen);
}
void http_header_request_append(connection *con, enum http_header_e id, const char *k, size_t klen, const char *v, size_t vlen) {
if (0 == vlen) return;
if (id > HTTP_HEADER_OTHER) con->request.htags |= id;
- buffer * const vb = array_get_buf_ptr(con->request.headers, k, klen);
+ buffer * const vb = array_get_buf_ptr(&con->request.headers, k, klen);
http_header_token_append(vb, v, vlen);
}
buffer * http_header_env_get(connection *con, const char *k, size_t klen) {
- return http_header_generic_get_ifnotempty(con->environment, k, klen);
+ return http_header_generic_get_ifnotempty(&con->environment, k, klen);
}
void http_header_env_set(connection *con, const char *k, size_t klen, const char *v, size_t vlen) {
- array_set_key_value(con->environment, k, klen, v, vlen);
+ array_set_key_value(&con->environment, k, klen, v, vlen);
}
void http_header_env_append(connection *con, const char *k, size_t klen, const char *v, size_t vlen) {
/*if (0 == vlen) return;*//* skip check; permit env var w/ blank value */
- buffer * const vb = array_get_buf_ptr(con->environment, k, klen);
+ buffer * const vb = array_get_buf_ptr(&con->environment, k, klen);
if (0 == vlen) return;
http_header_token_append(vb, v, vlen);
}
diff --git a/src/mod_magnet.c b/src/mod_magnet.c
index 2d16d611..53d32f56 100644
--- a/src/mod_magnet.c
+++ b/src/mod_magnet.c
@@ -437,7 +437,7 @@ static int magnet_reqhdr_get(lua_State *L) {
static int magnet_reqhdr_pairs(lua_State *L) {
connection *con = magnet_get_connection(L);
- return magnet_array_pairs(L, con->request.headers);
+ return magnet_array_pairs(L, &con->request.headers);
}
static int magnet_status_get(lua_State *L) {
@@ -688,7 +688,7 @@ static int magnet_cgi_set(lua_State *L) {
static int magnet_cgi_pairs(lua_State *L) {
connection *con = magnet_get_connection(L);
- return magnet_array_pairs(L, con->environment);
+ return magnet_array_pairs(L, &con->environment);
}
diff --git a/src/mod_proxy.c b/src/mod_proxy.c
index 0fe8e619..ad9b28b1 100644
--- a/src/mod_proxy.c
+++ b/src/mod_proxy.c
@@ -767,8 +767,8 @@ static handler_t proxy_create_env(server *srv, gw_handler_ctx *gwhctx) {
}
/* request header */
- for (size_t i = 0, used = con->request.headers->used; i < used; ++i) {
- data_string *ds = (data_string *)con->request.headers->data[i];
+ for (size_t i = 0, used = con->request.headers.used; i < used; ++i) {
+ data_string *ds = (data_string *)con->request.headers.data[i];
const size_t klen = buffer_string_length(&ds->key);
size_t vlen;
switch (klen) {
diff --git a/src/mod_webdav.c b/src/mod_webdav.c
index 29e51eb0..ffb46f24 100644
--- a/src/mod_webdav.c
+++ b/src/mod_webdav.c
@@ -3566,8 +3566,7 @@ webdav_has_lock (connection * const con,
/* XXX: maybe add config switch to require that authentication occurred? */
buffer owner = { NULL, 0, 0 };/*owner (not authenticated)(auth_user unset)*/
const data_string * const authn_user = (const data_string *)
- array_get_element_klen(con->environment,
- CONST_STR_LEN("REMOTE_USER"));
+ array_get_element_klen(&con->environment, CONST_STR_LEN("REMOTE_USER"));
cbdata.authn_user = authn_user ? &authn_user->value : &owner;
const buffer * const h =
@@ -5170,7 +5169,7 @@ mod_webdav_lock (connection * const con, const plugin_config * const pconf)
/* XXX: maybe add config switch to require that authentication occurred? */
buffer owner = { NULL, 0, 0 };/*owner (not authenticated)(auth_user unset)*/
const data_string * const authn_user = (const data_string *)
- array_get_element_klen(con->environment, CONST_STR_LEN("REMOTE_USER"));
+ array_get_element_klen(&con->environment, CONST_STR_LEN("REMOTE_USER"));
/* future: make max timeout configurable (e.g. pconf->lock_timeout_max)
*
@@ -5465,7 +5464,7 @@ mod_webdav_unlock (connection * const con, const plugin_config * const pconf)
buffer owner = { NULL, 0, 0 };/*owner (not authenticated)(auth_user unset)*/
const data_string * const authn_user = (const data_string *)
- array_get_element_klen(con->environment, CONST_STR_LEN("REMOTE_USER"));
+ array_get_element_klen(&con->environment, CONST_STR_LEN("REMOTE_USER"));
webdav_lockdata lockdata = {
{ h->ptr+1, h->used-2, 0 }, /* locktoken (remove < > around token) */
diff --git a/src/response.c b/src/response.c
index 32997794..4328cfc3 100644
--- a/src/response.c
+++ b/src/response.c
@@ -82,8 +82,8 @@ int http_response_write_header(server *srv, connection *con) {
}
/* add all headers */
- for (size_t i = 0; i < con->response.headers->used; ++i) {
- const data_string * const ds = (data_string *)con->response.headers->data[i];
+ for (size_t i = 0; i < con->response.headers.used; ++i) {
+ const data_string * const ds = (data_string *)con->response.headers.data[i];
if (buffer_string_is_empty(&ds->value)) continue;
if (buffer_string_is_empty(&ds->key)) continue;
diff --git a/src/t/test_request.c b/src/t/test_request.c
index a84d7052..9d75da52 100644
--- a/src/t/test_request.c
+++ b/src/t/test_request.c
@@ -24,7 +24,7 @@ static void test_request_connection_reset(connection *con)
buffer_reset(con->request.request);
buffer_reset(con->request.orig_uri);
buffer_reset(con->request.uri);
- array_reset_data_strings(con->request.headers);
+ array_reset_data_strings(&con->request.headers);
}
static void run_http_request_parse(connection *con, int line, int status, const char *desc, const char *req, size_t reqlen)
@@ -330,7 +330,7 @@ static void test_request_http_request_parse(connection *con)
" baz\r\n"
"\r\n"));
ds = (data_string *)
- array_get_element_klen(con->request.headers, CONST_STR_LEN("Location"));
+ array_get_element_klen(&con->request.headers, CONST_STR_LEN("Location"));
assert(ds
&& buffer_is_equal_string(&ds->value,
CONST_STR_LEN("foo, foobar baz")));
@@ -343,7 +343,7 @@ static void test_request_http_request_parse(connection *con)
" baz\r\n"
"\r\n"));
ds = (data_string *)
- array_get_element_klen(con->request.headers, CONST_STR_LEN("Location"));
+ array_get_element_klen(&con->request.headers, CONST_STR_LEN("Location"));
assert(ds
&& buffer_is_equal_string(&ds->value, CONST_STR_LEN("foobar baz")));
@@ -355,7 +355,7 @@ static void test_request_http_request_parse(connection *con)
" baz\r\n"
"\r\n"));
ds = (data_string *)
- array_get_element_klen(con->request.headers, CONST_STR_LEN("Location"));
+ array_get_element_klen(&con->request.headers, CONST_STR_LEN("Location"));
assert(ds
&& buffer_is_equal_string(&ds->value, CONST_STR_LEN("foobar baz")));
@@ -432,7 +432,7 @@ static void test_request_http_request_parse(connection *con)
"ABC:foo\r\n"
"\r\n"));
ds = (data_string *)
- array_get_element_klen(con->request.headers, CONST_STR_LEN("ABC"));
+ array_get_element_klen(&con->request.headers, CONST_STR_LEN("ABC"));
assert(ds && buffer_is_equal_string(&ds->value, CONST_STR_LEN("foo")));
run_http_request_parse(con, __LINE__, 0,
@@ -442,7 +442,7 @@ static void test_request_http_request_parse(connection *con)
" bc\r\n"
"\r\n"));
ds = (data_string *)
- array_get_element_klen(con->request.headers, CONST_STR_LEN("ABC"));
+ array_get_element_klen(&con->request.headers, CONST_STR_LEN("ABC"));
assert(ds && buffer_is_equal_string(&ds->value, CONST_STR_LEN("foo bc")));
run_http_request_parse(con, __LINE__, 411,
@@ -545,7 +545,7 @@ static void test_request_http_request_parse(connection *con)
"Connection: close\r\n"
"\r\n"));
ds = (data_string *)
- array_get_element_klen(con->request.headers, CONST_STR_LEN("Host"));
+ array_get_element_klen(&con->request.headers, CONST_STR_LEN("Host"));
assert(ds && buffer_is_equal_string(&ds->value, CONST_STR_LEN("zzz.example.org")));
run_http_request_parse(con, __LINE__, 0,
@@ -555,7 +555,7 @@ static void test_request_http_request_parse(connection *con)
"Connection: close\r\n"
"\r\n"));
ds = (data_string *)
- array_get_element_klen(con->request.headers, CONST_STR_LEN("Host"));
+ array_get_element_klen(&con->request.headers, CONST_STR_LEN("Host"));
assert(ds && buffer_is_equal_string(&ds->value, CONST_STR_LEN("zzz.example.org")));
run_http_request_parse(con, __LINE__, 400,
@@ -591,7 +591,6 @@ int main (void)
con.request.request = buffer_init();
con.request.orig_uri = buffer_init();
con.request.uri = buffer_init();
- con.request.headers = array_init();
con.conf.allow_http11 = 1;
con.conf.http_parseopts = HTTP_PARSEOPT_HEADER_STRICT
| HTTP_PARSEOPT_HOST_STRICT
@@ -603,7 +602,7 @@ int main (void)
buffer_free(con.request.request);
buffer_free(con.request.orig_uri);
buffer_free(con.request.uri);
- array_free(con.request.headers);
+ array_free_data(&con.request.headers);
log_error_st_free(srv.errh);