Mercurial > urweb
comparison src/c/urweb.c @ 457:360cbc202756
Request header reading works
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 06 Nov 2008 09:47:16 -0500 |
parents | 322c8620bbdf |
children | 8f65b0fa3b29 |
comparison
equal
deleted
inserted
replaced
456:1a4fa157fedd | 457:360cbc202756 |
---|---|
1 #define _XOPEN_SOURCE | 1 #define _XOPEN_SOURCE |
2 | 2 |
3 #include <stdlib.h> | 3 #include <stdlib.h> |
4 #include <stdio.h> | 4 #include <stdio.h> |
5 #include <string.h> | 5 #include <string.h> |
6 #include <strings.h> | |
6 #include <ctype.h> | 7 #include <ctype.h> |
7 #include <setjmp.h> | 8 #include <setjmp.h> |
8 #include <stdarg.h> | 9 #include <stdarg.h> |
9 | 10 |
10 #include "types.h" | 11 #include "types.h" |
21 void (*func)(void*); | 22 void (*func)(void*); |
22 void *arg; | 23 void *arg; |
23 } cleanup; | 24 } cleanup; |
24 | 25 |
25 struct uw_context { | 26 struct uw_context { |
27 char *headers; | |
28 | |
26 char *page, *page_front, *page_back; | 29 char *page, *page_front, *page_back; |
27 char *heap, *heap_front, *heap_back; | 30 char *heap, *heap_front, *heap_back; |
28 char **inputs; | 31 char **inputs; |
29 | 32 |
30 void *db; | 33 void *db; |
40 | 43 |
41 extern int uw_inputs_len; | 44 extern int uw_inputs_len; |
42 | 45 |
43 uw_context uw_init(size_t page_len, size_t heap_len) { | 46 uw_context uw_init(size_t page_len, size_t heap_len) { |
44 uw_context ctx = malloc(sizeof(struct uw_context)); | 47 uw_context ctx = malloc(sizeof(struct uw_context)); |
48 | |
49 ctx->headers = NULL; | |
45 | 50 |
46 ctx->page_front = ctx->page = malloc(page_len); | 51 ctx->page_front = ctx->page = malloc(page_len); |
47 ctx->page_back = ctx->page_front + page_len; | 52 ctx->page_back = ctx->page_front + page_len; |
48 | 53 |
49 ctx->heap_front = ctx->heap = malloc(heap_len); | 54 ctx->heap_front = ctx->heap = malloc(heap_len); |
109 uw_db_init(ctx); | 114 uw_db_init(ctx); |
110 | 115 |
111 return r; | 116 return r; |
112 } | 117 } |
113 | 118 |
114 failure_kind uw_begin(uw_context ctx, char *path) { | 119 failure_kind uw_begin(uw_context ctx, char *headers, char *path) { |
115 int r = setjmp(ctx->jmp_buf); | 120 int r = setjmp(ctx->jmp_buf); |
121 | |
122 ctx->headers = headers; | |
116 | 123 |
117 if (r == 0) | 124 if (r == 0) |
118 uw_handle(ctx, path); | 125 uw_handle(ctx, path); |
119 | 126 |
120 return r; | 127 return r; |
1049 return mktime(&stm); | 1056 return mktime(&stm); |
1050 else | 1057 else |
1051 uw_error(ctx, FATAL, "Can't parse time: %s", s); | 1058 uw_error(ctx, FATAL, "Can't parse time: %s", s); |
1052 } | 1059 } |
1053 } | 1060 } |
1061 | |
1062 uw_Basis_string uw_Basis_requestHeader(uw_context ctx, uw_Basis_string h) { | |
1063 int len = strlen(h); | |
1064 char *s = ctx->headers, *p; | |
1065 | |
1066 while (p = strchr(s, ':')) { | |
1067 if (p - s == len && !strncasecmp(s, h, len)) { | |
1068 s = p + 2; | |
1069 if (p = strchr(s, '\r')) { | |
1070 uw_Basis_string ret = uw_malloc(ctx, p - s + 1); | |
1071 memcpy(ret, s, p - s); | |
1072 ret[p - s] = 0; | |
1073 return ret; | |
1074 } | |
1075 else | |
1076 return NULL; | |
1077 } else { | |
1078 if (s = strchr(s, '\n')) | |
1079 ++s; | |
1080 else | |
1081 return NULL; | |
1082 } | |
1083 } | |
1084 | |
1085 } |