HomePort
Data Structures | Macros | Enumerations | Functions
httpd_url_parser.c File Reference
Include dependency graph for httpd_url_parser.c:

Go to the source code of this file.

Data Structures

struct  up
 An URL Parser instance. More...
 

Macros

#define UP_CALL(X, ...)
 

Enumerations

enum  up_state {
  S_START, S_PROTOCOL, S_SLASH1, S_SLASH2,
  S_HOST, S_PREPORT, S_PORT, S_SEGMENT,
  S_KEY, S_VALUE, S_ERROR
}
 The possible states of the URL Parser. More...
 

Functions

hpd_error_t up_add_chunk (struct up *instance, const char *chunk, size_t len)
 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...
 
static int up_isLegalURLChar (char c)
 Check if a given char is valid in an URL. More...
 

Data Structure Documentation

struct up

An URL Parser instance.

Definition at line 50 of file httpd_url_parser.c.

Collaboration diagram for up:
Data Fields
char * buffer URL Buffer.
const hpd_module_t * context
void * data User data.
size_t end Length of full URL.
size_t host Host start.
size_t host_l Host length.
size_t insert Location to insert new chunks.
size_t key_value Arguments start.
size_t last_key Last seen key start.
size_t last_key_l Last seen key length.
size_t last_path Last seen path segment start.
size_t last_path_l Last seen path segment length.
size_t last_value Last seen value start.
size_t last_value_l Last seen value length.
size_t parser Location of parser.
size_t path Path start.
size_t path_l Path length.
size_t port Port start.
size_t port_l Port length.
size_t protocol Protocol start.
size_t protocol_l Protocol length.
struct up_settings * settings Settings.
enum up_state state State.

Macro Definition Documentation

#define UP_CALL (   X,
  ... 
)
Value:
do { \
if (settings->X != NULL) { \
if ((rc = settings->X(instance->data, ##__VA_ARGS__))) { \
return rc; \
} \
} \
} while(0)
struct up * instance
enum up_state state
State.
struct hp_settings settings
enum hpd_error hpd_error_t
Definition: hpd_types.h:167
The error state. The parser will go here if the input char is not valid in an URL, or if it received an invalid char at some point.
void * data
User data.

Definition at line 186 of file httpd_url_parser.c.

Enumeration Type Documentation

enum up_state

The possible states of the URL Parser.

Enumerator
S_START 

The initial state. From here the parser can either go to S_PROTOCOL, S_SEGMENT or S_ERROR.

S_PROTOCOL 

In this state, the parser is parsing the protocol.

S_SLASH1 

Used for ignoring the first slash after protocol.

S_SLASH2 

Used for ignoring the second slash after protocol.

S_HOST 

The parser is parsing the host of an URL.

S_PREPORT 

Used for ignoring the : before a port.

S_PORT 

The parser is parsing the port of an URL.

S_SEGMENT 

The parser is parsing a path segment of an url.

S_KEY 

Here the parser is receiving the first part of a key/value pair.

S_VALUE 

The parser goes here after receiving a key, and is now expecting a value. It may go back to key if an & is found.

S_ERROR 

The error state. The parser will go here if the input char is not valid in an URL, or if it received an invalid char at some point.

Definition at line 35 of file httpd_url_parser.c.

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:

static int up_isLegalURLChar ( char  c)
static

Check if a given char is valid in an URL.

This method checks if a char is valid in an URL. Only specific chars are valid, others have to be encoded properly.

Parameters
cA char to check
Returns
1 if the char is valid in an URL, 0 otherwise

Definition at line 172 of file httpd_url_parser.c.

Here is the caller graph for this function: