diff options
author | Adam Chlipala <adamc@hcoop.net> | 2008-11-06 09:47:16 -0500 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2008-11-06 09:47:16 -0500 |
commit | 027f68ea322f9a52c3440a8d88be8d924b5c0395 (patch) | |
tree | a2eeed536be5e7cb6b43bf4bc8c8b48af01784a0 /src/c | |
parent | d7bd7d38e8f785b7366495ce977379929e5eb913 (diff) |
Request header reading works
Diffstat (limited to 'src/c')
-rw-r--r-- | src/c/driver.c | 5 | ||||
-rw-r--r-- | src/c/urweb.c | 34 |
2 files changed, 36 insertions, 3 deletions
diff --git a/src/c/driver.c b/src/c/driver.c index db982d96..4c54d3ba 100644 --- a/src/c/driver.c +++ b/src/c/driver.c @@ -135,7 +135,7 @@ static void *worker(void *data) { if (s = strstr(buf, "\r\n\r\n")) { failure_kind fk; - char *cmd, *path, path_copy[uw_bufsize+1], *inputs; + char *cmd, *path, *headers, path_copy[uw_bufsize+1], *inputs; *s = 0; @@ -145,6 +145,7 @@ static void *worker(void *data) { } *s = 0; + headers = s + 2; cmd = s = buf; printf("Read: %s\n", buf); @@ -208,7 +209,7 @@ static void *worker(void *data) { uw_write(ctx, "<html>"); strcpy(path_copy, path); - fk = uw_begin(ctx, path_copy); + fk = uw_begin(ctx, headers, path_copy); if (fk == SUCCESS) { uw_write(ctx, "</html>"); diff --git a/src/c/urweb.c b/src/c/urweb.c index f05b0b9d..9e83191e 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -3,6 +3,7 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <strings.h> #include <ctype.h> #include <setjmp.h> #include <stdarg.h> @@ -23,6 +24,8 @@ typedef struct { } cleanup; struct uw_context { + char *headers; + char *page, *page_front, *page_back; char *heap, *heap_front, *heap_back; char **inputs; @@ -43,6 +46,8 @@ extern int uw_inputs_len; uw_context uw_init(size_t page_len, size_t heap_len) { uw_context ctx = malloc(sizeof(struct uw_context)); + ctx->headers = NULL; + ctx->page_front = ctx->page = malloc(page_len); ctx->page_back = ctx->page_front + page_len; @@ -111,9 +116,11 @@ failure_kind uw_begin_init(uw_context ctx) { return r; } -failure_kind uw_begin(uw_context ctx, char *path) { +failure_kind uw_begin(uw_context ctx, char *headers, char *path) { int r = setjmp(ctx->jmp_buf); + ctx->headers = headers; + if (r == 0) uw_handle(ctx, path); @@ -1051,3 +1058,28 @@ uw_Basis_time uw_Basis_stringToTime_error(uw_context ctx, uw_Basis_string s) { uw_error(ctx, FATAL, "Can't parse time: %s", s); } } + +uw_Basis_string uw_Basis_requestHeader(uw_context ctx, uw_Basis_string h) { + int len = strlen(h); + char *s = ctx->headers, *p; + + while (p = strchr(s, ':')) { + if (p - s == len && !strncasecmp(s, h, len)) { + s = p + 2; + if (p = strchr(s, '\r')) { + uw_Basis_string ret = uw_malloc(ctx, p - s + 1); + memcpy(ret, s, p - s); + ret[p - s] = 0; + return ret; + } + else + return NULL; + } else { + if (s = strchr(s, '\n')) + ++s; + else + return NULL; + } + } + +} |