src/http_parser.h File Reference

Typedefs

typedef struct hp_transaction_tag hp_transaction_s
typedef struct hp_header_field_tag hp_header_field_s
typedef enum hp_role_tag hp_role_e
typedef enum hp_parse_result_tag hp_parse_result_e

Enumerations

enum  hp_role_tag { HP_ROLE_CLIENT = 0, HP_ROLE_SERVER }
enum  hp_parse_result_tag { HP_PARSE_OK = 0, HP_PARSE_ERROR, HP_PARSE_INCOMPLETE }

Functions

hp_transaction_shp_create_transaction (const hp_role_e role)
 Initialise a blank HTTP transaction.
void hp_transaction_free (hp_transaction_s *transaction)
 Free a HTTP transaction.
bool hp_add_data (hp_transaction_s *transaction, const char *data, const size_t dataLen)
 Call when you want to add data to a transaction.
hp_parse_result_e hp_parse_data (hp_transaction_s *transaction)
 Parse the message buffered.
const char * hp_get_host (hp_transaction_s *transaction)
 Return the host if given.
unsigned short int hp_get_host_port (const hp_transaction_s *transaction)
 Returns the parsed host port (default of HTTP_DEFAULT_PORT if none given).
http_method_e hp_get_method (const hp_transaction_s *transaction)
 Gets the method of the request.
size_t hp_get_raw_bytes (hp_transaction_s *transaction, char *buffer, const size_t bufferLen)
 Gets the raw bytes from the transaction.
size_t hp_get_number_raw_bytes (const hp_transaction_s *transaction)
 Returns how much raw data there is.
bool hp_set_header_field_value (const hp_transaction_s *transaction, const char *value)
 Sets a header field value.

Typedef Documentation

typedef enum hp_role_tag hp_role_e

Enumeration Type Documentation

Enumerator:
HP_PARSE_OK 
HP_PARSE_ERROR 
HP_PARSE_INCOMPLETE 
Enumerator:
HP_ROLE_CLIENT 
HP_ROLE_SERVER 

http errors will NOT be sent

http errors will be sent


Function Documentation

bool hp_add_data ( hp_transaction_s transaction,
const char *  data,
const size_t  dataLen 
)

Call when you want to add data to a transaction.

See also:
hp_parse_data()
Parameters:
transaction The transaction to add data to.
data The data to add.
dataLen The length of the data to add.
Returns:
true on success. On error, false is returned.
hp_transaction_s* hp_create_transaction ( const hp_role_e  role  ) 

Initialise a blank HTTP transaction.

It must be freed with http_free_transaction().

See also:
http_free_transaction()
Parameters:
role The role the parser will take.
Returns:
A blank HTTP transaction. On error, NULL is returned.
const char* hp_get_host ( hp_transaction_s transaction  ) 

Return the host if given.

The hostname will not exceed HTTP_LIMIT_HOSTNAME_LENGTH.

Returns:
The host to connect to (nul terminated) as a IP or hostname.

already "cached"

unsigned short int hp_get_host_port ( const hp_transaction_s transaction  ) 

Returns the parsed host port (default of HTTP_DEFAULT_PORT if none given).

Parameters:
transaction The transaction to return from.
Returns:
The port of the host given in the request path or Host: header.
http_method_e hp_get_method ( const hp_transaction_s transaction  ) 

Gets the method of the request.

Parameters:
transaction The transaction to return from.
Returns:
the request method.
size_t hp_get_number_raw_bytes ( const hp_transaction_s transaction  ) 

Returns how much raw data there is.

Parameters:
transaction The transaction to check if there is unread data on.
Returns:
The number of raw bytes that haven't been read yet. 0 if there are none.
size_t hp_get_raw_bytes ( hp_transaction_s transaction,
char *  buffer,
const size_t  bufferLen 
)

Gets the raw bytes from the transaction.

Parameters:
transaction The raw bytes to return.
buffer The buffer to write to.
bufferLen The maximum size of buffer.
Returns:
>0 if buffer contains raw bytes. On EOF or error 0 is returned.
hp_parse_result_e hp_parse_data ( hp_transaction_s transaction  ) 

Parse the message buffered.

See also:
hp_add_data()
Parameters:
transaction The transaction to parse.
Returns:
true on success. On error, false is returned.

Todo:
HTTP_ROLE_CLIENT for parsing response line
Todo:
use the return value of path and header fields.

bool hp_set_header_field_value ( const hp_transaction_s transaction,
const char *  value 
)

Sets a header field value.

Returns true if the value was set. On error, false is returned.

Parameters:
transaction The transaction to set the header field value of.
value 

Todo:
Replace field value OR add it to the end of the headers.
Todo:
Detect EOL style from transaction

void hp_transaction_free ( hp_transaction_s transaction  ) 

Free a HTTP transaction.

Parameters:
transaction The transaction to free.

Generated by  doxygen 1.6.2