udomain.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * $Id: udomain.h 5272 2008-11-27 12:32:26Z henningw $
  3. * Copyright (C) 2001-2003 FhG Fokus
  4. *
  5. * This file is part of Kamailio, a free SIP server.
  6. *
  7. * Kamailio is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version
  11. *
  12. * Kamailio is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /*
  22. * History:
  23. * --------
  24. * 2003-03-11 changed to new locking scheme: locking.h (andrei)
  25. */
  26. /*! \file
  27. * \brief USRLOC - Usrloc domain structure
  28. * \ingroup usrloc
  29. */
  30. #ifndef UDOMAIN_H
  31. #define UDOMAIN_H
  32. #include <stdio.h>
  33. #include "../../lib/kcore/statistics.h"
  34. #include "../../locking.h"
  35. #include "../../str.h"
  36. #include "../../lib/srdb1/db.h"
  37. #include "../usrloc/usrloc.h"
  38. #include "urecord.h"
  39. #include "hslot.h"
  40. struct hslot; /*!< Hash table slot */
  41. struct urecord; /*!< Usrloc record */
  42. /*! \brief
  43. * The structure represents a usrloc domain
  44. */
  45. struct udomain {
  46. str* name; /*!< Domain name (NULL terminated) */
  47. int size; /*!< Hash table size */
  48. struct hslot* table; /*!< Hash table - array of collision slots */
  49. /* statistics */
  50. stat_var *users; /*!< no of registered users */
  51. stat_var *contacts; /*!< no of registered contacts */
  52. stat_var *expires; /*!< no of expires */
  53. /* for ul_db_layer */
  54. int dbt; /* type of the database */
  55. db1_con_t * dbh; /* database handle */
  56. };
  57. /*!
  58. * \brief Create a new domain structure
  59. * \param _n is pointer to str representing name of the domain, the string is
  60. * not copied, it should point to str structure stored in domain list
  61. * \param _s is hash table size
  62. * \param _d new created domain
  63. * \return 0 on success, -1 on failure
  64. */
  65. int new_udomain(str* _n, int _s, udomain_t** _d);
  66. /*!
  67. * \brief Free all memory allocated for the domain
  68. * \param _d freed domain
  69. */
  70. void free_udomain(udomain_t* _d);
  71. /*!
  72. * \brief Print udomain, debugging helper function
  73. */
  74. void print_udomain(FILE* _f, udomain_t* _d);
  75. /*!
  76. * \brief Timer function to cleanup expired contacts, DB_ONLY db_mode
  77. * \param _d cleaned domain
  78. * \return 0 on success, -1 on failure
  79. */
  80. /*
  81. int db_timer_udomain(udomain_t* _d);
  82. */
  83. /*!
  84. * \brief Run timer handler for given domain
  85. * \param _d domain
  86. */
  87. void mem_timer_udomain(udomain_t* _d);
  88. /*!
  89. * \brief Insert a new record into domain in memory
  90. * \param _d domain the record belongs to
  91. * \param _aor address of record
  92. * \param _r new created record
  93. * \return 0 on success, -1 on failure
  94. */
  95. int mem_insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
  96. /*!
  97. * \brief Remove a record from domain in memory
  98. * \param _d domain the record belongs to
  99. * \param _r deleted record
  100. */
  101. void mem_delete_urecord(udomain_t* _d, struct urecord* _r);
  102. /*!
  103. * \brief Get lock for a slot
  104. * \param _d domain
  105. * \param i slot number
  106. */
  107. void lock_ulslot(udomain_t* _d, int i);
  108. /*!
  109. * \brief Release lock for a slot
  110. * \param _d domain
  111. * \param i slot number
  112. */
  113. void unlock_ulslot(udomain_t* _d, int i);
  114. /* ===== module interface ======= */
  115. /*! \brief
  116. * Timer handler for given domain
  117. */
  118. void lock_udomain(udomain_t* _d, str *_aor);
  119. /*!
  120. * \brief Release lock for a domain
  121. * \param _d domain
  122. * \param _aor address of record, uses as hash source for the lock slot
  123. */
  124. void unlock_udomain(udomain_t* _d, str *_aor);
  125. /*!
  126. * \brief Create and insert a new record
  127. * \param _d domain to insert the new record
  128. * \param _aor address of the record
  129. * \param _r new created record
  130. * \return return 0 on success, -1 on failure
  131. */
  132. int insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
  133. /*!
  134. * \brief Obtain a urecord pointer if the urecord exists in domain
  135. * \param _d domain to search the record
  136. * \param _aor address of record
  137. * \param _r new created record
  138. * \return 0 if a record was found, 1 if nothing could be found
  139. */
  140. int get_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
  141. /*!
  142. * \brief Obtain a urecord pointer if the urecord exists in domain (lock slot)
  143. * \param _d domain to search the record
  144. * \param _aorhash hash id for address of record
  145. * \param _ruid record internal unique id
  146. * \param _r store pointer to location record
  147. * \param _c store pointer to contact structure
  148. * \return 0 if a record was found, 1 if nothing could be found
  149. */
  150. int get_urecord_by_ruid(udomain_t* _d, unsigned int _aorhash,
  151. str *_ruid, struct urecord** _r, struct ucontact** _c);
  152. /*!
  153. * \brief Delete a urecord from domain
  154. * \param _d domain where the record should be deleted
  155. * \param _aor address of record
  156. * \param _r deleted record
  157. * \return 0 on success, -1 if the record could not be deleted
  158. */
  159. int delete_urecord(udomain_t* _d, str* _aor, struct urecord* _r);
  160. #endif