diff --git a/http_parser.c b/http_parser.c index 6e1198b..495e025 100644 --- a/http_parser.c +++ b/http_parser.c @@ -46,15 +46,20 @@ do { \ #define MARK(FOR) \ do { \ parser->FOR##_mark = p; \ - parser->FOR##_size = 0; \ + parser->current_mark_size = 0; \ +} while (0) + +#define MARK_NOSIZECLEAR(FOR) \ +do { \ + parser->FOR##_mark = p; \ } while (0) #define CALLBACK_NOCLEAR(FOR) \ do { \ if (parser->FOR##_mark) { \ - parser->FOR##_size += p - parser->FOR##_mark; \ - if (parser->FOR##_size > MAX_FIELD_SIZE) return (p - data); \ + parser->current_mark_size += p - parser->FOR##_mark; \ + if (parser->current_mark_size > MAX_FIELD_SIZE) return (p - data); \ if (settings->on_##FOR) { \ if (0 != settings->on_##FOR(parser, \ parser->FOR##_mark, \ @@ -650,7 +655,7 @@ size_t http_parser_execute (http_parser *parser, if (ch == '/') { MARK(url); - MARK(path); + MARK_NOSIZECLEAR(path); state = s_req_path; break; } @@ -700,7 +705,7 @@ size_t http_parser_execute (http_parser *parser, state = s_req_port; break; case '/': - MARK(path); + MARK_NOSIZECLEAR(path); state = s_req_path; break; case ' ': @@ -722,7 +727,7 @@ size_t http_parser_execute (http_parser *parser, if (ch >= '0' && ch <= '9') break; switch (ch) { case '/': - MARK(path); + MARK_NOSIZECLEAR(path); state = s_req_path; break; case ' ': @@ -778,7 +783,7 @@ size_t http_parser_execute (http_parser *parser, case s_req_query_string_start: { if (USUAL(ch)) { - MARK(query_string); + MARK_NOSIZECLEAR(query_string); state = s_req_query_string; break; } @@ -847,7 +852,7 @@ size_t http_parser_execute (http_parser *parser, case s_req_fragment_start: { if (USUAL(ch)) { - MARK(fragment); + MARK_NOSIZECLEAR(fragment); state = s_req_fragment; break; } @@ -868,7 +873,7 @@ size_t http_parser_execute (http_parser *parser, state = s_header_field_start; break; case '?': - MARK(fragment); + MARK_NOSIZECLEAR(fragment); state = s_req_fragment; break; case '#': diff --git a/http_parser.h b/http_parser.h index 4f5a420..de6d66d 100644 --- a/http_parser.h +++ b/http_parser.h @@ -112,18 +112,13 @@ struct http_parser { ssize_t body_read; ssize_t content_length; + size_t current_mark_size; const char *header_field_mark; - size_t header_field_size; const char *header_value_mark; - size_t header_value_size; const char *query_string_mark; - size_t query_string_size; const char *path_mark; - size_t path_size; const char *url_mark; - size_t url_size; const char *fragment_mark; - size_t fragment_size; /** READ-ONLY **/ unsigned short status_code; /* responses only */