add 'docroot' option, remove 'physical' action

personal/stbuehler/wip
Thomas Porzelt 15 years ago
parent 29c962fe06
commit d7b17a7746

@ -118,52 +118,34 @@ static action* core_set(server *srv, plugin* p, value *val) {
return a;
}
static action_result core_handle_physical(connection *con, gpointer param) {
GString *docroot = (GString*) param;
static action_result core_handle_static(connection *con, gpointer param) {
UNUSED(param);
int fd;
if (con->state != CON_STATE_HANDLE_REQUEST_HEADER) return ACTION_GO_ON;
/* build physical path: docroot + uri.path */
g_string_truncate(con->physical.path, 0);
g_string_append_len(con->physical.path, GSTR_LEN(docroot));
g_string_append_len(con->physical.path, GSTR_LEN(CORE_OPTION(CORE_OPTION_DOCROOT).string));
g_string_append_len(con->physical.path, GSTR_LEN(con->request.uri.path));
return ACTION_GO_ON;
}
static void core_physical_free(struct server *srv, gpointer param) {
UNUSED(srv);
g_string_free((GString*) param, TRUE);
}
static action* core_physical(server *srv, plugin* p, value *val) {
UNUSED(p);
GString *docroot;
if (!val) {
ERROR(srv, "%s", "need parameter");
return NULL;
}
if (val->type != VALUE_STRING) {
ERROR(srv, "expected string as parameter, got %s", value_type_string(val->type));
return NULL;
}
docroot = (GString*) value_extract_ptr(val);
return action_new_function(core_handle_physical, core_physical_free, docroot);
}
static action_result core_handle_static(connection *con, gpointer param) {
UNUSED(param);
int fd;
if (con->state != CON_STATE_HANDLE_REQUEST_HEADER) return ACTION_GO_ON;
CON_TRACE(con, "physical path: %s", con->physical.path->str);
if (con->physical.path->len == 0) return ACTION_GO_ON;
fd = open(con->physical.path->str, O_RDONLY);
if (fd == -1) {
con->response.http_status = 404;
CON_TRACE(con, "open() failed: %s (%d)\n", g_strerror(errno), errno);
switch (errno) {
case ENOENT:
con->response.http_status = 404; break;
case EACCES:
case EFAULT:
con->response.http_status = 403; break;
default:
con->response.http_status = 500;
}
} else {
struct stat st;
fstat(fd, &st);
@ -586,6 +568,9 @@ static const plugin_option options[] = {
{ "server.max_keep_alive_idle", VALUE_NUMBER, GINT_TO_POINTER(5), NULL, NULL },
{ "mime_types", VALUE_LIST, NULL, core_option_mime_types_parse, core_option_mime_types_free },
{ "docroot", VALUE_STRING, NULL, NULL, NULL },
{ NULL, 0, NULL, NULL, NULL }
};
@ -594,8 +579,8 @@ static const plugin_action actions[] = {
{ "when", core_when },
{ "set", core_set },
{ "physical", core_physical },
{ "static", core_static },
{ "test", core_test },
{ "blank", core_blank },
{ NULL, NULL }

@ -12,7 +12,9 @@ enum core_options_t {
CORE_OPTION_SERVER_TAG,
CORE_OPTION_MAX_KEEP_ALIVE_IDLE,
CORE_OPTION_MIME_TYPES
CORE_OPTION_MIME_TYPES,
CORE_OPTION_DOCROOT
};
/* the core plugin always has base index 0, as it is the first plugin loaded */

@ -164,6 +164,4 @@ void response_send_error_page(connection *con) {
" </body>\n"
"</html>\n"
));
g_printerr("%u\n", len);
}

Loading…
Cancel
Save