simplify functions to macro
This commit is contained in:
parent
8e39e58c88
commit
5137d4d8e4
4 changed files with 15 additions and 12 deletions
|
@ -126,6 +126,10 @@ edge * r3_node_find_common_prefix(node *n, const char *path, int path_len, int *
|
|||
|
||||
node * r3_tree_insert_pathl(node *tree, const char *path, int path_len, void * data);
|
||||
|
||||
#define r3_tree_insert_pathl(tree, path, path_len, data) r3_tree_insert_pathl_ex(tree, path, path_len, NULL , data, NULL)
|
||||
|
||||
|
||||
|
||||
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, char **errstr);
|
||||
|
@ -184,6 +188,9 @@ int r3_route_cmp(const route *r1, const match_entry *r2);
|
|||
|
||||
route * r3_tree_match_route(const node *n, match_entry * entry);
|
||||
|
||||
#define r3_route_create(p) r3_route_createl(p, strlen(p))
|
||||
|
||||
|
||||
#define METHOD_GET 2
|
||||
#define METHOD_POST 2<<1
|
||||
#define METHOD_PUT 2<<2
|
||||
|
|
|
@ -23,8 +23,15 @@
|
|||
#include "slug.h"
|
||||
#include "zmalloc.h"
|
||||
|
||||
|
||||
#define CHECK_PTR(ptr) if (ptr == NULL) return NULL;
|
||||
|
||||
|
||||
edge * r3_edge_createl(const char * pattern, int pattern_len, node * child) {
|
||||
edge * e = (edge*) zmalloc( sizeof(edge) );
|
||||
|
||||
CHECK_PTR(e);
|
||||
|
||||
e->pattern = (char*) pattern;
|
||||
e->pattern_len = pattern_len;
|
||||
e->opcode = 0;
|
||||
|
|
11
src/node.c
11
src/node.c
|
@ -450,11 +450,6 @@ node * r3_node_create() {
|
|||
return n;
|
||||
}
|
||||
|
||||
|
||||
route * r3_route_create(const char * path) {
|
||||
return r3_route_createl(path, strlen(path));
|
||||
}
|
||||
|
||||
void r3_route_free(route * route) {
|
||||
zfree(route);
|
||||
}
|
||||
|
@ -497,12 +492,6 @@ route * r3_tree_insert_routel_ex(node *tree, int method, const char *path, int p
|
|||
|
||||
|
||||
|
||||
node * r3_tree_insert_pathl(node *tree, const char *path, int path_len, void * data)
|
||||
{
|
||||
return r3_tree_insert_pathl_ex(tree, path, path_len, NULL , data, NULL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find common prefix from the edges of the node.
|
||||
*
|
||||
|
|
|
@ -674,7 +674,7 @@ START_TEST(test_insert_route)
|
|||
r3_tree_insert_route(n, METHOD_POST, "/blog/post", &var2);
|
||||
|
||||
route *c = r3_tree_match_route(n, entry);
|
||||
fail_if(c == NULL);
|
||||
ck_assert(c != NULL);
|
||||
|
||||
r3_tree_free(n);
|
||||
match_entry_free(entry);
|
||||
|
|
Loading…
Reference in a new issue