From c033a1966ef274a68140bcf505155b7c1a159b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Sun, 21 Feb 2016 18:32:17 +0000 Subject: [PATCH] [core] improve conditional enabling (thx Gwenlliana, #2598) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit instead of looping over all config blocks for each conditional var that gets enabled, enable them all and run over them once. Right now it seems we actually set all variables at once in normal config handling (SNI only sets a subset); future modifications might introduce new variables which are activated at a later stage (physical path related for example). From: Stefan Bühler git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3083 152afb58-edef-0310-8abb-c4023f1b3aa9 --- NEWS | 1 + src/configfile.c | 4 +--- src/configfile.h | 3 +++ src/connections.c | 1 + src/network.c | 7 ++++--- src/plugin.h | 2 -- src/response.c | 24 ++++++++++++------------ 7 files changed, 22 insertions(+), 20 deletions(-) diff --git a/NEWS b/NEWS index 79b93866..084ac1bb 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,7 @@ NEWS * [configparser] don't continue after parse error (fixes #2717) * [core] never evaluate else branches until the previous branches are ready (fixes #2598) * [core] fix conditional cache handling + * [core] improve conditional enabling (thx Gwenlliana, #2598) - 1.4.39 - 2016-01-02 * [core] fix memset_s call (fixes #2698) diff --git a/src/configfile.c b/src/configfile.c index 72dabb70..8a7e8534 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -383,11 +383,9 @@ int config_setup_connection(server *srv, connection *con) { return 0; } -int config_patch_connection(server *srv, connection *con, comp_key_t comp) { +int config_patch_connection(server *srv, connection *con) { size_t i, j; - con->conditional_is_valid[comp] = 1; - /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; diff --git a/src/configfile.h b/src/configfile.h index 17743a07..c6113142 100644 --- a/src/configfile.h +++ b/src/configfile.h @@ -21,6 +21,9 @@ int config_parse_file(server *srv, config_t *context, const char *fn); int config_parse_cmd(server *srv, config_t *context, const char *cmd); data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2); +int config_setup_connection(server *srv, connection *con); +int config_patch_connection(server *srv, connection *con); + void config_cond_cache_reset(server *srv, connection *con); void config_cond_cache_reset_item(server *srv, connection *con, comp_key_t item); diff --git a/src/connections.c b/src/connections.c index 8ecd9385..f01d6988 100644 --- a/src/connections.c +++ b/src/connections.c @@ -4,6 +4,7 @@ #include "connections.h" #include "fdevent.h" +#include "configfile.h" #include "request.h" #include "response.h" #include "network.h" diff --git a/src/network.c b/src/network.c index 846e5496..48491e0e 100644 --- a/src/network.c +++ b/src/network.c @@ -108,9 +108,10 @@ static int network_ssl_servername_callback(SSL *ssl, int *al, server *srv) { config_cond_cache_reset(srv, con); config_setup_connection(srv, con); - config_patch_connection(srv, con, COMP_SERVER_SOCKET); - config_patch_connection(srv, con, COMP_HTTP_SCHEME); - config_patch_connection(srv, con, COMP_HTTP_HOST); + con->conditional_is_valid[COMP_SERVER_SOCKET] = 1; + con->conditional_is_valid[COMP_HTTP_SCHEME] = 1; + con->conditional_is_valid[COMP_HTTP_HOST] = 1; + config_patch_connection(srv, con); if (NULL == con->conf.ssl_pemfile_x509 || NULL == con->conf.ssl_pemfile_pkey) { /* x509/pkey available <=> pemfile was set <=> pemfile got patched: so this should never happen, unless you nest $SERVER["socket"] */ diff --git a/src/plugin.h b/src/plugin.h index 73533626..b758b179 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -84,8 +84,6 @@ handler_t plugins_call_cleanup(server *srv); int config_insert_values_global(server *srv, array *ca, const config_values_t *cv, config_scope_type_t scope); int config_insert_values_internal(server *srv, array *ca, const config_values_t *cv, config_scope_type_t scope); -int config_setup_connection(server *srv, connection *con); -int config_patch_connection(server *srv, connection *con, comp_key_t comp); int config_check_cond(server *srv, connection *con, data_config *dc); int config_append_cond_match_buffer(connection *con, data_config *dc, buffer *buf, int n); diff --git a/src/response.c b/src/response.c index 357f43bc..be037a55 100644 --- a/src/response.c +++ b/src/response.c @@ -246,7 +246,6 @@ handler_t http_response_prepare(server *srv, connection *con) { if (con->conf.log_condition_handling) { log_error_write(srv, __FILE__, __LINE__, "s", "run condition"); } - config_patch_connection(srv, con, COMP_SERVER_SOCKET); /* SERVERsocket */ /** * prepare strings @@ -279,15 +278,6 @@ handler_t http_response_prepare(server *srv, connection *con) { buffer_copy_buffer(con->uri.authority, con->request.http_host); buffer_to_lower(con->uri.authority); - config_patch_connection(srv, con, COMP_HTTP_SCHEME); /* Scheme: */ - config_patch_connection(srv, con, COMP_HTTP_HOST); /* Host: */ - config_patch_connection(srv, con, COMP_HTTP_REMOTE_IP); /* Client-IP */ - config_patch_connection(srv, con, COMP_HTTP_REFERER); /* Referer: */ - config_patch_connection(srv, con, COMP_HTTP_USER_AGENT);/* User-Agent: */ - config_patch_connection(srv, con, COMP_HTTP_LANGUAGE); /* Accept-Language: */ - config_patch_connection(srv, con, COMP_HTTP_COOKIE); /* Cookie: */ - config_patch_connection(srv, con, COMP_HTTP_REQUEST_METHOD); /* REQUEST_METHOD */ - /** their might be a fragment which has to be cut away */ if (NULL != (qstr = strchr(con->request.uri->ptr, '#'))) { buffer_string_set_length(con->request.uri, qstr - con->request.uri->ptr); @@ -318,8 +308,18 @@ handler_t http_response_prepare(server *srv, connection *con) { buffer_path_simplify(con->uri.path, srv->tmp_buf); } - config_patch_connection(srv, con, COMP_HTTP_URL); /* HTTPurl */ - config_patch_connection(srv, con, COMP_HTTP_QUERY_STRING); /* HTTPqs */ + con->conditional_is_valid[COMP_SERVER_SOCKET] = 1; /* SERVERsocket */ + con->conditional_is_valid[COMP_HTTP_SCHEME] = 1; /* Scheme: */ + con->conditional_is_valid[COMP_HTTP_HOST] = 1; /* Host: */ + con->conditional_is_valid[COMP_HTTP_REMOTE_IP] = 1; /* Client-IP */ + con->conditional_is_valid[COMP_HTTP_REFERER] = 1; /* Referer: */ + con->conditional_is_valid[COMP_HTTP_USER_AGENT] = /* User-Agent: */ + con->conditional_is_valid[COMP_HTTP_LANGUAGE] = 1; /* Accept-Language: */ + con->conditional_is_valid[COMP_HTTP_COOKIE] = 1; /* Cookie: */ + con->conditional_is_valid[COMP_HTTP_REQUEST_METHOD] = 1; /* REQUEST_METHOD */ + con->conditional_is_valid[COMP_HTTP_URL] = 1; /* HTTPurl */ + con->conditional_is_valid[COMP_HTTP_QUERY_STRING] = 1; /* HTTPqs */ + config_patch_connection(srv, con); #ifdef USE_OPENSSL if (con->srv_socket->is_ssl && con->conf.ssl_verifyclient) {