Rename route_ptr => route

This commit is contained in:
c9s 2014-05-18 11:06:24 +08:00
parent 5ca345d570
commit 64acfd8cd6
4 changed files with 17 additions and 14 deletions

View file

@ -42,9 +42,9 @@ struct _node {
int * ov;
/**
* the pointer of route structure
* the pointer of route data
*/
void * route_ptr;
void * data;
int endpoint;
};
@ -60,8 +60,10 @@ typedef struct {
str_array * vars;
char * path; // current path to dispatch
int path_len; // the length of the current path
void * route_ptr; // route ptr
int request_method; // current request method
void * data; // route ptr
char * host; // the request host
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);
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);

View file

@ -219,7 +219,7 @@ match_entry * match_entry_createl(char * path, int path_len) {
entry->vars = str_array_create(3);
entry->path = path;
entry->path_len = path_len;
entry->route_ptr = NULL;
entry->data = NULL;
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;
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);
r3_tree_add_child(n, strndup(route, route_len) , child);
info("edge not found, insert one: %s\n", route);
child->route_ptr = route_ptr;
child->data = data;
child->endpoint++;
return child;
} 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
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 {
// no more,
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;
}
@ -451,7 +451,7 @@ node * r3_tree_insert_pathn(node *tree, char *route, int route_len, void * route
// move n->edges to c1
c2->endpoint++;
c2->route_ptr = route_ptr;
c2->data = data;
return c2;
} else {
printf("unexpected condition.");

View file

@ -88,3 +88,4 @@
1400374415,13164892.40
1400382244,12226293.04
1400382299,11775631.24
1400382382,12331702.88

1 1400242718 5649455.80
88 1400374415 13164892.40
89 1400382244 12226293.04
90 1400382299 11775631.24
91 1400382382 12331702.88

View file

@ -627,7 +627,7 @@ START_TEST(benchmark_str)
m = r3_tree_match(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL);
fail_if( m == NULL );
// 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");