feat(routing): add api to access key segments by name

This commit is contained in:
Jef Roosens 2024-02-22 22:31:00 +01:00
parent f652fa08c1
commit 9dbdb0b089
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
3 changed files with 45 additions and 4 deletions

View file

@ -268,3 +268,30 @@ lnm_http_route_err lnm_http_router_route(lnm_http_route_match *out,
return __lnm_http_router_route(out, router, method, path, 0, 0);
}
lnm_err lnm_http_route_match_get(lnm_http_route_match_segment **out,
lnm_http_route_match *match, const char *key) {
if (match->route->key_segments == NULL) {
return lnm_err_not_found;
}
lnm_http_route_segment_trie *trie = match->route->key_segments;
while (*key != '\0') {
trie = trie->children[(unsigned char)*key];
if (trie == NULL) {
return lnm_err_not_found;
}
key++;
}
if (!trie->represents_segment) {
return lnm_err_not_found;
}
*out = &match->key_segments[trie->index];
return lnm_err_ok;
}