Blame


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