Blame


1 04e4e993 2023-08-14 op /*
2 04e4e993 2023-08-14 op * Copyright (c) 2023 Omar Polo <op@omarpolo.com>
3 04e4e993 2023-08-14 op *
4 04e4e993 2023-08-14 op * Permission to use, copy, modify, and distribute this software for any
5 04e4e993 2023-08-14 op * purpose with or without fee is hereby granted, provided that the above
6 04e4e993 2023-08-14 op * copyright notice and this permission notice appear in all copies.
7 04e4e993 2023-08-14 op *
8 04e4e993 2023-08-14 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 04e4e993 2023-08-14 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 04e4e993 2023-08-14 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 04e4e993 2023-08-14 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 04e4e993 2023-08-14 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 04e4e993 2023-08-14 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 04e4e993 2023-08-14 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 04e4e993 2023-08-14 op */
16 04e4e993 2023-08-14 op
17 04e4e993 2023-08-14 op enum http_method {
18 04e4e993 2023-08-14 op METHOD_UNKNOWN,
19 04e4e993 2023-08-14 op METHOD_GET,
20 04e4e993 2023-08-14 op METHOD_POST,
21 04e4e993 2023-08-14 op };
22 04e4e993 2023-08-14 op
23 c83e450a 2023-08-14 op enum http_version {
24 c83e450a 2023-08-14 op HTTP_1_0,
25 c83e450a 2023-08-14 op HTTP_1_1,
26 c83e450a 2023-08-14 op };
27 c83e450a 2023-08-14 op
28 04e4e993 2023-08-14 op struct request {
29 04e4e993 2023-08-14 op char buf[BUFSIZ];
30 04e4e993 2023-08-14 op size_t len;
31 04e4e993 2023-08-14 op
32 04e4e993 2023-08-14 op char *path;
33 04e4e993 2023-08-14 op int method;
34 c83e450a 2023-08-14 op int version;
35 04e4e993 2023-08-14 op char *ctype;
36 04e4e993 2023-08-14 op size_t clen;
37 04e4e993 2023-08-14 op };
38 04e4e993 2023-08-14 op
39 04e4e993 2023-08-14 op struct reswriter {
40 04e4e993 2023-08-14 op int fd;
41 04e4e993 2023-08-14 op int err;
42 04e4e993 2023-08-14 op int chunked;
43 04e4e993 2023-08-14 op char buf[BUFSIZ];
44 04e4e993 2023-08-14 op size_t len;
45 04e4e993 2023-08-14 op };
46 04e4e993 2023-08-14 op
47 04e4e993 2023-08-14 op int http_parse(struct request *, int);
48 04e4e993 2023-08-14 op int http_read(struct request *, int);
49 c83e450a 2023-08-14 op void http_response_init(struct reswriter *, struct request *, int);
50 04e4e993 2023-08-14 op int http_reply(struct reswriter *, int, const char *, const char *);
51 04e4e993 2023-08-14 op int http_flush(struct reswriter *);
52 04e4e993 2023-08-14 op int http_write(struct reswriter *, const char *, size_t);
53 04e4e993 2023-08-14 op int http_writes(struct reswriter *, const char *);
54 04e4e993 2023-08-14 op int http_fmt(struct reswriter *, const char *, ...);
55 04e4e993 2023-08-14 op int http_urlescape(struct reswriter *, const char *);
56 04e4e993 2023-08-14 op int http_htmlescape(struct reswriter *, const char *);
57 04e4e993 2023-08-14 op int http_close(struct reswriter *);
58 04e4e993 2023-08-14 op void http_free_request(struct request *);