copy data to condition endpoints
This commit is contained in:
parent
e6c7d3e45e
commit
518fad82f2
3 changed files with 18 additions and 8 deletions
10
include/r3.h
10
include/r3.h
|
@ -22,10 +22,10 @@
|
|||
|
||||
struct _edge;
|
||||
struct _node;
|
||||
struct _route;
|
||||
struct _condition;
|
||||
typedef struct _edge edge;
|
||||
typedef struct _node node;
|
||||
typedef struct _route condition;
|
||||
typedef struct _condition condition;
|
||||
|
||||
struct _node {
|
||||
edge ** edges;
|
||||
|
@ -77,7 +77,7 @@ typedef struct {
|
|||
int remote_addr_len;
|
||||
} match_entry;
|
||||
|
||||
struct _route {
|
||||
struct _condition {
|
||||
char * path;
|
||||
int path_len;
|
||||
|
||||
|
@ -86,6 +86,8 @@ struct _route {
|
|||
char * host; // required host name
|
||||
int host_len;
|
||||
|
||||
void * data;
|
||||
|
||||
char * remote_addr_pattern;
|
||||
int remote_addr_pattern_len;
|
||||
};
|
||||
|
@ -150,7 +152,7 @@ condition * condition_createl(char * path, int path_len);
|
|||
|
||||
int condition_cmp(condition *r1, condition *r2);
|
||||
|
||||
void r3_node_append_condition(node * n, condition * condition, void * data);
|
||||
void r3_node_append_condition(node * n, condition * condition);
|
||||
|
||||
void condition_free(condition * condition);
|
||||
|
||||
|
|
13
src/node.c
13
src/node.c
|
@ -352,6 +352,8 @@ condition * condition_createl(char * path, int path_len) {
|
|||
info->path_len = path_len;
|
||||
info->request_method = 0; // can be (GET || POST)
|
||||
|
||||
info->data = NULL;
|
||||
|
||||
info->host = NULL; // required host name
|
||||
info->host_len = 0;
|
||||
|
||||
|
@ -411,7 +413,8 @@ node * r3_tree_insert_pathl(node *tree, char *path, int path_len, condition * co
|
|||
child->endpoint++;
|
||||
|
||||
if (condition) {
|
||||
r3_node_append_condition(child, condition, data);
|
||||
condition->data = data;
|
||||
r3_node_append_condition(child, condition);
|
||||
}
|
||||
return child;
|
||||
} else if ( offset == e->pattern_len ) { // fully-equal to the pattern of the edge
|
||||
|
@ -427,7 +430,8 @@ node * r3_tree_insert_pathl(node *tree, char *path, int path_len, condition * co
|
|||
e->child->endpoint++; // make it as an endpoint
|
||||
e->child->data = data;
|
||||
if (condition) {
|
||||
r3_node_append_condition(e->child, condition, data);
|
||||
condition->data = data;
|
||||
r3_node_append_condition(e->child, condition);
|
||||
}
|
||||
return e->child;
|
||||
}
|
||||
|
@ -465,7 +469,8 @@ node * r3_tree_insert_pathl(node *tree, char *path, int path_len, condition * co
|
|||
c2->data = data;
|
||||
|
||||
if (condition) {
|
||||
r3_node_append_condition(c2, condition, data);
|
||||
condition->data = data;
|
||||
r3_node_append_condition(c2, condition);
|
||||
}
|
||||
return c2;
|
||||
} else {
|
||||
|
@ -566,7 +571,7 @@ int condition_cmp(condition *r1, condition *r2) {
|
|||
/**
|
||||
* Create a data only node.
|
||||
*/
|
||||
void r3_node_append_condition(node * n, condition * condition, void * data) {
|
||||
void r3_node_append_condition(node * n, condition * condition) {
|
||||
if (!n->conditions) {
|
||||
n->condition_cap = 3;
|
||||
n->conditions = malloc(sizeof(condition) * n->condition_cap);
|
||||
|
|
|
@ -125,3 +125,6 @@
|
|||
1400387318,10842286.92
|
||||
1400387384,10651069.93
|
||||
1400387532,11055554.04
|
||||
1400387761,10803251.35
|
||||
1400387926,10854580.56
|
||||
1400388003,11099634.54
|
||||
|
|
|
Loading…
Reference in a new issue