summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/buffer.h19
-rw-r--r--include/http.h41
-rw-r--r--include/linked_list.h9
-rw-r--r--include/server.h6
-rw-r--r--include/util.h12
5 files changed, 87 insertions, 0 deletions
diff --git a/include/buffer.h b/include/buffer.h
new file mode 100644
index 0000000..dd4530c
--- /dev/null
+++ b/include/buffer.h
@@ -0,0 +1,19 @@
+#ifndef _BUFFER_H_
+#define _BUFFER_H_
+
+#include <stdlib.h>
+
+struct buffer {
+ char *data;
+ size_t len;
+ size_t size;
+};
+
+struct buffer *buf_new(const char *init);
+void buf_del(struct buffer **buf);
+struct buffer *buf_dup(struct buffer *src);
+char *buf_strdup(struct buffer *buf);
+void buf_append(struct buffer *buf, const char *str);
+void buf_printf(struct buffer *buf, char *fmt, ...);
+
+#endif
diff --git a/include/http.h b/include/http.h
new file mode 100644
index 0000000..c550b15
--- /dev/null
+++ b/include/http.h
@@ -0,0 +1,41 @@
+#ifndef _HTTP_H_
+#define _HTTP_H_
+#include <stdbool.h>
+
+#include "buffer.h"
+
+//static const char *supported_http_versions[] = { "1.1" };
+
+struct header_item;
+#define MAX_HEADERS 512
+struct header_list {
+ struct header_item *items[MAX_HEADERS];
+};
+
+struct request {
+ char http_version[4];
+ char *method;
+ char *path;
+ char *query;
+ char *body;
+ char *data;
+ struct header_list header;
+};
+
+struct reply {
+ int status;
+ char *body;
+};
+
+typedef struct reply *(request_callback)(struct request *, void *);
+
+struct http;
+
+struct http *http_init(void);
+bool http_register_handler(struct http *http, char *method, char *path,
+ void *data, request_callback *callback);
+struct reply *http_handle_request(struct http *http, struct buffer *req);
+struct buffer *http_build_reply(struct reply *reply);
+const char *http_get_header(struct request *req, const char *key);
+
+#endif
diff --git a/include/linked_list.h b/include/linked_list.h
new file mode 100644
index 0000000..e591e94
--- /dev/null
+++ b/include/linked_list.h
@@ -0,0 +1,9 @@
+#ifndef _LINKED_LIST_H_
+#define _LINKED_LIST_H_
+
+struct linked_list {
+ void *data;
+
+};
+
+#endif
diff --git a/include/server.h b/include/server.h
new file mode 100644
index 0000000..e59c38d
--- /dev/null
+++ b/include/server.h
@@ -0,0 +1,6 @@
+#ifndef _SERVER_H_
+#define _SERVER_H_
+
+
+
+#endif
diff --git a/include/util.h b/include/util.h
new file mode 100644
index 0000000..c4856db
--- /dev/null
+++ b/include/util.h
@@ -0,0 +1,12 @@
+#ifndef _UTIL_H_
+#define _UTIL_H_
+
+#include <stdarg.h>
+#include <stdlib.h>
+
+int vasprintf(char **dest, const char *fmt, va_list ap);
+int asprintf(char **dest, const char *fmt, ...);
+
+size_t hash(const char *str, int max_val);
+
+#endif