feat(routing): implement router merging

This commit is contained in:
Jef Roosens 2024-03-02 11:11:54 +01:00
parent 6eb965adcd
commit 2ce49a3347
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
3 changed files with 208 additions and 4 deletions

View file

@ -49,11 +49,23 @@ lnm_err lnm_http_router_add(lnm_http_route **out, lnm_http_router *http_router,
lnm_http_method method, const char *path);
/**
* Add all of the child router's routes to the parent router, under the given
* route prefix.
* Checks whether the two routers have any conflicting parts.
*/
lnm_err lnm_http_router_nest(lnm_http_router *parent,
const lnm_http_router *child, const char *prefix);
bool lnm_http_router_conflicts(const lnm_http_router *r1,
const lnm_http_router *r2);
/**
* Merge two routers, with the result ending up in r1. This is equivalent to
* nesting a router on '/'.
*/
lnm_err lnm_http_router_merge(lnm_http_router *r1, lnm_http_router *r2);
/**
* Integrate the child router into the parent routing, mounting its paths on the
* given prefix.
*/
lnm_err lnm_http_router_nest(lnm_http_router *parent, lnm_http_router *child,
const char *prefix);
lnm_http_route_err lnm_http_router_route(lnm_http_route_match *out,
const lnm_http_router *router,