Sagui library v3.5.0
Cross-platform library which helps to develop web servers or frameworks.
|
Data Structures | |
struct | sg_entrypoint |
struct | sg_entrypoints |
struct | sg_route |
struct | sg_router |
Typedefs | |
typedef int(* | sg_entrypoints_iter_cb) (void *cls, struct sg_entrypoint *entrypoint) |
typedef int(* | sg_segments_iter_cb) (void *cls, unsigned int index, const char *segment) |
typedef int(* | sg_vars_iter_cb) (void *cls, const char *name, const char *val) |
typedef void(* | sg_route_cb) (void *cls, struct sg_route *route) |
typedef int(* | sg_routes_iter_cb) (void *cls, struct sg_route *route) |
typedef int(* | sg_router_dispatch_cb) (void *cls, const char *path, struct sg_route *route) |
typedef int(* | sg_router_match_cb) (void *cls, struct sg_route *route) |
Functions | |
const char * | sg_entrypoint_name (struct sg_entrypoint *entrypoint) |
int | sg_entrypoint_set_user_data (struct sg_entrypoint *entrypoint, void *data) |
void * | sg_entrypoint_user_data (struct sg_entrypoint *entrypoint) |
struct sg_entrypoints * | sg_entrypoints_new (void) __attribute__((malloc)) |
void | sg_entrypoints_free (struct sg_entrypoints *entrypoints) |
int | sg_entrypoints_add (struct sg_entrypoints *entrypoints, const char *path, void *user_data) |
int | sg_entrypoints_rm (struct sg_entrypoints *entrypoints, const char *path) |
int | sg_entrypoints_iter (struct sg_entrypoints *entrypoints, sg_entrypoints_iter_cb cb, void *cls) |
int | sg_entrypoints_clear (struct sg_entrypoints *entrypoints) |
int | sg_entrypoints_find (struct sg_entrypoints *entrypoints, struct sg_entrypoint **entrypoint, const char *path) |
void * | sg_route_handle (struct sg_route *route) |
void * | sg_route_match (struct sg_route *route) |
const char * | sg_route_rawpattern (struct sg_route *route) |
char * | sg_route_pattern (struct sg_route *route) __attribute__((malloc)) |
const char * | sg_route_path (struct sg_route *route) |
int | sg_route_segments_iter (struct sg_route *route, sg_segments_iter_cb cb, void *cls) |
int | sg_route_vars_iter (struct sg_route *route, sg_vars_iter_cb cb, void *cls) |
void * | sg_route_user_data (struct sg_route *route) |
int | sg_routes_add2 (struct sg_route **routes, struct sg_route **route, const char *pattern, char *errmsg, size_t errlen, sg_route_cb cb, void *cls) |
bool | sg_routes_add (struct sg_route **routes, const char *pattern, sg_route_cb cb, void *cls) |
int | sg_routes_rm (struct sg_route **routes, const char *pattern) |
int | sg_routes_iter (struct sg_route *routes, sg_routes_iter_cb cb, void *cls) |
int | sg_routes_next (struct sg_route **route) |
unsigned int | sg_routes_count (struct sg_route *routes) |
int | sg_routes_cleanup (struct sg_route **routes) |
struct sg_router * | sg_router_new (struct sg_route *routes) __attribute__((malloc)) |
void | sg_router_free (struct sg_router *router) |
int | sg_router_dispatch2 (struct sg_router *router, const char *path, void *user_data, sg_router_dispatch_cb dispatch_cb, void *cls, sg_router_match_cb match_cb) |
int | sg_router_dispatch (struct sg_router *router, const char *path, void *user_data) |
High-performance path routing.
typedef int(* sg_entrypoints_iter_cb) (void *cls, struct sg_entrypoint *entrypoint) |
Callback signature used by sg_entrypoints_iter() to iterate entry-point items.
[out] | cls | User-defined closure. |
[out] | entrypoint | Current iterated entry-point. |
0 | Success. |
E<ERROR> | User-defined error to stop the items iteration. |
typedef int(* sg_segments_iter_cb) (void *cls, unsigned int index, const char *segment) |
Callback signature used by sg_route_segments_iter() to iterate the path segments.
[out] | cls | User-defined closure. |
[out] | index | Current iterated item index. |
[out] | segment | Current iterated segment. |
0 | Success. |
E<ERROR> | User-defined error to stop the segments iteration. |
typedef int(* sg_vars_iter_cb) (void *cls, const char *name, const char *val) |
Callback signature used by sg_route_vars_iter() to iterate the path variables.
[out] | cls | User-defined closure. |
[out] | name | Current iterated variable name. |
[out] | val | Current iterated variable value. |
0 | Success. |
E<ERROR> | User-defined error to stop the variables iteration. |
typedef void(* sg_route_cb) (void *cls, struct sg_route *route) |
Callback signature used to handle the path routing.
[out] | cls | User-defined closure. |
[out] | route | Route handle. |
typedef int(* sg_routes_iter_cb) (void *cls, struct sg_route *route) |
Callback signature used by sg_routes_iter() to iterate route items.
[out] | cls | User-defined closure. |
[out] | route | Current iterated route. |
0 | Success. |
E<ERROR> | User-defined error to stop the route items iteration. |
typedef int(* sg_router_dispatch_cb) (void *cls, const char *path, struct sg_route *route) |
Callback signature used by sg_router_dispatch2 in the route dispatching loop.
[out] | cls | User-defined closure. |
[out] | path | Route path as a null-terminated string. |
[out] | route | Route handle. |
0 | Success. |
E<ERROR> | User-defined error to stop the route dispatching loop. |
typedef int(* sg_router_match_cb) (void *cls, struct sg_route *route) |
Callback signature used by sg_router_dispatch2 when the path matches the pattern before the route dispatching.
[out] | cls | User-defined closure. |
[out] | route | Route handle. |
0 | Success. |
E<ERROR> | User-defined error to stop the route dispatching. |
const char * sg_entrypoint_name | ( | struct sg_entrypoint * | entrypoint | ) |
Returns the name of the entry-point handle entrypoint
.
[in] | entrypoint | Entry-point handle. |
NULL | If the entrypoint is null and set the errno to EINVAL . |
int sg_entrypoint_set_user_data | ( | struct sg_entrypoint * | entrypoint, |
void * | data | ||
) |
Sets user data to the entry-point handle.
[in] | entrypoint | Entry-point handle. |
[in] | data | User data pointer. |
0 | Success. |
EINVAL | Invalid argument. |
void * sg_entrypoint_user_data | ( | struct sg_entrypoint * | entrypoint | ) |
Gets user data from the entry-point handle.
[in] | entrypoint | Entry-point handle. |
NULL | If entrypoint is null and set the errno to EINVAL . |
struct sg_entrypoints * sg_entrypoints_new | ( | void | ) |
Creates a new entry-points handle.
NULL | If no memory space is available. |
void sg_entrypoints_free | ( | struct sg_entrypoints * | entrypoints | ) |
Frees the entry-points handle previously allocated by sg_entrypoints_new().
[in] | entrypoints | Pointer of the entry-points to be freed. |
int sg_entrypoints_add | ( | struct sg_entrypoints * | entrypoints, |
const char * | path, | ||
void * | user_data | ||
) |
Adds a new entry-point item to the entry-points entrypoints
.
[in] | entrypoints | Entry-points handle. |
[in] | path | Entry-point path. |
[in] | user_data | User data pointer. |
0 | Success. |
EINVAL | Invalid argument. |
ENOMEM | Out of memory. |
EALREADY | Entry-point already added. |
int sg_entrypoints_rm | ( | struct sg_entrypoints * | entrypoints, |
const char * | path | ||
) |
Removes an entry-point item from the entry-points entrypoints
.
[in] | entrypoints | Entry-points handle. |
[in] | path | Entry-point path to be removed. |
0 | Success. |
EINVAL | Invalid argument. |
ENOMEM | Out of memory. |
ENOENT | Entry-point already removed. |
int sg_entrypoints_iter | ( | struct sg_entrypoints * | entrypoints, |
sg_entrypoints_iter_cb | cb, | ||
void * | cls | ||
) |
Iterates over entry-point items.
[in] | entrypoints | Entry-points handle. |
[in] | cb | Callback to iterate the entry-point items. |
[in,out] | cls | User-specified value. |
0 | Success. |
EINVAL | Invalid argument. |
0
. int sg_entrypoints_clear | ( | struct sg_entrypoints * | entrypoints | ) |
Clears all existing entry-point items in the entry-points entrypoints
.
[in] | entrypoints | Entry-points handle. |
0 | Success. |
EINVAL | Invalid argument. |
int sg_entrypoints_find | ( | struct sg_entrypoints * | entrypoints, |
struct sg_entrypoint ** | entrypoint, | ||
const char * | path | ||
) |
Finds an entry-point item by path.
[in] | entrypoints | Entry-points handle. |
[in,out] | entrypoint | Pointer of the variable to store the found entry-point. |
[in] | path | Entry-point path to be found. |
0 | Success. |
EINVAL | Invalid argument. |
ENOMEM | Out of memory. |
ENOENT | Pair not found. |
void * sg_route_handle | ( | struct sg_route * | route | ) |
Returns the PCRE2 handle containing the compiled regex code.
[in] | route | Route handle. |
NULL | If route is null and set the errno to EINVAL . |
void * sg_route_match | ( | struct sg_route * | route | ) |
Returns the PCRE2 match data created from the route pattern.
[in] | route | Route handle. |
NULL | If route is null and set the errno to EINVAL . |
const char * sg_route_rawpattern | ( | struct sg_route * | route | ) |
Returns the raw route pattern. For example, given a pattern /foo
, the raw pattern is ^/foo$
.
[in] | route | Route handle. |
NULL | If route is null and set the errno to EINVAL . |
char * sg_route_pattern | ( | struct sg_route * | route | ) |
Returns the route pattern.
[in] | route | Route handle. |
NULL |
|
const char * sg_route_path | ( | struct sg_route * | route | ) |
Returns the route path.
[in] | route | Route handle. |
NULL | If route is null and set the errno to EINVAL . |
int sg_route_segments_iter | ( | struct sg_route * | route, |
sg_segments_iter_cb | cb, | ||
void * | cls | ||
) |
Iterates over path segments.
[in] | route | Route handle. |
[in] | cb | Callback to iterate the path segments. |
[in,out] | cls | User-specified value. |
0 | Success. |
EINVAL | Invalid argument. |
0
. int sg_route_vars_iter | ( | struct sg_route * | route, |
sg_vars_iter_cb | cb, | ||
void * | cls | ||
) |
Iterates over path variables.
[in] | route | Route handle. |
[in] | cb | Callback to iterate the path variables. |
[in,out] | cls | User-specified value. |
0 | Success. |
EINVAL | Invalid argument. |
ENOMEM | Out of memory. |
0
. void * sg_route_user_data | ( | struct sg_route * | route | ) |
Gets user data from the route handle.
[in] | route | Route handle. |
NULL | If route is null and set the errno to EINVAL . |
int sg_routes_add2 | ( | struct sg_route ** | routes, |
struct sg_route ** | route, | ||
const char * | pattern, | ||
char * | errmsg, | ||
size_t | errlen, | ||
sg_route_cb | cb, | ||
void * | cls | ||
) |
Adds a route item to the route list routes
.
[in,out] | routes | Route list pointer to add a new route item. |
[in,out] | route | Pointer of the variable to store the added route reference. |
[in] | pattern | Pattern as a null-terminated string. It must be a valid regular expression in PCRE2 syntax. |
[in,out] | errmsg | Pointer of a string to store the error message. |
[in] | errlen | Length of the error message. |
[in] | cb | Callback to handle the path routing. |
[in] | cls | User-defined closure. |
0 | Success. |
EINVAL | Invalid argument. |
EALREADY | Route already added. |
ENOMEM | Out of memory. |
^
and $
automatically if it does not start with (
. EINVAL
if used. bool sg_routes_add | ( | struct sg_route ** | routes, |
const char * | pattern, | ||
sg_route_cb | cb, | ||
void * | cls | ||
) |
Adds a route item to the route list routes
. It uses the stderr
to print the validation errors.
[in,out] | routes | Route list pointer to add a new route item. |
[in] | pattern | Pattern as a null-terminated string. It must be a valid regular expression in PCRE2 syntax. |
[in] | cb | Callback to handle the path routing. |
[in] | cls | User-defined closure. |
0 | Success. |
EINVAL | Invalid argument. |
EALREADY | Route already added. |
ENOMEM | Out of memory. |
^
and $
automatically if it does not start with (
. EINVAL
if used. int sg_routes_rm | ( | struct sg_route ** | routes, |
const char * | pattern | ||
) |
Removes a route item from the route list routes
.
[in,out] | routes | Route list pointer to add a new route item. |
[in] | pattern | Pattern as a null-terminated string of the route to be removed. |
0 | Success. |
EINVAL | Invalid argument. |
ENOENT | Route already removed. |
int sg_routes_iter | ( | struct sg_route * | routes, |
sg_routes_iter_cb | cb, | ||
void * | cls | ||
) |
Iterates over all the routes in the route list routes
.
[in] | routes | Route list handle. |
[in] | cb | Callback to iterate over route items. |
[in] | cls | User-defined closure. |
0 | Success. |
EINVAL | Invalid argument. |
E<ERROR> | User-defined error to abort the list iteration. |
int sg_routes_next | ( | struct sg_route ** | route | ) |
Returns the next route into the route list.
[in,out] | route | Pointer to the next route item. |
0 | Success. |
EINVAL | Invalid argument. |
unsigned int sg_routes_count | ( | struct sg_route * | routes | ) |
Counts the total routes in the route list routes
.
[in] | routes | Route list handle. |
0 | If the list is empty or null. |
int sg_routes_cleanup | ( | struct sg_route ** | routes | ) |
Cleans the entire route list.
[in,out] | routes | Pointer to the route list. |
Creates a new path router handle. It requires a filled route list routes
.
[in] | routes | Route list handle. |
NULL | If the routes is null and set the errno to EINVAL or no memory space. |
void sg_router_free | ( | struct sg_router * | router | ) |
Frees the router handle previously allocated by sg_router_new().
[in] | router | Router handle. |
int sg_router_dispatch2 | ( | struct sg_router * | router, |
const char * | path, | ||
void * | user_data, | ||
sg_router_dispatch_cb | dispatch_cb, | ||
void * | cls, | ||
sg_router_match_cb | match_cb | ||
) |
Dispatches a route that its pattern matches the path passed in path
.
[in] | router | Router handle. |
[in] | path | Path to dispatch a route. |
[in] | user_data | User data pointer to be held by the route. |
[in] | dispatch_cb | Callback triggered for each route item in the route dispatching loop. |
[in] | cls | User-defined closure passed to the dispatch_cb and match_cb callbacks. |
[in] | match_cb | Callback triggered when the path matches the route pattern. |
0 | Success. |
EINVAL | Invalid argument. |
ENOENT | Route not found or path not matched. |
E<ERROR> | User-defined error in dispatch_cb or match_cb . |
int sg_router_dispatch | ( | struct sg_router * | router, |
const char * | path, | ||
void * | user_data | ||
) |
Dispatches a route that its pattern matches the path passed in path
.
[in] | router | Router handle. |
[in] | path | Path to dispatch a route. |
[in] | user_data | User data pointer to be held by the route. |
0 | Success. |
EINVAL | Invalid argument. |
ENOENT | Route not found or path not matched. |
E<ERROR> | User-defined error in dispatch_cb or match_cb . |