From ebb0b35242f5c2967afdba9e746679bc87c5b745 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 27 May 2005 11:57:14 +0000 Subject: r7013: added tls support to the builtin web server. It auto-detects if the client is using tls by looking at the first byte on the connection. This allows both https and http services to be on the same port (This used to be commit 6369dfb6585ce4d4e3028c557395f2d73c290c92) --- source4/web_server/http.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'source4/web_server/http.c') diff --git a/source4/web_server/http.c b/source4/web_server/http.c index 6687ab7d16..11ddec552d 100644 --- a/source4/web_server/http.c +++ b/source4/web_server/http.c @@ -33,22 +33,6 @@ #define SWAT_SESSION_KEY "_swat_session_" -/* - context for long term storage in the web server, to support session[] - and application[] data. Stored in task->private. -*/ -struct esp_data { - struct session_data { - struct session_data *next, *prev; - struct esp_data *edata; - const char *id; - struct MprVar *data; - struct timed_event *te; - int lifetime; - } *sessions; - struct MprVar *application_data; -}; - /* state of the esp subsystem for a specific request */ struct esp_state { struct websrv_context *web; @@ -250,10 +234,13 @@ static void http_redirect(EspHandle handle, int code, char *url) if (url[0] != '/') { char *p = strrchr(web->input.url, '/'); if (p == web->input.url) { - url = talloc_asprintf(web, "http://%s/%s", host, url); + url = talloc_asprintf(web, "http%s://%s/%s", + web->tls_session?"s":"", + host, url); } else { int dirlen = p - web->input.url; - url = talloc_asprintf(web, "http://%s%*.*s/%s", + url = talloc_asprintf(web, "http%s://%s%*.*s/%s", + web->tls_session?"s":"", host, dirlen, dirlen, web->input.url, url); @@ -351,6 +338,7 @@ void http_error(struct websrv_context *web, int code, const char *info) http_output_headers(web); EVENT_FD_NOT_READABLE(web->conn->event.fde); EVENT_FD_WRITEABLE(web->conn->event.fde); + web->output.output_pending = True; } /* @@ -399,6 +387,7 @@ static void http_simple_request(struct websrv_context *web) http_output_headers(web); EVENT_FD_WRITEABLE(web->conn->event.fde); + web->output.output_pending = True; return; invalid: @@ -449,7 +438,7 @@ static void http_setup_arrays(struct esp_state *esp) SETVAR(ESP_SERVER_OBJ, "DOCUMENT_ROOT", lp_swat_directory()); SETVAR(ESP_SERVER_OBJ, "SERVER_PORT", talloc_asprintf(esp, "%u", socket_get_my_port(web->conn->socket))); - SETVAR(ESP_SERVER_OBJ, "SERVER_PROTOCOL", "http"); + SETVAR(ESP_SERVER_OBJ, "SERVER_PROTOCOL", web->tls_session?"https":"http"); SETVAR(ESP_SERVER_OBJ, "SERVER_SOFTWARE", "SWAT"); SETVAR(ESP_SERVER_OBJ, "GATEWAY_INTERFACE", "CGI/1.1"); SETVAR(ESP_REQUEST_OBJ, "SCRIPT_FILENAME", web->input.url); @@ -509,6 +498,7 @@ static void esp_request(struct esp_state *esp) talloc_free(buf); http_output_headers(web); EVENT_FD_WRITEABLE(web->conn->event.fde); + web->output.output_pending = True; } @@ -663,7 +653,7 @@ static void http_setup_session(struct esp_state *esp) s->data = NULL; s->te = NULL; s->edata = edata; - s->lifetime = lp_parm_int(-1, "http", "sessiontimeout", 300); + s->lifetime = lp_parm_int(-1, "web", "sessiontimeout", 300); DLIST_ADD(edata->sessions, s); talloc_set_destructor(s, session_destructor); } @@ -775,6 +765,9 @@ void http_process_input(struct websrv_context *web) /* work out the mime type */ p = strrchr(web->input.url, '.'); + if (p == NULL) { + esp_enable = True; + } for (i=0;p && iprivate = edata; - edata->sessions = NULL; - edata->application_data = NULL; return NT_STATUS_OK; } -- cgit