Break out errno into its own field.

v0.6
Peter Griess 14 years ago
parent 1786fdae36
commit 761a5eaeb1

@ -34,11 +34,14 @@
#if HTTP_PARSER_DEBUG #if HTTP_PARSER_DEBUG
#define SET_ERRNO(e) \ #define SET_ERRNO(e) \
do { \ do { \
parser->state = 0x80 | (e); \ parser->errno = (e); \
parser->error_lineno = __LINE__; \ parser->error_lineno = __LINE__; \
} while (0) } while (0)
#else #else
#define SET_ERRNO(e) do { parser->state = 0x80 | (e); } while(0) #define SET_ERRNO(e) \
do { \
parser->errno = (e); \
} while(0)
#endif #endif
@ -373,9 +376,7 @@ size_t http_parser_execute (http_parser *parser,
uint64_t index = parser->index; uint64_t index = parser->index;
uint64_t nread = parser->nread; uint64_t nread = parser->nread;
/* We're in an error state. Don't attempt to do anything lest we overwrite /* We're in an error state. Don't bother doing anything. */
* the error information that landed us here.
*/
if (HTTP_PARSER_ERRNO(parser) != HPE_OK) { if (HTTP_PARSER_ERRNO(parser) != HPE_OK) {
return 0; return 0;
} }
@ -1795,6 +1796,7 @@ http_parser_init (http_parser *parser, enum http_parser_type t)
parser->upgrade = 0; parser->upgrade = 0;
parser->flags = 0; parser->flags = 0;
parser->method = 0; parser->method = 0;
parser->errno = 0;
} }
const char * const char *

@ -150,7 +150,7 @@ enum flags
XX(CB_header_field, "the on_header_field callback failed") \ XX(CB_header_field, "the on_header_field callback failed") \
XX(CB_header_value, "the on_header_value callback failed") \ XX(CB_header_value, "the on_header_value callback failed") \
XX(CB_headers_complete, "the on_headers_complete 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") \ XX(CB_message_complete, "the on_message_complete callback failed") \
\ \
/* Parsing-related errors */ \ /* Parsing-related errors */ \
@ -189,9 +189,7 @@ enum http_errno {
/* Get an http_errno value from an http_parser */ /* Get an http_errno value from an http_parser */
#define HTTP_PARSER_ERRNO(p) \ #define HTTP_PARSER_ERRNO(p) ((enum http_errno) (p)->errno)
((enum http_errno) (((p)->state & 0x80) ? (p)->state & ~0x80 : 0))
/* Get the line number that generated the current error */ /* Get the line number that generated the current error */
#if HTTP_PARSER_DEBUG #if HTTP_PARSER_DEBUG
@ -217,13 +215,14 @@ struct http_parser {
unsigned short http_minor; unsigned short http_minor;
unsigned short status_code; /* responses only */ unsigned short status_code; /* responses only */
unsigned char method; /* requests only */ unsigned char method; /* requests only */
unsigned char errno : 7;
/* 1 = Upgrade header was present and the parser has exited because of that. /* 1 = Upgrade header was present and the parser has exited because of that.
* 0 = No upgrade header present. * 0 = No upgrade header present.
* Should be checked when http_parser_execute() returns in addition to * Should be checked when http_parser_execute() returns in addition to
* error checking. * error checking.
*/ */
char upgrade; char upgrade : 1;
#if HTTP_PARSER_DEBUG #if HTTP_PARSER_DEBUG
uint32_t error_lineno; uint32_t error_lineno;

Loading…
Cancel
Save