libonion
|
Data Structures | |
struct | onion_url_t |
Url regexp pack. This is also a handler, and can be converted with onion_url_to_handle. More... |
Functions | |
int | onion_url_handler (onion_url_data **dd, onion_request *request, onion_response *response) |
Performs the real request: checks if its for me, and then calls the inside level. | |
onion_url * | onion_url_new () |
Creates the URL handler to map regex urls to handlersThe onion_url object can be used to add urls as needed using onion_url_add_*. | |
void | onion_url_free (onion_url *url) |
Frees the url. | |
int | onion_url_add_handler (onion_url *url, const char *regexp, onion_handler *next) |
Adds a new handler with the given regexp.Adds the given handler. | |
int | onion_url_add (onion_url *url, const char *regexp, void *handler) |
Helper to simple add basic handlers. | |
int | onion_url_add_with_data (onion_url *url, const char *regexp, void *handler, void *data, void *f) |
Helper to simple add a basic handler with data. | |
int | onion_url_add_url (onion_url *url, const char *regexp, onion_url *handler) |
Adds a regex url, with another url as handler. | |
int | onion_url_add_static (onion_url *url, const char *regexp, const char *text, int http_code) |
Adds a simple handler, it has static data and a default return code. | |
onion_handler * | onion_url_to_handler (onion_url *url) |
Returns the related handler for this url object. |
Creates an handler that checks that crrent path matches the current regexp, and passes to next.
int onion_url_add | ( | onion_url * | url, |
const char * | regexp, | ||
void * | handler | ||
) |
Helper to simple add basic handlers.
Adds a simple handler, with no custom data.
References onion_handler_t::onion_handler_new(), and onion_url_add_handler().
int onion_url_add_handler | ( | onion_url * | url, |
const char * | regexp, | ||
onion_handler * | next | ||
) |
Adds a new handler with the given regexp.Adds the given handler.
Adds a handler, using handler methods.
References ONION_ERROR, onion_handler_t::onion_handler_get_private_data(), onion_low_free(), onion_low_malloc(), onion_low_strdup(), OUD_REGEXP, and OUD_STRCMP.
Referenced by onion_url_add(), onion_url_add_url(), and onion_url_add_with_data().
int onion_url_add_static | ( | onion_url * | url, |
const char * | regexp, | ||
const char * | text, | ||
int | http_code | ||
) |
Adds a simple handler, it has static data and a default return code.
References onion_low_malloc(), onion_low_strdup(), and onion_url_add_with_data().
Adds a regex url, with another url as handler.
Addsa another url on this regexp.
References onion_url_add_handler().
int onion_url_add_with_data | ( | onion_url * | url, |
const char * | regexp, | ||
void * | handler, | ||
void * | data, | ||
void * | f | ||
) |
Helper to simple add a basic handler with data.
Adds a handler, with custom data.
References onion_handler_t::onion_handler_new(), and onion_url_add_handler().
Referenced by onion_url_add_static().
void onion_url_free | ( | onion_url * | url | ) |
int onion_url_handler | ( | onion_url_data ** | dd, |
onion_request * | request, | ||
onion_response * | response | ||
) |
Performs the real request: checks if its for me, and then calls the inside level.
References onion_request_t::GET, OD_DUP_KEY, OD_FREE_VALUE, ONION_DEBUG, ONION_DEBUG0, onion_dict_t::onion_dict_add(), onion_handler_t::onion_handler_handle(), onion_low_scalar_malloc(), onion_request_t::onion_request_advance_path(), onion_request_t::onion_request_get_path(), and OUD_STRCMP.
Referenced by onion_url_new().
onion_url * onion_url_new | ( | ) |
Creates the URL handler to map regex urls to handlersThe onion_url object can be used to add urls as needed using onion_url_add_*.
The URLs can be regular expressions or simple strings. The way to discriminate them is just to check the first character; if its ^ its a regular expression.
If a string is passed then the full path must match. If its a regexp, just the begining is matched, unless $ is set at the end. When matched, this is removed from the path.
It is important to note that when the user pretends to match the initial path elements, to later pass to another handler that will do path transversal (another url object, for example), the path must be written with a regular expression, for example: "^login/". If the user just writes the string it will match only for that specific URL, and subpaths are not in the definition.
When looking for a match, they are looked in order.
Examples::
Regexp can have groups, and they will be added as request query parameters, with just the number of the group as key. The groups start at 1, as 0 should be the full match, but its not added for performance reasons; its a very strange situation that user will need it, and always can access full path with onion_request_get_fullpath. Also all expression can be a group, and passed as nr 1.:
Be careful as . means every character, and dots in URLs must be with a backslash \ (double because of C escaping), if using regexps.
Regular expressions are used by the regexec(3) standard C library. Check that documentation to check how to create proper regular expressions. They are compiled as REG_EXTENDED.
References onion_handler_t::onion_handler_new(), onion_low_calloc(), onion_url_free_data(), and onion_url_handler().
Referenced by onion_root_url().
onion_handler * onion_url_to_handler | ( | onion_url * | url | ) |
Returns the related handler for this url object.
Returns the related handler for this url.