tinywebd
diff src/http.h @ 3:852a745503cf
http header parsing, not tested
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 16 Apr 2015 15:20:16 +0300 |
parents | 7bb4c2a0a360 |
children | def49a046566 |
line diff
1.1 --- a/src/http.h Wed Apr 15 23:44:22 2015 +0300 1.2 +++ b/src/http.h Thu Apr 16 15:20:16 2015 +0300 1.3 @@ -15,93 +15,24 @@ 1.4 NUM_HTTP_METHODS 1.5 }; 1.6 1.7 -const char *http_method_str[] = { 1.8 - "<unknown>", 1.9 - "OPTIONS", 1.10 - "GET", 1.11 - "HEAD", 1.12 - "POST", 1.13 - "PUT", 1.14 - "DELETE", 1.15 - "TRACE", 1.16 - "CONNECT", 1.17 - 0 1.18 -}; 1.19 - 1.20 - 1.21 struct http_req_header { 1.22 enum http_method method; 1.23 char *uri; 1.24 int ver_major, ver_minor; /* http version */ 1.25 char **hdrfields; 1.26 int num_hdrfields; 1.27 + int body_offset; 1.28 }; 1.29 1.30 +#define HTTP_HDR_OK 0 1.31 +#define HTTP_HDR_INVALID -1 1.32 +#define HTTP_HDR_NOMEM -2 1.33 +#define HTTP_HDR_PARTIAL -3 1.34 1.35 int http_parse_header(struct http_req_header *hdr, const char *buf, int bufsz); 1.36 +void http_print_header(struct http_req_header *hdr); 1.37 +void http_destroy_header(struct http_req_header *hdr); 1.38 1.39 const char *http_strmsg(int code); 1.40 1.41 - 1.42 -/* HTTP 1xx message strings */ 1.43 -const char *http_msg1xx[] = { 1.44 - "Continue", /* 100 */ 1.45 - "Switching Protocols" /* 101 */ 1.46 -}; 1.47 - 1.48 -/* HTTP 2xx message strings */ 1.49 -const char *http_msg2xx[] = { 1.50 - "OK", /* 200 */ 1.51 - "Created", /* 201 */ 1.52 - "Accepted", /* 202 */ 1.53 - "Non-Authoritative Information", /* 203 */ 1.54 - "No Content", /* 204 */ 1.55 - "Reset Content", /* 205 */ 1.56 - "Partial Content" /* 206 */ 1.57 -}; 1.58 - 1.59 -/* HTTP 3xx message strings */ 1.60 -const char *http_msg3xx[] = { 1.61 - "Multiple Choices", /* 300 */ 1.62 - "Moved Permanently", /* 301 */ 1.63 - "Found", /* 302 */ 1.64 - "See Other", /* 303 */ 1.65 - "Not Modified", /* 304 */ 1.66 - "Use Proxy", /* 305 */ 1.67 - "<unknown>", /* 306 is undefined? */ 1.68 - "Temporary Redirect" /* 307 */ 1.69 -}; 1.70 - 1.71 -/* HTTP 4xx error strings */ 1.72 -const char *http_msg4xx[] = { 1.73 - "Bad Request", /* 400 */ 1.74 - "Unauthorized", /* 401 */ 1.75 - "What the Fuck?", /* 402 */ 1.76 - "Forbidden", /* 403 */ 1.77 - "Not Found", /* 404 */ 1.78 - "Method Not Allowed", /* 405 */ 1.79 - "Not Acceptable", /* 406 */ 1.80 - "Proxy Authentication Required", /* 407 */ 1.81 - "Request Time-out", /* 408 */ 1.82 - "Conflict", /* 409 */ 1.83 - "Gone", /* 410 */ 1.84 - "Length Required", /* 411 */ 1.85 - "Precondition Failed", /* 412 */ 1.86 - "Request Entity Too Large", /* 413 */ 1.87 - "Request-URI Too Large", /* 414 */ 1.88 - "Unsupported Media Type", /* 415 */ 1.89 - "Request range not satisfiable", /* 416 */ 1.90 - "Expectation Failed" /* 417 */ 1.91 -}; 1.92 - 1.93 -/* HTTP 5xx error strings */ 1.94 -const char *http_msg5xx[] = { 1.95 - "Internal Server Error", /* 500 */ 1.96 - "Not Implemented", /* 501 */ 1.97 - "Bad Gateway", /* 502 */ 1.98 - "Service Unavailable", /* 503 */ 1.99 - "Gateway Time-out", /* 504 */ 1.100 - "HTTP Version not supported" /* 505 */ 1.101 -}; 1.102 - 1.103 #endif /* HTTP_H_ */