summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-08-26 18:51:11 -0400
committerPaul Duncan <pabs@pablotron.org>2016-08-26 18:51:11 -0400
commit8a3c72fdaabdc8c565a8c91361a2f8d38c892e1e (patch)
tree44d11e53a0345844b2d44319e5ad648454e249d4 /include
downloadlibfhp-8a3c72fdaabdc8c565a8c91361a2f8d38c892e1e.tar.bz2
libfhp-8a3c72fdaabdc8c565a8c91361a2f8d38c892e1e.zip
initial commit
Diffstat (limited to 'include')
-rw-r--r--include/fhp/fhp.h97
1 files changed, 97 insertions, 0 deletions
diff --git a/include/fhp/fhp.h b/include/fhp/fhp.h
new file mode 100644
index 0000000..4a54e3c
--- /dev/null
+++ b/include/fhp/fhp.h
@@ -0,0 +1,97 @@
+#ifndef FHP_H_
+#define FHP_H
+
+#include <stdint.h> // for uint8_t
+#include <stddef.h> // for size_t
+#include <stdbool.h> // for size_t
+
+typedef enum {
+ FHP_TOKEN_METHOD_START,
+ FHP_TOKEN_METHOD_FRAGMENT,
+ FHP_TOKEN_METHOD_END,
+
+ FHP_TOKEN_URL_START,
+ FHP_TOKEN_URL_FRAGMENT,
+ FHP_TOKEN_URL_END,
+
+ FHP_TOKEN_VERSION_START,
+ FHP_TOKEN_VERSION_FRAGMENT,
+ FHP_TOKEN_VERSION_END,
+
+ FHP_TOKEN_HEADER_NAME_START,
+ FHP_TOKEN_HEADER_NAME_FRAGMENT,
+ FHP_TOKEN_HEADER_NAME_END,
+
+ FHP_TOKEN_HEADER_VALUE_START,
+ FHP_TOKEN_HEADER_VALUE_FRAGMENT,
+ FHP_TOKEN_HEADER_VALUE_END,
+
+ FHP_TOKEN_LAST
+} fhp_token_t;
+
+typedef struct fhp_t_ fhp_t;
+
+typedef bool (*fhp_cb_t)(
+ fhp_t * const,
+ fhp_token_t,
+ uint8_t * const,
+ size_t
+);
+
+typedef enum {
+ FHP_STATE_INIT,
+ FHP_STATE_ERROR,
+ FHP_STATE_METHOD,
+ FHP_STATE_METHOD_END,
+ FHP_STATE_URL,
+ FHP_STATE_URL_END,
+ FHP_STATE_VERSION,
+ FHP_STATE_VERSION_END,
+ FHP_STATE_VERSION_END_CR,
+ FHP_STATE_STATUS_END,
+ FHP_STATE_STATUS_END_CR,
+ FHP_STATE_HEADER_NAME,
+ FHP_STATE_HEADER_NAME_END,
+ FHP_STATE_HEADER_NAME_END_CR,
+ FHP_STATE_HEADER_VALUE,
+ FHP_STATE_HEADER_VALUE_END_CR,
+ FHP_STATE_HEADER_VALUE_END,
+ FHP_STATE_HEADERS_END,
+ FHP_STATE_HEADERS_END_CR,
+ FHP_STATE_LAST
+} fhp_state_t;
+
+typedef enum {
+ FHP_OK,
+ FHP_ERR_CB,
+ FHP_ERR_BAD_STATE,
+ FHP_ERR_INVALID_CHAR,
+ FHP_ERR_INVALID_ERROR,
+ FHP_ERR_BUFFER_TOO_SMALL,
+ FHP_ERR_LAST
+} fhp_err_t;
+
+fhp_err_t
+fhp_strerror(fhp_err_t, char * const, size_t);
+
+#define FHP_BUF_SIZE 1024
+
+struct fhp_t_ {
+ fhp_state_t state;
+ fhp_cb_t cb;
+ uint64_t ofs;
+ fhp_err_t err;
+
+ void *user_data;
+
+ uint8_t buf[FHP_BUF_SIZE];
+ size_t buf_len;
+};
+
+fhp_err_t
+fhp_init(fhp_t * const, fhp_cb_t, void * const);
+
+fhp_err_t
+fhp_push(fhp_t * const, uint8_t * const, size_t);
+
+#endif /* FHP_H */