blob: e455a20ffc5529114b40a3e9e1c523541d2ff29a [file] [log] [blame]
Benny Prijono268ca612006-02-07 12:34:11 +00001/* $Id$ */
2/*
Nanang Izzuddina62ffc92011-05-05 06:14:19 +00003 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
Benny Prijono32177c02008-06-20 22:44:47 +00004 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijono268ca612006-02-07 12:34:11 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#ifndef __SIP_INVITE_SESSION_H__
21#define __SIP_INVITE_SESSION_H__
22
Benny Prijono312aff92006-06-17 04:08:30 +000023/**
24 * @file sip_inv.h
25 * @brief INVITE sessions
26 */
27
28
Benny Prijono268ca612006-02-07 12:34:11 +000029#include <pjsip/sip_dialog.h>
30#include <pjmedia/sdp_neg.h>
31
Benny Prijonof3195072006-02-14 21:15:30 +000032
Benny Prijono312aff92006-06-17 04:08:30 +000033/**
34 * @defgroup PJSIP_HIGH_UA User Agent Library
Benny Prijono312aff92006-06-17 04:08:30 +000035 * @brief Mid-level User Agent Library.
36 *
37 * This is the high level user agent library, which consists of:
38 * - @ref PJSIP_INV, to encapsulate INVITE sessions and SDP
39 * negotiation in the session,
40 * - @ref PJSUA_REGC, high level client registration API, and
41 * - @ref PJSUA_XFER.
42 *
43 * More detailed information is explained in
44 * <A HREF="/docs.htm">PJSIP Developer's Guide</A>
45 * PDF document, and readers are encouraged to read the document to
46 * get the concept behind dialog, dialog usages, and INVITE sessions.
47 *
48 * The User Agent Library is implemented in <b>pjsip-ua</b> static
49 * library.
50 */
51
52/**
53 * @defgroup PJSIP_INV INVITE Session
54 * @ingroup PJSIP_HIGH_UA
55 * @brief Provides INVITE session management.
56 * @{
57 *
58 * The INVITE session uses the @ref PJSIP_DIALOG framework to manage
59 * the underlying dialog, and is one type of usages that can use
60 * a particular dialog instance (other usages are event subscription,
61 * discussed in @ref PJSIP_EVENT_NOT). The INVITE session manages
62 * the life-time of the session, and also manages the SDP negotiation.
63 *
64 * Application must link with <b>pjsip-ua</b> static library to use this API.
65 *
66 * More detailed information is explained in
67 * <A HREF="/docs.htm">PJSIP Developer's Guide</A>
68 * PDF document, and readers are encouraged to read the document to
69 * get the concept behind dialog, dialog usages, and INVITE sessions.
70 *
71 * The INVITE session does NOT manage media. If application wants to
72 * use API that encapsulates both signaling and media in a very easy
73 * to use API, it can use @ref PJSUA_LIB for this purpose.
74 */
75
Benny Prijonof3195072006-02-14 21:15:30 +000076PJ_BEGIN_DECL
77
78
Benny Prijono312aff92006-06-17 04:08:30 +000079/**
80 * @see pjsip_inv_session
81 */
Benny Prijono268ca612006-02-07 12:34:11 +000082typedef struct pjsip_inv_session pjsip_inv_session;
Benny Prijono312aff92006-06-17 04:08:30 +000083
Benny Prijono268ca612006-02-07 12:34:11 +000084
85/**
86 * This enumeration describes invite session state.
87 */
Benny Prijono312aff92006-06-17 04:08:30 +000088typedef enum pjsip_inv_state
Benny Prijono268ca612006-02-07 12:34:11 +000089{
90 PJSIP_INV_STATE_NULL, /**< Before INVITE is sent or received */
91 PJSIP_INV_STATE_CALLING, /**< After INVITE is sent */
92 PJSIP_INV_STATE_INCOMING, /**< After INVITE is received. */
93 PJSIP_INV_STATE_EARLY, /**< After response with To tag. */
94 PJSIP_INV_STATE_CONNECTING, /**< After 2xx is sent/received. */
95 PJSIP_INV_STATE_CONFIRMED, /**< After ACK is sent/received. */
96 PJSIP_INV_STATE_DISCONNECTED, /**< Session is terminated. */
Benny Prijono312aff92006-06-17 04:08:30 +000097} pjsip_inv_state;
Benny Prijono268ca612006-02-07 12:34:11 +000098
99/**
100 * This structure contains callbacks to be registered by application to
101 * receieve notifications from the framework about various events in
102 * the invite session.
103 */
Benny Prijono312aff92006-06-17 04:08:30 +0000104typedef struct pjsip_inv_callback
Benny Prijono268ca612006-02-07 12:34:11 +0000105{
106 /**
107 * This callback is called when the invite sesion state has changed.
108 * Application should inspect the session state (inv_sess->state) to get
109 * the current state of the session.
110 *
111 * This callback is mandatory.
112 *
113 * @param inv The invite session.
114 * @param e The event which has caused the invite session's
115 * state to change.
116 */
117 void (*on_state_changed)(pjsip_inv_session *inv, pjsip_event *e);
118
Benny Prijono268ca612006-02-07 12:34:11 +0000119 /**
120 * This callback is called when the invite usage module has created
121 * a new dialog and invite because of forked outgoing request.
122 *
123 * This callback is mandatory.
124 *
125 * @param inv The new invite session.
126 * @param e The event which has caused the dialog to fork.
127 * The type of this event can be either
128 * PJSIP_EVENT_RX_MSG or PJSIP_EVENT_RX_200_MSG.
129 */
130 void (*on_new_session)(pjsip_inv_session *inv, pjsip_event *e);
131
132 /**
133 * This callback is called whenever any transactions within the session
134 * has changed their state. Application MAY implement this callback,
Benny Prijonofeb69f42007-10-05 09:12:26 +0000135 * e.g. to monitor the progress of an outgoing request, or to send
136 * response to unhandled incoming request (such as INFO).
Benny Prijono268ca612006-02-07 12:34:11 +0000137 *
138 * This callback is optional.
139 *
140 * @param inv The invite session.
141 * @param tsx The transaction, which state has changed.
142 * @param e The event which has caused the transation state's
143 * to change.
144 */
145 void (*on_tsx_state_changed)(pjsip_inv_session *inv,
146 pjsip_transaction *tsx,
147 pjsip_event *e);
148
149 /**
150 * This callback is called when the invite session has received
151 * new offer from peer. Application can inspect the remote offer
Benny Prijono77998ce2007-06-20 10:03:46 +0000152 * in "offer", and set the SDP answer with #pjsip_inv_set_sdp_answer().
153 * When the application sends a SIP message to send the answer,
154 * this SDP answer will be negotiated with the offer, and the result
155 * will be sent with the SIP message.
Benny Prijono268ca612006-02-07 12:34:11 +0000156 *
157 * @param inv The invite session.
Benny Prijono26ff9062006-02-21 23:47:00 +0000158 * @param offer Remote offer.
Benny Prijono268ca612006-02-07 12:34:11 +0000159 */
Benny Prijono26ff9062006-02-21 23:47:00 +0000160 void (*on_rx_offer)(pjsip_inv_session *inv,
161 const pjmedia_sdp_session *offer);
Benny Prijono268ca612006-02-07 12:34:11 +0000162
163 /**
Benny Prijono77998ce2007-06-20 10:03:46 +0000164 * This callback is optional, and it is used to ask the application
165 * to create a fresh offer, when the invite session has received
166 * re-INVITE without offer. This offer then will be sent in the
167 * 200/OK response to the re-INVITE request.
168 *
169 * If application doesn't implement this callback, the invite session
170 * will send the currently active SDP as the offer.
171 *
172 * @param inv The invite session.
173 * @param p_offer Pointer to receive the SDP offer created by
174 * application.
175 */
176 void (*on_create_offer)(pjsip_inv_session *inv,
177 pjmedia_sdp_session **p_offer);
178
179 /**
Benny Prijono268ca612006-02-07 12:34:11 +0000180 * This callback is called after SDP offer/answer session has completed.
181 * The status argument specifies the status of the offer/answer,
182 * as returned by pjmedia_sdp_neg_negotiate().
183 *
184 * This callback is optional (from the point of view of the framework),
185 * but all useful applications normally need to implement this callback.
186 *
187 * @param inv The invite session.
188 * @param status The negotiation status.
189 */
190 void (*on_media_update)(pjsip_inv_session *inv_ses,
191 pj_status_t status);
Benny Prijono312aff92006-06-17 04:08:30 +0000192
Benny Prijonod5f9f422007-11-25 04:40:07 +0000193 /**
194 * This callback is called when the framework needs to send
195 * ACK request after it receives incoming 2xx response for
196 * INVITE. It allows application to manually handle the
197 * transmission of ACK request, which is required by some 3PCC
198 * scenarios. If this callback is not implemented, the framework
199 * will handle the ACK transmission automatically.
200 *
201 * When this callback is overridden, application may delay the
202 * sending of the ACK request (for example, when it needs to
203 * wait for answer from the other call leg, in 3PCC scenarios).
204 *
205 * Application creates the ACK request
206 *
207 * Once it has sent the ACK request, the framework will keep
208 * this ACK request in the cache. Subsequent receipt of 2xx response
209 * will not cause this callback to be called, and instead automatic
210 * retransmission of this ACK request from the cache will be done
211 * by the framework.
212 *
213 * This callback is optional.
214 */
215 void (*on_send_ack)(pjsip_inv_session *inv, pjsip_rx_data *rdata);
216
Benny Prijono5e51a4e2008-11-27 00:06:46 +0000217 /**
218 * This callback is called when the session is about to resend the
219 * INVITE request to the specified target, following the previously
220 * received redirection response.
221 *
222 * Application may accept the redirection to the specified target
223 * (the default behavior if this callback is implemented), reject
224 * this target only and make the session continue to try the next
225 * target in the list if such target exists, stop the whole
226 * redirection process altogether and cause the session to be
227 * disconnected, or defer the decision to ask for user confirmation.
228 *
229 * This callback is optional. If this callback is not implemented,
230 * the default behavior is to NOT follow the redirection response.
231 *
232 * @param inv The invite session.
233 * @param target The current target to be tried.
Benny Prijono08a48b82008-11-27 12:42:07 +0000234 * @param e The event that caused this callback to be called.
235 * This could be the receipt of 3xx response, or
236 * 4xx/5xx response received for the INVITE sent to
237 * subsequent targets, or NULL if this callback is
238 * called from within #pjsip_inv_process_redirect()
239 * context.
240 *
241 * @return Action to be performed for the target. Set this
Benny Prijono5e51a4e2008-11-27 00:06:46 +0000242 * parameter to one of the value below:
243 * - PJSIP_REDIRECT_ACCEPT: immediately accept the
Benny Prijono08a48b82008-11-27 12:42:07 +0000244 * redirection to this target. When set, the
Benny Prijono5e51a4e2008-11-27 00:06:46 +0000245 * session will immediately resend INVITE request
Benny Prijono08a48b82008-11-27 12:42:07 +0000246 * to the target after this callback returns.
Benny Prijono5e51a4e2008-11-27 00:06:46 +0000247 * - PJSIP_REDIRECT_REJECT: immediately reject this
248 * target. The session will continue retrying with
249 * next target if present, or disconnect the call
250 * if there is no more target to try.
251 * - PJSIP_REDIRECT_STOP: stop the whole redirection
252 * process and immediately disconnect the call. The
253 * on_state_changed() callback will be called with
254 * PJSIP_INV_STATE_DISCONNECTED state immediately
255 * after this callback returns.
256 * - PJSIP_REDIRECT_PENDING: set to this value if
257 * no decision can be made immediately (for example
258 * to request confirmation from user). Application
259 * then MUST call #pjsip_inv_process_redirect()
260 * to either accept or reject the redirection upon
261 * getting user decision.
Benny Prijono5e51a4e2008-11-27 00:06:46 +0000262 */
Benny Prijono08a48b82008-11-27 12:42:07 +0000263 pjsip_redirect_op (*on_redirected)(pjsip_inv_session *inv,
264 const pjsip_uri *target,
265 const pjsip_event *e);
Benny Prijono5e51a4e2008-11-27 00:06:46 +0000266
Benny Prijono312aff92006-06-17 04:08:30 +0000267} pjsip_inv_callback;
268
Benny Prijono268ca612006-02-07 12:34:11 +0000269
270
271/**
272 * This enumeration shows various options that can be applied to a session.
273 * The bitmask combination of these options need to be specified when
274 * creating a session. After the dialog is established (including early),
275 * the options member of #pjsip_inv_session shows which capabilities are
276 * common in both endpoints.
277 */
278enum pjsip_inv_option
279{
280 /**
281 * Indicate support for reliable provisional response extension
282 */
283 PJSIP_INV_SUPPORT_100REL = 1,
284
285 /**
286 * Indicate support for session timer extension.
287 */
288 PJSIP_INV_SUPPORT_TIMER = 2,
289
290 /**
291 * Indicate support for UPDATE method. This is automatically implied
292 * when creating outgoing dialog. After the dialog is established,
293 * the options member of #pjsip_inv_session shows whether peer supports
294 * this method as well.
295 */
296 PJSIP_INV_SUPPORT_UPDATE = 4,
297
Benny Prijono07fe2302010-06-24 12:33:18 +0000298 /**
299 * Indicate support for ICE
300 */
301 PJSIP_INV_SUPPORT_ICE = 8,
302
303 /**
304 * Require ICE support.
305 */
306 PJSIP_INV_REQUIRE_ICE = 16,
307
Benny Prijono268ca612006-02-07 12:34:11 +0000308 /**
309 * Require reliable provisional response extension.
310 */
311 PJSIP_INV_REQUIRE_100REL = 32,
312
313 /**
314 * Require session timer extension.
315 */
316 PJSIP_INV_REQUIRE_TIMER = 64,
317
Nanang Izzuddin59dffb12009-08-11 12:42:38 +0000318 /**
319 * Session timer extension will always be used even when peer doesn't
320 * support/want session timer.
321 */
Benny Prijono07fe2302010-06-24 12:33:18 +0000322 PJSIP_INV_ALWAYS_USE_TIMER = 128
Nanang Izzuddin59dffb12009-08-11 12:42:38 +0000323
Benny Prijono268ca612006-02-07 12:34:11 +0000324};
325
Nanang Izzuddin59dffb12009-08-11 12:42:38 +0000326/* Forward declaration of Session Timers */
327struct pjsip_timer;
Benny Prijono268ca612006-02-07 12:34:11 +0000328
329/**
330 * This structure describes the invite session.
Benny Prijono40d62b62009-08-12 17:53:47 +0000331 *
332 * Note regarding the invite session's pools. The inv_sess used to have
333 * only one pool, which is just a pointer to the dialog's pool. Ticket
334 * http://trac.pjsip.org/repos/ticket/877 has found that the memory
335 * usage will grow considerably everytime re-INVITE or UPDATE is
336 * performed.
337 *
338 * Ticket #877 then created two more memory pools for the inv_sess, so
339 * now we have three memory pools:
340 * - pool: to be used to allocate long term data for the session
341 * - pool_prov and pool_active: this is a flip-flop pools to be used
342 * interchangably during re-INVITE and UPDATE. pool_prov is
343 * "provisional" pool, used to allocate SDP offer or answer for
344 * the re-INVITE and UPDATE. Once SDP negotiation is done, the
345 * provisional pool will be made as the active pool, then the
346 * existing active pool will be reset, to release the memory
347 * back to the OS. So these pool's lifetime is synchronized to
348 * the SDP offer-answer negotiation.
349 *
350 * Higher level application such as PJSUA-LIB has been modified to
351 * make use of these flip-flop pools, i.e. by creating media objects
352 * from the provisional pool rather than from the long term pool.
353 *
354 * Other applications that want to use these pools must understand
355 * that the flip-flop pool's lifetimes are synchronized to the
356 * SDP offer-answer negotiation.
Benny Prijono268ca612006-02-07 12:34:11 +0000357 */
358struct pjsip_inv_session
359{
Benny Prijono0b6340c2006-06-13 22:21:23 +0000360 char obj_name[PJ_MAX_OBJ_NAME]; /**< Log identification */
Benny Prijono40d62b62009-08-12 17:53:47 +0000361 pj_pool_t *pool; /**< Long term pool. */
362 pj_pool_t *pool_prov; /**< Provisional pool */
363 pj_pool_t *pool_active; /**< Active/current pool*/
Benny Prijonoe4f2abb2006-02-10 14:04:05 +0000364 pjsip_inv_state state; /**< Invite sess state. */
Benny Prijono1dc8be02007-05-30 04:26:40 +0000365 pj_bool_t cancelling; /**< CANCEL requested */
366 pj_bool_t pending_cancel; /**< Wait to send CANCEL*/
Benny Prijonod4e0abd2006-03-05 11:53:36 +0000367 pjsip_status_code cause; /**< Disconnect cause. */
Benny Prijono0b6340c2006-06-13 22:21:23 +0000368 pj_str_t cause_text; /**< Cause text. */
Benny Prijonod4e0abd2006-03-05 11:53:36 +0000369 pj_bool_t notify; /**< Internal. */
Benny Prijonoe4f2abb2006-02-10 14:04:05 +0000370 pjsip_dialog *dlg; /**< Underlying dialog. */
371 pjsip_role_e role; /**< Invite role. */
372 unsigned options; /**< Options in use. */
373 pjmedia_sdp_neg *neg; /**< Negotiator. */
374 pjsip_transaction *invite_tsx; /**< 1st invite tsx. */
Benny Prijono5e51a4e2008-11-27 00:06:46 +0000375 pjsip_tx_data *invite_req; /**< Saved invite req */
Benny Prijonodcfc0ba2007-09-30 16:50:27 +0000376 pjsip_tx_data *last_answer; /**< Last INVITE resp. */
Benny Prijono1f7767b2007-10-03 18:28:49 +0000377 pjsip_tx_data *last_ack; /**< Last ACK request */
378 pj_int32_t last_ack_cseq; /**< CSeq of last ACK */
Benny Prijonoe4f2abb2006-02-10 14:04:05 +0000379 void *mod_data[PJSIP_MAX_MODULE];/**< Modules data. */
Nanang Izzuddin59dffb12009-08-11 12:42:38 +0000380 struct pjsip_timer *timer; /**< Session Timers. */
Benny Prijono268ca612006-02-07 12:34:11 +0000381};
382
383
384/**
Benny Prijono1c1d7342010-08-01 09:48:51 +0000385 * This structure represents SDP information in a pjsip_rx_data. Application
386 * retrieve this information by calling #pjsip_rdata_get_sdp_info(). This
387 * mechanism supports multipart message body.
388 */
389typedef struct pjsip_rdata_sdp_info
390{
391 /**
392 * Pointer and length of the text body in the incoming message. If
393 * the pointer is NULL, it means the message does not contain SDP
394 * body.
395 */
396 pj_str_t body;
397
398 /**
399 * This will contain non-zero if an invalid SDP body is found in the
400 * message.
401 */
402 pj_status_t sdp_err;
403
404 /**
405 * A parsed and validated SDP body.
406 */
407 pjmedia_sdp_session *sdp;
408
409} pjsip_rdata_sdp_info;
410
411
412/**
Benny Prijono268ca612006-02-07 12:34:11 +0000413 * Initialize the invite usage module and register it to the endpoint.
414 * The callback argument contains pointer to functions to be called on
415 * occurences of events in invite sessions.
416 *
417 * @param endpt The endpoint instance.
Benny Prijono312aff92006-06-17 04:08:30 +0000418 * @param cb Callback structure.
Benny Prijono268ca612006-02-07 12:34:11 +0000419 *
420 * @return PJ_SUCCESS on success, or the appropriate error code.
421 */
422PJ_DECL(pj_status_t) pjsip_inv_usage_init(pjsip_endpoint *endpt,
Benny Prijono268ca612006-02-07 12:34:11 +0000423 const pjsip_inv_callback *cb);
424
425/**
426 * Get the INVITE usage module instance.
427 *
428 * @return PJ_SUCCESS on success, or the appropriate error code.
429 */
430PJ_DECL(pjsip_module*) pjsip_inv_usage_instance(void);
431
432
Benny Prijono632ce712006-02-09 14:01:40 +0000433/**
434 * Dump user agent contents (e.g. all dialogs).
435 */
436PJ_DECL(void) pjsip_inv_usage_dump(void);
437
Benny Prijono268ca612006-02-07 12:34:11 +0000438
439/**
440 * Create UAC invite session for the specified dialog in dlg.
441 *
442 * @param dlg The dialog which will be used by this invite session.
443 * @param local_sdp If application has determined its media capability,
444 * it can specify the SDP here. Otherwise it can leave
445 * this to NULL, to let remote UAS specifies an offer.
446 * @param options The options argument is bitmask combination of SIP
447 * features in pjsip_inv_options enumeration.
448 * @param p_inv On successful return, the invite session will be put
449 * in this argument.
450 *
451 * @return The function will return PJ_SUCCESS if it can create
452 * the session. Otherwise the appropriate error status
453 * will be returned on failure.
454 */
455PJ_DECL(pj_status_t) pjsip_inv_create_uac(pjsip_dialog *dlg,
456 const pjmedia_sdp_session *local_sdp,
457 unsigned options,
458 pjsip_inv_session **p_inv);
459
460
461/**
462 * Application SHOULD call this function upon receiving the initial INVITE
463 * request in rdata before creating the invite session (or even dialog),
464 * to verify that the invite session can handle the INVITE request.
465 * This function verifies that local endpoint is capable to handle required
466 * SIP extensions in the request (i.e. Require header) and also the media,
467 * if media description is present in the request.
468 *
469 * @param rdata The incoming INVITE request.
470 *
471 * @param options Upon calling this function, the options argument
472 * MUST contain the desired SIP extensions to be
473 * applied to the session. Upon return, this argument
474 * will contain the SIP extension that will be applied
475 * to the session, after considering the Supported,
476 * Require, and Allow headers in the request.
477 *
478 * @param sdp If local media capability has been determined,
479 * and if application wishes to verify that it can
480 * handle the media offer in the incoming INVITE
481 * request, it SHOULD specify its local media capability
482 * in this argument.
483 * If it is not specified, media verification will not
484 * be performed by this function.
485 *
486 * @param dlg If tdata is not NULL, application needs to specify
487 * how to create the response. Either dlg or endpt
488 * argument MUST be specified, with dlg argument takes
489 * precedence when both are specified.
490 *
491 * If a dialog has been created prior to calling this
492 * function, then it MUST be specified in dlg argument.
493 * Otherwise application MUST specify the endpt argument
494 * (this is useful e.g. when application wants to send
495 * the response statelessly).
496 *
497 * @param endpt If tdata is not NULL, application needs to specify
498 * how to create the response. Either dlg or endpt
499 * argument MUST be specified, with dlg argument takes
500 * precedence when both are specified.
501 *
502 * @param tdata If this argument is not NULL, this function will
503 * create the appropriate non-2xx final response message
504 * when the verification fails.
505 *
506 * @return If everything has been negotiated successfully,
507 * the function will return PJ_SUCCESS. Otherwise it
508 * will return the reason of the failure as the return
509 * code.
510 *
511 * This function is capable to create the appropriate
512 * response message when the verification has failed.
513 * If tdata is specified, then a non-2xx final response
514 * will be created and put in this argument upon return,
515 * when the verification has failed.
516 *
517 * If a dialog has been created prior to calling this
518 * function, then it MUST be specified in dlg argument.
519 * Otherwise application MUST specify the endpt argument
520 * (this is useful e.g. when application wants to send
521 * the response statelessly).
Benny Prijono87a90212008-01-23 20:29:30 +0000522 *
523 * @see pjsip_inv_verify_request2()
Benny Prijono268ca612006-02-07 12:34:11 +0000524 */
525PJ_DECL(pj_status_t) pjsip_inv_verify_request( pjsip_rx_data *rdata,
526 unsigned *options,
527 const pjmedia_sdp_session *sdp,
528 pjsip_dialog *dlg,
529 pjsip_endpoint *endpt,
530 pjsip_tx_data **tdata);
531
Benny Prijono87a90212008-01-23 20:29:30 +0000532/**
533 * Variant of #pjsip_inv_verify_request() which allows application to specify
534 * the parsed SDP in the \a offer argument. This is useful to avoid having to
535 * re-parse the SDP in the incoming request.
536 *
537 * @see pjsip_inv_verify_request()
538 */
539PJ_DECL(pj_status_t) pjsip_inv_verify_request2( pjsip_rx_data *rdata,
540 unsigned *options,
541 const pjmedia_sdp_session *offer,
542 const pjmedia_sdp_session *answer,
543 pjsip_dialog *dlg,
544 pjsip_endpoint *endpt,
545 pjsip_tx_data **tdata);
Benny Prijono268ca612006-02-07 12:34:11 +0000546
547/**
548 * Create UAS invite session for the specified dialog in dlg. Application
549 * SHOULD call the verification function before calling this function,
550 * to ensure that it can create the session successfully.
551 *
552 * @param dlg The dialog to be used.
553 * @param rdata Application MUST specify the received INVITE request
554 * in rdata. The invite session needs to inspect the
555 * received request to see if the request contains
556 * features that it supports.
Benny Prijono312aff92006-06-17 04:08:30 +0000557 * @param local_sdp If application has determined its media capability,
Benny Prijono268ca612006-02-07 12:34:11 +0000558 * it can specify this capability in this argument.
559 * If SDP is received in the initial INVITE, the UAS
560 * capability specified in this argument doesn't have to
561 * match the received offer; the SDP negotiator is able
562 * to rearrange the media lines in the answer so that it
563 * matches the offer.
564 * @param options The options argument is bitmask combination of SIP
565 * features in pjsip_inv_options enumeration.
566 * @param p_inv Pointer to receive the newly created invite session.
567 *
568 * @return On successful, the invite session will be put in
569 * p_inv argument and the function will return PJ_SUCCESS.
570 * Otherwise the appropriate error status will be returned
571 * on failure.
572 */
573PJ_DECL(pj_status_t) pjsip_inv_create_uas(pjsip_dialog *dlg,
574 pjsip_rx_data *rdata,
575 const pjmedia_sdp_session *local_sdp,
576 unsigned options,
577 pjsip_inv_session **p_inv);
578
579
580/**
Benny Prijonod4e0abd2006-03-05 11:53:36 +0000581 * Forcefully terminate and destroy INVITE session, regardless of
582 * the state of the session. Note that this function should only be used
583 * when there is failure in the INVITE session creation. After the
584 * invite session has been created and initialized, normally application
585 * SHOULD use #pjsip_inv_end_session() to end the INVITE session instead.
586 *
587 * Note also that this function may terminate the underlying dialog, if
588 * there are no other sessions in the dialog.
589 *
590 * @param inv The invite session.
591 * @param st_code Status code for the reason of the termination.
592 * @param notify If set to non-zero, then on_state_changed()
593 * callback will be called.
594 *
595 * @return PJ_SUCCESS if the INVITE session has been
596 * terminated.
597 */
598PJ_DECL(pj_status_t) pjsip_inv_terminate( pjsip_inv_session *inv,
599 int st_code,
600 pj_bool_t notify );
601
602
603/**
Benny Prijono5e51a4e2008-11-27 00:06:46 +0000604 * Restart UAC session and prepare the session for a new initial INVITE.
605 * This function can be called for example when the application wants to
606 * follow redirection response with a new call reusing this session so
607 * that the new call will have the same Call-ID and From headers. After
608 * the session is restarted, application may create and send a new INVITE
609 * request.
610 *
611 * @param inv The invite session.
612 * @param new_offer Should be set to PJ_TRUE since the application will
613 * restart the session.
614 *
615 * @return PJ_SUCCESS on successful operation.
616 */
617PJ_DECL(pj_status_t) pjsip_inv_uac_restart(pjsip_inv_session *inv,
618 pj_bool_t new_offer);
619
620
621/**
622 * Accept or reject redirection response. Application MUST call this function
623 * after it signaled PJSIP_REDIRECT_PENDING in the \a on_redirected()
624 * callback, to notify the invite session whether to accept or reject the
625 * redirection to the current target. Application can use the combination of
626 * PJSIP_REDIRECT_PENDING command in \a on_redirected() callback and this
627 * function to ask for user permission before redirecting the call.
628 *
629 * Note that if the application chooses to reject or stop redirection (by
630 * using PJSIP_REDIRECT_REJECT or PJSIP_REDIRECT_STOP respectively), the
631 * session disconnection callback will be called before this function returns.
632 * And if the application rejects the target, the \a on_redirected() callback
633 * may also be called before this function returns if there is another target
634 * to try.
635 *
636 * @param inv The invite session.
637 * @param cmd Redirection operation. The semantic of this argument
638 * is similar to the description in the \a on_redirected()
639 * callback, except that the PJSIP_REDIRECT_PENDING is
640 * not accepted here.
641 * @param e Should be set to NULL.
642 *
643 * @return PJ_SUCCESS on successful operation.
644 */
645PJ_DECL(pj_status_t) pjsip_inv_process_redirect(pjsip_inv_session *inv,
646 pjsip_redirect_op cmd,
647 pjsip_event *e);
648
649
650/**
Benny Prijono268ca612006-02-07 12:34:11 +0000651 * Create the initial INVITE request for this session. This function can only
652 * be called for UAC session. If local media capability is specified when
653 * the invite session was created, then this function will put an SDP offer
654 * in the outgoing INVITE request. Otherwise the outgoing request will not
655 * contain SDP body.
656 *
657 * @param inv The UAC invite session.
658 * @param p_tdata The initial INVITE request will be put in this
659 * argument if it can be created successfully.
660 *
661 * @return PJ_SUCCESS if the INVITE request can be created.
662 */
663PJ_DECL(pj_status_t) pjsip_inv_invite( pjsip_inv_session *inv,
664 pjsip_tx_data **p_tdata );
665
666
667/**
Benny Prijono64f851e2006-02-23 13:49:28 +0000668 * Create the initial response message for the incoming INVITE request in
669 * rdata with status code st_code and optional status text st_text. Use
Benny Prijonoa7b376b2008-01-25 16:06:33 +0000670 * #pjsip_inv_answer() to create subsequent response message.
Benny Prijono64f851e2006-02-23 13:49:28 +0000671 */
672PJ_DECL(pj_status_t) pjsip_inv_initial_answer( pjsip_inv_session *inv,
673 pjsip_rx_data *rdata,
674 int st_code,
675 const pj_str_t *st_text,
676 const pjmedia_sdp_session *sdp,
677 pjsip_tx_data **p_tdata);
678
679/**
Benny Prijono268ca612006-02-07 12:34:11 +0000680 * Create a response message to the initial INVITE request. This function
681 * can only be called for the initial INVITE request, as subsequent
682 * re-INVITE request will be answered automatically.
683 *
684 * @param inv The UAS invite session.
685 * @param st_code The st_code contains the status code to be sent,
686 * which may be a provisional or final response.
687 * @param st_text If custom status text is desired, application can
688 * specify the text in st_text; otherwise if this
689 * argument is NULL, default status text will be used.
690 * @param local_sdp If application has specified its media capability
691 * during creation of UAS invite session, the local_sdp
692 * argument MUST be NULL. This is because application
693 * can not perform more than one SDP offer/answer session
694 * in a single INVITE transaction.
695 * If application has not specified its media capability
696 * during creation of UAS invite session, it MAY or MUST
697 * specify its capability in local_sdp argument,
698 * depending whether st_code indicates a 2xx final
699 * response.
700 * @param p_tdata Pointer to receive the response message created by
701 * this function.
702 *
703 * @return PJ_SUCCESS if response message was created
704 * successfully.
705 */
706PJ_DECL(pj_status_t) pjsip_inv_answer( pjsip_inv_session *inv,
707 int st_code,
708 const pj_str_t *st_text,
709 const pjmedia_sdp_session *local_sdp,
710 pjsip_tx_data **p_tdata );
711
712
Benny Prijonoa66c7152006-02-09 01:26:14 +0000713/**
Benny Prijono26ff9062006-02-21 23:47:00 +0000714 * Set local answer to respond to remote SDP offer, to be carried by
715 * subsequent response (or request).
Benny Prijonoa66c7152006-02-09 01:26:14 +0000716 *
717 * @param inv The invite session.
718 * @param sdp The SDP description which will be set as answer
719 * to remote.
Benny Prijono26ff9062006-02-21 23:47:00 +0000720 *
721 * @return PJ_SUCCESS if local answer can be accepted by
722 * SDP negotiator.
Benny Prijonoa66c7152006-02-09 01:26:14 +0000723 */
Benny Prijono26ff9062006-02-21 23:47:00 +0000724PJ_DECL(pj_status_t) pjsip_inv_set_sdp_answer(pjsip_inv_session *inv,
725 const pjmedia_sdp_session *sdp );
726
Benny Prijonoa66c7152006-02-09 01:26:14 +0000727
Benny Prijono268ca612006-02-07 12:34:11 +0000728/**
729 * Create a SIP message to initiate invite session termination. Depending on
730 * the state of the session, this function may return CANCEL request,
Benny Prijono006a4e82009-04-26 11:30:22 +0000731 * a non-2xx final response, a BYE request, or even no request.
732 *
733 * For UAS, if the session has not answered the incoming INVITE, this function
734 * creates the non-2xx final response with the specified status code in
735 * \a st_code and optional status text in \a st_text.
736 *
737 * For UAC, if the original INVITE has not been answered with a final
738 * response, the behavior depends on whether provisional response has been
739 * received. If provisional response has been received, this function will
740 * create CANCEL request. If no provisional response has been received, the
741 * function will not create CANCEL request (the function will return
742 * PJ_SUCCESS but the \a p_tdata will contain NULL) because we cannot send
743 * CANCEL before receiving provisional response. If then a provisional
744 * response is received, the invite session will send CANCEL automatically.
745 *
746 * For both UAC and UAS, if the INVITE session has been answered with final
747 * response, a BYE request will be created.
Benny Prijono268ca612006-02-07 12:34:11 +0000748 *
749 * @param inv The invite session.
750 * @param st_code Status code to be used for terminating the session.
751 * @param st_text Optional status text.
Benny Prijono006a4e82009-04-26 11:30:22 +0000752 * @param p_tdata Pointer to receive the message to be created. Note
753 * that it's possible to receive NULL here while the
754 * function returns PJ_SUCCESS, see the description.
Benny Prijono268ca612006-02-07 12:34:11 +0000755 *
Benny Prijono006a4e82009-04-26 11:30:22 +0000756 * @return PJ_SUCCESS if termination is initiated.
Benny Prijono268ca612006-02-07 12:34:11 +0000757 */
758PJ_DECL(pj_status_t) pjsip_inv_end_session( pjsip_inv_session *inv,
759 int st_code,
760 const pj_str_t *st_text,
761 pjsip_tx_data **p_tdata );
762
763
764
765/**
766 * Create a re-INVITE request.
767 *
768 * @param inv The invite session.
769 * @param new_contact If application wants to update its local contact and
770 * inform peer to perform target refresh with a new
771 * contact, it can specify the new contact in this
772 * argument; otherwise this argument must be NULL.
773 * @param new_offer Application MAY initiate a new SDP offer/answer
774 * session in the request when there is no pending
775 * answer to be sent or received. It can detect this
776 * condition by observing the state of the SDP
777 * negotiator of the invite session. If new offer
778 * should be sent to remote, the offer must be specified
779 * in this argument, otherwise it must be NULL.
780 * @param p_tdata Pointer to receive the re-INVITE request message to
781 * be created.
782 *
783 * @return PJ_SUCCESS if a re-INVITE request with the specified
784 * characteristics (e.g. to contain new offer) can be
785 * created.
786 */
787PJ_DECL(pj_status_t) pjsip_inv_reinvite(pjsip_inv_session *inv,
788 const pj_str_t *new_contact,
789 const pjmedia_sdp_session *new_offer,
790 pjsip_tx_data **p_tdata );
791
792
793
794/**
Benny Prijono1f7767b2007-10-03 18:28:49 +0000795 * Create an UPDATE request to initiate new SDP offer.
Benny Prijono268ca612006-02-07 12:34:11 +0000796 *
797 * @param inv The invite session.
798 * @param new_contact If application wants to update its local contact
799 * and inform peer to perform target refresh with a new
800 * contact, it can specify the new contact in this
801 * argument; otherwise this argument must be NULL.
Benny Prijono1f7767b2007-10-03 18:28:49 +0000802 * @param offer Offer to be sent to remote. This argument is
803 * mandatory.
Benny Prijono268ca612006-02-07 12:34:11 +0000804 * @param p_tdata Pointer to receive the UPDATE request message to
805 * be created.
806 *
807 * @return PJ_SUCCESS if a UPDATE request with the specified
808 * characteristics (e.g. to contain new offer) can be
809 * created.
810 */
811PJ_DECL(pj_status_t) pjsip_inv_update ( pjsip_inv_session *inv,
812 const pj_str_t *new_contact,
Benny Prijono1f7767b2007-10-03 18:28:49 +0000813 const pjmedia_sdp_session *offer,
Benny Prijono268ca612006-02-07 12:34:11 +0000814 pjsip_tx_data **p_tdata );
815
816
817/**
Benny Prijonod5f9f422007-11-25 04:40:07 +0000818 * Create an ACK request. Normally ACK request transmission is handled
819 * by the framework. Application only needs to use this function if it
820 * handles the ACK transmission manually, by overriding \a on_send_ack()
821 * callback in #pjsip_inv_callback.
822 *
823 * Note that if the invite session has a pending offer to be answered
824 * (for example when the last 2xx response to INVITE contains an offer),
825 * application MUST have set the SDP answer with #pjsip_create_sdp_body()
826 * prior to creating the ACK request. In this case, the ACK request
827 * will be added with SDP message body.
828 *
829 * @param inv The invite session.
830 * @param cseq Mandatory argument to specify the CSeq of the
831 * ACK request. This value MUST match the value
832 * of the INVITE transaction to be acknowledged.
833 * @param p_tdata Pointer to receive the ACK request message to
834 * be created.
835 *
836 * @return PJ_SUCCESS if ACK request has been created.
837 */
838PJ_DECL(pj_status_t) pjsip_inv_create_ack(pjsip_inv_session *inv,
839 int cseq,
840 pjsip_tx_data **p_tdata);
841
842
843/**
Benny Prijono268ca612006-02-07 12:34:11 +0000844 * Send request or response message in tdata.
845 *
846 * @param inv The invite session.
847 * @param tdata The message to be sent.
Benny Prijono268ca612006-02-07 12:34:11 +0000848 *
849 * @return PJ_SUCCESS if transaction can be initiated
850 * successfully to send this message. Note that the
851 * actual final state of the transaction itself will
852 * be reported later, in on_tsx_state_changed()
853 * callback.
854 */
855PJ_DECL(pj_status_t) pjsip_inv_send_msg(pjsip_inv_session *inv,
Benny Prijonoe8b0d3b2006-03-17 17:57:52 +0000856 pjsip_tx_data *tdata);
Benny Prijono268ca612006-02-07 12:34:11 +0000857
858
Benny Prijono268ca612006-02-07 12:34:11 +0000859/**
860 * Get the invite session for the dialog, if any.
861 *
862 * @param dlg The dialog which invite session is being queried.
863 *
864 * @return The invite session instance which has been
865 * associated with this dialog, or NULL.
866 */
867PJ_DECL(pjsip_inv_session*) pjsip_dlg_get_inv_session(pjsip_dialog *dlg);
868
869/**
870 * Get the invite session instance associated with transaction tsx, if any.
871 *
872 * @param tsx The transaction, which invite session is being
873 * queried.
874 *
875 * @return The invite session instance which has been
876 * associated with this transaction, or NULL.
877 */
878PJ_DECL(pjsip_inv_session*) pjsip_tsx_get_inv_session(pjsip_transaction *tsx);
879
880
Benny Prijonoe8b0d3b2006-03-17 17:57:52 +0000881/**
882 * Get state names for INVITE session state.
883 *
884 * @param state The invite state.
885 *
886 * @return String describing the state.
887 */
888PJ_DECL(const char *) pjsip_inv_state_name(pjsip_inv_state state);
889
Benny Prijono268ca612006-02-07 12:34:11 +0000890
Benny Prijono56315612006-07-18 14:39:40 +0000891/**
892 * This is a utility function to create SIP body for SDP content.
893 *
894 * @param pool Pool to allocate memory.
895 * @param sdp SDP session to be put in the SIP message body.
896 * @param p_body Pointer to receive SIP message body containing
897 * the SDP session.
898 *
899 * @return PJ_SUCCESS on success.
900 */
901PJ_DECL(pj_status_t) pjsip_create_sdp_body(pj_pool_t *pool,
902 pjmedia_sdp_session *sdp,
903 pjsip_msg_body **p_body);
904
Benny Prijono1c1d7342010-08-01 09:48:51 +0000905/**
906 * Retrieve SDP information from an incoming message. Application should
907 * prefer to use this function rather than parsing the SDP manually since
908 * this function supports multipart message body.
909 *
910 * This function will only parse the SDP once, the first time it is called
911 * on the same message. Subsequent call on the same message will just pick
912 * up the already parsed SDP from the message.
913 *
914 * @param rdata The incoming message.
915 *
916 * @return The SDP info.
917 */
918PJ_DECL(pjsip_rdata_sdp_info*) pjsip_rdata_get_sdp_info(pjsip_rx_data *rdata);
919
Benny Prijono56315612006-07-18 14:39:40 +0000920
Benny Prijonof3195072006-02-14 21:15:30 +0000921PJ_END_DECL
922
Benny Prijono312aff92006-06-17 04:08:30 +0000923/**
924 * @}
925 */
Benny Prijono268ca612006-02-07 12:34:11 +0000926
927
928#endif /* __SIP_INVITE_SESSION_H__ */