diff options
-rw-r--r-- | pttbbs/include/buffer.h | 23 | ||||
-rw-r--r-- | pttbbs/include/thttp.h | 26 |
2 files changed, 49 insertions, 0 deletions
diff --git a/pttbbs/include/buffer.h b/pttbbs/include/buffer.h new file mode 100644 index 00000000..6a004a68 --- /dev/null +++ b/pttbbs/include/buffer.h @@ -0,0 +1,23 @@ +#ifndef BUFFER_H +# define BUFFER_H +#include <stdint.h> + +#define BUFFER_MIN_INCREMENT (4096) + +typedef struct buffer { + int allocated; + int length; + uint8_t *pool; +} BUFFER; + +int buffer_init(BUFFER *b, int initial_size); +int buffer_cleanup(BUFFER *b); +int buffer_append(BUFFER *b, const void *data, int size); +int buffer_grow(BUFFER *b, int desired_size); +int buffer_length(BUFFER *b); +void *buffer_get(BUFFER *b, int offset); +int buffer_read_from_func( + BUFFER *b, int (*readfunc)(void *ctx, void *buf, int maxread), + void *ctx); + +#endif diff --git a/pttbbs/include/thttp.h b/pttbbs/include/thttp.h new file mode 100644 index 00000000..7e5fb88d --- /dev/null +++ b/pttbbs/include/thttp.h @@ -0,0 +1,26 @@ +#ifndef THTTP_H +# define THTTP_H + +typedef struct THTTP { + int fd; + int (*read)(struct THTTP *t, void *buffer, int size); + int (*write)(struct THTTP *t, const void *buffer, int size); + BUFFER bresp; + int code; + int content_at; + int content_length; + int failed; + int timeout_read; + int timeout_connect; +} THTTP; + +int thttp_init(THTTP *t); +int thttp_cleanup(THTTP *t); +void thttp_set_connect_timeout(THTTP *t, int microsecond); +void thttp_set_io_timeout(THTTP *t, int microsecond); +int thttp_get(THTTP *t, const char *addr, const char *uri, const char *host); +int thttp_code(THTTP *t); +void *thttp_get_content(THTTP *t); +int thttp_content_length(THTTP *t); + +#endif |