From 8cae1feeb430084fa8f952553bdefea86516ab38 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 27 Apr 2009 17:07:07 +0200 Subject: [PATCH] random clean ups --- README.md | 2 +- http_parser.h | 18 +++++++----------- http_parser.rl | 16 +++++++++++----- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 4e3b8d6..f69533e 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ HTTP Parser This is a parser for HTTP messages written in C. It parses both requests and responses. The parser is designed to be used in performance HTTP applications. It does not make any allocations, it does not buffer data, and -it can be interrupted at anytime. It only requires about 120 bytes of data +it can be interrupted at anytime. It only requires about 100 bytes of data per message stream (in a web server that is per connection). Features: diff --git a/http_parser.h b/http_parser.h index 9b48164..d41580e 100644 --- a/http_parser.h +++ b/http_parser.h @@ -82,13 +82,12 @@ struct http_parser { const char *fragment_mark; /** READ-ONLY **/ - unsigned int status_code; /* responses only */ - unsigned int method; /* requests only */ - int transfer_encoding; - unsigned int version_major; - unsigned int version_minor; - unsigned int number_of_headers; - int keep_alive; + unsigned short status_code; /* responses only */ + unsigned short method; /* requests only */ + short transfer_encoding; + unsigned short version_major; + unsigned short version_minor; + short keep_alive; size_t content_length; /** PUBLIC **/ @@ -112,8 +111,7 @@ struct http_parser { }; /* Initializes an http_parser structure. The second argument specifies if - * it will be parsing requests or responses. Set the second argument to 1 - * for requests; 0 for responses. + * it will be parsing requests or responses. */ void http_parser_init (http_parser *parser, enum http_parser_type); @@ -122,8 +120,6 @@ size_t http_parser_execute (http_parser *parser, const char *data, size_t len); int http_parser_has_error (http_parser *parser); int http_parser_should_keep_alive (http_parser *parser); -#define http_message_has_body(parser) \ - (parser->transfer_encoding == HTTP_CHUNKED || parser->content_length > 0 ) #ifdef __cplusplus } diff --git a/http_parser.rl b/http_parser.rl index 801a982..3b4700f 100644 --- a/http_parser.rl +++ b/http_parser.rl @@ -26,9 +26,7 @@ */ #include "http_parser.h" -#include #include -#include static int unhex[] = {-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,-1,-1,-1,-1,-1,-1,-1 @@ -42,6 +40,7 @@ static int unhex[] = {-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 REMAINING (pe - p) #define CALLBACK(FOR) \ @@ -64,7 +63,6 @@ static int unhex[] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 parser->transfer_encoding = HTTP_IDENTITY; \ parser->version_major = 0; \ parser->version_minor = 0; \ - parser->number_of_headers = 0; \ parser->keep_alive = -1; \ parser->content_length = 0; \ parser->body_read = 0; @@ -346,13 +344,21 @@ do { \ void http_parser_init (http_parser *parser, enum http_parser_type type) { - memset(parser, 0, sizeof(struct http_parser)); - int cs = 0; %% write init; parser->cs = cs; parser->type = type; + parser->on_message_begin = NULL; + parser->on_path = NULL; + parser->on_query_string = NULL; + parser->on_uri = NULL; + parser->on_header_field = NULL; + parser->on_header_value = NULL; + parser->on_headers_complete = NULL; + parser->on_body = NULL; + parser->on_message_complete = NULL; + RESET_PARSER(parser); }