diff --git a/source/http.c b/source/http.c index b3f1a2d..9312bd3 100644 --- a/source/http.c +++ b/source/http.c @@ -127,8 +127,18 @@ void HttpRequestHeaderFromS(HttpRequestHeader* rh, char* buffer) { int start, end = 0; + // Initialize the tokenization state + char** saveTokenState; + char* token; + + // Tokenize the request line + token = strtok_r(buffer, " ", saveTokenState); + while ((token = strtok_r(NULL, " ", saveTokenState)) != NULL) { + // Tokenize + } // GET /path/to/file/ HTTP:1.1 + } diff --git a/source/http.h b/source/http.h index 7af9e56..468c8fe 100644 --- a/source/http.h +++ b/source/http.h @@ -35,8 +35,10 @@ #define HTTP_CONTENT_TYPE_IMAGE_PNG "image/png" #define HTTP_CONTENT_TYPE_IMAGE_BMP "image/bmp" + #endif // HTTP_CONTENT_TYPES_H +#define HTTP_RECIVE_PACKET_SIZE 1024 diff --git a/source/main.c b/source/main.c index 670e2f0..a3d1c67 100644 --- a/source/main.c +++ b/source/main.c @@ -25,12 +25,29 @@ void handleClient(int sock) { continue; } + HttpRequestHeader rh; + char packetBuilder[HTTP_RECIVE_PACKET_SIZE] = ""; + + int sizeOfPacket = recv(sock, packetBuilder, HTTP_RECIVE_PACKET_SIZE, 0); + + char* packetBuffer = malloc(sizeOfPacket); + + while ((sizeOfPacket = recv(sock, packetBuilder, HTTP_RECIVE_PACKET_SIZE, 0)) > 0) { + strncat(packetBuffer, packetBuilder, sizeOfPacket); + } + + + HttpRequestHeaderFromS(&rh, packetBuffer); + + free(packetBuffer); + FILE* file = fopen("./web/index.html", "r"); if (file == NULL) { perror("that file dose not exists"); return; } + char* fileBuffer; fseek(file, 0, SEEK_END);