101 (*instance) = malloc(
sizeof(
struct up));
104 (*instance)->context = context;
107 (*instance)->settings = malloc(
sizeof(
struct up_settings));
108 if (!(*instance)->settings) {
112 memcpy((*instance)->settings, settings,
sizeof(
struct up_settings));
116 (*instance)->buffer = NULL;
119 (*instance)->protocol = 0;
120 (*instance)->protocol_l = 0;
121 (*instance)->host = 0;
122 (*instance)->host_l = 0;
123 (*instance)->port = 0;
124 (*instance)->port_l = 0;
125 (*instance)->path = 0;
126 (*instance)->path_l = 0;
127 (*instance)->key_value = 0;
128 (*instance)->end = 0;
129 (*instance)->last_key = 0;
130 (*instance)->last_key_l = 0;
131 (*instance)->last_value = 0;
132 (*instance)->last_value_l = 0;
133 (*instance)->last_path = 0;
134 (*instance)->last_path_l = 0;
135 (*instance)->parser = 0;
136 (*instance)->insert = 0;
139 (*instance)->data =
data;
174 if ((c >=
'0' && c <=
'9') ||
175 (c >=
'A' && c <=
'Z') || (c >=
'a' && c <=
'z') ||
176 c ==
'-' || c ==
'.' || c ==
'_' || c ==
'~' || c ==
':' ||
177 c ==
'/' || c ==
'?' || c ==
'#' || c ==
'[' || c ==
']' ||
178 c ==
'@' || c ==
'!' || c ==
'$' || c ==
'&' || c ==
'\'' ||
179 c ==
'(' || c ==
')' || c ==
'*' || c ==
'+' || c ==
',' ||
180 c ==
';' || c ==
'=' || c ==
'%')
186 #define UP_CALL(X, ...) do { \
188 if (settings->X != NULL) { \
189 if ((rc = settings->X(instance->data, ##__VA_ARGS__))) { \
190 instance->state = S_ERROR; \
217 instance->
end += len;
218 buffer = realloc(instance->
buffer, instance->
end *
sizeof(
char));
224 instance->
buffer = buffer;
225 memcpy(&buffer[instance->
insert], chunk, len);
241 switch(instance->
state)
282 if(c ==
':' || c ==
'/') {
318 if (c ==
'/' || c ==
'?') {
385 switch(instance->
state)
Used for ignoring the : before a port.
size_t path_l
Path length.
#define HPD_LOG_RETURN(CONTEXT, E, FMT,...)
size_t last_key
Last seen key start.
size_t last_key_l
Last seen key length.
Used for ignoring the second slash after protocol.
size_t last_value
Last seen value start.
up_state
The possible states of the URL Parser.
size_t protocol_l
Protocol length.
size_t host_l
Host length.
The parser is parsing a path segment of an url.
enum up_state state
State.
hpd_error_t up_add_chunk(struct up *instance, const char *chunk, size_t len)
Parse a chunk of an URL.
struct hp_settings settings
const hpd_module_t * context
size_t key_value
Arguments start.
struct up_settings * settings
Settings.
size_t protocol
Protocol start.
hpd_error_t up_destroy(struct up *instance)
Destroy URL parser instance.
The parser is parsing the port of an URL.
size_t port_l
Port length.
enum hpd_error hpd_error_t
#define HPD_LOG_RETURN_E_ALLOC(CONTEXT)
#define HPD_LOG_RETURN_E_NULL(CONTEXT)
Here the parser is receiving the first part of a key/value pair.
size_t insert
Location to insert new chunks.
static int up_isLegalURLChar(char c)
Check if a given char is valid in an URL.
The parser goes here after receiving a key, and is now expecting a value. It may go back to key if an...
The parser is parsing the host of an URL.
hpd_error_t up_complete(struct up *instance)
Informs the parser that the URL is complete.
size_t last_path
Last seen path segment start.
settings on_path_complete
Used for ignoring the first slash after protocol.
Settings struct for the URL Parser.
size_t end
Length of full URL.
The initial state. From here the parser can either go to S_PROTOCOL, S_SEGMENT or 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.
hpd_error_t up_create(struct up **instance, struct up_settings *settings, const hpd_module_t *context, void *data)
Create URL parser instance.
size_t parser
Location of parser.
size_t last_value_l
Last seen value length.
In this state, the parser is parsing the protocol.
size_t last_path_l
Last seen path segment length.