ucontact.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * $Id$
  3. *
  4. * Usrloc contact structure
  5. *
  6. * Copyright (C) 2001-2003 FhG Fokus
  7. *
  8. * This file is part of ser, a free SIP server.
  9. *
  10. * ser is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version
  14. *
  15. * For a license to use the ser software under conditions
  16. * other than those described here, or to purchase support for this
  17. * software, please contact iptel.org by e-mail at the following addresses:
  18. * [email protected]
  19. *
  20. * ser is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  28. *
  29. * History:
  30. * ---------
  31. * 2003-03-12 added replication mark and three zombie states (nils)
  32. * 2005-02-25 incoming socket is saved in ucontact record (bogdan)
  33. */
  34. #ifndef UCONTACT_H
  35. #define UCONTACT_H
  36. #include <stdio.h>
  37. #include <time.h>
  38. #include "../../qvalue.h"
  39. #include "../../str.h"
  40. #include "../../usr_avp.h"
  41. typedef enum cstate {
  42. CS_NEW, /* New contact - not flushed yet */
  43. CS_SYNC, /* Synchronized contact with the database */
  44. CS_DIRTY /* Update contact - not flushed yet */
  45. } cstate_t;
  46. /*
  47. * Flags that can be associated with a Contact
  48. */
  49. typedef enum flags {
  50. FL_NONE = 0, /* No flags set */
  51. FL_NAT = 1 << 0, /* Contact is behind NAT */
  52. FL_INVITE = 1 << 1, /* Contact supports INVITE and related methods */
  53. FL_N_INVITE = 1 << 2, /* Contact doesn't support INVITE and related methods */
  54. FL_MESSAGE = 1 << 3, /* Contact supports MESSAGE */
  55. FL_N_MESSAGE = 1 << 4, /* Contact doesn't support MESSAGE */
  56. FL_SUBSCRIBE = 1 << 5, /* Contact supports SUBSCRIBE and NOTIFY */
  57. FL_N_SUBSCRIBE = 1 << 6, /* Contact doesn't support SUBSCRIBE and NOTIFY */
  58. FL_PERMANENT = 1 << 7, /* Permanent contact (does not expire) */
  59. FL_MEM = 1 << 8, /* Update memory only -- used for REGISTER replication */
  60. FL_ALL = 0xFFFFFFFF /* All flags set */
  61. } flags_t;
  62. typedef struct ucontact {
  63. str* domain; /* Pointer to domain name */
  64. str* uid; /* UID of owner of contact*/
  65. str aor; /* Address of record */
  66. str c; /* Contact address */
  67. str received; /* IP, port, and protocol we received the REGISTER from */
  68. struct socket_info* sock; /* Socket to be used when sending SIP messages to this contact */
  69. time_t expires; /* expires parameter */
  70. qvalue_t q; /* q parameter */
  71. str callid; /* Call-ID header field */
  72. int cseq; /* CSeq value */
  73. cstate_t state; /* State of the contact */
  74. unsigned int flags; /* Various flags (NAT, supported methods etc) */
  75. str user_agent; /* User-Agent header field */
  76. str instance; /* sip.instance parameter */
  77. int server_id; /* ID of the server within a cluster responsible for the contact */
  78. struct ucontact* next; /* Next contact in the linked list */
  79. struct ucontact* prev; /* Previous contact in the linked list */
  80. avp_t *avps;
  81. } ucontact_t;
  82. /*
  83. * Valid contact is a contact that either didn't expire yet or is permanent
  84. */
  85. #define VALID_CONTACT(c, t) (((c->expires > t) || (c->flags & FL_PERMANENT)))
  86. /*
  87. * Create a new contact structure
  88. */
  89. int new_ucontact(str* _dom, str* _uid, str* aor, str* _contact, time_t _e, qvalue_t _q,
  90. str* _callid, int _cseq, unsigned int _flags, ucontact_t** _c,
  91. str* _ua, str* _recv, struct socket_info* sock, str* _inst, int sid);
  92. /*
  93. * Free all memory associated with given contact structure
  94. */
  95. void free_ucontact(ucontact_t* _c);
  96. /*
  97. * Print contact, for debugging purposes only
  98. */
  99. void print_ucontact(FILE* _f, ucontact_t* _c);
  100. /*
  101. * Update existing contact in memory with new values
  102. */
  103. int mem_update_ucontact(ucontact_t* _c, str* _u, str* aor, time_t _e, qvalue_t _q, str* _cid, int _cs,
  104. unsigned int _set, unsigned int _res, str* _ua, str* _recv,
  105. struct socket_info* sock, str* _inst);
  106. /* ===== State transition functions - for write back cache scheme ======== */
  107. /*
  108. * Update state of the contact if we
  109. * are using write-back scheme
  110. */
  111. void st_update_ucontact(ucontact_t* _c);
  112. /*
  113. * Update state of the contact if we
  114. * are using write-back scheme
  115. * Returns 1 if the contact should be
  116. * deleted from memory immediately,
  117. * 0 otherwise
  118. */
  119. int st_delete_ucontact(ucontact_t* _c);
  120. /*
  121. * Called when the timer is about to delete
  122. * an expired contact, this routine returns
  123. * 1 if the contact should be removed from
  124. * the database and 0 otherwise
  125. */
  126. int st_expired_ucontact(ucontact_t* _c);
  127. /*
  128. * Called when the timer is about flushing the contact,
  129. * updates contact state and returns 1 if the contact
  130. * should be inserted, 2 if updated and 0 otherwise
  131. */
  132. int st_flush_ucontact(ucontact_t* _c);
  133. /* ==== Database related functions ====== */
  134. /*
  135. * Insert contact into the database
  136. */
  137. int db_store_ucontact(ucontact_t* _c);
  138. /*
  139. * Delete contact from the database
  140. */
  141. int db_delete_ucontact(ucontact_t* _c);
  142. /* ====== Module interface ====== */
  143. /*
  144. * Update ucontact with new values without replication
  145. */
  146. typedef int (*update_ucontact_t)(ucontact_t* _c, str* _u, str* aor, time_t _e,
  147. qvalue_t _q, str* _cid, int _cs,
  148. unsigned int _set, unsigned int _reset,
  149. str* _ua, str* _recv,
  150. struct socket_info* sock, str* _inst,
  151. int sid);
  152. int update_ucontact(ucontact_t* _c, str* _u, str* aor, time_t _e, qvalue_t _q,
  153. str* _cid, int _cs, unsigned int _set,
  154. unsigned int _reset,
  155. str* _ua, str* _recv,
  156. struct socket_info* sock, str* _inst, int sid);
  157. #endif /* UCONTACT_H */