stop tracking lengths of returned values

This drops support for MAX_FIELD_SIZE, and saves 4 more bytes in the
parser object (44 bytes total now).
event_stream
Cliff Frey 15 years ago committed by Ryan Dahl
parent 076fa15132
commit 8732d108a4

@ -32,9 +32,6 @@
#endif #endif
#define MAX_FIELD_SIZE (80*1024)
#define CALLBACK2(FOR) \ #define CALLBACK2(FOR) \
do { \ do { \
if (settings->on_##FOR) { \ if (settings->on_##FOR) { \
@ -46,20 +43,11 @@ do { \
#define MARK(FOR) \ #define MARK(FOR) \
do { \ do { \
FOR##_mark = p; \ FOR##_mark = p; \
parser->current_mark_size = 0; \
} while (0) } while (0)
#define MARK_NOSIZECLEAR(FOR) \
do { \
FOR##_mark = p; \
} while (0)
#define CALLBACK_NOCLEAR(FOR) \ #define CALLBACK_NOCLEAR(FOR) \
do { \ do { \
if (FOR##_mark) { \ if (FOR##_mark) { \
parser->current_mark_size += p - FOR##_mark; \
if (parser->current_mark_size > MAX_FIELD_SIZE) return (p - data); \
if (settings->on_##FOR) { \ if (settings->on_##FOR) { \
if (0 != settings->on_##FOR(parser, \ if (0 != settings->on_##FOR(parser, \
FOR##_mark, \ FOR##_mark, \
@ -674,7 +662,7 @@ size_t http_parser_execute (http_parser *parser,
if (ch == '/') { if (ch == '/') {
MARK(url); MARK(url);
MARK_NOSIZECLEAR(path); MARK(path);
state = s_req_path; state = s_req_path;
break; break;
} }
@ -724,7 +712,7 @@ size_t http_parser_execute (http_parser *parser,
state = s_req_port; state = s_req_port;
break; break;
case '/': case '/':
MARK_NOSIZECLEAR(path); MARK(path);
state = s_req_path; state = s_req_path;
break; break;
case ' ': case ' ':
@ -746,7 +734,7 @@ size_t http_parser_execute (http_parser *parser,
if (ch >= '0' && ch <= '9') break; if (ch >= '0' && ch <= '9') break;
switch (ch) { switch (ch) {
case '/': case '/':
MARK_NOSIZECLEAR(path); MARK(path);
state = s_req_path; state = s_req_path;
break; break;
case ' ': case ' ':
@ -802,7 +790,7 @@ size_t http_parser_execute (http_parser *parser,
case s_req_query_string_start: case s_req_query_string_start:
{ {
if (USUAL(ch)) { if (USUAL(ch)) {
MARK_NOSIZECLEAR(query_string); MARK(query_string);
state = s_req_query_string; state = s_req_query_string;
break; break;
} }
@ -871,7 +859,7 @@ size_t http_parser_execute (http_parser *parser,
case s_req_fragment_start: case s_req_fragment_start:
{ {
if (USUAL(ch)) { if (USUAL(ch)) {
MARK_NOSIZECLEAR(fragment); MARK(fragment);
state = s_req_fragment; state = s_req_fragment;
break; break;
} }
@ -892,7 +880,7 @@ size_t http_parser_execute (http_parser *parser,
state = s_header_field_start; state = s_header_field_start;
break; break;
case '?': case '?':
MARK_NOSIZECLEAR(fragment); MARK(fragment);
state = s_req_fragment; state = s_req_fragment;
break; break;
case '#': case '#':

@ -105,8 +105,6 @@ struct http_parser {
ssize_t body_read; ssize_t body_read;
ssize_t content_length; ssize_t content_length;
size_t current_mark_size;
/** READ-ONLY **/ /** READ-ONLY **/
unsigned short status_code; /* responses only */ unsigned short status_code; /* responses only */
unsigned short method; /* requests only */ unsigned short method; /* requests only */

Loading…
Cancel
Save