From 8131e4396dcec676d8e7b681cee10003f1c4fefd Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Wed, 8 Jan 2020 23:35:39 -0500 Subject: [PATCH] [core] move addtl request-specific struct members --- src/base.h | 7 ----- src/configfile-glue.c | 16 +++++------ src/configfile.c | 2 +- src/connections.c | 44 +++++++++++++++--------------- src/gw_backend.c | 2 +- src/http-header-glue.c | 42 ++++++++++++++-------------- src/mod_accesslog.c | 6 ++-- src/mod_auth.c | 8 +++--- src/mod_authn_gssapi.c | 8 +++--- src/mod_authn_mysql.c | 2 +- src/mod_cml_lua.c | 2 +- src/mod_magnet.c | 4 +-- src/mod_mysql_vhost.c | 4 +-- src/mod_openssl.c | 4 +-- src/mod_proxy.c | 4 +-- src/mod_redirect.c | 11 ++++---- src/mod_rewrite.c | 15 +++++----- src/mod_simple_vhost.c | 4 +-- src/mod_ssi.c | 4 +-- src/mod_status.c | 16 +++++------ src/mod_vhostdb.c | 4 +-- src/mod_webdav.c | 8 +++--- src/request.c | 4 +-- src/request.h | 12 ++++++-- src/response.c | 62 +++++++++++++++++++++--------------------- src/t/test_request.c | 14 +++++----- 26 files changed, 156 insertions(+), 153 deletions(-) diff --git a/src/base.h b/src/base.h index efa152f8..518e359d 100644 --- a/src/base.h +++ b/src/base.h @@ -15,8 +15,6 @@ struct fdevents; /* declaration */ struct stat_cache; /* declaration */ -struct cond_cache_t; /* declaration */ -struct cond_match_t; /* declaration */ #define DIRECT 0 /* con->mode */ @@ -120,13 +118,8 @@ struct connection { void **plugin_ctx; /* plugin connection specific config */ request_config conf; - uint32_t conditional_is_valid; - struct cond_cache_t *cond_cache; - struct cond_match_t *cond_match; void *config_data_base; - const buffer *server_name; - buffer *server_name_buf; uint16_t proto_default_port; /* error-handler */ diff --git a/src/configfile-glue.c b/src/configfile-glue.c index 9f462c56..ea9d93f7 100644 --- a/src/configfile-glue.c +++ b/src/configfile-glue.c @@ -307,7 +307,7 @@ int config_plugin_values_init(server * const srv, void *p_d, const config_plugin __attribute_cold__ __attribute_noinline__ static void config_cond_result_trace(connection *con, const data_config *dc, int cached) { - cond_cache_t * const cache = &con->cond_cache[dc->context_ndx]; + cond_cache_t * const cache = &con->request.cond_cache[dc->context_ndx]; const char *msg; switch (cache->result) { case COND_RESULT_UNSET: msg = "unset"; break; @@ -338,7 +338,7 @@ static cond_result_t config_check_cond_nocache_calc(connection *con, const data_ } static cond_result_t config_check_cond_cached(connection *con, const data_config *dc, const int debug_cond) { - cond_cache_t * const cache = &con->cond_cache[dc->context_ndx]; + cond_cache_t * const cache = &con->request.cond_cache[dc->context_ndx]; if (COND_RESULT_UNSET != cache->result) { if (debug_cond) config_cond_result_trace(con, dc, 1); return cache->result; @@ -455,7 +455,7 @@ static cond_result_t config_check_cond_nocache(connection *con, const data_confi } } - if (!(con->conditional_is_valid & (1 << dc->comp))) { + if (!(con->request.conditional_is_valid & (1 << dc->comp))) { if (debug_cond) { log_error(con->conf.errh, __FILE__, __LINE__, "%d %s not available yet", dc->comp, @@ -591,7 +591,7 @@ static cond_result_t config_check_cond_nocache(connection *con, const data_confi } case CONFIG_COND_NOMATCH: case CONFIG_COND_MATCH: { - cond_match_t *cond_match = con->cond_match + dc->context_ndx; + cond_match_t *cond_match = con->request.cond_match + dc->context_ndx; if (data_config_pcre_exec(dc, cache, l, cond_match) > 0) { return (dc->cond == CONFIG_COND_MATCH) ? COND_RESULT_TRUE : COND_RESULT_FALSE; } else { @@ -621,7 +621,7 @@ static cond_result_t config_check_cond_calc(connection *con, const int context_n /* future: might make static inline in header for plugins */ int config_check_cond(connection * const con, const int context_ndx) { - cond_cache_t * const cache = &con->cond_cache[context_ndx]; + cond_cache_t * const cache = &con->request.cond_cache[context_ndx]; return COND_RESULT_TRUE == (COND_RESULT_UNSET != cache->result ? (cond_result_t)cache->result @@ -652,7 +652,7 @@ static void config_cond_clear_node(cond_cache_t * const cond_cache, const data_c * if the item is COND_LAST_ELEMENT we reset all items */ void config_cond_cache_reset_item(connection *con, comp_key_t item) { - cond_cache_t * const cond_cache = con->cond_cache; + cond_cache_t * const cond_cache = con->request.cond_cache; const array * const config_context = con->srv->config_context; for (uint32_t i = 0; i < config_context->used; ++i) { const data_config *dc = (data_config *)config_context->data[i]; @@ -670,12 +670,12 @@ void config_cond_cache_reset_item(connection *con, comp_key_t item) { * reset the config cache to its initial state at connection start */ void config_cond_cache_reset(connection *con) { - con->conditional_is_valid = 0; + con->request.conditional_is_valid = 0; /* resetting all entries; no need to follow children as in config_cond_cache_reset_item */ /* static_assert(0 == COND_RESULT_UNSET); */ const uint32_t used = con->srv->config_context->used; if (used > 1) - memset(con->cond_cache, 0, used*sizeof(cond_cache_t)); + memset(con->request.cond_cache, 0, used*sizeof(cond_cache_t)); } #ifdef HAVE_PCRE_H diff --git a/src/configfile.c b/src/configfile.c index 4c9bb776..dbd56d13 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -211,7 +211,7 @@ void config_patch_config(connection * const con) { void config_reset_config(connection * const con) { /* initialize request_config (con->conf) from top-level request_config */ config_data_base * const p = con->config_data_base; - con->server_name = p->defaults.server_name; + con->request.server_name = p->defaults.server_name; memcpy(&con->conf, &p->defaults, sizeof(request_config)); } diff --git a/src/connections.c b/src/connections.c index f238b5b6..094a97fc 100644 --- a/src/connections.c +++ b/src/connections.c @@ -67,7 +67,7 @@ static int connection_del(server *srv, connection *con) { buffer_clear(con->uri.authority); buffer_reset(con->uri.path); buffer_reset(con->uri.query); - buffer_reset(con->request.orig_uri); + buffer_reset(con->request.target_orig); connections * const conns = &srv->conns; @@ -544,11 +544,10 @@ static connection *connection_init(server *srv) { #define CLEAN(x) \ con->x = buffer_init(); - CLEAN(request.uri); + CLEAN(request.target); + CLEAN(request.target_orig); CLEAN(request.pathinfo); - CLEAN(request.orig_uri); - CLEAN(uri.scheme); CLEAN(uri.authority); CLEAN(uri.path); @@ -561,8 +560,8 @@ static connection *connection_init(server *srv) { CLEAN(physical.rel_path); CLEAN(physical.etag); - CLEAN(server_name_buf); CLEAN(dst_addr_buf); + CLEAN(request.server_name_buf); #undef CLEAN con->write_queue = chunkqueue_init(); @@ -578,12 +577,13 @@ static connection *connection_init(server *srv) { con->plugin_ctx = calloc(1, (srv->plugins.used + 1) * sizeof(void *)); force_assert(NULL != con->plugin_ctx); - con->cond_cache = calloc(srv->config_context->used, sizeof(cond_cache_t)); - force_assert(NULL != con->cond_cache); + con->request.cond_cache = calloc(srv->config_context->used, sizeof(cond_cache_t)); + force_assert(NULL != con->request.cond_cache); #ifdef HAVE_PCRE_H if (srv->config_context->used > 1) {/*save 128b per con if no conditions)*/ - con->cond_match=calloc(srv->config_context->used, sizeof(cond_match_t)); - force_assert(NULL != con->cond_match); + con->request.cond_match = + calloc(srv->config_context->used, sizeof(cond_match_t)); + force_assert(NULL != con->request.cond_match); } #endif config_reset_config(con); @@ -608,10 +608,10 @@ void connections_free(server *srv) { #define CLEAN(x) \ buffer_free(con->x); - CLEAN(request.uri); + CLEAN(request.target); CLEAN(request.pathinfo); - CLEAN(request.orig_uri); + CLEAN(request.target_orig); CLEAN(uri.scheme); CLEAN(uri.authority); @@ -625,12 +625,12 @@ void connections_free(server *srv) { CLEAN(physical.etag); CLEAN(physical.rel_path); - CLEAN(server_name_buf); + CLEAN(request.server_name_buf); CLEAN(dst_addr_buf); #undef CLEAN free(con->plugin_ctx); - free(con->cond_cache); - free(con->cond_match); + free(con->request.cond_cache); + free(con->request.cond_match); free(con); } @@ -658,10 +658,10 @@ static int connection_reset(connection *con) { #define CLEAN(x) \ buffer_reset(con->x); - CLEAN(request.uri); + CLEAN(request.target); CLEAN(request.pathinfo); - /* CLEAN(request.orig_uri); */ + /* CLEAN(request.target_orig); */ /* CLEAN(uri.path); */ CLEAN(uri.path_raw); @@ -670,7 +670,7 @@ static int connection_reset(connection *con) { buffer_clear(con->uri.scheme); /*buffer_clear(con->uri.authority);*/ - /*buffer_clear(con->server_name_buf);*//* reset when used */ + /*buffer_clear(con->request.server_name_buf);*//* reset when used */ /*con->proto_default_port = 80;*//*set to default in connection_accepted()*/ con->request.http_host = NULL; @@ -837,7 +837,7 @@ static int connection_handle_read_state(connection * const con) { buffer_clear(con->uri.authority); buffer_reset(con->uri.path); buffer_reset(con->uri.query); - buffer_reset(con->request.orig_uri); + buffer_reset(con->request.target_orig); } if (con->conf.log_request_header) { @@ -1121,8 +1121,8 @@ connection *connection_accepted(server *srv, server_socket *srv_socket, sock_add con->proto_default_port = 80; /* "http" */ config_cond_cache_reset(con); - con->conditional_is_valid |= (1 << COMP_SERVER_SOCKET) - | (1 << COMP_HTTP_REMOTE_IP); + con->request.conditional_is_valid |= (1 << COMP_SERVER_SOCKET) + | (1 << COMP_HTTP_REMOTE_IP); if (HANDLER_GO_ON != plugins_call_handle_connection_accept(con)) { connection_reset(con); @@ -1209,7 +1209,7 @@ static int connection_handle_request(connection *con) { if (con->request.http_version == HTTP_VERSION_UNSET) con->request.http_version = HTTP_VERSION_1_0; - buffer_copy_buffer(con->request.uri, error_handler); + buffer_copy_buffer(con->request.target, error_handler); connection_handle_errdoc_init(con); con->http_status = 0; /*(after connection_handle_errdoc_init())*/ @@ -1441,7 +1441,7 @@ static void connection_check_timeout (connection * const con, const time_t cur_t "%zd bytes. We waited %d seconds. If this is a problem, " "increase server.max-write-idle", BUFFER_INTLEN_PTR(con->dst_addr_buf), - BUFFER_INTLEN_PTR(con->request.uri), + BUFFER_INTLEN_PTR(con->request.target), con->bytes_written, (int)con->conf.max_write_idle); } connection_set_state(con, CON_STATE_ERROR); diff --git a/src/gw_backend.c b/src/gw_backend.c index 0e01e751..ade73086 100644 --- a/src/gw_backend.c +++ b/src/gw_backend.c @@ -2143,7 +2143,7 @@ static handler_t gw_recv_response(gw_handler_ctx *hctx, connection *con) { if (++con->request.loops_per_request > 5) { log_error(con->conf.errh, __FILE__, __LINE__, "too many loops while processing request: %s", - con->request.orig_uri->ptr); + con->request.target_orig->ptr); con->http_status = 500; /* Internal Server Error */ con->mode = DIRECT; return HANDLER_FINISHED; diff --git a/src/http-header-glue.c b/src/http-header-glue.c index 0176b54c..1bfb7ed0 100644 --- a/src/http-header-glue.c +++ b/src/http-header-glue.c @@ -66,8 +66,8 @@ static int http_response_buffer_append_authority(connection *con, buffer *o) { buffer_append_string_len(o, lhost, lhost_len); } } - } else if (!buffer_string_is_empty(con->server_name)) { - buffer_append_string_buffer(o, con->server_name); + } else if (!buffer_string_is_empty(con->request.server_name)) { + buffer_append_string_buffer(o, con->request.server_name); } else /* Lookup name: secondly try to get hostname for bind address */ if (0 != sock_addr_nameinfo_append_buffer(o, &our_addr, con->conf.errh)) { @@ -899,13 +899,13 @@ static handler_t http_response_process_local_redir(connection *con, size_t blen) if (++con->request.loops_per_request > 5) { log_error(con->conf.errh, __FILE__, __LINE__, "too many internal loops while processing request: %s", - con->request.orig_uri->ptr); + con->request.target_orig->ptr); con->http_status = 500; /* Internal Server Error */ con->mode = DIRECT; return HANDLER_FINISHED; } - buffer_copy_buffer(con->request.uri, vb); + buffer_copy_buffer(con->request.target, vb); if (con->request.reqbody_length) { if (con->request.reqbody_length @@ -1385,24 +1385,24 @@ int http_cgi_headers (connection *con, http_cgi_opts *opts, http_cgi_header_appe --len; } - if (buffer_string_length(con->request.orig_uri) >= len - && 0 == memcmp(con->request.orig_uri->ptr, + if (buffer_string_length(con->request.target_orig) >= len + && 0 == memcmp(con->request.target_orig->ptr, opts->strip_request_uri->ptr, len) - && con->request.orig_uri->ptr[len] == '/') { + && con->request.target_orig->ptr[len] == '/') { rc |= cb(vdata, CONST_STR_LEN("REQUEST_URI"), - con->request.orig_uri->ptr+len, - buffer_string_length(con->request.orig_uri) - len); + con->request.target_orig->ptr+len, + buffer_string_length(con->request.target_orig)-len); } else { rc |= cb(vdata, CONST_STR_LEN("REQUEST_URI"), - CONST_BUF_LEN(con->request.orig_uri)); + CONST_BUF_LEN(con->request.target_orig)); } } else { rc |= cb(vdata, CONST_STR_LEN("REQUEST_URI"), - CONST_BUF_LEN(con->request.orig_uri)); + CONST_BUF_LEN(con->request.target_orig)); } - if (!buffer_is_equal(con->request.uri, con->request.orig_uri)) { + if (!buffer_is_equal(con->request.target, con->request.target_orig)) { rc |= cb(vdata, CONST_STR_LEN("REDIRECT_URI"), - CONST_BUF_LEN(con->request.uri)); + CONST_BUF_LEN(con->request.target)); } /* set REDIRECT_STATUS for php compiled with --force-redirect * (if REDIRECT_STATUS has not already been set by error handler) */ @@ -1515,19 +1515,19 @@ int http_cgi_headers (connection *con, http_cgi_opts *opts, http_cgi_header_appe force_assert(s); rc |= cb(vdata, CONST_STR_LEN("SERVER_ADDR"), s, strlen(s)); - if (!buffer_string_is_empty(con->server_name)) { - size_t len = buffer_string_length(con->server_name); + if (!buffer_string_is_empty(con->request.server_name)) { + size_t len = buffer_string_length(con->request.server_name); - if (con->server_name->ptr[0] == '[') { - const char *colon = strstr(con->server_name->ptr, "]:"); - if (colon) len = (colon + 1) - con->server_name->ptr; + if (con->request.server_name->ptr[0] == '[') { + const char *colon = strstr(con->request.server_name->ptr, "]:"); + if (colon) len = (colon + 1) - con->request.server_name->ptr; } else { - const char *colon = strchr(con->server_name->ptr, ':'); - if (colon) len = colon - con->server_name->ptr; + const char *colon = strchr(con->request.server_name->ptr, ':'); + if (colon) len = colon - con->request.server_name->ptr; } rc |= cb(vdata, CONST_STR_LEN("SERVER_NAME"), - con->server_name->ptr, len); + con->request.server_name->ptr, len); } else { /* set to be same as SERVER_ADDR (above) */ rc |= cb(vdata, CONST_STR_LEN("SERVER_NAME"), s, strlen(s)); diff --git a/src/mod_accesslog.c b/src/mod_accesslog.c index 093c8224..11125ea8 100644 --- a/src/mod_accesslog.c +++ b/src/mod_accesslog.c @@ -948,7 +948,7 @@ static int log_access_record (const connection * const con, buffer * const b, fo /*(attempt to reconstruct request line)*/ buffer_append_string(b, get_http_method_name(con->request.http_method)); buffer_append_string_len(b, CONST_STR_LEN(" ")); - accesslog_append_escaped(b, con->request.orig_uri); + accesslog_append_escaped(b, con->request.target_orig); buffer_append_string_len(b, CONST_STR_LEN(" ")); buffer_append_string(b, get_http_version_name(con->request.http_version)); break; @@ -1008,8 +1008,8 @@ static int log_access_record (const connection * const con, buffer * const b, fo } break; case FORMAT_SERVER_NAME: - if (!buffer_string_is_empty(con->server_name)) { - buffer_append_string_buffer(b, con->server_name); + if (!buffer_string_is_empty(con->request.server_name)) { + buffer_append_string_buffer(b, con->request.server_name); } else { buffer_append_string_len(b, CONST_STR_LEN("-")); } diff --git a/src/mod_auth.c b/src/mod_auth.c index 89caaedd..4930b8f6 100644 --- a/src/mod_auth.c +++ b/src/mod_auth.c @@ -1101,14 +1101,14 @@ static handler_t mod_auth_check_digest(connection *con, void *p_d, const struct * the same digest as that calculated by the client.) * Internal redirects such as with mod_rewrite will modify request uri. * Reauthentication is done to detect crossing auth realms, but this - * uri validation step is bypassed. con->request.orig_uri is original - * uri sent in client request. */ + * uri validation step is bypassed. con->request.target_orig is + * original request-target sent in client request. */ { const size_t ulen = strlen(uri); - if (!buffer_is_equal_string(con->request.orig_uri, uri, ulen)) { + if (!buffer_is_equal_string(con->request.target_orig, uri, ulen)) { log_error(con->conf.errh, __FILE__, __LINE__, "digest: auth failed: uri mismatch (%s != %s), IP: %s", - con->request.orig_uri->ptr, uri, con->dst_addr_buf->ptr); + con->request.target_orig->ptr, uri, con->dst_addr_buf->ptr); buffer_free(b); return mod_auth_send_400_bad_request(con); } diff --git a/src/mod_authn_gssapi.c b/src/mod_authn_gssapi.c index 691ae88c..20dc27b1 100644 --- a/src/mod_authn_gssapi.c +++ b/src/mod_authn_gssapi.c @@ -339,8 +339,8 @@ static handler_t mod_authn_gssapi_check_spnego(connection *con, plugin_data *p, sprinc = buffer_init_buffer(p->conf.auth_gssapi_principal); if (strchr(sprinc->ptr, '/') == NULL) { /*(copy HTTP Host, omitting port if port is present)*/ - /* ??? Should con->server_name be used if http_host not present? - * ??? What if con->server_name is not set? + /* ??? Should con->request.server_name be used if http_host not present? + * ??? What if con->request.server_name is not set? * ??? Will this work below if IPv6 provided in Host? probably not */ if (!buffer_is_empty(con->request.http_host)) { buffer_append_string_len(sprinc, CONST_STR_LEN("/")); @@ -647,8 +647,8 @@ static handler_t mod_authn_gssapi_basic(connection *con, void *p_d, const http_a sprinc = buffer_init_buffer(p->conf.auth_gssapi_principal); if (strchr(sprinc->ptr, '/') == NULL) { /*(copy HTTP Host, omitting port if port is present)*/ - /* ??? Should con->server_name be used if http_host not present? - * ??? What if con->server_name is not set? + /* ??? Should con->request.server_name be used if http_host not present? + * ??? What if con->request.server_name is not set? * ??? Will this work below if IPv6 provided in Host? probably not */ if (!buffer_is_empty(con->request.http_host)) { buffer_append_string_len(sprinc, CONST_STR_LEN("/")); diff --git a/src/mod_authn_mysql.c b/src/mod_authn_mysql.c index 0f1e5d75..56210aa4 100644 --- a/src/mod_authn_mysql.c +++ b/src/mod_authn_mysql.c @@ -400,7 +400,7 @@ static handler_t mod_authn_mysql_query(connection *con, void *p_d, http_auth_inf /*(auth.backend.mysql.host, auth.backend.mysql.db might be NULL; do not log)*/ log_error(con->conf.errh, __FILE__, __LINE__, "auth config missing auth.backend.mysql.users_table for uri: %s", - con->request.uri->ptr); + con->request.target->ptr); return HANDLER_ERROR; } diff --git a/src/mod_cml_lua.c b/src/mod_cml_lua.c index 7e9ccf1f..444edcfc 100644 --- a/src/mod_cml_lua.c +++ b/src/mod_cml_lua.c @@ -137,7 +137,7 @@ int cache_parse_lua(connection *con, plugin_data *p, const buffer *fn) { { int header_tbl = lua_gettop(L); - c_to_lua_push(L, header_tbl, CONST_STR_LEN("REQUEST_URI"), CONST_BUF_LEN(con->request.orig_uri)); + c_to_lua_push(L, header_tbl, CONST_STR_LEN("REQUEST_URI"), CONST_BUF_LEN(con->request.target_orig)); c_to_lua_push(L, header_tbl, CONST_STR_LEN("SCRIPT_NAME"), CONST_BUF_LEN(con->uri.path)); c_to_lua_push(L, header_tbl, CONST_STR_LEN("SCRIPT_FILENAME"), CONST_BUF_LEN(con->physical.path)); c_to_lua_push(L, header_tbl, CONST_STR_LEN("DOCUMENT_ROOT"), CONST_BUF_LEN(con->physical.basedir)); diff --git a/src/mod_magnet.c b/src/mod_magnet.c index 5fb66635..294929b0 100644 --- a/src/mod_magnet.c +++ b/src/mod_magnet.c @@ -479,8 +479,8 @@ static buffer *magnet_env_get_buffer_by_id(connection *con, int id) { buffer_clear(dest); http_method_append(dest, con->request.http_method); break; - case MAGNET_ENV_REQUEST_URI: dest = con->request.uri; break; - case MAGNET_ENV_REQUEST_ORIG_URI: dest = con->request.orig_uri; break; + case MAGNET_ENV_REQUEST_URI: dest = con->request.target; break; + case MAGNET_ENV_REQUEST_ORIG_URI: dest = con->request.target_orig; break; case MAGNET_ENV_REQUEST_PATH_INFO: dest = con->request.pathinfo; break; case MAGNET_ENV_REQUEST_REMOTE_IP: dest = con->dst_addr_buf; break; case MAGNET_ENV_REQUEST_SERVER_ADDR: diff --git a/src/mod_mysql_vhost.c b/src/mod_mysql_vhost.c index c06e823a..05b765cc 100644 --- a/src/mod_mysql_vhost.c +++ b/src/mod_mysql_vhost.c @@ -345,8 +345,8 @@ CONNECTION_FUNC(mod_mysql_vhost_handle_docroot) { /* fix virtual server and docroot */ GO_ON: - con->server_name = con->server_name_buf; - buffer_copy_buffer(con->server_name_buf, c->server_name); + con->request.server_name = con->request.server_name_buf; + buffer_copy_buffer(con->request.server_name_buf, c->server_name); buffer_copy_buffer(con->physical.doc_root, c->document_root); return HANDLER_GO_ON; diff --git a/src/mod_openssl.c b/src/mod_openssl.c index 48b6a0e0..93dc8f1d 100644 --- a/src/mod_openssl.c +++ b/src/mod_openssl.c @@ -528,8 +528,8 @@ mod_openssl_SNI (SSL *ssl, handler_ctx *hctx, const char *servername, size_t len const buffer * const ssl_pemfile = hctx->conf.ssl_pemfile; - con->conditional_is_valid |= (1 << COMP_HTTP_SCHEME) - | (1 << COMP_HTTP_HOST); + con->request.conditional_is_valid |= (1 << COMP_HTTP_SCHEME) + | (1 << COMP_HTTP_HOST); mod_openssl_patch_config(con, &hctx->conf); /* reset COMP_HTTP_HOST so that conditions re-run after request hdrs read */ /*(done in response.c:config_cond_cache_reset() after request hdrs read)*/ diff --git a/src/mod_proxy.c b/src/mod_proxy.c index 03c99cdf..0dc3c738 100644 --- a/src/mod_proxy.c +++ b/src/mod_proxy.c @@ -828,9 +828,9 @@ static handler_t proxy_create_env(gw_handler_ctx *gwhctx) { /* request line */ http_method_append(b, con->request.http_method); buffer_append_string_len(b, CONST_STR_LEN(" ")); - buffer_append_string_buffer(b, con->request.uri); + buffer_append_string_buffer(b, con->request.target); if (remap_headers) - http_header_remap_uri(b, buffer_string_length(b) - buffer_string_length(con->request.uri), &hctx->conf.header, 1); + http_header_remap_uri(b, buffer_string_length(b) - buffer_string_length(con->request.target), &hctx->conf.header, 1); if (!upgrade) buffer_append_string_len(b, CONST_STR_LEN(" HTTP/1.0\r\n")); else diff --git a/src/mod_redirect.c b/src/mod_redirect.c index a72b78e2..7743edfc 100644 --- a/src/mod_redirect.c +++ b/src/mod_redirect.c @@ -156,8 +156,9 @@ URIHANDLER_FUNC(mod_redirect_uri_handler) { ctx.cache = NULL; if (p->conf.redirect->x0) { /*(p->conf.redirect->x0 is context_idx)*/ - ctx.cond_match_count=con->cond_cache[p->conf.redirect->x0].patterncount; - ctx.cache = con->cond_match + p->conf.redirect->x0; + ctx.cond_match_count = + con->request.cond_cache[p->conf.redirect->x0].patterncount; + ctx.cache = con->request.cond_match + p->conf.redirect->x0; } ctx.burl = &burl; burl.scheme = con->uri.scheme; @@ -166,14 +167,14 @@ URIHANDLER_FUNC(mod_redirect_uri_handler) { burl.path = con->uri.path_raw; burl.query = con->uri.query; if (buffer_string_is_empty(burl.authority)) - burl.authority = con->server_name; + burl.authority = con->request.server_name; /* redirect URL on match * e.g. redirect /base/ to /index.php?section=base */ buffer * const tb = con->srv->tmp_buf; rc = pcre_keyvalue_buffer_process(p->conf.redirect, &ctx, - con->request.uri, tb); + con->request.target, tb); if (HANDLER_FINISHED == rc) { http_header_response_set(con, HTTP_HEADER_LOCATION, CONST_STR_LEN("Location"), @@ -185,7 +186,7 @@ URIHANDLER_FUNC(mod_redirect_uri_handler) { else if (HANDLER_ERROR == rc) { log_error(con->conf.errh, __FILE__, __LINE__, "pcre_exec() error while processing uri: %s", - con->request.uri->ptr); + con->request.target->ptr); } return rc; } diff --git a/src/mod_rewrite.c b/src/mod_rewrite.c index 1070bd66..27e55d91 100644 --- a/src/mod_rewrite.c +++ b/src/mod_rewrite.c @@ -275,8 +275,9 @@ static handler_t process_rewrite_rules(connection *con, plugin_data *p, const pc ctx.cache = NULL; if (kvb->x0) { /*(kvb->x0 is context_idx)*/ - ctx.cond_match_count = con->cond_cache[kvb->x0].patterncount; - ctx.cache = con->cond_match + kvb->x0; + ctx.cond_match_count = + con->request.cond_cache[kvb->x0].patterncount; + ctx.cache = con->request.cond_match + kvb->x0; } ctx.burl = &burl; burl.scheme = con->uri.scheme; @@ -285,12 +286,12 @@ static handler_t process_rewrite_rules(connection *con, plugin_data *p, const pc burl.path = con->uri.path_raw; burl.query = con->uri.query; if (buffer_string_is_empty(burl.authority)) - burl.authority = con->server_name; + burl.authority = con->request.server_name; buffer * const tb = con->srv->tmp_buf; - rc = pcre_keyvalue_buffer_process(kvb, &ctx, con->request.uri, tb); + rc = pcre_keyvalue_buffer_process(kvb, &ctx, con->request.target, tb); if (HANDLER_FINISHED == rc && !buffer_is_empty(tb) && tb->ptr[0] == '/') { - buffer_copy_buffer(con->request.uri, tb); + buffer_copy_buffer(con->request.target, tb); uintptr_t * const hctx = (uintptr_t *)(con->plugin_ctx + p->id); *hctx |= REWRITE_STATE_REWRITTEN; /*(kvb->x1 is repeat_idx)*/ @@ -302,12 +303,12 @@ static handler_t process_rewrite_rules(connection *con, plugin_data *p, const pc rc = HANDLER_ERROR; log_error(con->conf.errh, __FILE__, __LINE__, "mod_rewrite invalid result (not beginning with '/') " - "while processing uri: %s", con->request.uri->ptr); + "while processing uri: %s", con->request.target->ptr); } else if (HANDLER_ERROR == rc) { log_error(con->conf.errh, __FILE__, __LINE__, "pcre_exec() error " - "while processing uri: %s", con->request.uri->ptr); + "while processing uri: %s", con->request.target->ptr); } return rc; } diff --git a/src/mod_simple_vhost.c b/src/mod_simple_vhost.c index 7b24ebd3..d1c69536 100644 --- a/src/mod_simple_vhost.c +++ b/src/mod_simple_vhost.c @@ -187,8 +187,8 @@ static handler_t mod_simple_vhost_docroot(connection *con, void *p_data) { const buffer *host = con->uri.authority; if ((!buffer_string_is_empty(host) && build_doc_root(con, p, b, host)) || build_doc_root(con, p, b, (host = p->conf.default_host))) { - con->server_name = con->server_name_buf; - buffer_copy_buffer(con->server_name_buf, host); + con->request.server_name = con->request.server_name_buf; + buffer_copy_buffer(con->request.server_name_buf, host); buffer_copy_buffer(con->physical.doc_root, b); } diff --git a/src/mod_ssi.c b/src/mod_ssi.c index fe2179e9..ac1f29f9 100644 --- a/src/mod_ssi.c +++ b/src/mod_ssi.c @@ -429,7 +429,7 @@ static int process_ssi_stmt(connection *con, handler_ctx *p, const char **l, siz chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(con->uri.scheme)); chunkqueue_append_mem(con->write_queue, CONST_STR_LEN("://")); chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(con->uri.authority)); - chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(con->request.uri)); + chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(con->request.target)); if (!buffer_string_is_empty(con->uri.query)) { chunkqueue_append_mem(con->write_queue, CONST_STR_LEN("?")); chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(con->uri.query)); @@ -438,7 +438,7 @@ static int process_ssi_stmt(connection *con, handler_ctx *p, const char **l, siz break; } case SSI_ECHO_SCRIPT_URL: { - chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(con->request.uri)); + chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(con->request.target)); if (!buffer_string_is_empty(con->uri.query)) { chunkqueue_append_mem(con->write_queue, CONST_STR_LEN("?")); chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(con->uri.query)); diff --git a/src/mod_status.c b/src/mod_status.c index 9d895882..29d3d1ac 100644 --- a/src/mod_status.c +++ b/src/mod_status.c @@ -299,7 +299,7 @@ static handler_t mod_status_handle_server_status_html(server *srv, connection *c buffer_append_string_len(b, CONST_STR_LEN("Hostname")); buffer_append_string_buffer(b, con->uri.authority); buffer_append_string_len(b, CONST_STR_LEN(" (")); - buffer_append_string_buffer(b, con->server_name); + buffer_append_string_buffer(b, con->request.server_name); buffer_append_string_len(b, CONST_STR_LEN(")\n")); buffer_append_string_len(b, CONST_STR_LEN("Uptime")); @@ -439,7 +439,7 @@ static handler_t mod_status_handle_server_status_html(server *srv, connection *c connection *c = srv->conns.ptr[j]; const char *state; - if (CON_STATE_READ == c->state && !buffer_string_is_empty(c->request.orig_uri)) { + if (CON_STATE_READ == c->state && !buffer_string_is_empty(c->request.target_orig)) { state = "k"; ++cstates[CON_STATE_CLOSE+2]; } else { @@ -509,7 +509,7 @@ static handler_t mod_status_handle_server_status_html(server *srv, connection *c buffer_append_string_len(b, CONST_STR_LEN("")); - if (CON_STATE_READ == c->state && !buffer_string_is_empty(c->request.orig_uri)) { + if (CON_STATE_READ == c->state && !buffer_string_is_empty(c->request.target_orig)) { buffer_append_string_len(b, CONST_STR_LEN("keep-alive")); } else { buffer_append_string(b, connection_get_state(c->state)); @@ -521,11 +521,11 @@ static handler_t mod_status_handle_server_status_html(server *srv, connection *c buffer_append_string_len(b, CONST_STR_LEN("")); - if (buffer_string_is_empty(c->server_name)) { + if (buffer_string_is_empty(c->request.server_name)) { buffer_append_string_buffer(b, c->uri.authority); } else { - buffer_append_string_buffer(b, c->server_name); + buffer_append_string_buffer(b, c->request.server_name); } buffer_append_string_len(b, CONST_STR_LEN("")); @@ -539,9 +539,9 @@ static handler_t mod_status_handle_server_status_html(server *srv, connection *c buffer_append_string_encoded(b, CONST_BUF_LEN(c->uri.query), ENCODING_HTML); } - if (!buffer_string_is_empty(c->request.orig_uri)) { + if (!buffer_string_is_empty(c->request.target_orig)) { buffer_append_string_len(b, CONST_STR_LEN(" (")); - buffer_append_string_encoded(b, CONST_BUF_LEN(c->request.orig_uri), ENCODING_HTML); + buffer_append_string_encoded(b, CONST_BUF_LEN(c->request.target_orig), ENCODING_HTML); buffer_append_string_len(b, CONST_STR_LEN(")")); } buffer_append_string_len(b, CONST_STR_LEN("")); @@ -607,7 +607,7 @@ static handler_t mod_status_handle_server_status_text(server *srv, connection *c for (uint32_t i = 0; i < srv->conns.used; ++i) { connection *c = srv->conns.ptr[i]; const char *state = - (CON_STATE_READ == c->state && !buffer_string_is_empty(c->request.orig_uri)) + (CON_STATE_READ == c->state && !buffer_string_is_empty(c->request.target_orig)) ? "k" : connection_get_short_state(c->state); buffer_append_string_len(b, state, 1); diff --git a/src/mod_vhostdb.c b/src/mod_vhostdb.c index d60e66fb..03912358 100644 --- a/src/mod_vhostdb.c +++ b/src/mod_vhostdb.c @@ -149,8 +149,8 @@ static handler_t mod_vhostdb_error_500 (connection *con) static handler_t mod_vhostdb_found (connection *con, vhostdb_entry *ve) { /* fix virtual server and docroot */ - con->server_name = con->server_name_buf; - buffer_copy_buffer(con->server_name_buf, ve->server_name); + con->request.server_name = con->request.server_name_buf; + buffer_copy_buffer(con->request.server_name_buf, ve->server_name); buffer_copy_buffer(con->physical.doc_root, ve->document_root); return HANDLER_GO_ON; } diff --git a/src/mod_webdav.c b/src/mod_webdav.c index eeda6319..b92f2fb2 100644 --- a/src/mod_webdav.c +++ b/src/mod_webdav.c @@ -3976,7 +3976,7 @@ static handler_t mod_webdav_delete (connection * const con, const plugin_config * const pconf) { /* reject DELETE if original URI sent with fragment ('litmus' warning) */ - if (NULL != strchr(con->request.orig_uri->ptr, '#')) { + if (NULL != strchr(con->request.target_orig->ptr, '#')) { http_status_set_error(con, 403); return HANDLER_FINISHED; } @@ -4004,12 +4004,12 @@ mod_webdav_delete (connection * const con, const plugin_config * const pconf) buffer_append_string_len(con->physical.path, CONST_STR_LEN("/")); buffer_append_string_len(con->physical.rel_path,CONST_STR_LEN("/")); #if 0 /*(Content-Location not very useful to client after DELETE)*/ - /*(? should it be request.uri or orig_uri ?)*/ + /*(? should it be request.target or target_orig ?)*/ /*(should be url-encoded path)*/ - buffer_append_string_len(con->request.uri, CONST_STR_LEN("/")); + buffer_append_string_len(con->request.target, CONST_STR_LEN("/")); http_header_response_set(con, HTTP_HEADER_CONTENT_LOCATION, CONST_STR_LEN("Content-Location"), - CONST_BUF_LEN(con->request.uri)); + CONST_BUF_LEN(con->request.target)); #endif #endif } diff --git a/src/request.c b/src/request.c index cc14a2fe..eeb0df6a 100644 --- a/src/request.c +++ b/src/request.c @@ -637,8 +637,8 @@ static int http_request_parse_reqline(request_st * const r, const char * const p return http_request_header_char_invalid(r, '\0', "invalid character in header -> 400"); } - buffer_copy_string_len(r->uri, uri, len); - buffer_copy_string_len(r->orig_uri, uri, len); + buffer_copy_string_len(r->target, uri, len); + buffer_copy_string_len(r->target_orig, uri, len); return 0; } diff --git a/src/request.h b/src/request.h index d161b11b..82020e6a 100644 --- a/src/request.h +++ b/src/request.h @@ -11,6 +11,8 @@ struct log_error_st; /* declaration */ struct chunkqueue; /* declaration */ +struct cond_cache_t; /* declaration */ +struct cond_match_t; /* declaration */ typedef struct { const array *mimetypes; @@ -79,8 +81,8 @@ struct request_st { connection *con; /** HEADER */ - buffer *uri; - buffer *orig_uri; + buffer *target; + buffer *target_orig; http_method_t http_method; http_version_t http_version; @@ -104,8 +106,14 @@ struct request_st { char loops_per_request; /* catch endless loops in a single request */ char async_callback; + const buffer *server_name; + /* internal */ + uint32_t conditional_is_valid; + struct cond_cache_t *cond_cache; + struct cond_match_t *cond_match; buffer *pathinfo; + buffer *server_name_buf; }; diff --git a/src/response.c b/src/response.c index 099304c4..3c967679 100644 --- a/src/response.c +++ b/src/response.c @@ -233,13 +233,13 @@ static handler_t http_response_physical_path_check(connection *con) { if (pathinfo) { size_t len = strlen(pathinfo), reqlen; if (con->conf.force_lowercase_filenames - && len <= (reqlen = buffer_string_length(con->request.uri)) - && buffer_eq_icase_ssn(con->request.uri->ptr + reqlen - len, pathinfo, len)) { + && len <= (reqlen = buffer_string_length(con->request.target)) + && buffer_eq_icase_ssn(con->request.target->ptr + reqlen - len, pathinfo, len)) { /* attempt to preserve case-insensitive PATH_INFO * (works in common case where mod_alias, mod_magnet, and other modules * have not modified the PATH_INFO portion of request URI, or did so * with exactly the PATH_INFO desired) */ - buffer_copy_string_len(con->request.pathinfo, con->request.uri->ptr + reqlen - len, len); + buffer_copy_string_len(con->request.pathinfo, con->request.target->ptr + reqlen - len, len); } else { buffer_copy_string_len(con->request.pathinfo, pathinfo, len); } @@ -364,32 +364,32 @@ handler_t http_response_prepare(connection *con) { if (con->request.http_method == HTTP_METHOD_CONNECT || (con->request.http_method == HTTP_METHOD_OPTIONS - && con->request.uri->ptr[0] == '*' - && con->request.uri->ptr[1] == '\0')) { + && con->request.target->ptr[0] == '*' + && con->request.target->ptr[1] == '\0')) { /* CONNECT ... (or) OPTIONS * ... */ - buffer_copy_buffer(con->uri.path_raw, con->request.uri); + buffer_copy_buffer(con->uri.path_raw, con->request.target); buffer_copy_buffer(con->uri.path, con->uri.path_raw); buffer_reset(con->uri.query); } else { char *qstr; if (con->conf.http_parseopts & HTTP_PARSEOPT_URL_NORMALIZE) { - /*uint32_t len = (uint32_t)buffer_string_length(con->request.uri);*/ - int qs = burl_normalize(con->request.uri, con->srv->tmp_buf, con->conf.http_parseopts); + /*uint32_t len = (uint32_t)buffer_string_length(con->request.target);*/ + int qs = burl_normalize(con->request.target, con->srv->tmp_buf, con->conf.http_parseopts); if (-2 == qs) { log_error(con->conf.errh, __FILE__, __LINE__, "invalid character in URI -> 400 %s", - con->request.uri->ptr); + con->request.target->ptr); return /* 400 Bad Request */ http_status_set_error_close(con, 400); } - qstr = (-1 == qs) ? NULL : con->request.uri->ptr+qs; + qstr = (-1 == qs) ? NULL : con->request.target->ptr+qs; #if 0 /* future: might enable here, or below for all requests */ /* (Note: total header size not recalculated on HANDLER_COMEBACK * even if other request headers changed during processing) * (If (0 != con->request.loops_per_request), then the generated * request is too large. Should a different error be returned?) */ con->request.rqst_header_len -= len; - len = buffer_string_length(con->request.uri); + len = buffer_string_length(con->request.target); con->request.rqst_header_len += len; if (len > MAX_HTTP_REQUEST_URI) { return /* 414 Request-URI Too Long */ @@ -403,25 +403,25 @@ handler_t http_response_prepare(connection *con) { } #endif } else { - size_t rlen = buffer_string_length(con->request.uri); - qstr = memchr(con->request.uri->ptr, '#', rlen);/* discard fragment */ + size_t rlen = buffer_string_length(con->request.target); + qstr = memchr(con->request.target->ptr, '#', rlen);/* discard fragment */ if (qstr) { - rlen = (size_t)(qstr - con->request.uri->ptr); - buffer_string_set_length(con->request.uri, rlen); + rlen = (size_t)(qstr - con->request.target->ptr); + buffer_string_set_length(con->request.target, rlen); } - qstr = memchr(con->request.uri->ptr, '?', rlen); + qstr = memchr(con->request.target->ptr, '?', rlen); } - /** extract query string from request.uri */ + /** extract query string from request.target */ if (NULL != qstr) { - const char * const pstr = con->request.uri->ptr; + const char * const pstr = con->request.target->ptr; const size_t plen = (size_t)(qstr - pstr); - const size_t rlen = buffer_string_length(con->request.uri); + const size_t rlen = buffer_string_length(con->request.target); buffer_copy_string_len(con->uri.query, qstr + 1, rlen - plen - 1); buffer_copy_string_len(con->uri.path_raw, pstr, plen); } else { buffer_reset(con->uri.query); - buffer_copy_buffer(con->uri.path_raw, con->request.uri); + buffer_copy_buffer(con->uri.path_raw, con->request.target); } /* decode url to path @@ -441,14 +441,14 @@ handler_t http_response_prepare(connection *con) { } } - con->conditional_is_valid |= (1 << COMP_SERVER_SOCKET) - | (1 << COMP_HTTP_SCHEME) - | (1 << COMP_HTTP_HOST) - | (1 << COMP_HTTP_REMOTE_IP) - | (1 << COMP_HTTP_REQUEST_METHOD) - | (1 << COMP_HTTP_URL) - | (1 << COMP_HTTP_QUERY_STRING) - | (1 << COMP_HTTP_REQUEST_HEADER); + con->request.conditional_is_valid |= (1 << COMP_SERVER_SOCKET) + | (1 << COMP_HTTP_SCHEME) + | (1 << COMP_HTTP_HOST) + | (1 << COMP_HTTP_REMOTE_IP) + | (1 << COMP_HTTP_REQUEST_METHOD) + | (1 << COMP_HTTP_URL) + | (1 << COMP_HTTP_QUERY_STRING) + | (1 << COMP_HTTP_REQUEST_HEADER); config_patch_config(con); /* do we have to downgrade to 1.0 ? */ @@ -460,7 +460,7 @@ handler_t http_response_prepare(connection *con) { log_error(con->conf.errh, __FILE__, __LINE__, "-- splitting Request-URI"); log_error(con->conf.errh, __FILE__, __LINE__, - "Request-URI : %s", con->request.uri->ptr); + "Request-URI : %s", con->request.target->ptr); log_error(con->conf.errh, __FILE__, __LINE__, "URI-scheme : %s", con->uri.scheme->ptr); log_error(con->conf.errh, __FILE__, __LINE__, @@ -615,8 +615,8 @@ handler_t http_response_prepare(connection *con) { } /* the docroot plugins might set the servername, if they don't we take http-host */ - if (buffer_string_is_empty(con->server_name)) { - con->server_name = con->uri.authority; + if (buffer_string_is_empty(con->request.server_name)) { + con->request.server_name = con->uri.authority; } /** diff --git a/src/t/test_request.c b/src/t/test_request.c index 9d2e17ad..dfd23186 100644 --- a/src/t/test_request.c +++ b/src/t/test_request.c @@ -15,8 +15,8 @@ static void test_request_reset(request_st * const r) r->http_host = NULL; r->htags = 0; r->reqbody_length = 0; - buffer_reset(r->orig_uri); - buffer_reset(r->uri); + buffer_reset(r->target_orig); + buffer_reset(r->target); array_reset_data_strings(&r->headers); } @@ -406,7 +406,7 @@ static void test_request_http_request_parse(request_st * const r) "\r\n")); assert(buffer_is_equal_string(r->http_host, CONST_STR_LEN("www.example.org"))); - assert(buffer_is_equal_string(r->uri, + assert(buffer_is_equal_string(r->target, CONST_STR_LEN("/"))); run_http_request_parse(r, __LINE__, 400, @@ -589,13 +589,13 @@ int main (void) request_st * const r = &con.request; r->conf = &con.conf; r->con = &con; - r->orig_uri = buffer_init(); - r->uri = buffer_init(); + r->target_orig = buffer_init(); + r->target = buffer_init(); test_request_http_request_parse(r); - buffer_free(r->orig_uri); - buffer_free(r->uri); + buffer_free(r->target_orig); + buffer_free(r->target); array_free_data(&r->headers); log_error_st_free(con.conf.errh);