4
0

schan.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (C) 2000,2001 Florian Sander
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. //static struct stats_chanset *schans = NULL;
  19. /*schanset.root = NULL;
  20. schanset.compare = schan_compare;
  21. schanset.expmem = schan_expmem;
  22. schanset.free = schan_free;*/
  23. static int schan_compare(void *data, void *key)
  24. {
  25. if (!rfc_casecmp(((struct stats_chan *)data)->chan, (char *)key))
  26. return 1;
  27. else
  28. return 0;
  29. }
  30. static int schan_expmem(void *data)
  31. {
  32. int size = 0;
  33. size += sizeof(struct stats_chan);
  34. size += strlen(((struct stats_chan *) data)->chan) + 1;
  35. size += llist_expmem(&(((struct stats_chan *)data)->members));
  36. return 0;
  37. }
  38. static void schan_free(void *data)
  39. {
  40. struct stats_chan *p = (struct stats_chan *) data;
  41. llist_free(&(p->members));
  42. nfree(p->chan);
  43. nfree(p);
  44. }
  45. static struct stats_chan *schan_find(char *name)
  46. {
  47. return (struct stats_chan *) llist_find(&schanset, (void *) name);
  48. }
  49. static struct stats_chan *schan_create(char *name)
  50. {
  51. struct stats_chan *ch;
  52. ch = nmalloc(sizeof(struct stats_chan));
  53. ch->chan = nmalloc(strlen(name) + 1);
  54. strcpy(ch->chan, name);
  55. schan_members_llist_init(&ch->members);
  56. ch->stats = findglobstats(name);
  57. if (!ch->stats)
  58. ch->stats = globstats_create(name);
  59. return ch;
  60. }
  61. static struct stats_chan *schan_add(char *name)
  62. {
  63. struct stats_chan *ch;
  64. ch = schan_find(name);
  65. if (ch)
  66. return ch;
  67. ch = schan_create(name);
  68. llist_append(&schanset, (void *) ch);
  69. return ch;
  70. }
  71. static void schan_remove(char *name)
  72. {
  73. llist_delete(&schanset, (void *) name);
  74. }
  75. static struct stats_chan *schan_getfirst()
  76. {
  77. return (struct stats_chan *)llist_getfirst(&schanset);
  78. }
  79. static struct stats_chan *schan_getnext()
  80. {
  81. return (struct stats_chan *)llist_getnext(&schanset);
  82. }
  83. static void schan_join(struct stats_chan *chan, char *nick, char *uhost,
  84. char *user)
  85. {
  86. Assert(chan);
  87. schan_members_join(&chan->members, nick, uhost, user, chan->chan);
  88. }
  89. static void schan_leave(struct stats_chan *chan, char *nick)
  90. {
  91. Assert(chan);
  92. schan_members_leave(&chan->members, nick);
  93. }