Mercurial > hg > nnchat
comparison util.c @ 446:3396acd40147
Rename and remove some functions.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 26 May 2012 03:40:57 +0300 |
parents | a9b20b31cae1 |
children | aeb3171f9e28 |
comparison
equal
deleted
inserted
replaced
445:7e46f2f0ba34 | 446:3396acd40147 |
---|---|
433 node->next = *list; | 433 node->next = *list; |
434 *list = node; | 434 *list = node; |
435 } | 435 } |
436 | 436 |
437 | 437 |
438 static void nn_user_free(nn_user_t *user) | |
439 { | |
440 th_free(user->name); | |
441 th_free(user); | |
442 } | |
443 | |
444 | |
445 static void nn_user_free_list(nn_user_t *list) | |
446 { | |
447 nn_user_t *next, *curr = list; | |
448 | |
449 while (curr != NULL) | |
450 { | |
451 next = curr->next; | |
452 nn_user_free(curr); | |
453 curr = next; | |
454 } | |
455 } | |
456 | |
457 | |
438 nn_user_t *nn_userhash_foreach(const nn_userhash_t *list, int (*func)(const nn_user_t *)) | 458 nn_user_t *nn_userhash_foreach(const nn_userhash_t *list, int (*func)(const nn_user_t *)) |
439 { | 459 { |
440 int i; | 460 int i; |
441 | 461 |
442 if (list == NULL) return NULL; | 462 if (list == NULL) return NULL; |
455 | 475 |
456 return NULL; | 476 return NULL; |
457 } | 477 } |
458 | 478 |
459 | 479 |
460 nn_user_t *nn_user_find(const nn_userhash_t *list, const char *name) | 480 nn_user_t *nn_userhash_find(const nn_userhash_t *list, const char *name) |
461 { | 481 { |
462 uint8_t hash; | 482 uint8_t hash; |
463 | 483 |
464 if (list == NULL) return NULL; | 484 if (list == NULL) return NULL; |
465 | 485 |
477 | 497 |
478 return NULL; | 498 return NULL; |
479 } | 499 } |
480 | 500 |
481 | 501 |
482 static nn_user_t *nn_user_match_do(nn_user_t *list, const char *pattern, size_t len) | 502 static nn_user_t *nn_userhash_match_do(nn_user_t *list, const char *pattern, size_t len) |
483 { | 503 { |
484 nn_user_t *curr = list; | 504 nn_user_t *curr = list; |
485 | 505 |
486 while (curr != NULL) | 506 while (curr != NULL) |
487 { | 507 { |
491 } | 511 } |
492 return NULL; | 512 return NULL; |
493 } | 513 } |
494 | 514 |
495 | 515 |
496 nn_user_t *nn_user_match(const nn_userhash_t *list, const char *pattern, const char *current, BOOL again) | 516 nn_user_t *nn_userhash_match(const nn_userhash_t *list, const char *pattern, const char *current, BOOL again) |
497 { | 517 { |
498 uint8_t hash; | 518 uint8_t hash; |
499 | 519 |
500 if (list == NULL || pattern == NULL) return NULL; | 520 if (list == NULL || pattern == NULL) return NULL; |
501 | 521 |
518 break; | 538 break; |
519 } | 539 } |
520 curr = curr->next; | 540 curr = curr->next; |
521 } | 541 } |
522 | 542 |
523 if (found != NULL && (found = nn_user_match_do(found, pattern, len)) != NULL) | 543 if (found != NULL && (found = nn_userhash_match_do(found, pattern, len)) != NULL) |
524 return found; | 544 return found; |
525 } | 545 } |
526 | 546 |
527 if ((curr = nn_user_match_do(list->buckets[hash], pattern, len)) != NULL) | 547 if ((curr = nn_userhash_match_do(list->buckets[hash], pattern, len)) != NULL) |
528 return curr; | 548 return curr; |
529 } | 549 } |
530 | 550 |
531 return NULL; | 551 return NULL; |
532 } | 552 } |
546 // Check arguments | 566 // Check arguments |
547 if (list == NULL || name == NULL) | 567 if (list == NULL || name == NULL) |
548 return -1; | 568 return -1; |
549 | 569 |
550 // Check if username is already there | 570 // Check if username is already there |
551 if (nn_user_find(list, name) != NULL) | 571 if (nn_userhash_find(list, name) != NULL) |
552 return 1; | 572 return 1; |
553 | 573 |
554 // No, we'll add it | 574 // No, we'll add it |
555 if ((user = th_calloc(1, sizeof(nn_user_t))) == NULL) | 575 if ((user = th_calloc(1, sizeof(nn_user_t))) == NULL) |
556 return -3; | 576 return -3; |
604 | 624 |
605 return 1; | 625 return 1; |
606 } | 626 } |
607 | 627 |
608 | 628 |
609 nn_user_t *nn_user_copy(const nn_user_t *src) | |
610 { | |
611 nn_user_t *user; | |
612 | |
613 if (src == NULL) return NULL; | |
614 | |
615 if ((user = th_calloc(1, sizeof(nn_user_t))) == NULL) | |
616 return NULL; | |
617 | |
618 // Copy relevant data | |
619 user->name = th_strdup(src->name); | |
620 user->lastspoke = src->lastspoke; | |
621 user->joined = src->joined; | |
622 | |
623 return user; | |
624 } | |
625 | |
626 | |
627 void nn_user_free(nn_user_t *user) | |
628 { | |
629 th_free(user->name); | |
630 th_free(user); | |
631 } | |
632 | |
633 | |
634 void nn_user_free_list(nn_user_t *list) | |
635 { | |
636 nn_user_t *next, *curr = list; | |
637 | |
638 while (curr != NULL) | |
639 { | |
640 next = curr->next; | |
641 nn_user_free(curr); | |
642 curr = next; | |
643 } | |
644 } | |
645 | |
646 void nn_userhash_free(nn_userhash_t *hash) | 629 void nn_userhash_free(nn_userhash_t *hash) |
647 { | 630 { |
648 int i; | 631 int i; |
649 if (hash == NULL) | 632 if (hash == NULL) |
650 return; | 633 return; |