print errmsg
This commit is contained in:
parent
d120389415
commit
57b4fde126
3 changed files with 14 additions and 14 deletions
|
@ -113,7 +113,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);
|
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)
|
#define r3_tree_insert_path(n,p,d) r3_tree_insert_pathl_(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)
|
#define r3_tree_insert_route(n,method,path,data) r3_tree_insert_routel(n, method, path, strlen(path), data)
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ route * r3_tree_insert_routel(node *tree, int method, const char *path, int path
|
||||||
/**
|
/**
|
||||||
* The private API to insert a 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);
|
node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route * route, void * data, char ** errstr);
|
||||||
|
|
||||||
void r3_tree_dump(const node * n, int level);
|
void r3_tree_dump(const node * n, int level);
|
||||||
|
|
||||||
|
|
22
src/node.c
22
src/node.c
|
@ -453,7 +453,7 @@ route * r3_tree_insert_routel(node *tree, int method, const char *path, int path
|
||||||
route *r = r3_route_createl(path, path_len);
|
route *r = r3_route_createl(path, path_len);
|
||||||
CHECK_PTR(r);
|
CHECK_PTR(r);
|
||||||
r->request_method = method; // ALLOW GET OR POST METHOD
|
r->request_method = method; // ALLOW GET OR POST METHOD
|
||||||
r3_tree_insert_pathl_(tree, path, path_len, r, data);
|
r3_tree_insert_pathl_(tree, path, path_len, r, data, NULL);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,14 +461,14 @@ 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)
|
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);
|
return r3_tree_insert_pathl_(tree, path, path_len, NULL , data, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the last inserted node.
|
* Return the last inserted node.
|
||||||
*/
|
*/
|
||||||
node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route * route, void * data)
|
node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route * route, void * data, char **errstr)
|
||||||
{
|
{
|
||||||
node * n = tree;
|
node * n = tree;
|
||||||
edge * e = NULL;
|
edge * e = NULL;
|
||||||
|
@ -499,10 +499,10 @@ node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route *
|
||||||
// common prefix not found, insert a new edge for this pattern
|
// common prefix not found, insert a new edge for this pattern
|
||||||
if ( prefix_len == 0 ) {
|
if ( prefix_len == 0 ) {
|
||||||
// there are two more slugs, we should break them into several parts
|
// there are two more slugs, we should break them into several parts
|
||||||
char *errstr = NULL;
|
char *err = NULL;
|
||||||
int slug_cnt = slug_count(path, path_len, &errstr);
|
int slug_cnt = slug_count(path, path_len, &err);
|
||||||
if (errstr) {
|
if (err) {
|
||||||
printf("Can not insert path '%s'. Error: %s\n", path, errstr);
|
printf("Can not insert path '%s'. Error: %s\n", path, err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,7 +529,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);
|
r3_node_connect(n, zstrndup(path, (int)(p - path)), child);
|
||||||
|
|
||||||
// and insert the rest part to the child
|
// and insert the rest part to the child
|
||||||
return r3_tree_insert_pathl_(child, p, path_len - (int)(p - path), route, data);
|
return r3_tree_insert_pathl_(child, p, path_len - (int)(p - path), route, data, errstr);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (slug_cnt == 1) {
|
if (slug_cnt == 1) {
|
||||||
|
@ -569,7 +569,7 @@ node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route *
|
||||||
// insert rest
|
// insert rest
|
||||||
int restlen = (path_len - (slug_p - path)) - slug_len;
|
int restlen = (path_len - (slug_p - path)) - slug_len;
|
||||||
if (restlen) {
|
if (restlen) {
|
||||||
return r3_tree_insert_pathl_(c2, slug_p + slug_len, restlen, route, data);
|
return r3_tree_insert_pathl_(c2, slug_p + slug_len, restlen, route, data, errstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
c2->data = data;
|
c2->data = data;
|
||||||
|
@ -598,7 +598,7 @@ node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route *
|
||||||
|
|
||||||
// there are something more we can insert
|
// there are something more we can insert
|
||||||
if ( subpath_len > 0 ) {
|
if ( subpath_len > 0 ) {
|
||||||
return r3_tree_insert_pathl_(e->child, subpath, subpath_len, route, data);
|
return r3_tree_insert_pathl_(e->child, subpath, subpath_len, route, data, errstr);
|
||||||
} else {
|
} else {
|
||||||
// there are no more path to insert
|
// there are no more path to insert
|
||||||
|
|
||||||
|
@ -621,7 +621,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...
|
* we should split the end point and make a branch here...
|
||||||
*/
|
*/
|
||||||
r3_edge_branch(e, prefix_len);
|
r3_edge_branch(e, prefix_len);
|
||||||
return r3_tree_insert_pathl_(e->child, subpath, subpath_len, route , data);
|
return r3_tree_insert_pathl_(e->child, subpath, subpath_len, route , data, errstr);
|
||||||
} else {
|
} else {
|
||||||
printf("unexpected route.");
|
printf("unexpected route.");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -69,7 +69,7 @@ char * inside_slug(const char * needle, int needle_len, char *offset, char **err
|
||||||
if (found_s1 || found_s2) {
|
if (found_s1 || found_s2) {
|
||||||
// wrong slug pattern
|
// wrong slug pattern
|
||||||
if(errstr) {
|
if(errstr) {
|
||||||
asprintf(errstr, "incomplete slug pattern");
|
asprintf(errstr, "Incomplete slug pattern");
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue