dlist.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  5. *
  6. * This file is part of Kamailio, a free SIP server.
  7. *
  8. * Kamailio is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * Kamailio is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * History:
  23. * ========
  24. * 2006-11-28 Added get_number_of_users() (Jeffrey Magder - SOMA Networks)
  25. * 2007-09-12 added partitioning support for fetching all ul contacts
  26. * (bogdan)
  27. */
  28. /*! \file
  29. * \brief USRLOC - List of registered domains
  30. * \ingroup usrloc
  31. */
  32. #ifndef DLIST_H
  33. #define DLIST_H
  34. #include <stdio.h>
  35. #include "../../str.h"
  36. #include "usrloc.h"
  37. #include "udomain.h"
  38. /*!
  39. * List of all domains registered with usrloc
  40. */
  41. typedef struct dlist {
  42. str name; /*!< Name of the domain (null terminated) */
  43. udomain_t* d; /*!< Payload */
  44. struct dlist* next; /*!< Next element in the list */
  45. } dlist_t;
  46. /*! \brief Global list of all registered domains */
  47. extern dlist_t* root;
  48. /*!
  49. * \brief Registers a new domain with usrloc
  50. *
  51. * Registers a new domain with usrloc. If the domain exists,
  52. * a pointer to existing structure will be returned, otherwise
  53. * a new domain will be created
  54. * \param _n domain name
  55. * \param _d new created domain
  56. * \return 0 on success, -1 on failure
  57. */
  58. int register_udomain(const char* _n, udomain_t** _d);
  59. /*!
  60. * \brief Free all allocated memory for domains
  61. */
  62. void free_all_udomains(void);
  63. /*!
  64. * \brief Print all domains, just for debugging
  65. * \param _f output file
  66. */
  67. void print_all_udomains(FILE* _f);
  68. /*!
  69. * \brief Run timer handler of all domains
  70. * \return 0 if all timer return 0, != 0 otherwise
  71. */
  72. int synchronize_all_udomains(int istart, int istep);
  73. /*!
  74. * \brief Get all contacts from the usrloc, in partitions if wanted
  75. *
  76. * Return list of all contacts for all currently registered
  77. * users in all domains. The caller must provide buffer of
  78. * sufficient length for fitting all those contacts. In the
  79. * case when buffer was exhausted, the function returns
  80. * estimated amount of additional space needed, in this
  81. * case the caller is expected to repeat the call using
  82. * this value as the hint.
  83. *
  84. * Information is packed into the buffer as follows:
  85. *
  86. * +------------+----------+-----+------+-----+
  87. * |contact1.len|contact1.s|sock1|flags1|path1|
  88. * +------------+----------+-----+------+-----+
  89. * |contact2.len|contact2.s|sock2|flags2|path1|
  90. * +------------+----------+-----+------+-----+
  91. * |..........................................|
  92. * +------------+----------+-----+------+-----+
  93. * |contactN.len|contactN.s|sockN|flagsN|pathN|
  94. * +------------+----------+-----+------+-----+
  95. * |000000000000|
  96. * +------------+
  97. *
  98. * \param buf target buffer
  99. * \param len length of buffer
  100. * \param flags contact flags
  101. * \param part_idx part index
  102. * \param part_max maximal part
  103. * \return 0 on success, positive if buffer size was not sufficient, negative on failure
  104. */
  105. int get_all_ucontacts(void *buf, int len, unsigned int flags,
  106. unsigned int part_idx, unsigned int part_max);
  107. /*!
  108. * \brief Find and return usrloc domain
  109. *
  110. * \param _n domain name
  111. * \param _d usrloc domain (location table)
  112. * \return 0 on success, -1 on failure
  113. */
  114. int get_udomain(const char* _n, udomain_t** _d);
  115. /*!
  116. * \brief Loops through all domains summing up the number of users
  117. * \return the number of users, could be zero
  118. */
  119. unsigned long get_number_of_users(void);
  120. /*!
  121. * \brief Find a particular domain, small wrapper around find_dlist
  122. * \param _d domain name
  123. * \param _p pointer to domain if found
  124. * \return 1 if domain was found, 0 otherwise
  125. */
  126. int find_domain(str* _d, udomain_t** _p);
  127. #endif