let mod_alias handle directories and files (merged [284], [294])

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@504 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.2
Jan Kneschke 2005-08-08 09:42:27 +00:00
parent dee5efa0e2
commit 6adaad5458
6 changed files with 71 additions and 21 deletions

View File

@ -182,6 +182,7 @@ typedef struct {
typedef struct {
buffer *path;
buffer *basedir; /* path = "(basedir)(.*)" */
buffer *doc_root; /* path = doc_root + rel_path */
buffer *rel_path;

View File

@ -583,6 +583,7 @@ connection *connection_init(server *srv) {
CLEAN(physical.doc_root);
CLEAN(physical.path);
CLEAN(physical.basedir);
CLEAN(physical.rel_path);
CLEAN(physical.etag);
CLEAN(parse_request);
@ -641,6 +642,7 @@ void connections_free(server *srv) {
CLEAN(physical.doc_root);
CLEAN(physical.path);
CLEAN(physical.basedir);
CLEAN(physical.etag);
CLEAN(physical.rel_path);
CLEAN(parse_request);
@ -709,6 +711,7 @@ int connection_reset(server *srv, connection *con) {
CLEAN(physical.doc_root);
CLEAN(physical.path);
CLEAN(physical.basedir);
CLEAN(physical.rel_path);
CLEAN(physical.etag);

View File

@ -131,12 +131,13 @@ static int mod_alias_setup_connection(server *srv, connection *con, plugin_data
}
#undef PATCH
URIHANDLER_FUNC(mod_alias_docroot_handler) {
PHYSICALPATH_FUNC(mod_alias_physical_handler) {
plugin_data *p = p_d;
int uri_len;
int uri_len, basedir_len;
char *uri_ptr;
size_t k, i;
if (con->uri.path->used == 0) return HANDLER_GO_ON;
if (con->physical.path->used == 0) return HANDLER_GO_ON;
mod_alias_setup_connection(srv, con, p);
for (i = 0; i < srv->config_patches->used; i++) {
@ -145,7 +146,10 @@ URIHANDLER_FUNC(mod_alias_docroot_handler) {
mod_alias_patch_connection(srv, con, p, CONST_BUF_LEN(patch));
}
uri_len = con->uri.path->used - 1;
/* not to include the tailing slash */
basedir_len = (con->physical.basedir->used - 1) - 1;
uri_len = con->physical.path->used - 1 - basedir_len;
uri_ptr = con->physical.path->ptr + basedir_len;
for (k = 0; k < p->conf.alias->used; k++) {
data_string *ds = (data_string *)p->conf.alias->data[k];
@ -154,11 +158,13 @@ URIHANDLER_FUNC(mod_alias_docroot_handler) {
if (alias_len > uri_len) continue;
if (ds->key->used == 0) continue;
if (0 == strncmp(con->uri.path->ptr, ds->key->ptr, alias_len)) {
if (0 == strncmp(uri_ptr, ds->key->ptr, alias_len)) {
/* matched */
buffer_copy_string_buffer(con->physical.doc_root, ds->value);
buffer_copy_string(con->physical.rel_path, con->uri.path->ptr + alias_len);
buffer_copy_string_buffer(con->physical.basedir, ds->value);
buffer_copy_string_buffer(srv->tmp_buf, ds->value);
buffer_append_string(srv->tmp_buf, uri_ptr + alias_len);
buffer_copy_string_buffer(con->physical.path, srv->tmp_buf);
return HANDLER_GO_ON;
}
@ -175,7 +181,7 @@ int mod_alias_plugin_init(plugin *p) {
p->name = buffer_init_string("alias");
p->init = mod_alias_init;
p->handle_docroot = mod_alias_docroot_handler;
p->handle_physical= mod_alias_physical_handler;
p->set_defaults = mod_alias_set_defaults;
p->cleanup = mod_alias_free;

View File

@ -41,6 +41,7 @@ typedef enum {
PLUGIN_FUNC_HANDLE_SUBREQUEST_START,
PLUGIN_FUNC_HANDLE_JOBLIST,
PLUGIN_FUNC_HANDLE_DOCROOT,
PLUGIN_FUNC_HANDLE_PHYSICAL,
PLUGIN_FUNC_CONNECTION_RESET,
PLUGIN_FUNC_INIT,
PLUGIN_FUNC_CLEANUP,
@ -252,6 +253,7 @@ PLUGIN_TO_SLOT(PLUGIN_FUNC_HANDLE_SUBREQUEST, handle_subrequest)
PLUGIN_TO_SLOT(PLUGIN_FUNC_HANDLE_SUBREQUEST_START, handle_subrequest_start)
PLUGIN_TO_SLOT(PLUGIN_FUNC_HANDLE_JOBLIST, handle_joblist)
PLUGIN_TO_SLOT(PLUGIN_FUNC_HANDLE_DOCROOT, handle_docroot)
PLUGIN_TO_SLOT(PLUGIN_FUNC_HANDLE_PHYSICAL, handle_physical)
PLUGIN_TO_SLOT(PLUGIN_FUNC_CONNECTION_RESET, connection_reset)
#undef PLUGIN_TO_SLOT
@ -381,6 +383,7 @@ handler_t plugins_call_init(server *srv) {
PLUGIN_TO_SLOT(PLUGIN_FUNC_HANDLE_SUBREQUEST_START, handle_subrequest_start);
PLUGIN_TO_SLOT(PLUGIN_FUNC_HANDLE_JOBLIST, handle_joblist);
PLUGIN_TO_SLOT(PLUGIN_FUNC_HANDLE_DOCROOT, handle_docroot);
PLUGIN_TO_SLOT(PLUGIN_FUNC_HANDLE_PHYSICAL, handle_physical);
PLUGIN_TO_SLOT(PLUGIN_FUNC_CONNECTION_RESET, connection_reset);
PLUGIN_TO_SLOT(PLUGIN_FUNC_CLEANUP, cleanup);
PLUGIN_TO_SLOT(PLUGIN_FUNC_SET_DEFAULTS, set_defaults);

View File

@ -42,6 +42,7 @@ typedef struct {
handler_t (* handle_uri_clean) (server *srv, connection *con, void *p_d); /* after uri is set */
handler_t (* handle_docroot) (server *srv, connection *con, void *p_d); /* getting the document-root */
handler_t (* handle_physical_path) (server *srv, connection *con, void *p_d); /* after the physical path is set */
handler_t (* handle_physical) (server *srv, connection *con, void *p_d); /* mapping url to physical path */
handler_t (* handle_request_done) (server *srv, connection *con, void *p_d); /* at the end of a request */
handler_t (* handle_connection_close)(server *srv, connection *con, void *p_d); /* at the end of a connection */
handler_t (* handle_joblist) (server *srv, connection *con, void *p_d); /* after all events are handled */
@ -70,6 +71,7 @@ handler_t plugins_call_handle_subrequest_start(server *srv, connection *con);
handler_t plugins_call_handle_subrequest(server *srv, connection *con);
handler_t plugins_call_handle_request_done(server *srv, connection *con);
handler_t plugins_call_handle_docroot(server *srv, connection *con);
handler_t plugins_call_handle_physical(server *srv, connection *con);
handler_t plugins_call_handle_connection_close(server *srv, connection *con);
handler_t plugins_call_handle_joblist(server *srv, connection *con);
handler_t plugins_call_handle_physical_path(server *srv, connection *con);

View File

@ -1127,9 +1127,14 @@ handler_t http_response_prepare(server *srv, connection *con) {
buffer_reset(con->physical.path);
if (con->conf.log_request_handling) {
log_error_write(srv, __FILE__, __LINE__, "s", "-- before doc_root");
log_error_write(srv, __FILE__, __LINE__, "sb", "Doc-Root :", con->physical.doc_root);
log_error_write(srv, __FILE__, __LINE__, "sb", "Rel-Path :", con->physical.rel_path);
}
/* the docroot plugin should set the doc_root and might also set the physical.path
* for us (all vhost-plugins are supposed to set the doc_root, the alias plugin
* sets the path too)
* for us (all vhost-plugins are supposed to set the doc_root)
* */
switch(r = plugins_call_handle_docroot(srv, con)) {
case HANDLER_GO_ON:
@ -1159,10 +1164,47 @@ handler_t http_response_prepare(server *srv, connection *con) {
buffer_append_string_buffer(con->physical.path, con->physical.rel_path);
}
}
/* the docroot plugins might set the servername, if they don't we take http-host */
if (buffer_is_empty(con->server_name)) {
buffer_copy_string_buffer(con->server_name, con->uri.authority);
}
/**
* create physical filename
* -> physical.path = docroot + rel_path
*
*/
buffer_copy_string_buffer(con->physical.path, con->physical.doc_root);
BUFFER_APPEND_SLASH(con->physical.path);
buffer_copy_string_buffer(con->physical.basedir, con->physical.path);
if (con->physical.rel_path->ptr[0] == '/') {
buffer_append_string_len(con->physical.path, con->physical.rel_path->ptr + 1, con->physical.rel_path->used - 2);
} else {
buffer_append_string_buffer(con->physical.path, con->physical.rel_path);
}
if (con->conf.log_request_handling) {
log_error_write(srv, __FILE__, __LINE__, "s", "-- after doc_root");
log_error_write(srv, __FILE__, __LINE__, "sb", "Doc-Root :", con->physical.doc_root);
log_error_write(srv, __FILE__, __LINE__, "sb", "Rel-Path :", con->physical.rel_path);
log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path);
}
switch(r = plugins_call_handle_physical(srv, con)) {
case HANDLER_GO_ON:
break;
case HANDLER_FINISHED:
case HANDLER_COMEBACK:
case HANDLER_WAIT_FOR_EVENT:
case HANDLER_ERROR:
return r;
default:
log_error_write(srv, __FILE__, __LINE__, "");
break;
}
if (con->conf.log_request_handling) {
log_error_write(srv, __FILE__, __LINE__, "s", "-- logical -> physical");
log_error_write(srv, __FILE__, __LINE__, "sb", "Doc-Root :", con->physical.doc_root);
@ -1214,12 +1256,7 @@ handler_t http_response_prepare(server *srv, connection *con) {
}
/* not found, perhaps PATHINFO */
if (con->physical.rel_path->ptr[0] == '/') {
buffer_copy_string_len(srv->tmp_buf, con->physical.rel_path->ptr + 1, con->physical.rel_path->used - 2);
} else {
buffer_copy_string_buffer(srv->tmp_buf, con->physical.rel_path);
}
buffer_copy_string_buffer(srv->tmp_buf, con->physical.path);
/*
*
@ -1236,12 +1273,10 @@ handler_t http_response_prepare(server *srv, connection *con) {
do {
struct stat st;
buffer_copy_string_buffer(con->physical.path, con->physical.doc_root);
BUFFER_APPEND_SLASH(con->physical.path);
if (slash) {
buffer_append_string_len(con->physical.path, srv->tmp_buf->ptr, slash - srv->tmp_buf->ptr);
buffer_copy_string_len(con->physical.path, srv->tmp_buf->ptr, slash - srv->tmp_buf->ptr);
} else {
buffer_append_string_buffer(con->physical.path, srv->tmp_buf);
buffer_copy_string_buffer(con->physical.path, srv->tmp_buf);
}
if (0 == stat(con->physical.path->ptr, &(st)) &&
@ -1261,7 +1296,7 @@ handler_t http_response_prepare(server *srv, connection *con) {
}
if (slash) pathinfo = slash;
} while ((found == 0) && (slash != NULL) && (slash != srv->tmp_buf->ptr));
} while ((found == 0) && (slash != NULL) && (slash - srv->tmp_buf->ptr > con->physical.basedir->used - 2));
if (found == 0) {
/* no it really doesn't exists */