klist.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* vccd/include/klist.h
  2. *
  3. * This file is part of vccd.
  4. *
  5. * vccd is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * vccd is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with vccd. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #ifndef __KLIST_H
  19. #define __KLIST_H
  20. #include <vcc/vcc.h>
  21. /* before, i think using a 'container_of' in things we did in kernel
  22. * is silly, but now i realize that, i'm the stupid one, there are
  23. * too many things in the structure. */
  24. #define STAT_UNLOGGED 0
  25. #define STAT_LOGGED 1
  26. #define check_logged(n) \
  27. if (find_connection(n)->stat != STAT_LOGGED) { \
  28. vcc_log("%d requested before logging in. \n", fd); \
  29. vcc_info("WUNLOG %d\n", fd); \
  30. return 1; \
  31. }
  32. struct klist_node {
  33. long value;
  34. int stat;
  35. union {
  36. void *data;
  37. int nusers;
  38. };
  39. union {
  40. char *usrname;
  41. struct klist_node *connection;
  42. };
  43. union {
  44. struct klist_node *sending;
  45. struct klist_node *session;
  46. };
  47. struct klist_node *next, *prev;
  48. };
  49. struct klist_node *klist_find_value(struct klist_node *head, int value);
  50. void klist_init(struct klist_node *head);
  51. void klist_add(struct klist_node *head, struct klist_node *new);
  52. void klist_del(struct klist_node *head, struct klist_node *will_del);
  53. #define klist_empty(list) ((list)->next == (list))
  54. #define KLIST_NODE_INIT(__x) { \
  55. .value = 0, \
  56. .data = NULL, \
  57. .sending = NULL, \
  58. .usrname = NULL, \
  59. .next = __x, \
  60. .prev = __x, \
  61. }
  62. #endif