From 0ce30f8c22074a0cd2254be1b94e08631e6e8d9c Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Thu, 10 Oct 2019 02:28:04 -0400 Subject: [PATCH] [core] (const buffer *) for con->server_name use con->server_name_buf when modules set server_name (e.g from db) --- src/base.h | 3 ++- src/configfile.c | 5 +++-- src/connections.c | 6 +++--- src/mod_mysql_vhost.c | 3 ++- src/mod_simple_vhost.c | 9 ++++++--- src/mod_vhostdb.c | 3 ++- src/response.c | 2 +- 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/base.h b/src/base.h index a7258cc0..4f2364e9 100644 --- a/src/base.h +++ b/src/base.h @@ -264,8 +264,9 @@ struct connection { specific_config conf; /* global connection specific config */ cond_cache_t *cond_cache; - buffer *server_name; + const buffer *server_name; buffer *proto; + buffer *server_name_buf; /* error-handler */ int error_handler_saved_status; diff --git a/src/configfile.c b/src/configfile.c index 2e99af8c..43b1c9c2 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -695,7 +695,6 @@ int config_setup_connection(server *srv, connection *con) { PATCH(global_bytes_per_second_cnt); con->conf.global_bytes_per_second_cnt_ptr = &s->global_bytes_per_second_cnt; - buffer_copy_buffer(con->server_name, s->server_name); PATCH(log_request_header); PATCH(log_response_header); @@ -715,6 +714,8 @@ int config_setup_connection(server *srv, connection *con) { PATCH(etag_use_mtime); PATCH(etag_use_size); + con->server_name = s->server_name; + return 0; } @@ -768,7 +769,7 @@ int config_patch_connection(server *srv, connection *con) { } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.follow-symlink"))) { PATCH(follow_symlink); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.name"))) { - buffer_copy_buffer(con->server_name, s->server_name); + PATCH(server_name); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.tag"))) { PATCH(server_tag); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.stream-request-body"))) { diff --git a/src/connections.c b/src/connections.c index 54766684..3e608610 100644 --- a/src/connections.c +++ b/src/connections.c @@ -566,7 +566,7 @@ static connection *connection_init(server *srv) { CLEAN(physical.rel_path); CLEAN(physical.etag); - CLEAN(server_name); + CLEAN(server_name_buf); CLEAN(proto); CLEAN(dst_addr_buf); @@ -626,7 +626,7 @@ void connections_free(server *srv) { CLEAN(physical.etag); CLEAN(physical.rel_path); - CLEAN(server_name); + CLEAN(server_name_buf); CLEAN(proto); CLEAN(dst_addr_buf); #undef CLEAN @@ -672,7 +672,7 @@ static int connection_reset(server *srv, connection *con) { buffer_clear(con->uri.scheme); /*buffer_clear(con->proto);*//* set to default in connection_accepted() */ /*buffer_clear(con->uri.authority);*/ - buffer_clear(con->server_name); + /*buffer_clear(con->server_name_buf);*//* reset when used */ con->request.http_host = NULL; con->request.content_length = 0; diff --git a/src/mod_mysql_vhost.c b/src/mod_mysql_vhost.c index 039422cf..a61bc14f 100644 --- a/src/mod_mysql_vhost.c +++ b/src/mod_mysql_vhost.c @@ -348,7 +348,8 @@ CONNECTION_FUNC(mod_mysql_vhost_handle_docroot) { /* fix virtual server and docroot */ GO_ON: - buffer_copy_buffer(con->server_name, c->server_name); + con->server_name = con->server_name_buf; + buffer_copy_buffer(con->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_simple_vhost.c b/src/mod_simple_vhost.c index 0639b556..711ac5c9 100644 --- a/src/mod_simple_vhost.c +++ b/src/mod_simple_vhost.c @@ -239,7 +239,8 @@ static handler_t mod_simple_vhost_docroot(server *srv, connection *con, void *p_ !buffer_string_is_empty(con->uri.authority) && buffer_is_equal(p->conf.docroot_cache_key, con->uri.authority)) { /* cache hit */ - buffer_copy_buffer(con->server_name, p->conf.docroot_cache_servername); + con->server_name = con->server_name_buf; + buffer_copy_buffer(con->server_name_buf, p->conf.docroot_cache_servername); buffer_copy_buffer(con->physical.doc_root, p->conf.docroot_cache_value); } else { /* build document-root */ @@ -250,7 +251,8 @@ static handler_t mod_simple_vhost_docroot(server *srv, connection *con, void *p_ p->doc_root, p->conf.default_host)) { /* default host worked */ - buffer_copy_buffer(con->server_name, p->conf.default_host); + con->server_name = con->server_name_buf; + buffer_copy_buffer(con->server_name_buf, p->conf.default_host); buffer_copy_buffer(con->physical.doc_root, p->doc_root); /* do not cache default host */ } @@ -258,7 +260,8 @@ static handler_t mod_simple_vhost_docroot(server *srv, connection *con, void *p_ } /* found host */ - buffer_copy_buffer(con->server_name, con->uri.authority); + con->server_name = con->server_name_buf; + buffer_copy_buffer(con->server_name_buf, con->uri.authority); buffer_copy_buffer(con->physical.doc_root, p->doc_root); /* copy to cache */ diff --git a/src/mod_vhostdb.c b/src/mod_vhostdb.c index f65c696b..0ec50886 100644 --- a/src/mod_vhostdb.c +++ b/src/mod_vhostdb.c @@ -166,7 +166,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 */ - buffer_copy_buffer(con->server_name, ve->server_name); + con->server_name = con->server_name_buf; + buffer_copy_buffer(con->server_name_buf, ve->server_name); buffer_copy_buffer(con->physical.doc_root, ve->document_root); return HANDLER_GO_ON; } diff --git a/src/response.c b/src/response.c index ad48fea7..166f2f5c 100644 --- a/src/response.c +++ b/src/response.c @@ -626,7 +626,7 @@ handler_t http_response_prepare(server *srv, 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)) { - buffer_copy_buffer(con->server_name, con->uri.authority); + con->server_name = con->uri.authority; } /**