Add r3_tree_insert_routel_ex for error message

This commit is contained in:
c9s 2014-06-03 23:50:02 +08:00
parent a3c527e1b2
commit b2946352f1
2 changed files with 16 additions and 2 deletions

View file

@ -128,6 +128,10 @@ 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);
route * r3_tree_insert_routel_ex(node *tree, int method, const char *path, int path_len, void *data, const char **errstr);
#define r3_tree_insert_routel(n, method, path, path_len, data) r3_tree_insert_routel_ex(n, method, path, path_len, data, 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_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) #define r3_tree_insert_route(n,method,path,data) r3_tree_insert_routel(n, method, path, strlen(path), data)

View file

@ -468,11 +468,21 @@ route * r3_route_createl(const char * path, int path_len) {
} }
route * r3_tree_insert_routel(node *tree, int method, const char *path, int path_len, void *data) { /**
* Helper function for creating routes from request URI path and request method
*
* method (int): METHOD_GET, METHOD_POST, METHOD_PUT, METHOD_DELETE ...
*/
route * r3_tree_insert_routel_ex(node *tree, int method, const char *path, int path_len, void *data, const char **errstr) {
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_ex(tree, path, path_len, r, data, NULL); node * ret = r3_tree_insert_pathl_ex(tree, path, path_len, r, data, errstr);
if (!ret) {
// failed insert
r3_route_free(r);
return NULL;
}
return r; return r;
} }