random clean ups

version0.2
Ryan 16 years ago
parent 7898f1a97a
commit 8cae1feeb4

@ -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:

@ -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
}

@ -26,9 +26,7 @@
*/
#include "http_parser.h"
#include <stdio.h>
#include <assert.h>
#include <string.h>
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);
}

Loading…
Cancel
Save