r3_tree_insert_pathl_ex function

This commit is contained in:
c9s 2014-06-02 14:47:46 +08:00
parent 16d7cc207f
commit 04d8977b21
3 changed files with 12 additions and 12 deletions

View file

@ -18,15 +18,15 @@ by Yo-An Lin <yoanlin93@gmail.com>
API changes:
1. Removed the `route` argument from `r3_tree_insert_pathl_`:
1. Removed the `route` argument from `r3_tree_insert_pathl_ex`:
node * r3_tree_insert_pathl_(node *tree, char *path, int path_len, void * data);
node * r3_tree_insert_pathl_ex(node *tree, char *path, int path_len, void * data);
This reduce the interface complexity, e.g.,
r3_tree_insert_path(n, "/user2/{id:\\d+}", &var2);
2. The original `r3_tree_insert_pathl_` has been moved to `r3_tree_insert_pathl_` as a private API.
2. The original `r3_tree_insert_pathl_ex` has been moved to `r3_tree_insert_pathl_ex` as a private API.
3. Moved `r3_tree_matchl` to `r3_tree_matchl` since it require the length of the path string.

View file

@ -115,7 +115,7 @@ node * r3_tree_insert_pathl(node *tree, const char *path, int path_len, void * d
route * r3_tree_insert_routel(node *tree, int method, const char *path, int path_len, void *data);
#define r3_tree_insert_path(n,p,d) r3_tree_insert_pathl_(n,p,strlen(p), NULL, d, NULL)
#define r3_tree_insert_path(n,p,d) r3_tree_insert_pathl_ex(n,p,strlen(p), NULL, d, NULL)
#define r3_tree_insert_route(n,method,path,data) r3_tree_insert_routel(n, method, path, strlen(path), data)
@ -123,7 +123,7 @@ route * r3_tree_insert_routel(node *tree, int method, const char *path, int path
/**
* The private API to insert a path
*/
node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route * route, void * data, char ** errstr);
node * r3_tree_insert_pathl_ex(node *tree, const char *path, int path_len, route * route, void * data, char ** errstr);
void r3_tree_dump(const node * n, int level);

View file

@ -468,7 +468,7 @@ route * r3_tree_insert_routel(node *tree, int method, const char *path, int path
route *r = r3_route_createl(path, path_len);
CHECK_PTR(r);
r->request_method = method; // ALLOW GET OR POST METHOD
r3_tree_insert_pathl_(tree, path, path_len, r, data, NULL);
r3_tree_insert_pathl_ex(tree, path, path_len, r, data, NULL);
return r;
}
@ -476,7 +476,7 @@ route * r3_tree_insert_routel(node *tree, int method, const char *path, int path
node * r3_tree_insert_pathl(node *tree, const char *path, int path_len, void * data)
{
return r3_tree_insert_pathl_(tree, path, path_len, NULL , data, NULL);
return r3_tree_insert_pathl_ex(tree, path, path_len, NULL , data, NULL);
}
@ -552,7 +552,7 @@ edge * r3_node_find_common_prefix(node *n, char *path, int path_len, int *prefix
/**
* Return the last inserted node.
*/
node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route * route, void * data, char **errstr)
node * r3_tree_insert_pathl_ex(node *tree, const char *path, int path_len, route * route, void * data, char **errstr)
{
node * n = tree;
@ -602,7 +602,7 @@ node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route *
r3_node_connect(n, zstrndup(path, (int)(p - path)), child);
// and insert the rest part to the child
return r3_tree_insert_pathl_(child, p, path_len - (int)(p - path), route, data, errstr);
return r3_tree_insert_pathl_ex(child, p, path_len - (int)(p - path), route, data, errstr);
} else {
if (slug_cnt == 1) {
@ -644,7 +644,7 @@ node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route *
int restlen = path_len - ((slug_p - path) + slug_len);
if (restlen) {
return r3_tree_insert_pathl_(c2, slug_p + slug_len, restlen, route, data, errstr);
return r3_tree_insert_pathl_ex(c2, slug_p + slug_len, restlen, route, data, errstr);
}
c2->data = data;
@ -673,7 +673,7 @@ node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route *
// there are something more we can insert
if ( subpath_len > 0 ) {
return r3_tree_insert_pathl_(e->child, subpath, subpath_len, route, data, errstr);
return r3_tree_insert_pathl_ex(e->child, subpath, subpath_len, route, data, errstr);
} else {
// there are no more path to insert
@ -696,7 +696,7 @@ node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route *
* we should split the end point and make a branch here...
*/
r3_edge_branch(e, prefix_len);
return r3_tree_insert_pathl_(e->child, subpath, subpath_len, route , data, errstr);
return r3_tree_insert_pathl_ex(e->child, subpath, subpath_len, route , data, errstr);
} else {
fprintf(stderr, "unexpected route.");
return NULL;