![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
HTTP router (see n_http_router.h). More...
#include "nilorea/n_http_router.h"#include "nilorea/n_common.h"#include "nilorea/n_log.h"#include "nilorea/n_str.h"#include <stdio.h>#include <stdlib.h>#include <string.h>Go to the source code of this file.
Data Structures | |
| struct | _compiled |
| struct | _seg |
| struct | N_ROUTER |
| a compiled router (opaque) More... | |
Macros | |
| #define | N_ROUTER_SEGS_MAX 32 |
Enumerations | |
| enum | _seg_rank { _SEG_LITERAL = 0 , _SEG_DIGITS = 1 , _SEG_HEX = 1 , _SEG_INT = 2 , _SEG_SLUG = 3 , _SEG_ANY = 4 , _SEG_REST = 5 } |
| enum | _seg_type { _T_LITERAL , _T_DIGITS , _T_HEX , _T_INT , _T_SLUG , _T_ANY , _T_REST } |
Functions | |
| static int | _compile (const N_ROUTE *route, _compiled *c, const char **why) |
| static size_t | _decode (const char *s, size_t n, char *dst) |
| static int | _hexval (char c) |
| static int | _literal_byte_ok (unsigned char c) |
| static unsigned | _methods (unsigned m) |
| static int | _more_specific (const _compiled *a, const _compiled *b) |
| static int | _parse_n (const char *s, size_t len, size_t lo, size_t hi, size_t *n) |
| static int | _rank (_seg_type t) |
| static int | _route_fits (const _compiled *c, const char **seg, const size_t *seglen, int nseg, int trailing) |
| static int | _seg_fits (const _seg *g, const char *s, size_t n) |
| static int | _split (const char *path, size_t len, const char **seg, size_t *seglen, int *trailing) |
| static int | _types_overlap (const _seg *a, const _seg *b) |
| const char * | n_route_param (const N_ROUTE_MATCH *m, const char *name, size_t *len) |
| decoded value of a placeholder | |
| int | n_router_add (N_ROUTER *r, const N_ROUTE *routes, size_t count) |
| compile and add a route table; nothing is added when a route is refused | |
| int | n_router_allow_header (unsigned allowed, char *out, size_t size) |
| write an Allow header value for a method mask (GET implies HEAD) | |
| int | n_router_check (const N_ROUTER *r, char *err, size_t errsz) |
| refuse two routes sharing a method that can match the same path with the same specificity | |
| size_t | n_router_count (const N_ROUTER *r) |
| number of routes added | |
| void | n_router_free (N_ROUTER **r) |
| free a router and set *r to NULL (the route tables are not touched) | |
| 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 | |
| N_ROUTER * | n_router_new (void) |
| new, empty router | |
| const N_ROUTE * | n_router_route (const N_ROUTER *r, size_t i) |
| the i-th route added | |
| struct _compiled |
Definition at line 70 of file n_http_router.c.
| Data Fields | ||
|---|---|---|
| char | names[8][31+1] | |
| size_t | nb_params | |
| size_t | nb_segs | |
| const N_ROUTE * | route | |
| _seg | segs[32] | |
| int | trailing_slash | |
| struct _seg |
Definition at line 62 of file n_http_router.c.
| Data Fields | ||
|---|---|---|
| const char * | lit | |
| size_t | lit_len | |
| size_t | n | |
| int | param | |
| _seg_type | type | |
| struct N_ROUTER |
| #define N_ROUTER_SEGS_MAX 32 |
Definition at line 39 of file n_http_router.c.
Referenced by _compile(), _split(), and n_router_match().
| enum _seg_rank |
| Enumerator | |
|---|---|
| _SEG_LITERAL | |
| _SEG_DIGITS | |
| _SEG_HEX | |
| _SEG_INT | |
| _SEG_SLUG | |
| _SEG_ANY | |
| _SEG_REST | |
Definition at line 42 of file n_http_router.c.
| enum _seg_type |
| Enumerator | |
|---|---|
| _T_LITERAL | |
| _T_DIGITS | |
| _T_HEX | |
| _T_INT | |
| _T_SLUG | |
| _T_ANY | |
| _T_REST | |
Definition at line 52 of file n_http_router.c.
Definition at line 143 of file n_http_router.c.
References _literal_byte_ok(), _parse_n(), _T_ANY, _T_DIGITS, _T_HEX, _T_INT, _T_LITERAL, _T_REST, _T_SLUG, N_ROUTE::handler, _seg::lit, _seg::lit_len, N_ROUTE::methods, _seg::n, N_HTTP_REQ_PATH_MAX, N_ROUTE_GET, N_ROUTE_HEAD, N_ROUTE_NAME_MAX, N_ROUTE_PARAMS_MAX, N_ROUTE_POST, N_ROUTER_SEGS_MAX, _compiled::names, _compiled::nb_params, _compiled::nb_segs, _seg::param, N_ROUTE::pattern, _compiled::route, _compiled::segs, _compiled::trailing_slash, and _seg::type.
Referenced by n_router_add().
|
static |
Definition at line 422 of file n_http_router.c.
References _hexval(), and n_str_utf8_valid().
Referenced by n_router_match().
|
static |
Definition at line 410 of file n_http_router.c.
Referenced by _decode().
|
static |
Definition at line 138 of file n_http_router.c.
Referenced by _compile().
|
static |
Definition at line 319 of file n_http_router.c.
References N_ROUTE_GET, and N_ROUTE_HEAD.
Referenced by n_router_allow_header(), n_router_check(), and n_router_match().
Definition at line 444 of file n_http_router.c.
References _rank(), _compiled::nb_segs, _compiled::segs, and _seg::type.
Referenced by n_router_match().
|
static |
Definition at line 125 of file n_http_router.c.
Referenced by _compile().
|
static |
Definition at line 84 of file n_http_router.c.
References _SEG_ANY, _SEG_DIGITS, _SEG_HEX, _SEG_INT, _SEG_LITERAL, _SEG_REST, _SEG_SLUG, _T_ANY, _T_DIGITS, _T_HEX, _T_INT, _T_LITERAL, and _T_SLUG.
Referenced by _more_specific(), _types_overlap(), and n_router_check().
|
static |
Definition at line 480 of file n_http_router.c.
References _seg_fits(), _T_REST, _compiled::nb_segs, _compiled::segs, _compiled::trailing_slash, and _seg::type.
Referenced by n_router_match().
|
static |
Definition at line 376 of file n_http_router.c.
References _T_ANY, _T_DIGITS, _T_HEX, _T_INT, _T_LITERAL, _T_SLUG, _seg::lit, _seg::lit_len, _seg::n, and _seg::type.
Referenced by _route_fits().
|
static |
Definition at line 455 of file n_http_router.c.
References N_ROUTER_SEGS_MAX.
Referenced by n_router_match().
Definition at line 326 of file n_http_router.c.
References _rank(), _SEG_DIGITS, _seg::n, and _seg::type.
Referenced by n_router_check().