feat(routing): add api to access key segments by name
This commit is contained in:
parent
f652fa08c1
commit
9dbdb0b089
3 changed files with 45 additions and 4 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue