usrloc.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 - module API exports interface
  24. * \ingroup usrloc
  25. */
  26. #ifndef USRLOC_H
  27. #define USRLOC_H
  28. #include <time.h>
  29. #include "ul_callback.h"
  30. #include "../../qvalue.h"
  31. #include "../../str.h"
  32. #ifdef WITH_XAVP
  33. #include "../../xavp.h"
  34. #endif
  35. #define NO_DB 0
  36. #define WRITE_THROUGH 1
  37. #define WRITE_BACK 2
  38. #define DB_ONLY 3
  39. #define DB_READONLY 4
  40. /*forward declaration necessary for udomain*/
  41. struct udomain;
  42. typedef struct udomain udomain_t;
  43. /*!
  44. * \brief States for in-memory contacts in regards to contact storage handler (db, in-memory, ldap etc)
  45. */
  46. typedef enum cstate {
  47. CS_NEW, /*!< New contact - not flushed yet */
  48. CS_SYNC, /*!< Synchronized contact with the database */
  49. CS_DIRTY /*!< Update contact - not flushed yet */
  50. } cstate_t;
  51. /*! \brief Flags that can be associated with a Contact */
  52. typedef enum flags {
  53. FL_NONE = 0, /*!< No flags set */
  54. FL_MEM = 1 << 0, /*!< Update memory only */
  55. FL_ALL = (int)0xFFFFFFFF /*!< All flags set */
  56. } flags_t;
  57. /*! \brief Valid contact is a contact that either didn't expire yet or is permanent */
  58. #define VALID_CONTACT(c, t) ((c->expires>t) || (c->expires==0))
  59. struct hslot; /*!< Hash table slot */
  60. struct socket_info;
  61. /*! \brief Main structure for handling of registered Contact data */
  62. typedef struct ucontact {
  63. str* domain; /*!< Pointer to domain name (NULL terminated) */
  64. str ruid; /*!< Pointer to record internal unique id */
  65. str* aor; /*!< Pointer to the AOR string in record structure*/
  66. str c; /*!< Contact address */
  67. str received; /*!< IP+port+protocol we received the REGISTER from */
  68. str path; /*!< Path header */
  69. time_t expires; /*!< Expires parameter */
  70. qvalue_t q; /*!< q parameter */
  71. str callid; /*!< Call-ID header field of registration */
  72. int cseq; /*!< CSeq value */
  73. cstate_t state; /*!< State of the contact (\ref cstate) */
  74. unsigned int flags; /*!< Various flags (NAT, ping type, etc) */
  75. unsigned int cflags; /*!< Custom contact flags (from script) */
  76. str user_agent; /*!< User-Agent header field */
  77. struct socket_info *sock; /*!< received socket */
  78. time_t last_modified; /*!< When the record was last modified */
  79. time_t last_keepalive; /*!< last keepalive timestamp */
  80. unsigned int methods; /*!< Supported methods */
  81. str instance; /*!< SIP instance value - gruu */
  82. unsigned int reg_id; /*!< reg-id parameters */
  83. int tcpconn_id; /* unique tcp connection id */
  84. #ifdef WITH_XAVP
  85. sr_xavp_t * xavp; /*!< per contact xavps */
  86. #endif
  87. struct ucontact* next; /*!< Next contact in the linked list */
  88. struct ucontact* prev; /*!< Previous contact in the linked list */
  89. } ucontact_t;
  90. /*! \brief Informations related to a contact */
  91. typedef struct ucontact_info {
  92. str ruid; /*!< Pointer to record internal unique id */
  93. str *c; /*!< Contact address */
  94. str received; /*!< Received interface */
  95. str* path; /*!< Path informations */
  96. time_t expires; /*!< Contact expires */
  97. qvalue_t q; /*!< Q-value */
  98. str* callid; /*!< call-ID */
  99. int cseq; /*!< CSEQ number */
  100. unsigned int flags; /*!< message flags */
  101. unsigned int cflags; /*!< contact flags */
  102. str *user_agent; /*!< user agent header */
  103. struct socket_info *sock; /*!< socket informations */
  104. unsigned int methods; /*!< supported methods */
  105. str instance; /*!< SIP instance value - gruu */
  106. unsigned int reg_id; /*!< reg-id parameters */
  107. int tcpconn_id;
  108. #ifdef WITH_XAVP
  109. sr_xavp_t * xavp; /*!< per contact xavps */
  110. #endif
  111. time_t last_modified; /*!< last modified */
  112. } ucontact_info_t;
  113. typedef struct udomain_head{
  114. str* name;
  115. } udomain_head_t;
  116. /*! \brief
  117. * Basic hash table element
  118. */
  119. typedef struct urecord {
  120. str* domain; /*!< Pointer to domain we belong to
  121. * ( null terminated string) */
  122. str aor; /*!< Address of record */
  123. unsigned int aorhash; /*!< Hash over address of record */
  124. ucontact_t* contacts; /*!< One or more contact fields */
  125. struct hslot* slot; /*!< Collision slot in the hash table
  126. * array we belong to */
  127. struct urecord* prev; /*!< Next item in the hash entry */
  128. struct urecord* next; /*!< Previous item in the hash entry */
  129. } urecord_t;
  130. typedef int (*insert_urecord_t)(struct udomain* _d, str* _aor, struct urecord** _r);
  131. typedef int (*get_urecord_t)(struct udomain* _d, str* _aor, struct urecord** _r);
  132. typedef int (*get_urecord_by_ruid_t)(udomain_t* _d, unsigned int _aorhash,
  133. str *_ruid, struct urecord** _r, struct ucontact** _c);
  134. typedef int (*delete_urecord_t)(struct udomain* _d, str* _aor, struct urecord* _r);
  135. typedef int (*delete_urecord_by_ruid_t)(struct udomain* _d, str* _ruid);
  136. typedef int (*update_ucontact_t)(struct urecord* _r, struct ucontact* _c,
  137. struct ucontact_info* _ci);
  138. typedef void (*release_urecord_t)(struct urecord* _r);
  139. typedef int (*insert_ucontact_t)(struct urecord* _r, str* _contact,
  140. struct ucontact_info* _ci, struct ucontact** _c);
  141. typedef int (*delete_ucontact_t)(struct urecord* _r, struct ucontact* _c);
  142. typedef int (*get_ucontact_t)(struct urecord* _r, str* _c, str* _callid,
  143. str* _path, int _cseq,
  144. struct ucontact** _co);
  145. typedef int (*get_ucontact_by_instance_t)(struct urecord* _r, str* _c,
  146. ucontact_info_t* _ci, ucontact_t** _co);
  147. typedef void (*lock_udomain_t)(struct udomain* _d, str *_aor);
  148. typedef void (*unlock_udomain_t)(struct udomain* _d, str *_aor);
  149. typedef int (*register_udomain_t)(const char* _n, struct udomain** _d);
  150. typedef int (*get_all_ucontacts_t) (void* buf, int len, unsigned int flags,
  151. unsigned int part_idx, unsigned int part_max);
  152. typedef int (*get_udomain_t)(const char* _n, udomain_t** _d);
  153. typedef unsigned int (*ul_get_aorhash_t)(str *_aor);
  154. unsigned int ul_get_aorhash(str *_aor);
  155. typedef int (*ul_set_keepalive_timeout_t)(int _to);
  156. int ul_set_keepalive_timeout(int _to);
  157. typedef int (*ul_refresh_keepalive_t)(unsigned int _aorhash, str *_ruid);
  158. int ul_refresh_keepalive(unsigned int _aorhash, str *_ruid);
  159. /*! usrloc API export structure */
  160. typedef struct usrloc_api {
  161. int use_domain; /*! use_domain module parameter */
  162. int db_mode; /*! db_mode module parameter */
  163. unsigned int nat_flag; /*! nat_flag module parameter */
  164. register_udomain_t register_udomain;
  165. get_udomain_t get_udomain;
  166. get_all_ucontacts_t get_all_ucontacts;
  167. insert_urecord_t insert_urecord;
  168. delete_urecord_t delete_urecord;
  169. delete_urecord_by_ruid_t delete_urecord_by_ruid;
  170. get_urecord_t get_urecord;
  171. lock_udomain_t lock_udomain;
  172. unlock_udomain_t unlock_udomain;
  173. release_urecord_t release_urecord;
  174. insert_ucontact_t insert_ucontact;
  175. delete_ucontact_t delete_ucontact;
  176. get_ucontact_t get_ucontact;
  177. get_urecord_by_ruid_t get_urecord_by_ruid;
  178. get_ucontact_by_instance_t get_ucontact_by_instance;
  179. update_ucontact_t update_ucontact;
  180. register_ulcb_t register_ulcb;
  181. ul_get_aorhash_t get_aorhash;
  182. ul_set_keepalive_timeout_t set_keepalive_timeout;
  183. ul_refresh_keepalive_t refresh_keepalive;
  184. } usrloc_api_t;
  185. /*! usrloc API export bind function */
  186. typedef int (*bind_usrloc_t)(usrloc_api_t* api);
  187. #endif