urecord.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. /*! \file
  23. * \brief USRLOC - Usrloc record structure
  24. * \ingroup usrloc
  25. */
  26. #ifndef URECORD_H
  27. #define URECORD_H
  28. #include <stdio.h>
  29. #include <time.h>
  30. #include "hslot.h"
  31. #include "../../str.h"
  32. #include "../../qvalue.h"
  33. #include "ucontact.h"
  34. #include "usrloc.h"
  35. struct hslot; /*!< Hash table slot */
  36. /*!
  37. * \brief Create and initialize new record structure
  38. * \param _dom domain name
  39. * \param _aor address of record
  40. * \param _r pointer to the new record
  41. * \return 0 on success, negative on failure
  42. */
  43. int new_urecord(str* _dom, str* _aor, urecord_t** _r);
  44. /*!
  45. * \brief Free all memory used by the given structure
  46. *
  47. * Free all memory used by the given structure.
  48. * The structure must be removed from all linked
  49. * lists first
  50. * \param _r freed record list
  51. */
  52. void free_urecord(urecord_t* _r);
  53. /*!
  54. * \brief Print a record, useful for debugging
  55. * \param _f print output
  56. * \param _r printed record
  57. */
  58. void print_urecord(FILE* _f, urecord_t* _r);
  59. /*!
  60. * \brief Add a new contact in memory
  61. *
  62. * Add a new contact in memory, contacts are ordered by:
  63. * 1) q value, 2) descending modification time
  64. * \param _r record this contact belongs to
  65. * \param _c contact
  66. * \param _ci contact information
  67. * \return pointer to new created contact on success, 0 on failure
  68. */
  69. ucontact_t* mem_insert_ucontact(urecord_t* _r, str* _c, ucontact_info_t* _ci);
  70. /*!
  71. * \brief Remove the contact from lists in memory
  72. * \param _r record this contact belongs to
  73. * \param _c removed contact
  74. */
  75. void mem_remove_ucontact(urecord_t* _r, ucontact_t* _c);
  76. /*!
  77. * \brief Remove contact in memory from the list and delete it
  78. * \param _r record this contact belongs to
  79. * \param _c deleted contact
  80. */
  81. void mem_delete_ucontact(urecord_t* _r, ucontact_t* _c);
  82. /*!
  83. * \brief Run timer functions depending on the db_mode setting.
  84. *
  85. * Helper function that run the appropriate timer function, depending
  86. * on the db_mode setting.
  87. * \param _r processed record
  88. */
  89. void timer_urecord(urecord_t* _r);
  90. /*!
  91. * \brief Delete a record from the database
  92. * \param _r deleted record
  93. * \return 0 on success, -1 on failure
  94. */
  95. int db_delete_urecord(urecord_t* _r);
  96. /*!
  97. * \brief Delete a record from the database based on ruid
  98. * \param _d pointer to domain from which record is deleted
  99. * \param _ruid pointer to ruid of the record which is deleted
  100. * \return 0 on success, -1 on failure, and -2 if record was
  101. * not found
  102. */
  103. int delete_urecord_by_ruid(udomain_t* _d, str *_ruid);
  104. /* ===== Module interface ======== */
  105. /*!
  106. * \brief Release urecord previously obtained through get_urecord
  107. * \warning Failing to calls this function after get_urecord will
  108. * result in a memory leak when the DB_ONLY mode is used. When
  109. * the records is later deleted, e.g. with delete_urecord, then
  110. * its not necessary, as this function already releases the record.
  111. * \param _r released record
  112. */
  113. void release_urecord(urecord_t* _r);
  114. /*!
  115. * \brief Create and insert new contact into urecord
  116. * \param _r record into the new contact should be inserted
  117. * \param _contact contact string
  118. * \param _ci contact information
  119. * \param _c new created contact
  120. * \return 0 on success, -1 on failure
  121. */
  122. int insert_ucontact(urecord_t* _r, str* _contact,
  123. ucontact_info_t* _ci, ucontact_t** _c);
  124. /*!
  125. * \brief Delete ucontact from urecord
  126. * \param _r record where the contact belongs to
  127. * \param _c deleted contact
  128. * \return 0 on success, -1 on failure
  129. */
  130. int delete_ucontact(urecord_t* _r, struct ucontact* _c);
  131. /*!
  132. * \brief Get pointer to ucontact with given contact
  133. * \param _r record where to search the contacts
  134. * \param _c contact string
  135. * \param _callid callid
  136. * \param _path path
  137. * \param _cseq CSEQ number
  138. * \param _co found contact
  139. * \return 0 - found, 1 - not found, -1 - invalid found,
  140. * -2 - found, but to be skipped (same cseq)
  141. */
  142. int get_ucontact(urecord_t* _r, str* _c, str* _callid, str* _path,
  143. int _cseq,
  144. struct ucontact** _co);
  145. /*!
  146. * \brief Get pointer to ucontact with given contact
  147. * \param _r record where to search the contacts
  148. * \param _c contact string
  149. * \param _ci contact info (callid, cseq, instance, ...)
  150. * \param _co found contact
  151. * \return 0 - found, 1 - not found, -1 - invalid found,
  152. * -2 - found, but to be skipped (same cseq)
  153. */
  154. int get_ucontact_by_instance(urecord_t* _r, str* _c, ucontact_info_t* _ci,
  155. ucontact_t** _co);
  156. #endif