Debian Codegraph @

Xpjproject/pjsip/include/pjsip-ua/sip_replaces.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
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 __PJSIP_REPLACES_H__
20 #define __PJSIP_REPLACES_H__
21
22
23 /**
24 * @file sip_replaces.h
25 * @brief SIP Replaces support (RFC 3891 - SIP "Replaces" Header)
26 */
27 #include <pjsip/sip_msg.h>
28
29 /**
30 * @defgroup PJSIP_REPLACES SIP Replaces support (RFC 3891 - "Replaces" Header)
31 * @ingroup PJSIP_HIGH_UA
32 * @brief SIP Replaces support (RFC 3891 - "Replaces" Header)
33 * @{
34 *
35 * This module implements support for Replaces header in PJSIP. The Replaces
36 * specification is written in RFC 3891 - The Session Initiation Protocol (SIP)
37 * "Replaces" Header, and can be used to enable a variety of features,
38 * for example: "Attended Transfer" and "Call Pickup".
39 *
40 *
41 *
42 * \section PJSIP_REPLACES_USING_SEC Using PJSIP Replaces Support
43 *
44 * \subsection PJSIP_REPLACES_INIT_SUBSEC Initialization
45 *
46 * Application needs to call #pjsip_replaces_init_module() during application
47 * initialization stage to register "replaces" support in PJSIP.
48 *
49 *
50 *
51 * \subsection PJSIP_REPLACES_UAC_SUBSEC UAC Behavior: Sending a Replaces Header
52 *
53 * A User Agent that wishes to replace a single existing early or
54 * confirmed dialog with a new dialog of its own, MAY send the target
55 * User Agent an INVITE request containing a Replaces header field. The
56 * User Agent Client (UAC) places the Call-ID, to-tag, and from-tag
57 * information for the target dialog in a single Replaces header field
58 * and sends the new INVITE to the target.
59 *
60 * To initiate outgoing INVITE request with Replaces header, application
61 * would create the INVITE request with #pjsip_inv_invite(), then adds
62 * #pjsip_replaces_hdr instance into the request, filling up the Call-ID,
63 * To-tag, and From-tag properties of the header with the identification
64 * of the dialog to be replaced. Application may also optionally
65 * set the \a early_only property of the header to indicate that it only
66 * wants to replace early dialog.
67 *
68 * Note that when the outgoing INVITE request (with Replaces) is initiated
69 * from an incoming REFER request (as in Attended Call Transfer case),
70 * this process should be done rather more automatically by PJSIP. Upon
71 * receiving incoming incoming REFER request, normally these processes
72 * will be performed:
73 * - Application finds \a Refer-To header,
74 * - Application creates outgoing dialog/invite session, specifying
75 * the URI in the \a Refer-To header as the initial remote target,
76 * - The URI in the \a Refer-To header may contain header parameters such
77 * as \a Replaces and \a Require headers.
78 * - The dialog keeps the header fields in the header parameters
79 * of the URI, and the invite session would add these headers into
80 * the outgoing INVITE request. Because of this, the outgoing
81 * INVITE request will contain the \a Replaces and \a Require headers.
82 *
83 *
84 * For more information, please see the implementation of
85 * #pjsua_call_xfer_replaces() in \ref PJSUA_LIB source code.
86 *
87 *
88 * \subsection PJSIP_REPLACES_UAS_SUBSEC UAS Behavior: Receiving a Replaces Header
89 *
90 * The Replaces header contains information used to match an existing
91 * SIP dialog (call-id, to-tag, and from-tag). Upon receiving an INVITE
92 * with a Replaces header, the User Agent (UA) attempts to match this
93 * information with a confirmed or early dialog.
94 *
95 * In PJSIP, if application wants to process the Replaces header in the
96 * incoming INVITE request, it should call #pjsip_replaces_verify_request()
97 * before creating the INVITE session. The #pjsip_replaces_verify_request()
98 * function checks and verifies the request to see if Replaces request
99 * can be processed. To be more specific, it performs the following
100 * verification:
101 * - checks that Replaces header is present. If not, the function will
102 * return PJ_SUCCESS without doing anything.
103 * - checks that no duplicate Replaces headers are present, or otherwise
104 * it will return 400 "Bad Request" response.
105 * - checks for matching dialog and verifies that the invite session has
106 * the correct state, and may return 481 "Call/Transaction Does Not Exist",
107 * 603 "Declined", or 486 "Busy Here" according to the processing rules
108 * specified in RFC 3891.
109 * - if matching dialog with correct state is found, it will give PJ_SUCCESS
110 * status and return the matching dialog back to the application.
111 *
112 * The following pseudocode illustrates how application can process the
113 * incoming INVITE if it wants to support Replaces extension:
114 *
115 \code
116 // Incoming INVITE request handler
117 pj_bool_t on_rx_invite(pjsip_rx_data *rdata)
118 {
119 pjsip_dialog *dlg, *replaced_dlg;
120 pjsip_inv_session *inv;
121 pjsip_tx_data *response;
122 pj_status_t status;
123
124 // Check whether Replaces header is present in the request and process accordingly.
125 //
126 status = pjsip_replaces_verify_request(rdata, &replaced_dlg, PJ_FALSE, &response);
127 if (status != PJ_SUCCESS) {
128 // Something wrong with Replaces request.
129 //
130 pj_status_t status;
131 if (response) {
132 status = pjsip_endpt_send_response(endpt, rdata, response, NULL, NULL);
133 if (status != PJ_SUCCESS) pjsip_tx_data_dec_ref(tdata);
134 } else {
135 // Respond with 500 (Internal Server Error)
136 status = pjsip_endpt_respond_stateless(endpt, rdata, 500, NULL, NULL, NULL);
137 if (status != PJ_SUCCESS) pjsip_tx_data_dec_ref(tdata);
138 }
139 }
140
141 // Create UAS Invite session as usual.
142 //
143 status = pjsip_dlg_create_uas_and_inc_lock(.., rdata, .., &dlg);
144 ..
145 status = pjsip_inv_create_uas(dlg, .., &inv);
146
147 // Send initial 100 "Trying" to the INVITE request
148 //
149 status = pjsip_inv_initial_answer(inv, rdata, 100, ..., &response);
150 if (status == PJ_SUCCESS)
151 pjsip_inv_send_msg(inv, response);
152
153
154 // This is where processing is different between normal call
155 // (without Replaces) and call with Replaces.
156 //
157 if (replaced_dlg) {
158 pjsip_inv_session *replaced_inv;
159
160 // Always answer the new INVITE with 200, regardless whether
161 // the replaced call is in early or confirmed state.
162 //
163 status = pjsip_inv_answer(inv, 200, NULL, NULL, &response);
164 if (status == PJ_SUCCESS)
165 pjsip_inv_send_msg(inv, response);
166
167
168 // Get the INVITE session associated with the replaced dialog.
169 //
170 replaced_inv = pjsip_dlg_get_inv_session(replaced_dlg);
171
172
173 // Disconnect the "replaced" INVITE session.
174 //
175 status = pjsip_inv_end_session(replaced_inv, PJSIP_SC_GONE, NULL, &tdata);
176 if (status == PJ_SUCCESS && tdata)
177 status = pjsip_inv_send_msg(replaced_inv, tdata);
178
179
180 // It's up to application to associate the new INVITE session
181 // with the old (now terminated) session. For example, application
182 // may assign the same User Interface object for the new INVITE
183 // session.
184
185 } else {
186 // Process normal INVITE without Replaces.
187 ...
188 }
189 }
190
191 \endcode
192 *
193 *
194 * For a complete sample implementation, please see \a pjsua_call_on_incoming()
195 * function of \ref PJSUA_LIB in \a pjsua_call.c file.
196 *
197 *
198 * \section PJSIP_REPLACES_REFERENCE References
199 *
200 * References:
201 * - <A HREF="http://www.ietf.org/rfc/rfc3891.txt">RFC 3891: The Session
202 * Initiation Protocol (SIP) "Replaces" Header</A>
203 * - \ref PJSUA_XFER
204 */
205
206 PJ_BEGIN_DECL
207
208
209 /**
210 * Declaration of SIP Replaces header (RFC 3891).
211 */
212 typedef struct pjsip_replaces_hdr
213 {
214 /** Standard header field. */
215 PJSIP_DECL_HDR_MEMBER(struct pjsip_replaces_hdr);
216
217 /** Call-Id */
218 pj_str_t call_id;
219
220 /** to-tag */
221 pj_str_t to_tag;
222
223 /** from-tag */
224 pj_str_t from_tag;
225
226 /** early-only? */
227 pj_bool_t early_only;
228
229 /** Other parameters */
230 pjsip_param other_param;
231
232 } pjsip_replaces_hdr;
233
234
235
236 /**
237 * Initialize Replaces support in PJSIP. This would, among other things,
238 * register the header parser for Replaces header.
239 *
240 * @param endpt The endpoint instance.
241 *
242 * @return PJ_SUCCESS on success.
243 */
244 PJ_DECL(pj_status_t) pjsip_replaces_init_module(pjsip_endpoint *endpt);
245
246
247 /**
248 * Create Replaces header.
249 *
250 * @param pool Pool to allocate the header instance from.
251 *
252 * @return An empty Replaces header instance.
253 */
254 PJ_DECL(pjsip_replaces_hdr*) pjsip_replaces_hdr_create(pj_pool_t *pool);
255
256
257 /**
258 * Verify that incoming request with Replaces header can be processed.
259 * This function will perform all necessary checks according to RFC 3891
260 * Section 3 "User Agent Server Behavior: Receiving a Replaces Header".
261 *
262 * @param rdata The incoming request to be verified.
263 * @param p_dlg On return, it will be filled with the matching
264 * dialog.
265 * @param lock_dlg Specifies whether this function should acquire lock
266 * to the matching dialog. If yes (and should be yes!),
267 * then application will need to release the dialog's
268 * lock with #pjsip_dlg_dec_lock() when the function
269 * returns PJ_SUCCESS and the \a p_dlg parameter is filled
270 * with the dialog instance.
271 * @param p_tdata Upon error, it will be filled with the final response
272 * to be sent to the request sender.
273 *
274 * @return The function returns the following:
275 * - If the request doesn't contain Replaces header, the
276 * function returns PJ_SUCCESS and \a p_dlg parameter
277 * will be set to NULL.
278 * - If the request contains Replaces header and a valid,
279 * matching dialog is found, the function returns
280 * PJ_SUCCESS and \a p_dlg parameter will be set to the
281 * matching dialog instance.
282 * - Upon error condition (as described by RFC 3891), the
283 * function returns non-PJ_SUCCESS, and \a p_tdata
284 * parameter SHOULD be set with a final response message
285 * to be sent to the sender of the request.
286 */
287 PJ_DECL(pj_status_t) pjsip_replaces_verify_request(pjsip_rx_data *rdata,
288 pjsip_dialog **p_dlg,
289 pj_bool_t lock_dlg,
290 pjsip_tx_data **p_tdata);
291
292
293
294 PJ_END_DECL
295
296
297 /**
298 * @}
299 */
300
301
302 #endif /* __PJSIP_REPLACES_H__ */
303