nuclear@12: /* tinyweb - tiny web server library and daemon nuclear@12: * Author: John Tsiombikas nuclear@12: * nuclear@12: * This program is placed in the public domain. Feel free to use it any nuclear@12: * way you like. Mentions and retaining this attribution header will be nuclear@12: * appreciated, but not required. nuclear@12: */ nuclear@1: #ifndef HTTP_H_ nuclear@1: #define HTTP_H_ nuclear@1: nuclear@1: enum http_method { nuclear@1: HTTP_UNKNOWN, nuclear@1: HTTP_OPTIONS, nuclear@1: HTTP_GET, nuclear@1: HTTP_HEAD, nuclear@1: HTTP_POST, nuclear@1: HTTP_PUT, nuclear@1: HTTP_DELETE, nuclear@1: HTTP_TRACE, nuclear@1: HTTP_CONNECT, nuclear@1: nuclear@1: NUM_HTTP_METHODS nuclear@1: }; nuclear@1: nuclear@1: struct http_req_header { nuclear@1: enum http_method method; nuclear@1: char *uri; nuclear@1: int ver_major, ver_minor; /* http version */ nuclear@2: char **hdrfields; nuclear@2: int num_hdrfields; nuclear@3: int body_offset; nuclear@1: }; nuclear@1: nuclear@5: struct http_resp_header { nuclear@5: int status; nuclear@5: int ver_major, ver_minor; nuclear@5: char **fields; nuclear@5: int num_fields; nuclear@5: }; nuclear@5: nuclear@3: #define HTTP_HDR_OK 0 nuclear@3: #define HTTP_HDR_INVALID -1 nuclear@3: #define HTTP_HDR_NOMEM -2 nuclear@3: #define HTTP_HDR_PARTIAL -3 nuclear@1: nuclear@7: int http_parse_request(struct http_req_header *hdr, const char *buf, int bufsz); nuclear@7: void http_log_request(struct http_req_header *hdr); nuclear@7: void http_destroy_request(struct http_req_header *hdr); nuclear@2: nuclear@5: int http_init_resp(struct http_resp_header *resp); nuclear@5: int http_add_resp_field(struct http_resp_header *resp, const char *fmt, ...); nuclear@5: void http_destroy_resp(struct http_resp_header *resp); nuclear@5: int http_serialize_resp(struct http_resp_header *resp, char *buf); nuclear@5: nuclear@2: const char *http_strmsg(int code); nuclear@2: nuclear@1: #endif /* HTTP_H_ */