diff --git a/http_parser.c b/http_parser.c index 2f4cd59..ebfccbb 100644 --- a/http_parser.c +++ b/http_parser.c @@ -34,11 +34,14 @@ #if HTTP_PARSER_DEBUG #define SET_ERRNO(e) \ do { \ - parser->state = 0x80 | (e); \ + parser->errno = (e); \ parser->error_lineno = __LINE__; \ } while (0) #else -#define SET_ERRNO(e) do { parser->state = 0x80 | (e); } while(0) +#define SET_ERRNO(e) \ +do { \ + parser->errno = (e); \ +} while(0) #endif @@ -373,9 +376,7 @@ size_t http_parser_execute (http_parser *parser, uint64_t index = parser->index; uint64_t nread = parser->nread; - /* We're in an error state. Don't attempt to do anything lest we overwrite - * the error information that landed us here. - */ + /* We're in an error state. Don't bother doing anything. */ if (HTTP_PARSER_ERRNO(parser) != HPE_OK) { return 0; } @@ -1795,6 +1796,7 @@ http_parser_init (http_parser *parser, enum http_parser_type t) parser->upgrade = 0; parser->flags = 0; parser->method = 0; + parser->errno = 0; } const char * diff --git a/http_parser.h b/http_parser.h index 6e8cf4d..0d2ea47 100644 --- a/http_parser.h +++ b/http_parser.h @@ -150,7 +150,7 @@ enum flags XX(CB_header_field, "the on_header_field callback failed") \ XX(CB_header_value, "the on_header_value callback failed") \ XX(CB_headers_complete, "the on_headers_complete callback failed") \ - XX(CB_body, "th on_body callback failed") \ + XX(CB_body, "the on_body callback failed") \ XX(CB_message_complete, "the on_message_complete callback failed") \ \ /* Parsing-related errors */ \ @@ -189,9 +189,7 @@ enum http_errno { /* Get an http_errno value from an http_parser */ -#define HTTP_PARSER_ERRNO(p) \ - ((enum http_errno) (((p)->state & 0x80) ? (p)->state & ~0x80 : 0)) - +#define HTTP_PARSER_ERRNO(p) ((enum http_errno) (p)->errno) /* Get the line number that generated the current error */ #if HTTP_PARSER_DEBUG @@ -217,13 +215,14 @@ struct http_parser { unsigned short http_minor; unsigned short status_code; /* responses only */ unsigned char method; /* requests only */ + unsigned char errno : 7; /* 1 = Upgrade header was present and the parser has exited because of that. * 0 = No upgrade header present. * Should be checked when http_parser_execute() returns in addition to * error checking. */ - char upgrade; + char upgrade : 1; #if HTTP_PARSER_DEBUG uint32_t error_lineno;