tinywebd
changeset 2:7bb4c2a0a360
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 15 Apr 2015 23:44:22 +0300 |
parents | f425a9805d17 |
children | 852a745503cf |
files | src/http.c src/http.h |
diffstat | 2 files changed, 30 insertions(+), 3 deletions(-) [+] |
line diff
1.1 --- a/src/http.c Tue Apr 14 08:32:51 2015 +0300 1.2 +++ b/src/http.c Wed Apr 15 23:44:22 2015 +0300 1.3 @@ -1,5 +1,28 @@ 1.4 #include "http.h" 1.5 1.6 +int http_parse_header(struct http_req_header *hdr, const char *buf, int bufsz) 1.7 +{ 1.8 + int i, nlines = 0; 1.9 + char *endhdr; 1.10 + char *rqline = 0; 1.11 + 1.12 + for(i=1; i<bufsz; i++) { 1.13 + if(buf[i] == '\n' && buf[i - 1] == '\r') { 1.14 + if(!rqline) { 1.15 + rqline = alloca(i); 1.16 + memcpy(rqline, buf, i - 1); 1.17 + rqline[i - 1] = 0; 1.18 + } 1.19 + ++nlines; 1.20 + } 1.21 + } 1.22 + 1.23 + if(!rqline) 1.24 + return -1; 1.25 + 1.26 + 1.27 +} 1.28 + 1.29 const char *http_strmsg(int code) 1.30 { 1.31 static const char **msgxxx[] = {
2.1 --- a/src/http.h Tue Apr 14 08:32:51 2015 +0300 2.2 +++ b/src/http.h Wed Apr 15 23:44:22 2015 +0300 2.3 @@ -33,10 +33,16 @@ 2.4 enum http_method method; 2.5 char *uri; 2.6 int ver_major, ver_minor; /* http version */ 2.7 - /* XXX cont. */ 2.8 + char **hdrfields; 2.9 + int num_hdrfields; 2.10 }; 2.11 2.12 2.13 +int http_parse_header(struct http_req_header *hdr, const char *buf, int bufsz); 2.14 + 2.15 +const char *http_strmsg(int code); 2.16 + 2.17 + 2.18 /* HTTP 1xx message strings */ 2.19 const char *http_msg1xx[] = { 2.20 "Continue", /* 100 */ 2.21 @@ -98,6 +104,4 @@ 2.22 "HTTP Version not supported" /* 505 */ 2.23 }; 2.24 2.25 -const char *http_strmsg(int code); 2.26 - 2.27 #endif /* HTTP_H_ */