urecord.h 4.8 KB

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