udefchan.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * udefchan.c -- part of channels.mod
  3. * user definable channel flags/settings
  4. *
  5. */
  6. static int getudef(struct udef_chans *ul, char *name)
  7. {
  8. int val = 0;
  9. for (; ul; ul = ul->next)
  10. if (!egg_strcasecmp(ul->chan, name)) {
  11. val = ul->value;
  12. break;
  13. }
  14. return val;
  15. }
  16. static int ngetudef(char *name, char *chan)
  17. {
  18. struct udef_struct *l;
  19. struct udef_chans *ll;
  20. for (l = udef; l; l = l->next)
  21. if (!egg_strcasecmp(l->name, name)) {
  22. for (ll = l->values; ll; ll = ll->next)
  23. if (!egg_strcasecmp(ll->chan, chan))
  24. return ll->value;
  25. break;
  26. }
  27. return 0;
  28. }
  29. static void setudef(struct udef_struct *us, char *name, int value)
  30. {
  31. struct udef_chans *ul, *ul_last = NULL;
  32. for (ul = us->values; ul; ul_last = ul, ul = ul->next)
  33. if (!egg_strcasecmp(ul->chan, name)) {
  34. ul->value = value;
  35. return;
  36. }
  37. ul = nmalloc(sizeof(struct udef_chans));
  38. ul->chan = nmalloc(strlen(name) + 1);
  39. strcpy(ul->chan, name);
  40. ul->value = value;
  41. ul->next = NULL;
  42. if (ul_last)
  43. ul_last->next = ul;
  44. else
  45. us->values = ul;
  46. }
  47. static void initudef(int type, char *name, int defined)
  48. {
  49. struct udef_struct *ul, *ul_last = NULL;
  50. if (strlen(name) < 1)
  51. return;
  52. for (ul = udef; ul; ul_last = ul, ul = ul->next)
  53. if (ul->name && !egg_strcasecmp(ul->name, name)) {
  54. if (defined) {
  55. debug1("UDEF: %s defined", ul->name);
  56. ul->defined = 1;
  57. }
  58. return;
  59. }
  60. debug2("Creating %s (type %d)", name, type);
  61. ul = nmalloc(sizeof(struct udef_struct));
  62. ul->name = nmalloc(strlen(name) + 1);
  63. strcpy(ul->name, name);
  64. if (defined)
  65. ul->defined = 1;
  66. else
  67. ul->defined = 0;
  68. ul->type = type;
  69. ul->values = NULL;
  70. ul->next = NULL;
  71. if (ul_last)
  72. ul_last->next = ul;
  73. else
  74. udef = ul;
  75. }
  76. static void free_udef_chans(struct udef_chans *ul)
  77. {
  78. struct udef_chans *ull;
  79. for (; ul; ul = ull) {
  80. ull = ul->next;
  81. nfree(ul->chan);
  82. nfree(ul);
  83. }
  84. }