Fix whitespace, clean up some macros.

event_stream
Ryan 15 years ago
parent 152cce76df
commit e244dbf797

@ -1,4 +1,5 @@
Copyright 2009, Ryan Lienhart Dahl. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
@ -17,12 +18,9 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
http_parser is based on Zed Shaw's Mongrel. Mongrel's license is as follows.
-- CUT ---- CUT ---- CUT ---- CUT ---- CUT ---- CUT ---- CUT ---- CUT --
---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ----
Mongrel Web Server (Mongrel) is copyrighted free software by Zed A. Shaw
<zedshaw at zedshaw dot com> and contributors. You can redistribute it
and/or modify it under either the terms of the GPL2 or the conditions below:
@ -76,4 +74,4 @@ and/or modify it under either the terms of the GPL2 or the conditions below:
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.
-- CUT ---- CUT ---- CUT ---- CUT ---- CUT ---- CUT ---- CUT ---- CUT --
---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ----

@ -35,12 +35,14 @@ static int unhex[] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
};
#define TRUE 1
#define FALSE 0
#define MIN(a,b) (a < b ? a : b)
#define NULL (void*)(0)
#define MAX_FIELD_SIZE 80*1024
#undef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#undef NULL
#define NULL ((void*)(0))
#define MAX_FIELD_SIZE (80*1024)
#define REMAINING (unsigned long)(pe - p)
#define CALLBACK(FOR) \
@ -48,7 +50,7 @@ do { \
if (parser->FOR##_mark) { \
parser->FOR##_size += p - parser->FOR##_mark; \
if (parser->FOR##_size > MAX_FIELD_SIZE) { \
parser->error = TRUE; \
parser->error = 1; \
return 0; \
} \
if (parser->on_##FOR) { \
@ -75,7 +77,7 @@ do { \
parser->version_minor = 0; \
parser->keep_alive = -1; \
parser->content_length = 0; \
parser->body_read = 0;
parser->body_read = 0
#define END_REQUEST \
do { \
@ -97,12 +99,12 @@ do { \
parser->body_read += tmp; \
parser->chunk_size -= tmp; \
if (0 == parser->chunk_size) { \
parser->eating = FALSE; \
parser->eating = 0; \
if (parser->transfer_encoding == HTTP_IDENTITY) { \
END_REQUEST; \
} \
} else { \
parser->eating = TRUE; \
parser->eating = 1; \
} \
} \
} while (0)
@ -143,7 +145,7 @@ do { \
action header_field {
CALLBACK(header_field);
if (callback_return_value != 0) {
parser->error = TRUE;
parser->error = 1;
return 0;
}
parser->header_field_mark = NULL;
@ -153,7 +155,7 @@ do { \
action header_value {
CALLBACK(header_value);
if (callback_return_value != 0) {
parser->error = TRUE;
parser->error = 1;
return 0;
}
parser->header_value_mark = NULL;
@ -163,7 +165,7 @@ do { \
action request_uri {
CALLBACK(uri);
if (callback_return_value != 0) {
parser->error = TRUE;
parser->error = 1;
return 0;
}
parser->uri_mark = NULL;
@ -173,7 +175,7 @@ do { \
action fragment {
CALLBACK(fragment);
if (callback_return_value != 0) {
parser->error = TRUE;
parser->error = 1;
return 0;
}
parser->fragment_mark = NULL;
@ -183,7 +185,7 @@ do { \
action query_string {
CALLBACK(query_string);
if (callback_return_value != 0) {
parser->error = TRUE;
parser->error = 1;
return 0;
}
parser->query_string_mark = NULL;
@ -193,7 +195,7 @@ do { \
action request_path {
CALLBACK(path);
if (callback_return_value != 0) {
parser->error = TRUE;
parser->error = 1;
return 0;
}
parser->path_mark = NULL;
@ -204,7 +206,7 @@ do { \
if(parser->on_headers_complete) {
callback_return_value = parser->on_headers_complete(parser);
if (callback_return_value != 0) {
parser->error = TRUE;
parser->error = 1;
return 0;
}
}
@ -214,7 +216,7 @@ do { \
if(parser->on_message_begin) {
callback_return_value = parser->on_message_begin(parser);
if (callback_return_value != 0) {
parser->error = TRUE;
parser->error = 1;
return 0;
}
}
@ -222,7 +224,7 @@ do { \
action content_length {
if (parser->content_length > INT_MAX) {
parser->error = TRUE;
parser->error = 1;
return 0;
}
parser->content_length *= 10;
@ -237,8 +239,8 @@ do { \
action use_identity_encoding { parser->transfer_encoding = HTTP_IDENTITY; }
action use_chunked_encoding { parser->transfer_encoding = HTTP_CHUNKED; }
action set_keep_alive { parser->keep_alive = TRUE; }
action set_not_keep_alive { parser->keep_alive = FALSE; }
action set_keep_alive { parser->keep_alive = 1; }
action set_not_keep_alive { parser->keep_alive = 0; }
action version_major {
parser->version_major *= 10;
@ -258,7 +260,7 @@ do { \
action skip_chunk_data {
SKIP_BODY(MIN(parser->chunk_size, REMAINING));
if (callback_return_value != 0) {
parser->error = TRUE;
parser->error = 1;
return 0;
}
@ -290,7 +292,7 @@ do { \
SKIP_BODY(MIN(REMAINING, parser->content_length));
if (callback_return_value != 0) {
parser->error = TRUE;
parser->error = 1;
return 0;
}
@ -453,7 +455,7 @@ http_parser_execute (http_parser *parser, const char *buffer, size_t len)
/* eat body */
SKIP_BODY(MIN(len, parser->chunk_size));
if (callback_return_value != 0) {
parser->error = TRUE;
parser->error = 1;
return 0;
}
}
@ -483,7 +485,7 @@ http_parser_execute (http_parser *parser, const char *buffer, size_t len)
int
http_parser_has_error (http_parser *parser)
{
if (parser->error) return TRUE;
if (parser->error) return 1;
return parser->cs == http_parser_error;
}
@ -494,9 +496,9 @@ http_parser_should_keep_alive (http_parser *parser)
if (parser->version_major == 1)
return (parser->version_minor != 0);
else if (parser->version_major == 0)
return FALSE;
return 0;
else
return TRUE;
return 1;
else
return parser->keep_alive;
}

Loading…
Cancel
Save