diff options
author | filipe <filipe@19e92222-5c0b-0410-8929-a290d50e31e9> | 2007-09-13 04:12:01 +0000 |
---|---|---|
committer | filipe <filipe@19e92222-5c0b-0410-8929-a290d50e31e9> | 2007-09-13 04:12:01 +0000 |
commit | 706aef01fbbcee885fcb6d76228f669d48d16f25 (patch) | |
tree | a42509c89301d451300a3bc64dd1f2ac388bff66 /ext/http11/tst_search.c | |
parent | 6bfa360e4a418cf6d3531334cea185be0878c0ed (diff) | |
download | unicorn-706aef01fbbcee885fcb6d76228f669d48d16f25.tar.gz |
and he also close the bug upstream :D So we are in sync with his source code and bug 10279 is closed with this commit. git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@586 19e92222-5c0b-0410-8929-a290d50e31e9
Diffstat (limited to 'ext/http11/tst_search.c')
-rw-r--r-- | ext/http11/tst_search.c | 115 |
1 files changed, 60 insertions, 55 deletions
diff --git a/ext/http11/tst_search.c b/ext/http11/tst_search.c index 44aee7a..176f953 100644 --- a/ext/http11/tst_search.c +++ b/ext/http11/tst_search.c @@ -4,65 +4,70 @@ #include <stdlib.h> #include <assert.h> -void *tst_search(unsigned char *key, struct tst *tst, int *prefix_len) + +void *tst_search(const unsigned char *key, struct tst *tst, int option, + unsigned int *match_len) { - struct node *current_node; - void *longest_match = NULL; - int key_index; - - assert(key != NULL && "key can't be NULL"); - assert(tst != NULL && "tst can't be NULL"); - - if(key[0] == 0) - return NULL; - - if(tst->head[(int)key[0]] == NULL) - return NULL; + struct node *current_node; + struct node *longest_match = NULL; + unsigned int longest_match_len = 0; + int key_index; + + assert(key != NULL && "key can't be NULL"); + assert(tst != NULL && "tst can't be NULL"); + + if (key[0] == 0) + return NULL; + + if (tst->head[(int) key[0]] == NULL) + return NULL; + + if (match_len) + *match_len = 0; + + current_node = tst->head[(int) key[0]]; + key_index = 1; - - if(prefix_len) *prefix_len = 0; - current_node = tst->head[(int)key[0]]; - key_index = 1; - - while (current_node != NULL) - { - if(key[key_index] == current_node->value) - { - if(current_node->value == 0) { - if(prefix_len) *prefix_len = key_index; - return current_node->middle; - } else { - current_node = current_node->middle; - if(current_node && current_node->value == 0) { - if(prefix_len) *prefix_len = key_index+1; - longest_match = current_node->middle; + while (current_node != NULL) { + if (key[key_index] == current_node->value) { + if (current_node->value == 0) { + if (match_len) + *match_len = key_index; + return current_node->middle; + } else { + current_node = current_node->middle; + key_index++; + continue; } + } else { + if (current_node->value == 0) { + if (option & TST_LONGEST_MATCH) { + longest_match = current_node->middle; + longest_match_len = key_index; + } - key_index++; - continue; - } - } - else if( ((current_node->value == 0) && (key[key_index] < 64)) || - ((current_node->value != 0) && (key[key_index] < - current_node->value)) ) - { - if(current_node->value == 0) { - if(prefix_len) *prefix_len = key_index; - longest_match = current_node->middle; - } - current_node = current_node->left; - continue; - } - else - { - if(current_node->value == 0) { - if(prefix_len) *prefix_len = key_index; - longest_match = current_node->middle; - } - current_node = current_node->right; - continue; + if (key[key_index] < 64) { + current_node = current_node->left; + continue; + } else { + current_node = current_node->right; + continue; + } + } else { + if (key[key_index] < current_node->value) { + current_node = current_node->left; + continue; + } else { + current_node = current_node->right; + continue; + } + } } } - - return longest_match; + + if (match_len) + *match_len = longest_match_len; + + return longest_match; + } |