feat: implement router free function
parent
9fa009ccf4
commit
fbd41f7e4e
|
@ -12,6 +12,15 @@ lnm_err lnm_http_route_init(lnm_http_route **out) {
|
|||
return lnm_err_ok;
|
||||
}
|
||||
|
||||
void lnm_http_route_free(lnm_http_route *route) {
|
||||
if (route == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
lnm_http_route_segment_trie_free(route->key_segments);
|
||||
free(route);
|
||||
}
|
||||
|
||||
lnm_err lnm_http_route_segment_trie_init(lnm_http_route_segment_trie **out) {
|
||||
lnm_http_route_segment_trie *trie =
|
||||
calloc(1, sizeof(lnm_http_route_segment_trie));
|
||||
|
|
|
@ -15,13 +15,22 @@ lnm_err lnm_http_router_init(lnm_http_router **out) {
|
|||
return lnm_err_ok;
|
||||
}
|
||||
|
||||
void lnm_http_route_free(lnm_http_route *route) {
|
||||
if (route == NULL) {
|
||||
void lnm_http_router_free(lnm_http_router *router) {
|
||||
if (router == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
lnm_http_route_segment_trie_free(route->key_segments);
|
||||
free(route);
|
||||
for (size_t i = 0; i < 128; i++) {
|
||||
lnm_http_router_free(router->exact_children[i]);
|
||||
}
|
||||
|
||||
lnm_http_router_free(router->single_segment_child);
|
||||
|
||||
for (size_t i = 0; i < lnm_http_method_total; i++) {
|
||||
lnm_http_route_free(router->routes[i]);
|
||||
}
|
||||
|
||||
free(router);
|
||||
}
|
||||
|
||||
static bool is_ascii(const char *s) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
void test_routing_simple() {
|
||||
lnm_http_router *router;
|
||||
lnm_http_router_init(&router);
|
||||
TEST_CHECK(lnm_http_router_init(&router) == lnm_err_ok);
|
||||
|
||||
TEST_CHECK(lnm_http_router_add(NULL, router, lnm_http_method_get, "/test") == lnm_err_ok);
|
||||
TEST_CHECK(lnm_http_router_add(NULL, router, lnm_http_method_get, "/test/test2") == lnm_err_ok);
|
||||
|
@ -37,6 +37,8 @@ void test_routing_simple() {
|
|||
TEST_CHECK((segment = lnm_http_route_match_get(&match, "hello")) != NULL);
|
||||
TEST_CHECK(segment->start == 6);
|
||||
TEST_CHECK(segment->len == 8);
|
||||
|
||||
lnm_http_router_free(router);
|
||||
}
|
||||
|
||||
TEST_LIST = {
|
||||
|
|
Loading…
Reference in New Issue