diff --git a/backend/GNUmakefile b/backend/GNUmakefile deleted file mode 100644 index 17d28d3..0000000 --- a/backend/GNUmakefile +++ /dev/null @@ -1,19 +0,0 @@ - -CFLAGS = -std=c17 -Wall -Wextra -Wpedantic -Wconversion - -HEADERS = $(wildcard *.h) - -all: compile_flags.txt server - -server: main.o linux.o - gcc $^ -o $@ - -%.o: %.c $(HEADERS) - gcc $< -c -o $@ $(CFLAGS) - -clean: - rm -rf *.o server client - -compile_flags.txt: - echo -xc $(CFLAGS) | sed 's/\s\+/\n/g' > compile_flags.txt - diff --git a/backend/Makefile b/backend/Makefile index 5a26094..ebfdd98 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -1,12 +1,19 @@ -OBJS=main.obj windows.obj +CFLAGS = -std=c17 -Wall -Wextra -Wpedantic -Wconversion -all: $(OBJS) - link /out:server.exe $(OBJS) WS2_32.lib +HEADERS = $(wildcard *.h) -.obj: - cl $*.c +all: compile_flags.txt server + +server: main.o linux.o http.o + gcc $^ -o $@ + +%.o: %.c $(HEADERS) + gcc $< -c -o $@ $(CFLAGS) clean: - del *.obj server.exe + rm -rf *.o server client + +compile_flags.txt: + echo -xc $(CFLAGS) | sed 's/\s\+/\n/g' > compile_flags.txt diff --git a/backend/NMakefile b/backend/NMakefile new file mode 100644 index 0000000..5a26094 --- /dev/null +++ b/backend/NMakefile @@ -0,0 +1,12 @@ + +OBJS=main.obj windows.obj + +all: $(OBJS) + link /out:server.exe $(OBJS) WS2_32.lib + +.obj: + cl $*.c + +clean: + del *.obj server.exe + diff --git a/backend/http.c b/backend/http.c new file mode 100644 index 0000000..5ad2e5b --- /dev/null +++ b/backend/http.c @@ -0,0 +1,26 @@ +#include "http.h" +#include + +HttpRequestHeader parse_http_request_header(const char* message, size_t message_size) +{ + size_t i = 0; + + // parse method + HttpMethod method; + if (i + 3 < message_size && strncmp(&message[0], "GET", 3)) { + method = HttpMethodGet; + i += 3; + } else if (i + 4 < message_size && strncmp(&message[0], "POST", 4)) { + method = HttpMethodPost; + i += 4; + } else { + printf("error: header parse fail #1\n"); + exit(1); + } + + // skip space + i += 1; + if (i >= message_size) { } + + return (HttpRequestHeader) { 0 }; +} diff --git a/backend/http.h b/backend/http.h new file mode 100644 index 0000000..b4e8e35 --- /dev/null +++ b/backend/http.h @@ -0,0 +1,19 @@ +#ifndef HTTP_H +#define HTTP_H + +#include + +typedef enum { + HttpMethodGet, + HttpMethodPost, +} HttpMethod; + +typedef struct { + HttpMethod method; + size_t path_index, path_length; + size_t content_length; +} HttpRequestHeader; + +HttpRequestHeader parse_http_request_header(const char* message, size_t message_size); + +#endif diff --git a/backend/main.c b/backend/main.c index b908f69..59db0f7 100644 --- a/backend/main.c +++ b/backend/main.c @@ -1,46 +1,10 @@ +#include "native.h" #include #include #include #include #include -#include "native.h" - -typedef enum { - HttpMethodGet, - HttpMethodPost, -} HttpMethod; - -typedef struct { - HttpMethod method; - size_t path_index, path_length; - size_t content_length; -} HttpRequestHeader; - -HttpRequestHeader parse_http_request_header(const char* message, size_t message_size) -{ - size_t i = 0; - - // parse method - HttpMethod method; - if (i + 3 < message_size && strncmp(&message[0], "GET", 3)) { - method = HttpMethodGet; - i += 3; - } else if (i + 4 < message_size && strncmp(&message[0], "POST", 4)) { - method = HttpMethodPost; - i += 4; - } else { - printf("error: header parse fail #1\n"); - exit(1); - } - - // skip space - i += 1; - if (i >= message_size) { } - - return (HttpRequestHeader) { 0 }; -} - const uint16_t port = 8000; int main(void)