2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "smbd/service_task.h"
25 #include "web_server/web_server.h"
26 #include "smbd/service_stream.h"
27 #include "lib/events/events.h"
28 #include "system/filesys.h"
29 #include "system/iconv.h"
30 #include "system/time.h"
31 #include "web_server/esp/esp.h"
32 #include "dlinklist.h"
34 #define SWAT_SESSION_KEY "SwatSessionId"
35 #define HTTP_PREAUTH_URI "/scripting/preauth.esp"
37 /* state of the esp subsystem for a specific request */
39 struct websrv_context *web;
40 struct EspRequest *req;
41 struct MprVar variables[ESP_OBJ_MAX];
42 struct session_data *session;
45 /* destroy a esp session */
46 static int esp_destructor(void *ptr)
48 struct esp_state *esp = talloc_get_type(ptr, struct esp_state);
51 espDestroyRequest(esp->req);
57 output the http headers
59 static void http_output_headers(struct websrv_context *web)
64 uint32_t content_length = 0;
65 const char *response_string = "Unknown Code";
68 const char *response_string;
74 { 304, "Not Modified" },
75 { 400, "Bad request" },
76 { 401, "Unauthorized" },
79 { 500, "Internal Server Error" },
80 { 501, "Not implemented" }
82 for (i=0;i<ARRAY_SIZE(codes);i++) {
83 if (codes[i].code == web->output.response_code) {
84 response_string = codes[i].response_string;
88 if (web->output.headers == NULL) return;
89 s = talloc_asprintf(web, "HTTP/1.0 %u %s\r\n",
90 web->output.response_code, response_string);
91 if (s == NULL) return;
92 for (i=0;web->output.headers[i];i++) {
93 s = talloc_asprintf_append(s, "%s\r\n", web->output.headers[i]);
96 /* work out the content length */
97 content_length = web->output.content.length;
98 if (web->output.fd != -1) {
100 fstat(web->output.fd, &st);
101 content_length += st.st_size;
103 s = talloc_asprintf_append(s, "Content-Length: %u\r\n\r\n", content_length);
104 if (s == NULL) return;
106 b = web->output.content;
107 web->output.content.data = s;
108 web->output.content.length = strlen(s);
109 data_blob_append(web, &web->output.content, b.data, b.length);
114 return the local path for a URL
116 static const char *http_local_path(struct websrv_context *web, const char *url)
121 /* check that the url is OK */
122 if (url[0] != '/') return NULL;
124 for (i=0;url[i];i++) {
125 if ((!isalnum(url[i]) && !strchr("./_", url[i])) ||
126 (url[i] == '.' && strchr("/.", url[i+1]))) {
131 path = talloc_asprintf(web, "%s/%s", lp_swat_directory(), url+1);
132 if (path == NULL) return NULL;
134 if (directory_exist(path)) {
135 path = talloc_asprintf_append(path, "/index.esp");
141 called when esp wants to read a file to support include() calls
143 static int http_readFile(EspHandle handle, char **buf, int *len, const char *path)
145 struct websrv_context *web = talloc_get_type(handle, struct websrv_context);
150 path = http_local_path(web, path);
151 if (path == NULL) goto failed;
153 fd = open(path, O_RDONLY);
154 if (fd == -1 || fstat(fd, &st) != 0 || !S_ISREG(st.st_mode)) goto failed;
156 *buf = talloc_size(handle, st.st_size+1);
157 if (*buf == NULL) goto failed;
159 if (read(fd, *buf, st.st_size) != st.st_size) goto failed;
161 (*buf)[st.st_size] = 0;
168 DEBUG(0,("Failed to read file %s - %s\n", path, strerror(errno)));
169 if (fd != -1) close(fd);
176 called when esp wants to find the real path of a file
178 static int http_mapToStorage(EspHandle handle, char *path, int len, const char *uri, int flags)
180 if (uri == NULL || strlen(uri) >= len) return -1;
181 strncpy(path, uri, len);
186 called when esp wants to output something
188 static int http_writeBlock(EspHandle handle, char *buf, int size)
190 struct websrv_context *web = talloc_get_type(handle, struct websrv_context);
192 status = data_blob_append(web, &web->output.content, buf, size);
193 if (!NT_STATUS_IS_OK(status)) return -1;
201 static void http_setHeader(EspHandle handle, const char *value, bool allowMultiple)
203 struct websrv_context *web = talloc_get_type(handle, struct websrv_context);
204 char *p = strchr(value, ':');
206 if (p && !allowMultiple && web->output.headers) {
208 for (i=0;web->output.headers[i];i++) {
209 if (strncmp(web->output.headers[i], value, (p+1)-value) == 0) {
210 web->output.headers[i] = talloc_strdup(web, value);
216 web->output.headers = str_list_add(web->output.headers, value);
217 talloc_steal(web, web->output.headers);
221 set a http response code
223 static void http_setResponseCode(EspHandle handle, int code)
225 struct websrv_context *web = talloc_get_type(handle, struct websrv_context);
226 web->output.response_code = code;
230 redirect to another web page
232 static void http_redirect(EspHandle handle, int code, char *url)
234 struct websrv_context *web = talloc_get_type(handle, struct websrv_context);
235 const char *host = web->input.host;
237 /* form the full url, unless it already looks like a url */
238 if (strchr(url, ':') == NULL) {
240 host = talloc_asprintf(web, "%s:%u",
241 socket_get_my_addr(web->conn->socket, web),
242 socket_get_my_port(web->conn->socket));
244 if (host == NULL) goto internal_error;
246 char *p = strrchr(web->input.url, '/');
247 if (p == web->input.url) {
248 url = talloc_asprintf(web, "http%s://%s/%s",
249 web->tls_session?"s":"",
252 int dirlen = p - web->input.url;
253 url = talloc_asprintf(web, "http%s://%s%*.*s/%s",
254 web->tls_session?"s":"",
256 dirlen, dirlen, web->input.url,
259 if (url == NULL) goto internal_error;
263 http_setHeader(handle, talloc_asprintf(web, "Location: %s", url), 0);
265 /* make sure we give a valid redirect code */
266 if (code >= 300 && code < 400) {
267 http_setResponseCode(handle, code);
269 http_setResponseCode(handle, 302);
274 http_error(web, 500, "Internal server error");
281 static void http_setCookie(EspHandle handle, const char *name, const char *value,
282 int lifetime, const char *path, bool secure)
284 struct websrv_context *web = talloc_get_type(handle, struct websrv_context);
288 buf = talloc_asprintf(web, "Set-Cookie: %s=%s; path=%s; Expires=%s; %s",
289 name, value, path?path:"/",
290 http_timestring(web, time(NULL)+lifetime),
293 buf = talloc_asprintf(web, "Set-Cookie: %s=%s; path=%s; %s",
294 name, value, path?path:"/",
297 http_setHeader(handle, "Cache-control: no-cache=\"set-cookie\"", 0);
298 http_setHeader(handle, buf, 0);
303 return the session id
305 static const char *http_getSessionId(EspHandle handle)
307 struct websrv_context *web = talloc_get_type(handle, struct websrv_context);
308 return web->session->id;
314 static void http_createSession(EspHandle handle, int timeout)
316 struct websrv_context *web = talloc_get_type(handle, struct websrv_context);
318 web->session->lifetime = timeout;
319 http_setCookie(web, SWAT_SESSION_KEY, web->session->id,
320 web->session->lifetime, "/", 0);
327 static void http_destroySession(EspHandle handle)
329 struct websrv_context *web = talloc_get_type(handle, struct websrv_context);
330 talloc_free(web->session);
336 setup for a raw http level error
338 void http_error(struct websrv_context *web, int code, const char *info)
341 s = talloc_asprintf(web,"<HTML><HEAD><TITLE>Error %u</TITLE></HEAD><BODY><H1>Error %u</H1>%s<p></BODY></HTML>\r\n\r\n",
344 stream_terminate_connection(web->conn, "http_error: out of memory");
347 http_writeBlock(web, s, strlen(s));
348 http_setResponseCode(web, code);
349 http_output_headers(web);
350 EVENT_FD_NOT_READABLE(web->conn->event.fde);
351 EVENT_FD_WRITEABLE(web->conn->event.fde);
352 web->output.output_pending = True;
356 map a unix error code to a http error
358 void http_error_unix(struct websrv_context *web, const char *info)
370 info = talloc_asprintf(web, "%s<p>%s<p>\n", info, strerror(errno));
371 http_error(web, code, info);
376 a simple file request
378 static void http_simple_request(struct websrv_context *web)
380 const char *url = web->input.url;
384 path = http_local_path(web, url);
385 if (path == NULL) goto invalid;
388 web->output.fd = open(path, O_RDONLY);
389 if (web->output.fd == -1) {
390 DEBUG(0,("Failed to read file %s - %s\n", path, strerror(errno)));
391 http_error_unix(web, path);
395 if (fstat(web->output.fd, &st) != 0 || !S_ISREG(st.st_mode)) {
396 close(web->output.fd);
403 http_error(web, 400, "Malformed URL");
407 setup the standard ESP arrays
409 static void http_setup_arrays(struct esp_state *esp)
411 struct websrv_context *web = esp->web;
412 struct esp_data *edata = talloc_get_type(web->task->private, struct esp_data);
413 struct EspRequest *req = esp->req;
416 #define SETVAR(type, name, value) do { \
417 const char *v = value; \
418 if (v) espSetStringVar(req, type, name, v); \
421 SETVAR(ESP_REQUEST_OBJ, "CONTENT_LENGTH",
422 talloc_asprintf(esp, "%u", web->input.content_length));
423 SETVAR(ESP_REQUEST_OBJ, "QUERY_STRING", web->input.query_string);
424 SETVAR(ESP_REQUEST_OBJ, "REQUEST_METHOD", web->input.post_request?"POST":"GET");
425 SETVAR(ESP_REQUEST_OBJ, "REQUEST_URI", web->input.url);
426 p = strrchr(web->input.url, '/');
427 SETVAR(ESP_REQUEST_OBJ, "SCRIPT_NAME", p+1);
428 SETVAR(ESP_REQUEST_OBJ, "SCRIPT_FILENAME", web->input.url);
429 p = socket_get_peer_addr(web->conn->socket, esp);
430 SETVAR(ESP_REQUEST_OBJ, "REMOTE_ADDR", p);
431 p = socket_get_peer_name(web->conn->socket, esp);
432 SETVAR(ESP_REQUEST_OBJ, "REMOTE_HOST", p);
433 SETVAR(ESP_REQUEST_OBJ, "REMOTE_USER", "");
434 SETVAR(ESP_REQUEST_OBJ, "CONTENT_TYPE", web->input.content_type);
436 SETVAR(ESP_REQUEST_OBJ, "SESSION_ID", web->session->id);
438 SETVAR(ESP_REQUEST_OBJ, "COOKIE_SUPPORT", web->input.cookie?"True":"False");
440 SETVAR(ESP_HEADERS_OBJ, "HTT_REFERER", web->input.referer);
441 SETVAR(ESP_HEADERS_OBJ, "HOST", web->input.host);
442 SETVAR(ESP_HEADERS_OBJ, "ACCEPT_ENCODING", web->input.accept_encoding);
443 SETVAR(ESP_HEADERS_OBJ, "ACCEPT_LANGUAGE", web->input.accept_language);
444 SETVAR(ESP_HEADERS_OBJ, "ACCEPT_CHARSET", web->input.accept_charset);
445 SETVAR(ESP_HEADERS_OBJ, "COOKIE", web->input.cookie);
446 SETVAR(ESP_HEADERS_OBJ, "USER_AGENT", web->input.user_agent);
448 SETVAR(ESP_SERVER_OBJ, "SERVER_ADDR", socket_get_my_addr(web->conn->socket, esp));
449 SETVAR(ESP_SERVER_OBJ, "SERVER_NAME", socket_get_my_addr(web->conn->socket, esp));
450 SETVAR(ESP_SERVER_OBJ, "SERVER_HOST", socket_get_my_addr(web->conn->socket, esp));
451 SETVAR(ESP_SERVER_OBJ, "DOCUMENT_ROOT", lp_swat_directory());
452 SETVAR(ESP_SERVER_OBJ, "SERVER_PORT",
453 talloc_asprintf(esp, "%u", socket_get_my_port(web->conn->socket)));
454 SETVAR(ESP_SERVER_OBJ, "SERVER_PROTOCOL", web->tls_session?"https":"http");
455 SETVAR(ESP_SERVER_OBJ, "SERVER_SOFTWARE", "SWAT");
456 SETVAR(ESP_SERVER_OBJ, "GATEWAY_INTERFACE", "CGI/1.1");
457 SETVAR(ESP_SERVER_OBJ, "TLS_SUPPORT", edata->tls_data?"True":"False");
461 /* the esp scripting lirary generates exceptions when
462 it hits a major error. We need to catch these and
463 report a internal server error via http
466 static jmp_buf ejs_exception_buf;
467 static const char *exception_reason;
469 void ejs_exception(const char *reason)
471 exception_reason = reason;
472 DEBUG(0,("%s", reason));
473 longjmp(ejs_exception_buf, -1);
476 void ejs_exception(const char *reason)
478 DEBUG(0,("%s", reason));
484 process a esp request
486 static void esp_request(struct esp_state *esp, const char *url)
488 struct websrv_context *web = esp->web;
491 char *emsg = NULL, *buf;
493 if (http_readFile(web, &buf, &size, url) != 0) {
494 http_error_unix(web, url);
499 if (setjmp(ejs_exception_buf) != 0) {
500 http_error(web, 500, exception_reason);
504 res = espProcessRequest(esp->req, url, buf, &emsg);
505 if (res != 0 && emsg) {
506 http_writeBlock(web, emsg, strlen(emsg));
513 perform pre-authentication on every page is /scripting/preauth.esp
514 exists. If this script generates any non-whitepace output at all,
515 then we don't run the requested URL.
517 note that the preauth is run even for static pages such as images.
519 static BOOL http_preauth(struct esp_state *esp)
521 const char *path = http_local_path(esp->web, HTTP_PREAUTH_URI);
524 http_error(esp->web, 500, "Internal server error");
527 if (!file_exist(path)) {
528 /* if the preath script is not installed then allow access */
531 esp_request(esp, HTTP_PREAUTH_URI);
532 for (i=0;i<esp->web->output.content.length;i++) {
533 if (!isspace(esp->web->output.content.data[i])) {
534 /* if the preauth has generated content, then force it to be
535 html, so that we can show the login page for failed
537 http_setHeader(esp->web, "Content-Type: text/html", 0);
541 data_blob_free(&esp->web->output.content);
547 handling of + and % escapes in http variables
549 static const char *http_unescape(TALLOC_CTX *mem_ctx, const char *p)
551 char *s0 = talloc_strdup(mem_ctx, p);
553 if (s == NULL) return NULL;
557 if (*s == '+') *s = ' ';
558 if (*s == '%' && sscanf(s+1, "%02x", &v) == 1) {
560 memmove(s+1, s+3, strlen(s+3)+1);
569 set a form or GET variable
571 static void esp_putvar(struct esp_state *esp, const char *var, const char *value)
573 if (strcasecmp(var, SWAT_SESSION_KEY) == 0) {
574 /* special case support for browsers without cookie
576 esp->web->input.session_key = talloc_strdup(esp, value);
578 mprSetPropertyValue(&esp->variables[ESP_FORM_OBJ],
579 http_unescape(esp, var),
580 mprCreateStringVar(http_unescape(esp, value), 0));
586 parse the variables in a POST style request
588 static NTSTATUS http_parse_post(struct esp_state *esp)
590 DATA_BLOB b = esp->web->input.partial;
596 p = memchr(b.data, '&', b.length);
600 len = p - (char *)b.data;
602 line = talloc_strndup(esp, b.data, len);
603 NT_STATUS_HAVE_NO_MEMORY(line);
605 p = strchr(line,'=');
608 esp_putvar(esp, line, p+1);
623 parse the variables in a GET style request
625 static NTSTATUS http_parse_get(struct esp_state *esp)
627 struct websrv_context *web = esp->web;
631 p = strchr(web->input.url, '?');
632 web->input.query_string = p+1;
635 s = talloc_strdup(esp, esp->web->input.query_string);
636 NT_STATUS_HAVE_NO_MEMORY(s);
638 for (tok=strtok_r(s,"&;", &pp);tok;tok=strtok_r(NULL,"&;", &pp)) {
642 esp_putvar(esp, tok, p+1);
649 called when a session times out
651 static void session_timeout(struct event_context *ev, struct timed_event *te,
652 struct timeval t, void *private)
654 struct session_data *s = talloc_get_type(private, struct session_data);
661 static int session_destructor(void *ptr)
663 struct session_data *s = talloc_get_type(ptr, struct session_data);
664 DLIST_REMOVE(s->edata->sessions, s);
669 setup the session for this request
671 static void http_setup_session(struct esp_state *esp)
673 const char *session_key = SWAT_SESSION_KEY;
675 const char *cookie = esp->web->input.cookie;
676 const char *key = NULL;
677 struct esp_data *edata = talloc_get_type(esp->web->task->private, struct esp_data);
678 struct session_data *s;
679 BOOL generated_key = False;
681 /* look for our session key */
682 if (cookie && (p = strstr(cookie, session_key)) &&
683 p[strlen(session_key)] == '=') {
684 p += strlen(session_key)+1;
685 key = talloc_strndup(esp, p, strcspn(p, ";"));
688 if (key == NULL && esp->web->input.session_key) {
689 key = esp->web->input.session_key;
690 } else if (key == NULL) {
691 key = generate_random_str_list(esp, 16, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
692 generated_key = True;
695 /* try to find this session in the existing session list */
696 for (s=edata->sessions;s;s=s->next) {
697 if (strcmp(key, s->id) == 0) {
703 /* create a new session */
704 s = talloc_zero(edata, struct session_data);
705 s->id = talloc_steal(s, key);
709 s->lifetime = lp_parm_int(-1, "web", "sessiontimeout", 300);
710 DLIST_ADD(edata->sessions, s);
711 talloc_set_destructor(s, session_destructor);
712 if (!generated_key) {
713 mprSetPropertyValue(&esp->variables[ESP_REQUEST_OBJ],
714 "SESSION_EXPIRED", mprCreateStringVar("True", 0));
718 http_setCookie(esp->web, session_key, key, s->lifetime, "/", 0);
721 mprCopyVar(&esp->variables[ESP_SESSION_OBJ], s->data, MPR_DEEP_COPY);
724 esp->web->session = s;
728 /* callbacks for esp processing */
729 static const struct Esp esp_control = {
730 .maxScriptSize = 60000,
731 .writeBlock = http_writeBlock,
732 .setHeader = http_setHeader,
733 .redirect = http_redirect,
734 .setResponseCode = http_setResponseCode,
735 .readFile = http_readFile,
736 .mapToStorage = http_mapToStorage,
737 .setCookie = http_setCookie,
738 .createSession = http_createSession,
739 .destroySession = http_destroySession,
740 .getSessionId = http_getSessionId
744 process a complete http request
746 void http_process_input(struct websrv_context *web)
749 struct esp_state *esp;
750 struct esp_data *edata = talloc_get_type(web->task->private, struct esp_data);
753 const char *file_type = NULL;
754 BOOL esp_enable = False;
756 const char *extension;
757 const char *mime_type;
760 {"gif", "image/gif"},
761 {"png", "image/png"},
762 {"jpg", "image/jpeg"},
763 {"txt", "text/plain"},
764 {"ico", "image/x-icon"},
766 {"esp", "text/html", True}
769 esp = talloc_zero(web, struct esp_state);
770 if (esp == NULL) goto internal_error;
776 if (espOpen(&esp_control) != 0) goto internal_error;
778 for (i=0;i<ARRAY_SIZE(esp->variables);i++) {
779 esp->variables[i] = mprCreateUndefinedVar();
781 esp->variables[ESP_HEADERS_OBJ] = mprCreateObjVar("headers", ESP_HASH_SIZE);
782 esp->variables[ESP_FORM_OBJ] = mprCreateObjVar("form", ESP_HASH_SIZE);
783 esp->variables[ESP_APPLICATION_OBJ] = mprCreateObjVar("application", ESP_HASH_SIZE);
784 esp->variables[ESP_COOKIES_OBJ] = mprCreateObjVar("cookies", ESP_HASH_SIZE);
785 esp->variables[ESP_FILES_OBJ] = mprCreateObjVar("files", ESP_HASH_SIZE);
786 esp->variables[ESP_REQUEST_OBJ] = mprCreateObjVar("request", ESP_HASH_SIZE);
787 esp->variables[ESP_SERVER_OBJ] = mprCreateObjVar("server", ESP_HASH_SIZE);
788 esp->variables[ESP_SESSION_OBJ] = mprCreateObjVar("session", ESP_HASH_SIZE);
790 if (edata->application_data) {
791 mprCopyVar(&esp->variables[ESP_APPLICATION_OBJ],
792 edata->application_data, MPR_DEEP_COPY);
795 talloc_set_destructor(esp, esp_destructor);
797 smb_setup_ejs_functions();
798 http_setup_ejs_functions();
800 if (web->input.url == NULL) {
801 http_error(web, 400, "You must specify a GET or POST request");
805 /* parse any form or get variables */
806 if (web->input.post_request) {
807 status = http_parse_post(esp);
808 if (!NT_STATUS_IS_OK(status)) {
809 http_error(web, 400, "Malformed POST data");
813 if (strchr(web->input.url, '?')) {
814 status = http_parse_get(esp);
815 if (!NT_STATUS_IS_OK(status)) {
816 http_error(web, 400, "Malformed GET data");
821 http_setup_session(esp);
823 esp->req = espCreateRequest(web, web->input.url, esp->variables);
824 if (esp->req == NULL) goto internal_error;
826 /* work out the mime type */
827 p = strrchr(web->input.url, '.');
831 for (i=0;p && i<ARRAY_SIZE(mime_types);i++) {
832 if (strcmp(mime_types[i].extension, p+1) == 0) {
833 file_type = mime_types[i].mime_type;
834 esp_enable = mime_types[i].esp_enable;
837 if (file_type == NULL) {
838 file_type = "text/html";
841 /* setup basic headers */
842 http_setResponseCode(web, 200);
843 http_setHeader(web, talloc_asprintf(esp, "Date: %s",
844 http_timestring(esp, time(NULL))), 0);
845 http_setHeader(web, "Server: Samba", 0);
846 http_setHeader(web, "Connection: close", 0);
847 http_setHeader(web, talloc_asprintf(esp, "Content-Type: %s", file_type), 0);
849 http_setup_arrays(esp);
851 /* possibly do pre-authentication */
852 if (http_preauth(esp)) {
854 esp_request(esp, web->input.url);
856 http_simple_request(web);
860 if (!web->output.output_pending) {
861 http_output_headers(web);
862 EVENT_FD_WRITEABLE(web->conn->event.fde);
863 web->output.output_pending = True;
866 /* copy any application data to long term storage in edata */
867 talloc_free(edata->application_data);
868 edata->application_data = talloc_zero(edata, struct MprVar);
869 mprSetCtx(edata->application_data);
870 mprCopyVar(edata->application_data, &esp->variables[ESP_APPLICATION_OBJ],
873 /* copy any session data */
875 talloc_free(web->session->data);
876 web->session->data = talloc_zero(web->session, struct MprVar);
877 mprSetCtx(web->session->data);
878 if (esp->variables[ESP_SESSION_OBJ].properties == NULL ||
879 esp->variables[ESP_SESSION_OBJ].properties[0].numItems == 0) {
880 talloc_free(web->session);
883 mprCopyVar(web->session->data, &esp->variables[ESP_SESSION_OBJ],
885 /* setup the timeout for the session data */
886 talloc_free(web->session->te);
887 web->session->te = event_add_timed(web->conn->event.ctx, web->session,
888 timeval_current_ofs(web->session->lifetime, 0),
889 session_timeout, web->session);
898 http_error(web, 500, "Internal server error");
903 parse one line of header input
905 NTSTATUS http_parse_header(struct websrv_context *web, const char *line)
908 web->input.end_of_headers = True;
909 } else if (strncasecmp(line,"GET ", 4)==0) {
910 web->input.url = talloc_strndup(web, &line[4], strcspn(&line[4], " \t"));
911 } else if (strncasecmp(line,"POST ", 5)==0) {
912 web->input.post_request = True;
913 web->input.url = talloc_strndup(web, &line[5], strcspn(&line[5], " \t"));
914 } else if (strchr(line, ':') == NULL) {
915 http_error(web, 400, "This server only accepts GET and POST requests");
916 return NT_STATUS_INVALID_PARAMETER;
917 } else if (strncasecmp(line,"Content-Length: ", 16)==0) {
918 web->input.content_length = strtoul(&line[16], NULL, 10);
920 #define PULL_HEADER(v, s) do { \
921 if (strncmp(line, s, strlen(s)) == 0) { \
922 web->input.v = talloc_strdup(web, &line[strlen(s)]); \
923 return NT_STATUS_OK; \
926 PULL_HEADER(content_type, "Content-Type: ");
927 PULL_HEADER(user_agent, "User-Agent: ");
928 PULL_HEADER(referer, "Referer: ");
929 PULL_HEADER(host, "Host: ");
930 PULL_HEADER(accept_encoding, "Accept-Encoding: ");
931 PULL_HEADER(accept_language, "Accept-Language: ");
932 PULL_HEADER(accept_charset, "Accept-Charset: ");
933 PULL_HEADER(cookie, "Cookie: ");
936 /* ignore all other headers for now */
942 setup the esp processor - called at task initialisation
944 NTSTATUS http_setup_esp(struct task_server *task)
946 struct esp_data *edata;
948 edata = talloc_zero(task, struct esp_data);
949 NT_STATUS_HAVE_NO_MEMORY(edata);
951 task->private = edata;