summaryrefslogtreecommitdiff
path: root/source4/web_server/web_server.c
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-09-21 19:03:12 +0200
committerJelmer Vernooij <jelmer@samba.org>2008-09-21 19:03:12 +0200
commit1ed040d8e22a63079c72126bbc896fa3c32c7f0f (patch)
tree5457207af93bec257ba1665ad90d83f1b5beefa8 /source4/web_server/web_server.c
parent4141e70da97d924969b48fcd198e5996d615e75d (diff)
downloadsamba-1ed040d8e22a63079c72126bbc896fa3c32c7f0f.tar.gz
samba-1ed040d8e22a63079c72126bbc896fa3c32c7f0f.tar.bz2
samba-1ed040d8e22a63079c72126bbc896fa3c32c7f0f.zip
First GET request works. SWAT now displays a Hello world message.
Diffstat (limited to 'source4/web_server/web_server.c')
-rw-r--r--source4/web_server/web_server.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/source4/web_server/web_server.c b/source4/web_server/web_server.c
index 1a3c48a03d..1ed37f657b 100644
--- a/source4/web_server/web_server.c
+++ b/source4/web_server/web_server.c
@@ -63,27 +63,45 @@ static void websrv_timeout(struct event_context *event_context,
/*
setup for a raw http level error
*/
-void http_error(struct websrv_context *web, int code, const char *info)
+void http_error(struct websrv_context *web, const char *status, const char *info)
{
char *s;
- s = talloc_asprintf(web,"<HTML><HEAD><TITLE>Error %u</TITLE></HEAD><BODY><H1>Error %u</H1><pre>%s</pre><p></BODY></HTML>\r\n\r\n",
- code, code, info);
+ s = talloc_asprintf(web,"<HTML><HEAD><TITLE>Error %s</TITLE></HEAD><BODY><H1>Error %s</H1><pre>%s</pre><p></BODY></HTML>\r\n\r\n",
+ status, status, info);
if (s == NULL) {
stream_terminate_connection(web->conn, "http_error: out of memory");
return;
}
- /* FIXME:
- http_writeBlock(web, s, strlen(s));
- http_setResponseCode(web, code);
- http_output_headers(web); */
- EVENT_FD_NOT_READABLE(web->conn->event.fde);
- EVENT_FD_WRITEABLE(web->conn->event.fde);
- web->output.output_pending = true;
+ websrv_output_headers(web, status, NULL);
+ websrv_output(web, s, strlen(s));
}
void websrv_output_headers(struct websrv_context *web, const char *status, struct http_header *headers)
{
- /* FIXME */
+ char *s;
+ DATA_BLOB b;
+ struct http_header *hdr;
+
+ s = talloc_asprintf(web, "HTTP/1.0 %s\r\n", status);
+ if (s == NULL) return;
+ for (hdr = headers; hdr; hdr = hdr->next) {
+ s = talloc_asprintf_append_buffer(s, "%s: %s\r\n", hdr->name, hdr->value);
+ }
+
+ s = talloc_asprintf_append_buffer(s, "\r\n");
+
+ b = web->output.content;
+ web->output.content = data_blob_string_const(s);
+ websrv_output(web, b.data, b.length);
+ data_blob_free(&b);
+}
+
+void websrv_output(struct websrv_context *web, void *data, size_t length)
+{
+ data_blob_append(web, &web->output.content, data, length);
+ EVENT_FD_NOT_READABLE(web->conn->event.fde);
+ EVENT_FD_WRITEABLE(web->conn->event.fde);
+ web->output.output_pending = true;
}
@@ -100,7 +118,7 @@ NTSTATUS http_parse_header(struct websrv_context *web, const char *line)
web->input.post_request = true;
web->input.url = talloc_strndup(web, &line[5], strcspn(&line[5], " \t"));
} else if (strchr(line, ':') == NULL) {
- http_error(web, 400, "This server only accepts GET and POST requests");
+ http_error(web, "400 Bad request", "This server only accepts GET and POST requests");
return NT_STATUS_INVALID_PARAMETER;
} else if (strncasecmp(line, "Content-Length: ", 16)==0) {
web->input.content_length = strtoul(&line[16], NULL, 10);
@@ -108,7 +126,7 @@ NTSTATUS http_parse_header(struct websrv_context *web, const char *line)
struct http_header *hdr = talloc_zero(web, struct http_header);
char *colon = strchr(line, ':');
if (colon == NULL) {
- http_error(web, 500, "invalidly formatted header");
+ http_error(web, "500 Internal Server Error", "invalidly formatted header");
return NT_STATUS_INVALID_PARAMETER;
}