67#ifndef __NILOREA_HTTP_ROUTER_HEADER
68#define __NILOREA_HTTP_ROUTER_HEADER
84#define N_ROUTE_GET N_HTTP_REQ_METHOD_BIT(N_HTTP_REQ_GET)
86#define N_ROUTE_POST N_HTTP_REQ_METHOD_BIT(N_HTTP_REQ_POST)
88#define N_ROUTE_HEAD N_HTTP_REQ_METHOD_BIT(N_HTTP_REQ_HEAD)
91#define N_ROUTE_PARAMS_MAX 8
93#define N_ROUTE_NAME_MAX 31
n_http_req_method
The methods accepted.
#define N_HTTP_REQ_PATH_MAX
Longest origin-form request target ('/'-prefixed, query included).
const char * names[8]
placeholder names, in pattern order
const char * pattern
the pattern, see the file documentation
size_t lens[8]
decoded value lengths
const char * values[8]
decoded values (NUL-terminated, inside buf)
n_route_handler handler
what the caller runs on a match
size_t nb_params
number of placeholders
char buf[2048u+8+1]
storage for the decoded values
unsigned methods
accepted methods, an OR of N_ROUTE_GET / N_ROUTE_POST / N_ROUTE_HEAD
const N_ROUTE * route
the route that matched
const void * data
caller data for this route (a policy: auth, CSRF, limits...)
N_ROUTER_RESULT
result of n_router_match()
N_ROUTER * n_router_new(void)
new, empty router
int n_router_allow_header(unsigned allowed, char *out, size_t size)
write an Allow header value ("GET, HEAD, POST") for a method mask
N_ROUTER_RESULT n_router_match(const N_ROUTER *r, n_http_req_method method, const char *path, size_t len, N_ROUTE_MATCH *match, unsigned *allowed)
find the route for a method and a path
int(* n_route_handler)(void *ctx, const struct N_ROUTE_MATCH *match)
a route handler: ctx is the caller's request context
int n_router_check(const N_ROUTER *r, char *err, size_t errsz)
refuse ambiguous routes: two routes sharing a method that can match the same path with the same speci...
void n_router_free(N_ROUTER **r)
free a router and set *r to NULL (the route tables are not touched)
size_t n_router_count(const N_ROUTER *r)
number of routes added
const N_ROUTE * n_router_route(const N_ROUTER *r, size_t i)
the i-th route added (to check caller policies at start-up)
int n_router_add(N_ROUTER *r, const N_ROUTE *routes, size_t count)
compile and add a route table
#define N_ROUTE_PARAMS_MAX
most placeholders in one route
const char * n_route_param(const N_ROUTE_MATCH *m, const char *name, size_t *len)
decoded value of a placeholder
@ N_ROUTER_BAD_REQUEST
the path itself is invalid: 400
@ N_ROUTER_FOUND
a route matched path and method
@ N_ROUTER_NOT_FOUND
no route matches the path: 404 or a fallback
@ N_ROUTER_METHOD_NOT_ALLOWED
the path matches, the method does not: 405
a successful match: the route and its decoded placeholder values
Pure, strict, bounded parser for an HTTP/1.1 request head.
a compiled router (opaque)