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