From a179c83f819587910c540dd49216a1087f40faec Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 30 Apr 2023 14:16:19 +0000 Subject: [PATCH] http: Remove unused code --- include/http.h | 12 ++------- src/http.c | 72 ++------------------------------------------------ 2 files changed, 4 insertions(+), 80 deletions(-) diff --git a/include/http.h b/include/http.h index 84b889a..958a6a4 100644 --- a/include/http.h +++ b/include/http.h @@ -16,8 +16,6 @@ #pragma once -#define URL_INDEX_MAX 32 -#define URL_QUERY_INDEX_MAX 32 #define HTTP_FIELD_INDEX_MAX 32 #include @@ -38,15 +36,9 @@ struct http_req { size_t header_length; size_t content_length; char* content_type; - size_t url_index; - char* url[URL_INDEX_MAX]; - size_t url_query_index; - struct http_kv url_query[URL_QUERY_INDEX_MAX]; - size_t field_index; - struct http_kv field[HTTP_FIELD_INDEX_MAX]; + size_t field_index; + struct http_kv field[HTTP_FIELD_INDEX_MAX]; }; int http_req_parse(struct http_req* req, const char* head); void http_req_free(struct http_req* req); - -const char* http_req_query(struct http_req* req, const char* key); diff --git a/src/http.c b/src/http.c index 3d941a2..2114abe 100644 --- a/src/http.c +++ b/src/http.c @@ -329,68 +329,17 @@ static int http__url_path(struct http_req* req, struct httplex* lex) if (tok->type != HTTPLEX_LITERAL) return tok->type == HTTPLEX_WS; - if (req->url_index >= URL_INDEX_MAX) - return 0; - - char* elem = strdup(tok->value); - if (!elem) - return 0; - - req->url[req->url_index++] = elem; - httplex_accept_token(lex); return http__peek(lex, HTTPLEX_SOLIDUS) ? http__url_path(req, lex) : 1; } -static int http__url_query_key(struct http_req* req, struct httplex* lex) -{ - struct httplex_token* tok = httplex_next_token(lex); - if (!tok) - return 0; - - if (tok->type != HTTPLEX_LITERAL) - return 0; - - if (req->url_index >= URL_INDEX_MAX) - return 0; - - char* elem = strdup(tok->value); - if (!elem) - return 0; - - req->url_query[req->url_query_index].key = elem; - - return httplex_accept_token(lex); -} - -static int http__url_query_value(struct http_req* req, struct httplex* lex) -{ - struct httplex_token* tok = httplex_next_token(lex); - if (!tok) - return 0; - - if (tok->type != HTTPLEX_LITERAL) - return 0; - - if (req->url_index >= URL_INDEX_MAX) - return 0; - - char* elem = strdup(tok->value); - if (!elem) - return 0; - - req->url_query[req->url_query_index++].value = elem; - - return httplex_accept_token(lex); -} - static int http__url_query(struct http_req* req, struct httplex* lex) { - return http__url_query_key(req, lex) + return http__expect(lex, HTTPLEX_LITERAL) && http__expect(lex, HTTPLEX_EQ) - && http__url_query_value(req, lex) + && http__expect(lex, HTTPLEX_LITERAL) && http__expect(lex, HTTPLEX_AMPERSAND) ? http__url_query(req, lex) : 1; } @@ -548,25 +497,8 @@ void http_req_free(struct http_req* req) { free(req->content_type); - for (size_t i = 0; i < req->url_index; ++i) - free(req->url[i]); - - for (size_t i = 0; i < req->url_query_index; ++i) { - free(req->url_query[i].key); - free(req->url_query[i].value); - } - for (size_t i = 0; i < req->field_index; ++i) { free(req->field[i].key); free(req->field[i].value); } } - -const char* http_req_query(struct http_req* req, const char* key) -{ - for (size_t i = 0; i < req->url_query_index; ++i) - if (strcmp(key, req->url_query[i].key) == 0) - return req->url_query[i].value; - - return NULL; -}