udomain.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * $Id$
  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 "urecord.h"
  38. #include "hslot.h"
  39. #include "usrloc.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. };
  54. /*!
  55. * \brief Create a new domain structure
  56. * \param _n is pointer to str representing name of the domain, the string is
  57. * not copied, it should point to str structure stored in domain list
  58. * \param _s is hash table size
  59. * \param _d new created domain
  60. * \return 0 on success, -1 on failure
  61. */
  62. int new_udomain(str* _n, int _s, udomain_t** _d);
  63. /*!
  64. * \brief Free all memory allocated for the domain
  65. * \param _d freed domain
  66. */
  67. void free_udomain(udomain_t* _d);
  68. /*!
  69. * \brief Print udomain, debugging helper function
  70. */
  71. void print_udomain(FILE* _f, udomain_t* _d);
  72. /*!
  73. * \brief Load all records from a udomain
  74. *
  75. * Load all records from a udomain, useful to populate the
  76. * memory cache on startup.
  77. * \param _c database connection
  78. * \param _d loaded domain
  79. * \return 0 on success, -1 on failure
  80. */
  81. int preload_udomain(db1_con_t* _c, udomain_t* _d);
  82. /*!
  83. * \brief performs a dummy query just to see if DB is ok
  84. * \param con database connection
  85. * \param d domain
  86. */
  87. int testdb_udomain(db1_con_t* con, udomain_t* d);
  88. /*!
  89. * \brief Timer function to cleanup expired contacts, DB_ONLY db_mode
  90. * \param _d cleaned domain
  91. * \return 0 on success, -1 on failure
  92. */
  93. int db_timer_udomain(udomain_t* _d);
  94. /*!
  95. * \brief Run timer handler for given domain
  96. * \param _d domain
  97. * \param istart index of hash table slot to start processing
  98. * \param istep step through hash table slots to process
  99. */
  100. void mem_timer_udomain(udomain_t* _d, int istart, int istep);
  101. /*!
  102. * \brief Insert a new record into domain in memory
  103. * \param _d domain the record belongs to
  104. * \param _aor address of record
  105. * \param _r new created record
  106. * \return 0 on success, -1 on failure
  107. */
  108. int mem_insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
  109. /*!
  110. * \brief Remove a record from domain in memory
  111. * \param _d domain the record belongs to
  112. * \param _r deleted record
  113. */
  114. void mem_delete_urecord(udomain_t* _d, struct urecord* _r);
  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 Get lock for a slot
  127. * \param _d domain
  128. * \param i slot number
  129. */
  130. void lock_ulslot(udomain_t* _d, int i);
  131. /*!
  132. * \brief Release lock for a slot
  133. * \param _d domain
  134. * \param i slot number
  135. */
  136. void unlock_ulslot(udomain_t* _d, int i);
  137. /* ===== module interface ======= */
  138. /*!
  139. * \brief Create and insert a new record
  140. * \param _d domain to insert the new record
  141. * \param _aor address of the record
  142. * \param _r new created record
  143. * \return return 0 on success, -1 on failure
  144. */
  145. int insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
  146. /*!
  147. * \brief Obtain a urecord pointer if the urecord exists in domain
  148. * \param _d domain to search the record
  149. * \param _aor address of record
  150. * \param _r new created record
  151. * \return 0 if a record was found, 1 if nothing could be found
  152. */
  153. int get_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
  154. /*!
  155. * \brief Obtain a urecord pointer if the urecord exists in domain (lock slot)
  156. * \param _d domain to search the record
  157. * \param _aorhash hash id for address of record
  158. * \param _ruid record internal unique id
  159. * \param _r store pointer to location record
  160. * \param _c store pointer to contact structure
  161. * \return 0 if a record was found, 1 if nothing could be found
  162. */
  163. int get_urecord_by_ruid(udomain_t* _d, unsigned int _aorhash,
  164. str *_ruid, struct urecord** _r, struct ucontact** _c);
  165. /*!
  166. * \brief Delete a urecord from domain
  167. * \param _d domain where the record should be deleted
  168. * \param _aor address of record
  169. * \param _r deleted record
  170. * \return 0 on success, -1 if the record could not be deleted
  171. */
  172. int delete_urecord(udomain_t* _d, str* _aor, struct urecord* _r);
  173. /* ===== per-contact attributes ======= */
  174. /*!
  175. * \brief Load all location attributes from an udomain
  176. *
  177. * Load all location attributes from a udomain, useful to populate the
  178. * memory cache on startup.
  179. * \param _d loaded domain
  180. * \return 0 on success, -1 on failure
  181. */
  182. int uldb_preload_attrs(udomain_t *_d);
  183. #endif