tinywebd
diff libtinyweb/src/http.h @ 10:0dd50a23f3dd
separated all the tinyweb functionality out as a library
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 18 Apr 2015 22:47:57 +0300 |
parents | src/http.h@5ec50ca0d071 |
children | 86f703031228 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libtinyweb/src/http.h Sat Apr 18 22:47:57 2015 +0300 1.3 @@ -0,0 +1,50 @@ 1.4 +#ifndef HTTP_H_ 1.5 +#define HTTP_H_ 1.6 + 1.7 +enum http_method { 1.8 + HTTP_UNKNOWN, 1.9 + HTTP_OPTIONS, 1.10 + HTTP_GET, 1.11 + HTTP_HEAD, 1.12 + HTTP_POST, 1.13 + HTTP_PUT, 1.14 + HTTP_DELETE, 1.15 + HTTP_TRACE, 1.16 + HTTP_CONNECT, 1.17 + 1.18 + NUM_HTTP_METHODS 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 +struct http_resp_header { 1.31 + int status; 1.32 + int ver_major, ver_minor; 1.33 + char **fields; 1.34 + int num_fields; 1.35 +}; 1.36 + 1.37 +#define HTTP_HDR_OK 0 1.38 +#define HTTP_HDR_INVALID -1 1.39 +#define HTTP_HDR_NOMEM -2 1.40 +#define HTTP_HDR_PARTIAL -3 1.41 + 1.42 +int http_parse_request(struct http_req_header *hdr, const char *buf, int bufsz); 1.43 +void http_log_request(struct http_req_header *hdr); 1.44 +void http_destroy_request(struct http_req_header *hdr); 1.45 + 1.46 +int http_init_resp(struct http_resp_header *resp); 1.47 +int http_add_resp_field(struct http_resp_header *resp, const char *fmt, ...); 1.48 +void http_destroy_resp(struct http_resp_header *resp); 1.49 +int http_serialize_resp(struct http_resp_header *resp, char *buf); 1.50 + 1.51 +const char *http_strmsg(int code); 1.52 + 1.53 +#endif /* HTTP_H_ */