Debian Codegraph @

Xpjproject/pjsip/include/pjsip-ua/sip_inv.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 __SIP_INVITE_SESSION_H__
20 #define __SIP_INVITE_SESSION_H__
21
22 /**
23 * @file sip_inv.h
24 * @brief INVITE sessions
25 */
26
27
28 #include <pjsip/sip_dialog.h>
29 #include <pjmedia/sdp_neg.h>
30
31
32 /**
33 * @defgroup PJSIP_HIGH_UA User Agent Library
34 * @brief Mid-level User Agent Library.
35 *
36 * This is the high level user agent library, which consists of:
37 * - @ref PJSIP_INV, to encapsulate INVITE sessions and SDP
38 * negotiation in the session,
39 * - @ref PJSUA_REGC, high level client registration API, and
40 * - @ref PJSUA_XFER.
41 *
42 * More detailed information is explained in
43 * <A HREF="/docs.htm">PJSIP Developer's Guide</A>
44 * PDF document, and readers are encouraged to read the document to
45 * get the concept behind dialog, dialog usages, and INVITE sessions.
46 *
47 * The User Agent Library is implemented in <b>pjsip-ua</b> static
48 * library.
49 */
50
51 /**
52 * @defgroup PJSIP_INV INVITE Session
53 * @ingroup PJSIP_HIGH_UA
54 * @brief Provides INVITE session management.
55 * @{
56 *
57 * The INVITE session uses the @ref PJSIP_DIALOG framework to manage
58 * the underlying dialog, and is one type of usages that can use
59 * a particular dialog instance (other usages are event subscription,
60 * discussed in @ref PJSIP_EVENT_NOT). The INVITE session manages
61 * the life-time of the session, and also manages the SDP negotiation.
62 *
63 * Application must link with <b>pjsip-ua</b> static library to use this API.
64 *
65 * More detailed information is explained in
66 * <A HREF="/docs.htm">PJSIP Developer's Guide</A>
67 * PDF document, and readers are encouraged to read the document to
68 * get the concept behind dialog, dialog usages, and INVITE sessions.
69 *
70 * The INVITE session does NOT manage media. If application wants to
71 * use API that encapsulates both signaling and media in a very easy
72 * to use API, it can use @ref PJSUA_LIB for this purpose.
73 */
74
75 PJ_BEGIN_DECL
76
77
78 /**
79 * @see pjsip_inv_session
80 */
81 typedef struct pjsip_inv_session pjsip_inv_session;
82
83
84 /**
85 * This enumeration describes invite session state.
86 */
87 typedef enum pjsip_inv_state
88 {
89 PJSIP_INV_STATE_NULL, /**< Before INVITE is sent or received */
90 PJSIP_INV_STATE_CALLING, /**< After INVITE is sent */
91 PJSIP_INV_STATE_INCOMING, /**< After INVITE is received. */
92 PJSIP_INV_STATE_EARLY, /**< After response with To tag. */
93 PJSIP_INV_STATE_CONNECTING, /**< After 2xx is sent/received. */
94 PJSIP_INV_STATE_CONFIRMED, /**< After ACK is sent/received. */
95 PJSIP_INV_STATE_DISCONNECTED, /**< Session is terminated. */
96 } pjsip_inv_state;
97
98 /**
99 * Structure to hold parameters when calling the callback
100 * on_rx_offer2().
101 */
102 struct pjsip_inv_on_rx_offer_cb_param
103 {
104 const pjmedia_sdp_session *offer; /**< Remote offer. */
105 const pjsip_rx_data *rdata; /**< The received request. */
106 };
107
108
109 /**
110 * This structure contains callbacks to be registered by application to
111 * receive notifications from the framework about various events in
112 * the invite session.
113 */
114 typedef struct pjsip_inv_callback
115 {
116 /**
117 * This callback is called when the invite sesion state has changed.
118 * Application should inspect the session state (inv_sess->state) to get
119 * the current state of the session.
120 *
121 * This callback is mandatory.
122 *
123 * @param inv The invite session.
124 * @param e The event which has caused the invite session's
125 * state to change.
126 */
127 void (*on_state_changed)(pjsip_inv_session *inv, pjsip_event *e);
128
129 /**
130 * This callback is called when the invite usage module has created
131 * a new dialog and invite because of forked outgoing request.
132 *
133 * Currently the invite session does not create a new dialog in
134 * forking scenario, so this callback will never be invoked.
135 *
136 * @param inv The new invite session.
137 * @param e The event which has caused the dialog to fork.
138 * The type of this event can be either
139 * PJSIP_EVENT_RX_MSG or PJSIP_EVENT_RX_200_MSG.
140 */
141 void (*on_new_session)(pjsip_inv_session *inv, pjsip_event *e);
142
143 /**
144 * This callback is called whenever any transactions within the session
145 * has changed their state. Application MAY implement this callback,
146 * e.g. to monitor the progress of an outgoing request, or to send
147 * response to unhandled incoming request (such as INFO).
148 *
149 * This callback is optional.
150 *
151 * @param inv The invite session.
152 * @param tsx The transaction, which state has changed.
153 * @param e The event which has caused the transation state's
154 * to change.
155 */
156 void (*on_tsx_state_changed)(pjsip_inv_session *inv,
157 pjsip_transaction *tsx,
158 pjsip_event *e);
159
160 /**
161 * This callback is called when the invite session has received
162 * new offer from peer. Application can inspect the remote offer
163 * in "offer", and set the SDP answer with #pjsip_inv_set_sdp_answer().
164 * When the application sends a SIP message to send the answer,
165 * this SDP answer will be negotiated with the offer, and the result
166 * will be sent with the SIP message.
167 *
168 * Note: if callback #on_rx_offer2() is implemented, this callback will
169 * not be called.
170 *
171 * @param inv The invite session.
172 * @param offer Remote offer.
173 */
174 void (*on_rx_offer)(pjsip_inv_session *inv,
175 const pjmedia_sdp_session *offer);
176
177 /**
178 * This callback is called when the invite session has received
179 * new offer from peer. Variant of #on_rx_offer() callback.
180 *
181 * @param inv The invite session.
182 * @param param The callback parameters.
183 */
184 void (*on_rx_offer2)(pjsip_inv_session *inv,
185 struct pjsip_inv_on_rx_offer_cb_param *param);
186
187 /**
188 * This callback is optional, and is called when the invite session has
189 * received a re-INVITE from the peer. It will be called after
190 * on_rx_offer() callback and works only for re-INVITEs. It allows more
191 * fine-grained control over the response to a re-INVITE, e.g. sending
192 * a provisional response first. Application can return PJ_SUCCESS and
193 * send a reply using the function #pjsip_inv_initial_answer() or
194 * #pjsip_inv_answer(), as with the initial INVITE. If application
195 * returns non-PJ_SUCCESS, it needs to set the SDP answer with
196 * #pjsip_inv_set_sdp_answer() and the re-INVITE will be answered
197 * automatically.
198 *
199 * Remarks: Application may need to monitor on_tsx_state_changed()
200 * callback to check whether the re-INVITE is already answered
201 * automatically with 487 due to being cancelled.
202 *
203 * @param inv The invite session.
204 * @param offer Remote offer.
205 * @param rdata The received re-INVITE request.
206 *
207 * @return - PJ_SUCCESS: application will answer the re-INVITE
208 * manually
209 * - non-PJ_SUCCESS: answer the re-INVITE automatically
210 * using the SDP set via #pjsip_inv_set_sdp_answer()
211 */
212 pj_status_t (*on_rx_reinvite)(pjsip_inv_session *inv,
213 const pjmedia_sdp_session *offer,
214 pjsip_rx_data *rdata);
215
216 /**
217 * This callback is optional, and it is used to ask the application
218 * to create a fresh offer, when the invite session has received
219 * re-INVITE without offer. This offer then will be sent in the
220 * 200/OK response to the re-INVITE request.
221 *
222 * If application doesn't implement this callback, the invite session
223 * will send the currently active SDP as the offer.
224 *
225 * @param inv The invite session.
226 * @param p_offer Pointer to receive the SDP offer created by
227 * application.
228 */
229 void (*on_create_offer)(pjsip_inv_session *inv,
230 pjmedia_sdp_session **p_offer);
231
232 /**
233 * This callback is called after SDP offer/answer session has completed.
234 * The status argument specifies the status of the offer/answer,
235 * i.e. whether the SDP answer is valid or the negotiation result
236 * as returned by pjmedia_sdp_neg_negotiate().
237 *
238 * This callback is optional (from the point of view of the framework),
239 * but all useful applications normally need to implement this callback.
240 *
241 * @param inv The invite session.
242 * @param status The negotiation status.
243 */
244 void (*on_media_update)(pjsip_inv_session *inv_ses,
245 pj_status_t status);
246
247 /**
248 * This callback is called when the framework needs to send
249 * ACK request after it receives incoming 2xx response for
250 * INVITE. It allows application to manually handle the
251 * transmission of ACK request, which is required by some 3PCC
252 * scenarios. If this callback is not implemented, the framework
253 * will handle the ACK transmission automatically.
254 *
255 * When this callback is overridden, application may delay the
256 * sending of the ACK request (for example, when it needs to
257 * wait for answer from the other call leg, in 3PCC scenarios).
258 *
259 * Application MUST create the ACK request using pjsip_inv_create_ack()
260 * and send it using pjsip_inv_send_msg().
261 *
262 * Once it has sent the ACK request, the framework will keep
263 * this ACK request in the cache. Subsequent receipt of 2xx response
264 * will not cause this callback to be called (but see exception below),
265 * and instead automatic retransmission of this ACK request from
266 * the cache will be done by the framework.
267 * Exception: if app has created the ACK but has not sent it,
268 * while it receives a retransmission of 2xx response, this callback
269 * will be called again.
270 *
271 * This callback is optional.
272 */
273 void (*on_send_ack)(pjsip_inv_session *inv, pjsip_rx_data *rdata);
274
275 /**
276 * This callback is called when the session is about to resend the
277 * INVITE request to the specified target, following the previously
278 * received redirection response.
279 *
280 * Application may accept the redirection to the specified target
281 * (the default behavior if this callback is implemented), reject
282 * this target only and make the session continue to try the next
283 * target in the list if such target exists, stop the whole
284 * redirection process altogether and cause the session to be
285 * disconnected, or defer the decision to ask for user confirmation.
286 *
287 * This callback is optional. If this callback is not implemented,
288 * the default behavior is to NOT follow the redirection response.
289 *
290 * Note: when \a e is NULL (e.g. called from
291 * #pjsip_inv_uac_try_next_target() after an async auth failure),
292 * the application should carry any needed context through its own
293 * state, such as the \a user_data field in
294 * #pjsip_auth_clt_async_setting.
295 *
296 * @param inv The invite session.
297 * @param target The current target to be tried.
298 * @param e The event that caused this callback to be called.
299 * This could be the receipt of 3xx response, or
300 * 4xx/5xx response received for the INVITE sent to
301 * subsequent targets, or NULL if this callback is
302 * called from within #pjsip_inv_process_redirect()
303 * or #pjsip_inv_uac_try_next_target() context.
304 *
305 * @return Action to be performed for the target. Set this
306 * parameter to one of the value below:
307 * - PJSIP_REDIRECT_ACCEPT: immediately accept the
308 * redirection to this target. When set, the
309 * session will immediately resend INVITE request
310 * to the target after this callback returns.
311 * - PJSIP_REDIRECT_REJECT: immediately reject this
312 * target. The session will continue retrying with
313 * next target if present, or disconnect the call
314 * if there is no more target to try.
315 * - PJSIP_REDIRECT_STOP: stop the whole redirection
316 * process and immediately disconnect the call. The
317 * on_state_changed() callback will be called with
318 * PJSIP_INV_STATE_DISCONNECTED state immediately
319 * after this callback returns.
320 * - PJSIP_REDIRECT_PENDING: set to this value if
321 * no decision can be made immediately (for example
322 * to request confirmation from user). Application
323 * then MUST call #pjsip_inv_process_redirect()
324 * to either accept or reject the redirection upon
325 * getting user decision.
326 */
327 pjsip_redirect_op (*on_redirected)(pjsip_inv_session *inv,
328 const pjsip_uri *target,
329 const pjsip_event *e);
330
331 } pjsip_inv_callback;
332
333
334
335 /**
336 * This enumeration shows various options that can be applied to a session.
337 * The bitmask combination of these options need to be specified when
338 * creating a session. After the dialog is established (including early),
339 * the options member of #pjsip_inv_session shows which capabilities are
340 * common in both endpoints.
341 */
342 enum pjsip_inv_option
343 {
344 /**
345 * Indicate support for reliable provisional response extension
346 */
347 PJSIP_INV_SUPPORT_100REL = 1,
348
349 /**
350 * Indicate support for session timer extension.
351 */
352 PJSIP_INV_SUPPORT_TIMER = 2,
353
354 /**
355 * Indicate support for UPDATE method. This is automatically implied
356 * when creating outgoing dialog. After the dialog is established,
357 * the options member of #pjsip_inv_session shows whether peer supports
358 * this method as well.
359 */
360 PJSIP_INV_SUPPORT_UPDATE = 4,
361
362 /**
363 * Indicate support for ICE
364 */
365 PJSIP_INV_SUPPORT_ICE = 8,
366
367 /**
368 * Require ICE support.
369 */
370 PJSIP_INV_REQUIRE_ICE = 16,
371
372 /**
373 * Require reliable provisional response extension.
374 */
375 PJSIP_INV_REQUIRE_100REL = 32,
376
377 /**
378 * Require session timer extension.
379 */
380 PJSIP_INV_REQUIRE_TIMER = 64,
381
382 /**
383 * Session timer extension will always be used even when peer doesn't
384 * support/want session timer.
385 */
386 PJSIP_INV_ALWAYS_USE_TIMER = 128,
387
388 /**
389 * Indicate support for trickle ICE
390 */
391 PJSIP_INV_SUPPORT_TRICKLE_ICE = 256,
392
393 /**
394 * Require trickle ICE support.
395 */
396 PJSIP_INV_REQUIRE_TRICKLE_ICE = 512,
397
398 /**
399 * Require siprec support.
400 */
401 PJSIP_INV_REQUIRE_SIPREC = 1024,
402
403 /**
404 * Indicate support for siprec
405 */
406 PJSIP_INV_SUPPORT_SIPREC = 2048,
407
408 };
409
410 /* Forward declaration of Session Timers */
411 struct pjsip_timer;
412
413 /**
414 * This structure describes the invite session.
415 *
416 * Note regarding the invite session's pools. The inv_sess used to have
417 * only one pool, which is just a pointer to the dialog's pool. Ticket
418 * https://github.com/pjsip/pjproject/issues/877 has found that the memory
419 * usage will grow considerably everytime re-INVITE or UPDATE is
420 * performed.
421 *
422 * Ticket #877 then created two more memory pools for the inv_sess, so
423 * now we have three memory pools:
424 * - pool: to be used to allocate long term data for the session
425 * - pool_prov and pool_active: this is a flip-flop pools to be used
426 * interchangably during re-INVITE and UPDATE. pool_prov is
427 * "provisional" pool, used to allocate SDP offer or answer for
428 * the re-INVITE and UPDATE. Once SDP negotiation is done, the
429 * provisional pool will be made as the active pool, then the
430 * existing active pool will be reset, to release the memory
431 * back to the OS. So these pool's lifetime is synchronized to
432 * the SDP offer-answer negotiation.
433 *
434 * Higher level application such as PJSUA-LIB has been modified to
435 * make use of these flip-flop pools, i.e. by creating media objects
436 * from the provisional pool rather than from the long term pool.
437 *
438 * Other applications that want to use these pools must understand
439 * that the flip-flop pool's lifetimes are synchronized to the
440 * SDP offer-answer negotiation.
441 *
442 * The lifetime of this session is controlled by the reference counter in this
443 * structure, which is manipulated by calling #pjsip_inv_add_ref and
444 * #pjsip_inv_dec_ref. When the reference counter has reached zero, then
445 * this session will be destroyed.
446 */
447 struct pjsip_inv_session
448 {
449 char obj_name[PJ_MAX_OBJ_NAME]; /**< Log identification */
450 pj_pool_t *pool; /**< Long term pool. */
451 pj_pool_t *pool_prov; /**< Provisional pool */
452 pj_pool_t *pool_active; /**< Active/current pool*/
453 pjsip_inv_state state; /**< Invite sess state. */
454 pj_bool_t cancelling; /**< CANCEL requested */
455 pj_bool_t pending_cancel; /**< Wait to send CANCEL*/
456 pjsip_tx_data *pending_bye; /**< BYE to send later */
457 pjsip_status_code cause; /**< Disconnect cause. */
458 pj_str_t cause_text; /**< Cause text. */
459 pj_bool_t notify; /**< Internal. */
460 pj_bool_t sdp_done_early_rel; /**< Nego done in early
461 med was reliable? */
462 unsigned cb_called; /**< Cb has been called */
463 pjsip_dialog *dlg; /**< Underlying dialog. */
464 pjsip_role_e role; /**< Invite role. */
465 unsigned options; /**< Options in use. */
466 pjmedia_sdp_neg *neg; /**< Negotiator. */
467 unsigned sdp_neg_flags; /**< SDP neg flags. */
468 pjsip_transaction *invite_tsx; /**< 1st invite tsx. */
469 pjsip_tx_data *invite_req; /**< Saved invite req */
470 pjsip_tx_data *last_answer; /**< Last INVITE resp. */
471 pjsip_tx_data *last_ack; /**< Last ACK request */
472 pj_int32_t last_ack_cseq; /**< CSeq of last ACK */
473 void *mod_data[PJSIP_MAX_MODULE];/**< Modules data. */
474 struct pjsip_timer *timer; /**< Session Timers. */
475 pj_bool_t following_fork; /**< Internal, following
476 forked media? */
477 pj_atomic_t *ref_cnt; /**< Reference counter. */
478 pj_bool_t updated_sdp_answer; /**< SDP answer just been
479 updated? */
480 };
481
482
483 /**
484 * This structure represents SDP information in a pjsip_(rx|tx)_data. Application
485 * retrieve this information by calling #pjsip_get_sdp_info(). This
486 * mechanism supports multipart message body.
487 */
488 typedef struct pjsip_sdp_info
489 {
490 /**
491 * Pointer and length of the text body in the incoming message. If
492 * the pointer is NULL, it means the message does not contain SDP
493 * body.
494 */
495 pj_str_t body;
496
497 /**
498 * This will contain non-zero if an invalid SDP body is found in the
499 * message.
500 */
501 pj_status_t sdp_err;
502
503 /**
504 * A parsed and validated SDP body.
505 */
506 pjmedia_sdp_session *sdp;
507
508 } pjsip_sdp_info;
509
510 /**
511 * For backwards compatibility and completeness,
512 * pjsip_rdata_sdp_info and pjsip_tdata_sdp_info
513 * are typedef'd to pjsip_sdp_info.
514 */
515 typedef pjsip_sdp_info pjsip_rdata_sdp_info;
516
517 /**
518 * For backwards compatibility and completeness,
519 * pjsip_rdata_sdp_info and pjsip_tdata_sdp_info
520 * are typedef'd to pjsip_sdp_info.
521 */
522 typedef pjsip_sdp_info pjsip_tdata_sdp_info;
523
524
525 /**
526 * Initialize the invite usage module and register it to the endpoint.
527 * The callback argument contains pointer to functions to be called on
528 * occurences of events in invite sessions.
529 *
530 * @param endpt The endpoint instance.
531 * @param cb Callback structure.
532 *
533 * @return PJ_SUCCESS on success, or the appropriate error code.
534 */
535 PJ_DECL(pj_status_t) pjsip_inv_usage_init(pjsip_endpoint *endpt,
536 const pjsip_inv_callback *cb);
537
538 /**
539 * Get the INVITE usage module instance.
540 *
541 * @return PJ_SUCCESS on success, or the appropriate error code.
542 */
543 PJ_DECL(pjsip_module*) pjsip_inv_usage_instance(void);
544
545
546 /**
547 * Dump user agent contents (e.g. all dialogs).
548 */
549 PJ_DECL(void) pjsip_inv_usage_dump(void);
550
551
552 /**
553 * Create UAC invite session for the specified dialog in dlg.
554 *
555 * @param dlg The dialog which will be used by this invite session.
556 * @param local_sdp If application has determined its media capability,
557 * it can specify the SDP here. Otherwise it can leave
558 * this to NULL, if app wishes to specify the SDP at
559 * a later time using the API pjsip_inv_set_local_sdp(),
560 * or if it wants to let remote UAS specify an offer.
561 * @param options The options argument is bitmask combination of SIP
562 * features in pjsip_inv_option enumeration.
563 * @param p_inv On successful return, the invite session will be put
564 * in this argument.
565 *
566 * @return The function will return PJ_SUCCESS if it can create
567 * the session. Otherwise the appropriate error status
568 * will be returned on failure.
569 */
570 PJ_DECL(pj_status_t) pjsip_inv_create_uac(pjsip_dialog *dlg,
571 const pjmedia_sdp_session *local_sdp,
572 unsigned options,
573 pjsip_inv_session **p_inv);
574
575
576 /**
577 * Application SHOULD call this function upon receiving the initial INVITE
578 * request in rdata before creating the invite session (or even dialog),
579 * to verify that the invite session can handle the INVITE request.
580 * This function verifies that local endpoint is capable to handle required
581 * SIP extensions in the request (i.e. Require header) and also the media,
582 * if media description is present in the request.
583 *
584 * @param rdata The incoming INVITE request.
585 *
586 * @param options Upon calling this function, the options argument
587 * MUST contain the desired SIP extensions to be
588 * applied to the session. Upon return, this argument
589 * will contain the SIP extension that will be applied
590 * to the session, after considering the Supported,
591 * Require, and Allow headers in the request.
592 *
593 * @param sdp If local media capability has been determined,
594 * and if application wishes to verify that it can
595 * handle the media offer in the incoming INVITE
596 * request, it SHOULD specify its local media capability
597 * in this argument.
598 * If it is not specified, media verification will not
599 * be performed by this function.
600 *
601 * @param dlg If tdata is not NULL, application needs to specify
602 * how to create the response. Either dlg or endpt
603 * argument MUST be specified, with dlg argument takes
604 * precedence when both are specified.
605 *
606 * If a dialog has been created prior to calling this
607 * function, then it MUST be specified in dlg argument.
608 * Otherwise application MUST specify the endpt argument
609 * (this is useful e.g. when application wants to send
610 * the response statelessly).
611 *
612 * @param endpt If tdata is not NULL, application needs to specify
613 * how to create the response. Either dlg or endpt
614 * argument MUST be specified, with dlg argument takes
615 * precedence when both are specified.
616 *
617 * @param tdata If this argument is not NULL, this function will
618 * create the appropriate non-2xx final response message
619 * when the verification fails.
620 *
621 * @return If everything has been negotiated successfully,
622 * the function will return PJ_SUCCESS. Otherwise it
623 * will return the reason of the failure as the return
624 * code.
625 *
626 * This function is capable to create the appropriate
627 * response message when the verification has failed.
628 * If tdata is specified, then a non-2xx final response
629 * will be created and put in this argument upon return,
630 * when the verification has failed.
631 *
632 * If a dialog has been created prior to calling this
633 * function, then it MUST be specified in dlg argument.
634 * Otherwise application MUST specify the endpt argument
635 * (this is useful e.g. when application wants to send
636 * the response statelessly).
637 *
638 * @see pjsip_inv_verify_request2()
639 */
640 PJ_DECL(pj_status_t) pjsip_inv_verify_request( pjsip_rx_data *rdata,
641 unsigned *options,
642 const pjmedia_sdp_session *sdp,
643 pjsip_dialog *dlg,
644 pjsip_endpoint *endpt,
645 pjsip_tx_data **tdata);
646
647 /**
648 * Variant of #pjsip_inv_verify_request() which allows application to specify
649 * the parsed SDP in the \a offer argument. This is useful to avoid having to
650 * re-parse the SDP in the incoming request.
651 *
652 * @see pjsip_inv_verify_request()
653 */
654 PJ_DECL(pj_status_t) pjsip_inv_verify_request2( pjsip_rx_data *rdata,
655 unsigned *options,
656 const pjmedia_sdp_session *offer,
657 const pjmedia_sdp_session *answer,
658 pjsip_dialog *dlg,
659 pjsip_endpoint *endpt,
660 pjsip_tx_data **tdata);
661
662 /**
663 * Variant of #pjsip_inv_verify_request() which allows application not to
664 * specify the rdata (i.e. pass NULL as the rdata parameter) and specify
665 * the parsed SDP in the \a offer argument and a temporary pool in the
666 * \a tmp_pool argument.
667 * This is useful if application no longer has access to the rdata.
668 *
669 * @see pjsip_inv_verify_request()
670 */
671 PJ_DECL(pj_status_t) pjsip_inv_verify_request3( pjsip_rx_data *rdata,
672 pj_pool_t *tmp_pool,
673 unsigned *options,
674 const pjmedia_sdp_session *offer,
675 const pjmedia_sdp_session *answer,
676 pjsip_dialog *dlg,
677 pjsip_endpoint *endpt,
678 pjsip_tx_data **tdata);
679
680
681 /**
682 * Create UAS invite session for the specified dialog in dlg. Application
683 * SHOULD call the verification function before calling this function,
684 * to ensure that it can create the session successfully.
685 *
686 * @param dlg The dialog to be used.
687 * @param rdata Application MUST specify the received INVITE request
688 * in rdata. The invite session needs to inspect the
689 * received request to see if the request contains
690 * features that it supports.
691 * @param local_sdp If application has determined its media capability,
692 * it can specify this capability in this argument.
693 * If SDP is received in the initial INVITE, the UAS
694 * capability specified in this argument doesn't have to
695 * match the received offer; the SDP negotiator is able
696 * to rearrange the media lines in the answer so that it
697 * matches the offer.
698 * @param options The options argument is bitmask combination of SIP
699 * features in pjsip_inv_option enumeration.
700 * @param p_inv Pointer to receive the newly created invite session.
701 *
702 * @return On successful, the invite session will be put in
703 * p_inv argument and the function will return PJ_SUCCESS.
704 * Otherwise the appropriate error status will be returned
705 * on failure.
706 */
707 PJ_DECL(pj_status_t) pjsip_inv_create_uas(pjsip_dialog *dlg,
708 pjsip_rx_data *rdata,
709 const pjmedia_sdp_session *local_sdp,
710 unsigned options,
711 pjsip_inv_session **p_inv);
712
713
714 /**
715 * Add reference counter to the INVITE session. The reference counter controls
716 * the life time of the session, ie. when the counter reaches zero, then it
717 * will be destroyed.
718 *
719 * @param inv The INVITE session.
720 * @return PJ_SUCCESS if the INVITE session reference counter
721 * was increased.
722 */
723 PJ_DECL(pj_status_t) pjsip_inv_add_ref( pjsip_inv_session *inv );
724
725 /**
726 * Decrement reference counter of the INVITE session.
727 * When the session is no longer used, it will be destroyed and
728 * caller is informed with PJ_EGONE return status.
729 *
730 * @param inv The INVITE session.
731 * @return PJ_SUCCESS if the INVITE session reference counter
732 * was decreased. A status PJ_EGONE will be returned to
733 * inform that session is destroyed.
734 */
735 PJ_DECL(pj_status_t) pjsip_inv_dec_ref( pjsip_inv_session *inv );
736
737
738 /**
739 * Forcefully terminate and destroy INVITE session, regardless of
740 * the state of the session. Note that this function should only be used
741 * when there is failure in the INVITE session creation. After the
742 * invite session has been created and initialized, normally application
743 * SHOULD use #pjsip_inv_end_session() to end the INVITE session instead.
744 *
745 * Note also that this function may terminate the underlying dialog, if
746 * there are no other sessions in the dialog.
747 *
748 * @param inv The invite session.
749 * @param st_code Status code for the reason of the termination.
750 * @param notify If set to non-zero, then on_state_changed()
751 * callback will be called.
752 *
753 * @return PJ_SUCCESS if the INVITE session has been
754 * terminated.
755 */
756 PJ_DECL(pj_status_t) pjsip_inv_terminate( pjsip_inv_session *inv,
757 int st_code,
758 pj_bool_t notify );
759
760
761 /**
762 * Restart UAC session and prepare the session for a new initial INVITE.
763 * This function can be called for example when the application wants to
764 * follow redirection response with a new call reusing this session so
765 * that the new call will have the same Call-ID and From headers. After
766 * the session is restarted, application may create and send a new INVITE
767 * request.
768 *
769 * @param inv The invite session.
770 * @param new_offer Should be set to PJ_TRUE since the application will
771 * restart the session.
772 *
773 * @return PJ_SUCCESS on successful operation.
774 */
775 PJ_DECL(pj_status_t) pjsip_inv_uac_restart(pjsip_inv_session *inv,
776 pj_bool_t new_offer);
777
778
779 /**
780 * Attempt to recurse to the next target in the dialog's target set
781 * after an authentication failure in which the application could not
782 * supply credentials. This is intended to be called from an
783 * asynchronous authentication challenge callback (see
784 * #pjsip_auth_clt_async_setting) when the application decides it
785 * cannot authenticate the current attempt and wants the session to
786 * fall back to the same redirect-target walk that the synchronous
787 * code path would have performed.
788 *
789 * The function invokes #pjsip_inv_callback::on_redirected for each
790 * candidate target, passing NULL for the event parameter (see the
791 * note in that callback's documentation for how to handle this).
792 *
793 * If no suitable next target exists the function returns PJ_FALSE
794 * and the caller is responsible for ending the session, typically
795 * via #pjsip_inv_end_session().
796 *
797 * @param inv The UAC invite session.
798 *
799 * @return PJ_TRUE if a next target was found and
800 * #pjsip_inv_callback::on_redirected was invoked,
801 * PJ_FALSE if no more targets are available.
802 */
803 PJ_DECL(pj_bool_t) pjsip_inv_uac_try_next_target(
804 pjsip_inv_session *inv);
805
806
807 /**
808 * Accept or reject redirection response. Application MUST call this function
809 * after it signaled PJSIP_REDIRECT_PENDING in the \a on_redirected()
810 * callback, to notify the invite session whether to accept or reject the
811 * redirection to the current target. Application can use the combination of
812 * PJSIP_REDIRECT_PENDING command in \a on_redirected() callback and this
813 * function to ask for user permission before redirecting the call.
814 *
815 * Note that if the application chooses to reject or stop redirection (by
816 * using PJSIP_REDIRECT_REJECT or PJSIP_REDIRECT_STOP respectively), the
817 * session disconnection callback will be called before this function returns.
818 * And if the application rejects the target, the \a on_redirected() callback
819 * may also be called before this function returns if there is another target
820 * to try.
821 *
822 * @param inv The invite session.
823 * @param cmd Redirection operation. The semantic of this argument
824 * is similar to the description in the \a on_redirected()
825 * callback, except that the PJSIP_REDIRECT_PENDING is
826 * not accepted here.
827 * @param e Should be set to NULL.
828 *
829 * @return PJ_SUCCESS on successful operation.
830 */
831 PJ_DECL(pj_status_t) pjsip_inv_process_redirect(pjsip_inv_session *inv,
832 pjsip_redirect_op cmd,
833 pjsip_event *e);
834
835
836 /**
837 * Create the initial INVITE request for this session. This function can only
838 * be called for UAC session. If local media capability is specified when
839 * the invite session was created, then this function will put an SDP offer
840 * in the outgoing INVITE request. Otherwise the outgoing request will not
841 * contain SDP body.
842 *
843 * @param inv The UAC invite session.
844 * @param p_tdata The initial INVITE request will be put in this
845 * argument if it can be created successfully.
846 *
847 * @return PJ_SUCCESS if the INVITE request can be created.
848 */
849 PJ_DECL(pj_status_t) pjsip_inv_invite( pjsip_inv_session *inv,
850 pjsip_tx_data **p_tdata );
851
852
853 /**
854 * Create the initial response message for the incoming INVITE request in
855 * rdata with status code st_code and optional status text st_text. Use
856 * #pjsip_inv_answer() to create subsequent response message.
857 *
858 * When this function returning non-PJ_SUCCESS, it may be caused by an
859 * unacceptable INVITE request. In such cases the function will generate
860 * an appropriate answer in p_tdata,
861 * e.g: when session timer header Session-Expires is too low,
862 * the generated answer will include Min-SE header.
863 * If the generated answer is not sent, it must be destroyed.
864 * i.e: using #pjsip_tx_data_dec_ref(), to avoid resource leak.
865 *
866 * @param inv The UAS invite session.
867 * @param rdata The incoming request message.
868 * @param st_code The st_code contains the status code to be sent,
869 * which may be a provisional or final response.
870 * @param st_text If custom status text is desired, application can
871 * specify the text in st_text; otherwise if this
872 * argument is NULL, default status text will be used.
873 * @param sdp If application has specified its media capability
874 * during creation of UAS invite session, the sdp
875 * argument MUST be NULL. This is because application
876 * can not perform more than one SDP offer/answer session
877 * in a single INVITE transaction.
878 * If application has not specified its media capability
879 * during creation of UAS invite session, it MAY or MUST
880 * specify its capability in sdp argument,
881 * depending whether st_code indicates a 2xx final
882 * response.
883 * @param p_tdata Pointer to receive the response message created by
884 * this function.
885 *
886 * @return PJ_SUCCESS if response message was created
887 * successfully.
888 */
889 PJ_DECL(pj_status_t) pjsip_inv_initial_answer( pjsip_inv_session *inv,
890 pjsip_rx_data *rdata,
891 int st_code,
892 const pj_str_t *st_text,
893 const pjmedia_sdp_session *sdp,
894 pjsip_tx_data **p_tdata);
895
896 /**
897 * Create a response message to an INVITE request.
898 *
899 * @param inv The UAS invite session.
900 * @param st_code The st_code contains the status code to be sent,
901 * which may be a provisional or final response.
902 * @param st_text If custom status text is desired, application can
903 * specify the text in st_text; otherwise if this
904 * argument is NULL, default status text will be used.
905 * @param local_sdp If application has specified its media capability
906 * during creation of UAS invite session, the local_sdp
907 * argument MUST be NULL. This is because application
908 * can not perform more than one SDP offer/answer session
909 * in a single INVITE transaction.
910 * If application has not specified its media capability
911 * during creation of UAS invite session, it MAY or MUST
912 * specify its capability in local_sdp argument,
913 * depending whether st_code indicates a 2xx final
914 * response.
915 * @param p_tdata Pointer to receive the response message created by
916 * this function.
917 *
918 * @return PJ_SUCCESS if response message was created
919 * successfully.
920 */
921 PJ_DECL(pj_status_t) pjsip_inv_answer( pjsip_inv_session *inv,
922 int st_code,
923 const pj_str_t *st_text,
924 const pjmedia_sdp_session *local_sdp,
925 pjsip_tx_data **p_tdata );
926
927
928 /**
929 * Set local offer or answer depending on negotiator state (it may also
930 * create a negotiator if it doesn't exist yet).
931 *
932 * @param inv The invite session.
933 * @param sdp The SDP description which will be set as
934 * an offer/answer to remote.
935 *
936 * @return PJ_SUCCESS if local offer/answer can be accepted by
937 * SDP negotiator.
938 */
939 PJ_DECL(pj_status_t) pjsip_inv_set_local_sdp(pjsip_inv_session *inv,
940 const pjmedia_sdp_session *sdp );
941
942
943 /**
944 * Set local answer to respond to remote SDP offer, to be carried by
945 * subsequent response (or request).
946 *
947 * @param inv The invite session.
948 * @param sdp The SDP description which will be set as answer
949 * to remote.
950 *
951 * @return PJ_SUCCESS if local answer can be accepted by
952 * SDP negotiator.
953 */
954 PJ_DECL(pj_status_t) pjsip_inv_set_sdp_answer(pjsip_inv_session *inv,
955 const pjmedia_sdp_session *sdp );
956
957
958 /**
959 * Create a SIP message to initiate invite session termination. Depending on
960 * the state of the session, this function may return CANCEL request,
961 * a non-2xx final response, a BYE request, or even no request.
962 *
963 * For UAS, if the session has not answered the incoming INVITE, this function
964 * creates the non-2xx final response with the specified status code in
965 * \a st_code and optional status text in \a st_text.
966 *
967 * For UAC, if the original INVITE has not been answered with a final
968 * response, the behavior depends on whether provisional response has been
969 * received. If provisional response has been received, this function will
970 * create CANCEL request. If no provisional response has been received, the
971 * function will not create CANCEL request (the function will return
972 * PJ_SUCCESS but the \a p_tdata will contain NULL) because we cannot send
973 * CANCEL before receiving provisional response. If then a provisional
974 * response is received, the invite session will send CANCEL automatically.
975 *
976 * For both UAC and UAS, if the INVITE session has been answered with final
977 * response, a BYE request will be created.
978 *
979 * @param inv The invite session.
980 * @param st_code Status code to be used for terminating the session.
981 * @param st_text Optional status text.
982 * @param p_tdata Pointer to receive the message to be created. Note
983 * that it's possible to receive NULL here while the
984 * function returns PJ_SUCCESS, see the description.
985 *
986 * @return PJ_SUCCESS if termination is initiated.
987 */
988 PJ_DECL(pj_status_t) pjsip_inv_end_session( pjsip_inv_session *inv,
989 int st_code,
990 const pj_str_t *st_text,
991 pjsip_tx_data **p_tdata );
992
993
994 /**
995 * Create a CANCEL request for an ongoing re-INVITE transaction. If no
996 * provisional response has been received, the function will not create
997 * CANCEL request (the function will return PJ_SUCCESS but the \a p_tdata
998 * will contain NULL) because we cannot send CANCEL before receiving
999 * provisional response. If then a provisional response is received,
1000 * the invite session will send CANCEL automatically.
1001 *
1002 * @param inv The invite session.
1003 * @param p_tdata Pointer to receive the message to be created. Note
1004 * that it's possible to receive NULL here while the
1005 * function returns PJ_SUCCESS, see the description.
1006 *
1007 * @return PJ_SUCCESS if termination is initiated.
1008 */
1009 PJ_DECL(pj_status_t) pjsip_inv_cancel_reinvite( pjsip_inv_session *inv,
1010 pjsip_tx_data **p_tdata );
1011
1012
1013 /**
1014 * Create a re-INVITE request.
1015 *
1016 * @param inv The invite session.
1017 * @param new_contact If application wants to update its local contact and
1018 * inform peer to perform target refresh with a new
1019 * contact, it can specify the new contact in this
1020 * argument; otherwise this argument must be NULL.
1021 * @param new_offer Application MAY initiate a new SDP offer/answer
1022 * session in the request when there is no pending
1023 * answer to be sent or received. It can detect this
1024 * condition by observing the state of the SDP
1025 * negotiator of the invite session. If new offer
1026 * should be sent to remote, the offer must be specified
1027 * in this argument, otherwise it must be NULL.
1028 * @param p_tdata Pointer to receive the re-INVITE request message to
1029 * be created.
1030 *
1031 * @return PJ_SUCCESS if a re-INVITE request with the specified
1032 * characteristics (e.g. to contain new offer) can be
1033 * created.
1034 */
1035 PJ_DECL(pj_status_t) pjsip_inv_reinvite(pjsip_inv_session *inv,
1036 const pj_str_t *new_contact,
1037 const pjmedia_sdp_session *new_offer,
1038 pjsip_tx_data **p_tdata );
1039
1040
1041
1042 /**
1043 * Create an UPDATE request to initiate new SDP offer.
1044 *
1045 * @param inv The invite session.
1046 * @param new_contact If application wants to update its local contact
1047 * and inform peer to perform target refresh with a new
1048 * contact, it can specify the new contact in this
1049 * argument; otherwise this argument must be NULL.
1050 * @param offer Offer to be sent to remote. This argument is
1051 * mandatory.
1052 * @param p_tdata Pointer to receive the UPDATE request message to
1053 * be created.
1054 *
1055 * @return PJ_SUCCESS if a UPDATE request with the specified
1056 * characteristics (e.g. to contain new offer) can be
1057 * created.
1058 */
1059 PJ_DECL(pj_status_t) pjsip_inv_update ( pjsip_inv_session *inv,
1060 const pj_str_t *new_contact,
1061 const pjmedia_sdp_session *offer,
1062 pjsip_tx_data **p_tdata );
1063
1064
1065 /**
1066 * Create an ACK request. Normally ACK request transmission is handled
1067 * by the framework. Application only needs to use this function if it
1068 * handles the ACK transmission manually, by overriding \a on_send_ack()
1069 * callback in #pjsip_inv_callback.
1070 *
1071 * Note that if the invite session has a pending offer to be answered
1072 * (for example when the last 2xx response to INVITE contains an offer),
1073 * application MUST have set the SDP answer with #pjsip_inv_set_sdp_answer()
1074 * prior to creating the ACK request. In this case, the ACK request
1075 * will be added with SDP message body.
1076 *
1077 * @param inv The invite session.
1078 * @param cseq Mandatory argument to specify the CSeq of the
1079 * ACK request. This value MUST match the value
1080 * of the INVITE transaction to be acknowledged.
1081 * @param p_tdata Pointer to receive the ACK request message to
1082 * be created.
1083 *
1084 * @return PJ_SUCCESS if ACK request has been created.
1085 */
1086 PJ_DECL(pj_status_t) pjsip_inv_create_ack(pjsip_inv_session *inv,
1087 int cseq,
1088 pjsip_tx_data **p_tdata);
1089
1090
1091 /**
1092 * Send request or response message in tdata.
1093 *
1094 * @param inv The invite session.
1095 * @param tdata The message to be sent.
1096 *
1097 * @return PJ_SUCCESS if transaction can be initiated
1098 * successfully to send this message. Note that the
1099 * actual final state of the transaction itself will
1100 * be reported later, in on_tsx_state_changed()
1101 * callback.
1102 */
1103 PJ_DECL(pj_status_t) pjsip_inv_send_msg(pjsip_inv_session *inv,
1104 pjsip_tx_data *tdata);
1105
1106
1107 /**
1108 * Get the invite session for the dialog, if any.
1109 *
1110 * @param dlg The dialog which invite session is being queried.
1111 *
1112 * @return The invite session instance which has been
1113 * associated with this dialog, or NULL.
1114 */
1115 PJ_DECL(pjsip_inv_session*) pjsip_dlg_get_inv_session(pjsip_dialog *dlg);
1116
1117 /**
1118 * Get the invite session instance associated with transaction tsx, if any.
1119 *
1120 * @param tsx The transaction, which invite session is being
1121 * queried.
1122 *
1123 * @return The invite session instance which has been
1124 * associated with this transaction, or NULL.
1125 */
1126 PJ_DECL(pjsip_inv_session*) pjsip_tsx_get_inv_session(pjsip_transaction *tsx);
1127
1128
1129 /**
1130 * Get state names for INVITE session state.
1131 *
1132 * @param state The invite state.
1133 *
1134 * @return String describing the state.
1135 */
1136 PJ_DECL(const char *) pjsip_inv_state_name(pjsip_inv_state state);
1137
1138
1139 /**
1140 * This is a utility function to create SIP body for SDP content.
1141 *
1142 * @param pool Pool to allocate memory.
1143 * @param sdp SDP session to be put in the SIP message body.
1144 * @param p_body Pointer to receive SIP message body containing
1145 * the SDP session.
1146 *
1147 * @return PJ_SUCCESS on success.
1148 */
1149 PJ_DECL(pj_status_t) pjsip_create_sdp_body(pj_pool_t *pool,
1150 pjmedia_sdp_session *sdp,
1151 pjsip_msg_body **p_body);
1152
1153 /**
1154 * This is a utility function to create a multipart body with the
1155 * SIP body as the first part.
1156 *
1157 * @param pool Pool to allocate memory.
1158 * @param sdp SDP session to be put in the SIP message body.
1159 * @param p_body Pointer to receive SIP message body containing
1160 * the SDP session.
1161 *
1162 * @return PJ_SUCCESS on success.
1163 */
1164 PJ_DECL(pj_status_t) pjsip_create_multipart_sdp_body( pj_pool_t *pool,
1165 pjmedia_sdp_session *sdp,
1166 pjsip_msg_body **p_body);
1167
1168 /**
1169 * Retrieve SDP information from a message body. Application should
1170 * prefer to use this function rather than parsing the SDP manually since
1171 * this function supports multipart message body.
1172 *
1173 * This function will only parse the SDP once, the first time it is called
1174 * on the same message. Subsequent call on the same message will just pick
1175 * up the already parsed SDP from the message.
1176 *
1177 * @param pool Pool to allocate memory.
1178 * @param body The message body.
1179 * @param msg_media_type From the rdata or tdata Content-Type header, if available.
1180 * If NULL, the content_type from the body will be used.
1181 * @param search_media_type The media type to search for.
1182 * If NULL, "application/sdp" will be used.
1183 *
1184 * @return The SDP info.
1185 */
1186 PJ_DECL(pjsip_sdp_info*) pjsip_get_sdp_info(pj_pool_t *pool,
1187 pjsip_msg_body *body,
1188 pjsip_media_type *msg_media_type,
1189 const pjsip_media_type *search_media_type);
1190
1191 /**
1192 * Retrieve SDP information from an incoming message. Application should
1193 * prefer to use this function rather than parsing the SDP manually since
1194 * this function supports multipart message body.
1195 *
1196 * This function will only parse the SDP once, the first time it is called
1197 * on the same message. Subsequent call on the same message will just pick
1198 * up the already parsed SDP from the message.
1199 *
1200 * @param rdata The incoming message.
1201 *
1202 * @return The SDP info.
1203 */
1204 PJ_DECL(pjsip_rdata_sdp_info*) pjsip_rdata_get_sdp_info(pjsip_rx_data *rdata);
1205
1206
1207 /**
1208 * Retrieve SDP information from an incoming message. Application should
1209 * prefer to use this function rather than parsing the SDP manually since
1210 * this function supports multipart message body.
1211 *
1212 * This function will only parse the SDP once, the first time it is called
1213 * on the same message. Subsequent call on the same message will just pick
1214 * up the already parsed SDP from the message.
1215 *
1216 * @param rdata The incoming message.
1217 * @param search_media_type The SDP media type to search for.
1218 * If NULL, "application/sdp" will be used.
1219 *
1220 * @return The SDP info.
1221 */
1222 PJ_DECL(pjsip_rdata_sdp_info*) pjsip_rdata_get_sdp_info2(
1223 pjsip_rx_data *rdata,
1224 const pjsip_media_type *search_media_type);
1225
1226 /**
1227 * Retrieve SDP information from an outgoing message. Application should
1228 * prefer to use this function rather than parsing the SDP manually since
1229 * this function supports multipart message body.
1230 *
1231 * This function will only parse the SDP once, the first time it is called
1232 * on the same message. Subsequent call on the same message will just pick
1233 * up the already parsed SDP from the message.
1234 *
1235 * @param tdata The outgoing message.
1236 *
1237 * @return The SDP info.
1238 */
1239 PJ_DECL(pjsip_tdata_sdp_info*) pjsip_tdata_get_sdp_info(pjsip_tx_data *tdata);
1240
1241 /**
1242 * Retrieve SDP information from an outgoing message. Application should
1243 * prefer to use this function rather than parsing the SDP manually since
1244 * this function supports multipart message body.
1245 *
1246 * This function will only parse the SDP once, the first time it is called
1247 * on the same message. Subsequent call on the same message will just pick
1248 * up the already parsed SDP from the message.
1249 *
1250 * @param tdata The outgoing message.
1251 * @param search_media_type The SDP media type to search for.
1252 * If NULL, "application/sdp" will be used.
1253 *
1254 * @return The SDP info.
1255 */
1256 PJ_DECL(pjsip_tdata_sdp_info*) pjsip_tdata_get_sdp_info2(
1257 pjsip_tx_data *tdata,
1258 const pjsip_media_type *search_media_type);
1259
1260
1261 PJ_END_DECL
1262
1263 /**
1264 * @}
1265 */
1266
1267
1268 #endif /* __SIP_INVITE_SESSION_H__ */