version 1.1.1.1, 2013/10/14 10:32:47
|
version 1.1.1.3, 2016/11/02 10:35:00
|
Line 1
|
Line 1
|
|
#include "first.h" |
|
|
#include "base.h" |
#include "base.h" |
#include "log.h" |
#include "log.h" |
#include "buffer.h" |
#include "buffer.h" |
Line 89 SETDEFAULTS_FUNC(mod_simple_vhost_set_defaults) {
|
Line 91 SETDEFAULTS_FUNC(mod_simple_vhost_set_defaults) {
|
|
|
if (!p) return HANDLER_ERROR; |
if (!p) return HANDLER_ERROR; |
|
|
p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *)); | p->config_storage = calloc(1, srv->config_context->used * sizeof(plugin_config *)); |
|
|
for (i = 0; i < srv->config_context->used; i++) { |
for (i = 0; i < srv->config_context->used; i++) { |
|
data_config const* config = (data_config const*)srv->config_context->data[i]; |
plugin_config *s; |
plugin_config *s; |
|
|
s = calloc(1, sizeof(plugin_config)); |
s = calloc(1, sizeof(plugin_config)); |
Line 114 SETDEFAULTS_FUNC(mod_simple_vhost_set_defaults) {
|
Line 117 SETDEFAULTS_FUNC(mod_simple_vhost_set_defaults) {
|
|
|
p->config_storage[i] = s; |
p->config_storage[i] = s; |
|
|
if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) { | if (0 != config_insert_values_global(srv, config->value, cv, i == 0 ? T_CONFIG_SCOPE_SERVER : T_CONFIG_SCOPE_CONNECTION)) { |
return HANDLER_ERROR; |
return HANDLER_ERROR; |
} |
} |
} |
} |
Line 124 SETDEFAULTS_FUNC(mod_simple_vhost_set_defaults) {
|
Line 127 SETDEFAULTS_FUNC(mod_simple_vhost_set_defaults) {
|
|
|
static int build_doc_root(server *srv, connection *con, plugin_data *p, buffer *out, buffer *host) { |
static int build_doc_root(server *srv, connection *con, plugin_data *p, buffer *out, buffer *host) { |
stat_cache_entry *sce = NULL; |
stat_cache_entry *sce = NULL; |
assert(p->conf.server_root->used > 1); | force_assert(!buffer_string_is_empty(p->conf.server_root)); |
|
|
buffer_prepare_copy(out, 128); | buffer_string_prepare_copy(out, 127); |
buffer_copy_string_buffer(out, p->conf.server_root); | buffer_copy_buffer(out, p->conf.server_root); |
|
|
if (host->used) { | if (!buffer_string_is_empty(host)) { |
/* a hostname has to start with a alpha-numerical character |
/* a hostname has to start with a alpha-numerical character |
* and must not contain a slash "/" |
* and must not contain a slash "/" |
*/ |
*/ |
char *dp; |
char *dp; |
|
|
BUFFER_APPEND_SLASH(out); | buffer_append_slash(out); |
|
|
if (NULL == (dp = strchr(host->ptr, ':'))) { |
if (NULL == (dp = strchr(host->ptr, ':'))) { |
buffer_append_string_buffer(out, host); |
buffer_append_string_buffer(out, host); |
Line 143 static int build_doc_root(server *srv, connection *con
|
Line 146 static int build_doc_root(server *srv, connection *con
|
buffer_append_string_len(out, host->ptr, dp - host->ptr); |
buffer_append_string_len(out, host->ptr, dp - host->ptr); |
} |
} |
} |
} |
BUFFER_APPEND_SLASH(out); | buffer_append_slash(out); |
|
|
if (p->conf.document_root->used > 2 && p->conf.document_root->ptr[0] == '/') { | if (buffer_string_length(p->conf.document_root) > 1 && p->conf.document_root->ptr[0] == '/') { |
buffer_append_string_len(out, p->conf.document_root->ptr + 1, p->conf.document_root->used - 2); | buffer_append_string_len(out, p->conf.document_root->ptr + 1, buffer_string_length(p->conf.document_root) - 1); |
} else { |
} else { |
buffer_append_string_buffer(out, p->conf.document_root); |
buffer_append_string_buffer(out, p->conf.document_root); |
BUFFER_APPEND_SLASH(out); | buffer_append_slash(out); |
} |
} |
|
|
if (HANDLER_ERROR == stat_cache_get_entry(srv, con, out, &sce)) { |
if (HANDLER_ERROR == stat_cache_get_entry(srv, con, out, &sce)) { |
Line 227 static handler_t mod_simple_vhost_docroot(server *srv,
|
Line 230 static handler_t mod_simple_vhost_docroot(server *srv,
|
/* build_doc_root() requires a server_root; skip module if simple-vhost.server-root is not set |
/* build_doc_root() requires a server_root; skip module if simple-vhost.server-root is not set |
* or set to an empty string (especially don't cache any results!) |
* or set to an empty string (especially don't cache any results!) |
*/ |
*/ |
if (p->conf.server_root->used < 2) return HANDLER_GO_ON; | if (buffer_string_is_empty(p->conf.server_root)) return HANDLER_GO_ON; |
|
|
if (p->conf.docroot_cache_key->used && | if (!buffer_string_is_empty(p->conf.docroot_cache_key) && |
con->uri.authority->used && | !buffer_string_is_empty(con->uri.authority) && |
buffer_is_equal(p->conf.docroot_cache_key, con->uri.authority)) { |
buffer_is_equal(p->conf.docroot_cache_key, con->uri.authority)) { |
/* cache hit */ |
/* cache hit */ |
buffer_copy_string_buffer(con->server_name, p->conf.docroot_cache_servername); | buffer_copy_buffer(con->server_name, p->conf.docroot_cache_servername); |
buffer_copy_string_buffer(con->physical.doc_root, p->conf.docroot_cache_value); | buffer_copy_buffer(con->physical.doc_root, p->conf.docroot_cache_value); |
} else { |
} else { |
/* build document-root */ |
/* build document-root */ |
if ((con->uri.authority->used == 0) || | if (buffer_string_is_empty(con->uri.authority) || |
build_doc_root(srv, con, p, p->doc_root, con->uri.authority)) { |
build_doc_root(srv, con, p, p->doc_root, con->uri.authority)) { |
/* not found, fallback the default-host */ |
/* not found, fallback the default-host */ |
if (0 == build_doc_root(srv, con, p, |
if (0 == build_doc_root(srv, con, p, |
p->doc_root, |
p->doc_root, |
p->conf.default_host)) { |
p->conf.default_host)) { |
/* default host worked */ |
/* default host worked */ |
buffer_copy_string_buffer(con->server_name, p->conf.default_host); | buffer_copy_buffer(con->server_name, p->conf.default_host); |
buffer_copy_string_buffer(con->physical.doc_root, p->doc_root); | buffer_copy_buffer(con->physical.doc_root, p->doc_root); |
/* do not cache default host */ |
/* do not cache default host */ |
} |
} |
return HANDLER_GO_ON; |
return HANDLER_GO_ON; |
} |
} |
|
|
/* found host */ |
/* found host */ |
buffer_copy_string_buffer(con->server_name, con->uri.authority); | buffer_copy_buffer(con->server_name, con->uri.authority); |
buffer_copy_string_buffer(con->physical.doc_root, p->doc_root); | buffer_copy_buffer(con->physical.doc_root, p->doc_root); |
|
|
/* copy to cache */ |
/* copy to cache */ |
buffer_copy_string_buffer(p->conf.docroot_cache_key, con->uri.authority); | buffer_copy_buffer(p->conf.docroot_cache_key, con->uri.authority); |
buffer_copy_string_buffer(p->conf.docroot_cache_value, p->doc_root); | buffer_copy_buffer(p->conf.docroot_cache_value, p->doc_root); |
buffer_copy_string_buffer(p->conf.docroot_cache_servername, con->server_name); | buffer_copy_buffer(p->conf.docroot_cache_servername, con->server_name); |
} |
} |
|
|
return HANDLER_GO_ON; |
return HANDLER_GO_ON; |