diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9b83028 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +CC = gcc +CFLAGS = -Wall -Wpedantic +LD = gcc +LDFLAGS = + +BIN_NAME = cfloor + +all: $(BIN_NAME) + +test: obj/test.o obj/networking.o + $(LD) -o $@ $^ + +obj/networking.o: src/networking.h src/headers.h + +obj/%.o: src/%.c obj + $(CC) -c -o $@ $< + +obj: + @mkdir -p obj + +clean: + @echo "Cleaning up..." + @rm -f obj/*.o + @rm -f test + @rm -f $(BIN_NAME) diff --git a/src/auth.c b/src/auth.c new file mode 100644 index 0000000..e69de29 diff --git a/src/auth.h b/src/auth.h new file mode 100644 index 0000000..e69de29 diff --git a/src/cgi.c b/src/cgi.c new file mode 100644 index 0000000..e69de29 diff --git a/src/cgi.h b/src/cgi.h new file mode 100644 index 0000000..e69de29 diff --git a/src/config.c b/src/config.c new file mode 100644 index 0000000..e69de29 diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..e69de29 diff --git a/src/files.c b/src/files.c new file mode 100644 index 0000000..e69de29 diff --git a/src/files.h b/src/files.h new file mode 100644 index 0000000..e69de29 diff --git a/src/headers.c b/src/headers.c new file mode 100644 index 0000000..e69de29 diff --git a/src/headers.h b/src/headers.h new file mode 100644 index 0000000..bb4a403 --- /dev/null +++ b/src/headers.h @@ -0,0 +1,14 @@ +#ifndef HEADERS_H +#define HEADERS_H + +struct header { + char* key; + char* value; +}; + +struct headers { + int number; + struct header* headers; +}; + +#endif diff --git a/src/linked.c b/src/linked.c new file mode 100644 index 0000000..e69de29 diff --git a/src/linked.h b/src/linked.h new file mode 100644 index 0000000..e69de29 diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..86cb63f --- /dev/null +++ b/src/main.c @@ -0,0 +1,7 @@ + + + +int main(int argc, char* argv) { + + +} diff --git a/src/misc.h b/src/misc.h new file mode 100644 index 0000000..583e995 --- /dev/null +++ b/src/misc.h @@ -0,0 +1,34 @@ +#ifndef MISC_H +#define MISC_H + +#include "headers.h" + +enum method { + GET, POST, PUT +}; + +enum httpVersion { + HTTP10, HTTP11 +}; + +struct metaData { + enum method method; + enum httpVersion httpVersion; + char* path; + char* queryString; +}; + +struct request { + struct metaData metaData; + struct headers* headers; + int fd; + void* _private; +}; + +struct response { + int (*sendHeader)(int statusCode, struct headers headers); +}; + +typedef void (*handler_t)(struct request request, struct response response); + +#endif diff --git a/src/networking.c b/src/networking.c new file mode 100644 index 0000000..49b1f34 --- /dev/null +++ b/src/networking.c @@ -0,0 +1,44 @@ +#include +#include + +#include "networking.h" + +struct networkingConfig networkingConfig; + +struct connection connections[MAX_CONNECTIONS]; + +static inline struct connection emptyConnection() { + return (struct connection) { + .used = false, + .connectionState = CLOSED, + .metaData = { + .path = NULL, + .queryString = NULL + }, + .headers = { + .number = 0, + .headers = NULL + }, + .currentHeaderLength = 0, + .fd = -1, + /* + * ignored: + * .metaData.method + * .metaData.httpVersion + * .currentHeader + * .timing.* + */ + }; +} + +void initNetworking(struct networkingConfig _networkingConfig) { + networkingConfig = _networkingConfig; + + for (int i = 0; i < MAX_CONNECTIONS; i++) { + connections[i] = emptyConnection(); + } +} + +void newConnection() { + +} diff --git a/src/networking.h b/src/networking.h new file mode 100644 index 0000000..11e792e --- /dev/null +++ b/src/networking.h @@ -0,0 +1,60 @@ +#ifndef NETWORKING_H +#define NETWORKING_H + +#include +#include + +#include "headers.h" +#include "misc.h" + +#define MAX_CONNECTIONS (512) + +#define NR_CONNECTION_STATE (6) +enum connectionState { + ESTABLISHED = 0, + HEADERS_COMPLETE = 1, + DATA_COMPLETE = 2, + PROCESSING = 3, + ABORTED = 4, + CLOSED = 5, + FREED = 6 +}; + +struct timing { + struct timeval states[NR_CONNECTION_STATE]; + struct timeval lastUpdate; +}; + +struct connection { + bool used; + enum connectionState connectionState; + struct metaData metaData; + struct headers headers; + size_t currentHeaderLength; + char* currentHeader; + int fd; + struct timing timing; +}; + +typedef handler_t (*handlerGetter_t)(struct metaData metaData, const char* host); + +struct bind { + const char* address; + const char* port; +}; + +struct binds { + int number; + struct bind* binds; +}; + +struct networkingConfig { + struct binds binds; + long connectionTimeout; + struct headers defaultResponse; + handlerGetter_t getHandler; +}; + +void initNetworking(struct networkingConfig networkingConfig); + +#endif diff --git a/src/test.c b/src/test.c new file mode 100644 index 0000000..f6a919d --- /dev/null +++ b/src/test.c @@ -0,0 +1,17 @@ +#include + +#include "networking.h" + +handler_t handlerGetter(struct metaData metaData, const char* host) { + return NULL; +} + +int main(int argc, char* argv) { + initNetworking((struct networkingConfig) { + .connectionTimeout = 30000, + .defaultResponse = { + .number = 0 + }, + .getHandler = &handlerGetter + }); +}