osip_list.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
  3. Copyright (C) 2001-2020 Aymeric MOIZARD amoizard@antisip.com
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. #ifndef _LIST_H_
  17. #define _LIST_H_
  18. #ifdef ENABLE_MPATROL
  19. #include <mpatrol.h>
  20. #endif
  21. /**
  22. * @file osip_list.h
  23. * @brief oSIP list Routines
  24. *
  25. * This is a simple implementation of a linked list.
  26. */
  27. /**
  28. * @defgroup oSIP_LIST oSIP list Handling
  29. * @{
  30. */
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. #ifndef DOXYGEN
  35. /**
  36. * Structure for referencing a node in a osip_list_t element.
  37. * @var __node_t
  38. */
  39. typedef struct __node __node_t;
  40. /**
  41. * Structure for referencing a node in a osip_list_t element.
  42. * @struct __node
  43. */
  44. struct __node {
  45. __node_t *next; /**< next __node_t containing element */
  46. void *element; /**< element in Current node */
  47. };
  48. #endif
  49. /**
  50. * Structure for referencing a list of elements.
  51. * @var osip_list_t
  52. */
  53. typedef struct osip_list osip_list_t;
  54. /**
  55. * Structure used to iterate list.
  56. * @var osip_list_iterator_t
  57. */
  58. typedef struct osip_list_iterator osip_list_iterator_t;
  59. /**
  60. * Structure used to iterate list.
  61. * @struct osip_list_iterator
  62. */
  63. struct osip_list_iterator {
  64. __node_t *actual; /**< actual */
  65. __node_t **prev; /**< prev */
  66. osip_list_t *li; /**< li */
  67. int pos; /**< pos */
  68. };
  69. /**
  70. * Structure for referencing a list of elements.
  71. * @struct osip_list
  72. */
  73. struct osip_list {
  74. int nb_elt; /**< Number of element in the list */
  75. __node_t *node; /**< Next node containing element */
  76. };
  77. /**
  78. * Initialise a osip_list_t element.
  79. * NOTE: this element MUST be previously allocated with
  80. * osip_malloc(). The osip_free() call on the list is
  81. * still automatically done by osip_list_free(). This
  82. * also means you can't use a static osip_list_t variable
  83. * if you want to use osip_list_free().
  84. * @param li The element to initialise.
  85. */
  86. int osip_list_init(osip_list_t *li);
  87. /**
  88. * Free a list of element.
  89. * Each element will be free with the method given as the second parameter.
  90. * @param li The element to work on.
  91. * @param free_func The method that is able to release one element of the list.
  92. */
  93. void osip_list_special_free(osip_list_t *li, void (*free_func)(void *));
  94. /**
  95. * Clone a list of element.
  96. * Each element will be cloned with the method given as the second parameter.
  97. * @param src The element to work on.
  98. * @param dst The element to work on.
  99. * @param clone_func The method that is able to release one element of the list.
  100. */
  101. int osip_list_clone(const osip_list_t *src, osip_list_t *dst, int (*clone_func)(void *, void **));
  102. /**
  103. * Free a list of element where elements are pointer to 'char'.
  104. * @param li The element to work on.
  105. */
  106. void osip_list_ofchar_free(osip_list_t *li);
  107. /**
  108. * Get the size of a list of element.
  109. * @param li The element to work on.
  110. */
  111. int osip_list_size(const osip_list_t *li);
  112. /**
  113. * Check if the end of list is detected .
  114. * @param li The element to work on.
  115. * @param pos The index of the possible element.
  116. */
  117. int osip_list_eol(const osip_list_t *li, int pos);
  118. /**
  119. * Add an element in a list.
  120. * @param li The element to work on.
  121. * @param element The pointer on the element to add.
  122. * @param pos the index of the element to add. (or -1 to append the element at the end)
  123. */
  124. int osip_list_add(osip_list_t *li, void *element, int pos);
  125. /**
  126. * Get an element from a list.
  127. * @param li The element to work on.
  128. * @param pos the index of the element to get.
  129. */
  130. void *osip_list_get(const osip_list_t *li, int pos);
  131. /**
  132. * Remove an element from a list.
  133. * @param li The element to work on.
  134. * @param pos the index of the element to remove.
  135. */
  136. int osip_list_remove(osip_list_t *li, int pos);
  137. /**
  138. * Check current iterator state.
  139. * @param it The element to work on.
  140. */
  141. #define osip_list_iterator_has_elem(it) (0 != (it).actual && (it).pos < (it).li->nb_elt)
  142. /**
  143. * Get first iterator from list.
  144. * @param li The element to work on.
  145. * @param it The iterator.
  146. */
  147. void *osip_list_get_first(const osip_list_t *li, osip_list_iterator_t *it);
  148. /**
  149. * GEt next iterator.
  150. * @param it The element to work on.
  151. */
  152. void *osip_list_get_next(osip_list_iterator_t *it);
  153. /**
  154. * Remove current iterator.
  155. * @param it The element to work on.
  156. */
  157. void *osip_list_iterator_remove(osip_list_iterator_t *it);
  158. #ifdef __cplusplus
  159. }
  160. #endif
  161. /** @} */
  162. #endif