tinywebd

annotate src/http.h @ 5:def49a046566

serialization of responses
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 17 Apr 2015 01:57:00 +0300
parents 852a745503cf
children 5ec50ca0d071
rev   line source
nuclear@1 1 #ifndef HTTP_H_
nuclear@1 2 #define HTTP_H_
nuclear@1 3
nuclear@1 4 enum http_method {
nuclear@1 5 HTTP_UNKNOWN,
nuclear@1 6 HTTP_OPTIONS,
nuclear@1 7 HTTP_GET,
nuclear@1 8 HTTP_HEAD,
nuclear@1 9 HTTP_POST,
nuclear@1 10 HTTP_PUT,
nuclear@1 11 HTTP_DELETE,
nuclear@1 12 HTTP_TRACE,
nuclear@1 13 HTTP_CONNECT,
nuclear@1 14
nuclear@1 15 NUM_HTTP_METHODS
nuclear@1 16 };
nuclear@1 17
nuclear@1 18 struct http_req_header {
nuclear@1 19 enum http_method method;
nuclear@1 20 char *uri;
nuclear@1 21 int ver_major, ver_minor; /* http version */
nuclear@2 22 char **hdrfields;
nuclear@2 23 int num_hdrfields;
nuclear@3 24 int body_offset;
nuclear@1 25 };
nuclear@1 26
nuclear@5 27 struct http_resp_header {
nuclear@5 28 int status;
nuclear@5 29 int ver_major, ver_minor;
nuclear@5 30 char **fields;
nuclear@5 31 int num_fields;
nuclear@5 32 };
nuclear@5 33
nuclear@3 34 #define HTTP_HDR_OK 0
nuclear@3 35 #define HTTP_HDR_INVALID -1
nuclear@3 36 #define HTTP_HDR_NOMEM -2
nuclear@3 37 #define HTTP_HDR_PARTIAL -3
nuclear@1 38
nuclear@2 39 int http_parse_header(struct http_req_header *hdr, const char *buf, int bufsz);
nuclear@3 40 void http_print_header(struct http_req_header *hdr);
nuclear@3 41 void http_destroy_header(struct http_req_header *hdr);
nuclear@2 42
nuclear@5 43 int http_init_resp(struct http_resp_header *resp);
nuclear@5 44 int http_add_resp_field(struct http_resp_header *resp, const char *fmt, ...);
nuclear@5 45 void http_destroy_resp(struct http_resp_header *resp);
nuclear@5 46 int http_serialize_resp(struct http_resp_header *resp, char *buf);
nuclear@5 47
nuclear@2 48 const char *http_strmsg(int code);
nuclear@2 49
nuclear@1 50 #endif /* HTTP_H_ */