blob: 5782cf92b61bbd64fbaecaa534b1e7270dce07be [file] [log] [blame]
Alexandre Lision94f06ba2013-12-09 16:28:33 -05001/* $Id$ */
Tristan Matthews0a329cc2013-07-17 13:20:14 -04002/*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5 *
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
23/**
24 * @file sip_inv.h
25 * @brief INVITE sessions
26 */
27
28
29#include <pjsip/sip_dialog.h>
30#include <pjmedia/sdp_neg.h>
31
32
33/**
34 * @defgroup PJSIP_HIGH_UA User Agent Library
35 * @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
76PJ_BEGIN_DECL
77
78
79/**
80 * @see pjsip_inv_session
81 */
82typedef struct pjsip_inv_session pjsip_inv_session;
83
84
85/**
86 * This enumeration describes invite session state.
87 */
88typedef enum pjsip_inv_state
89{
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. */
97} pjsip_inv_state;
98
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 */
104typedef struct pjsip_inv_callback
105{
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
119 /**
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,
135 * e.g. to monitor the progress of an outgoing request, or to send
136 * response to unhandled incoming request (such as INFO).
137 *
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
152 * 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.
156 *
157 * @param inv The invite session.
158 * @param offer Remote offer.
159 */
160 void (*on_rx_offer)(pjsip_inv_session *inv,
161 const pjmedia_sdp_session *offer);
162
163 /**
164 * This callback is optional, and is called when the invite session has
165 * received a re-INVITE from the peer. It will be called after
166 * on_rx_offer() callback and works only for re-INVITEs. It allows more
167 * fine-grained control over the response to a re-INVITE, e.g. sending
168 * a provisional response first. Application can return PJ_SUCCESS and
169 * send a reply using the function #pjsip_inv_initial_answer() or
170 * #pjsip_inv_answer(), as with the initial INVITE. If application
171 * returns non-PJ_SUCCESS, it needs to set the SDP answer with
172 * #pjsip_inv_set_sdp_answer() and the re-INVITE will be answered
173 * automatically.
174 *
Alexandre Lision94f06ba2013-12-09 16:28:33 -0500175 * Remarks: Application may need to monitor on_tsx_state_changed()
176 * callback to check whether the re-INVITE is already answered
177 * automatically with 487 due to being cancelled.
178 *
Tristan Matthews0a329cc2013-07-17 13:20:14 -0400179 * @param inv The invite session.
180 * @param offer Remote offer.
181 * @param rdata The received re-INVITE request.
182 *
183 * @return - PJ_SUCCESS: application will answer the re-INVITE
184 * manually
185 * - non-PJ_SUCCESS: answer the re-INVITE automatically
186 * using the SDP set via #pjsip_inv_set_sdp_answer()
187 */
188 pj_status_t (*on_rx_reinvite)(pjsip_inv_session *inv,
189 const pjmedia_sdp_session *offer,
190 pjsip_rx_data *rdata);
191
192 /**
193 * This callback is optional, and it is used to ask the application
194 * to create a fresh offer, when the invite session has received
195 * re-INVITE without offer. This offer then will be sent in the
196 * 200/OK response to the re-INVITE request.
197 *
198 * If application doesn't implement this callback, the invite session
199 * will send the currently active SDP as the offer.
200 *
201 * @param inv The invite session.
202 * @param p_offer Pointer to receive the SDP offer created by
203 * application.
204 */
205 void (*on_create_offer)(pjsip_inv_session *inv,
206 pjmedia_sdp_session **p_offer);
207
208 /**
209 * This callback is called after SDP offer/answer session has completed.
210 * The status argument specifies the status of the offer/answer,
211 * as returned by pjmedia_sdp_neg_negotiate().
212 *
213 * This callback is optional (from the point of view of the framework),
214 * but all useful applications normally need to implement this callback.
215 *
216 * @param inv The invite session.
217 * @param status The negotiation status.
218 */
219 void (*on_media_update)(pjsip_inv_session *inv_ses,
220 pj_status_t status);
221
222 /**
223 * This callback is called when the framework needs to send
224 * ACK request after it receives incoming 2xx response for
225 * INVITE. It allows application to manually handle the
226 * transmission of ACK request, which is required by some 3PCC
227 * scenarios. If this callback is not implemented, the framework
228 * will handle the ACK transmission automatically.
229 *
230 * When this callback is overridden, application may delay the
231 * sending of the ACK request (for example, when it needs to
232 * wait for answer from the other call leg, in 3PCC scenarios).
233 *
234 * Application creates the ACK request
235 *
236 * Once it has sent the ACK request, the framework will keep
237 * this ACK request in the cache. Subsequent receipt of 2xx response
238 * will not cause this callback to be called, and instead automatic
239 * retransmission of this ACK request from the cache will be done
240 * by the framework.
241 *
242 * This callback is optional.
243 */
244 void (*on_send_ack)(pjsip_inv_session *inv, pjsip_rx_data *rdata);
245
246 /**
247 * This callback is called when the session is about to resend the
248 * INVITE request to the specified target, following the previously
249 * received redirection response.
250 *
251 * Application may accept the redirection to the specified target
252 * (the default behavior if this callback is implemented), reject
253 * this target only and make the session continue to try the next
254 * target in the list if such target exists, stop the whole
255 * redirection process altogether and cause the session to be
256 * disconnected, or defer the decision to ask for user confirmation.
257 *
258 * This callback is optional. If this callback is not implemented,
259 * the default behavior is to NOT follow the redirection response.
260 *
261 * @param inv The invite session.
262 * @param target The current target to be tried.
263 * @param e The event that caused this callback to be called.
264 * This could be the receipt of 3xx response, or
265 * 4xx/5xx response received for the INVITE sent to
266 * subsequent targets, or NULL if this callback is
267 * called from within #pjsip_inv_process_redirect()
268 * context.
269 *
270 * @return Action to be performed for the target. Set this
271 * parameter to one of the value below:
272 * - PJSIP_REDIRECT_ACCEPT: immediately accept the
273 * redirection to this target. When set, the
274 * session will immediately resend INVITE request
275 * to the target after this callback returns.
276 * - PJSIP_REDIRECT_REJECT: immediately reject this
277 * target. The session will continue retrying with
278 * next target if present, or disconnect the call
279 * if there is no more target to try.
280 * - PJSIP_REDIRECT_STOP: stop the whole redirection
281 * process and immediately disconnect the call. The
282 * on_state_changed() callback will be called with
283 * PJSIP_INV_STATE_DISCONNECTED state immediately
284 * after this callback returns.
285 * - PJSIP_REDIRECT_PENDING: set to this value if
286 * no decision can be made immediately (for example
287 * to request confirmation from user). Application
288 * then MUST call #pjsip_inv_process_redirect()
289 * to either accept or reject the redirection upon
290 * getting user decision.
291 */
292 pjsip_redirect_op (*on_redirected)(pjsip_inv_session *inv,
293 const pjsip_uri *target,
294 const pjsip_event *e);
295
296} pjsip_inv_callback;
297
298
299
300/**
301 * This enumeration shows various options that can be applied to a session.
302 * The bitmask combination of these options need to be specified when
303 * creating a session. After the dialog is established (including early),
304 * the options member of #pjsip_inv_session shows which capabilities are
305 * common in both endpoints.
306 */
307enum pjsip_inv_option
308{
309 /**
310 * Indicate support for reliable provisional response extension
311 */
312 PJSIP_INV_SUPPORT_100REL = 1,
313
314 /**
315 * Indicate support for session timer extension.
316 */
317 PJSIP_INV_SUPPORT_TIMER = 2,
318
319 /**
320 * Indicate support for UPDATE method. This is automatically implied
321 * when creating outgoing dialog. After the dialog is established,
322 * the options member of #pjsip_inv_session shows whether peer supports
323 * this method as well.
324 */
325 PJSIP_INV_SUPPORT_UPDATE = 4,
326
327 /**
328 * Indicate support for ICE
329 */
330 PJSIP_INV_SUPPORT_ICE = 8,
331
332 /**
333 * Require ICE support.
334 */
335 PJSIP_INV_REQUIRE_ICE = 16,
336
337 /**
338 * Require reliable provisional response extension.
339 */
340 PJSIP_INV_REQUIRE_100REL = 32,
341
342 /**
343 * Require session timer extension.
344 */
345 PJSIP_INV_REQUIRE_TIMER = 64,
346
347 /**
348 * Session timer extension will always be used even when peer doesn't
349 * support/want session timer.
350 */
351 PJSIP_INV_ALWAYS_USE_TIMER = 128
352
353};
354
355/* Forward declaration of Session Timers */
356struct pjsip_timer;
357
358/**
359 * This structure describes the invite session.
360 *
361 * Note regarding the invite session's pools. The inv_sess used to have
362 * only one pool, which is just a pointer to the dialog's pool. Ticket
363 * http://trac.pjsip.org/repos/ticket/877 has found that the memory
364 * usage will grow considerably everytime re-INVITE or UPDATE is
365 * performed.
366 *
367 * Ticket #877 then created two more memory pools for the inv_sess, so
368 * now we have three memory pools:
369 * - pool: to be used to allocate long term data for the session
370 * - pool_prov and pool_active: this is a flip-flop pools to be used
371 * interchangably during re-INVITE and UPDATE. pool_prov is
372 * "provisional" pool, used to allocate SDP offer or answer for
373 * the re-INVITE and UPDATE. Once SDP negotiation is done, the
374 * provisional pool will be made as the active pool, then the
375 * existing active pool will be reset, to release the memory
376 * back to the OS. So these pool's lifetime is synchronized to
377 * the SDP offer-answer negotiation.
378 *
379 * Higher level application such as PJSUA-LIB has been modified to
380 * make use of these flip-flop pools, i.e. by creating media objects
381 * from the provisional pool rather than from the long term pool.
382 *
383 * Other applications that want to use these pools must understand
384 * that the flip-flop pool's lifetimes are synchronized to the
385 * SDP offer-answer negotiation.
386 */
387struct pjsip_inv_session
388{
389 char obj_name[PJ_MAX_OBJ_NAME]; /**< Log identification */
390 pj_pool_t *pool; /**< Long term pool. */
391 pj_pool_t *pool_prov; /**< Provisional pool */
392 pj_pool_t *pool_active; /**< Active/current pool*/
393 pjsip_inv_state state; /**< Invite sess state. */
394 pj_bool_t cancelling; /**< CANCEL requested */
395 pj_bool_t pending_cancel; /**< Wait to send CANCEL*/
396 pjsip_status_code cause; /**< Disconnect cause. */
397 pj_str_t cause_text; /**< Cause text. */
398 pj_bool_t notify; /**< Internal. */
399 unsigned cb_called; /**< Cb has been called */
400 pjsip_dialog *dlg; /**< Underlying dialog. */
401 pjsip_role_e role; /**< Invite role. */
402 unsigned options; /**< Options in use. */
403 pjmedia_sdp_neg *neg; /**< Negotiator. */
404 unsigned sdp_neg_flags; /**< SDP neg flags. */
405 pjsip_transaction *invite_tsx; /**< 1st invite tsx. */
406 pjsip_tx_data *invite_req; /**< Saved invite req */
407 pjsip_tx_data *last_answer; /**< Last INVITE resp. */
408 pjsip_tx_data *last_ack; /**< Last ACK request */
409 pj_int32_t last_ack_cseq; /**< CSeq of last ACK */
410 void *mod_data[PJSIP_MAX_MODULE];/**< Modules data. */
411 struct pjsip_timer *timer; /**< Session Timers. */
412};
413
414
415/**
416 * This structure represents SDP information in a pjsip_rx_data. Application
417 * retrieve this information by calling #pjsip_rdata_get_sdp_info(). This
418 * mechanism supports multipart message body.
419 */
420typedef struct pjsip_rdata_sdp_info
421{
422 /**
423 * Pointer and length of the text body in the incoming message. If
424 * the pointer is NULL, it means the message does not contain SDP
425 * body.
426 */
427 pj_str_t body;
428
429 /**
430 * This will contain non-zero if an invalid SDP body is found in the
431 * message.
432 */
433 pj_status_t sdp_err;
434
435 /**
436 * A parsed and validated SDP body.
437 */
438 pjmedia_sdp_session *sdp;
439
440} pjsip_rdata_sdp_info;
441
442
443/**
444 * Initialize the invite usage module and register it to the endpoint.
445 * The callback argument contains pointer to functions to be called on
446 * occurences of events in invite sessions.
447 *
448 * @param endpt The endpoint instance.
449 * @param cb Callback structure.
450 *
451 * @return PJ_SUCCESS on success, or the appropriate error code.
452 */
453PJ_DECL(pj_status_t) pjsip_inv_usage_init(pjsip_endpoint *endpt,
454 const pjsip_inv_callback *cb);
455
456/**
457 * Get the INVITE usage module instance.
458 *
459 * @return PJ_SUCCESS on success, or the appropriate error code.
460 */
461PJ_DECL(pjsip_module*) pjsip_inv_usage_instance(void);
462
463
464/**
465 * Dump user agent contents (e.g. all dialogs).
466 */
467PJ_DECL(void) pjsip_inv_usage_dump(void);
468
469
470/**
471 * Create UAC invite session for the specified dialog in dlg.
472 *
473 * @param dlg The dialog which will be used by this invite session.
474 * @param local_sdp If application has determined its media capability,
475 * it can specify the SDP here. Otherwise it can leave
476 * this to NULL, to let remote UAS specifies an offer.
477 * @param options The options argument is bitmask combination of SIP
478 * features in pjsip_inv_options enumeration.
479 * @param p_inv On successful return, the invite session will be put
480 * in this argument.
481 *
482 * @return The function will return PJ_SUCCESS if it can create
483 * the session. Otherwise the appropriate error status
484 * will be returned on failure.
485 */
486PJ_DECL(pj_status_t) pjsip_inv_create_uac(pjsip_dialog *dlg,
487 const pjmedia_sdp_session *local_sdp,
488 unsigned options,
489 pjsip_inv_session **p_inv);
490
491
492/**
493 * Application SHOULD call this function upon receiving the initial INVITE
494 * request in rdata before creating the invite session (or even dialog),
495 * to verify that the invite session can handle the INVITE request.
496 * This function verifies that local endpoint is capable to handle required
497 * SIP extensions in the request (i.e. Require header) and also the media,
498 * if media description is present in the request.
499 *
500 * @param rdata The incoming INVITE request.
501 *
502 * @param options Upon calling this function, the options argument
503 * MUST contain the desired SIP extensions to be
504 * applied to the session. Upon return, this argument
505 * will contain the SIP extension that will be applied
506 * to the session, after considering the Supported,
507 * Require, and Allow headers in the request.
508 *
509 * @param sdp If local media capability has been determined,
510 * and if application wishes to verify that it can
511 * handle the media offer in the incoming INVITE
512 * request, it SHOULD specify its local media capability
513 * in this argument.
514 * If it is not specified, media verification will not
515 * be performed by this function.
516 *
517 * @param dlg If tdata is not NULL, application needs to specify
518 * how to create the response. Either dlg or endpt
519 * argument MUST be specified, with dlg argument takes
520 * precedence when both are specified.
521 *
522 * If a dialog has been created prior to calling this
523 * function, then it MUST be specified in dlg argument.
524 * Otherwise application MUST specify the endpt argument
525 * (this is useful e.g. when application wants to send
526 * the response statelessly).
527 *
528 * @param endpt If tdata is not NULL, application needs to specify
529 * how to create the response. Either dlg or endpt
530 * argument MUST be specified, with dlg argument takes
531 * precedence when both are specified.
532 *
533 * @param tdata If this argument is not NULL, this function will
534 * create the appropriate non-2xx final response message
535 * when the verification fails.
536 *
537 * @return If everything has been negotiated successfully,
538 * the function will return PJ_SUCCESS. Otherwise it
539 * will return the reason of the failure as the return
540 * code.
541 *
542 * This function is capable to create the appropriate
543 * response message when the verification has failed.
544 * If tdata is specified, then a non-2xx final response
545 * will be created and put in this argument upon return,
546 * when the verification has failed.
547 *
548 * If a dialog has been created prior to calling this
549 * function, then it MUST be specified in dlg argument.
550 * Otherwise application MUST specify the endpt argument
551 * (this is useful e.g. when application wants to send
552 * the response statelessly).
553 *
554 * @see pjsip_inv_verify_request2()
555 */
556PJ_DECL(pj_status_t) pjsip_inv_verify_request( pjsip_rx_data *rdata,
557 unsigned *options,
558 const pjmedia_sdp_session *sdp,
559 pjsip_dialog *dlg,
560 pjsip_endpoint *endpt,
561 pjsip_tx_data **tdata);
562
563/**
564 * Variant of #pjsip_inv_verify_request() which allows application to specify
565 * the parsed SDP in the \a offer argument. This is useful to avoid having to
566 * re-parse the SDP in the incoming request.
567 *
568 * @see pjsip_inv_verify_request()
569 */
570PJ_DECL(pj_status_t) pjsip_inv_verify_request2( pjsip_rx_data *rdata,
571 unsigned *options,
572 const pjmedia_sdp_session *offer,
573 const pjmedia_sdp_session *answer,
574 pjsip_dialog *dlg,
575 pjsip_endpoint *endpt,
576 pjsip_tx_data **tdata);
577
578/**
579 * Variant of #pjsip_inv_verify_request() which allows application not to
580 * specify the rdata (i.e. pass NULL as the rdata parameter) and specify
581 * the parsed SDP in the \a offer argument and a temporary pool in the
582 * \a tmp_pool argument.
583 * This is useful if application no longer has access to the rdata.
584 *
585 * @see pjsip_inv_verify_request()
586 */
587PJ_DECL(pj_status_t) pjsip_inv_verify_request3( pjsip_rx_data *rdata,
588 pj_pool_t *tmp_pool,
589 unsigned *options,
590 const pjmedia_sdp_session *offer,
591 const pjmedia_sdp_session *answer,
592 pjsip_dialog *dlg,
593 pjsip_endpoint *endpt,
594 pjsip_tx_data **tdata);
595
596
597/**
598 * Create UAS invite session for the specified dialog in dlg. Application
599 * SHOULD call the verification function before calling this function,
600 * to ensure that it can create the session successfully.
601 *
602 * @param dlg The dialog to be used.
603 * @param rdata Application MUST specify the received INVITE request
604 * in rdata. The invite session needs to inspect the
605 * received request to see if the request contains
606 * features that it supports.
607 * @param local_sdp If application has determined its media capability,
608 * it can specify this capability in this argument.
609 * If SDP is received in the initial INVITE, the UAS
610 * capability specified in this argument doesn't have to
611 * match the received offer; the SDP negotiator is able
612 * to rearrange the media lines in the answer so that it
613 * matches the offer.
614 * @param options The options argument is bitmask combination of SIP
615 * features in pjsip_inv_options enumeration.
616 * @param p_inv Pointer to receive the newly created invite session.
617 *
618 * @return On successful, the invite session will be put in
619 * p_inv argument and the function will return PJ_SUCCESS.
620 * Otherwise the appropriate error status will be returned
621 * on failure.
622 */
623PJ_DECL(pj_status_t) pjsip_inv_create_uas(pjsip_dialog *dlg,
624 pjsip_rx_data *rdata,
625 const pjmedia_sdp_session *local_sdp,
626 unsigned options,
627 pjsip_inv_session **p_inv);
628
629
630/**
631 * Forcefully terminate and destroy INVITE session, regardless of
632 * the state of the session. Note that this function should only be used
633 * when there is failure in the INVITE session creation. After the
634 * invite session has been created and initialized, normally application
635 * SHOULD use #pjsip_inv_end_session() to end the INVITE session instead.
636 *
637 * Note also that this function may terminate the underlying dialog, if
638 * there are no other sessions in the dialog.
639 *
640 * @param inv The invite session.
641 * @param st_code Status code for the reason of the termination.
642 * @param notify If set to non-zero, then on_state_changed()
643 * callback will be called.
644 *
645 * @return PJ_SUCCESS if the INVITE session has been
646 * terminated.
647 */
648PJ_DECL(pj_status_t) pjsip_inv_terminate( pjsip_inv_session *inv,
649 int st_code,
650 pj_bool_t notify );
651
652
653/**
654 * Restart UAC session and prepare the session for a new initial INVITE.
655 * This function can be called for example when the application wants to
656 * follow redirection response with a new call reusing this session so
657 * that the new call will have the same Call-ID and From headers. After
658 * the session is restarted, application may create and send a new INVITE
659 * request.
660 *
661 * @param inv The invite session.
662 * @param new_offer Should be set to PJ_TRUE since the application will
663 * restart the session.
664 *
665 * @return PJ_SUCCESS on successful operation.
666 */
667PJ_DECL(pj_status_t) pjsip_inv_uac_restart(pjsip_inv_session *inv,
668 pj_bool_t new_offer);
669
670
671/**
672 * Accept or reject redirection response. Application MUST call this function
673 * after it signaled PJSIP_REDIRECT_PENDING in the \a on_redirected()
674 * callback, to notify the invite session whether to accept or reject the
675 * redirection to the current target. Application can use the combination of
676 * PJSIP_REDIRECT_PENDING command in \a on_redirected() callback and this
677 * function to ask for user permission before redirecting the call.
678 *
679 * Note that if the application chooses to reject or stop redirection (by
680 * using PJSIP_REDIRECT_REJECT or PJSIP_REDIRECT_STOP respectively), the
681 * session disconnection callback will be called before this function returns.
682 * And if the application rejects the target, the \a on_redirected() callback
683 * may also be called before this function returns if there is another target
684 * to try.
685 *
686 * @param inv The invite session.
687 * @param cmd Redirection operation. The semantic of this argument
688 * is similar to the description in the \a on_redirected()
689 * callback, except that the PJSIP_REDIRECT_PENDING is
690 * not accepted here.
691 * @param e Should be set to NULL.
692 *
693 * @return PJ_SUCCESS on successful operation.
694 */
695PJ_DECL(pj_status_t) pjsip_inv_process_redirect(pjsip_inv_session *inv,
696 pjsip_redirect_op cmd,
697 pjsip_event *e);
698
699
700/**
701 * Create the initial INVITE request for this session. This function can only
702 * be called for UAC session. If local media capability is specified when
703 * the invite session was created, then this function will put an SDP offer
704 * in the outgoing INVITE request. Otherwise the outgoing request will not
705 * contain SDP body.
706 *
707 * @param inv The UAC invite session.
708 * @param p_tdata The initial INVITE request will be put in this
709 * argument if it can be created successfully.
710 *
711 * @return PJ_SUCCESS if the INVITE request can be created.
712 */
713PJ_DECL(pj_status_t) pjsip_inv_invite( pjsip_inv_session *inv,
714 pjsip_tx_data **p_tdata );
715
716
717/**
718 * Create the initial response message for the incoming INVITE request in
719 * rdata with status code st_code and optional status text st_text. Use
720 * #pjsip_inv_answer() to create subsequent response message.
721 */
722PJ_DECL(pj_status_t) pjsip_inv_initial_answer( pjsip_inv_session *inv,
723 pjsip_rx_data *rdata,
724 int st_code,
725 const pj_str_t *st_text,
726 const pjmedia_sdp_session *sdp,
727 pjsip_tx_data **p_tdata);
728
729/**
730 * Create a response message to an INVITE request.
731 *
732 * @param inv The UAS invite session.
733 * @param st_code The st_code contains the status code to be sent,
734 * which may be a provisional or final response.
735 * @param st_text If custom status text is desired, application can
736 * specify the text in st_text; otherwise if this
737 * argument is NULL, default status text will be used.
738 * @param local_sdp If application has specified its media capability
739 * during creation of UAS invite session, the local_sdp
740 * argument MUST be NULL. This is because application
741 * can not perform more than one SDP offer/answer session
742 * in a single INVITE transaction.
743 * If application has not specified its media capability
744 * during creation of UAS invite session, it MAY or MUST
745 * specify its capability in local_sdp argument,
746 * depending whether st_code indicates a 2xx final
747 * response.
748 * @param p_tdata Pointer to receive the response message created by
749 * this function.
750 *
751 * @return PJ_SUCCESS if response message was created
752 * successfully.
753 */
754PJ_DECL(pj_status_t) pjsip_inv_answer( pjsip_inv_session *inv,
755 int st_code,
756 const pj_str_t *st_text,
757 const pjmedia_sdp_session *local_sdp,
758 pjsip_tx_data **p_tdata );
759
760
761/**
762 * Set local offer or answer depending on negotiator state (it may also
763 * create a negotiator if it doesn't exist yet).
764 *
765 * @param inv The invite session.
766 * @param sdp The SDP description which will be set as
767 * an offer/answer to remote.
768 *
769 * @return PJ_SUCCESS if local offer/answer can be accepted by
770 * SDP negotiator.
771 */
772PJ_DECL(pj_status_t) pjsip_inv_set_local_sdp(pjsip_inv_session *inv,
773 const pjmedia_sdp_session *sdp );
774
775
776/**
777 * Set local answer to respond to remote SDP offer, to be carried by
778 * subsequent response (or request).
779 *
780 * @param inv The invite session.
781 * @param sdp The SDP description which will be set as answer
782 * to remote.
783 *
784 * @return PJ_SUCCESS if local answer can be accepted by
785 * SDP negotiator.
786 */
787PJ_DECL(pj_status_t) pjsip_inv_set_sdp_answer(pjsip_inv_session *inv,
788 const pjmedia_sdp_session *sdp );
789
790
791/**
792 * Create a SIP message to initiate invite session termination. Depending on
793 * the state of the session, this function may return CANCEL request,
794 * a non-2xx final response, a BYE request, or even no request.
795 *
796 * For UAS, if the session has not answered the incoming INVITE, this function
797 * creates the non-2xx final response with the specified status code in
798 * \a st_code and optional status text in \a st_text.
799 *
800 * For UAC, if the original INVITE has not been answered with a final
801 * response, the behavior depends on whether provisional response has been
802 * received. If provisional response has been received, this function will
803 * create CANCEL request. If no provisional response has been received, the
804 * function will not create CANCEL request (the function will return
805 * PJ_SUCCESS but the \a p_tdata will contain NULL) because we cannot send
806 * CANCEL before receiving provisional response. If then a provisional
807 * response is received, the invite session will send CANCEL automatically.
808 *
809 * For both UAC and UAS, if the INVITE session has been answered with final
810 * response, a BYE request will be created.
811 *
812 * @param inv The invite session.
813 * @param st_code Status code to be used for terminating the session.
814 * @param st_text Optional status text.
815 * @param p_tdata Pointer to receive the message to be created. Note
816 * that it's possible to receive NULL here while the
817 * function returns PJ_SUCCESS, see the description.
818 *
819 * @return PJ_SUCCESS if termination is initiated.
820 */
821PJ_DECL(pj_status_t) pjsip_inv_end_session( pjsip_inv_session *inv,
822 int st_code,
823 const pj_str_t *st_text,
824 pjsip_tx_data **p_tdata );
825
826
827/**
828 * Create a CANCEL request for an ongoing re-INVITE transaction. If no
829 * provisional response has been received, the function will not create
830 * CANCEL request (the function will return PJ_SUCCESS but the \a p_tdata
831 * will contain NULL) because we cannot send CANCEL before receiving
832 * provisional response. If then a provisional response is received,
833 * the invite session will send CANCEL automatically.
834 *
835 * @param inv The invite session.
836 * @param p_tdata Pointer to receive the message to be created. Note
837 * that it's possible to receive NULL here while the
838 * function returns PJ_SUCCESS, see the description.
839 *
840 * @return PJ_SUCCESS if termination is initiated.
841 */
842PJ_DECL(pj_status_t) pjsip_inv_cancel_reinvite( pjsip_inv_session *inv,
843 pjsip_tx_data **p_tdata );
844
845
846/**
847 * Create a re-INVITE request.
848 *
849 * @param inv The invite session.
850 * @param new_contact If application wants to update its local contact and
851 * inform peer to perform target refresh with a new
852 * contact, it can specify the new contact in this
853 * argument; otherwise this argument must be NULL.
854 * @param new_offer Application MAY initiate a new SDP offer/answer
855 * session in the request when there is no pending
856 * answer to be sent or received. It can detect this
857 * condition by observing the state of the SDP
858 * negotiator of the invite session. If new offer
859 * should be sent to remote, the offer must be specified
860 * in this argument, otherwise it must be NULL.
861 * @param p_tdata Pointer to receive the re-INVITE request message to
862 * be created.
863 *
864 * @return PJ_SUCCESS if a re-INVITE request with the specified
865 * characteristics (e.g. to contain new offer) can be
866 * created.
867 */
868PJ_DECL(pj_status_t) pjsip_inv_reinvite(pjsip_inv_session *inv,
869 const pj_str_t *new_contact,
870 const pjmedia_sdp_session *new_offer,
871 pjsip_tx_data **p_tdata );
872
873
874
875/**
876 * Create an UPDATE request to initiate new SDP offer.
877 *
878 * @param inv The invite session.
879 * @param new_contact If application wants to update its local contact
880 * and inform peer to perform target refresh with a new
881 * contact, it can specify the new contact in this
882 * argument; otherwise this argument must be NULL.
883 * @param offer Offer to be sent to remote. This argument is
884 * mandatory.
885 * @param p_tdata Pointer to receive the UPDATE request message to
886 * be created.
887 *
888 * @return PJ_SUCCESS if a UPDATE request with the specified
889 * characteristics (e.g. to contain new offer) can be
890 * created.
891 */
892PJ_DECL(pj_status_t) pjsip_inv_update ( pjsip_inv_session *inv,
893 const pj_str_t *new_contact,
894 const pjmedia_sdp_session *offer,
895 pjsip_tx_data **p_tdata );
896
897
898/**
899 * Create an ACK request. Normally ACK request transmission is handled
900 * by the framework. Application only needs to use this function if it
901 * handles the ACK transmission manually, by overriding \a on_send_ack()
902 * callback in #pjsip_inv_callback.
903 *
904 * Note that if the invite session has a pending offer to be answered
905 * (for example when the last 2xx response to INVITE contains an offer),
906 * application MUST have set the SDP answer with #pjsip_create_sdp_body()
907 * prior to creating the ACK request. In this case, the ACK request
908 * will be added with SDP message body.
909 *
910 * @param inv The invite session.
911 * @param cseq Mandatory argument to specify the CSeq of the
912 * ACK request. This value MUST match the value
913 * of the INVITE transaction to be acknowledged.
914 * @param p_tdata Pointer to receive the ACK request message to
915 * be created.
916 *
917 * @return PJ_SUCCESS if ACK request has been created.
918 */
919PJ_DECL(pj_status_t) pjsip_inv_create_ack(pjsip_inv_session *inv,
920 int cseq,
921 pjsip_tx_data **p_tdata);
922
923
924/**
925 * Send request or response message in tdata.
926 *
927 * @param inv The invite session.
928 * @param tdata The message to be sent.
929 *
930 * @return PJ_SUCCESS if transaction can be initiated
931 * successfully to send this message. Note that the
932 * actual final state of the transaction itself will
933 * be reported later, in on_tsx_state_changed()
934 * callback.
935 */
936PJ_DECL(pj_status_t) pjsip_inv_send_msg(pjsip_inv_session *inv,
937 pjsip_tx_data *tdata);
938
939
940/**
941 * Get the invite session for the dialog, if any.
942 *
943 * @param dlg The dialog which invite session is being queried.
944 *
945 * @return The invite session instance which has been
946 * associated with this dialog, or NULL.
947 */
948PJ_DECL(pjsip_inv_session*) pjsip_dlg_get_inv_session(pjsip_dialog *dlg);
949
950/**
951 * Get the invite session instance associated with transaction tsx, if any.
952 *
953 * @param tsx The transaction, which invite session is being
954 * queried.
955 *
956 * @return The invite session instance which has been
957 * associated with this transaction, or NULL.
958 */
959PJ_DECL(pjsip_inv_session*) pjsip_tsx_get_inv_session(pjsip_transaction *tsx);
960
961
962/**
963 * Get state names for INVITE session state.
964 *
965 * @param state The invite state.
966 *
967 * @return String describing the state.
968 */
969PJ_DECL(const char *) pjsip_inv_state_name(pjsip_inv_state state);
970
971
972/**
973 * This is a utility function to create SIP body for SDP content.
974 *
975 * @param pool Pool to allocate memory.
976 * @param sdp SDP session to be put in the SIP message body.
977 * @param p_body Pointer to receive SIP message body containing
978 * the SDP session.
979 *
980 * @return PJ_SUCCESS on success.
981 */
982PJ_DECL(pj_status_t) pjsip_create_sdp_body(pj_pool_t *pool,
983 pjmedia_sdp_session *sdp,
984 pjsip_msg_body **p_body);
985
986/**
987 * Retrieve SDP information from an incoming message. Application should
988 * prefer to use this function rather than parsing the SDP manually since
989 * this function supports multipart message body.
990 *
991 * This function will only parse the SDP once, the first time it is called
992 * on the same message. Subsequent call on the same message will just pick
993 * up the already parsed SDP from the message.
994 *
995 * @param rdata The incoming message.
996 *
997 * @return The SDP info.
998 */
999PJ_DECL(pjsip_rdata_sdp_info*) pjsip_rdata_get_sdp_info(pjsip_rx_data *rdata);
1000
1001
1002PJ_END_DECL
1003
1004/**
1005 * @}
1006 */
1007
1008
1009#endif /* __SIP_INVITE_SESSION_H__ */