Mercurial > hg > nnchat
changeset 164:701c54a45466
Fix matching of usernames against hash. In some cases after the last match the function would not go back to the first match.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 04 Nov 2010 16:00:02 +0200 |
parents | cc1cc49d26f0 |
children | f2f0b6f9281b |
files | libnnchat.c |
diffstat | 1 files changed, 17 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/libnnchat.c Thu Nov 04 15:55:37 2010 +0200 +++ b/libnnchat.c Thu Nov 04 16:00:02 2010 +0200 @@ -653,6 +653,18 @@ } +static nn_user_t *nn_user_match_do(nn_user_t *list, const char *pattern, size_t len) +{ + nn_user_t *curr = list; + while (curr != NULL) { + if (len <= strlen(curr->name) && strncasecmp(curr->name, pattern, len) == 0) + return curr; + curr = curr->next; + } + return NULL; +} + + nn_user_t *nn_user_match(const nn_userhash_t *list, const char *pattern, const char *current, BOOL again) { uint8_t hash; @@ -675,18 +687,13 @@ } curr = curr->next; } - if (found != NULL) - curr = found; - else - curr = list->buckets[hash]; + + if (found != NULL && (found = nn_user_match_do(found, pattern, len)) != NULL) + return found; } - - while (curr != NULL) { - if (len <= strlen(curr->name) && strncasecmp(curr->name, pattern, len) == 0) - return curr; - curr = curr->next; - } + if ((curr = nn_user_match_do(list->buckets[hash], pattern, len)) != NULL) + return curr; } return NULL;