Blob


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