zrtp_list.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * libZRTP SDK library, implements the ZRTP secure VoIP protocol.
  3. * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
  4. * Contact: http://philzimmermann.com
  5. * For licensing and other legal details, see the file zrtp_legal.c.
  6. *
  7. * Viktor Krykun <v.krikun at zfoneproject.com>
  8. */
  9. #ifndef __ZRTP_LIST_H__
  10. #define __ZRTP_LIST_H__
  11. #include "zrtp_config.h"
  12. typedef struct mlist mlist_t;
  13. struct mlist
  14. {
  15. mlist_t *next;
  16. mlist_t *prev;
  17. };
  18. #if defined(__cplusplus)
  19. extern "C"
  20. {
  21. #endif
  22. /*
  23. * \warning
  24. * We cast pointer to integer. There is bad thing for 64 bit platforms but
  25. * calculated offset couldn't be bigger then 2x32 and it will be casted
  26. * to integer correctly.
  27. */
  28. #define mlist_list_offset(type, list_name) ((size_t)&(((type*)0)->list_name))
  29. #define mlist_get_struct(type, list_name, list_ptr) \
  30. ((type*)(((char*)(list_ptr)) - mlist_list_offset(type,list_name)))
  31. #define mlist_for_each(pos, head) \
  32. for (pos = (head)->next; pos != (head); pos = pos->next)
  33. #define mlist_for_each_safe(pos, n, head) \
  34. for (pos = (head)->next, n = pos->next; pos != (head); \
  35. pos = n, n = pos->next)
  36. void init_mlist(mlist_t* head);
  37. void mlist_add(mlist_t* head, mlist_t* node);
  38. void mlist_add_tail(mlist_t *head, mlist_t *node);
  39. void mlist_insert(mlist_t *prev, mlist_t *node);
  40. void mlist_del(mlist_t *node);
  41. void mlist_del_tail(mlist_t *node);
  42. mlist_t* mlist_get(mlist_t *head);
  43. mlist_t* mlist_get_tail(mlist_t *head);
  44. int mlist_isempty(mlist_t *head);
  45. #if defined(__cplusplus)
  46. }
  47. #endif
  48. #endif /*__ZRTP_LIST_H__ */