fix condition match for request method

This commit is contained in:
c9s 2014-05-18 12:49:58 +08:00
parent 518fad82f2
commit 641d1e53d8
4 changed files with 24 additions and 20 deletions

View file

@ -150,7 +150,7 @@ condition * condition_create(char * path);
condition * condition_createl(char * path, int path_len); condition * condition_createl(char * path, int path_len);
int condition_cmp(condition *r1, condition *r2); int condition_cmp(condition *r1, match_entry *r2);
void r3_node_append_condition(node * n, condition * condition); void r3_node_append_condition(node * n, condition * condition);

View file

@ -300,6 +300,14 @@ node * r3_tree_match(node * n, char * path, int path_len, match_entry * entry) {
return NULL; return NULL;
} }
condition * r3_node_match_condition(node *n, match_entry * entry) {
if (n->conditions && n->condition_len > 0) {
int i;
for (i = 0; i < n->condition_len ; i++ ) {
}
}
}
inline edge * r3_node_find_edge_str(node * n, char * str, int str_len) { inline edge * r3_node_find_edge_str(node * n, char * str, int str_len) {
int i = 0; int i = 0;
@ -526,25 +534,20 @@ void r3_tree_dump(node * n, int level) {
* *
* -1 == different condition * -1 == different condition
*/ */
int condition_cmp(condition *r1, condition *r2) { int condition_cmp(condition *r1, match_entry *r2) {
if ( r1 == r2 ) { if (r1->request_method != 0) {
return 0; if (0 == (r1->request_method & r2->request_method) ) {
} return -1;
}
if (r1->request_method != r2->request_method) {
return -1;
} }
int ret; int ret;
if ( r1->path && r2->path ) { if ( r1->path && r2->path ) {
ret = strcmp(r1->path, r2->path); ret = strcmp(r1->path, r2->path);
if (ret != 0) { if (ret != 0) {
return -1; return -1;
} }
} else if ((r1->path && !r2->path) || (!r1->path && r2->path )) {
return -1;
} }
if ( r1->host && r2->host ) { if ( r1->host && r2->host ) {
@ -552,17 +555,13 @@ int condition_cmp(condition *r1, condition *r2) {
if (ret != 0) { if (ret != 0) {
return -1; return -1;
} }
} else if ((r1->host && !r2->host) || (!r1->host && r2->host )) {
return -1;
} }
if (r1->remote_addr_pattern && r2->remote_addr_pattern ) { if (r1->remote_addr_pattern) {
ret = strcmp(r1->remote_addr_pattern, r2->remote_addr_pattern); ret = strcmp(r1->remote_addr_pattern, r2->remote_addr);
if (ret != 0) { if (ret != 0) {
return -1; return -1;
} }
} else if ((r1->remote_addr_pattern && !r2->remote_addr_pattern) || (!r1->remote_addr_pattern && r2->remote_addr_pattern )) {
return -1;
} }
return 0; return 0;
} }

View file

@ -128,3 +128,9 @@
1400387761,10803251.35 1400387761,10803251.35
1400387926,10854580.56 1400387926,10854580.56
1400388003,11099634.54 1400388003,11099634.54
1400388313,11132551.99
1400388338,11139229.93
1400388369,10898128.85
1400388529,10815527.23
1400388539,10930897.10
1400388591,10720695.10

1 1400242718 5649455.80
128 1400387761 10803251.35
129 1400387926 10854580.56
130 1400388003 11099634.54
131 1400388313 11132551.99
132 1400388338 11139229.93
133 1400388369 10898128.85
134 1400388529 10815527.23
135 1400388539 10930897.10
136 1400388591 10720695.10

View file

@ -225,7 +225,7 @@ END_TEST
START_TEST(test_route_cmp) START_TEST(test_route_cmp)
{ {
condition *r1 = condition_create("/blog/post"); condition *r1 = condition_create("/blog/post");
condition *r2 = condition_create("/blog/post"); match_entry * r2 = match_entry_create("/blog/post");
fail_if( condition_cmp(r1, r2) == -1, "should be the same"); fail_if( condition_cmp(r1, r2) == -1, "should be the same");
@ -239,7 +239,7 @@ START_TEST(test_route_cmp)
condition_free(r1); condition_free(r1);
condition_free(r2); match_entry_free(r2);
} }
END_TEST END_TEST
@ -253,7 +253,6 @@ START_TEST(test_insert_route)
condition *r2 = condition_create("/blog/post"); condition *r2 = condition_create("/blog/post");
r1->request_method = METHOD_GET; r1->request_method = METHOD_GET;
r2->request_method = METHOD_POST; r2->request_method = METHOD_POST;
fail_if( condition_cmp(r1, r2) == 0, "should be different");
match_entry * entry = match_entry_create("/blog/post"); match_entry * entry = match_entry_create("/blog/post");