From 16481ec708ff41a51d6fc1d77144223c1fc9fba7 Mon Sep 17 00:00:00 2001 From: SuperNovaa41 Date: Wed, 29 Jan 2025 09:52:34 -0500 Subject: [PATCH] changes version from a double to a struct containing major and minor --- src/http.c | 19 ++++++++++++++++--- src/include/http.h | 7 ++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/http.c b/src/http.c index 9239acf..4370595 100644 --- a/src/http.c +++ b/src/http.c @@ -46,7 +46,7 @@ const char* http_method_to_str(http_method_t input) void parse_request_line(char** line, http_request* request) { - char *tok, *ver; + char *tok, *ver, *num; tok = strtok(*line, " "); // this is the method @@ -80,8 +80,21 @@ void parse_request_line(char** line, http_request* request) perror("strtok"); exit(EXIT_FAILURE); } - - request->version = atof(ver); + + + num = strtok(ver, "."); + if (tok == NULL) { + perror("strtok"); + exit(EXIT_FAILURE); + } + request->version.major = atoi(num); + + num = strtok(NULL, "."); + if (tok == NULL) { + perror("strtok"); + exit(EXIT_FAILURE); + } + request->version.minor = atoi(num); } void parse_http_request(char** buffer, http_request* request) diff --git a/src/include/http.h b/src/include/http.h index 832bbc8..01ce7d0 100644 --- a/src/include/http.h +++ b/src/include/http.h @@ -7,10 +7,15 @@ typedef enum { UNKNOWN, } http_method_t; +struct http_version { + int major; + int minor; +}; + typedef struct { http_method_t method; char* request_uri; - double version; + struct http_version version; } http_request;