comparison libnnchat.c @ 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 741e45592522
children b0b63d164702
comparison
equal deleted inserted replaced
163:cc1cc49d26f0 164:701c54a45466
651 651
652 return NULL; 652 return NULL;
653 } 653 }
654 654
655 655
656 static nn_user_t *nn_user_match_do(nn_user_t *list, const char *pattern, size_t len)
657 {
658 nn_user_t *curr = list;
659 while (curr != NULL) {
660 if (len <= strlen(curr->name) && strncasecmp(curr->name, pattern, len) == 0)
661 return curr;
662 curr = curr->next;
663 }
664 return NULL;
665 }
666
667
656 nn_user_t *nn_user_match(const nn_userhash_t *list, const char *pattern, const char *current, BOOL again) 668 nn_user_t *nn_user_match(const nn_userhash_t *list, const char *pattern, const char *current, BOOL again)
657 { 669 {
658 uint8_t hash; 670 uint8_t hash;
659 671
660 if (list == NULL || pattern == NULL) return NULL; 672 if (list == NULL || pattern == NULL) return NULL;
673 found = curr->next; 685 found = curr->next;
674 break; 686 break;
675 } 687 }
676 curr = curr->next; 688 curr = curr->next;
677 } 689 }
678 if (found != NULL) 690
679 curr = found; 691 if (found != NULL && (found = nn_user_match_do(found, pattern, len)) != NULL)
680 else 692 return found;
681 curr = list->buckets[hash];
682 } 693 }
683 694
684 695 if ((curr = nn_user_match_do(list->buckets[hash], pattern, len)) != NULL)
685 while (curr != NULL) { 696 return curr;
686 if (len <= strlen(curr->name) && strncasecmp(curr->name, pattern, len) == 0)
687 return curr;
688 curr = curr->next;
689 }
690 } 697 }
691 698
692 return NULL; 699 return NULL;
693 } 700 }
694 701