HomePort
Data Structures | Macros | Typedefs | Functions
httpd_url_parser.h File Reference
Include dependency graph for httpd_url_parser.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  up_settings
 Settings struct for the URL Parser. More...
 

Macros

#define UP_SETTINGS_DEFAULT
 

Typedefs

typedef hpd_error_t(* up_pair_cb) (void *data, const char *key, size_t key_length, const char *value, size_t value_length)
 
typedef hpd_error_t(* up_string_cb) (void *data, const char *parsedSegment, size_t segment_length)
 
typedef hpd_error_t(* up_void_cb) (void *data)
 

Functions

hpd_error_t up_add_chunk (struct up *instance, const char *chunk, size_t chunk_size)
 Parse a chunk of an URL. More...
 
hpd_error_t up_complete (struct up *instance)
 Informs the parser that the URL is complete. More...
 
hpd_error_t up_create (struct up **instance, struct up_settings *settings, const hpd_module_t *context, void *data)
 Create URL parser instance. More...
 
hpd_error_t up_destroy (struct up *instance)
 Destroy URL parser instance. More...
 

Data Structure Documentation

struct up_settings

Settings struct for the URL Parser.

Please initialise this struct as following, to ensure that all settings have acceptable default values:

struct url_parser_settings *settings = URL_PARSER_SETTINGS_DEFAULT;

The settings hold a series of callbacks of type either up_string_cb, up_pair_cb or up_void_cb. Strings received in up_pair_cb and up_string_cb are never null-terminated, and they always have a length. The callbacks are called when the URL parser finishes parsing a specific chunk. The callback with the last part of a segment (e.g. the c in /a/b/c) might first be called when up_complete has been called, as it cannot know if c is the last character of the segment unless it terminates with a /.

Definition at line 59 of file httpd_url_parser.h.

Collaboration diagram for up_settings:
Data Fields
up_void_cb on_begin
up_string_cb on_complete
up_string_cb on_host
up_pair_cb on_key_value
up_string_cb on_path_complete
up_string_cb on_path_segment
up_string_cb on_port
up_string_cb on_protocol

Macro Definition Documentation

#define UP_SETTINGS_DEFAULT
Value:
{\
.on_begin = NULL, .on_protocol = NULL, .on_host = NULL, \
.on_port = NULL, .on_path_segment = NULL, .on_path_complete = NULL, \
.on_key_value = NULL, .on_complete = NULL }

Definition at line 70 of file httpd_url_parser.h.

Typedef Documentation

typedef hpd_error_t(* up_pair_cb) (void *data, const char *key, size_t key_length, const char *value, size_t value_length)

Definition at line 34 of file httpd_url_parser.h.

typedef hpd_error_t(* up_string_cb) (void *data, const char *parsedSegment, size_t segment_length)

Definition at line 33 of file httpd_url_parser.h.

typedef hpd_error_t(* up_void_cb) (void *data)

Definition at line 35 of file httpd_url_parser.h.

Function Documentation

hpd_error_t up_add_chunk ( struct up instance,
const char *  chunk,
size_t  len 
)

Parse a chunk of an URL.

This method receives a chunk of an URL, and calls the appropriate callbacks. It increases the size of buffer, copies the new chunk to it and then parses each character and changes state accordingly. A chunk may of course be a complete URL, all of which will be parsed immediately.

Parameters
instanceA pointer to an URL Parser instance
chunkA pointer to the chunk (non zero terminated)
chunk_sizeThe size of the chunk

Definition at line 209 of file httpd_url_parser.c.

Here is the call graph for this function:

Here is the caller graph for this function:

hpd_error_t up_complete ( struct up instance)

Informs the parser that the URL is complete.

This method will let the parser know that the URL is complete. This always results in the on_complete callback being called, but it may also inflict two others: on_path_segment and on_key_value. This is due to the nature of the URL parser being able to receive in chunks: it can simply now know if an URL path is complete without a slash at the end. It also cannot know if a value part of a key is done before being told.

Parameters
instanceA pointer to an URL Parser instance

Definition at line 377 of file httpd_url_parser.c.

Here is the caller graph for this function:

hpd_error_t up_create ( struct up **  instance,
struct up_settings settings,
const hpd_module_t context,
void *  data 
)

Create URL parser instance.

This method creates an URL Parser instance. It allocates memory for itself and copy the settings struct. It also sets all values to default.

The instance should be destroyed using up_destroy when it is no longer needed.

Parameters
settingsA pointer to a url_parser_settings struct
dataPointer to user data, will be supplied to callbacks
Returns
a pointer to the newly created instance

Definition at line 96 of file httpd_url_parser.c.

Here is the call graph for this function:

Here is the caller graph for this function:

hpd_error_t up_destroy ( struct up instance)

Destroy URL parser instance.

This method destroys an URL Parser instance, including the buffer and settings struct.

Parameters
instanceA pointer to an url_parser_instance to destroy

Definition at line 152 of file httpd_url_parser.c.

Here is the call graph for this function:

Here is the caller graph for this function: