blob: 6ba8485cda416c51a40b8777249b8b72191cc170 [file] [log] [blame]
Benny Prijonodcfc0ba2007-09-30 16:50:27 +00001/* $Id$ */
2/*
3 * Copyright (C) 2003-2007 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/**
23 * @file sip_100rel.h
24 * @brief PRACK (Reliability of Provisional Responses)
25 */
26
27
28#include <pjsip-ua/sip_inv.h>
29
30
31/**
32 * @defgroup PJSIP_100REL 100rel/PRACK - Reliability of Provisional Responses
33 * @ingroup PJSIP_HIGH_UA
34 * @brief PRACK - Reliability of Provisional Responses
35 * @{
36 *
37 * This module provides management of Reliability of Provisional Responses
38 * (\a 100rel and \a PRACK), as described in RFC 3262.
39 *
40 * Other than the #pjsip_100rel_init_module() function, the 100rel API
41 * exported by this module are not intended to be used by application, but
42 * rather they will be invoked by the \ref PJSIP_INV.
43 *
44 * \section pjsip_100rel_using Using Reliable Provisional Response
45 *
46 * \subsection pjsip_100rel_init Initializing 100rel Module
47 *
Benny Prijono1f7767b2007-10-03 18:28:49 +000048 * Application must explicitly initialize 100rel module by calling
Benny Prijonodcfc0ba2007-09-30 16:50:27 +000049 * #pjsip_100rel_init_module() in application initialization function.
50 *
51 * Once the 100rel module is initialized, it will register \a PRACK method
52 * in \a Allow header, and \a 100rel tag in \a Supported header.
53 *
54 * \subsection pjsip_100rel_sess Using 100rel in a Session
55 *
56 * For UAC, \a 100rel support will be enabled in the session if \a 100rel
Benny Prijono1f7767b2007-10-03 18:28:49 +000057 * support is enabled in the library (default is yes).
Benny Prijonodcfc0ba2007-09-30 16:50:27 +000058 * Outgoing INVITE request will include \a 100rel tag in \a Supported
59 * header and \a PRACK method in \a Allow header. When callee endpoint
60 * sends reliable provisional responses, the UAC will automatically send
61 * \a PRACK request to acknowledge the response. If callee endpoint doesn't
62 * send reliable provisional response, the response will be handled using
63 * normal, non-100rel procedure (that is, \a PRACK will not be sent).
64 *
65 * If the UAC wants to <b>mandate</b> \a 100rel support, it can specify
66 * #PJSIP_INV_REQUIRE_100REL in the \a options argument when calling
67 * #pjsip_inv_create_uac(). In this case, PJSIP will add \a 100rel tag
68 * in the \a Require header of the outgoing INVITE request.
69 *
70 * For UAS, if it wants to support \a 100rel but not to mandate it,
71 * it must specify #PJSIP_INV_SUPPORT_100REL flag in the \a options
72 * argument when calling #pjsip_inv_verify_request(), and pass the same
73 * \a options variable when calling #pjsip_inv_verify_request. If UAC had
74 * specified \a 100rel in it's list of extensions in \a Require header,
75 * the UAS will send provisional responses reliably. If UAC only listed
76 * \a 100rel in its \a Supported header but not in \a Require header,
77 * or if UAC does not list \a 100rel support at all, the UAS WILL NOT
78 * send provisional responses reliably.
79 * The snippet below can be used to accomplish this task:
80 *
81 * \verbatim
82 unsigned options = 0;
83
Benny Prijonodcfc0ba2007-09-30 16:50:27 +000084 options |= PJSIP_INV_SUPPORT_100REL;
Benny Prijonodcfc0ba2007-09-30 16:50:27 +000085
86 status = pjsip_inv_verify_request(rdata, &options, answer, NULL,
87 endpt, &resp);
88 if (status != PJ_SUCCESS) {
89 // INVITE request cannot be handled.
90 // Reject the request with the response in resp.
91 ...
92 return;
93 }
94
95 // Create UAS dialog, populate Contact header, etc.
96 ...
97
98 // Create UAS invite session
99 status = pjsip_inv_create_uas( dlg, rdata, answer, options, &inv);
100
101 ..
102
103 \endverbatim
104 *
105 * For another requirement, if UAS wants to <b>mandate</b> \a 100rel support,
106 * it can specify #PJSIP_INV_REQUIRE_100REL flag when calling
107 * #pjsip_inv_verify_request(), and pass the \a options when calling
108 * #pjsip_inv_verify_request. In this case,
109 * \a 100rel extension will be used if UAC specifies \a 100rel in its
110 * \a Supported header. If UAC does not list \a 100rel in \a Supported header,
111 * the incoming INVITE request will be rejected with 421 (Extension Required)
112 * response. For the sample code, it should be identical to the snippet
113 * above, except that application must specify #PJSIP_INV_REQUIRE_100REL
114 * flag in the \a options instead of #PJSIP_INV_SUPPORT_100REL.
115 *
116 * For yet another requirement, if UAS <b>does not</b> want to support
117 * \a 100rel extension, it can reject incoming INVITE request with
118 * 420 (Bad Extension) response whenever incoming INVITE request has
119 * \a 100rel tag in its \a Require header. This can be done by specifying
120 * zero as the \a options when calling #pjsip_inv_verify_request().
121 */
122
123PJ_BEGIN_DECL
124
Benny Prijono1f7767b2007-10-03 18:28:49 +0000125
126/**
127 * PRACK method constant.
128 * @see pjsip_get_prack_method()
129 */
130PJ_DECL_DATA(const pjsip_method) pjsip_prack_method;
131
132
133/**
134 * Get #pjsip_invite_method constant.
135 */
136PJ_DECL(const pjsip_method*) pjsip_get_prack_method(void);
137
138
Benny Prijonodcfc0ba2007-09-30 16:50:27 +0000139/**
140 * Initialize 100rel module. This function must be called once during
141 * application initialization, to register 100rel module to SIP endpoint.
142 *
143 * @param endpt The SIP endpoint instance.
144 *
145 * @return PJ_SUCCESS if module is successfully initialized.
146 */
147PJ_DECL(pj_status_t) pjsip_100rel_init_module(pjsip_endpoint *endpt);
148
Benny Prijono1f7767b2007-10-03 18:28:49 +0000149
Benny Prijonodcfc0ba2007-09-30 16:50:27 +0000150/**
151 * Add 100rel support to the specified invite session. This function will
152 * be called internally by the invite session if it detects that the
153 * session needs 100rel support.
154 *
155 * @param inv The invite session.
156 *
157 * @return PJ_SUCCESS on successful.
158 */
159PJ_DECL(pj_status_t) pjsip_100rel_attach(pjsip_inv_session *inv);
160
Benny Prijono1f7767b2007-10-03 18:28:49 +0000161
162/**
163 * Check if incoming response has reliable provisional response feature.
164 *
165 * @param rdata Receive data buffer containing the response.
166 *
167 * @return PJ_TRUE if the provisional response is reliable.
168 */
169PJ_DECL(pj_bool_t) pjsip_100rel_is_reliable(pjsip_rx_data *rdata);
170
171
172/**
173 * Create PRACK request for the incoming reliable provisional response.
174 * Note that PRACK request MUST be sent using #pjsip_100rel_send_prack().
175 *
176 * @param inv The invite session.
177 * @param rdata The incoming reliable provisional response.
178 * @param p_tdata Upon return, it will be initialized with the
179 * PRACK request.
180 *
181 * @return PJ_SUCCESS on successful.
182 */
183PJ_DECL(pj_status_t) pjsip_100rel_create_prack(pjsip_inv_session *inv,
184 pjsip_rx_data *rdata,
185 pjsip_tx_data **p_tdata);
186
187/**
188 * Send PRACK request.
189 *
190 * @param inv The invite session.
191 * @param tdata The PRACK request.
192 *
193 * @return PJ_SUCCESS on successful.
194 */
195PJ_DECL(pj_status_t) pjsip_100rel_send_prack(pjsip_inv_session *inv,
196 pjsip_tx_data *tdata);
197
198
199/**
200 * Handle incoming PRACK request.
201 *
202 * @param inv The invite session.
203 * @param rdata Incoming PRACK request.
204 *
205 * @return PJ_SUCCESS on successful.
206 */
207PJ_DECL(pj_status_t) pjsip_100rel_on_rx_prack(pjsip_inv_session *inv,
208 pjsip_rx_data *rdata);
209
210
Benny Prijonodcfc0ba2007-09-30 16:50:27 +0000211/**
212 * Transmit INVITE response (provisional or final) reliably according to
213 * 100rel specification. The 100rel module will take care of retransmitting
214 * or enqueueing the response according to the current state of the
215 * reliable response processing. This function will be called internally
216 * by invite session.
217 *
218 * @param inv The invite session.
219 * @param tdata The INVITE response.
220 *
221 * @return PJ_SUCCESS on successful.
222 */
223PJ_DECL(pj_status_t) pjsip_100rel_tx_response(pjsip_inv_session *inv,
224 pjsip_tx_data *tdata);
225
226
Benny Prijono1f7767b2007-10-03 18:28:49 +0000227/**
228 * Notify 100rel module that the invite session has been disconnected.
229 *
230 * @param inv The invite session.
231 *
232 * @return PJ_SUCCESS on successful.
233 */
234PJ_DECL(pj_status_t) pjsip_100rel_end_session(pjsip_inv_session *inv);
235
236
Benny Prijonodcfc0ba2007-09-30 16:50:27 +0000237PJ_END_DECL
238
239/**
240 * @}
241 */
242
243
244#endif /* __SIP_100REL_H__ */