Blame


1 7a554149 2024-02-18 op /*
2 7a554149 2024-02-18 op * This is free and unencumbered software released into the public domain.
3 7a554149 2024-02-18 op *
4 7a554149 2024-02-18 op * Anyone is free to copy, modify, publish, use, compile, sell, or
5 7a554149 2024-02-18 op * distribute this software, either in source code form or as a compiled
6 7a554149 2024-02-18 op * binary, for any purpose, commercial or non-commercial, and by any
7 7a554149 2024-02-18 op * means.
8 7a554149 2024-02-18 op *
9 7a554149 2024-02-18 op * In jurisdictions that recognize copyright laws, the author or authors
10 7a554149 2024-02-18 op * of this software dedicate any and all copyright interest in the
11 7a554149 2024-02-18 op * software to the public domain. We make this dedication for the benefit
12 7a554149 2024-02-18 op * of the public at large and to the detriment of our heirs and
13 7a554149 2024-02-18 op * successors. We intend this dedication to be an overt act of
14 7a554149 2024-02-18 op * relinquishment in perpetuity of all present and future rights to this
15 7a554149 2024-02-18 op * software under copyright law.
16 7a554149 2024-02-18 op *
17 7a554149 2024-02-18 op * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 7a554149 2024-02-18 op * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 7a554149 2024-02-18 op * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 7a554149 2024-02-18 op * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 7a554149 2024-02-18 op * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 7a554149 2024-02-18 op * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 7a554149 2024-02-18 op * OTHER DEALINGS IN THE SOFTWARE.
24 7a554149 2024-02-18 op */
25 7a554149 2024-02-18 op
26 7a554149 2024-02-18 op struct tls;
27 7a554149 2024-02-18 op
28 7a554149 2024-02-18 op #define BIO_CHUNK 128
29 7a554149 2024-02-18 op struct buf {
30 7a554149 2024-02-18 op uint8_t *buf;
31 7a554149 2024-02-18 op size_t len;
32 7a554149 2024-02-18 op size_t cap;
33 7a554149 2024-02-18 op size_t cur;
34 7a554149 2024-02-18 op };
35 7a554149 2024-02-18 op
36 7a554149 2024-02-18 op struct bufio {
37 7a554149 2024-02-18 op int fd;
38 7a554149 2024-02-18 op struct tls *ctx;
39 c4d1f652 2024-03-25 op int wantev;
40 7a554149 2024-02-18 op struct buf wbuf;
41 7a554149 2024-02-18 op struct buf rbuf;
42 7a554149 2024-02-18 op };
43 7a554149 2024-02-18 op
44 ce023433 2024-02-22 op #define BUFIO_WANT_READ 0x1
45 ce023433 2024-02-22 op #define BUFIO_WANT_WRITE 0x2
46 ce023433 2024-02-22 op
47 7a554149 2024-02-18 op int buf_init(struct buf *);
48 7a554149 2024-02-18 op int buf_has_line(struct buf *, const char *);
49 98f8e538 2024-03-22 op char *buf_getdelim(struct buf *, const char *, size_t *);
50 7a554149 2024-02-18 op void buf_drain(struct buf *, size_t);
51 7a554149 2024-02-18 op void buf_drain_line(struct buf *, const char *);
52 7a554149 2024-02-18 op void buf_free(struct buf *);
53 7a554149 2024-02-18 op
54 7a554149 2024-02-18 op int bufio_init(struct bufio *);
55 0d6af421 2024-02-18 op void bufio_free(struct bufio *);
56 8b00d570 2024-02-18 op int bufio_close(struct bufio *);
57 7a554149 2024-02-18 op int bufio_reset(struct bufio *);
58 7a554149 2024-02-18 op void bufio_set_fd(struct bufio *, int);
59 9c5586a7 2024-02-18 op int bufio_starttls(struct bufio *, const char *, int,
60 9c5586a7 2024-02-18 op const uint8_t *, size_t, const uint8_t *, size_t);
61 3c988896 2024-02-18 op int bufio_ev(struct bufio *);
62 0e0994b2 2024-02-18 op int bufio_handshake(struct bufio *);
63 7a554149 2024-02-18 op ssize_t bufio_read(struct bufio *);
64 b19b8dbc 2024-02-18 op size_t bufio_drain(struct bufio *, void *, size_t);
65 7a554149 2024-02-18 op ssize_t bufio_write(struct bufio *);
66 7a554149 2024-02-18 op int bufio_compose(struct bufio *, const void *, size_t);
67 7a554149 2024-02-18 op int bufio_compose_str(struct bufio *, const char *);
68 7a554149 2024-02-18 op int bufio_compose_fmt(struct bufio *, const char *, ...)
69 7a554149 2024-02-18 op __attribute__((__format__ (printf, 2, 3)));
70 7a554149 2024-02-18 op void bufio_rewind_cursor(struct bufio *);
71 7a554149 2024-02-18 op
72 7a554149 2024-02-18 op /* callbacks for pdjson */
73 7a554149 2024-02-18 op int bufio_get_cb(void *);
74 7a554149 2024-02-18 op int bufio_peek_cb(void *);