tinywebd

annotate libtinyweb/src/http.h @ 12:86f703031228

Attribution headers
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 19 Apr 2015 00:01:01 +0300
parents 0dd50a23f3dd
children
rev   line source
nuclear@12 1 /* tinyweb - tiny web server library and daemon
nuclear@12 2 * Author: John Tsiombikas <nuclear@member.fsf.org>
nuclear@12 3 *
nuclear@12 4 * This program is placed in the public domain. Feel free to use it any
nuclear@12 5 * way you like. Mentions and retaining this attribution header will be
nuclear@12 6 * appreciated, but not required.
nuclear@12 7 */
nuclear@1 8 #ifndef HTTP_H_
nuclear@1 9 #define HTTP_H_
nuclear@1 10
nuclear@1 11 enum http_method {
nuclear@1 12 HTTP_UNKNOWN,
nuclear@1 13 HTTP_OPTIONS,
nuclear@1 14 HTTP_GET,
nuclear@1 15 HTTP_HEAD,
nuclear@1 16 HTTP_POST,
nuclear@1 17 HTTP_PUT,
nuclear@1 18 HTTP_DELETE,
nuclear@1 19 HTTP_TRACE,
nuclear@1 20 HTTP_CONNECT,
nuclear@1 21
nuclear@1 22 NUM_HTTP_METHODS
nuclear@1 23 };
nuclear@1 24
nuclear@1 25 struct http_req_header {
nuclear@1 26 enum http_method method;
nuclear@1 27 char *uri;
nuclear@1 28 int ver_major, ver_minor; /* http version */
nuclear@2 29 char **hdrfields;
nuclear@2 30 int num_hdrfields;
nuclear@3 31 int body_offset;
nuclear@1 32 };
nuclear@1 33
nuclear@5 34 struct http_resp_header {
nuclear@5 35 int status;
nuclear@5 36 int ver_major, ver_minor;
nuclear@5 37 char **fields;
nuclear@5 38 int num_fields;
nuclear@5 39 };
nuclear@5 40
nuclear@3 41 #define HTTP_HDR_OK 0
nuclear@3 42 #define HTTP_HDR_INVALID -1
nuclear@3 43 #define HTTP_HDR_NOMEM -2
nuclear@3 44 #define HTTP_HDR_PARTIAL -3
nuclear@1 45
nuclear@7 46 int http_parse_request(struct http_req_header *hdr, const char *buf, int bufsz);
nuclear@7 47 void http_log_request(struct http_req_header *hdr);
nuclear@7 48 void http_destroy_request(struct http_req_header *hdr);
nuclear@2 49
nuclear@5 50 int http_init_resp(struct http_resp_header *resp);
nuclear@5 51 int http_add_resp_field(struct http_resp_header *resp, const char *fmt, ...);
nuclear@5 52 void http_destroy_resp(struct http_resp_header *resp);
nuclear@5 53 int http_serialize_resp(struct http_resp_header *resp, char *buf);
nuclear@5 54
nuclear@2 55 const char *http_strmsg(int code);
nuclear@2 56
nuclear@1 57 #endif /* HTTP_H_ */