sip_timer.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. * Copyright (C) 2009-2011 Teluu Inc. (http://www.teluu.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #ifndef __PJSIP_TIMER_H__
  19. #define __PJSIP_TIMER_H__
  20. /**
  21. * @file sip_timer.h
  22. * @brief SIP Session Timers support (RFC 4028 - Session Timer in SIP)
  23. */
  24. #include <pjsip-ua/sip_inv.h>
  25. #include <pjsip/sip_msg.h>
  26. /**
  27. * @defgroup PJSIP_TIMER SIP Session Timers support (RFC 4028 - Session Timers in SIP)
  28. * @ingroup PJSIP_HIGH_UA
  29. * @brief SIP Session Timers support (RFC 4028 - Session Timers in SIP)
  30. * @{
  31. *
  32. * \section PJSIP_TIMER_REFERENCE References
  33. *
  34. * References:
  35. * - <A HREF="http://www.ietf.org/rfc/rfc4028.txt">RFC 4028: Session Timers
  36. * in the Session Initiation Protocol (SIP)</A>
  37. */
  38. PJ_BEGIN_DECL
  39. /**
  40. * Opaque declaration of Session Timers.
  41. */
  42. typedef struct pjsip_timer pjsip_timer;
  43. /**
  44. * This structure describes Session Timers settings in an invite session.
  45. */
  46. typedef struct pjsip_timer_setting
  47. {
  48. /**
  49. * Specify minimum session expiration period, in seconds. Must not be
  50. * lower than 90. Default is 90.
  51. */
  52. unsigned min_se;
  53. /**
  54. * Specify session expiration period, in seconds. Must not be lower than
  55. * #min_se. Default is 1800.
  56. */
  57. unsigned sess_expires;
  58. } pjsip_timer_setting;
  59. /**
  60. * SIP Session-Expires header (RFC 4028).
  61. */
  62. typedef struct pjsip_sess_expires_hdr
  63. {
  64. /** Standard header field. */
  65. PJSIP_DECL_HDR_MEMBER(struct pjsip_sess_expires_hdr);
  66. /** Session expiration period */
  67. unsigned sess_expires;
  68. /** Refresher */
  69. pj_str_t refresher;
  70. /** Other parameters */
  71. pjsip_param other_param;
  72. } pjsip_sess_expires_hdr;
  73. /**
  74. * SIP Min-SE header (RFC 4028).
  75. */
  76. typedef struct pjsip_min_se_hdr
  77. {
  78. /** Standard header field. */
  79. PJSIP_DECL_HDR_MEMBER(struct pjsip_min_se_hdr);
  80. /** Minimum session expiration period */
  81. unsigned min_se;
  82. /** Other parameters */
  83. pjsip_param other_param;
  84. } pjsip_min_se_hdr;
  85. /**
  86. * Initialize Session Timers module. This function must be called once during
  87. * application initialization, to register this module to SIP endpoint.
  88. *
  89. * @param endpt The SIP endpoint instance.
  90. *
  91. * @return PJ_SUCCESS if module is successfully initialized.
  92. */
  93. PJ_DECL(pj_status_t) pjsip_timer_init_module(pjsip_endpoint *endpt);
  94. /**
  95. * Initialize Session Timers setting with default values.
  96. *
  97. * @param setting Session Timers setting to be initialized.
  98. *
  99. * @return PJ_SUCCESS on successful.
  100. */
  101. PJ_DECL(pj_status_t) pjsip_timer_setting_default(pjsip_timer_setting *setting);
  102. /**
  103. * Initialize Session Timers for an invite session. This function should be
  104. * called by application to apply Session Timers setting, otherwise invite
  105. * session will apply default setting to the Session Timers.
  106. *
  107. * @param inv The invite session.
  108. * @param setting Session Timers setting, see pjsip_timer_setting.
  109. * If setting is NULL, default setting will be applied.
  110. *
  111. * @return PJ_SUCCESS on successful.
  112. */
  113. PJ_DECL(pj_status_t) pjsip_timer_init_session(
  114. pjsip_inv_session *inv,
  115. const pjsip_timer_setting *setting);
  116. /**
  117. * Create Session-Expires header.
  118. *
  119. * @param pool Pool to allocate the header instance from.
  120. *
  121. * @return An empty Session-Expires header instance.
  122. */
  123. PJ_DECL(pjsip_sess_expires_hdr*) pjsip_sess_expires_hdr_create(
  124. pj_pool_t *pool);
  125. /**
  126. * Create Min-SE header.
  127. *
  128. * @param pool Pool to allocate the header instance from.
  129. *
  130. * @return An empty Min-SE header instance.
  131. */
  132. PJ_DECL(pjsip_min_se_hdr*) pjsip_min_se_hdr_create(pj_pool_t *pool);
  133. /**
  134. * Update outgoing request to insert Session Timers headers and also
  135. * signal Session Timers capability in Supported and/or Require headers.
  136. *
  137. * This function will be called internally by the invite session if it
  138. * detects that the session needs Session Timers support.
  139. *
  140. * @param inv The invite session.
  141. * @param tdata Outgoing INVITE or UPDATE request.
  142. *
  143. * @return PJ_SUCCESS on successful.
  144. */
  145. PJ_DECL(pj_status_t) pjsip_timer_update_req(pjsip_inv_session *inv,
  146. pjsip_tx_data *tdata);
  147. /**
  148. * Process Session Timers headers in incoming response, this function
  149. * will only process incoming response with status code 422 (Session
  150. * Interval Too Small) or 2xx (final response).
  151. *
  152. * This function will be called internally by the invite session if it
  153. * detects that the session needs Session Timers support.
  154. *
  155. * @param inv The invite session.
  156. * @param rdata Incoming response data.
  157. * @param st_code Output buffer to store corresponding SIP status code
  158. * when function returning non-PJ_SUCCESS.
  159. *
  160. * @return PJ_SUCCESS on successful.
  161. */
  162. PJ_DECL(pj_status_t) pjsip_timer_process_resp(pjsip_inv_session *inv,
  163. const pjsip_rx_data *rdata,
  164. pjsip_status_code *st_code);
  165. /**
  166. * Process Session Timers refresh error, this function will process
  167. * error from refresh request. The error will be handle according the
  168. * error code, i.e : BYE will be sent after error 503 (Transport Error).
  169. *
  170. * @param inv The invite session.
  171. * @param event The event that trigger the error.
  172. *
  173. * @return PJ_SUCCESS on successful.
  174. */
  175. PJ_DECL(pj_status_t) pjsip_timer_handle_refresh_error(
  176. pjsip_inv_session *inv,
  177. pjsip_event *event);
  178. /**
  179. * Process Session Timers headers in incoming request, this function
  180. * will only process incoming INVITE and UPDATE request.
  181. *
  182. * This function will be called internally by the invite session if it
  183. * detects that the session needs Session Timers support.
  184. *
  185. * @param inv The invite session.
  186. * @param rdata Incoming INVITE or UPDATE request.
  187. * @param st_code Output buffer to store corresponding SIP status code
  188. * when function returning non-PJ_SUCCESS.
  189. *
  190. * @return PJ_SUCCESS on successful.
  191. */
  192. PJ_DECL(pj_status_t) pjsip_timer_process_req(pjsip_inv_session *inv,
  193. const pjsip_rx_data *rdata,
  194. pjsip_status_code *st_code);
  195. /**
  196. * Update outgoing response to insert Session Timers headers and also
  197. * signal Session Timers capability in Supported and/or Require headers.
  198. * This function will only update outgoing response with status code
  199. * 422 (Session Interval Too Small) or 2xx (final response).
  200. *
  201. * This function will be called internally by the invite session if it
  202. * detects that the session needs Session Timers support.
  203. *
  204. * @param inv The invite session.
  205. * @param tdata Outgoing 422/2xx response.
  206. *
  207. * @return PJ_SUCCESS on successful.
  208. */
  209. PJ_DECL(pj_status_t) pjsip_timer_update_resp(pjsip_inv_session *inv,
  210. pjsip_tx_data *tdata);
  211. /**
  212. * End Session Timers in an invite session.
  213. *
  214. * This function will be called internally by the invite session if it
  215. * detects that the session needs Session Timers support.
  216. *
  217. * @param inv The invite session.
  218. *
  219. * @return PJ_SUCCESS on successful.
  220. */
  221. PJ_DECL(pj_status_t) pjsip_timer_end_session(pjsip_inv_session *inv);
  222. PJ_END_DECL
  223. /**
  224. * @}
  225. */
  226. #endif /* __PJSIP_TIMER_H__ */