HTTP Parser and message builder / objects in plain C Snapshot
Classes | Defines | Typedefs | Enumerations | Functions
http.h File Reference
#include <stdlib.h>
#include <nutils/bf.h>
#include <hutils/uri.h>
#include <cutils/dlistunr.h>
#include <cutils/bhash.h>

Go to the source code of this file.

Classes

struct  tagSTRINGPAIR
struct  tagHTTP_MESSAGE
struct  tagHTTP_REQUEST
struct  tagHTTP_RESPONSE
struct  tagHTTP_PARSER
struct  tagHTTP_REQUEST_PARSER
struct  tagHTTP_RESPONSE_PARSER
struct  tagHTTP_RESPONSE_WRITER

Defines

#define HTTP_MESSAGE_FLAG_CONNECTION_CLOSE   1
#define HTTP_MESSAGE_FLAG_TRANSFER_CHUNKED   2
#define HTTP_MESSAGE_FLAG_HAS_CONTENT_LENGTH   4
#define HTTP_MESSAGE_FLAG_KEEPALIVE   8

Typedefs

typedef struct tagSTRINGPAIR STRINGPAIR
typedef struct tagHTTP_MESSAGE HTTP_MESSAGE
typedef int(* HEADER_ACTION )(struct tagHTTP_MESSAGE *request, struct tagHTTP_PARSER *parser)
 callback that is invoked in order to parse contents of a specific http header
typedef enum tagHttp_method_type Http_method_type
typedef enum tagHttp_version_type Http_version_type
typedef struct tagHTTP_REQUEST HTTP_REQUEST
typedef struct tagHTTP_RESPONSE HTTP_RESPONSE
typedef int(* HTTP_RESP_HEADER_PARSED )(HTTP_RESPONSE *request, void *ctx)
typedef int(* HTTP_RESP_MESSAGE_BODY_DATA )(HTTP_RESPONSE *request, void *data, size_t data_size, void *ctx)
typedef int(* HTTP_RESP_FINISHED )(HTTP_RESPONSE *request, void *ctx)
typedef enum tagHTTP_STATE_PARSING HTTP_STATE_PARSING
typedef struct tagHTTP_PARSER HTTP_PARSER
typedef int(* HTTP_PROCESS_MSG_DATA )(HTTP_MESSAGE *msg, void *data, size_t data_size, void *ctx)
typedef int(* HTTP_REQ_HEADER_PARSED )(HTTP_REQUEST *request, void *ctx)
typedef int(* HTTP_REQ_MESSAGE_BODY_DATA )(HTTP_REQUEST *request, void *data, size_t data_size, void *ctx)
typedef int(* HTTP_REQ_FINISHED )(HTTP_REQUEST *request, void *ctx)
typedef struct
tagHTTP_REQUEST_PARSER 
HTTP_REQUEST_PARSER
typedef struct
tagHTTP_RESPONSE_PARSER 
HTTP_RESPONSE_PARSER
typedef struct
tagHTTP_RESPONSE_WRITER 
HTTP_RESPONSE_WRITER

Enumerations

enum  tagHttp_method_type {
  HTTP_METHOD_GET, HTTP_METHOD_POST, HTTP_METHOD_PUT, HTTP_METHOD_HEAD,
  HTTP_METHOD_OPTIONS, HTTP_METHOD_DELETE, HTTP_METHOD_TRACE, HTTP_METHOD_CONNECT
}
enum  tagHttp_version_type { HTTP_VERSION_1_0, HTTP_VERSION_1_1 }
enum  tagHTTP_STATE_PARSING {
  HTTP_STATE_PARSING_REQUEST_LINE, HTTP_STATE_PARSING_HEADERS, HTTP_STATE_PARSING_BODY_CONTENT_LENGTH, HTTP_STATE_PARSING_BODY_CHUNK_HEADER,
  HTTP_STATE_PARSING_BODY_CHUNK_DATA, HTTP_STATE_PARSING_BODY_CHUNK_EOF_AFTER_DATA, HTTP_STATE_PARSING_BODY_CHUNK_TRAILER
}
enum  PARSER_STATUS { PARSER_STATUS_ERROR = -1, PARSER_STATUS_COMPLETED = 0, PARSER_STATUS_NEED_MORE_DATA = 1 }
enum  HTTP_TK_TYPE { HTTP_TK_QUOTED_STRING, HTTP_TK_TEXT, HTTP_TK_SEPARATOR, HTTP_TK_EOF }
enum  HTTP_RESPONSE_WR_STATE {
  HTTP_RESPONSE_WR_STATUS_LINE, HTTP_RESPONSE_WR_CONNECTION_CLOSE, HTTP_RESPONSE_WR_CHUNKED, HTTP_RESPONSE_WR_CONTENT_LENGTH,
  HTTP_RESPONSE_WR_HEADERS, HTTP_RESPONSE_WR_EOF
}

Functions

int HTTP_MESSAGE_init (HTTP_MESSAGE *message)
void HTTP_MESSAGE_free (HTTP_MESSAGE *message)
int HTTP_MESSAGE_add_header (HTTP_MESSAGE *message, const char *name, const char *value)
M_INLINE void HTTP_MESSAGE_set_content_length (HTTP_MESSAGE *message, int content_length)
const char * HTTP_MESSAGE_find_header (HTTP_MESSAGE *message, const char *name)
STRINGPAIRHTTP_MESSAGE_first_header (HTTP_MESSAGE *message, DLISTUNR_position *pos)
STRINGPAIRHTTP_MESSAGE_next_header (HTTP_MESSAGE *message, DLISTUNR_position *pos)
int HTTP_REQUEST_is_persistent (HTTP_REQUEST *message)
M_INLINE int HTTP_REQUEST_init (HTTP_REQUEST *message)
M_INLINE void HTTP_REQUEST_free (HTTP_REQUEST *message)
M_INLINE int HTTP_RESPONSE_init (HTTP_RESPONSE *message, Http_version_type version, int status_code)
M_INLINE void HTTP_RESPONSE_free (HTTP_RESPONSE *message)
int HTTP_PARSER_init (HTTP_PARSER *parser)
int HTTP_PARSER_free (HTTP_PARSER *parser)
int HTTP_add_header_parser (HTTP_PARSER *parser, const char *header_name, HEADER_ACTION action)
 add a parser for a specific http header type
PARSER_STATUS HTTP_get_line (BF *bf, char **start_line)
 returns next raw line from http header, adjoins line continuations.
int HTTP_get_header_token (HTTP_PARSER *parser)
 return next token while parsing http header value.
PARSER_STATUS HTTP_parse_header_line (HTTP_PARSER *parser, HTTP_MESSAGE *request, BF *bf, int *eof_header)
 dispatch parsing of one http header
int HTTP_PARSER_content_length_init (HTTP_PARSER *parser, HTTP_MESSAGE *msg)
 start parsing content length message body
PARSER_STATUS HTTP_PARSER_content_length_process (HTTP_PARSER *parser, BF *bf, HTTP_PROCESS_MSG_DATA cb, HTTP_MESSAGE *msg, void *ctx)
 consume content length message body.
int HTTP_PARSER_chunked_data_init (HTTP_PARSER *parser)
 start parsing chunked data
PARSER_STATUS HTTP_PARSER_chunked_data_process (HTTP_PARSER *parser, BF *bf, HTTP_PROCESS_MSG_DATA cb, HTTP_MESSAGE *msg, void *ctx)
 finish parsind chunked content data.
int HTTP_REQUEST_PARSER_init (HTTP_REQUEST_PARSER *parser, HTTP_REQ_HEADER_PARSED header_parsed, HTTP_REQ_MESSAGE_BODY_DATA on_message_body_data, HTTP_REQ_FINISHED on_request_finished, void *ctx)
 initialise request parser object
PARSER_STATUS HTTP_REQUEST_PARSER_process (HTTP_REQUEST_PARSER *parser, HTTP_REQUEST *request, BF *data)
 parse a http request
int HTTP_RESPONSE_PARSER_init (HTTP_RESPONSE_PARSER *parser, HTTP_RESP_HEADER_PARSED header_parsed, HTTP_RESP_MESSAGE_BODY_DATA on_message_body_data, HTTP_RESP_FINISHED on_request_finished, void *ctx)
 initialise request parser object
PARSER_STATUS HTTP_RESPONSE_PARSER_process (HTTP_RESPONSE_PARSER *parser, HTTP_RESPONSE *response, BF *data)
 parse a http response
M_INLINE void HTTP_RESPONSE_WRITER_init (HTTP_RESPONSE_WRITER *writer, HTTP_RESPONSE *response)
PARSER_STATUS HTTP_RESPONSE_WRITER_write (HTTP_RESPONSE_WRITER *writer, BF *data)

Define Documentation

#define HTTP_MESSAGE_FLAG_CONNECTION_CLOSE   1

Definition at line 13 of file http.h.

#define HTTP_MESSAGE_FLAG_HAS_CONTENT_LENGTH   4

Definition at line 15 of file http.h.

#define HTTP_MESSAGE_FLAG_KEEPALIVE   8

Definition at line 16 of file http.h.

#define HTTP_MESSAGE_FLAG_TRANSFER_CHUNKED   2

Definition at line 14 of file http.h.