Rename route_ptr => route
This commit is contained in:
parent
5ca345d570
commit
64acfd8cd6
4 changed files with 17 additions and 14 deletions
12
include/r3.h
12
include/r3.h
|
@ -42,9 +42,9 @@ struct _node {
|
||||||
int * ov;
|
int * ov;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the pointer of route structure
|
* the pointer of route data
|
||||||
*/
|
*/
|
||||||
void * route_ptr;
|
void * data;
|
||||||
|
|
||||||
int endpoint;
|
int endpoint;
|
||||||
};
|
};
|
||||||
|
@ -60,8 +60,10 @@ typedef struct {
|
||||||
str_array * vars;
|
str_array * vars;
|
||||||
char * path; // current path to dispatch
|
char * path; // current path to dispatch
|
||||||
int path_len; // the length of the current path
|
int path_len; // the length of the current path
|
||||||
void * route_ptr; // route ptr
|
|
||||||
int request_method; // current request method
|
int request_method; // current request method
|
||||||
|
|
||||||
|
void * data; // route ptr
|
||||||
|
|
||||||
char * host; // the request host
|
char * host; // the request host
|
||||||
int host_len;
|
int host_len;
|
||||||
|
|
||||||
|
@ -98,9 +100,9 @@ edge * r3_node_find_edge(node * n, char * pat);
|
||||||
|
|
||||||
void r3_tree_append_edge(node *n, edge *child);
|
void r3_tree_append_edge(node *n, edge *child);
|
||||||
|
|
||||||
node * r3_tree_insert_path(node *tree, char *route, void * route_ptr);
|
node * r3_tree_insert_path(node *tree, char *route, void * data);
|
||||||
|
|
||||||
node * r3_tree_insert_pathn(node *tree, char *route, int route_len, void * route_ptr);
|
node * r3_tree_insert_pathn(node *tree, char *route, int route_len, void * data);
|
||||||
|
|
||||||
void r3_tree_dump(node * n, int level);
|
void r3_tree_dump(node * n, int level);
|
||||||
|
|
||||||
|
|
16
src/node.c
16
src/node.c
|
@ -219,7 +219,7 @@ match_entry * match_entry_createl(char * path, int path_len) {
|
||||||
entry->vars = str_array_create(3);
|
entry->vars = str_array_create(3);
|
||||||
entry->path = path;
|
entry->path = path;
|
||||||
entry->path_len = path_len;
|
entry->path_len = path_len;
|
||||||
entry->route_ptr = NULL;
|
entry->data = NULL;
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,12 +364,12 @@ node * r3_node_create() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
node * r3_tree_insert_path(node *tree, char *route, void * route_ptr)
|
node * r3_tree_insert_path(node *tree, char *route, void * data)
|
||||||
{
|
{
|
||||||
return r3_tree_insert_pathn(tree, route, strlen(route) , route_ptr);
|
return r3_tree_insert_pathn(tree, route, strlen(route) , data);
|
||||||
}
|
}
|
||||||
|
|
||||||
node * r3_tree_insert_pathn(node *tree, char *route, int route_len, void * route_ptr)
|
node * r3_tree_insert_pathn(node *tree, char *route, int route_len, void * data)
|
||||||
{
|
{
|
||||||
node * n = tree;
|
node * n = tree;
|
||||||
edge * e = NULL;
|
edge * e = NULL;
|
||||||
|
@ -403,7 +403,7 @@ node * r3_tree_insert_pathn(node *tree, char *route, int route_len, void * route
|
||||||
node * child = r3_tree_create(3);
|
node * child = r3_tree_create(3);
|
||||||
r3_tree_add_child(n, strndup(route, route_len) , child);
|
r3_tree_add_child(n, strndup(route, route_len) , child);
|
||||||
info("edge not found, insert one: %s\n", route);
|
info("edge not found, insert one: %s\n", route);
|
||||||
child->route_ptr = route_ptr;
|
child->data = data;
|
||||||
child->endpoint++;
|
child->endpoint++;
|
||||||
return child;
|
return child;
|
||||||
} else if ( offset == e->pattern_len ) { // fully-equal to the pattern of the edge
|
} else if ( offset == e->pattern_len ) { // fully-equal to the pattern of the edge
|
||||||
|
@ -413,11 +413,11 @@ node * r3_tree_insert_pathn(node *tree, char *route, int route_len, void * route
|
||||||
|
|
||||||
// there are something more we can insert
|
// there are something more we can insert
|
||||||
if ( subroute_len > 0 ) {
|
if ( subroute_len > 0 ) {
|
||||||
return r3_tree_insert_pathn(e->child, subroute, subroute_len, route_ptr);
|
return r3_tree_insert_pathn(e->child, subroute, subroute_len, data);
|
||||||
} else {
|
} else {
|
||||||
// no more,
|
// no more,
|
||||||
e->child->endpoint++; // make it as an endpoint, TODO: put the route value
|
e->child->endpoint++; // make it as an endpoint, TODO: put the route value
|
||||||
e->child->route_ptr = route_ptr;
|
e->child->data = data;
|
||||||
return e->child;
|
return e->child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,7 +451,7 @@ node * r3_tree_insert_pathn(node *tree, char *route, int route_len, void * route
|
||||||
|
|
||||||
// move n->edges to c1
|
// move n->edges to c1
|
||||||
c2->endpoint++;
|
c2->endpoint++;
|
||||||
c2->route_ptr = route_ptr;
|
c2->data = data;
|
||||||
return c2;
|
return c2;
|
||||||
} else {
|
} else {
|
||||||
printf("unexpected condition.");
|
printf("unexpected condition.");
|
||||||
|
|
|
@ -88,3 +88,4 @@
|
||||||
1400374415,13164892.40
|
1400374415,13164892.40
|
||||||
1400382244,12226293.04
|
1400382244,12226293.04
|
||||||
1400382299,11775631.24
|
1400382299,11775631.24
|
||||||
|
1400382382,12331702.88
|
||||||
|
|
|
|
@ -627,7 +627,7 @@ START_TEST(benchmark_str)
|
||||||
m = r3_tree_match(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL);
|
m = r3_tree_match(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL);
|
||||||
fail_if( m == NULL );
|
fail_if( m == NULL );
|
||||||
// r3_tree_dump( m, 0 );
|
// r3_tree_dump( m, 0 );
|
||||||
ck_assert_int_eq( *((int*) m->route_ptr), 999 );
|
ck_assert_int_eq( *((int*) m->data), 999 );
|
||||||
|
|
||||||
|
|
||||||
printf("Benchmarking...\n");
|
printf("Benchmarking...\n");
|
||||||
|
|
Loading…
Reference in a new issue