httpmessage  0.4.0
HTTP message parsing library
Classes | Functions | Variables
HTTP header field and values

Classes

struct  httpmessage_headerfield_value
 HTTP header field value text reference. More...
 
struct  httpmessage_headerfield
 HTTP header field and value. More...
 

Functions

HMAPI int httpmessage_headerfield_name_consume (const char **name, size_t *name_length, const char *text, size_t length)
 Read the header field name. More...
 
HMAPI httpmessage_headerfield_valuehttpmessage_headerfield_value_new (void)
 Allocate and initialize a new header value. More...
 
HMAPI void httpmessage_headerfield_value_init (httpmessage_headerfield_value *value)
 Initialize a header value. More...
 
HMAPI httpmessage_headerfield_valuehttpmessage_headerfield_value_append_line (httpmessage_headerfield_value *value, const char *text, size_t length)
 Append a new line of data to the given header value. More...
 
HMAPI size_t httpmessage_headerfield_value_total_length (const httpmessage_headerfield_value *value)
 Get the total length of the header value text. More...
 
HMAPI int httpmessage_headerfield_value_merge_lines (char *output, size_t output_size, const httpmessage_headerfield_value *value)
 Copy the referenced header value lines to a contiguous text buffer. More...
 
HMAPI void httpmessage_headerfield_value_free (httpmessage_headerfield_value **value)
 Free header value and following lines. More...
 
HMAPI int httpmessage_headerfield_value_line_consume (const char **value, size_t *value_length, const char *text, size_t length, int option_flags)
 Read header value content until the end of the current line. More...
 
HMAPI httpmessage_headerfieldhttpmessage_headerfield_new (void)
 Allocate and initialize a new header object. More...
 
HMAPI void httpmessage_headerfield_init (httpmessage_headerfield *field)
 Initialize header members. More...
 
HMAPI void httpmessage_headerfield_free (httpmessage_headerfield **field)
 Free header memory. More...
 
HMAPI int httpmessage_headerfield_is (const httpmessage_headerfield *field, const char *name)
 Indicates if the given header field name match the expected name. More...
 
HMAPI void httpmessage_headerfield_clear (httpmessage_headerfield *field, int option_flags)
 Clear header member to their initial state. More...
 
HMAPI size_t httpmessage_headerfield_count (httpmessage_headerfield *headerfield_list)
 Get the number of valid headers in the given header list. More...
 
HMAPI httpmessage_headerfieldhttpmessage_headerfield_find (httpmessage_headerfield *headerfield_list, const char *name, size_t name_length)
 Find the first header field matching the given field name. More...
 
HMAPI int httpmessage_headerfield_line_consume (httpmessage_headerfield **field, httpmessage_headerfield *current_header, const char *text, size_t length, int option_flags)
 Read header field name and value on a single line

  • If the current line starts by a header field name, a new header is created assigned as next header of current_header and header will point to it.
More...
 
HMAPI ssize_t httpmessage_headerfield_write_file (FILE *file, const httpmessage_headerfield *field)
 Write a HTTP header line to a file. More...
 
HMAPI ssize_t httpmessage_headerfield_write_buffer (void *output, size_t output_size, const httpmessage_headerfield *field)
 Write a HTTP header line to a buffer. More...
 
HMAPI int httpmessage_headerfield_list_consume (httpmessage_headerfield *headerfield_list, const char *text, size_t length, int option_flags)
 Parse all headers in the given text. More...
 
HMAPI ssize_t httpmessage_headerfield_list_write_file (FILE *file, const httpmessage_headerfield *headerfield_list)
 Write HTTP headers to a file. More...
 
HMAPI ssize_t httpmessage_headerfield_list_write_buffer (void *output, size_t output_size, const httpmessage_headerfield *headerfield_list)
 Write a list of HTTP header to a buffer. More...
 

Variables

HTTPMESSAGE_C_BEGIN typedef httpmessage_stringview httpmessage_headerfield_name
 Headef field name text reference.
 

Detailed Description

Function Documentation

◆ httpmessage_headerfield_clear()

HMAPI void httpmessage_headerfield_clear ( httpmessage_headerfield field,
int  option_flags 
)

Clear header member to their initial state.

Except if HTTPMESSAGE_CLEAR_NO_FREE option is set, all dynamically allocated members are freed.

Parameters
fieldHeader to clear
option_flagsOption flags. Supported flags are:
See also
httpmessage_option_flags

◆ httpmessage_headerfield_count()

HMAPI size_t httpmessage_headerfield_count ( httpmessage_headerfield headerfield_list)

Get the number of valid headers in the given header list.

Parameters
headerfield_listHeader list
Returns
Number of element in headerfield_list

◆ httpmessage_headerfield_find()

HMAPI httpmessage_headerfield* httpmessage_headerfield_find ( httpmessage_headerfield headerfield_list,
const char *  name,
size_t  name_length 
)

Find the first header field matching the given field name.

Parameters
headerfield_listHeader field list.
nameHeader field name to find.
name_lengthHeader field name length.
Returns
Pointer to the first header field with the given field name or NULL if none of the header fields in the list have the exepected field name.

◆ httpmessage_headerfield_free()

HMAPI void httpmessage_headerfield_free ( httpmessage_headerfield **  field)

Free header memory.

Parameters
fieldHeader to free

◆ httpmessage_headerfield_init()

HMAPI void httpmessage_headerfield_init ( httpmessage_headerfield field)

Initialize header members.

Initialize a header descriptor.

Parameters
fieldHeader structure to initialize
fieldHeader descriptor instance

◆ httpmessage_headerfield_is()

HMAPI int httpmessage_headerfield_is ( const httpmessage_headerfield field,
const char *  name 
)

Indicates if the given header field name match the expected name.

String comparison is case instensitive.

Parameters
fieldHeader to test field name
nameName to match. The string MUST be null-terminated
Returns
Non-zero value if the header field name match name

◆ httpmessage_headerfield_line_consume()

HMAPI int httpmessage_headerfield_line_consume ( httpmessage_headerfield **  field,
httpmessage_headerfield current_header,
const char *  text,
size_t  length,
int  option_flags 
)

Read header field name and value on a single line

  • If the current line starts by a header field name, a new header is created assigned as next header of current_header and header will point to it.

If the current line starts with a white psace, the content of the line is added the the current_header value and header will point to current_header

Parameters
fieldThe new header
current_headerThe current header
textInput text
lengthInput text length
option_flagsOption flags. Supported flags are:
Returns
On success, the numbre of bytes consumed (the current line length). On error, one of httpmessage_result_code
See also
httpmessage_result_code
httpmessage_option_flags

◆ httpmessage_headerfield_list_consume()

HMAPI int httpmessage_headerfield_list_consume ( httpmessage_headerfield headerfield_list,
const char *  text,
size_t  length,
int  option_flags 
)

Parse all headers in the given text.

Function stops when end of input is reached or if a leading CRLF is found.

Parameters
headerfield_listHeader list to populate
textInput text
lengthInput text length
option_flagsOption flags. These flags are passed to httpmessage API functions called internally.
Returns
On success, number of bytes conumed in text. On error, one of httpmessage_result_code
See also
httpmessage_result_code

◆ httpmessage_headerfield_list_write_buffer()

HMAPI ssize_t httpmessage_headerfield_list_write_buffer ( void *  output,
size_t  output_size,
const httpmessage_headerfield headerfield_list 
)

Write a list of HTTP header to a buffer.

Parameters
outputOutput buffer
output_sizeOutput buffer size
headerfield_listList of headers to write.
Attention
NULL termination character may not be written at end of string if the buffer is too small.
Returns
On success, the number of bytes written (excludint the null-termination character). On error, one of httpmessage_result_type
See also
httpmessage_result_code

◆ httpmessage_headerfield_list_write_file()

HMAPI ssize_t httpmessage_headerfield_list_write_file ( FILE *  file,
const httpmessage_headerfield headerfield_list 
)

Write HTTP headers to a file.

Parameters
fileOutput file
headerfield_listList of header to write
Returns
On success, the number of bytes written (excludint the null-termination character). On error, one of httpmessage_result_type
See also
httpmessage_result_code

◆ httpmessage_headerfield_name_consume()

HMAPI int httpmessage_headerfield_name_consume ( const char **  name,
size_t *  name_length,
const char *  text,
size_t  length 
)

Read the header field name.

Alias of httpmessage_token_consume()

Parameters
nameOutput field
name_lengthOutput field length
textInput text
lengthInput text length
Returns
On success, number of bytes of text consumed. On error, one of httpmessage_result_code
See also
httpmessage_result_code

◆ httpmessage_headerfield_new()

HMAPI httpmessage_headerfield* httpmessage_headerfield_new ( void  )

Allocate and initialize a new header object.

Returns
The new header object or NULL on error.

◆ httpmessage_headerfield_value_append_line()

HMAPI httpmessage_headerfield_value* httpmessage_headerfield_value_append_line ( httpmessage_headerfield_value value,
const char *  text,
size_t  length 
)

Append a new line of data to the given header value.

Parameters
valueHeader value that will receive the line
textText to add
lengthText length
Returns
The newly created httpmessage_headerfield_value

◆ httpmessage_headerfield_value_free()

HMAPI void httpmessage_headerfield_value_free ( httpmessage_headerfield_value **  value)

Free header value and following lines.

Parameters
valueHeader value to free

◆ httpmessage_headerfield_value_init()

HMAPI void httpmessage_headerfield_value_init ( httpmessage_headerfield_value value)

Initialize a header value.

Parameters
valueInstance to initialize

◆ httpmessage_headerfield_value_line_consume()

HMAPI int httpmessage_headerfield_value_line_consume ( const char **  value,
size_t *  value_length,
const char *  text,
size_t  length,
int  option_flags 
)

Read header value content until the end of the current line.

Parameters
valuePointer that will hold a reference to the first meaningful byte of the header value
value_lengthPointer that will hold the trimmed header value length
textInput text
lengthInput text length
option_flagsOption flags. Supported flags are
Returns
On success, the number of bytes of text consumed. This MAY be greated than the value stored in value_length since leading white space and trailing CRLF and white space are not counted in value_length. On error, one of the httpmessage_result_code
See also
httpmessage_result_code
httpmessage_option_flags

◆ httpmessage_headerfield_value_merge_lines()

HMAPI int httpmessage_headerfield_value_merge_lines ( char *  output,
size_t  output_size,
const httpmessage_headerfield_value value 
)

Copy the referenced header value lines to a contiguous text buffer.

Parameters
outputOutput buffer
output_sizeOutput buffer size
valueInput header value
Returns
On success, the number of bytes copied to output (excluding the NULL termination character). On error, one of the httpmessage_result_code codes
See also
httpmessage_result_code

◆ httpmessage_headerfield_value_new()

HMAPI httpmessage_headerfield_value* httpmessage_headerfield_value_new ( void  )

Allocate and initialize a new header value.

Returns
The new header value or NULL on error

◆ httpmessage_headerfield_value_total_length()

HMAPI size_t httpmessage_headerfield_value_total_length ( const httpmessage_headerfield_value value)

Get the total length of the header value text.

Parameters
valueHeader value
Returns
Sum of all header value line lenght

◆ httpmessage_headerfield_write_buffer()

HMAPI ssize_t httpmessage_headerfield_write_buffer ( void *  output,
size_t  output_size,
const httpmessage_headerfield field 
)

Write a HTTP header line to a buffer.

Parameters
outputOutput buffer
output_sizeOutput buffer size
fieldHeader to write
Attention
NULL termination character may not be written at end of string if the buffer is too small.
Returns
On success, the number of bytes written (excludint the null-termination character). On error, one of httpmessage_result_type
See also
httpmessage_result_code

◆ httpmessage_headerfield_write_file()

HMAPI ssize_t httpmessage_headerfield_write_file ( FILE *  file,
const httpmessage_headerfield field 
)

Write a HTTP header line to a file.

Parameters
fileOutput file
fieldHeader to write
Attention
NULL termination character may not be written at end of string if the buffer is too small.
Returns
On success, the number of bytes written (excludint the null-termination character). On error, one of httpmessage_result_type
See also
httpmessage_result_code