http: Remove unused code
parent
c0b3e16bb0
commit
a179c83f81
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define URL_INDEX_MAX 32
|
|
||||||
#define URL_QUERY_INDEX_MAX 32
|
|
||||||
#define HTTP_FIELD_INDEX_MAX 32
|
#define HTTP_FIELD_INDEX_MAX 32
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
@ -38,15 +36,9 @@ struct http_req {
|
||||||
size_t header_length;
|
size_t header_length;
|
||||||
size_t content_length;
|
size_t content_length;
|
||||||
char* content_type;
|
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;
|
size_t field_index;
|
||||||
struct http_kv field[HTTP_FIELD_INDEX_MAX];
|
struct http_kv field[HTTP_FIELD_INDEX_MAX];
|
||||||
};
|
};
|
||||||
|
|
||||||
int http_req_parse(struct http_req* req, const char* head);
|
int http_req_parse(struct http_req* req, const char* head);
|
||||||
void http_req_free(struct http_req* req);
|
void http_req_free(struct http_req* req);
|
||||||
|
|
||||||
const char* http_req_query(struct http_req* req, const char* key);
|
|
||||||
|
|
72
src/http.c
72
src/http.c
|
@ -329,68 +329,17 @@ static int http__url_path(struct http_req* req, struct httplex* lex)
|
||||||
if (tok->type != HTTPLEX_LITERAL)
|
if (tok->type != HTTPLEX_LITERAL)
|
||||||
return tok->type == HTTPLEX_WS;
|
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);
|
httplex_accept_token(lex);
|
||||||
|
|
||||||
return http__peek(lex, HTTPLEX_SOLIDUS)
|
return http__peek(lex, HTTPLEX_SOLIDUS)
|
||||||
? http__url_path(req, lex) : 1;
|
? 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)
|
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__expect(lex, HTTPLEX_EQ)
|
||||||
&& http__url_query_value(req, lex)
|
&& http__expect(lex, HTTPLEX_LITERAL)
|
||||||
&& http__expect(lex, HTTPLEX_AMPERSAND)
|
&& http__expect(lex, HTTPLEX_AMPERSAND)
|
||||||
? http__url_query(req, lex) : 1;
|
? http__url_query(req, lex) : 1;
|
||||||
}
|
}
|
||||||
|
@ -548,25 +497,8 @@ void http_req_free(struct http_req* req)
|
||||||
{
|
{
|
||||||
free(req->content_type);
|
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) {
|
for (size_t i = 0; i < req->field_index; ++i) {
|
||||||
free(req->field[i].key);
|
free(req->field[i].key);
|
||||||
free(req->field[i].value);
|
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;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue