sip_100rel.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __SIP_100REL_H__
  20. #define __SIP_100REL_H__
  21. /**
  22. * @file sip_100rel.h
  23. * @brief PRACK (Reliability of Provisional Responses)
  24. */
  25. #include <pjsip-ua/sip_inv.h>
  26. /**
  27. * @defgroup PJSIP_100REL 100rel/PRACK - Reliability of Provisional Responses
  28. * @ingroup PJSIP_HIGH_UA
  29. * @brief PRACK - Reliability of Provisional Responses
  30. * @{
  31. *
  32. * This module provides management of Reliability of Provisional Responses
  33. * (\a 100rel and \a PRACK), as described in RFC 3262.
  34. *
  35. * Other than the #pjsip_100rel_init_module() function, the 100rel API
  36. * exported by this module are not intended to be used by application, but
  37. * rather they will be invoked by the \ref PJSIP_INV.
  38. *
  39. * \section pjsip_100rel_using Using Reliable Provisional Response
  40. *
  41. * \subsection pjsip_100rel_init Initializing 100rel Module
  42. *
  43. * Application must explicitly initialize 100rel module by calling
  44. * #pjsip_100rel_init_module() in application initialization function.
  45. *
  46. * Once the 100rel module is initialized, it will register \a PRACK method
  47. * in \a Allow header, and \a 100rel tag in \a Supported header.
  48. *
  49. * \subsection pjsip_100rel_sess Using 100rel in a Session
  50. *
  51. * For UAC, \a 100rel support will be enabled in the session if \a 100rel
  52. * support is enabled in the library (default is yes).
  53. * Outgoing INVITE request will include \a 100rel tag in \a Supported
  54. * header and \a PRACK method in \a Allow header. When callee endpoint
  55. * sends reliable provisional responses, the UAC will automatically send
  56. * \a PRACK request to acknowledge the response. If callee endpoint doesn't
  57. * send reliable provisional response, the response will be handled using
  58. * normal, non-100rel procedure (that is, \a PRACK will not be sent).
  59. *
  60. * If the UAC wants to <b>mandate</b> \a 100rel support, it can specify
  61. * #PJSIP_INV_REQUIRE_100REL in the \a options argument when calling
  62. * #pjsip_inv_create_uac(). In this case, PJSIP will add \a 100rel tag
  63. * in the \a Require header of the outgoing INVITE request.
  64. *
  65. * For UAS, if it wants to support \a 100rel but not to mandate it,
  66. * it must specify #PJSIP_INV_SUPPORT_100REL flag in the \a options
  67. * argument when calling #pjsip_inv_verify_request(), and pass the same
  68. * \a options variable when calling #pjsip_inv_verify_request. If UAC had
  69. * specified \a 100rel in it's list of extensions in \a Require header,
  70. * the UAS will send provisional responses reliably. If UAC only listed
  71. * \a 100rel in its \a Supported header but not in \a Require header,
  72. * or if UAC does not list \a 100rel support at all, the UAS WILL NOT
  73. * send provisional responses reliably.
  74. * The snippet below can be used to accomplish this task:
  75. *
  76. * \verbatim
  77. unsigned options = 0;
  78. options |= PJSIP_INV_SUPPORT_100REL;
  79. status = pjsip_inv_verify_request(rdata, &options, answer, NULL,
  80. endpt, &resp);
  81. if (status != PJ_SUCCESS) {
  82. // INVITE request cannot be handled.
  83. // Reject the request with the response in resp.
  84. ...
  85. return;
  86. }
  87. // Create UAS dialog, populate Contact header, etc.
  88. ...
  89. // Create UAS invite session
  90. status = pjsip_inv_create_uas( dlg, rdata, answer, options, &inv);
  91. ..
  92. \endverbatim
  93. *
  94. * For another requirement, if UAS wants to <b>mandate</b> \a 100rel support,
  95. * it can specify #PJSIP_INV_REQUIRE_100REL flag when calling
  96. * #pjsip_inv_verify_request(), and pass the \a options when calling
  97. * #pjsip_inv_verify_request. In this case,
  98. * \a 100rel extension will be used if UAC specifies \a 100rel in its
  99. * \a Supported header. If UAC does not list \a 100rel in \a Supported header,
  100. * the incoming INVITE request will be rejected with 421 (Extension Required)
  101. * response. For the sample code, it should be identical to the snippet
  102. * above, except that application must specify #PJSIP_INV_REQUIRE_100REL
  103. * flag in the \a options instead of #PJSIP_INV_SUPPORT_100REL.
  104. *
  105. * For yet another requirement, if UAS <b>does not</b> want to support
  106. * \a 100rel extension, it can reject incoming INVITE request with
  107. * 420 (Bad Extension) response whenever incoming INVITE request has
  108. * \a 100rel tag in its \a Require header. This can be done by specifying
  109. * zero as the \a options when calling #pjsip_inv_verify_request().
  110. */
  111. PJ_BEGIN_DECL
  112. /**
  113. * PRACK method constant.
  114. * @see pjsip_get_prack_method()
  115. */
  116. PJ_DECL_DATA(const pjsip_method) pjsip_prack_method;
  117. /**
  118. * Get #pjsip_invite_method constant.
  119. */
  120. PJ_DECL(const pjsip_method*) pjsip_get_prack_method(void);
  121. /**
  122. * Initialize 100rel module. This function must be called once during
  123. * application initialization, to register 100rel module to SIP endpoint.
  124. *
  125. * @param endpt The SIP endpoint instance.
  126. *
  127. * @return PJ_SUCCESS if module is successfully initialized.
  128. */
  129. PJ_DECL(pj_status_t) pjsip_100rel_init_module(pjsip_endpoint *endpt);
  130. /**
  131. * Add 100rel support to the specified invite session. This function will
  132. * be called internally by the invite session if it detects that the
  133. * session needs 100rel support.
  134. *
  135. * @param inv The invite session.
  136. *
  137. * @return PJ_SUCCESS on successful.
  138. */
  139. PJ_DECL(pj_status_t) pjsip_100rel_attach(pjsip_inv_session *inv);
  140. /**
  141. * Check if incoming response has reliable provisional response feature.
  142. *
  143. * @param rdata Receive data buffer containing the response.
  144. *
  145. * @return PJ_TRUE if the provisional response is reliable.
  146. */
  147. PJ_DECL(pj_bool_t) pjsip_100rel_is_reliable(pjsip_rx_data *rdata);
  148. /**
  149. * Create PRACK request for the incoming reliable provisional response.
  150. * Note that PRACK request MUST be sent using #pjsip_100rel_send_prack().
  151. *
  152. * @param inv The invite session.
  153. * @param rdata The incoming reliable provisional response.
  154. * @param p_tdata Upon return, it will be initialized with the
  155. * PRACK request.
  156. *
  157. * @return PJ_SUCCESS on successful.
  158. */
  159. PJ_DECL(pj_status_t) pjsip_100rel_create_prack(pjsip_inv_session *inv,
  160. pjsip_rx_data *rdata,
  161. pjsip_tx_data **p_tdata);
  162. /**
  163. * Send PRACK request.
  164. *
  165. * @param inv The invite session.
  166. * @param tdata The PRACK request.
  167. *
  168. * @return PJ_SUCCESS on successful.
  169. */
  170. PJ_DECL(pj_status_t) pjsip_100rel_send_prack(pjsip_inv_session *inv,
  171. pjsip_tx_data *tdata);
  172. /**
  173. * Handle incoming PRACK request.
  174. *
  175. * @param inv The invite session.
  176. * @param rdata Incoming PRACK request.
  177. *
  178. * @return PJ_SUCCESS on successful.
  179. */
  180. PJ_DECL(pj_status_t) pjsip_100rel_on_rx_prack(pjsip_inv_session *inv,
  181. pjsip_rx_data *rdata);
  182. /**
  183. * Transmit INVITE response (provisional or final) reliably according to
  184. * 100rel specification. The 100rel module will take care of retransmitting
  185. * or enqueueing the response according to the current state of the
  186. * reliable response processing. This function will be called internally
  187. * by invite session.
  188. *
  189. * @param inv The invite session.
  190. * @param tdata The INVITE response.
  191. *
  192. * @return PJ_SUCCESS on successful.
  193. */
  194. PJ_DECL(pj_status_t) pjsip_100rel_tx_response(pjsip_inv_session *inv,
  195. pjsip_tx_data *tdata);
  196. /**
  197. * Notify 100rel module that the invite session has been disconnected.
  198. *
  199. * @param inv The invite session.
  200. *
  201. * @return PJ_SUCCESS on successful.
  202. */
  203. PJ_DECL(pj_status_t) pjsip_100rel_end_session(pjsip_inv_session *inv);
  204. PJ_END_DECL
  205. /**
  206. * @}
  207. */
  208. #endif /* __SIP_100REL_H__ */