Data Structures | Macros | Enumerations | Functions
http_parser.h File Reference

HTTP parser. More...

Data Structures

struct  vtm_http_parser
 

Macros

#define VTM_HTTP_DEF_MAX_HEADER_SIZE   8192
 
#define VTM_HTTP_DEF_MAX_BODY_SIZE   (8*1024*1024)
 

Enumerations

enum  vtm_http_parser_mode { VTM_HTTP_PM_REQUEST, VTM_HTTP_PM_RESPONSE }
 
enum  vtm_http_parser_state {
  VTM_HTTP_PARSE_BEGIN, VTM_HTTP_PARSE_REQ_METHOD, VTM_HTTP_PARSE_REQ_PATH, VTM_HTTP_PARSE_REQ_PARAM_BEGIN,
  VTM_HTTP_PARSE_REQ_PARAM_NAME, VTM_HTTP_PARSE_REQ_PARAM_VALUE, VTM_HTTP_PARSE_REQ_LINE_LF, VTM_HTTP_PARSE_RES_STATUS_CODE,
  VTM_HTTP_PARSE_RES_STATUS_MSG_CR, VTM_HTTP_PARSE_RES_STATUS_MSG_LF, VTM_HTTP_PARSE_VERSION_H, VTM_HTTP_PARSE_VERSION_HT,
  VTM_HTTP_PARSE_VERSION_HTT, VTM_HTTP_PARSE_VERSION_HTTP, VTM_HTTP_PARSE_VERSION_SLASH, VTM_HTTP_PARSE_VERSION_MAJOR,
  VTM_HTTP_PARSE_VERSION_MINOR, VTM_HTTP_PARSE_HEADER_LINE_BEGIN, VTM_HTTP_PARSE_HEADER_NAME, VTM_HTTP_PARSE_HEADER_VALUE,
  VTM_HTTP_PARSE_HEADER_LINE_LF, VTM_HTTP_PARSE_HEADER_LINE_COMPLETE, VTM_HTTP_PARSE_HEADERS_END_LF, VTM_HTTP_PARSE_BODY,
  VTM_HTTP_PARSE_BODY_READALL, VTM_HTTP_PARSE_BODY_FIXEDLENGTH, VTM_HTTP_PARSE_BODY_CHUNKED, VTM_HTTP_PARSE_BODY_CHUNK_SIZE,
  VTM_HTTP_PARSE_BODY_CHUNK_SIZE_LF, VTM_HTTP_PARSE_BODY_CHUNK_CONTENT, VTM_HTTP_PARSE_BODY_CHUNK_END_LF, VTM_HTTP_PARSE_COMPLETE
}
 

Functions

VTM_API void vtm_http_parser_init (struct vtm_http_parser *par, enum vtm_http_parser_mode mode)
 
VTM_API void vtm_http_parser_release (struct vtm_http_parser *par)
 
VTM_API void vtm_http_parser_reset (struct vtm_http_parser *par)
 
VTM_API enum vtm_net_recv_stat vtm_http_parser_run (struct vtm_http_parser *par, struct vtm_buf *buf)
 

Macro Definition Documentation

#define VTM_HTTP_DEF_MAX_HEADER_SIZE   8192

default maximum header size in bytes

#define VTM_HTTP_DEF_MAX_BODY_SIZE   (8*1024*1024)

default maximum body size in bytes

Enumeration Type Documentation

Enumerator
VTM_HTTP_PM_REQUEST 

Parse client request

VTM_HTTP_PM_RESPONSE 

Parse server response

Function Documentation

VTM_API void vtm_http_parser_init ( struct vtm_http_parser par,
enum vtm_http_parser_mode  mode 
)

Initializes the parser for the given mode.

Parameters
parthe parser that should be initialized
modethe mode under which the parser should run
VTM_API void vtm_http_parser_release ( struct vtm_http_parser par)

Releases the parser and all allocated resources.

After this call the parser is no longer valid.

Parameters
parthe parser that should be released
VTM_API void vtm_http_parser_reset ( struct vtm_http_parser par)

Resets the parser for parsing a new request or response.

Parameters
parthe parser that should be reset
VTM_API enum vtm_net_recv_stat vtm_http_parser_run ( struct vtm_http_parser par,
struct vtm_buf buf 
)

Lets the parser examine the input data.

Parameters
parthe parser the should run
bufthe input buffer for the parser
Returns
VTM_NET_RECV_STAT_COMPLETE if a request or response was successfully parsed
VTM_NET_RECV_STAT_AGAIN if the parser need a another run with more input data
VTM_NET_RECV_STAT_INVALID if the input data is not a valid request or response
VTM_NET_RECV_STAT_ERROR if an error occured for example a necessary buffer could not be allocated