version0.2
Ryan 16 years ago
parent 5214fb2524
commit c288a966fe

@ -58,6 +58,7 @@ typedef int (*http_cb) (http_parser*);
#define HTTP_PUT 0x0800 #define HTTP_PUT 0x0800
#define HTTP_TRACE 0x1000 #define HTTP_TRACE 0x1000
#define HTTP_UNLOCK 0x2000 #define HTTP_UNLOCK 0x2000
/* Transfer Encodings */ /* Transfer Encodings */
#define HTTP_IDENTITY 0x01 #define HTTP_IDENTITY 0x01
#define HTTP_CHUNKED 0x02 #define HTTP_CHUNKED 0x02

@ -376,13 +376,15 @@ http_parser_execute(http_parser *parser, const char *buffer, size_t len)
return(p - buffer); return(p - buffer);
} }
int http_parser_has_error(http_parser *parser) int
http_parser_has_error (http_parser *parser)
{ {
return parser->cs == http_parser_error; return parser->cs == http_parser_error;
} }
#if 0 #if 0
int http_should_keep_alive(http *request) int
http_should_keep_alive (http *request)
{ {
if (request->keep_alive == -1) if (request->keep_alive == -1)
if (request->version_major == 1) if (request->version_major == 1)

@ -329,31 +329,36 @@ const struct message responses[] =
, {.name= NULL } /* sentinel */ , {.name= NULL } /* sentinel */
}; };
int request_path_cb(http_parser *_, const char *p, size_t len) int
request_path_cb (http_parser *_, const char *p, size_t len)
{ {
strncat(messages[num_messages].request_path, p, len); strncat(messages[num_messages].request_path, p, len);
return 0; return 0;
} }
int request_uri_cb(http_parser *_, const char *p, size_t len) int
request_uri_cb (http_parser *_, const char *p, size_t len)
{ {
strncat(messages[num_messages].request_uri, p, len); strncat(messages[num_messages].request_uri, p, len);
return 0; return 0;
} }
int query_string_cb(http_parser *_, const char *p, size_t len) int
query_string_cb (http_parser *_, const char *p, size_t len)
{ {
strncat(messages[num_messages].query_string, p, len); strncat(messages[num_messages].query_string, p, len);
return 0; return 0;
} }
int fragment_cb(http_parser *_, const char *p, size_t len) int
fragment_cb (http_parser *_, const char *p, size_t len)
{ {
strncat(messages[num_messages].fragment, p, len); strncat(messages[num_messages].fragment, p, len);
return 0; return 0;
} }
int header_field_cb(http_parser *_, const char *p, size_t len) int
header_field_cb (http_parser *_, const char *p, size_t len)
{ {
struct message *m = &messages[num_messages]; struct message *m = &messages[num_messages];
@ -367,7 +372,8 @@ int header_field_cb(http_parser *_, const char *p, size_t len)
return 0; return 0;
} }
int header_value_cb (http_parser *_, const char *p, size_t len) int
header_value_cb (http_parser *_, const char *p, size_t len)
{ {
struct message *m = &messages[num_messages]; struct message *m = &messages[num_messages];
@ -378,14 +384,16 @@ int header_value_cb (http_parser *_, const char *p, size_t len)
return 0; return 0;
} }
int body_handler (http_parser *_, const char *p, size_t len) int
body_cb (http_parser *_, const char *p, size_t len)
{ {
strncat(messages[num_messages].body, p, len); strncat(messages[num_messages].body, p, len);
// printf("body_handler: '%s'\n", requests[num_messages].body); // printf("body_cb: '%s'\n", requests[num_messages].body);
return 0; return 0;
} }
int message_complete(http_parser *parser) int
message_complete_cb (http_parser *parser)
{ {
messages[num_messages].method = parser->method; messages[num_messages].method = parser->method;
@ -393,7 +401,8 @@ int message_complete(http_parser *parser)
return 0; return 0;
} }
int begin_message (http_parser *_) int
message_begin_cb (http_parser *_)
{ {
return 0; return 0;
} }
@ -407,16 +416,16 @@ parser_init (enum http_parser_type type)
memset(&messages, 0, sizeof messages); memset(&messages, 0, sizeof messages);
parser.on_message_begin = begin_message; parser.on_message_begin = message_begin_cb;
parser.on_header_field = header_field_cb; parser.on_header_field = header_field_cb;
parser.on_header_value = header_value_cb; parser.on_header_value = header_value_cb;
parser.on_path = request_path_cb; parser.on_path = request_path_cb;
parser.on_uri = request_uri_cb; parser.on_uri = request_uri_cb;
parser.on_fragment = fragment_cb; parser.on_fragment = fragment_cb;
parser.on_query_string = query_string_cb; parser.on_query_string = query_string_cb;
parser.on_body = body_handler; parser.on_body = body_cb;
parser.on_headers_complete = NULL; parser.on_headers_complete = NULL;
parser.on_message_complete = message_complete; parser.on_message_complete = message_complete_cb;
} }
void void
@ -438,8 +447,6 @@ request_eq (int index, const struct message *expected)
} }
} }
void void
parse_messages (int message_count, const struct message *input_messages[]) parse_messages (int message_count, const struct message *input_messages[])
{ {
@ -495,7 +502,6 @@ test_error (const char *buf)
assert(http_parser_has_error(&parser)); assert(http_parser_has_error(&parser));
} }
void void
test_multiple3 (const struct message *r1, const struct message *r2, const struct message *r3) test_multiple3 (const struct message *r1, const struct message *r2, const struct message *r3)
{ {
@ -595,7 +601,8 @@ test_scan (const struct message *r1, const struct message *r2, const struct mess
printf("\b\b\b\b100%\n"); printf("\b\b\b\b100%\n");
} }
int main() int
main (void)
{ {
test_error("hello world"); test_error("hello world");
test_error("GET / HTP/1.1\r\n\r\n"); test_error("GET / HTP/1.1\r\n\r\n");
@ -690,4 +697,3 @@ int main()
return 0; return 0;
} }

Loading…
Cancel
Save