| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <pjsip-ua/sip_inv.h> |
| 20 |
#include <pjsip-ua/sip_100rel.h> |
| 21 |
#include <pjsip-ua/sip_timer.h> |
| 22 |
#include <pjsip-ua/sip_siprec.h> |
| 23 |
#include <pjsip/print_util.h> |
| 24 |
#include <pjsip/sip_module.h> |
| 25 |
#include <pjsip/sip_endpoint.h> |
| 26 |
#include <pjsip/sip_event.h> |
| 27 |
#include <pjsip/sip_multipart.h> |
| 28 |
#include <pjsip/sip_transaction.h> |
| 29 |
#include <pjmedia/sdp.h> |
| 30 |
#include <pjmedia/sdp_neg.h> |
| 31 |
#include <pjmedia/errno.h> |
| 32 |
#include <pj/array.h> |
| 33 |
#include <pj/string.h> |
| 34 |
#include <pj/pool.h> |
| 35 |
#include <pj/assert.h> |
| 36 |
#include <pj/os.h> |
| 37 |
#include <pj/log.h> |
| 38 |
#include <pj/rand.h> |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
#define THIS_FILE "sip_inv.c" |
| 64 |
|
| 65 |
static const char *inv_state_names[] = |
| 66 |
{ |
| 67 |
"NULL", |
| 68 |
"CALLING", |
| 69 |
"INCOMING", |
| 70 |
"EARLY", |
| 71 |
"CONNECTING", |
| 72 |
"CONFIRMED", |
| 73 |
"DISCONNECTED", |
| 74 |
"TERMINATED", |
| 75 |
}; |
| 76 |
|
| 77 |
|
| 78 |
static const pjsip_method pjsip_update_method = |
| 79 |
{ |
| 80 |
PJSIP_OTHER_METHOD, |
| 81 |
{ "UPDATE", 6 } |
| 82 |
}; |
| 83 |
|
| 84 |
#define POOL_INIT_SIZE 1000 |
| 85 |
#define POOL_INC_SIZE 1000 |
| 86 |
|
| 87 |
|
| 88 |
void pjsip_inv_process_hparam(pjsip_inv_session *sess, |
| 89 |
const pj_str_t *hname, |
| 90 |
const pj_str_t *hvalue, |
| 91 |
pjsip_tx_data *tdata); |
| 92 |
|
| 93 |
|
| 94 |
void (*pjsip_inv_process_hparam_ptr)(pjsip_inv_session *sess, |
| 95 |
const pj_str_t *hname, |
| 96 |
const pj_str_t *hvalue, |
| 97 |
pjsip_tx_data *tdata) = |
| 98 |
&pjsip_inv_process_hparam; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
static pj_status_t mod_inv_load(pjsip_endpoint *endpt); |
| 104 |
static pj_status_t mod_inv_unload(void); |
| 105 |
static pj_bool_t mod_inv_on_rx_request(pjsip_rx_data *rdata); |
| 106 |
static pj_bool_t mod_inv_on_rx_response(pjsip_rx_data *rdata); |
| 107 |
static void mod_inv_on_tsx_state(pjsip_transaction*, pjsip_event*); |
| 108 |
|
| 109 |
static void inv_on_state_null( pjsip_inv_session *inv, pjsip_event *e); |
| 110 |
static void inv_on_state_calling( pjsip_inv_session *inv, pjsip_event *e); |
| 111 |
static void inv_on_state_incoming( pjsip_inv_session *inv, pjsip_event *e); |
| 112 |
static void inv_on_state_early( pjsip_inv_session *inv, pjsip_event *e); |
| 113 |
static void inv_on_state_connecting( pjsip_inv_session *inv, pjsip_event *e); |
| 114 |
static void inv_on_state_confirmed( pjsip_inv_session *inv, pjsip_event *e); |
| 115 |
static void inv_on_state_disconnected( pjsip_inv_session *inv, pjsip_event *e); |
| 116 |
|
| 117 |
static pj_status_t inv_check_sdp_in_incoming_msg( pjsip_inv_session *inv, |
| 118 |
pjsip_transaction *tsx, |
| 119 |
pjsip_rx_data *rdata); |
| 120 |
static pj_status_t inv_negotiate_sdp( pjsip_inv_session *inv ); |
| 121 |
static pjsip_msg_body *create_sdp_body(pj_pool_t *pool, |
| 122 |
const pjmedia_sdp_session *c_sdp); |
| 123 |
static pj_status_t process_answer( pjsip_inv_session *inv, |
| 124 |
int st_code, |
| 125 |
pjsip_tx_data *tdata, |
| 126 |
const pjmedia_sdp_session *local_sdp); |
| 127 |
|
| 128 |
static pj_status_t handle_timer_response(pjsip_inv_session *inv, |
| 129 |
const pjsip_rx_data *rdata, |
| 130 |
pj_bool_t end_sess_on_failure); |
| 131 |
|
| 132 |
static pj_bool_t inv_check_secure_dlg(pjsip_inv_session *inv, |
| 133 |
pjsip_event *e); |
| 134 |
|
| 135 |
static int print_sdp(pjsip_msg_body *body, char *buf, pj_size_t len); |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
static pj_status_t add_reason_warning_hdr(pjsip_tx_data *tdata, |
| 141 |
unsigned code, |
| 142 |
const pj_str_t *reason); |
| 143 |
|
| 144 |
static pj_status_t inv_async_auth_send_impl( |
| 145 |
pjsip_auth_clt_sess *auth_sess, |
| 146 |
void *user_data, |
| 147 |
pjsip_tx_data *tdata); |
| 148 |
static void inv_bye_auth_abandon_impl( |
| 149 |
pjsip_auth_clt_sess *auth_sess, |
| 150 |
void *user_data); |
| 151 |
static void inv_initial_invite_auth_abandon_impl( |
| 152 |
pjsip_auth_clt_sess *auth_sess, |
| 153 |
void *user_data); |
| 154 |
static void inv_set_state(pjsip_inv_session *inv, pjsip_inv_state state, |
| 155 |
pjsip_event *e); |
| 156 |
static void inv_set_cause(pjsip_inv_session *inv, int cause_code, |
| 157 |
const pj_str_t *cause_text); |
| 158 |
|
| 159 |
static void (*inv_state_handler[])( pjsip_inv_session *inv, pjsip_event *e) = |
| 160 |
{ |
| 161 |
&inv_on_state_null, |
| 162 |
&inv_on_state_calling, |
| 163 |
&inv_on_state_incoming, |
| 164 |
&inv_on_state_early, |
| 165 |
&inv_on_state_connecting, |
| 166 |
&inv_on_state_confirmed, |
| 167 |
&inv_on_state_disconnected, |
| 168 |
}; |
| 169 |
|
| 170 |
static struct mod_inv |
| 171 |
{ |
| 172 |
pjsip_module mod; |
| 173 |
pjsip_endpoint *endpt; |
| 174 |
pjsip_inv_callback cb; |
| 175 |
} mod_inv = |
| 176 |
{ |
| 177 |
{ |
| 178 |
NULL, NULL, |
| 179 |
{ "mod-invite", 10 }, |
| 180 |
-1, |
| 181 |
PJSIP_MOD_PRIORITY_DIALOG_USAGE, |
| 182 |
&mod_inv_load, |
| 183 |
NULL, |
| 184 |
NULL, |
| 185 |
&mod_inv_unload, |
| 186 |
&mod_inv_on_rx_request, |
| 187 |
&mod_inv_on_rx_response, |
| 188 |
NULL, |
| 189 |
NULL, |
| 190 |
&mod_inv_on_tsx_state, |
| 191 |
} |
| 192 |
}; |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
struct tsx_inv_data |
| 197 |
{ |
| 198 |
pjsip_inv_session *inv; |
| 199 |
pj_bool_t sdp_done; |
| 200 |
pj_bool_t retrying; |
| 201 |
pj_str_t done_tag; |
| 202 |
pj_bool_t done_early; |
| 203 |
pj_bool_t done_early_rel; |
| 204 |
pj_bool_t has_sdp; |
| 205 |
}; |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
static pj_status_t add_reason_warning_hdr(pjsip_tx_data *tdata, |
| 212 |
unsigned code, |
| 213 |
const pj_str_t *reason) |
| 214 |
{ |
| 215 |
PJ_ASSERT_RETURN(tdata && reason, PJ_EINVAL); |
| 216 |
|
| 217 |
if (tdata->msg->type == PJSIP_REQUEST_MSG) { |
| 218 |
|
| 219 |
|
| 220 |
pjsip_hdr *hdr; |
| 221 |
const pj_str_t hname = { "Reason", 6 }; |
| 222 |
pj_str_t hvalue; |
| 223 |
pj_size_t hval_len; |
| 224 |
|
| 225 |
PJ_ASSERT_RETURN(tdata && reason && reason->slen >= 0, PJ_EINVAL); |
| 226 |
PJ_ASSERT_RETURN(code < 1000, PJ_EINVAL); |
| 227 |
|
| 228 |
hval_len = 3 + |
| 229 |
11 + |
| 230 |
(pj_size_t)reason->slen + 10; |
| 231 |
hvalue.ptr = (char*)pj_pool_alloc(tdata->pool, hval_len); |
| 232 |
if (!hvalue.ptr) |
| 233 |
return PJ_ENOMEM; |
| 234 |
|
| 235 |
hvalue.slen = pj_ansi_snprintf(hvalue.ptr, hval_len, |
| 236 |
"SIP ;cause=%u ;text=\"%.*s\"", |
| 237 |
code, (int)reason->slen, reason->ptr); |
| 238 |
hdr = (pjsip_hdr*) |
| 239 |
pjsip_generic_string_hdr_create(tdata->pool, &hname, &hvalue); |
| 240 |
if (hdr) |
| 241 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)hdr); |
| 242 |
else |
| 243 |
return PJ_ENOMEM; |
| 244 |
|
| 245 |
} else { |
| 246 |
|
| 247 |
|
| 248 |
pjsip_warning_hdr *hdr; |
| 249 |
pjsip_dialog *dlg = pjsip_tdata_get_dlg(tdata); |
| 250 |
|
| 251 |
|
| 252 |
unsigned warn_code = 390; |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
PJ_ASSERT_RETURN(dlg, PJ_EINVAL); |
| 257 |
|
| 258 |
hdr = pjsip_warning_hdr_create(tdata->pool, warn_code, |
| 259 |
pjsip_endpt_name(dlg->endpt), reason); |
| 260 |
if (hdr) |
| 261 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)hdr); |
| 262 |
else |
| 263 |
return PJ_ENOMEM; |
| 264 |
} |
| 265 |
|
| 266 |
return PJ_SUCCESS; |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
static pj_status_t mod_inv_load(pjsip_endpoint *endpt) |
| 274 |
{ |
| 275 |
pj_str_t allowed[] = {{"INVITE", 6}, {"ACK",3}, {"BYE",3}, {"CANCEL",6}, |
| 276 |
{ "UPDATE", 6}}; |
| 277 |
pj_str_t accepted = { "application/sdp", 15 }; |
| 278 |
|
| 279 |
|
| 280 |
pjsip_endpt_add_capability(endpt, &mod_inv.mod, PJSIP_H_ALLOW, NULL, |
| 281 |
PJ_ARRAY_SIZE(allowed), allowed); |
| 282 |
|
| 283 |
|
| 284 |
pjsip_endpt_add_capability(endpt, &mod_inv.mod, PJSIP_H_ACCEPT, NULL, |
| 285 |
1, &accepted); |
| 286 |
|
| 287 |
return PJ_SUCCESS; |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
static pj_status_t mod_inv_unload(void) |
| 294 |
{ |
| 295 |
|
| 296 |
return PJ_SUCCESS; |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
PJ_DEF(pj_status_t) pjsip_inv_add_ref( pjsip_inv_session *inv ) |
| 303 |
{ |
| 304 |
PJ_ASSERT_RETURN(inv && inv->ref_cnt, PJ_EINVAL); |
| 305 |
|
| 306 |
pj_atomic_inc(inv->ref_cnt); |
| 307 |
|
| 308 |
return PJ_SUCCESS; |
| 309 |
} |
| 310 |
|
| 311 |
static void inv_session_destroy(pjsip_inv_session *inv) |
| 312 |
{ |
| 313 |
if (inv->last_ack) { |
| 314 |
pjsip_tx_data_dec_ref(inv->last_ack); |
| 315 |
inv->last_ack = NULL; |
| 316 |
} |
| 317 |
if (inv->invite_req) { |
| 318 |
pjsip_tx_data_dec_ref(inv->invite_req); |
| 319 |
inv->invite_req = NULL; |
| 320 |
} |
| 321 |
if (inv->pending_bye) { |
| 322 |
pjsip_tx_data_dec_ref(inv->pending_bye); |
| 323 |
inv->pending_bye = NULL; |
| 324 |
} |
| 325 |
pjsip_100rel_end_session(inv); |
| 326 |
pjsip_timer_end_session(inv); |
| 327 |
pjsip_dlg_dec_session(inv->dlg, &mod_inv.mod); |
| 328 |
|
| 329 |
|
| 330 |
pj_pool_release(inv->pool_prov); |
| 331 |
inv->pool_prov = NULL; |
| 332 |
pj_pool_release(inv->pool_active); |
| 333 |
inv->pool_active = NULL; |
| 334 |
|
| 335 |
pj_atomic_destroy(inv->ref_cnt); |
| 336 |
inv->ref_cnt = NULL; |
| 337 |
} |
| 338 |
|
| 339 |
static pj_status_t inv_async_auth_send_impl( |
| 340 |
pjsip_auth_clt_sess *auth_sess, |
| 341 |
void *user_data, |
| 342 |
pjsip_tx_data *tdata) |
| 343 |
{ |
| 344 |
pjsip_inv_session *inv = (pjsip_inv_session *)user_data; |
| 345 |
PJ_UNUSED_ARG(auth_sess); |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
if (tdata->msg->line.req.method.id == PJSIP_INVITE_METHOD && |
| 352 |
inv->state != PJSIP_INV_STATE_CONFIRMED) |
| 353 |
{ |
| 354 |
pjsip_inv_uac_restart(inv, PJ_FALSE); |
| 355 |
} |
| 356 |
return pjsip_inv_send_msg(inv, tdata); |
| 357 |
} |
| 358 |
|
| 359 |
|
| 360 |
static void inv_bye_auth_abandon_impl(pjsip_auth_clt_sess *auth_sess, |
| 361 |
void *user_data) |
| 362 |
{ |
| 363 |
pjsip_inv_session *inv = (pjsip_inv_session *)user_data; |
| 364 |
pjsip_event usr_event; |
| 365 |
|
| 366 |
PJ_UNUSED_ARG(auth_sess); |
| 367 |
PJSIP_EVENT_INIT_USER(usr_event, NULL, NULL, NULL, NULL); |
| 368 |
inv_set_cause(inv, PJSIP_SC_OK, NULL); |
| 369 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, &usr_event); |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
static void inv_initial_invite_auth_abandon_impl( |
| 374 |
pjsip_auth_clt_sess *auth_sess, |
| 375 |
void *user_data) |
| 376 |
{ |
| 377 |
pjsip_inv_session *inv = (pjsip_inv_session *)user_data; |
| 378 |
pjsip_event usr_event; |
| 379 |
|
| 380 |
PJ_UNUSED_ARG(auth_sess); |
| 381 |
PJSIP_EVENT_INIT_USER(usr_event, NULL, NULL, NULL, NULL); |
| 382 |
inv_set_cause(inv, PJSIP_SC_UNAUTHORIZED, NULL); |
| 383 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, &usr_event); |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
PJ_DEF(pj_status_t) pjsip_inv_dec_ref( pjsip_inv_session *inv ) |
| 391 |
{ |
| 392 |
pj_atomic_value_t ref_cnt; |
| 393 |
|
| 394 |
PJ_ASSERT_RETURN(inv && inv->ref_cnt, PJ_EINVAL); |
| 395 |
|
| 396 |
ref_cnt = pj_atomic_dec_and_get(inv->ref_cnt); |
| 397 |
pj_assert( ref_cnt >= 0); |
| 398 |
if (ref_cnt == 0) { |
| 399 |
inv_session_destroy(inv); |
| 400 |
return PJ_EGONE; |
| 401 |
} |
| 402 |
return PJ_SUCCESS; |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
static void inv_set_state(pjsip_inv_session *inv, pjsip_inv_state state, |
| 409 |
pjsip_event *e) |
| 410 |
{ |
| 411 |
pjsip_inv_state prev_state = inv->state; |
| 412 |
pj_bool_t dont_notify = PJ_FALSE; |
| 413 |
pj_status_t status; |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
if (state==PJSIP_INV_STATE_CALLING && |
| 420 |
(inv->cb_called & (1 << PJSIP_INV_STATE_CALLING)) != 0) |
| 421 |
{ |
| 422 |
dont_notify = PJ_TRUE; |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
if (state == PJSIP_INV_STATE_CONFIRMED) { |
| 429 |
struct tsx_inv_data *tsx_inv_data = NULL; |
| 430 |
|
| 431 |
if (inv->invite_tsx) { |
| 432 |
tsx_inv_data = (struct tsx_inv_data*) |
| 433 |
inv->invite_tsx->mod_data[mod_inv.mod.id]; |
| 434 |
} |
| 435 |
|
| 436 |
if ((tsx_inv_data && !tsx_inv_data->sdp_done) && |
| 437 |
(!inv->neg || pjmedia_sdp_neg_get_state(inv->neg)!= |
| 438 |
PJMEDIA_SDP_NEG_STATE_DONE)) |
| 439 |
{ |
| 440 |
pjsip_tx_data *bye; |
| 441 |
pj_str_t reason = pj_str("SDP offer/answer incomplete"); |
| 442 |
|
| 443 |
PJ_LOG(4,(inv->obj_name, "SDP offer/answer incomplete, ending the " |
| 444 |
"session")); |
| 445 |
|
| 446 |
status = pjsip_inv_end_session(inv, PJSIP_SC_NOT_ACCEPTABLE, |
| 447 |
&reason, &bye); |
| 448 |
if (status == PJ_SUCCESS && bye) |
| 449 |
status = pjsip_inv_send_msg(inv, bye); |
| 450 |
|
| 451 |
return; |
| 452 |
} |
| 453 |
} |
| 454 |
|
| 455 |
PJ_LOG(5, (inv->obj_name, "State changed from %s to %s, event=%s", |
| 456 |
inv_state_names[inv->state], inv_state_names[state], |
| 457 |
pjsip_event_str(e->type))); |
| 458 |
|
| 459 |
|
| 460 |
inv->state = state; |
| 461 |
|
| 462 |
|
| 463 |
pj_assert(inv->state != PJSIP_INV_STATE_DISCONNECTED || |
| 464 |
inv->cause != 0); |
| 465 |
|
| 466 |
|
| 467 |
inv->cb_called |= (1 << state); |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
pjsip_inv_add_ref(inv); |
| 475 |
if (mod_inv.cb.on_state_changed && inv->notify && !dont_notify) |
| 476 |
(*mod_inv.cb.on_state_changed)(inv, e); |
| 477 |
pjsip_inv_dec_ref(inv); |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
if (state == PJSIP_INV_STATE_DISCONNECTED && |
| 490 |
prev_state != PJSIP_INV_STATE_DISCONNECTED && |
| 491 |
inv->state == PJSIP_INV_STATE_DISCONNECTED) |
| 492 |
{ |
| 493 |
pjsip_inv_dec_ref(inv); |
| 494 |
} |
| 495 |
} |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
static void inv_set_cause(pjsip_inv_session *inv, int cause_code, |
| 502 |
const pj_str_t *cause_text) |
| 503 |
{ |
| 504 |
if ((cause_code > (int)inv->cause) || inv->pending_bye) { |
| 505 |
inv->cause = (pjsip_status_code) cause_code; |
| 506 |
if (cause_text) |
| 507 |
pj_strdup(inv->pool, &inv->cause_text, cause_text); |
| 508 |
else if (cause_code/100 == 2) |
| 509 |
inv->cause_text = pj_str("Normal call clearing"); |
| 510 |
else |
| 511 |
inv->cause_text = *pjsip_get_status_text(cause_code); |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
static const pjmedia_sdp_session *inv_has_pending_answer(pjsip_inv_session *inv, |
| 521 |
pjsip_transaction *tsx) |
| 522 |
{ |
| 523 |
pjmedia_sdp_neg_state neg_state; |
| 524 |
const pjmedia_sdp_session *sdp = NULL; |
| 525 |
pj_status_t status; |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
neg_state = inv->neg ? pjmedia_sdp_neg_get_state(inv->neg) : |
| 531 |
PJMEDIA_SDP_NEG_STATE_NULL; |
| 532 |
|
| 533 |
if (neg_state == PJMEDIA_SDP_NEG_STATE_DONE) { |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
} else if (neg_state == PJMEDIA_SDP_NEG_STATE_WAIT_NEGO && |
| 538 |
pjmedia_sdp_neg_has_local_answer(inv->neg) ) |
| 539 |
{ |
| 540 |
struct tsx_inv_data *tsx_inv_data; |
| 541 |
struct tsx_inv_data dummy; |
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
if (tsx) { |
| 549 |
tsx_inv_data = (struct tsx_inv_data*)tsx->mod_data[mod_inv.mod.id]; |
| 550 |
} else { |
| 551 |
tsx_inv_data = &dummy; |
| 552 |
pj_bzero(&dummy, sizeof(dummy)); |
| 553 |
dummy.inv = inv; |
| 554 |
} |
| 555 |
|
| 556 |
status = inv_negotiate_sdp(inv); |
| 557 |
if (status != PJ_SUCCESS) |
| 558 |
return NULL; |
| 559 |
|
| 560 |
|
| 561 |
tsx_inv_data->sdp_done = 1; |
| 562 |
|
| 563 |
status = pjmedia_sdp_neg_get_active_local(inv->neg, &sdp); |
| 564 |
|
| 565 |
} else { |
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
} |
| 573 |
|
| 574 |
return sdp; |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
static void inv_perform_pending_bye(pjsip_inv_session *inv) |
| 581 |
{ |
| 582 |
if (inv->pending_bye) { |
| 583 |
pjsip_tx_data *bye = inv->pending_bye; |
| 584 |
pj_status_t status; |
| 585 |
|
| 586 |
PJ_LOG(4,(inv->dlg->obj_name, "Sending pending BYE")); |
| 587 |
|
| 588 |
inv->pending_bye = NULL; |
| 589 |
status = pjsip_inv_send_msg(inv, bye); |
| 590 |
|
| 591 |
if (status != PJ_SUCCESS) { |
| 592 |
PJ_PERROR(1,(inv->dlg->obj_name, status, |
| 593 |
"Failed sending pending BYE")); |
| 594 |
} |
| 595 |
} |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
static pj_status_t inv_send_ack(pjsip_inv_session *inv, pjsip_event *e) |
| 602 |
{ |
| 603 |
pjsip_rx_data *rdata; |
| 604 |
pjsip_event ack_e; |
| 605 |
pj_status_t status; |
| 606 |
|
| 607 |
if (e->type == PJSIP_EVENT_TSX_STATE) |
| 608 |
rdata = e->body.tsx_state.src.rdata; |
| 609 |
else if (e->type == PJSIP_EVENT_RX_MSG) |
| 610 |
rdata = e->body.rx_msg.rdata; |
| 611 |
else { |
| 612 |
pj_assert(!"Unsupported event type"); |
| 613 |
return PJ_EBUG; |
| 614 |
} |
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
PJ_LOG(5,(inv->obj_name, "Received %s, sending ACK", |
| 622 |
pjsip_rx_data_get_info(rdata))); |
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
if (inv->last_ack && rdata->msg_info.cseq->cseq == inv->last_ack_cseq && |
| 629 |
inv->last_ack->tp_info.transport != NULL && |
| 630 |
!inv->last_ack->is_pending) |
| 631 |
{ |
| 632 |
pjsip_tx_data_add_ref(inv->last_ack); |
| 633 |
|
| 634 |
} else if (mod_inv.cb.on_send_ack) { |
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
PJ_LOG(5,(inv->obj_name, "Received %s, notifying application callback", |
| 639 |
pjsip_rx_data_get_info(rdata))); |
| 640 |
|
| 641 |
(*mod_inv.cb.on_send_ack)(inv, rdata); |
| 642 |
return PJ_SUCCESS; |
| 643 |
|
| 644 |
} else { |
| 645 |
status = pjsip_inv_create_ack(inv, rdata->msg_info.cseq->cseq, |
| 646 |
&inv->last_ack); |
| 647 |
if (status != PJ_SUCCESS) |
| 648 |
return status; |
| 649 |
} |
| 650 |
|
| 651 |
PJSIP_EVENT_INIT_TX_MSG(ack_e, inv->last_ack); |
| 652 |
|
| 653 |
|
| 654 |
status = pjsip_dlg_send_request(inv->dlg, inv->last_ack, -1, NULL); |
| 655 |
if (status != PJ_SUCCESS) { |
| 656 |
|
| 657 |
pj_assert(!"Unable to send ACK!"); |
| 658 |
return status; |
| 659 |
} |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
if (inv->state < PJSIP_INV_STATE_CONFIRMED) { |
| 667 |
inv_set_state(inv, PJSIP_INV_STATE_CONFIRMED, &ack_e); |
| 668 |
} else if (inv->state == PJSIP_INV_STATE_DISCONNECTED && inv->last_ack) { |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
pjsip_tx_data_dec_ref(inv->last_ack); |
| 674 |
inv->last_ack = NULL; |
| 675 |
} |
| 676 |
|
| 677 |
return PJ_SUCCESS; |
| 678 |
} |
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
static pj_bool_t mod_inv_on_rx_request(pjsip_rx_data *rdata) |
| 689 |
{ |
| 690 |
pjsip_method *method; |
| 691 |
pjsip_dialog *dlg; |
| 692 |
pjsip_inv_session *inv; |
| 693 |
|
| 694 |
|
| 695 |
dlg = pjsip_rdata_get_dlg(rdata); |
| 696 |
if (dlg == NULL) |
| 697 |
return PJ_FALSE; |
| 698 |
|
| 699 |
inv = (pjsip_inv_session*) dlg->mod_data[mod_inv.mod.id]; |
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
method = &rdata->msg_info.msg->line.req.method; |
| 706 |
|
| 707 |
if (method->id == PJSIP_INVITE_METHOD) { |
| 708 |
return PJ_TRUE; |
| 709 |
} |
| 710 |
|
| 711 |
|
| 712 |
if (method->id == PJSIP_BYE_METHOD || |
| 713 |
method->id == PJSIP_CANCEL_METHOD) |
| 714 |
{ |
| 715 |
if (inv == NULL) |
| 716 |
return PJ_FALSE; |
| 717 |
|
| 718 |
return PJ_TRUE; |
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
if (method->id == PJSIP_ACK_METHOD && inv) { |
| 725 |
|
| 726 |
|
| 727 |
if (!inv->invite_tsx) { |
| 728 |
return PJ_TRUE; |
| 729 |
} |
| 730 |
|
| 731 |
|
| 732 |
if (inv->invite_tsx->state < PJSIP_TSX_STATE_COMPLETED) { |
| 733 |
return PJ_TRUE; |
| 734 |
} |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
if (rdata->msg_info.cseq->cseq != inv->invite_tsx->cseq) { |
| 740 |
return PJ_TRUE; |
| 741 |
} |
| 742 |
|
| 743 |
|
| 744 |
if (inv->invite_tsx->state <= PJSIP_TSX_STATE_COMPLETED) { |
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
if (inv->state < PJSIP_INV_STATE_DISCONNECTED) { |
| 751 |
inv_check_sdp_in_incoming_msg(inv, inv->invite_tsx, rdata); |
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
if (pjmedia_sdp_neg_get_state(inv->neg)== |
| 757 |
PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER && |
| 758 |
inv->state==PJSIP_INV_STATE_CONFIRMED) |
| 759 |
{ |
| 760 |
pjmedia_sdp_neg_cancel_offer(inv->neg); |
| 761 |
} |
| 762 |
} |
| 763 |
|
| 764 |
|
| 765 |
if (inv->invite_tsx->status_code/100 == 2) { |
| 766 |
|
| 767 |
pjsip_tsx_stop_retransmit(inv->invite_tsx); |
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
pjsip_tsx_terminate_async2(inv->invite_tsx, |
| 774 |
inv->invite_tsx->status_code, |
| 775 |
NULL, |
| 776 |
pjsip_cfg()->tsx.td); |
| 777 |
} else { |
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
pjsip_tsx_terminate_async(inv->invite_tsx, |
| 786 |
inv->invite_tsx->status_code); |
| 787 |
} |
| 788 |
inv->invite_tsx = NULL; |
| 789 |
|
| 790 |
if (inv->last_answer) { |
| 791 |
pjsip_tx_data_dec_ref(inv->last_answer); |
| 792 |
inv->last_answer = NULL; |
| 793 |
} |
| 794 |
} |
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
if (inv->state == PJSIP_INV_STATE_CONNECTING) { |
| 801 |
pjsip_event event; |
| 802 |
|
| 803 |
PJSIP_EVENT_INIT_RX_MSG(event, rdata); |
| 804 |
inv_set_state(inv, PJSIP_INV_STATE_CONFIRMED, &event); |
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
if (inv->pending_bye) |
| 812 |
inv_perform_pending_bye(inv); |
| 813 |
} |
| 814 |
} |
| 815 |
|
| 816 |
return PJ_FALSE; |
| 817 |
} |
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
static pj_status_t handle_timer_response(pjsip_inv_session *inv, |
| 823 |
const pjsip_rx_data *rdata, |
| 824 |
pj_bool_t end_sess_on_failure) |
| 825 |
{ |
| 826 |
pjsip_status_code st_code; |
| 827 |
pj_status_t status; |
| 828 |
|
| 829 |
status = pjsip_timer_process_resp(inv, rdata, &st_code); |
| 830 |
if (status != PJ_SUCCESS && end_sess_on_failure) { |
| 831 |
pjsip_tx_data *tdata; |
| 832 |
pj_status_t status2; |
| 833 |
pj_str_t reason = pj_str("Failed processing session timer response"); |
| 834 |
|
| 835 |
status2 = pjsip_inv_end_session(inv, st_code, &reason, &tdata); |
| 836 |
if (tdata && status2 == PJ_SUCCESS) |
| 837 |
pjsip_inv_send_msg(inv, tdata); |
| 838 |
} |
| 839 |
|
| 840 |
return status; |
| 841 |
} |
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
static pj_bool_t mod_inv_on_rx_response(pjsip_rx_data *rdata) |
| 852 |
{ |
| 853 |
pjsip_dialog *dlg; |
| 854 |
pjsip_inv_session *inv; |
| 855 |
pjsip_msg *msg = rdata->msg_info.msg; |
| 856 |
|
| 857 |
dlg = pjsip_rdata_get_dlg(rdata); |
| 858 |
|
| 859 |
|
| 860 |
if (dlg == NULL) |
| 861 |
return PJ_FALSE; |
| 862 |
|
| 863 |
|
| 864 |
inv = pjsip_dlg_get_inv_session(dlg); |
| 865 |
if (inv == NULL) |
| 866 |
return PJ_FALSE; |
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
if (msg->type == PJSIP_RESPONSE_MSG && msg->line.status.code/100==2 && |
| 872 |
rdata->msg_info.cseq->method.id == PJSIP_INVITE_METHOD) |
| 873 |
{ |
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
if (inv->invite_tsx == NULL || |
| 883 |
inv->state == PJSIP_INV_STATE_DISCONNECTED || |
| 884 |
(inv->last_ack && inv->last_ack_cseq==rdata->msg_info.cseq->cseq)) |
| 885 |
{ |
| 886 |
pjsip_event e; |
| 887 |
|
| 888 |
PJSIP_EVENT_INIT_RX_MSG(e, rdata); |
| 889 |
inv_send_ack(inv, &e); |
| 890 |
return PJ_TRUE; |
| 891 |
} |
| 892 |
} |
| 893 |
|
| 894 |
|
| 895 |
return PJ_FALSE; |
| 896 |
} |
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
static void mod_inv_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e) |
| 905 |
{ |
| 906 |
pjsip_dialog *dlg; |
| 907 |
pjsip_inv_session *inv; |
| 908 |
pj_bool_t cb_called = PJ_FALSE; |
| 909 |
|
| 910 |
dlg = pjsip_tsx_get_dlg(tsx); |
| 911 |
if (dlg == NULL) |
| 912 |
return; |
| 913 |
|
| 914 |
inv = pjsip_dlg_get_inv_session(dlg); |
| 915 |
if (inv == NULL) |
| 916 |
return; |
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
if (mod_inv.cb.on_tsx_state_changed && inv->notify && |
| 923 |
e->body.tsx_state.tsx->state == PJSIP_TSX_STATE_TRYING) |
| 924 |
{ |
| 925 |
cb_called = PJ_TRUE; |
| 926 |
(*mod_inv.cb.on_tsx_state_changed)(inv, tsx, e); |
| 927 |
} |
| 928 |
|
| 929 |
|
| 930 |
(*inv_state_handler[inv->state])(inv, e); |
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
if (tsx->state==PJSIP_TSX_STATE_TERMINATED && tsx == inv->invite_tsx) { |
| 937 |
inv->invite_tsx = NULL; |
| 938 |
|
| 939 |
if (inv->last_answer) { |
| 940 |
pjsip_tx_data_dec_ref(inv->last_answer); |
| 941 |
inv->last_answer = NULL; |
| 942 |
} |
| 943 |
} |
| 944 |
|
| 945 |
|
| 946 |
if (mod_inv.cb.on_tsx_state_changed && inv->notify && !cb_called) { |
| 947 |
(*mod_inv.cb.on_tsx_state_changed)(inv, tsx, e); |
| 948 |
} |
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
if (tsx->state>=PJSIP_TSX_STATE_CONFIRMED && tsx == inv->invite_tsx) { |
| 956 |
inv->invite_tsx = NULL; |
| 957 |
|
| 958 |
if (inv->last_answer) { |
| 959 |
pjsip_tx_data_dec_ref(inv->last_answer); |
| 960 |
inv->last_answer = NULL; |
| 961 |
} |
| 962 |
} |
| 963 |
} |
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
static pj_bool_t tx_data_has_sdp(const pjsip_tx_data *tdata) |
| 969 |
{ |
| 970 |
pjsip_msg_body *body = tdata->msg->body; |
| 971 |
pjsip_media_type app_sdp; |
| 972 |
|
| 973 |
PJ_ASSERT_RETURN(tdata, PJ_FALSE); |
| 974 |
|
| 975 |
pjsip_media_type_init2(&app_sdp, "application", "sdp"); |
| 976 |
|
| 977 |
if (body && |
| 978 |
pj_stricmp(&body->content_type.type, &app_sdp.type)==0 && |
| 979 |
pj_stricmp(&body->content_type.subtype, &app_sdp.subtype)==0) |
| 980 |
{ |
| 981 |
return PJ_TRUE; |
| 982 |
|
| 983 |
} else if (body && |
| 984 |
pj_stricmp2(&body->content_type.type, "multipart") && |
| 985 |
(pj_stricmp2(&body->content_type.subtype, "mixed")==0 || |
| 986 |
pj_stricmp2(&body->content_type.subtype, "alternative")==0)) |
| 987 |
{ |
| 988 |
pjsip_multipart_part *part; |
| 989 |
|
| 990 |
part = pjsip_multipart_find_part(body, &app_sdp, NULL); |
| 991 |
if (part) { |
| 992 |
return PJ_TRUE; |
| 993 |
} |
| 994 |
} |
| 995 |
|
| 996 |
return PJ_FALSE; |
| 997 |
} |
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
PJ_DEF(pj_status_t) pjsip_inv_usage_init( pjsip_endpoint *endpt, |
| 1004 |
const pjsip_inv_callback *cb) |
| 1005 |
{ |
| 1006 |
pj_status_t status; |
| 1007 |
|
| 1008 |
|
| 1009 |
PJ_ASSERT_RETURN(endpt && cb, PJ_EINVAL); |
| 1010 |
|
| 1011 |
|
| 1012 |
PJ_ASSERT_RETURN(cb->on_state_changed, PJ_EINVAL); |
| 1013 |
|
| 1014 |
|
| 1015 |
PJ_ASSERT_RETURN(mod_inv.mod.id == -1, PJ_EINVALIDOP); |
| 1016 |
|
| 1017 |
|
| 1018 |
pj_memcpy(&mod_inv.cb, cb, sizeof(pjsip_inv_callback)); |
| 1019 |
|
| 1020 |
mod_inv.endpt = endpt; |
| 1021 |
|
| 1022 |
|
| 1023 |
status = pjsip_endpt_register_module(endpt, &mod_inv.mod); |
| 1024 |
if (status != PJ_SUCCESS) |
| 1025 |
return status; |
| 1026 |
|
| 1027 |
return PJ_SUCCESS; |
| 1028 |
} |
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
PJ_DEF(pjsip_module*) pjsip_inv_usage_instance(void) |
| 1034 |
{ |
| 1035 |
return &mod_inv.mod; |
| 1036 |
} |
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
PJ_DEF(pjsip_inv_session*) pjsip_dlg_get_inv_session(pjsip_dialog *dlg) |
| 1044 |
{ |
| 1045 |
return (pjsip_inv_session*) dlg->mod_data[mod_inv.mod.id]; |
| 1046 |
} |
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
PJ_DEF(const char *) pjsip_inv_state_name(pjsip_inv_state state) |
| 1053 |
{ |
| 1054 |
PJ_ASSERT_RETURN(state >= PJSIP_INV_STATE_NULL && |
| 1055 |
state <= PJSIP_INV_STATE_DISCONNECTED, |
| 1056 |
"??"); |
| 1057 |
|
| 1058 |
return inv_state_names[state]; |
| 1059 |
} |
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
PJ_DEF(pj_status_t) pjsip_inv_create_uac( pjsip_dialog *dlg, |
| 1065 |
const pjmedia_sdp_session *local_sdp, |
| 1066 |
unsigned options, |
| 1067 |
pjsip_inv_session **p_inv) |
| 1068 |
{ |
| 1069 |
pjsip_inv_session *inv; |
| 1070 |
pj_status_t status; |
| 1071 |
|
| 1072 |
|
| 1073 |
PJ_ASSERT_RETURN(dlg && p_inv, PJ_EINVAL); |
| 1074 |
|
| 1075 |
|
| 1076 |
pjsip_dlg_inc_lock(dlg); |
| 1077 |
|
| 1078 |
|
| 1079 |
if (options & PJSIP_INV_REQUIRE_100REL) |
| 1080 |
options |= PJSIP_INV_SUPPORT_100REL; |
| 1081 |
if (options & PJSIP_INV_REQUIRE_TIMER) |
| 1082 |
options |= PJSIP_INV_SUPPORT_TIMER; |
| 1083 |
if (options & PJSIP_INV_REQUIRE_TRICKLE_ICE) |
| 1084 |
options |= PJSIP_INV_SUPPORT_TRICKLE_ICE; |
| 1085 |
|
| 1086 |
|
| 1087 |
inv = PJ_POOL_ZALLOC_T(dlg->pool, pjsip_inv_session); |
| 1088 |
pj_assert(inv != NULL); |
| 1089 |
|
| 1090 |
status = pj_atomic_create(dlg->pool, 0, &inv->ref_cnt); |
| 1091 |
if (status != PJ_SUCCESS) { |
| 1092 |
pjsip_dlg_dec_lock(dlg); |
| 1093 |
return status; |
| 1094 |
} |
| 1095 |
|
| 1096 |
inv->pool = dlg->pool; |
| 1097 |
inv->role = PJSIP_ROLE_UAC; |
| 1098 |
inv->state = PJSIP_INV_STATE_NULL; |
| 1099 |
inv->dlg = dlg; |
| 1100 |
inv->options = options; |
| 1101 |
inv->notify = PJ_TRUE; |
| 1102 |
inv->cause = (pjsip_status_code) 0; |
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
pj_ansi_snprintf(inv->obj_name, PJ_MAX_OBJ_NAME, "inv%p", dlg->pool); |
| 1107 |
inv->pool_prov = pjsip_endpt_create_pool(dlg->endpt, inv->obj_name, |
| 1108 |
POOL_INIT_SIZE, POOL_INC_SIZE); |
| 1109 |
inv->pool_active = pjsip_endpt_create_pool(dlg->endpt, inv->obj_name, |
| 1110 |
POOL_INIT_SIZE, POOL_INC_SIZE); |
| 1111 |
|
| 1112 |
|
| 1113 |
pj_ansi_snprintf(inv->obj_name, PJ_MAX_OBJ_NAME, "inv%p", dlg); |
| 1114 |
|
| 1115 |
|
| 1116 |
if (local_sdp) { |
| 1117 |
status = pjmedia_sdp_neg_create_w_local_offer(inv->pool, |
| 1118 |
local_sdp, &inv->neg); |
| 1119 |
if (status != PJ_SUCCESS) { |
| 1120 |
pjsip_dlg_dec_lock(dlg); |
| 1121 |
return status; |
| 1122 |
} |
| 1123 |
} |
| 1124 |
|
| 1125 |
|
| 1126 |
status = pjsip_dlg_add_usage(dlg, &mod_inv.mod, inv); |
| 1127 |
if (status != PJ_SUCCESS) { |
| 1128 |
pjsip_dlg_dec_lock(dlg); |
| 1129 |
return status; |
| 1130 |
} |
| 1131 |
|
| 1132 |
|
| 1133 |
pjsip_dlg_inc_session(dlg, &mod_inv.mod); |
| 1134 |
|
| 1135 |
|
| 1136 |
pjsip_100rel_attach(inv); |
| 1137 |
|
| 1138 |
|
| 1139 |
pjsip_inv_add_ref(inv); |
| 1140 |
*p_inv = inv; |
| 1141 |
|
| 1142 |
pjsip_dlg_dec_lock(dlg); |
| 1143 |
|
| 1144 |
PJ_LOG(5,(inv->obj_name, "UAC invite session created for dialog %s", |
| 1145 |
dlg->obj_name)); |
| 1146 |
|
| 1147 |
return PJ_SUCCESS; |
| 1148 |
} |
| 1149 |
|
| 1150 |
PJ_DEF(pjsip_sdp_info*) pjsip_get_sdp_info(pj_pool_t *pool, |
| 1151 |
pjsip_msg_body *body, |
| 1152 |
pjsip_media_type *msg_media_type, |
| 1153 |
const pjsip_media_type *search_media_type) |
| 1154 |
{ |
| 1155 |
pjsip_sdp_info *sdp_info; |
| 1156 |
pjsip_media_type search_type; |
| 1157 |
pjsip_media_type multipart_mixed; |
| 1158 |
pjsip_media_type multipart_alternative; |
| 1159 |
pjsip_media_type *msg_type; |
| 1160 |
pj_status_t status; |
| 1161 |
|
| 1162 |
sdp_info = PJ_POOL_ZALLOC_T(pool, |
| 1163 |
pjsip_sdp_info); |
| 1164 |
|
| 1165 |
PJ_ASSERT_RETURN(mod_inv.mod.id >= 0, sdp_info); |
| 1166 |
|
| 1167 |
if (!body) { |
| 1168 |
return sdp_info; |
| 1169 |
} |
| 1170 |
|
| 1171 |
if (msg_media_type) { |
| 1172 |
msg_type = msg_media_type; |
| 1173 |
} else { |
| 1174 |
if (body->content_type.type.slen == 0) { |
| 1175 |
return sdp_info; |
| 1176 |
} |
| 1177 |
msg_type = &body->content_type; |
| 1178 |
} |
| 1179 |
|
| 1180 |
if (!search_media_type) { |
| 1181 |
pjsip_media_type_init2(&search_type, "application", "sdp"); |
| 1182 |
} else { |
| 1183 |
pj_memcpy(&search_type, search_media_type, sizeof(search_type)); |
| 1184 |
} |
| 1185 |
|
| 1186 |
pjsip_media_type_init2(&multipart_mixed, "multipart", "mixed"); |
| 1187 |
pjsip_media_type_init2(&multipart_alternative, "multipart", "alternative"); |
| 1188 |
|
| 1189 |
if (pjsip_media_type_cmp(msg_type, &search_type, PJ_FALSE) == 0) |
| 1190 |
{ |
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
if (body->print_body == print_sdp) { |
| 1198 |
sdp_info->sdp = body->data; |
| 1199 |
} else { |
| 1200 |
sdp_info->body.ptr = (char*)body->data; |
| 1201 |
sdp_info->body.slen = body->len; |
| 1202 |
} |
| 1203 |
} else if (pjsip_media_type_cmp(&multipart_mixed, msg_type, PJ_FALSE) == 0 || |
| 1204 |
pjsip_media_type_cmp(&multipart_alternative, msg_type, PJ_FALSE) == 0) |
| 1205 |
{ |
| 1206 |
pjsip_multipart_part *part; |
| 1207 |
part = pjsip_multipart_find_part(body, &search_type, NULL); |
| 1208 |
if (part) { |
| 1209 |
if (part->body->print_body == print_sdp) { |
| 1210 |
sdp_info->sdp = part->body->data; |
| 1211 |
} else { |
| 1212 |
sdp_info->body.ptr = (char*)part->body->data; |
| 1213 |
sdp_info->body.slen = part->body->len; |
| 1214 |
} |
| 1215 |
} |
| 1216 |
} |
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
if (sdp_info->sdp || !sdp_info->body.ptr) { |
| 1224 |
return sdp_info; |
| 1225 |
} |
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
status = pjmedia_sdp_parse(pool, |
| 1232 |
sdp_info->body.ptr, |
| 1233 |
sdp_info->body.slen, |
| 1234 |
&sdp_info->sdp); |
| 1235 |
if (status == PJ_SUCCESS) |
| 1236 |
status = pjmedia_sdp_validate2(sdp_info->sdp, PJ_FALSE); |
| 1237 |
|
| 1238 |
if (status != PJ_SUCCESS) { |
| 1239 |
sdp_info->sdp = NULL; |
| 1240 |
PJ_PERROR(1, (THIS_FILE, status, |
| 1241 |
"Error parsing/validating SDP body")); |
| 1242 |
} |
| 1243 |
|
| 1244 |
sdp_info->sdp_err = status; |
| 1245 |
|
| 1246 |
return sdp_info; |
| 1247 |
} |
| 1248 |
|
| 1249 |
PJ_DEF(pjsip_rdata_sdp_info*) pjsip_rdata_get_sdp_info2( |
| 1250 |
pjsip_rx_data *rdata, |
| 1251 |
const pjsip_media_type *search_media_type) |
| 1252 |
{ |
| 1253 |
pjsip_media_type *msg_media_type = NULL; |
| 1254 |
pjsip_rdata_sdp_info *sdp_info; |
| 1255 |
|
| 1256 |
if (rdata->endpt_info.mod_data[mod_inv.mod.id]) { |
| 1257 |
return (pjsip_rdata_sdp_info *)rdata->endpt_info.mod_data[mod_inv.mod.id]; |
| 1258 |
} |
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
if (rdata->msg_info.ctype) { |
| 1265 |
msg_media_type = &rdata->msg_info.ctype->media; |
| 1266 |
} |
| 1267 |
sdp_info = pjsip_get_sdp_info(rdata->tp_info.pool, |
| 1268 |
rdata->msg_info.msg->body, |
| 1269 |
msg_media_type, |
| 1270 |
search_media_type); |
| 1271 |
rdata->endpt_info.mod_data[mod_inv.mod.id] = sdp_info; |
| 1272 |
|
| 1273 |
return sdp_info; |
| 1274 |
} |
| 1275 |
|
| 1276 |
PJ_DEF(pjsip_rdata_sdp_info*) pjsip_rdata_get_sdp_info(pjsip_rx_data *rdata) |
| 1277 |
{ |
| 1278 |
return pjsip_rdata_get_sdp_info2(rdata, NULL); |
| 1279 |
} |
| 1280 |
|
| 1281 |
PJ_DEF(pjsip_tdata_sdp_info*) pjsip_tdata_get_sdp_info2( |
| 1282 |
pjsip_tx_data *tdata, |
| 1283 |
const pjsip_media_type *search_media_type) |
| 1284 |
{ |
| 1285 |
pjsip_ctype_hdr *ctype_hdr = NULL; |
| 1286 |
pjsip_media_type *msg_media_type = NULL; |
| 1287 |
pjsip_tdata_sdp_info *sdp_info; |
| 1288 |
|
| 1289 |
if (tdata->mod_data[mod_inv.mod.id]) { |
| 1290 |
return (pjsip_tdata_sdp_info *)tdata->mod_data[mod_inv.mod.id]; |
| 1291 |
} |
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
ctype_hdr = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTENT_TYPE, NULL); |
| 1297 |
if (ctype_hdr) { |
| 1298 |
msg_media_type = &ctype_hdr->media; |
| 1299 |
} |
| 1300 |
|
| 1301 |
sdp_info = pjsip_get_sdp_info(tdata->pool, |
| 1302 |
tdata->msg->body, |
| 1303 |
msg_media_type, |
| 1304 |
search_media_type); |
| 1305 |
tdata->mod_data[mod_inv.mod.id] = sdp_info; |
| 1306 |
|
| 1307 |
return sdp_info; |
| 1308 |
} |
| 1309 |
|
| 1310 |
PJ_DEF(pjsip_tdata_sdp_info*) pjsip_tdata_get_sdp_info(pjsip_tx_data *tdata) |
| 1311 |
{ |
| 1312 |
return pjsip_tdata_get_sdp_info2(tdata, NULL); |
| 1313 |
} |
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
PJ_DEF(pj_status_t) pjsip_inv_verify_request3(pjsip_rx_data *rdata, |
| 1319 |
pj_pool_t *tmp_pool, |
| 1320 |
unsigned *options, |
| 1321 |
const pjmedia_sdp_session *r_sdp, |
| 1322 |
const pjmedia_sdp_session *l_sdp, |
| 1323 |
pjsip_dialog *dlg, |
| 1324 |
pjsip_endpoint *endpt, |
| 1325 |
pjsip_tx_data **p_tdata) |
| 1326 |
{ |
| 1327 |
pjsip_msg *msg = NULL; |
| 1328 |
pjsip_allow_hdr *allow = NULL; |
| 1329 |
pjsip_supported_hdr *sup_hdr = NULL; |
| 1330 |
pjsip_require_hdr *req_hdr = NULL; |
| 1331 |
pjsip_contact_hdr *c_hdr = NULL; |
| 1332 |
int code = 200; |
| 1333 |
unsigned rem_option = 0; |
| 1334 |
pj_status_t status = PJ_SUCCESS; |
| 1335 |
pjsip_hdr res_hdr_list; |
| 1336 |
pjsip_rdata_sdp_info *sdp_info; |
| 1337 |
|
| 1338 |
|
| 1339 |
if (p_tdata) *p_tdata = NULL; |
| 1340 |
|
| 1341 |
|
| 1342 |
PJ_ASSERT_RETURN(tmp_pool != NULL && options != NULL, PJ_EINVAL); |
| 1343 |
|
| 1344 |
|
| 1345 |
if (*options & PJSIP_INV_REQUIRE_100REL) |
| 1346 |
*options |= PJSIP_INV_SUPPORT_100REL; |
| 1347 |
if (*options & PJSIP_INV_REQUIRE_TIMER) |
| 1348 |
*options |= PJSIP_INV_SUPPORT_TIMER; |
| 1349 |
if (*options & PJSIP_INV_REQUIRE_ICE) |
| 1350 |
*options |= PJSIP_INV_SUPPORT_ICE; |
| 1351 |
if (*options & PJSIP_INV_REQUIRE_TRICKLE_ICE) |
| 1352 |
*options |= PJSIP_INV_SUPPORT_TRICKLE_ICE; |
| 1353 |
if (*options & PJSIP_INV_REQUIRE_SIPREC) |
| 1354 |
*options |= PJSIP_INV_SUPPORT_SIPREC; |
| 1355 |
|
| 1356 |
if (rdata) { |
| 1357 |
|
| 1358 |
msg = rdata->msg_info.msg; |
| 1359 |
|
| 1360 |
|
| 1361 |
PJ_ASSERT_RETURN(msg && msg->type == PJSIP_REQUEST_MSG && |
| 1362 |
msg->line.req.method.id == PJSIP_INVITE_METHOD, |
| 1363 |
PJ_EINVAL); |
| 1364 |
} |
| 1365 |
|
| 1366 |
|
| 1367 |
PJ_ASSERT_RETURN((!p_tdata) || (endpt || dlg), PJ_EINVAL); |
| 1368 |
|
| 1369 |
|
| 1370 |
endpt = endpt ? endpt : dlg->endpt; |
| 1371 |
|
| 1372 |
|
| 1373 |
pj_list_init(&res_hdr_list); |
| 1374 |
|
| 1375 |
|
| 1376 |
if (msg) { |
| 1377 |
c_hdr = (pjsip_contact_hdr*) |
| 1378 |
pjsip_msg_find_hdr(msg, PJSIP_H_CONTACT, NULL); |
| 1379 |
} |
| 1380 |
if (msg && (!c_hdr || !c_hdr->uri)) { |
| 1381 |
|
| 1382 |
pjsip_warning_hdr *w; |
| 1383 |
pj_str_t warn_text; |
| 1384 |
|
| 1385 |
warn_text = pj_str("Bad/missing Contact header"); |
| 1386 |
w = pjsip_warning_hdr_create(tmp_pool, 399, |
| 1387 |
pjsip_endpt_name(endpt), |
| 1388 |
&warn_text); |
| 1389 |
if (w) { |
| 1390 |
pj_list_push_back(&res_hdr_list, w); |
| 1391 |
} |
| 1392 |
|
| 1393 |
code = PJSIP_SC_BAD_REQUEST; |
| 1394 |
status = PJSIP_ERRNO_FROM_SIP_STATUS(code); |
| 1395 |
goto on_return; |
| 1396 |
} |
| 1397 |
|
| 1398 |
|
| 1399 |
if (pjsip_cfg()->endpt.disable_secure_dlg_check == PJ_FALSE && |
| 1400 |
msg && PJSIP_URI_SCHEME_IS_SIPS(msg->line.req.uri)) |
| 1401 |
{ |
| 1402 |
|
| 1403 |
if (!PJSIP_URI_SCHEME_IS_SIPS(c_hdr->uri)) |
| 1404 |
status = PJSIP_ESESSIONINSECURE; |
| 1405 |
|
| 1406 |
|
| 1407 |
if (status == PJ_SUCCESS) { |
| 1408 |
pjsip_rr_hdr *r = (pjsip_rr_hdr*) |
| 1409 |
pjsip_msg_find_hdr(msg, PJSIP_H_RECORD_ROUTE, |
| 1410 |
NULL); |
| 1411 |
if (r && !PJSIP_URI_SCHEME_IS_SIPS(&r->name_addr)) { |
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
if (PJSIP_URI_SCHEME_IS_SIP(&r->name_addr)) { |
| 1416 |
pjsip_sip_uri *sip_uri = (pjsip_sip_uri*) |
| 1417 |
pjsip_uri_get_uri(r->name_addr.uri); |
| 1418 |
if (pj_stricmp2(&sip_uri->transport_param, "tls")!=0) |
| 1419 |
status = PJSIP_ESESSIONINSECURE; |
| 1420 |
} else { |
| 1421 |
|
| 1422 |
status = PJSIP_ESESSIONINSECURE; |
| 1423 |
} |
| 1424 |
} |
| 1425 |
} |
| 1426 |
|
| 1427 |
if (status != PJ_SUCCESS) { |
| 1428 |
pjsip_warning_hdr *w; |
| 1429 |
pj_str_t warn_text = pj_str("SIPS Required"); |
| 1430 |
w = pjsip_warning_hdr_create(tmp_pool, 381, |
| 1431 |
pjsip_endpt_name(endpt), |
| 1432 |
&warn_text); |
| 1433 |
if (w) { |
| 1434 |
pj_list_push_back(&res_hdr_list, w); |
| 1435 |
} |
| 1436 |
code = PJSIP_SC_TEMPORARILY_UNAVAILABLE; |
| 1437 |
goto on_return; |
| 1438 |
} |
| 1439 |
} |
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
if (r_sdp == NULL && rdata) { |
| 1445 |
sdp_info = pjsip_rdata_get_sdp_info(rdata); |
| 1446 |
} else { |
| 1447 |
sdp_info = NULL; |
| 1448 |
} |
| 1449 |
|
| 1450 |
if (r_sdp==NULL && msg && msg->body) { |
| 1451 |
|
| 1452 |
|
| 1453 |
if (sdp_info->body.ptr == NULL && !PJSIP_INV_ACCEPT_UNKNOWN_BODY) { |
| 1454 |
|
| 1455 |
code = PJSIP_SC_UNSUPPORTED_MEDIA_TYPE; |
| 1456 |
status = PJSIP_ERRNO_FROM_SIP_STATUS(code); |
| 1457 |
|
| 1458 |
if (p_tdata) { |
| 1459 |
|
| 1460 |
pjsip_accept_hdr *acc; |
| 1461 |
|
| 1462 |
acc = pjsip_accept_hdr_create(tmp_pool); |
| 1463 |
PJ_ASSERT_RETURN(acc, PJ_ENOMEM); |
| 1464 |
acc->values[acc->count++] = pj_str("application/sdp"); |
| 1465 |
pj_list_push_back(&res_hdr_list, acc); |
| 1466 |
} |
| 1467 |
|
| 1468 |
goto on_return; |
| 1469 |
} |
| 1470 |
|
| 1471 |
if (sdp_info->sdp_err != PJ_SUCCESS) { |
| 1472 |
|
| 1473 |
code = PJSIP_SC_BAD_REQUEST; |
| 1474 |
|
| 1475 |
if (p_tdata) { |
| 1476 |
|
| 1477 |
pjsip_warning_hdr *w; |
| 1478 |
|
| 1479 |
w = pjsip_warning_hdr_create_from_status(tmp_pool, |
| 1480 |
pjsip_endpt_name(endpt), |
| 1481 |
sdp_info->sdp_err); |
| 1482 |
PJ_ASSERT_RETURN(w, PJ_ENOMEM); |
| 1483 |
|
| 1484 |
pj_list_push_back(&res_hdr_list, w); |
| 1485 |
} |
| 1486 |
|
| 1487 |
goto on_return; |
| 1488 |
} |
| 1489 |
|
| 1490 |
r_sdp = sdp_info->sdp; |
| 1491 |
} |
| 1492 |
|
| 1493 |
if (r_sdp) { |
| 1494 |
|
| 1495 |
if (l_sdp) { |
| 1496 |
pjmedia_sdp_neg *neg; |
| 1497 |
|
| 1498 |
|
| 1499 |
status = pjmedia_sdp_validate(l_sdp); |
| 1500 |
if (status != PJ_SUCCESS) { |
| 1501 |
pj_assert(!"Invalid local SDP"); |
| 1502 |
code = PJSIP_SC_INTERNAL_SERVER_ERROR; |
| 1503 |
goto on_return; |
| 1504 |
} |
| 1505 |
|
| 1506 |
|
| 1507 |
status = pjmedia_sdp_neg_create_w_remote_offer( |
| 1508 |
tmp_pool, l_sdp, r_sdp, &neg); |
| 1509 |
if (status != PJ_SUCCESS) { |
| 1510 |
pj_assert(!"Failed creating SDP negotiator"); |
| 1511 |
code = PJSIP_SC_INTERNAL_SERVER_ERROR; |
| 1512 |
goto on_return; |
| 1513 |
} |
| 1514 |
|
| 1515 |
|
| 1516 |
status = pjmedia_sdp_neg_negotiate(tmp_pool, neg, 0); |
| 1517 |
if (status != PJ_SUCCESS) { |
| 1518 |
|
| 1519 |
|
| 1520 |
code = PJSIP_SC_NOT_ACCEPTABLE_HERE; |
| 1521 |
|
| 1522 |
if (p_tdata) { |
| 1523 |
pjsip_accept_hdr *acc; |
| 1524 |
pjsip_warning_hdr *w; |
| 1525 |
|
| 1526 |
|
| 1527 |
w = pjsip_warning_hdr_create_from_status( |
| 1528 |
tmp_pool, |
| 1529 |
pjsip_endpt_name(endpt), status); |
| 1530 |
PJ_ASSERT_RETURN(w, PJ_ENOMEM); |
| 1531 |
|
| 1532 |
pj_list_push_back(&res_hdr_list, w); |
| 1533 |
|
| 1534 |
|
| 1535 |
acc = pjsip_accept_hdr_create(tmp_pool); |
| 1536 |
PJ_ASSERT_RETURN(acc, PJ_ENOMEM); |
| 1537 |
acc->values[acc->count++] = pj_str("application/sdp"); |
| 1538 |
pj_list_push_back(&res_hdr_list, acc); |
| 1539 |
|
| 1540 |
} |
| 1541 |
|
| 1542 |
goto on_return; |
| 1543 |
} |
| 1544 |
} |
| 1545 |
} |
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
if (msg) { |
| 1552 |
allow = (pjsip_allow_hdr*) pjsip_msg_find_hdr(msg, PJSIP_H_ALLOW, |
| 1553 |
NULL); |
| 1554 |
} |
| 1555 |
if (allow) { |
| 1556 |
unsigned i; |
| 1557 |
const pj_str_t STR_UPDATE = { "UPDATE", 6 }; |
| 1558 |
|
| 1559 |
for (i=0; i<allow->count; ++i) { |
| 1560 |
if (pj_stricmp(&allow->values[i], &STR_UPDATE)==0) |
| 1561 |
break; |
| 1562 |
} |
| 1563 |
|
| 1564 |
if (i != allow->count) { |
| 1565 |
|
| 1566 |
*options |= PJSIP_INV_SUPPORT_UPDATE; |
| 1567 |
} |
| 1568 |
|
| 1569 |
} |
| 1570 |
|
| 1571 |
|
| 1572 |
if (msg) { |
| 1573 |
sup_hdr = (pjsip_supported_hdr*) |
| 1574 |
pjsip_msg_find_hdr(msg, PJSIP_H_SUPPORTED, NULL); |
| 1575 |
} |
| 1576 |
if (sup_hdr) { |
| 1577 |
unsigned i; |
| 1578 |
const pj_str_t STR_100REL = { "100rel", 6}; |
| 1579 |
const pj_str_t STR_TIMER = { "timer", 5}; |
| 1580 |
const pj_str_t STR_ICE = { "ice", 3 }; |
| 1581 |
const pj_str_t STR_TRICKLE_ICE = { "trickle-ice", 11 }; |
| 1582 |
|
| 1583 |
for (i=0; i<sup_hdr->count; ++i) { |
| 1584 |
if (pj_stricmp(&sup_hdr->values[i], &STR_100REL)==0) |
| 1585 |
rem_option |= PJSIP_INV_SUPPORT_100REL; |
| 1586 |
else if (pj_stricmp(&sup_hdr->values[i], &STR_TIMER)==0) |
| 1587 |
rem_option |= PJSIP_INV_SUPPORT_TIMER; |
| 1588 |
else if (pj_stricmp(&sup_hdr->values[i], &STR_ICE)==0) |
| 1589 |
rem_option |= PJSIP_INV_SUPPORT_ICE; |
| 1590 |
else if (pj_stricmp(&sup_hdr->values[i], &STR_TRICKLE_ICE)==0) |
| 1591 |
rem_option |= PJSIP_INV_SUPPORT_TRICKLE_ICE; |
| 1592 |
} |
| 1593 |
} |
| 1594 |
|
| 1595 |
|
| 1596 |
if (msg) { |
| 1597 |
req_hdr = (pjsip_require_hdr*) |
| 1598 |
pjsip_msg_find_hdr(msg, PJSIP_H_REQUIRE, NULL); |
| 1599 |
} |
| 1600 |
if (req_hdr) { |
| 1601 |
unsigned i; |
| 1602 |
const pj_str_t STR_100REL = { "100rel", 6}; |
| 1603 |
const pj_str_t STR_REPLACES = { "replaces", 8 }; |
| 1604 |
const pj_str_t STR_TIMER = { "timer", 5 }; |
| 1605 |
const pj_str_t STR_ICE = { "ice", 3 }; |
| 1606 |
const pj_str_t STR_TRICKLE_ICE = { "trickle-ice", 11 }; |
| 1607 |
const pj_str_t STR_SIPREC = { "siprec", 6 }; |
| 1608 |
unsigned unsupp_cnt = 0; |
| 1609 |
pj_str_t unsupp_tags[PJSIP_GENERIC_ARRAY_MAX_COUNT]; |
| 1610 |
|
| 1611 |
for (i=0; i<req_hdr->count; ++i) { |
| 1612 |
if ((*options & PJSIP_INV_SUPPORT_100REL) && |
| 1613 |
pj_stricmp(&req_hdr->values[i], &STR_100REL)==0) |
| 1614 |
{ |
| 1615 |
rem_option |= PJSIP_INV_REQUIRE_100REL; |
| 1616 |
|
| 1617 |
} else if (!(*options & PJSIP_INV_SUPPORT_SIPREC) && |
| 1618 |
pj_stricmp(&req_hdr->values[i], &STR_SIPREC)==0) |
| 1619 |
{ |
| 1620 |
unsupp_tags[unsupp_cnt++] = req_hdr->values[i]; |
| 1621 |
|
| 1622 |
} else if ((*options & PJSIP_INV_SUPPORT_TIMER) && |
| 1623 |
pj_stricmp(&req_hdr->values[i], &STR_TIMER)==0) |
| 1624 |
{ |
| 1625 |
rem_option |= PJSIP_INV_REQUIRE_TIMER; |
| 1626 |
|
| 1627 |
} else if (pj_stricmp(&req_hdr->values[i], &STR_REPLACES)==0) { |
| 1628 |
pj_bool_t supp; |
| 1629 |
|
| 1630 |
supp = pjsip_endpt_has_capability(endpt, PJSIP_H_SUPPORTED, |
| 1631 |
NULL, &STR_REPLACES); |
| 1632 |
if (!supp) |
| 1633 |
unsupp_tags[unsupp_cnt++] = req_hdr->values[i]; |
| 1634 |
} else if ((*options & PJSIP_INV_SUPPORT_ICE) && |
| 1635 |
pj_stricmp(&req_hdr->values[i], &STR_ICE)==0) |
| 1636 |
{ |
| 1637 |
rem_option |= PJSIP_INV_REQUIRE_ICE; |
| 1638 |
|
| 1639 |
} else if ((*options & PJSIP_INV_SUPPORT_TRICKLE_ICE) && |
| 1640 |
pj_stricmp(&req_hdr->values[i], &STR_TRICKLE_ICE)==0) |
| 1641 |
{ |
| 1642 |
rem_option |= PJSIP_INV_REQUIRE_TRICKLE_ICE; |
| 1643 |
|
| 1644 |
} else if (!pjsip_endpt_has_capability(endpt, PJSIP_H_SUPPORTED, |
| 1645 |
NULL, &req_hdr->values[i])) |
| 1646 |
{ |
| 1647 |
|
| 1648 |
unsupp_tags[unsupp_cnt++] = req_hdr->values[i]; |
| 1649 |
} |
| 1650 |
} |
| 1651 |
|
| 1652 |
|
| 1653 |
if (unsupp_cnt) { |
| 1654 |
|
| 1655 |
code = PJSIP_SC_BAD_EXTENSION; |
| 1656 |
status = PJSIP_ERRNO_FROM_SIP_STATUS(code); |
| 1657 |
|
| 1658 |
if (p_tdata) { |
| 1659 |
pjsip_unsupported_hdr *unsupp_hdr; |
| 1660 |
const pjsip_hdr *h; |
| 1661 |
|
| 1662 |
|
| 1663 |
unsupp_hdr = pjsip_unsupported_hdr_create(tmp_pool); |
| 1664 |
PJ_ASSERT_RETURN(unsupp_hdr != NULL, PJ_ENOMEM); |
| 1665 |
|
| 1666 |
unsupp_hdr->count = unsupp_cnt; |
| 1667 |
for (i=0; i<unsupp_cnt; ++i) |
| 1668 |
unsupp_hdr->values[i] = unsupp_tags[i]; |
| 1669 |
|
| 1670 |
pj_list_push_back(&res_hdr_list, unsupp_hdr); |
| 1671 |
|
| 1672 |
|
| 1673 |
h = pjsip_endpt_get_capability(endpt, PJSIP_H_SUPPORTED, |
| 1674 |
NULL); |
| 1675 |
pj_assert(h); |
| 1676 |
if (h) { |
| 1677 |
sup_hdr = (pjsip_supported_hdr*) |
| 1678 |
pjsip_hdr_clone(tmp_pool, h); |
| 1679 |
pj_list_push_back(&res_hdr_list, sup_hdr); |
| 1680 |
} |
| 1681 |
} |
| 1682 |
|
| 1683 |
goto on_return; |
| 1684 |
} |
| 1685 |
} |
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
if ( msg && (((*options & PJSIP_INV_REQUIRE_100REL)!=0 && |
| 1691 |
(rem_option & PJSIP_INV_SUPPORT_100REL)==0) || |
| 1692 |
((*options & PJSIP_INV_REQUIRE_TIMER)!=0 && |
| 1693 |
(rem_option & PJSIP_INV_SUPPORT_TIMER)==0) || |
| 1694 |
((*options & PJSIP_INV_REQUIRE_TRICKLE_ICE)!=0 && |
| 1695 |
(rem_option & PJSIP_INV_SUPPORT_TRICKLE_ICE)==0))) |
| 1696 |
{ |
| 1697 |
code = PJSIP_SC_EXTENSION_REQUIRED; |
| 1698 |
status = PJSIP_ERRNO_FROM_SIP_STATUS(code); |
| 1699 |
|
| 1700 |
if (p_tdata) { |
| 1701 |
const pjsip_hdr *h; |
| 1702 |
|
| 1703 |
|
| 1704 |
req_hdr = pjsip_require_hdr_create(tmp_pool); |
| 1705 |
PJ_ASSERT_RETURN(req_hdr != NULL, PJ_ENOMEM); |
| 1706 |
|
| 1707 |
if (*options & PJSIP_INV_REQUIRE_100REL) |
| 1708 |
req_hdr->values[req_hdr->count++] = pj_str("100rel"); |
| 1709 |
if (*options & PJSIP_INV_REQUIRE_TIMER) |
| 1710 |
req_hdr->values[req_hdr->count++] = pj_str("timer"); |
| 1711 |
if (*options & PJSIP_INV_REQUIRE_TRICKLE_ICE) |
| 1712 |
req_hdr->values[req_hdr->count++] = pj_str("trickle-ice"); |
| 1713 |
|
| 1714 |
pj_list_push_back(&res_hdr_list, req_hdr); |
| 1715 |
|
| 1716 |
|
| 1717 |
h = pjsip_endpt_get_capability(endpt, PJSIP_H_SUPPORTED, |
| 1718 |
NULL); |
| 1719 |
pj_assert(h); |
| 1720 |
if (h) { |
| 1721 |
sup_hdr = (pjsip_supported_hdr*) |
| 1722 |
pjsip_hdr_clone(tmp_pool, h); |
| 1723 |
pj_list_push_back(&res_hdr_list, sup_hdr); |
| 1724 |
} |
| 1725 |
|
| 1726 |
} |
| 1727 |
|
| 1728 |
goto on_return; |
| 1729 |
} |
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
if (rem_option & PJSIP_INV_REQUIRE_100REL) { |
| 1735 |
pj_assert(*options & PJSIP_INV_SUPPORT_100REL); |
| 1736 |
*options |= PJSIP_INV_REQUIRE_100REL; |
| 1737 |
} |
| 1738 |
if (rem_option & PJSIP_INV_REQUIRE_TIMER) { |
| 1739 |
pj_assert(*options & PJSIP_INV_SUPPORT_TIMER); |
| 1740 |
*options |= PJSIP_INV_REQUIRE_TIMER; |
| 1741 |
} |
| 1742 |
if (rem_option & PJSIP_INV_REQUIRE_TRICKLE_ICE) { |
| 1743 |
pj_assert(*options & PJSIP_INV_SUPPORT_TRICKLE_ICE); |
| 1744 |
*options |= PJSIP_INV_REQUIRE_TRICKLE_ICE; |
| 1745 |
} |
| 1746 |
|
| 1747 |
on_return: |
| 1748 |
|
| 1749 |
|
| 1750 |
if (code != 200 && p_tdata) { |
| 1751 |
pjsip_tx_data *tdata; |
| 1752 |
const pjsip_hdr *h; |
| 1753 |
|
| 1754 |
if (!rdata) { |
| 1755 |
return PJSIP_ERRNO_FROM_SIP_STATUS(code); |
| 1756 |
} |
| 1757 |
|
| 1758 |
if (dlg) { |
| 1759 |
status = pjsip_dlg_create_response(dlg, rdata, code, NULL, |
| 1760 |
&tdata); |
| 1761 |
} else { |
| 1762 |
status = pjsip_endpt_create_response(endpt, rdata, code, NULL, |
| 1763 |
&tdata); |
| 1764 |
} |
| 1765 |
|
| 1766 |
if (status != PJ_SUCCESS) |
| 1767 |
return status; |
| 1768 |
|
| 1769 |
|
| 1770 |
h = res_hdr_list.next; |
| 1771 |
while (h != &res_hdr_list) { |
| 1772 |
pjsip_hdr *cloned; |
| 1773 |
|
| 1774 |
cloned = (pjsip_hdr*) pjsip_hdr_clone(tdata->pool, h); |
| 1775 |
PJ_ASSERT_RETURN(cloned, PJ_ENOMEM); |
| 1776 |
|
| 1777 |
pjsip_msg_add_hdr(tdata->msg, cloned); |
| 1778 |
|
| 1779 |
h = h->next; |
| 1780 |
} |
| 1781 |
|
| 1782 |
*p_tdata = tdata; |
| 1783 |
|
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
if (status == PJ_SUCCESS) |
| 1788 |
status = PJSIP_ERRNO_FROM_SIP_STATUS(code); |
| 1789 |
|
| 1790 |
} |
| 1791 |
|
| 1792 |
return status; |
| 1793 |
} |
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
PJ_DEF(pj_status_t) pjsip_inv_verify_request2(pjsip_rx_data *rdata, |
| 1800 |
unsigned *options, |
| 1801 |
const pjmedia_sdp_session *r_sdp, |
| 1802 |
const pjmedia_sdp_session *l_sdp, |
| 1803 |
pjsip_dialog *dlg, |
| 1804 |
pjsip_endpoint *endpt, |
| 1805 |
pjsip_tx_data **p_tdata) |
| 1806 |
{ |
| 1807 |
return pjsip_inv_verify_request3(rdata, rdata->tp_info.pool, |
| 1808 |
options, r_sdp, l_sdp, dlg, |
| 1809 |
endpt, p_tdata); |
| 1810 |
} |
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
PJ_DEF(pj_status_t) pjsip_inv_verify_request( pjsip_rx_data *rdata, |
| 1817 |
unsigned *options, |
| 1818 |
const pjmedia_sdp_session *l_sdp, |
| 1819 |
pjsip_dialog *dlg, |
| 1820 |
pjsip_endpoint *endpt, |
| 1821 |
pjsip_tx_data **p_tdata) |
| 1822 |
{ |
| 1823 |
return pjsip_inv_verify_request3(rdata, rdata->tp_info.pool, |
| 1824 |
options, NULL, l_sdp, dlg, |
| 1825 |
endpt, p_tdata); |
| 1826 |
} |
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
PJ_DEF(pj_status_t) pjsip_inv_create_uas( pjsip_dialog *dlg, |
| 1832 |
pjsip_rx_data *rdata, |
| 1833 |
const pjmedia_sdp_session *local_sdp, |
| 1834 |
unsigned options, |
| 1835 |
pjsip_inv_session **p_inv) |
| 1836 |
{ |
| 1837 |
pjsip_inv_session *inv; |
| 1838 |
struct tsx_inv_data *tsx_inv_data; |
| 1839 |
pjsip_msg *msg; |
| 1840 |
pjsip_rdata_sdp_info *sdp_info; |
| 1841 |
pj_status_t status; |
| 1842 |
|
| 1843 |
|
| 1844 |
PJ_ASSERT_RETURN(dlg && rdata && p_inv, PJ_EINVAL); |
| 1845 |
|
| 1846 |
|
| 1847 |
PJ_ASSERT_RETURN(pjsip_rdata_get_tsx(rdata) != NULL, PJ_EINVALIDOP); |
| 1848 |
|
| 1849 |
msg = rdata->msg_info.msg; |
| 1850 |
|
| 1851 |
|
| 1852 |
PJ_ASSERT_RETURN(msg->type == PJSIP_REQUEST_MSG && |
| 1853 |
msg->line.req.method.id == PJSIP_INVITE_METHOD, |
| 1854 |
PJ_EINVALIDOP); |
| 1855 |
|
| 1856 |
|
| 1857 |
pjsip_dlg_inc_lock(dlg); |
| 1858 |
|
| 1859 |
|
| 1860 |
if (options & PJSIP_INV_REQUIRE_100REL) |
| 1861 |
options |= PJSIP_INV_SUPPORT_100REL; |
| 1862 |
if (options & PJSIP_INV_REQUIRE_TIMER) |
| 1863 |
options |= PJSIP_INV_SUPPORT_TIMER; |
| 1864 |
|
| 1865 |
|
| 1866 |
inv = PJ_POOL_ZALLOC_T(dlg->pool, pjsip_inv_session); |
| 1867 |
pj_assert(inv != NULL); |
| 1868 |
|
| 1869 |
status = pj_atomic_create(dlg->pool, 0, &inv->ref_cnt); |
| 1870 |
if (status != PJ_SUCCESS) { |
| 1871 |
pjsip_dlg_dec_lock(dlg); |
| 1872 |
return status; |
| 1873 |
} |
| 1874 |
|
| 1875 |
inv->pool = dlg->pool; |
| 1876 |
inv->role = PJSIP_ROLE_UAS; |
| 1877 |
inv->state = PJSIP_INV_STATE_NULL; |
| 1878 |
inv->dlg = dlg; |
| 1879 |
inv->options = options; |
| 1880 |
inv->notify = PJ_TRUE; |
| 1881 |
inv->cause = (pjsip_status_code) 0; |
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
pj_ansi_snprintf(inv->obj_name, PJ_MAX_OBJ_NAME, "inv%p", dlg->pool); |
| 1886 |
inv->pool_prov = pjsip_endpt_create_pool(dlg->endpt, inv->obj_name, |
| 1887 |
POOL_INIT_SIZE, POOL_INC_SIZE); |
| 1888 |
inv->pool_active = pjsip_endpt_create_pool(dlg->endpt, inv->obj_name, |
| 1889 |
POOL_INIT_SIZE, POOL_INC_SIZE); |
| 1890 |
|
| 1891 |
|
| 1892 |
pj_ansi_snprintf(inv->obj_name, PJ_MAX_OBJ_NAME, "inv%p", dlg); |
| 1893 |
|
| 1894 |
|
| 1895 |
sdp_info = pjsip_rdata_get_sdp_info(rdata); |
| 1896 |
if (sdp_info->sdp_err) { |
| 1897 |
pjsip_dlg_dec_lock(dlg); |
| 1898 |
return sdp_info->sdp_err; |
| 1899 |
} |
| 1900 |
|
| 1901 |
|
| 1902 |
if (sdp_info->sdp) { |
| 1903 |
status = pjmedia_sdp_neg_create_w_remote_offer(inv->pool, local_sdp, |
| 1904 |
sdp_info->sdp, |
| 1905 |
&inv->neg); |
| 1906 |
|
| 1907 |
} else if (local_sdp) { |
| 1908 |
status = pjmedia_sdp_neg_create_w_local_offer(inv->pool, |
| 1909 |
local_sdp, &inv->neg); |
| 1910 |
} else { |
| 1911 |
status = PJ_SUCCESS; |
| 1912 |
} |
| 1913 |
|
| 1914 |
if (status != PJ_SUCCESS) { |
| 1915 |
pjsip_dlg_dec_lock(dlg); |
| 1916 |
return status; |
| 1917 |
} |
| 1918 |
|
| 1919 |
|
| 1920 |
status = pjsip_dlg_add_usage(dlg, &mod_inv.mod, inv); |
| 1921 |
if (status != PJ_SUCCESS) { |
| 1922 |
pjsip_dlg_dec_lock(dlg); |
| 1923 |
return status; |
| 1924 |
} |
| 1925 |
|
| 1926 |
|
| 1927 |
pjsip_dlg_inc_session(dlg, &mod_inv.mod); |
| 1928 |
|
| 1929 |
|
| 1930 |
inv->invite_tsx = pjsip_rdata_get_tsx(rdata); |
| 1931 |
|
| 1932 |
|
| 1933 |
tsx_inv_data = PJ_POOL_ZALLOC_T(inv->invite_tsx->pool, struct tsx_inv_data); |
| 1934 |
tsx_inv_data->inv = inv; |
| 1935 |
tsx_inv_data->has_sdp = (sdp_info->sdp!=NULL); |
| 1936 |
inv->invite_tsx->mod_data[mod_inv.mod.id] = tsx_inv_data; |
| 1937 |
|
| 1938 |
|
| 1939 |
if (inv->options & PJSIP_INV_REQUIRE_100REL) { |
| 1940 |
pjsip_100rel_attach(inv); |
| 1941 |
} |
| 1942 |
|
| 1943 |
|
| 1944 |
pjsip_inv_add_ref(inv); |
| 1945 |
pjsip_dlg_dec_lock(dlg); |
| 1946 |
*p_inv = inv; |
| 1947 |
|
| 1948 |
PJ_LOG(5,(inv->obj_name, "UAS invite session created for dialog %s", |
| 1949 |
dlg->obj_name)); |
| 1950 |
|
| 1951 |
return PJ_SUCCESS; |
| 1952 |
} |
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
PJ_DEF(pj_status_t) pjsip_inv_terminate( pjsip_inv_session *inv, |
| 1958 |
int st_code, |
| 1959 |
pj_bool_t notify) |
| 1960 |
{ |
| 1961 |
PJ_ASSERT_RETURN(inv, PJ_EINVAL); |
| 1962 |
|
| 1963 |
|
| 1964 |
pjsip_dlg_inc_lock(inv->dlg); |
| 1965 |
|
| 1966 |
|
| 1967 |
inv->notify = notify; |
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
if (inv->invite_tsx && |
| 1974 |
inv->invite_tsx->state <= PJSIP_TSX_STATE_COMPLETED) |
| 1975 |
{ |
| 1976 |
pjsip_tsx_terminate(inv->invite_tsx, st_code); |
| 1977 |
|
| 1978 |
} |
| 1979 |
|
| 1980 |
|
| 1981 |
inv_set_cause(inv, st_code, NULL); |
| 1982 |
|
| 1983 |
|
| 1984 |
if (inv->state != PJSIP_INV_STATE_DISCONNECTED) { |
| 1985 |
pjsip_event usr_event; |
| 1986 |
|
| 1987 |
PJSIP_EVENT_INIT_USER(usr_event, NULL, NULL, NULL, NULL); |
| 1988 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, &usr_event); |
| 1989 |
} |
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
pjsip_dlg_dec_lock(inv->dlg); |
| 1996 |
|
| 1997 |
return PJ_SUCCESS; |
| 1998 |
} |
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
PJ_DEF(pj_status_t) pjsip_inv_uac_restart(pjsip_inv_session *inv, |
| 2006 |
pj_bool_t new_offer) |
| 2007 |
{ |
| 2008 |
PJ_ASSERT_RETURN(inv, PJ_EINVAL); |
| 2009 |
|
| 2010 |
pjsip_inv_add_ref(inv); |
| 2011 |
|
| 2012 |
inv->state = PJSIP_INV_STATE_NULL; |
| 2013 |
inv->invite_tsx = NULL; |
| 2014 |
if (inv->last_answer) { |
| 2015 |
pjsip_tx_data_dec_ref(inv->last_answer); |
| 2016 |
inv->last_answer = NULL; |
| 2017 |
} |
| 2018 |
|
| 2019 |
if (new_offer && inv->neg) { |
| 2020 |
pjmedia_sdp_neg_state neg_state; |
| 2021 |
|
| 2022 |
neg_state = pjmedia_sdp_neg_get_state(inv->neg); |
| 2023 |
if (neg_state == PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER) { |
| 2024 |
pjmedia_sdp_neg_cancel_offer(inv->neg); |
| 2025 |
} |
| 2026 |
} |
| 2027 |
|
| 2028 |
pjsip_inv_dec_ref(inv); |
| 2029 |
|
| 2030 |
return PJ_SUCCESS; |
| 2031 |
} |
| 2032 |
|
| 2033 |
|
| 2034 |
static void *clone_sdp(pj_pool_t *pool, const void *data, unsigned len) |
| 2035 |
{ |
| 2036 |
PJ_UNUSED_ARG(len); |
| 2037 |
return pjmedia_sdp_session_clone(pool, (const pjmedia_sdp_session*)data); |
| 2038 |
} |
| 2039 |
|
| 2040 |
static int print_sdp(pjsip_msg_body *body, char *buf, pj_size_t len) |
| 2041 |
{ |
| 2042 |
return pjmedia_sdp_print((const pjmedia_sdp_session*)body->data, buf, len); |
| 2043 |
} |
| 2044 |
|
| 2045 |
|
| 2046 |
PJ_DEF(pj_status_t) pjsip_create_sdp_body( pj_pool_t *pool, |
| 2047 |
pjmedia_sdp_session *sdp, |
| 2048 |
pjsip_msg_body **p_body) |
| 2049 |
{ |
| 2050 |
const pj_str_t STR_APPLICATION = { "application", 11}; |
| 2051 |
const pj_str_t STR_SDP = { "sdp", 3 }; |
| 2052 |
pjsip_msg_body *body; |
| 2053 |
|
| 2054 |
body = PJ_POOL_ZALLOC_T(pool, pjsip_msg_body); |
| 2055 |
PJ_ASSERT_RETURN(body != NULL, PJ_ENOMEM); |
| 2056 |
|
| 2057 |
pjsip_media_type_init(&body->content_type, (pj_str_t*)&STR_APPLICATION, |
| 2058 |
(pj_str_t*)&STR_SDP); |
| 2059 |
body->data = sdp; |
| 2060 |
body->len = 0; |
| 2061 |
body->clone_data = &clone_sdp; |
| 2062 |
body->print_body = &print_sdp; |
| 2063 |
|
| 2064 |
*p_body = body; |
| 2065 |
|
| 2066 |
return PJ_SUCCESS; |
| 2067 |
} |
| 2068 |
|
| 2069 |
static pjsip_multipart_part* create_sdp_part(pj_pool_t *pool, pjmedia_sdp_session *sdp) |
| 2070 |
{ |
| 2071 |
pjsip_multipart_part *sdp_part; |
| 2072 |
pjsip_media_type media_type; |
| 2073 |
|
| 2074 |
pjsip_media_type_init2(&media_type, "application", "sdp"); |
| 2075 |
|
| 2076 |
sdp_part = pjsip_multipart_create_part(pool); |
| 2077 |
PJ_ASSERT_RETURN(sdp_part != NULL, NULL); |
| 2078 |
|
| 2079 |
sdp_part->body = PJ_POOL_ZALLOC_T(pool, pjsip_msg_body); |
| 2080 |
PJ_ASSERT_RETURN(sdp_part->body != NULL, NULL); |
| 2081 |
|
| 2082 |
pjsip_media_type_cp(pool, &sdp_part->body->content_type, &media_type); |
| 2083 |
|
| 2084 |
sdp_part->body->data = sdp; |
| 2085 |
sdp_part->body->clone_data = clone_sdp; |
| 2086 |
sdp_part->body->print_body = print_sdp; |
| 2087 |
|
| 2088 |
return sdp_part; |
| 2089 |
} |
| 2090 |
|
| 2091 |
PJ_DEF(pj_status_t) pjsip_create_multipart_sdp_body(pj_pool_t *pool, |
| 2092 |
pjmedia_sdp_session *sdp, |
| 2093 |
pjsip_msg_body **p_body) |
| 2094 |
{ |
| 2095 |
pjsip_media_type media_type; |
| 2096 |
pjsip_msg_body *multipart; |
| 2097 |
pjsip_multipart_part *sdp_part; |
| 2098 |
|
| 2099 |
pjsip_media_type_init2(&media_type, "multipart", "mixed"); |
| 2100 |
multipart = pjsip_multipart_create(pool, &media_type, NULL); |
| 2101 |
PJ_ASSERT_RETURN(multipart != NULL, PJ_ENOMEM); |
| 2102 |
|
| 2103 |
sdp_part = create_sdp_part(pool, sdp); |
| 2104 |
PJ_ASSERT_RETURN(sdp_part != NULL, PJ_ENOMEM); |
| 2105 |
pjsip_multipart_add_part(pool, multipart, sdp_part); |
| 2106 |
*p_body = multipart; |
| 2107 |
|
| 2108 |
return PJ_SUCCESS; |
| 2109 |
} |
| 2110 |
|
| 2111 |
static pjsip_msg_body *create_sdp_body(pj_pool_t *pool, |
| 2112 |
const pjmedia_sdp_session *c_sdp) |
| 2113 |
{ |
| 2114 |
pjsip_msg_body *body; |
| 2115 |
pj_status_t status; |
| 2116 |
|
| 2117 |
status = pjsip_create_sdp_body(pool, |
| 2118 |
pjmedia_sdp_session_clone(pool, c_sdp), |
| 2119 |
&body); |
| 2120 |
|
| 2121 |
if (status != PJ_SUCCESS) |
| 2122 |
return NULL; |
| 2123 |
|
| 2124 |
return body; |
| 2125 |
} |
| 2126 |
|
| 2127 |
|
| 2128 |
static void remove_val_from_array_hdr(pjsip_generic_array_hdr *arr_hdr, |
| 2129 |
const pj_str_t *val) |
| 2130 |
{ |
| 2131 |
unsigned i; |
| 2132 |
for (i=0; i<arr_hdr->count; ++i) { |
| 2133 |
if (pj_stricmp(&arr_hdr->values[i], val)==0) { |
| 2134 |
pj_array_erase(arr_hdr->values, sizeof(arr_hdr->values[0]), |
| 2135 |
arr_hdr->count, i); |
| 2136 |
--arr_hdr->count; |
| 2137 |
break; |
| 2138 |
} |
| 2139 |
} |
| 2140 |
} |
| 2141 |
|
| 2142 |
|
| 2143 |
|
| 2144 |
|
| 2145 |
|
| 2146 |
static void cleanup_allow_sup_hdr(unsigned inv_option, |
| 2147 |
pjsip_tx_data *tdata, |
| 2148 |
pjsip_allow_hdr *allow_hdr, |
| 2149 |
pjsip_supported_hdr *sup_hdr) |
| 2150 |
{ |
| 2151 |
|
| 2152 |
if ((inv_option & PJSIP_INV_SUPPORT_100REL) && |
| 2153 |
(inv_option & PJSIP_INV_SUPPORT_TIMER) && |
| 2154 |
(inv_option & PJSIP_INV_SUPPORT_TRICKLE_ICE) && |
| 2155 |
(inv_option & PJSIP_INV_SUPPORT_SIPREC)) |
| 2156 |
{ |
| 2157 |
return; |
| 2158 |
} |
| 2159 |
|
| 2160 |
if (!allow_hdr && tdata) { |
| 2161 |
allow_hdr = (pjsip_allow_hdr*) pjsip_msg_find_hdr(tdata->msg, |
| 2162 |
PJSIP_H_ALLOW, |
| 2163 |
NULL); |
| 2164 |
} |
| 2165 |
if (!sup_hdr && tdata) { |
| 2166 |
sup_hdr = (pjsip_supported_hdr*) pjsip_msg_find_hdr(tdata->msg, |
| 2167 |
PJSIP_H_SUPPORTED, |
| 2168 |
NULL); |
| 2169 |
} |
| 2170 |
|
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
if ((inv_option & PJSIP_INV_SUPPORT_TIMER) == 0 && sup_hdr) { |
| 2175 |
const pj_str_t STR_TIMER = { "timer", 5 }; |
| 2176 |
remove_val_from_array_hdr(sup_hdr, &STR_TIMER); |
| 2177 |
} |
| 2178 |
|
| 2179 |
if ((inv_option & PJSIP_INV_SUPPORT_TRICKLE_ICE) == 0 && sup_hdr) { |
| 2180 |
const pj_str_t STR_TRICKLE_ICE = { "trickle-ice", 11 }; |
| 2181 |
remove_val_from_array_hdr(sup_hdr, &STR_TRICKLE_ICE); |
| 2182 |
} |
| 2183 |
|
| 2184 |
if ((inv_option & PJSIP_INV_SUPPORT_100REL) == 0) { |
| 2185 |
const pj_str_t STR_PRACK = { "PRACK", 5 }; |
| 2186 |
const pj_str_t STR_100REL = { "100rel", 6 }; |
| 2187 |
|
| 2188 |
if (allow_hdr) |
| 2189 |
remove_val_from_array_hdr(allow_hdr, &STR_PRACK); |
| 2190 |
if (sup_hdr) |
| 2191 |
remove_val_from_array_hdr(sup_hdr, &STR_100REL); |
| 2192 |
} |
| 2193 |
|
| 2194 |
if ((inv_option & PJSIP_INV_SUPPORT_SIPREC) == 0 && sup_hdr) { |
| 2195 |
const pj_str_t STR_SIPREC = { "siprec", 6 }; |
| 2196 |
remove_val_from_array_hdr(sup_hdr, &STR_SIPREC); |
| 2197 |
} |
| 2198 |
} |
| 2199 |
|
| 2200 |
|
| 2201 |
|
| 2202 |
|
| 2203 |
PJ_DEF(pj_status_t) pjsip_inv_invite( pjsip_inv_session *inv, |
| 2204 |
pjsip_tx_data **p_tdata ) |
| 2205 |
{ |
| 2206 |
pjsip_tx_data *tdata; |
| 2207 |
const pjsip_hdr *hdr; |
| 2208 |
pjsip_allow_hdr *allow_hdr = NULL; |
| 2209 |
pjsip_supported_hdr *sup_hdr = NULL; |
| 2210 |
pj_bool_t has_sdp; |
| 2211 |
pj_status_t status; |
| 2212 |
|
| 2213 |
|
| 2214 |
PJ_ASSERT_RETURN(inv && p_tdata, PJ_EINVAL); |
| 2215 |
|
| 2216 |
|
| 2217 |
PJ_ASSERT_RETURN(inv->state == PJSIP_INV_STATE_NULL || |
| 2218 |
inv->state == PJSIP_INV_STATE_CONFIRMED, |
| 2219 |
PJ_EINVALIDOP); |
| 2220 |
|
| 2221 |
|
| 2222 |
pjsip_dlg_inc_lock(inv->dlg); |
| 2223 |
|
| 2224 |
|
| 2225 |
status = pjsip_dlg_create_request(inv->dlg, pjsip_get_invite_method(), -1, |
| 2226 |
&tdata); |
| 2227 |
if (status != PJ_SUCCESS) |
| 2228 |
goto on_return; |
| 2229 |
|
| 2230 |
|
| 2231 |
|
| 2232 |
|
| 2233 |
|
| 2234 |
|
| 2235 |
if (inv->state == PJSIP_INV_STATE_NULL) { |
| 2236 |
hdr = inv->dlg->inv_hdr.next; |
| 2237 |
|
| 2238 |
while (hdr != &inv->dlg->inv_hdr) { |
| 2239 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*) |
| 2240 |
pjsip_hdr_shallow_clone(tdata->pool, hdr)); |
| 2241 |
hdr = hdr->next; |
| 2242 |
} |
| 2243 |
} |
| 2244 |
|
| 2245 |
|
| 2246 |
if (inv->neg) { |
| 2247 |
pjmedia_sdp_neg_state neg_state; |
| 2248 |
|
| 2249 |
neg_state = pjmedia_sdp_neg_get_state(inv->neg); |
| 2250 |
|
| 2251 |
has_sdp = (neg_state == PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER || |
| 2252 |
(neg_state == PJMEDIA_SDP_NEG_STATE_WAIT_NEGO && |
| 2253 |
pjmedia_sdp_neg_has_local_answer(inv->neg))); |
| 2254 |
|
| 2255 |
|
| 2256 |
} else { |
| 2257 |
has_sdp = PJ_FALSE; |
| 2258 |
} |
| 2259 |
|
| 2260 |
|
| 2261 |
if (has_sdp) { |
| 2262 |
const pjmedia_sdp_session *offer; |
| 2263 |
|
| 2264 |
status = pjmedia_sdp_neg_get_neg_local(inv->neg, &offer); |
| 2265 |
if (status != PJ_SUCCESS) { |
| 2266 |
pjsip_tx_data_dec_ref(tdata); |
| 2267 |
goto on_return; |
| 2268 |
} |
| 2269 |
|
| 2270 |
tdata->msg->body = create_sdp_body(tdata->pool, offer); |
| 2271 |
} |
| 2272 |
|
| 2273 |
|
| 2274 |
if (inv->dlg->add_allow) { |
| 2275 |
hdr = pjsip_endpt_get_capability(inv->dlg->endpt, PJSIP_H_ALLOW, NULL); |
| 2276 |
if (hdr) { |
| 2277 |
allow_hdr = (pjsip_allow_hdr*) |
| 2278 |
pjsip_hdr_shallow_clone(tdata->pool, hdr); |
| 2279 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)allow_hdr); |
| 2280 |
} |
| 2281 |
} |
| 2282 |
|
| 2283 |
|
| 2284 |
hdr = pjsip_endpt_get_capability(inv->dlg->endpt, PJSIP_H_SUPPORTED, NULL); |
| 2285 |
if (hdr) { |
| 2286 |
sup_hdr = (pjsip_supported_hdr*) |
| 2287 |
pjsip_hdr_shallow_clone(tdata->pool, hdr); |
| 2288 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)sup_hdr); |
| 2289 |
} |
| 2290 |
|
| 2291 |
|
| 2292 |
cleanup_allow_sup_hdr(inv->options, NULL, allow_hdr, sup_hdr); |
| 2293 |
|
| 2294 |
|
| 2295 |
if ((inv->options & PJSIP_INV_REQUIRE_100REL) || |
| 2296 |
(inv->options & PJSIP_INV_REQUIRE_TIMER) || |
| 2297 |
(inv->options & PJSIP_INV_REQUIRE_TRICKLE_ICE)) |
| 2298 |
{ |
| 2299 |
pjsip_require_hdr *hreq; |
| 2300 |
|
| 2301 |
hreq = pjsip_require_hdr_create(tdata->pool); |
| 2302 |
|
| 2303 |
if (inv->options & PJSIP_INV_REQUIRE_100REL) |
| 2304 |
hreq->values[hreq->count++] = pj_str("100rel"); |
| 2305 |
if (inv->options & PJSIP_INV_REQUIRE_TIMER) |
| 2306 |
hreq->values[hreq->count++] = pj_str("timer"); |
| 2307 |
if (inv->options & PJSIP_INV_REQUIRE_TRICKLE_ICE) |
| 2308 |
hreq->values[hreq->count++] = pj_str("trickle-ice"); |
| 2309 |
|
| 2310 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*) hreq); |
| 2311 |
} |
| 2312 |
|
| 2313 |
status = pjsip_timer_update_req(inv, tdata); |
| 2314 |
if (status != PJ_SUCCESS) |
| 2315 |
goto on_return; |
| 2316 |
|
| 2317 |
|
| 2318 |
*p_tdata = tdata; |
| 2319 |
|
| 2320 |
|
| 2321 |
on_return: |
| 2322 |
pjsip_dlg_dec_lock(inv->dlg); |
| 2323 |
return status; |
| 2324 |
} |
| 2325 |
|
| 2326 |
|
| 2327 |
|
| 2328 |
static void swap_pool(pj_pool_t **p1, pj_pool_t **p2) |
| 2329 |
{ |
| 2330 |
pj_pool_t *tmp = *p1; |
| 2331 |
*p1 = *p2; |
| 2332 |
*p2 = tmp; |
| 2333 |
} |
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
static pj_status_t inv_negotiate_sdp( pjsip_inv_session *inv ) |
| 2340 |
{ |
| 2341 |
pj_status_t status; |
| 2342 |
|
| 2343 |
PJ_ASSERT_RETURN(pjmedia_sdp_neg_get_state(inv->neg) == |
| 2344 |
PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, |
| 2345 |
PJMEDIA_SDPNEG_EINSTATE); |
| 2346 |
|
| 2347 |
status = pjmedia_sdp_neg_negotiate(inv->pool_prov, inv->neg, 0); |
| 2348 |
|
| 2349 |
PJ_PERROR(4,(inv->obj_name, status, "SDP negotiation done")); |
| 2350 |
|
| 2351 |
if (mod_inv.cb.on_media_update && inv->notify) |
| 2352 |
(*mod_inv.cb.on_media_update)(inv, status); |
| 2353 |
|
| 2354 |
|
| 2355 |
|
| 2356 |
|
| 2357 |
|
| 2358 |
if (inv->state != PJSIP_INV_STATE_DISCONNECTED) { |
| 2359 |
|
| 2360 |
|
| 2361 |
if (status == PJ_SUCCESS) { |
| 2362 |
swap_pool(&inv->pool_prov, &inv->pool_active); |
| 2363 |
} |
| 2364 |
|
| 2365 |
|
| 2366 |
pj_pool_reset(inv->pool_prov); |
| 2367 |
|
| 2368 |
} else { |
| 2369 |
|
| 2370 |
status = PJSIP_ERRNO_FROM_SIP_STATUS(inv->cause); |
| 2371 |
} |
| 2372 |
|
| 2373 |
return status; |
| 2374 |
} |
| 2375 |
|
| 2376 |
|
| 2377 |
|
| 2378 |
|
| 2379 |
static pj_status_t inv_check_sdp_in_incoming_msg( pjsip_inv_session *inv, |
| 2380 |
pjsip_transaction *tsx, |
| 2381 |
pjsip_rx_data *rdata) |
| 2382 |
{ |
| 2383 |
struct tsx_inv_data *tsx_inv_data; |
| 2384 |
pj_status_t status = PJ_SUCCESS; |
| 2385 |
pjsip_msg *msg; |
| 2386 |
pjsip_rdata_sdp_info *sdp_info; |
| 2387 |
|
| 2388 |
|
| 2389 |
|
| 2390 |
msg = rdata->msg_info.msg; |
| 2391 |
if (msg->body == NULL) { |
| 2392 |
|
| 2393 |
return PJ_SUCCESS; |
| 2394 |
} |
| 2395 |
|
| 2396 |
sdp_info = pjsip_rdata_get_sdp_info(rdata); |
| 2397 |
if (sdp_info->body.ptr == NULL) { |
| 2398 |
|
| 2399 |
status = PJMEDIA_SDP_EINSDP; |
| 2400 |
if (PJSIP_INV_ACCEPT_UNKNOWN_BODY) |
| 2401 |
return status; |
| 2402 |
goto on_return; |
| 2403 |
} |
| 2404 |
|
| 2405 |
|
| 2406 |
if (sdp_info->sdp_err) { |
| 2407 |
PJ_PERROR(4,(THIS_FILE, sdp_info->sdp_err, |
| 2408 |
"Error parsing SDP in %s", |
| 2409 |
pjsip_rx_data_get_info(rdata))); |
| 2410 |
status = PJMEDIA_SDP_EINSDP; |
| 2411 |
goto on_return; |
| 2412 |
} |
| 2413 |
|
| 2414 |
|
| 2415 |
tsx_inv_data = (struct tsx_inv_data*) tsx->mod_data[mod_inv.mod.id]; |
| 2416 |
if (tsx_inv_data == NULL) { |
| 2417 |
tsx_inv_data = PJ_POOL_ZALLOC_T(tsx->pool, struct tsx_inv_data); |
| 2418 |
tsx_inv_data->inv = inv; |
| 2419 |
tsx_inv_data->has_sdp = (sdp_info->sdp!=NULL); |
| 2420 |
tsx->mod_data[mod_inv.mod.id] = tsx_inv_data; |
| 2421 |
} |
| 2422 |
|
| 2423 |
|
| 2424 |
inv->following_fork = PJ_FALSE; |
| 2425 |
inv->updated_sdp_answer = PJ_FALSE; |
| 2426 |
|
| 2427 |
|
| 2428 |
|
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
|
| 2433 |
|
| 2434 |
|
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
|
| 2439 |
|
| 2440 |
if (tsx_inv_data->sdp_done) { |
| 2441 |
pj_str_t res_tag; |
| 2442 |
int st_code; |
| 2443 |
|
| 2444 |
res_tag = rdata->msg_info.to->tag; |
| 2445 |
st_code = rdata->msg_info.msg->line.status.code; |
| 2446 |
|
| 2447 |
if (tsx->role == PJSIP_ROLE_UAC && tsx_inv_data->done_early && |
| 2448 |
( |
| 2449 |
|
| 2450 |
( |
| 2451 |
!tsx_inv_data->done_early_rel && |
| 2452 |
(st_code/100 == 2 || st_code/10 == 18) && |
| 2453 |
pjsip_cfg()->endpt.accept_multiple_sdp_answers && |
| 2454 |
!pj_stricmp(&tsx_inv_data->done_tag, &res_tag) |
| 2455 |
) |
| 2456 |
|| |
| 2457 |
|
| 2458 |
( |
| 2459 |
(st_code/100 == 2 || |
| 2460 |
(st_code/10 == 18 && |
| 2461 |
pjsip_cfg()->endpt.follow_early_media_fork)) && |
| 2462 |
pj_stricmp(&tsx_inv_data->done_tag, &res_tag) |
| 2463 |
) |
| 2464 |
) |
| 2465 |
) |
| 2466 |
{ |
| 2467 |
pjsip_sdp_info *tdata_sdp_info; |
| 2468 |
const pjmedia_sdp_session *reoffer_sdp = NULL; |
| 2469 |
|
| 2470 |
if (pjmedia_sdp_neg_get_state(inv->neg) != |
| 2471 |
PJMEDIA_SDP_NEG_STATE_DONE) |
| 2472 |
{ |
| 2473 |
PJ_LOG(4,(inv->obj_name, "SDP negotiation in progress, " |
| 2474 |
"message body in %s response is ignored", |
| 2475 |
(st_code/10==18? "early" : "final" ))); |
| 2476 |
return PJ_SUCCESS; |
| 2477 |
} |
| 2478 |
|
| 2479 |
PJ_LOG(4,(inv->obj_name, "Received %s response " |
| 2480 |
"after SDP negotiation has been done in early " |
| 2481 |
"media. Renegotiating SDP..", |
| 2482 |
(st_code/10==18? "early" : "final" ))); |
| 2483 |
|
| 2484 |
|
| 2485 |
tdata_sdp_info = pjsip_tdata_get_sdp_info(tsx->last_tx); |
| 2486 |
reoffer_sdp = tdata_sdp_info->sdp; |
| 2487 |
|
| 2488 |
|
| 2489 |
status = pjmedia_sdp_neg_modify_local_offer2(inv->pool_prov, |
| 2490 |
inv->neg, |
| 2491 |
inv->sdp_neg_flags, |
| 2492 |
reoffer_sdp); |
| 2493 |
|
| 2494 |
if (status != PJ_SUCCESS) { |
| 2495 |
PJ_LOG(1,(inv->obj_name, "Error updating local offer for " |
| 2496 |
"forked 2xx/18x response (err=%d)", status)); |
| 2497 |
return status; |
| 2498 |
} |
| 2499 |
|
| 2500 |
inv->following_fork = !!pj_stricmp(&tsx_inv_data->done_tag, |
| 2501 |
&res_tag); |
| 2502 |
inv->updated_sdp_answer = PJ_TRUE; |
| 2503 |
|
| 2504 |
} else { |
| 2505 |
|
| 2506 |
if (rdata->msg_info.msg->body) { |
| 2507 |
PJ_LOG(4,(inv->obj_name, "SDP negotiation done, message " |
| 2508 |
"body is ignored")); |
| 2509 |
} |
| 2510 |
return PJ_SUCCESS; |
| 2511 |
} |
| 2512 |
} |
| 2513 |
|
| 2514 |
pj_assert(sdp_info->sdp != NULL); |
| 2515 |
|
| 2516 |
|
| 2517 |
|
| 2518 |
if (inv->neg == NULL || |
| 2519 |
pjmedia_sdp_neg_get_state(inv->neg) == PJMEDIA_SDP_NEG_STATE_DONE) |
| 2520 |
{ |
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
PJ_LOG(5,(inv->obj_name, "Got SDP offer in %s", |
| 2525 |
pjsip_rx_data_get_info(rdata))); |
| 2526 |
|
| 2527 |
if (inv->neg == NULL) { |
| 2528 |
status=pjmedia_sdp_neg_create_w_remote_offer(inv->pool, NULL, |
| 2529 |
sdp_info->sdp, |
| 2530 |
&inv->neg); |
| 2531 |
} else { |
| 2532 |
status=pjmedia_sdp_neg_set_remote_offer(inv->pool_prov, inv->neg, |
| 2533 |
sdp_info->sdp); |
| 2534 |
} |
| 2535 |
|
| 2536 |
if (status != PJ_SUCCESS) { |
| 2537 |
PJ_PERROR(4,(THIS_FILE, status, "Error processing SDP offer in %s", |
| 2538 |
pjsip_rx_data_get_info(rdata))); |
| 2539 |
return PJMEDIA_SDP_EINSDP; |
| 2540 |
} |
| 2541 |
|
| 2542 |
|
| 2543 |
if (mod_inv.cb.on_rx_offer2 && inv->notify) { |
| 2544 |
struct pjsip_inv_on_rx_offer_cb_param param; |
| 2545 |
|
| 2546 |
param.offer = sdp_info->sdp; |
| 2547 |
param.rdata = rdata; |
| 2548 |
(*mod_inv.cb.on_rx_offer2)(inv, ¶m); |
| 2549 |
} else if (mod_inv.cb.on_rx_offer && inv->notify) { |
| 2550 |
(*mod_inv.cb.on_rx_offer)(inv, sdp_info->sdp); |
| 2551 |
} |
| 2552 |
|
| 2553 |
|
| 2554 |
if (pjmedia_sdp_neg_get_state(inv->neg) != |
| 2555 |
PJMEDIA_SDP_NEG_STATE_WAIT_NEGO) |
| 2556 |
{ |
| 2557 |
if (mod_inv.cb.on_rx_reinvite && inv->notify && |
| 2558 |
msg->type == PJSIP_REQUEST_MSG && |
| 2559 |
msg->line.req.method.id == PJSIP_INVITE_METHOD) |
| 2560 |
{ |
| 2561 |
|
| 2562 |
|
| 2563 |
|
| 2564 |
PJ_LOG(5,(inv->obj_name, "Ignoring on_rx_offer() status " |
| 2565 |
"because on_rx_reinvite() is implemented")); |
| 2566 |
return PJ_SUCCESS; |
| 2567 |
} |
| 2568 |
return PJMEDIA_SDPNEG_EINSTATE; |
| 2569 |
} |
| 2570 |
|
| 2571 |
} else if (pjmedia_sdp_neg_get_state(inv->neg) == |
| 2572 |
PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER) |
| 2573 |
{ |
| 2574 |
int status_code; |
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
PJ_LOG(5,(inv->obj_name, "Got SDP answer in %s", |
| 2581 |
pjsip_rx_data_get_info(rdata))); |
| 2582 |
|
| 2583 |
status = pjmedia_sdp_neg_set_remote_answer(inv->pool_prov, inv->neg, |
| 2584 |
sdp_info->sdp); |
| 2585 |
|
| 2586 |
if (status != PJ_SUCCESS) { |
| 2587 |
PJ_PERROR(4,(THIS_FILE, status, "Error processing SDP answer in %s", |
| 2588 |
pjsip_rx_data_get_info(rdata))); |
| 2589 |
status = PJMEDIA_SDP_EINSDP; |
| 2590 |
goto on_return; |
| 2591 |
} |
| 2592 |
|
| 2593 |
|
| 2594 |
|
| 2595 |
inv_negotiate_sdp(inv); |
| 2596 |
|
| 2597 |
|
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
tsx_inv_data->sdp_done = 1; |
| 2602 |
status_code = rdata->msg_info.msg->line.status.code; |
| 2603 |
tsx_inv_data->done_early = (status_code/100==1); |
| 2604 |
tsx_inv_data->done_early_rel = tsx_inv_data->done_early && |
| 2605 |
pjsip_100rel_is_reliable(rdata); |
| 2606 |
if (!inv->sdp_done_early_rel) |
| 2607 |
inv->sdp_done_early_rel = tsx_inv_data->done_early_rel; |
| 2608 |
pj_strdup(tsx->pool, &tsx_inv_data->done_tag, |
| 2609 |
&rdata->msg_info.to->tag); |
| 2610 |
|
| 2611 |
} else { |
| 2612 |
|
| 2613 |
PJ_LOG(5,(THIS_FILE, "Ignored SDP in %s: negotiator state is %s", |
| 2614 |
pjsip_rx_data_get_info(rdata), |
| 2615 |
pjmedia_sdp_neg_state_str(pjmedia_sdp_neg_get_state(inv->neg)))); |
| 2616 |
} |
| 2617 |
|
| 2618 |
on_return: |
| 2619 |
if (status != PJ_SUCCESS && inv->neg && |
| 2620 |
pjmedia_sdp_neg_get_state(inv->neg) == |
| 2621 |
PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER) |
| 2622 |
{ |
| 2623 |
if (mod_inv.cb.on_media_update && inv->notify) |
| 2624 |
(*mod_inv.cb.on_media_update)(inv, status); |
| 2625 |
} |
| 2626 |
|
| 2627 |
return status; |
| 2628 |
} |
| 2629 |
|
| 2630 |
|
| 2631 |
|
| 2632 |
|
| 2633 |
|
| 2634 |
static pj_status_t process_answer( pjsip_inv_session *inv, |
| 2635 |
int st_code, |
| 2636 |
pjsip_tx_data *tdata, |
| 2637 |
const pjmedia_sdp_session *local_sdp) |
| 2638 |
{ |
| 2639 |
pj_status_t status; |
| 2640 |
const pjmedia_sdp_session *sdp = NULL; |
| 2641 |
|
| 2642 |
|
| 2643 |
|
| 2644 |
|
| 2645 |
if (local_sdp && (st_code/100==1 || st_code/100==2)) { |
| 2646 |
|
| 2647 |
if (inv->neg == NULL) { |
| 2648 |
status = pjmedia_sdp_neg_create_w_local_offer(inv->pool, |
| 2649 |
local_sdp, |
| 2650 |
&inv->neg); |
| 2651 |
} else if (pjmedia_sdp_neg_get_state(inv->neg)== |
| 2652 |
PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER) |
| 2653 |
{ |
| 2654 |
status = pjmedia_sdp_neg_set_local_answer(inv->pool_prov, inv->neg, |
| 2655 |
local_sdp); |
| 2656 |
} else { |
| 2657 |
|
| 2658 |
|
| 2659 |
pj_assert(0); |
| 2660 |
status = PJMEDIA_SDPNEG_EINSTATE; |
| 2661 |
} |
| 2662 |
|
| 2663 |
if (status != PJ_SUCCESS) |
| 2664 |
return status; |
| 2665 |
|
| 2666 |
} |
| 2667 |
|
| 2668 |
|
| 2669 |
|
| 2670 |
if (st_code/100==2 || (st_code/10==18 && st_code!=180 && st_code!=181)) { |
| 2671 |
|
| 2672 |
pjmedia_sdp_neg_state neg_state; |
| 2673 |
|
| 2674 |
|
| 2675 |
neg_state = inv->neg ? pjmedia_sdp_neg_get_state(inv->neg) : |
| 2676 |
PJMEDIA_SDP_NEG_STATE_NULL; |
| 2677 |
|
| 2678 |
if (neg_state == PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER) { |
| 2679 |
|
| 2680 |
status = pjmedia_sdp_neg_get_neg_local(inv->neg, &sdp); |
| 2681 |
|
| 2682 |
} else if (neg_state == PJMEDIA_SDP_NEG_STATE_WAIT_NEGO && |
| 2683 |
pjmedia_sdp_neg_has_local_answer(inv->neg) ) |
| 2684 |
{ |
| 2685 |
struct tsx_inv_data *tsx_inv_data; |
| 2686 |
|
| 2687 |
|
| 2688 |
tsx_inv_data = (struct tsx_inv_data*) |
| 2689 |
inv->invite_tsx->mod_data[mod_inv.mod.id]; |
| 2690 |
|
| 2691 |
status = inv_negotiate_sdp(inv); |
| 2692 |
if (status != PJ_SUCCESS) |
| 2693 |
return status; |
| 2694 |
|
| 2695 |
|
| 2696 |
tsx_inv_data->sdp_done = 1; |
| 2697 |
|
| 2698 |
status = pjmedia_sdp_neg_get_active_local(inv->neg, &sdp); |
| 2699 |
} |
| 2700 |
} |
| 2701 |
|
| 2702 |
|
| 2703 |
|
| 2704 |
|
| 2705 |
|
| 2706 |
|
| 2707 |
|
| 2708 |
|
| 2709 |
|
| 2710 |
|
| 2711 |
if (sdp) { |
| 2712 |
tdata->msg->body = create_sdp_body(tdata->pool, sdp); |
| 2713 |
} else { |
| 2714 |
if (inv->options & PJSIP_INV_REQUIRE_100REL) { |
| 2715 |
tdata->msg->body = NULL; |
| 2716 |
} |
| 2717 |
} |
| 2718 |
|
| 2719 |
|
| 2720 |
if (st_code >= 300 && inv->neg != NULL && |
| 2721 |
inv->state == PJSIP_INV_STATE_CONFIRMED) |
| 2722 |
{ |
| 2723 |
pjmedia_sdp_neg_state neg_state; |
| 2724 |
neg_state = pjmedia_sdp_neg_get_state(inv->neg); |
| 2725 |
if (neg_state == PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER) { |
| 2726 |
pjmedia_sdp_neg_cancel_offer(inv->neg); |
| 2727 |
} |
| 2728 |
} |
| 2729 |
|
| 2730 |
return PJ_SUCCESS; |
| 2731 |
} |
| 2732 |
|
| 2733 |
|
| 2734 |
|
| 2735 |
|
| 2736 |
|
| 2737 |
PJ_DEF(pj_status_t) pjsip_inv_initial_answer( pjsip_inv_session *inv, |
| 2738 |
pjsip_rx_data *rdata, |
| 2739 |
int st_code, |
| 2740 |
const pj_str_t *st_text, |
| 2741 |
const pjmedia_sdp_session *sdp, |
| 2742 |
pjsip_tx_data **p_tdata) |
| 2743 |
{ |
| 2744 |
pjsip_tx_data *tdata; |
| 2745 |
pj_status_t status; |
| 2746 |
pjsip_status_code st_code2; |
| 2747 |
|
| 2748 |
|
| 2749 |
PJ_ASSERT_RETURN(inv && p_tdata, PJ_EINVAL); |
| 2750 |
|
| 2751 |
|
| 2752 |
PJ_ASSERT_RETURN(inv->invite_tsx, PJ_EBUG); |
| 2753 |
|
| 2754 |
pj_log_push_indent(); |
| 2755 |
|
| 2756 |
pjsip_dlg_inc_lock(inv->dlg); |
| 2757 |
|
| 2758 |
|
| 2759 |
status = pjsip_dlg_create_response(inv->dlg, rdata, st_code, st_text, |
| 2760 |
&tdata); |
| 2761 |
if (status != PJ_SUCCESS) |
| 2762 |
goto on_return; |
| 2763 |
|
| 2764 |
|
| 2765 |
status = pjsip_timer_process_req(inv, rdata, &st_code2); |
| 2766 |
if (status != PJ_SUCCESS) { |
| 2767 |
pj_status_t status2; |
| 2768 |
|
| 2769 |
status2 = pjsip_dlg_modify_response(inv->dlg, tdata, st_code2, NULL); |
| 2770 |
if (status2 != PJ_SUCCESS) { |
| 2771 |
pjsip_tx_data_dec_ref(tdata); |
| 2772 |
goto on_return; |
| 2773 |
} |
| 2774 |
status2 = pjsip_timer_update_resp(inv, tdata); |
| 2775 |
if (status2 == PJ_SUCCESS) { |
| 2776 |
inv->last_answer = tdata; |
| 2777 |
*p_tdata = tdata; |
| 2778 |
} else { |
| 2779 |
|
| 2780 |
|
| 2781 |
|
| 2782 |
pjsip_tx_data_dec_ref(tdata); |
| 2783 |
pjsip_tx_data_dec_ref(tdata); |
| 2784 |
} |
| 2785 |
|
| 2786 |
goto on_return; |
| 2787 |
} |
| 2788 |
|
| 2789 |
|
| 2790 |
status = process_answer(inv, st_code, tdata, sdp); |
| 2791 |
if (status != PJ_SUCCESS) { |
| 2792 |
pjsip_tx_data_dec_ref(tdata); |
| 2793 |
goto on_return; |
| 2794 |
} |
| 2795 |
|
| 2796 |
|
| 2797 |
cleanup_allow_sup_hdr(inv->options, tdata, NULL, NULL); |
| 2798 |
|
| 2799 |
|
| 2800 |
inv->last_answer = tdata; |
| 2801 |
pjsip_tx_data_add_ref(inv->last_answer); |
| 2802 |
PJ_LOG(5,(inv->dlg->obj_name, "Initial answer %s", |
| 2803 |
pjsip_tx_data_get_info(inv->last_answer))); |
| 2804 |
|
| 2805 |
|
| 2806 |
pjsip_timer_update_resp(inv, tdata); |
| 2807 |
|
| 2808 |
*p_tdata = tdata; |
| 2809 |
|
| 2810 |
on_return: |
| 2811 |
pjsip_dlg_dec_lock(inv->dlg); |
| 2812 |
pj_log_pop_indent(); |
| 2813 |
return status; |
| 2814 |
} |
| 2815 |
|
| 2816 |
|
| 2817 |
|
| 2818 |
|
| 2819 |
|
| 2820 |
PJ_DEF(pj_status_t) pjsip_inv_answer( pjsip_inv_session *inv, |
| 2821 |
int st_code, |
| 2822 |
const pj_str_t *st_text, |
| 2823 |
const pjmedia_sdp_session *local_sdp, |
| 2824 |
pjsip_tx_data **p_tdata ) |
| 2825 |
{ |
| 2826 |
pjsip_tx_data *last_res; |
| 2827 |
pjsip_tx_data *old_res; |
| 2828 |
pj_status_t status; |
| 2829 |
|
| 2830 |
|
| 2831 |
PJ_ASSERT_RETURN(inv && p_tdata, PJ_EINVAL); |
| 2832 |
|
| 2833 |
|
| 2834 |
PJ_ASSERT_RETURN(inv->invite_tsx, PJ_EBUG); |
| 2835 |
|
| 2836 |
|
| 2837 |
PJ_ASSERT_RETURN(inv->last_answer, PJ_EINVALIDOP); |
| 2838 |
|
| 2839 |
pj_log_push_indent(); |
| 2840 |
|
| 2841 |
pjsip_dlg_inc_lock(inv->dlg); |
| 2842 |
|
| 2843 |
|
| 2844 |
|
| 2845 |
|
| 2846 |
|
| 2847 |
|
| 2848 |
status = pjsip_tx_data_clone(inv->last_answer, 0, &last_res); |
| 2849 |
if (status != PJ_SUCCESS) |
| 2850 |
goto on_return; |
| 2851 |
|
| 2852 |
|
| 2853 |
last_res->mod_data[inv->dlg->ua->id] = inv->dlg; |
| 2854 |
|
| 2855 |
|
| 2856 |
status = pjsip_dlg_modify_response(inv->dlg, last_res, st_code, st_text); |
| 2857 |
if (status != PJ_SUCCESS) { |
| 2858 |
pjsip_tx_data_dec_ref(last_res); |
| 2859 |
goto on_return; |
| 2860 |
} |
| 2861 |
|
| 2862 |
|
| 2863 |
if (st_code >= 300) { |
| 2864 |
last_res->msg->body = NULL; |
| 2865 |
} |
| 2866 |
|
| 2867 |
|
| 2868 |
status = process_answer(inv, st_code, last_res, local_sdp); |
| 2869 |
if (status != PJ_SUCCESS) { |
| 2870 |
|
| 2871 |
|
| 2872 |
|
| 2873 |
pjsip_tx_data_dec_ref(last_res); |
| 2874 |
pjsip_tx_data_dec_ref(last_res); |
| 2875 |
goto on_return; |
| 2876 |
} |
| 2877 |
|
| 2878 |
|
| 2879 |
pjsip_timer_update_resp(inv, last_res); |
| 2880 |
|
| 2881 |
|
| 2882 |
cleanup_allow_sup_hdr(inv->options, last_res, NULL, NULL); |
| 2883 |
|
| 2884 |
|
| 2885 |
old_res = inv->last_answer; |
| 2886 |
inv->last_answer = last_res; |
| 2887 |
|
| 2888 |
|
| 2889 |
pjsip_tx_data_dec_ref(old_res); |
| 2890 |
|
| 2891 |
*p_tdata = last_res; |
| 2892 |
|
| 2893 |
on_return: |
| 2894 |
pjsip_dlg_dec_lock(inv->dlg); |
| 2895 |
pj_log_pop_indent(); |
| 2896 |
return status; |
| 2897 |
} |
| 2898 |
|
| 2899 |
|
| 2900 |
|
| 2901 |
|
| 2902 |
|
| 2903 |
PJ_DEF(pj_status_t) pjsip_inv_set_local_sdp(pjsip_inv_session *inv, |
| 2904 |
const pjmedia_sdp_session *sdp ) |
| 2905 |
{ |
| 2906 |
const pjmedia_sdp_session *offer; |
| 2907 |
pj_status_t status; |
| 2908 |
|
| 2909 |
PJ_ASSERT_RETURN(inv && sdp, PJ_EINVAL); |
| 2910 |
|
| 2911 |
pjsip_inv_add_ref(inv); |
| 2912 |
|
| 2913 |
|
| 2914 |
|
| 2915 |
|
| 2916 |
|
| 2917 |
if (inv->neg) { |
| 2918 |
pjmedia_sdp_neg_state neg_state = pjmedia_sdp_neg_get_state(inv->neg); |
| 2919 |
|
| 2920 |
if ((neg_state == PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER || |
| 2921 |
neg_state == PJMEDIA_SDP_NEG_STATE_WAIT_NEGO) && |
| 2922 |
pjmedia_sdp_neg_get_neg_remote(inv->neg, &offer) == PJ_SUCCESS) |
| 2923 |
{ |
| 2924 |
status = pjsip_inv_set_sdp_answer(inv, sdp); |
| 2925 |
} else if (neg_state == PJMEDIA_SDP_NEG_STATE_DONE) { |
| 2926 |
status = pjmedia_sdp_neg_modify_local_offer2(inv->pool, inv->neg, |
| 2927 |
inv->sdp_neg_flags, |
| 2928 |
sdp); |
| 2929 |
} else { |
| 2930 |
pjsip_inv_dec_ref(inv); |
| 2931 |
return PJMEDIA_SDPNEG_EINSTATE; |
| 2932 |
} |
| 2933 |
} else { |
| 2934 |
status = pjmedia_sdp_neg_create_w_local_offer(inv->pool, |
| 2935 |
sdp, &inv->neg); |
| 2936 |
} |
| 2937 |
|
| 2938 |
pjsip_inv_dec_ref(inv); |
| 2939 |
|
| 2940 |
return status; |
| 2941 |
} |
| 2942 |
|
| 2943 |
|
| 2944 |
|
| 2945 |
|
| 2946 |
|
| 2947 |
PJ_DEF(pj_status_t) pjsip_inv_set_sdp_answer( pjsip_inv_session *inv, |
| 2948 |
const pjmedia_sdp_session *sdp ) |
| 2949 |
{ |
| 2950 |
pj_status_t status; |
| 2951 |
|
| 2952 |
PJ_ASSERT_RETURN(inv && sdp, PJ_EINVAL); |
| 2953 |
|
| 2954 |
pjsip_dlg_inc_lock(inv->dlg); |
| 2955 |
status = pjmedia_sdp_neg_set_local_answer( inv->pool_prov, inv->neg, sdp); |
| 2956 |
pjsip_dlg_dec_lock(inv->dlg); |
| 2957 |
|
| 2958 |
return status; |
| 2959 |
} |
| 2960 |
|
| 2961 |
|
| 2962 |
|
| 2963 |
|
| 2964 |
|
| 2965 |
PJ_DEF(pj_status_t) pjsip_inv_end_session( pjsip_inv_session *inv, |
| 2966 |
int st_code, |
| 2967 |
const pj_str_t *st_text, |
| 2968 |
pjsip_tx_data **p_tdata ) |
| 2969 |
{ |
| 2970 |
pjsip_tx_data *tdata; |
| 2971 |
pj_status_t status; |
| 2972 |
|
| 2973 |
|
| 2974 |
PJ_ASSERT_RETURN(inv && p_tdata, PJ_EINVAL); |
| 2975 |
|
| 2976 |
pj_log_push_indent(); |
| 2977 |
pjsip_inv_add_ref(inv); |
| 2978 |
|
| 2979 |
|
| 2980 |
inv_set_cause(inv, st_code, st_text); |
| 2981 |
|
| 2982 |
|
| 2983 |
switch (inv->state) { |
| 2984 |
case PJSIP_INV_STATE_NULL: |
| 2985 |
case PJSIP_INV_STATE_CALLING: |
| 2986 |
case PJSIP_INV_STATE_EARLY: |
| 2987 |
case PJSIP_INV_STATE_INCOMING: |
| 2988 |
|
| 2989 |
if (inv->role == PJSIP_ROLE_UAC) { |
| 2990 |
|
| 2991 |
|
| 2992 |
|
| 2993 |
|
| 2994 |
PJ_ASSERT_ON_FAIL(inv->invite_tsx != NULL, |
| 2995 |
{ pjsip_inv_dec_ref(inv); return PJ_EBUG; }); |
| 2996 |
|
| 2997 |
|
| 2998 |
|
| 2999 |
|
| 3000 |
|
| 3001 |
if (inv->invite_tsx->status_code < 100) { |
| 3002 |
|
| 3003 |
|
| 3004 |
|
| 3005 |
inv->cancelling = PJ_TRUE; |
| 3006 |
inv->pending_cancel = PJ_TRUE; |
| 3007 |
*p_tdata = NULL; |
| 3008 |
PJ_LOG(4, (inv->obj_name, "Delaying CANCEL since no " |
| 3009 |
"provisional response is received yet")); |
| 3010 |
pjsip_inv_dec_ref(inv); |
| 3011 |
pj_log_pop_indent(); |
| 3012 |
return PJ_SUCCESS; |
| 3013 |
} |
| 3014 |
|
| 3015 |
|
| 3016 |
|
| 3017 |
|
| 3018 |
|
| 3019 |
|
| 3020 |
status = pjsip_endpt_create_cancel(inv->dlg->endpt, |
| 3021 |
inv->invite_tsx->last_tx, |
| 3022 |
&tdata); |
| 3023 |
if (status != PJ_SUCCESS) { |
| 3024 |
pjsip_inv_dec_ref(inv); |
| 3025 |
pj_log_pop_indent(); |
| 3026 |
return status; |
| 3027 |
} |
| 3028 |
|
| 3029 |
if (st_text && st_text->slen) |
| 3030 |
add_reason_warning_hdr(tdata, st_code, st_text); |
| 3031 |
|
| 3032 |
|
| 3033 |
|
| 3034 |
|
| 3035 |
|
| 3036 |
pjsip_tsx_set_timeout(inv->invite_tsx, 64 * pjsip_cfg()->tsx.t1); |
| 3037 |
|
| 3038 |
} else { |
| 3039 |
|
| 3040 |
|
| 3041 |
tdata = inv->invite_tsx->last_tx; |
| 3042 |
if (tdata == NULL) |
| 3043 |
tdata = inv->last_answer; |
| 3044 |
|
| 3045 |
PJ_ASSERT_ON_FAIL(tdata != NULL, |
| 3046 |
{ pjsip_inv_dec_ref(inv); |
| 3047 |
return PJ_EINVALIDOP; }); |
| 3048 |
|
| 3049 |
|
| 3050 |
|
| 3051 |
status = pjsip_inv_answer(inv, st_code, st_text, NULL, &tdata); |
| 3052 |
} |
| 3053 |
break; |
| 3054 |
|
| 3055 |
case PJSIP_INV_STATE_CONNECTING: |
| 3056 |
case PJSIP_INV_STATE_CONFIRMED: |
| 3057 |
|
| 3058 |
pjsip_timer_end_session(inv); |
| 3059 |
|
| 3060 |
|
| 3061 |
status = pjsip_dlg_create_request(inv->dlg, pjsip_get_bye_method(), |
| 3062 |
-1, &tdata); |
| 3063 |
if (status == PJ_SUCCESS && st_text && st_text->slen) |
| 3064 |
add_reason_warning_hdr(tdata, st_code, st_text); |
| 3065 |
break; |
| 3066 |
|
| 3067 |
case PJSIP_INV_STATE_DISCONNECTED: |
| 3068 |
|
| 3069 |
pjsip_inv_dec_ref(inv); |
| 3070 |
pj_log_pop_indent(); |
| 3071 |
return PJSIP_ESESSIONTERMINATED; |
| 3072 |
|
| 3073 |
default: |
| 3074 |
pj_assert(!"Invalid operation!"); |
| 3075 |
pjsip_inv_dec_ref(inv); |
| 3076 |
pj_log_pop_indent(); |
| 3077 |
return PJ_EINVALIDOP; |
| 3078 |
} |
| 3079 |
|
| 3080 |
if (status != PJ_SUCCESS) { |
| 3081 |
pjsip_inv_dec_ref(inv); |
| 3082 |
pj_log_pop_indent(); |
| 3083 |
return status; |
| 3084 |
} |
| 3085 |
|
| 3086 |
|
| 3087 |
|
| 3088 |
|
| 3089 |
inv->cancelling = PJ_TRUE; |
| 3090 |
*p_tdata = tdata; |
| 3091 |
|
| 3092 |
pjsip_inv_dec_ref(inv); |
| 3093 |
pj_log_pop_indent(); |
| 3094 |
return PJ_SUCCESS; |
| 3095 |
} |
| 3096 |
|
| 3097 |
|
| 3098 |
|
| 3099 |
|
| 3100 |
PJ_DEF(pj_status_t) pjsip_inv_cancel_reinvite( pjsip_inv_session *inv, |
| 3101 |
pjsip_tx_data **p_tdata ) |
| 3102 |
{ |
| 3103 |
pjsip_tx_data *tdata; |
| 3104 |
pj_status_t status; |
| 3105 |
|
| 3106 |
|
| 3107 |
PJ_ASSERT_RETURN(inv && p_tdata, PJ_EINVAL); |
| 3108 |
|
| 3109 |
pj_log_push_indent(); |
| 3110 |
pjsip_inv_add_ref(inv); |
| 3111 |
|
| 3112 |
|
| 3113 |
switch (inv->state) { |
| 3114 |
case PJSIP_INV_STATE_CONFIRMED: |
| 3115 |
|
| 3116 |
PJ_ASSERT_RETURN(inv->invite_tsx != NULL, PJ_EBUG); |
| 3117 |
|
| 3118 |
|
| 3119 |
|
| 3120 |
|
| 3121 |
if (inv->invite_tsx->status_code < 100) { |
| 3122 |
inv->cancelling = PJ_TRUE; |
| 3123 |
inv->pending_cancel = PJ_TRUE; |
| 3124 |
*p_tdata = NULL; |
| 3125 |
PJ_LOG(4, (inv->obj_name, "Delaying CANCEL since no " |
| 3126 |
"provisional response is received yet")); |
| 3127 |
pjsip_inv_dec_ref(inv); |
| 3128 |
pj_log_pop_indent(); |
| 3129 |
return PJ_SUCCESS; |
| 3130 |
} |
| 3131 |
|
| 3132 |
status = pjsip_endpt_create_cancel(inv->dlg->endpt, |
| 3133 |
inv->invite_tsx->last_tx, |
| 3134 |
&tdata); |
| 3135 |
if (status != PJ_SUCCESS) { |
| 3136 |
pjsip_inv_dec_ref(inv); |
| 3137 |
pj_log_pop_indent(); |
| 3138 |
return status; |
| 3139 |
} |
| 3140 |
break; |
| 3141 |
|
| 3142 |
default: |
| 3143 |
|
| 3144 |
|
| 3145 |
|
| 3146 |
pjsip_inv_dec_ref(inv); |
| 3147 |
pj_log_pop_indent(); |
| 3148 |
return PJ_EINVALIDOP; |
| 3149 |
} |
| 3150 |
|
| 3151 |
pjsip_inv_dec_ref(inv); |
| 3152 |
pj_log_pop_indent(); |
| 3153 |
|
| 3154 |
*p_tdata = tdata; |
| 3155 |
return PJ_SUCCESS; |
| 3156 |
} |
| 3157 |
|
| 3158 |
|
| 3159 |
|
| 3160 |
|
| 3161 |
|
| 3162 |
|
| 3163 |
|
| 3164 |
|
| 3165 |
|
| 3166 |
|
| 3167 |
|
| 3168 |
static pj_bool_t inv_uac_recurse(pjsip_inv_session *inv, int code, |
| 3169 |
const pj_str_t *reason, pjsip_event *e) |
| 3170 |
{ |
| 3171 |
pjsip_redirect_op op; |
| 3172 |
pjsip_target *target; |
| 3173 |
|
| 3174 |
|
| 3175 |
if (mod_inv.cb.on_redirected == NULL) |
| 3176 |
return PJ_FALSE; |
| 3177 |
|
| 3178 |
if (reason == NULL) |
| 3179 |
reason = pjsip_get_status_text(code); |
| 3180 |
|
| 3181 |
|
| 3182 |
pjsip_target_assign_status(inv->dlg->target_set.current, inv->dlg->pool, |
| 3183 |
code, reason); |
| 3184 |
|
| 3185 |
|
| 3186 |
|
| 3187 |
|
| 3188 |
for (;;) { |
| 3189 |
target = pjsip_target_set_get_next(&inv->dlg->target_set); |
| 3190 |
if (target == NULL) { |
| 3191 |
|
| 3192 |
return PJ_FALSE; |
| 3193 |
} |
| 3194 |
|
| 3195 |
if (!PJSIP_URI_SCHEME_IS_SIP(target->uri) && |
| 3196 |
!PJSIP_URI_SCHEME_IS_SIPS(target->uri)) |
| 3197 |
{ |
| 3198 |
code = PJSIP_SC_UNSUPPORTED_URI_SCHEME; |
| 3199 |
reason = pjsip_get_status_text(code); |
| 3200 |
|
| 3201 |
|
| 3202 |
pjsip_target_assign_status(target, inv->dlg->pool, code, reason); |
| 3203 |
} else { |
| 3204 |
|
| 3205 |
break; |
| 3206 |
} |
| 3207 |
} |
| 3208 |
|
| 3209 |
|
| 3210 |
|
| 3211 |
|
| 3212 |
pjsip_target_set_set_current(&inv->dlg->target_set, target); |
| 3213 |
|
| 3214 |
op = (*mod_inv.cb.on_redirected)(inv, target->uri, e); |
| 3215 |
|
| 3216 |
|
| 3217 |
|
| 3218 |
switch (op) { |
| 3219 |
case PJSIP_REDIRECT_ACCEPT: |
| 3220 |
case PJSIP_REDIRECT_ACCEPT_REPLACE: |
| 3221 |
case PJSIP_REDIRECT_STOP: |
| 3222 |
|
| 3223 |
|
| 3224 |
|
| 3225 |
pjsip_dlg_inc_session(inv->dlg, &mod_inv.mod); |
| 3226 |
|
| 3227 |
|
| 3228 |
pjsip_inv_process_redirect(inv, op, e); |
| 3229 |
return PJ_TRUE; |
| 3230 |
|
| 3231 |
case PJSIP_REDIRECT_PENDING: |
| 3232 |
|
| 3233 |
|
| 3234 |
|
| 3235 |
pjsip_dlg_inc_session(inv->dlg, &mod_inv.mod); |
| 3236 |
|
| 3237 |
|
| 3238 |
|
| 3239 |
|
| 3240 |
inv->invite_tsx = NULL; |
| 3241 |
|
| 3242 |
|
| 3243 |
|
| 3244 |
|
| 3245 |
return PJ_TRUE; |
| 3246 |
|
| 3247 |
case PJSIP_REDIRECT_REJECT: |
| 3248 |
|
| 3249 |
|
| 3250 |
return inv_uac_recurse(inv, PJSIP_SC_REQUEST_TERMINATED, NULL, e); |
| 3251 |
|
| 3252 |
} |
| 3253 |
|
| 3254 |
pj_assert(!"Should not reach here"); |
| 3255 |
return PJ_FALSE; |
| 3256 |
} |
| 3257 |
|
| 3258 |
PJ_DEF(pj_bool_t) pjsip_inv_uac_try_next_target(pjsip_inv_session *inv) |
| 3259 |
{ |
| 3260 |
PJ_ASSERT_RETURN(inv, PJ_FALSE); |
| 3261 |
return inv_uac_recurse(inv, PJSIP_SC_UNAUTHORIZED, |
| 3262 |
pjsip_get_status_text(PJSIP_SC_UNAUTHORIZED), |
| 3263 |
NULL); |
| 3264 |
} |
| 3265 |
|
| 3266 |
|
| 3267 |
|
| 3268 |
void pjsip_inv_process_hparam(pjsip_inv_session *sess, |
| 3269 |
const pj_str_t *hname, |
| 3270 |
const pj_str_t *hvalue, |
| 3271 |
pjsip_tx_data *tdata) |
| 3272 |
{ |
| 3273 |
const pjsip_hdr_e ignored_hdrs[] = { |
| 3274 |
|
| 3275 |
|
| 3276 |
|
| 3277 |
|
| 3278 |
PJSIP_H_ACCEPT, PJSIP_H_ACCEPT_ENCODING_UNIMP, |
| 3279 |
PJSIP_H_ACCEPT_LANGUAGE_UNIMP, PJSIP_H_ALLOW, |
| 3280 |
PJSIP_H_CALL_ID, PJSIP_H_CONTACT, PJSIP_H_CSEQ, |
| 3281 |
PJSIP_H_FROM, PJSIP_H_ORGANIZATION_UNIMP, |
| 3282 |
PJSIP_H_RECORD_ROUTE, PJSIP_H_ROUTE, |
| 3283 |
PJSIP_H_SUPPORTED, PJSIP_H_TO, |
| 3284 |
PJSIP_H_USER_AGENT_UNIMP, PJSIP_H_VIA, |
| 3285 |
|
| 3286 |
|
| 3287 |
|
| 3288 |
PJSIP_H_CONTENT_LENGTH, PJSIP_H_CONTENT_TYPE, |
| 3289 |
|
| 3290 |
|
| 3291 |
|
| 3292 |
|
| 3293 |
PJSIP_H_PROXY_AUTHENTICATE, PJSIP_H_PROXY_AUTHORIZATION |
| 3294 |
}; |
| 3295 |
|
| 3296 |
|
| 3297 |
|
| 3298 |
|
| 3299 |
|
| 3300 |
const pjsip_hdr_e verify_hdrs[] = { |
| 3301 |
PJSIP_H_CONTENT_DISPOSITION_UNIMP, |
| 3302 |
PJSIP_H_CONTENT_ENCODING_UNIMP, |
| 3303 |
PJSIP_H_CONTENT_LANGUAGE_UNIMP, |
| 3304 |
PJSIP_H_DATE_UNIMP, PJSIP_H_MIME_VERSION_UNIMP, |
| 3305 |
PJSIP_H_TIMESTAMP_UNIMP |
| 3306 |
|
| 3307 |
|
| 3308 |
|
| 3309 |
|
| 3310 |
|
| 3311 |
}; |
| 3312 |
const pjsip_hdr_e append_hdrs[] = { |
| 3313 |
|
| 3314 |
|
| 3315 |
|
| 3316 |
|
| 3317 |
|
| 3318 |
|
| 3319 |
|
| 3320 |
PJSIP_H_CALL_INFO_UNIMP |
| 3321 |
}; |
| 3322 |
|
| 3323 |
unsigned i; |
| 3324 |
pjsip_hdr *hdr; |
| 3325 |
|
| 3326 |
PJ_UNUSED_ARG(sess); |
| 3327 |
PJ_UNUSED_ARG(verify_hdrs); |
| 3328 |
|
| 3329 |
|
| 3330 |
for (i = 0; i < PJ_ARRAY_SIZE(ignored_hdrs); i++) { |
| 3331 |
if (!pj_stricmp2(hname, pjsip_hdr_names[ignored_hdrs[i]].name)) { |
| 3332 |
PJ_LOG(4, (THIS_FILE, "Redirection header %.*s ignored", |
| 3333 |
(int)hname->slen, |
| 3334 |
hname->ptr)); |
| 3335 |
return; |
| 3336 |
} |
| 3337 |
} |
| 3338 |
|
| 3339 |
hdr = pjsip_msg_find_hdr_by_name(tdata->msg, hname, NULL); |
| 3340 |
|
| 3341 |
|
| 3342 |
if (hdr) { |
| 3343 |
|
| 3344 |
for (i = 0; i < PJ_ARRAY_SIZE(append_hdrs); i++) { |
| 3345 |
if (!pj_stricmp2(hname, pjsip_hdr_names[append_hdrs[i]].name)) { |
| 3346 |
pjsip_generic_string_hdr *shdr; |
| 3347 |
pj_str_t old_hval; |
| 3348 |
|
| 3349 |
shdr = (pjsip_generic_string_hdr *)hdr; |
| 3350 |
old_hval = shdr->hvalue; |
| 3351 |
|
| 3352 |
|
| 3353 |
|
| 3354 |
|
| 3355 |
pj_bzero(&shdr->hvalue, sizeof(pj_str_t)); |
| 3356 |
shdr->hvalue.ptr = (char *) pj_pool_alloc(tdata->pool, |
| 3357 |
old_hval.slen + |
| 3358 |
hvalue->slen + 2); |
| 3359 |
pj_strcat(&shdr->hvalue, &old_hval); |
| 3360 |
pj_strcat2(&shdr->hvalue, ", "); |
| 3361 |
pj_strcat(&shdr->hvalue, hvalue); |
| 3362 |
|
| 3363 |
return; |
| 3364 |
} |
| 3365 |
} |
| 3366 |
|
| 3367 |
|
| 3368 |
pjsip_msg_find_remove_hdr(tdata->msg, PJSIP_H_OTHER, hdr); |
| 3369 |
} |
| 3370 |
|
| 3371 |
|
| 3372 |
hdr = (pjsip_hdr *)pjsip_generic_string_hdr_create(tdata->pool, hname, |
| 3373 |
hvalue); |
| 3374 |
pjsip_msg_add_hdr(tdata->msg, hdr); |
| 3375 |
} |
| 3376 |
|
| 3377 |
|
| 3378 |
|
| 3379 |
PJ_DEF(pj_status_t) pjsip_inv_process_redirect( pjsip_inv_session *inv, |
| 3380 |
pjsip_redirect_op op, |
| 3381 |
pjsip_event *e) |
| 3382 |
{ |
| 3383 |
const pjsip_status_code cancel_code = PJSIP_SC_REQUEST_TERMINATED; |
| 3384 |
pjsip_event usr_event; |
| 3385 |
pj_status_t status = PJ_SUCCESS; |
| 3386 |
|
| 3387 |
PJ_ASSERT_RETURN(inv && op != PJSIP_REDIRECT_PENDING, PJ_EINVAL); |
| 3388 |
|
| 3389 |
if (e == NULL) { |
| 3390 |
PJSIP_EVENT_INIT_USER(usr_event, NULL, NULL, NULL, NULL); |
| 3391 |
e = &usr_event; |
| 3392 |
} |
| 3393 |
|
| 3394 |
pjsip_dlg_inc_lock(inv->dlg); |
| 3395 |
|
| 3396 |
|
| 3397 |
|
| 3398 |
|
| 3399 |
|
| 3400 |
pjsip_dlg_dec_session(inv->dlg, &mod_inv.mod); |
| 3401 |
|
| 3402 |
|
| 3403 |
switch (op) { |
| 3404 |
case PJSIP_REDIRECT_ACCEPT: |
| 3405 |
case PJSIP_REDIRECT_ACCEPT_REPLACE: |
| 3406 |
|
| 3407 |
|
| 3408 |
|
| 3409 |
{ |
| 3410 |
pjsip_tx_data *tdata; |
| 3411 |
pjsip_via_hdr *via; |
| 3412 |
pjsip_uri *req_uri; |
| 3413 |
|
| 3414 |
|
| 3415 |
tdata = inv->invite_req; |
| 3416 |
pjsip_tx_data_add_ref(tdata); |
| 3417 |
|
| 3418 |
|
| 3419 |
|
| 3420 |
|
| 3421 |
pjsip_restore_strict_route_set(tdata); |
| 3422 |
|
| 3423 |
|
| 3424 |
tdata->msg->line.req.uri = req_uri = (pjsip_uri*) |
| 3425 |
pjsip_uri_clone(tdata->pool, inv->dlg->target_set.current->uri); |
| 3426 |
|
| 3427 |
if (PJSIP_URI_SCHEME_IS_SIP(req_uri) || |
| 3428 |
PJSIP_URI_SCHEME_IS_SIPS(req_uri)) |
| 3429 |
{ |
| 3430 |
pjsip_sip_uri *uri; |
| 3431 |
pjsip_param *param; |
| 3432 |
|
| 3433 |
uri = (pjsip_sip_uri *)pjsip_uri_get_uri(req_uri); |
| 3434 |
|
| 3435 |
|
| 3436 |
|
| 3437 |
|
| 3438 |
if (uri->method_param.slen > 0) { |
| 3439 |
|
| 3440 |
|
| 3441 |
|
| 3442 |
|
| 3443 |
if (pj_stricmp(&uri->method_param, |
| 3444 |
&pjsip_get_invite_method()->name)) |
| 3445 |
{ |
| 3446 |
PJ_LOG(3, (THIS_FILE, "Redirection using %.*s " |
| 3447 |
"method unsupported, terminating session", |
| 3448 |
(int)uri->method_param.slen, |
| 3449 |
uri->method_param.ptr)); |
| 3450 |
|
| 3451 |
inv_set_cause(inv, cancel_code, |
| 3452 |
pjsip_get_status_text(cancel_code)); |
| 3453 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); |
| 3454 |
|
| 3455 |
status = PJSIP_EINVALIDMETHOD; |
| 3456 |
break; |
| 3457 |
} |
| 3458 |
pj_bzero(&uri->method_param, sizeof(pj_str_t)); |
| 3459 |
} |
| 3460 |
|
| 3461 |
|
| 3462 |
param = uri->header_param.next; |
| 3463 |
while (param != &uri->header_param) { |
| 3464 |
(*pjsip_inv_process_hparam_ptr)(inv, ¶m->name, |
| 3465 |
¶m->value, |
| 3466 |
tdata); |
| 3467 |
param = param->next; |
| 3468 |
} |
| 3469 |
|
| 3470 |
|
| 3471 |
if (!pj_list_empty(&uri->header_param)) { |
| 3472 |
pj_list_init(&uri->header_param); |
| 3473 |
} |
| 3474 |
} |
| 3475 |
|
| 3476 |
|
| 3477 |
via = (pjsip_via_hdr*) |
| 3478 |
pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL); |
| 3479 |
via->branch_param.slen = 0; |
| 3480 |
|
| 3481 |
|
| 3482 |
if (op == PJSIP_REDIRECT_ACCEPT_REPLACE) { |
| 3483 |
pjsip_to_hdr *to; |
| 3484 |
pjsip_dialog *dlg = inv->dlg; |
| 3485 |
enum { TMP_LEN = PJSIP_MAX_URL_SIZE }; |
| 3486 |
char tmp[TMP_LEN]; |
| 3487 |
int len; |
| 3488 |
|
| 3489 |
|
| 3490 |
to = PJSIP_MSG_TO_HDR(tdata->msg); |
| 3491 |
to->uri = (pjsip_uri*) |
| 3492 |
pjsip_uri_clone(tdata->pool, |
| 3493 |
dlg->target_set.current->uri); |
| 3494 |
to->tag.slen = 0; |
| 3495 |
pj_list_init(&to->other_param); |
| 3496 |
|
| 3497 |
|
| 3498 |
dlg->remote.info = (pjsip_to_hdr*) |
| 3499 |
pjsip_hdr_clone(dlg->pool, to); |
| 3500 |
|
| 3501 |
|
| 3502 |
if (PJSIP_URI_SCHEME_IS_SIP(dlg->remote.info->uri) || |
| 3503 |
PJSIP_URI_SCHEME_IS_SIPS(dlg->remote.info->uri)) |
| 3504 |
{ |
| 3505 |
pjsip_sip_uri *sip_uri = (pjsip_sip_uri *) |
| 3506 |
pjsip_uri_get_uri(dlg->remote.info->uri); |
| 3507 |
if (!pj_list_empty(&sip_uri->header_param)) { |
| 3508 |
|
| 3509 |
pj_list_init(&sip_uri->header_param); |
| 3510 |
} |
| 3511 |
} |
| 3512 |
|
| 3513 |
|
| 3514 |
len = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, |
| 3515 |
dlg->remote.info->uri, tmp, TMP_LEN); |
| 3516 |
if (len < 1) { |
| 3517 |
pj_ansi_strxcpy(tmp, "<-error: uri too long->", |
| 3518 |
sizeof(tmp)); |
| 3519 |
len = (int)pj_ansi_strlen(tmp); |
| 3520 |
} |
| 3521 |
pj_strdup2_with_null(dlg->pool, &dlg->remote.info_str, tmp); |
| 3522 |
|
| 3523 |
|
| 3524 |
dlg->secure = PJSIP_URI_SCHEME_IS_SIPS(to->uri); |
| 3525 |
} |
| 3526 |
|
| 3527 |
|
| 3528 |
pj_bzero(&tdata->dest_info, sizeof(tdata->dest_info)); |
| 3529 |
|
| 3530 |
|
| 3531 |
pjsip_tx_data_invalidate_msg(tdata); |
| 3532 |
|
| 3533 |
|
| 3534 |
pjsip_inv_uac_restart(inv, PJ_FALSE); |
| 3535 |
|
| 3536 |
|
| 3537 |
status = pjsip_inv_send_msg(inv, tdata); |
| 3538 |
} |
| 3539 |
break; |
| 3540 |
|
| 3541 |
case PJSIP_REDIRECT_STOP: |
| 3542 |
|
| 3543 |
inv_set_cause(inv, cancel_code, pjsip_get_status_text(cancel_code)); |
| 3544 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); |
| 3545 |
|
| 3546 |
|
| 3547 |
|
| 3548 |
|
| 3549 |
break; |
| 3550 |
|
| 3551 |
case PJSIP_REDIRECT_REJECT: |
| 3552 |
|
| 3553 |
if (inv_uac_recurse(inv, cancel_code, NULL, NULL) == PJ_FALSE) { |
| 3554 |
inv_set_cause(inv, cancel_code, |
| 3555 |
pjsip_get_status_text(cancel_code)); |
| 3556 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); |
| 3557 |
|
| 3558 |
|
| 3559 |
status = PJSIP_ESESSIONTERMINATED; |
| 3560 |
} |
| 3561 |
break; |
| 3562 |
|
| 3563 |
|
| 3564 |
case PJSIP_REDIRECT_PENDING: |
| 3565 |
pj_assert(!"Should not happen"); |
| 3566 |
break; |
| 3567 |
} |
| 3568 |
|
| 3569 |
|
| 3570 |
pjsip_dlg_dec_lock(inv->dlg); |
| 3571 |
|
| 3572 |
return status; |
| 3573 |
} |
| 3574 |
|
| 3575 |
|
| 3576 |
|
| 3577 |
|
| 3578 |
|
| 3579 |
PJ_DEF(pj_status_t) pjsip_inv_reinvite( pjsip_inv_session *inv, |
| 3580 |
const pj_str_t *new_contact, |
| 3581 |
const pjmedia_sdp_session *new_offer, |
| 3582 |
pjsip_tx_data **p_tdata ) |
| 3583 |
{ |
| 3584 |
pj_status_t status; |
| 3585 |
pjsip_contact_hdr *contact_hdr = NULL; |
| 3586 |
|
| 3587 |
|
| 3588 |
PJ_ASSERT_RETURN(inv && p_tdata, PJ_EINVAL); |
| 3589 |
|
| 3590 |
|
| 3591 |
if (inv->invite_tsx!=NULL) |
| 3592 |
return PJ_EINVALIDOP; |
| 3593 |
|
| 3594 |
pj_log_push_indent(); |
| 3595 |
|
| 3596 |
pjsip_dlg_inc_lock(inv->dlg); |
| 3597 |
|
| 3598 |
if (new_contact) { |
| 3599 |
pj_str_t tmp; |
| 3600 |
const pj_str_t STR_CONTACT = { "Contact", 7 }; |
| 3601 |
|
| 3602 |
pj_strdup_with_null(inv->dlg->pool, &tmp, new_contact); |
| 3603 |
contact_hdr = (pjsip_contact_hdr*) |
| 3604 |
pjsip_parse_hdr(inv->dlg->pool, &STR_CONTACT, |
| 3605 |
tmp.ptr, tmp.slen, NULL); |
| 3606 |
if (!contact_hdr) { |
| 3607 |
status = PJSIP_EINVALIDURI; |
| 3608 |
goto on_return; |
| 3609 |
} |
| 3610 |
} |
| 3611 |
|
| 3612 |
|
| 3613 |
if (new_offer) { |
| 3614 |
if (!inv->neg) { |
| 3615 |
status = pjmedia_sdp_neg_create_w_local_offer(inv->pool, |
| 3616 |
new_offer, |
| 3617 |
&inv->neg); |
| 3618 |
if (status != PJ_SUCCESS) |
| 3619 |
goto on_return; |
| 3620 |
|
| 3621 |
} else switch (pjmedia_sdp_neg_get_state(inv->neg)) { |
| 3622 |
|
| 3623 |
case PJMEDIA_SDP_NEG_STATE_NULL: |
| 3624 |
pj_assert(!"Unexpected SDP neg state NULL"); |
| 3625 |
status = PJ_EBUG; |
| 3626 |
goto on_return; |
| 3627 |
|
| 3628 |
case PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER: |
| 3629 |
PJ_LOG(4,(inv->obj_name, |
| 3630 |
"pjsip_inv_reinvite: already have an offer, new " |
| 3631 |
"offer is ignored")); |
| 3632 |
break; |
| 3633 |
|
| 3634 |
case PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER: |
| 3635 |
status = pjmedia_sdp_neg_set_local_answer(inv->pool_prov, |
| 3636 |
inv->neg, |
| 3637 |
new_offer); |
| 3638 |
if (status != PJ_SUCCESS) |
| 3639 |
goto on_return; |
| 3640 |
break; |
| 3641 |
|
| 3642 |
case PJMEDIA_SDP_NEG_STATE_WAIT_NEGO: |
| 3643 |
PJ_LOG(4,(inv->obj_name, |
| 3644 |
"pjsip_inv_reinvite: SDP in WAIT_NEGO state, new " |
| 3645 |
"offer is ignored")); |
| 3646 |
break; |
| 3647 |
|
| 3648 |
case PJMEDIA_SDP_NEG_STATE_DONE: |
| 3649 |
status = pjmedia_sdp_neg_modify_local_offer2( |
| 3650 |
inv->pool_prov, inv->neg, |
| 3651 |
inv->sdp_neg_flags, new_offer); |
| 3652 |
if (status != PJ_SUCCESS) |
| 3653 |
goto on_return; |
| 3654 |
break; |
| 3655 |
} |
| 3656 |
} |
| 3657 |
|
| 3658 |
if (contact_hdr) |
| 3659 |
inv->dlg->local.contact = contact_hdr; |
| 3660 |
|
| 3661 |
status = pjsip_inv_invite(inv, p_tdata); |
| 3662 |
|
| 3663 |
on_return: |
| 3664 |
pjsip_dlg_dec_lock(inv->dlg); |
| 3665 |
pj_log_pop_indent(); |
| 3666 |
return status; |
| 3667 |
} |
| 3668 |
|
| 3669 |
|
| 3670 |
|
| 3671 |
|
| 3672 |
PJ_DEF(pj_status_t) pjsip_inv_update ( pjsip_inv_session *inv, |
| 3673 |
const pj_str_t *new_contact, |
| 3674 |
const pjmedia_sdp_session *offer, |
| 3675 |
pjsip_tx_data **p_tdata ) |
| 3676 |
{ |
| 3677 |
pjsip_contact_hdr *contact_hdr = NULL; |
| 3678 |
pjsip_tx_data *tdata = NULL; |
| 3679 |
pjmedia_sdp_session *sdp_copy; |
| 3680 |
const pjsip_hdr *hdr; |
| 3681 |
pjsip_supported_hdr *sup_hdr = NULL; |
| 3682 |
pj_status_t status = PJ_SUCCESS; |
| 3683 |
|
| 3684 |
|
| 3685 |
PJ_ASSERT_RETURN(inv && p_tdata, PJ_EINVAL); |
| 3686 |
|
| 3687 |
|
| 3688 |
PJ_ASSERT_RETURN(inv->dlg->state == PJSIP_DIALOG_STATE_ESTABLISHED, |
| 3689 |
PJ_EINVALIDOP); |
| 3690 |
|
| 3691 |
|
| 3692 |
PJ_ASSERT_RETURN(inv->state < PJSIP_INV_STATE_DISCONNECTED, |
| 3693 |
PJ_EINVALIDOP); |
| 3694 |
|
| 3695 |
pj_log_push_indent(); |
| 3696 |
|
| 3697 |
|
| 3698 |
pjsip_dlg_inc_lock(inv->dlg); |
| 3699 |
|
| 3700 |
|
| 3701 |
if (offer) { |
| 3702 |
if (inv->state == PJSIP_INV_STATE_EARLY && !inv->sdp_done_early_rel) { |
| 3703 |
PJ_LOG(4,(inv->dlg->obj_name, |
| 3704 |
"RFC 3311 section 5.1 recommends against sending UPDATE" |
| 3705 |
" without reliable prov response")); |
| 3706 |
#if PJSIP_INV_UPDATE_EARLY_CHECK_RELIABLE |
| 3707 |
status = PJ_EINVALIDOP; |
| 3708 |
goto on_error; |
| 3709 |
#endif |
| 3710 |
} |
| 3711 |
|
| 3712 |
if (pjmedia_sdp_neg_get_state(inv->neg)!=PJMEDIA_SDP_NEG_STATE_DONE) { |
| 3713 |
PJ_LOG(4,(inv->dlg->obj_name, |
| 3714 |
"Invalid SDP offer/answer state for UPDATE")); |
| 3715 |
status = PJ_EINVALIDOP; |
| 3716 |
goto on_error; |
| 3717 |
} |
| 3718 |
|
| 3719 |
|
| 3720 |
|
| 3721 |
|
| 3722 |
status = pjmedia_sdp_neg_modify_local_offer2(inv->pool_prov, inv->neg, |
| 3723 |
inv->sdp_neg_flags, offer); |
| 3724 |
if (status != PJ_SUCCESS) |
| 3725 |
goto on_error; |
| 3726 |
|
| 3727 |
|
| 3728 |
pjmedia_sdp_neg_get_neg_local(inv->neg, &offer); |
| 3729 |
} |
| 3730 |
|
| 3731 |
|
| 3732 |
if (new_contact) { |
| 3733 |
pj_str_t tmp; |
| 3734 |
const pj_str_t STR_CONTACT = { "Contact", 7 }; |
| 3735 |
|
| 3736 |
pj_strdup_with_null(inv->dlg->pool, &tmp, new_contact); |
| 3737 |
contact_hdr = (pjsip_contact_hdr*) |
| 3738 |
pjsip_parse_hdr(inv->dlg->pool, &STR_CONTACT, |
| 3739 |
tmp.ptr, tmp.slen, NULL); |
| 3740 |
if (!contact_hdr) { |
| 3741 |
status = PJSIP_EINVALIDURI; |
| 3742 |
goto on_error; |
| 3743 |
} |
| 3744 |
|
| 3745 |
inv->dlg->local.contact = contact_hdr; |
| 3746 |
} |
| 3747 |
|
| 3748 |
|
| 3749 |
status = pjsip_dlg_create_request(inv->dlg, &pjsip_update_method, |
| 3750 |
-1, &tdata); |
| 3751 |
if (status != PJ_SUCCESS) |
| 3752 |
goto on_error; |
| 3753 |
|
| 3754 |
|
| 3755 |
if (offer) { |
| 3756 |
sdp_copy = pjmedia_sdp_session_clone(tdata->pool, offer); |
| 3757 |
pjsip_create_sdp_body(tdata->pool, sdp_copy, &tdata->msg->body); |
| 3758 |
} |
| 3759 |
|
| 3760 |
|
| 3761 |
|
| 3762 |
|
| 3763 |
|
| 3764 |
|
| 3765 |
hdr = pjsip_endpt_get_capability(inv->dlg->endpt, PJSIP_H_SUPPORTED, NULL); |
| 3766 |
if (hdr) { |
| 3767 |
sup_hdr = (pjsip_supported_hdr*) |
| 3768 |
pjsip_hdr_shallow_clone(tdata->pool, hdr); |
| 3769 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)sup_hdr); |
| 3770 |
} |
| 3771 |
|
| 3772 |
status = pjsip_timer_update_req(inv, tdata); |
| 3773 |
if (status != PJ_SUCCESS) |
| 3774 |
goto on_error; |
| 3775 |
|
| 3776 |
|
| 3777 |
cleanup_allow_sup_hdr(inv->options, NULL, NULL, sup_hdr); |
| 3778 |
|
| 3779 |
|
| 3780 |
pjsip_dlg_dec_lock(inv->dlg); |
| 3781 |
|
| 3782 |
*p_tdata = tdata; |
| 3783 |
|
| 3784 |
pj_log_pop_indent(); |
| 3785 |
return PJ_SUCCESS; |
| 3786 |
|
| 3787 |
on_error: |
| 3788 |
if (tdata) |
| 3789 |
pjsip_tx_data_dec_ref(tdata); |
| 3790 |
|
| 3791 |
|
| 3792 |
pjsip_dlg_dec_lock(inv->dlg); |
| 3793 |
|
| 3794 |
pj_log_pop_indent(); |
| 3795 |
return status; |
| 3796 |
} |
| 3797 |
|
| 3798 |
|
| 3799 |
|
| 3800 |
|
| 3801 |
PJ_DEF(pj_status_t) pjsip_inv_create_ack(pjsip_inv_session *inv, |
| 3802 |
int cseq, |
| 3803 |
pjsip_tx_data **p_tdata) |
| 3804 |
{ |
| 3805 |
const pjmedia_sdp_session *sdp = NULL; |
| 3806 |
pj_status_t status; |
| 3807 |
|
| 3808 |
PJ_ASSERT_RETURN(inv && p_tdata, PJ_EINVAL); |
| 3809 |
|
| 3810 |
|
| 3811 |
pjsip_dlg_inc_lock(inv->dlg); |
| 3812 |
|
| 3813 |
|
| 3814 |
if (inv->last_ack) { |
| 3815 |
pjsip_tx_data_dec_ref(inv->last_ack); |
| 3816 |
inv->last_ack = NULL; |
| 3817 |
} |
| 3818 |
|
| 3819 |
|
| 3820 |
status = pjsip_dlg_create_request(inv->dlg, pjsip_get_ack_method(), |
| 3821 |
cseq, &inv->last_ack); |
| 3822 |
if (status != PJ_SUCCESS) { |
| 3823 |
pjsip_dlg_dec_lock(inv->dlg); |
| 3824 |
return status; |
| 3825 |
} |
| 3826 |
|
| 3827 |
|
| 3828 |
sdp = inv_has_pending_answer(inv, inv->invite_tsx); |
| 3829 |
if (sdp) { |
| 3830 |
inv->last_ack->msg->body = create_sdp_body(inv->last_ack->pool, sdp); |
| 3831 |
} |
| 3832 |
|
| 3833 |
|
| 3834 |
inv->last_ack_cseq = cseq; |
| 3835 |
pjsip_tx_data_add_ref(inv->last_ack); |
| 3836 |
|
| 3837 |
|
| 3838 |
*p_tdata = inv->last_ack; |
| 3839 |
|
| 3840 |
|
| 3841 |
pjsip_dlg_dec_lock(inv->dlg); |
| 3842 |
|
| 3843 |
return PJ_SUCCESS; |
| 3844 |
} |
| 3845 |
|
| 3846 |
|
| 3847 |
|
| 3848 |
|
| 3849 |
PJ_DEF(pj_status_t) pjsip_inv_send_msg( pjsip_inv_session *inv, |
| 3850 |
pjsip_tx_data *tdata) |
| 3851 |
{ |
| 3852 |
pj_status_t status; |
| 3853 |
|
| 3854 |
|
| 3855 |
PJ_ASSERT_RETURN(inv && tdata, PJ_EINVAL); |
| 3856 |
|
| 3857 |
pj_log_push_indent(); |
| 3858 |
pjsip_inv_add_ref(inv); |
| 3859 |
|
| 3860 |
PJ_LOG(5,(inv->obj_name, "Sending %s", |
| 3861 |
pjsip_tx_data_get_info(tdata))); |
| 3862 |
|
| 3863 |
if (tdata->msg->type == PJSIP_REQUEST_MSG) { |
| 3864 |
struct tsx_inv_data *tsx_inv_data; |
| 3865 |
|
| 3866 |
pjsip_dlg_inc_lock(inv->dlg); |
| 3867 |
|
| 3868 |
|
| 3869 |
if (tdata->msg->line.req.method.id==PJSIP_INVITE_METHOD && |
| 3870 |
inv->invite_tsx) |
| 3871 |
{ |
| 3872 |
pjsip_tx_data_dec_ref(tdata); |
| 3873 |
pjsip_dlg_dec_lock(inv->dlg); |
| 3874 |
status = PJ_EINVALIDOP; |
| 3875 |
goto on_error; |
| 3876 |
} |
| 3877 |
|
| 3878 |
|
| 3879 |
|
| 3880 |
|
| 3881 |
if (tdata->msg->line.req.method.id == PJSIP_BYE_METHOD && |
| 3882 |
inv->role == PJSIP_ROLE_UAS && |
| 3883 |
inv->state == PJSIP_INV_STATE_CONNECTING && |
| 3884 |
inv->cause != PJSIP_SC_REQUEST_TIMEOUT && |
| 3885 |
inv->cause != PJSIP_SC_TSX_TRANSPORT_ERROR) |
| 3886 |
{ |
| 3887 |
if (inv->pending_bye) |
| 3888 |
pjsip_tx_data_dec_ref(inv->pending_bye); |
| 3889 |
|
| 3890 |
inv->pending_bye = tdata; |
| 3891 |
PJ_LOG(4, (inv->obj_name, "Delaying BYE request until " |
| 3892 |
"ACK is received")); |
| 3893 |
pjsip_dlg_dec_lock(inv->dlg); |
| 3894 |
goto on_return; |
| 3895 |
} |
| 3896 |
|
| 3897 |
|
| 3898 |
tsx_inv_data = PJ_POOL_ZALLOC_T(inv->pool, struct tsx_inv_data); |
| 3899 |
tsx_inv_data->inv = inv; |
| 3900 |
tsx_inv_data->has_sdp = tx_data_has_sdp(tdata); |
| 3901 |
|
| 3902 |
pjsip_dlg_dec_lock(inv->dlg); |
| 3903 |
|
| 3904 |
status = pjsip_dlg_send_request(inv->dlg, tdata, mod_inv.mod.id, |
| 3905 |
tsx_inv_data); |
| 3906 |
if (status != PJ_SUCCESS) { |
| 3907 |
goto on_error; |
| 3908 |
} |
| 3909 |
|
| 3910 |
|
| 3911 |
if (mod_inv.cb.on_send_ack && |
| 3912 |
tdata->msg->line.req.method.id == PJSIP_ACK_METHOD && |
| 3913 |
tdata == inv->last_ack) |
| 3914 |
{ |
| 3915 |
pjsip_dlg_inc_lock(inv->dlg); |
| 3916 |
|
| 3917 |
|
| 3918 |
|
| 3919 |
|
| 3920 |
|
| 3921 |
if (inv->state < PJSIP_INV_STATE_CONFIRMED) { |
| 3922 |
pjsip_event ack_e; |
| 3923 |
PJSIP_EVENT_INIT_TX_MSG(ack_e, inv->last_ack); |
| 3924 |
inv_set_state(inv, PJSIP_INV_STATE_CONFIRMED, &ack_e); |
| 3925 |
} else if (inv->state == PJSIP_INV_STATE_DISCONNECTED) { |
| 3926 |
|
| 3927 |
|
| 3928 |
|
| 3929 |
|
| 3930 |
pjsip_tx_data_dec_ref(inv->last_ack); |
| 3931 |
inv->last_ack = NULL; |
| 3932 |
} |
| 3933 |
|
| 3934 |
pjsip_dlg_dec_lock(inv->dlg); |
| 3935 |
} |
| 3936 |
|
| 3937 |
} else { |
| 3938 |
pjsip_cseq_hdr *cseq; |
| 3939 |
|
| 3940 |
|
| 3941 |
|
| 3942 |
|
| 3943 |
cseq = (pjsip_cseq_hdr*)pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CSEQ, NULL); |
| 3944 |
PJ_ASSERT_ON_FAIL(cseq != NULL |
| 3945 |
&& (inv->invite_tsx && cseq->cseq == inv->invite_tsx->cseq), |
| 3946 |
{ pjsip_tx_data_dec_ref(tdata); |
| 3947 |
pjsip_inv_dec_ref(inv); |
| 3948 |
return PJ_EINVALIDOP; }); |
| 3949 |
|
| 3950 |
if (inv->options & PJSIP_INV_REQUIRE_100REL) { |
| 3951 |
status = pjsip_100rel_tx_response(inv, tdata); |
| 3952 |
} else |
| 3953 |
{ |
| 3954 |
status = pjsip_dlg_send_response(inv->dlg, inv->invite_tsx, tdata); |
| 3955 |
} |
| 3956 |
|
| 3957 |
if (status != PJ_SUCCESS) { |
| 3958 |
goto on_error; |
| 3959 |
} |
| 3960 |
} |
| 3961 |
|
| 3962 |
|
| 3963 |
on_return: |
| 3964 |
pjsip_inv_dec_ref(inv); |
| 3965 |
pj_log_pop_indent(); |
| 3966 |
return PJ_SUCCESS; |
| 3967 |
|
| 3968 |
on_error: |
| 3969 |
pjsip_inv_dec_ref(inv); |
| 3970 |
pj_log_pop_indent(); |
| 3971 |
return status; |
| 3972 |
} |
| 3973 |
|
| 3974 |
|
| 3975 |
|
| 3976 |
|
| 3977 |
|
| 3978 |
static void inv_respond_incoming_cancel(pjsip_inv_session *inv, |
| 3979 |
pjsip_transaction *cancel_tsx, |
| 3980 |
pjsip_event *e) |
| 3981 |
{ |
| 3982 |
pjsip_tx_data *tdata; |
| 3983 |
pjsip_transaction *invite_tsx; |
| 3984 |
pjsip_rx_data *rdata; |
| 3985 |
pj_str_t key; |
| 3986 |
pj_status_t status; |
| 3987 |
|
| 3988 |
pj_assert(e->body.tsx_state.type == PJSIP_EVENT_RX_MSG); |
| 3989 |
rdata = e->body.tsx_state.src.rdata; |
| 3990 |
|
| 3991 |
|
| 3992 |
|
| 3993 |
|
| 3994 |
|
| 3995 |
|
| 3996 |
|
| 3997 |
|
| 3998 |
|
| 3999 |
|
| 4000 |
|
| 4001 |
|
| 4002 |
|
| 4003 |
|
| 4004 |
|
| 4005 |
|
| 4006 |
|
| 4007 |
pjsip_tsx_create_key(rdata->tp_info.pool, &key, PJSIP_ROLE_UAS, |
| 4008 |
pjsip_get_invite_method(), rdata); |
| 4009 |
invite_tsx = pjsip_tsx_layer_find_tsx2(&key, PJ_TRUE); |
| 4010 |
|
| 4011 |
if (invite_tsx == NULL) { |
| 4012 |
|
| 4013 |
|
| 4014 |
|
| 4015 |
|
| 4016 |
status = pjsip_dlg_create_response( inv->dlg, rdata, 481, NULL, |
| 4017 |
&tdata); |
| 4018 |
|
| 4019 |
} else { |
| 4020 |
inv->cancelling = PJ_TRUE; |
| 4021 |
|
| 4022 |
|
| 4023 |
|
| 4024 |
|
| 4025 |
status = pjsip_dlg_create_response( inv->dlg, rdata, 200, NULL, |
| 4026 |
&tdata); |
| 4027 |
} |
| 4028 |
|
| 4029 |
|
| 4030 |
if (status != PJ_SUCCESS) return; |
| 4031 |
|
| 4032 |
|
| 4033 |
status = pjsip_dlg_send_response(inv->dlg, cancel_tsx, tdata); |
| 4034 |
if (status != PJ_SUCCESS) return; |
| 4035 |
|
| 4036 |
|
| 4037 |
|
| 4038 |
|
| 4039 |
|
| 4040 |
if (invite_tsx && invite_tsx->status_code < 200) { |
| 4041 |
|
| 4042 |
pj_assert(invite_tsx->last_tx != NULL); |
| 4043 |
|
| 4044 |
tdata = invite_tsx->last_tx; |
| 4045 |
|
| 4046 |
status = pjsip_dlg_modify_response(inv->dlg, tdata, 487, NULL); |
| 4047 |
if (status == PJ_SUCCESS) { |
| 4048 |
|
| 4049 |
tdata->msg->body = NULL; |
| 4050 |
if (inv->options & PJSIP_INV_REQUIRE_100REL) { |
| 4051 |
status = pjsip_100rel_tx_response(inv, tdata); |
| 4052 |
} else { |
| 4053 |
status = pjsip_dlg_send_response(inv->dlg, invite_tsx, |
| 4054 |
tdata); |
| 4055 |
} |
| 4056 |
} |
| 4057 |
} |
| 4058 |
|
| 4059 |
if (invite_tsx) |
| 4060 |
pj_grp_lock_dec_ref(invite_tsx->grp_lock); |
| 4061 |
} |
| 4062 |
|
| 4063 |
|
| 4064 |
|
| 4065 |
|
| 4066 |
|
| 4067 |
static void inv_respond_incoming_bye( pjsip_inv_session *inv, |
| 4068 |
pjsip_transaction *bye_tsx, |
| 4069 |
pjsip_rx_data *rdata, |
| 4070 |
pjsip_event *e ) |
| 4071 |
{ |
| 4072 |
pj_status_t status; |
| 4073 |
pjsip_tx_data *tdata; |
| 4074 |
|
| 4075 |
|
| 4076 |
|
| 4077 |
status = pjsip_dlg_create_response(inv->dlg, rdata, 200, NULL, &tdata); |
| 4078 |
if (status != PJ_SUCCESS) return; |
| 4079 |
|
| 4080 |
status = pjsip_dlg_send_response(inv->dlg, bye_tsx, tdata); |
| 4081 |
if (status != PJ_SUCCESS) return; |
| 4082 |
|
| 4083 |
|
| 4084 |
pjsip_timer_end_session(inv); |
| 4085 |
|
| 4086 |
|
| 4087 |
|
| 4088 |
if (inv->state != PJSIP_INV_STATE_DISCONNECTED) { |
| 4089 |
inv_set_cause(inv, PJSIP_SC_OK, NULL); |
| 4090 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); |
| 4091 |
} |
| 4092 |
} |
| 4093 |
|
| 4094 |
|
| 4095 |
|
| 4096 |
|
| 4097 |
static void inv_handle_bye_response( pjsip_inv_session *inv, |
| 4098 |
pjsip_transaction *tsx, |
| 4099 |
pjsip_rx_data *rdata, |
| 4100 |
pjsip_event *e ) |
| 4101 |
{ |
| 4102 |
pj_status_t status; |
| 4103 |
|
| 4104 |
if (e->body.tsx_state.type != PJSIP_EVENT_RX_MSG) { |
| 4105 |
inv_set_cause(inv, PJSIP_SC_OK, NULL); |
| 4106 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); |
| 4107 |
return; |
| 4108 |
} |
| 4109 |
|
| 4110 |
|
| 4111 |
if (tsx->status_code == 401 || tsx->status_code == 407) { |
| 4112 |
|
| 4113 |
pjsip_tx_data *tdata; |
| 4114 |
pjsip_auth_clt_async_on_chal_param chal_param = { 0 }; |
| 4115 |
struct tsx_inv_data *tsx_inv_data; |
| 4116 |
|
| 4117 |
|
| 4118 |
|
| 4119 |
|
| 4120 |
|
| 4121 |
|
| 4122 |
|
| 4123 |
pj_bzero(&chal_param, sizeof(chal_param)); |
| 4124 |
{ |
| 4125 |
pjsip_auth_clt_async_impl_token *token; |
| 4126 |
token = PJ_POOL_ZALLOC_T(tsx->pool, |
| 4127 |
pjsip_auth_clt_async_impl_token); |
| 4128 |
token->user_data = inv; |
| 4129 |
token->send_impl = &inv_async_auth_send_impl; |
| 4130 |
token->abandon_impl = &inv_bye_auth_abandon_impl; |
| 4131 |
token->grp_lock = tsx->grp_lock; |
| 4132 |
pj_grp_lock_add_ref(tsx->grp_lock); |
| 4133 |
|
| 4134 |
chal_param.rdata = rdata; |
| 4135 |
chal_param.tdata = tsx->last_tx; |
| 4136 |
status = pjsip_auth_clt_async_impl_on_challenge( |
| 4137 |
&inv->dlg->auth_sess, |
| 4138 |
token, &chal_param); |
| 4139 |
if (status != PJ_SUCCESS) |
| 4140 |
pj_grp_lock_dec_ref(tsx->grp_lock); |
| 4141 |
} |
| 4142 |
if (status == PJ_SUCCESS) { |
| 4143 |
tsx_inv_data = |
| 4144 |
(struct tsx_inv_data*)tsx->mod_data[mod_inv.mod.id]; |
| 4145 |
if (tsx_inv_data) |
| 4146 |
tsx_inv_data->retrying = PJ_TRUE; |
| 4147 |
} else { |
| 4148 |
status = pjsip_auth_clt_reinit_req(&inv->dlg->auth_sess, |
| 4149 |
rdata, tsx->last_tx, |
| 4150 |
&tdata); |
| 4151 |
if (status != PJ_SUCCESS) { |
| 4152 |
|
| 4153 |
|
| 4154 |
|
| 4155 |
|
| 4156 |
inv_set_cause(inv, PJSIP_SC_OK, NULL); |
| 4157 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); |
| 4158 |
|
| 4159 |
} else { |
| 4160 |
tsx_inv_data = |
| 4161 |
(struct tsx_inv_data*)tsx->mod_data[mod_inv.mod.id]; |
| 4162 |
if (tsx_inv_data) |
| 4163 |
tsx_inv_data->retrying = PJ_TRUE; |
| 4164 |
|
| 4165 |
|
| 4166 |
status = pjsip_inv_send_msg(inv, tdata); |
| 4167 |
} |
| 4168 |
} |
| 4169 |
|
| 4170 |
} else { |
| 4171 |
|
| 4172 |
|
| 4173 |
inv_set_cause(inv, PJSIP_SC_OK, NULL); |
| 4174 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); |
| 4175 |
} |
| 4176 |
|
| 4177 |
} |
| 4178 |
|
| 4179 |
|
| 4180 |
|
| 4181 |
|
| 4182 |
static void inv_respond_incoming_update(pjsip_inv_session *inv, |
| 4183 |
pjsip_event *e) |
| 4184 |
{ |
| 4185 |
pjmedia_sdp_neg_state neg_state; |
| 4186 |
pj_status_t status; |
| 4187 |
pjsip_tx_data *tdata = NULL; |
| 4188 |
pjsip_rx_data *rdata; |
| 4189 |
pjsip_status_code st_code; |
| 4190 |
|
| 4191 |
pj_assert(e->type == PJSIP_EVENT_TSX_STATE && |
| 4192 |
e->body.tsx_state.type == PJSIP_EVENT_RX_MSG); |
| 4193 |
rdata = e->body.tsx_state.src.rdata; |
| 4194 |
|
| 4195 |
|
| 4196 |
if (!inv_check_secure_dlg(inv, e)) |
| 4197 |
return; |
| 4198 |
|
| 4199 |
|
| 4200 |
status = pjsip_timer_process_req(inv, rdata, &st_code); |
| 4201 |
if (status != PJ_SUCCESS) { |
| 4202 |
status = pjsip_dlg_create_response(inv->dlg, rdata, st_code, |
| 4203 |
NULL, &tdata); |
| 4204 |
goto on_return; |
| 4205 |
} |
| 4206 |
|
| 4207 |
neg_state = pjmedia_sdp_neg_get_state(inv->neg); |
| 4208 |
|
| 4209 |
|
| 4210 |
|
| 4211 |
|
| 4212 |
if (rdata->msg_info.msg->body == NULL) { |
| 4213 |
|
| 4214 |
status = pjsip_dlg_create_response(inv->dlg, rdata, |
| 4215 |
200, NULL, &tdata); |
| 4216 |
} |
| 4217 |
|
| 4218 |
else if (neg_state == PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER) { |
| 4219 |
status = pjsip_dlg_create_response(inv->dlg, rdata, |
| 4220 |
PJSIP_SC_REQUEST_PENDING, NULL, |
| 4221 |
&tdata); |
| 4222 |
} |
| 4223 |
|
| 4224 |
|
| 4225 |
|
| 4226 |
else if (neg_state == PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER || |
| 4227 |
neg_state == PJMEDIA_SDP_NEG_STATE_WAIT_NEGO) |
| 4228 |
{ |
| 4229 |
pjsip_retry_after_hdr *ra_hdr; |
| 4230 |
int val; |
| 4231 |
|
| 4232 |
status = pjsip_dlg_create_response(inv->dlg, rdata, |
| 4233 |
PJSIP_SC_INTERNAL_SERVER_ERROR, |
| 4234 |
NULL, &tdata); |
| 4235 |
|
| 4236 |
if (status == PJ_SUCCESS) { |
| 4237 |
val = (pj_rand() % 10); |
| 4238 |
ra_hdr = pjsip_retry_after_hdr_create(tdata->pool, val); |
| 4239 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)ra_hdr); |
| 4240 |
} |
| 4241 |
|
| 4242 |
} else { |
| 4243 |
|
| 4244 |
inv_check_sdp_in_incoming_msg(inv, pjsip_rdata_get_tsx(rdata), rdata); |
| 4245 |
|
| 4246 |
|
| 4247 |
|
| 4248 |
|
| 4249 |
neg_state = pjmedia_sdp_neg_get_state(inv->neg); |
| 4250 |
if (neg_state != PJMEDIA_SDP_NEG_STATE_WAIT_NEGO || |
| 4251 |
(status=inv_negotiate_sdp(inv)) != PJ_SUCCESS) |
| 4252 |
{ |
| 4253 |
|
| 4254 |
|
| 4255 |
|
| 4256 |
neg_state = pjmedia_sdp_neg_get_state(inv->neg); |
| 4257 |
if (neg_state != PJMEDIA_SDP_NEG_STATE_DONE) { |
| 4258 |
pjmedia_sdp_neg_cancel_offer(inv->neg); |
| 4259 |
} |
| 4260 |
|
| 4261 |
status = pjsip_dlg_create_response(inv->dlg, rdata, |
| 4262 |
PJSIP_SC_NOT_ACCEPTABLE_HERE, |
| 4263 |
NULL, &tdata); |
| 4264 |
} else { |
| 4265 |
|
| 4266 |
status = pjsip_dlg_create_response(inv->dlg, rdata, |
| 4267 |
PJSIP_SC_OK, NULL, &tdata); |
| 4268 |
if (status == PJ_SUCCESS) { |
| 4269 |
const pjmedia_sdp_session *sdp; |
| 4270 |
status = pjmedia_sdp_neg_get_active_local(inv->neg, &sdp); |
| 4271 |
if (status == PJ_SUCCESS) |
| 4272 |
tdata->msg->body = create_sdp_body(tdata->pool, sdp); |
| 4273 |
} |
| 4274 |
} |
| 4275 |
} |
| 4276 |
|
| 4277 |
on_return: |
| 4278 |
|
| 4279 |
if (status == PJ_SUCCESS) |
| 4280 |
status = pjsip_timer_update_resp(inv, tdata); |
| 4281 |
|
| 4282 |
if (status != PJ_SUCCESS) { |
| 4283 |
if (tdata != NULL) { |
| 4284 |
pjsip_tx_data_dec_ref(tdata); |
| 4285 |
tdata = NULL; |
| 4286 |
} |
| 4287 |
return; |
| 4288 |
} |
| 4289 |
|
| 4290 |
pjsip_dlg_send_response(inv->dlg, pjsip_rdata_get_tsx(rdata), tdata); |
| 4291 |
} |
| 4292 |
|
| 4293 |
|
| 4294 |
|
| 4295 |
|
| 4296 |
|
| 4297 |
static pj_bool_t inv_handle_update_response( pjsip_inv_session *inv, |
| 4298 |
pjsip_event *e) |
| 4299 |
{ |
| 4300 |
pjsip_transaction *tsx = e->body.tsx_state.tsx; |
| 4301 |
struct tsx_inv_data *tsx_inv_data; |
| 4302 |
pj_bool_t handled = PJ_FALSE; |
| 4303 |
pj_status_t status = -1; |
| 4304 |
|
| 4305 |
tsx_inv_data = (struct tsx_inv_data*)tsx->mod_data[mod_inv.mod.id]; |
| 4306 |
pj_assert(tsx_inv_data); |
| 4307 |
|
| 4308 |
|
| 4309 |
if (inv->state != PJSIP_INV_STATE_DISCONNECTED && |
| 4310 |
tsx->state == PJSIP_TSX_STATE_COMPLETED && |
| 4311 |
((tsx->status_code == PJSIP_SC_CALL_TSX_DOES_NOT_EXIST) || |
| 4312 |
(tsx->status_code == PJSIP_SC_REQUEST_TIMEOUT && |
| 4313 |
!pjsip_cfg()->endpt.keep_inv_after_tsx_timeout))) |
| 4314 |
{ |
| 4315 |
pjsip_tx_data *bye = NULL; |
| 4316 |
|
| 4317 |
|
| 4318 |
status = pjsip_inv_end_session(inv, tsx->status_code, |
| 4319 |
&tsx->status_text, &bye); |
| 4320 |
if (status == PJ_SUCCESS && bye) { |
| 4321 |
status = pjsip_inv_send_msg(inv, bye); |
| 4322 |
} |
| 4323 |
|
| 4324 |
handled = PJ_TRUE; |
| 4325 |
} |
| 4326 |
|
| 4327 |
|
| 4328 |
else if (tsx->state == PJSIP_TSX_STATE_COMPLETED && |
| 4329 |
(tsx->status_code == 401 || tsx->status_code == 407)) |
| 4330 |
{ |
| 4331 |
pjsip_tx_data *tdata; |
| 4332 |
pjsip_auth_clt_async_on_chal_param chal_param = { 0 }; |
| 4333 |
|
| 4334 |
|
| 4335 |
|
| 4336 |
|
| 4337 |
|
| 4338 |
pj_bzero(&chal_param, sizeof(chal_param)); |
| 4339 |
{ |
| 4340 |
pjsip_auth_clt_async_impl_token *token; |
| 4341 |
token = PJ_POOL_ZALLOC_T(tsx->pool, |
| 4342 |
pjsip_auth_clt_async_impl_token); |
| 4343 |
token->user_data = inv; |
| 4344 |
token->send_impl = &inv_async_auth_send_impl; |
| 4345 |
token->abandon_impl = NULL; |
| 4346 |
token->grp_lock = tsx->grp_lock; |
| 4347 |
pj_grp_lock_add_ref(tsx->grp_lock); |
| 4348 |
|
| 4349 |
chal_param.rdata = e->body.tsx_state.src.rdata; |
| 4350 |
chal_param.tdata = tsx->last_tx; |
| 4351 |
status = pjsip_auth_clt_async_impl_on_challenge( |
| 4352 |
&inv->dlg->auth_sess, |
| 4353 |
token, &chal_param); |
| 4354 |
if (status != PJ_SUCCESS) |
| 4355 |
pj_grp_lock_dec_ref(tsx->grp_lock); |
| 4356 |
} |
| 4357 |
if (status == PJ_SUCCESS) { |
| 4358 |
if (tsx_inv_data) |
| 4359 |
tsx_inv_data->retrying = PJ_TRUE; |
| 4360 |
} else { |
| 4361 |
status = pjsip_auth_clt_reinit_req( |
| 4362 |
&inv->dlg->auth_sess, |
| 4363 |
e->body.tsx_state.src.rdata, |
| 4364 |
tsx->last_tx, &tdata); |
| 4365 |
if (status == PJ_SUCCESS) { |
| 4366 |
if (tsx_inv_data) |
| 4367 |
tsx_inv_data->retrying = PJ_TRUE; |
| 4368 |
|
| 4369 |
|
| 4370 |
status = pjsip_inv_send_msg(inv, tdata); |
| 4371 |
} |
| 4372 |
|
| 4373 |
|
| 4374 |
|
| 4375 |
|
| 4376 |
|
| 4377 |
} |
| 4378 |
|
| 4379 |
handled = PJ_TRUE; |
| 4380 |
} |
| 4381 |
|
| 4382 |
|
| 4383 |
else if (tsx->state == PJSIP_TSX_STATE_COMPLETED && |
| 4384 |
tsx->status_code == 422) |
| 4385 |
{ |
| 4386 |
status = handle_timer_response(inv, e->body.tsx_state.src.rdata, |
| 4387 |
PJ_FALSE); |
| 4388 |
handled = PJ_TRUE; |
| 4389 |
} |
| 4390 |
|
| 4391 |
|
| 4392 |
else if (tsx->state == PJSIP_TSX_STATE_COMPLETED && |
| 4393 |
tsx->status_code/100 == 2) |
| 4394 |
{ |
| 4395 |
pjsip_rx_data *rdata = e->body.tsx_state.src.rdata; |
| 4396 |
|
| 4397 |
|
| 4398 |
if (inv_check_secure_dlg(inv, e)) { |
| 4399 |
|
| 4400 |
status = handle_timer_response(inv, rdata, PJ_FALSE); |
| 4401 |
|
| 4402 |
if (rdata->msg_info.msg->body) { |
| 4403 |
|
| 4404 |
if (inv->neg && pjmedia_sdp_neg_get_state(inv->neg) == |
| 4405 |
PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER) |
| 4406 |
{ |
| 4407 |
status = inv_check_sdp_in_incoming_msg(inv, tsx, rdata); |
| 4408 |
} else { |
| 4409 |
PJ_LOG(5,(THIS_FILE, "Ignored message body in %s as no " |
| 4410 |
"local offer was sent", |
| 4411 |
pjsip_rx_data_get_info(rdata))); |
| 4412 |
} |
| 4413 |
} |
| 4414 |
} |
| 4415 |
|
| 4416 |
handled = PJ_TRUE; |
| 4417 |
} |
| 4418 |
|
| 4419 |
|
| 4420 |
else if ((tsx->state == PJSIP_TSX_STATE_TERMINATED) && |
| 4421 |
(tsx->status_code == 503 || tsx->status_code == 502)) |
| 4422 |
{ |
| 4423 |
status = pjsip_timer_handle_refresh_error(inv, e); |
| 4424 |
|
| 4425 |
handled = PJ_TRUE; |
| 4426 |
} |
| 4427 |
|
| 4428 |
|
| 4429 |
else |
| 4430 |
{ |
| 4431 |
|
| 4432 |
|
| 4433 |
|
| 4434 |
if (tsx->state == PJSIP_TSX_STATE_COMPLETED && |
| 4435 |
tsx->role == PJSIP_ROLE_UAC) |
| 4436 |
{ |
| 4437 |
status = handle_timer_response(inv, e->body.tsx_state.src.rdata, |
| 4438 |
PJ_FALSE); |
| 4439 |
handled = PJ_TRUE; |
| 4440 |
} |
| 4441 |
} |
| 4442 |
|
| 4443 |
|
| 4444 |
|
| 4445 |
|
| 4446 |
if (pjmedia_sdp_neg_get_state(inv->neg) == |
| 4447 |
PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER && |
| 4448 |
tsx_inv_data && tsx_inv_data->sdp_done == PJ_FALSE && |
| 4449 |
!tsx_inv_data->retrying && tsx_inv_data->has_sdp) |
| 4450 |
{ |
| 4451 |
pjmedia_sdp_neg_cancel_offer(inv->neg); |
| 4452 |
|
| 4453 |
|
| 4454 |
tsx_inv_data->sdp_done = PJ_TRUE; |
| 4455 |
} |
| 4456 |
|
| 4457 |
return handled; |
| 4458 |
} |
| 4459 |
|
| 4460 |
|
| 4461 |
|
| 4462 |
|
| 4463 |
|
| 4464 |
static void inv_handle_incoming_reliable_response(pjsip_inv_session *inv, |
| 4465 |
pjsip_rx_data *rdata) |
| 4466 |
{ |
| 4467 |
pjsip_tx_data *tdata; |
| 4468 |
const pjmedia_sdp_session *sdp; |
| 4469 |
pj_status_t status; |
| 4470 |
|
| 4471 |
|
| 4472 |
status = pjsip_100rel_create_prack(inv, rdata, &tdata); |
| 4473 |
if (status != PJ_SUCCESS) |
| 4474 |
return; |
| 4475 |
|
| 4476 |
|
| 4477 |
sdp = inv_has_pending_answer(inv, pjsip_rdata_get_tsx(rdata)); |
| 4478 |
if (sdp) { |
| 4479 |
tdata->msg->body = create_sdp_body(tdata->pool, sdp); |
| 4480 |
} |
| 4481 |
|
| 4482 |
|
| 4483 |
pjsip_100rel_send_prack(inv, tdata); |
| 4484 |
} |
| 4485 |
|
| 4486 |
|
| 4487 |
|
| 4488 |
|
| 4489 |
|
| 4490 |
static void inv_respond_incoming_prack(pjsip_inv_session *inv, |
| 4491 |
pjsip_rx_data *rdata) |
| 4492 |
{ |
| 4493 |
pjmedia_sdp_neg_state neg_state; |
| 4494 |
pj_status_t status, prack_sdp_status; |
| 4495 |
pjsip_tx_data *tdata = NULL; |
| 4496 |
|
| 4497 |
|
| 4498 |
|
| 4499 |
|
| 4500 |
status = pjsip_100rel_on_rx_prack(inv, rdata); |
| 4501 |
|
| 4502 |
|
| 4503 |
if (status == PJSIP_ENOTINITIALIZED) |
| 4504 |
return; |
| 4505 |
|
| 4506 |
|
| 4507 |
|
| 4508 |
|
| 4509 |
if (status != PJ_SUCCESS) { |
| 4510 |
status = pjsip_dlg_create_response(inv->dlg, rdata, PJSIP_SC_OK, NULL, |
| 4511 |
&tdata); |
| 4512 |
goto on_return; |
| 4513 |
} |
| 4514 |
|
| 4515 |
|
| 4516 |
if (rdata->msg_info.msg->body == NULL) { |
| 4517 |
status = pjsip_dlg_create_response(inv->dlg, rdata, PJSIP_SC_OK, NULL, |
| 4518 |
&tdata); |
| 4519 |
goto on_return; |
| 4520 |
} |
| 4521 |
|
| 4522 |
neg_state = pjmedia_sdp_neg_get_state(inv->neg); |
| 4523 |
|
| 4524 |
if (neg_state == PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER) { |
| 4525 |
status = inv_check_sdp_in_incoming_msg(inv, pjsip_rdata_get_tsx(rdata), |
| 4526 |
rdata); |
| 4527 |
|
| 4528 |
|
| 4529 |
|
| 4530 |
|
| 4531 |
if (status == PJ_SUCCESS && inv->invite_tsx) { |
| 4532 |
struct tsx_inv_data *tsx_inv_data; |
| 4533 |
|
| 4534 |
|
| 4535 |
tsx_inv_data = (struct tsx_inv_data*) |
| 4536 |
inv->invite_tsx->mod_data[mod_inv.mod.id]; |
| 4537 |
if (tsx_inv_data == NULL) { |
| 4538 |
tsx_inv_data = PJ_POOL_ZALLOC_T(inv->invite_tsx->pool, |
| 4539 |
struct tsx_inv_data); |
| 4540 |
tsx_inv_data->inv = inv; |
| 4541 |
tsx_inv_data->has_sdp = PJ_TRUE; |
| 4542 |
inv->invite_tsx->mod_data[mod_inv.mod.id] = tsx_inv_data; |
| 4543 |
} |
| 4544 |
|
| 4545 |
tsx_inv_data->sdp_done = PJ_TRUE; |
| 4546 |
} |
| 4547 |
|
| 4548 |
status = pjsip_dlg_create_response(inv->dlg, rdata, PJSIP_SC_OK, |
| 4549 |
NULL, &tdata); |
| 4550 |
if (pjmedia_sdp_neg_get_state(inv->neg) == PJMEDIA_SDP_NEG_STATE_DONE) |
| 4551 |
{ |
| 4552 |
inv->sdp_done_early_rel = PJ_TRUE; |
| 4553 |
} |
| 4554 |
goto on_return; |
| 4555 |
} |
| 4556 |
|
| 4557 |
|
| 4558 |
inv_check_sdp_in_incoming_msg(inv, pjsip_rdata_get_tsx(rdata), rdata); |
| 4559 |
|
| 4560 |
|
| 4561 |
|
| 4562 |
|
| 4563 |
|
| 4564 |
|
| 4565 |
|
| 4566 |
|
| 4567 |
prack_sdp_status = inv_negotiate_sdp(inv); |
| 4568 |
inv->sdp_done_early_rel = PJ_TRUE; |
| 4569 |
status = pjsip_dlg_create_response(inv->dlg, rdata, PJSIP_SC_OK, NULL, |
| 4570 |
&tdata); |
| 4571 |
if (status == PJ_SUCCESS) { |
| 4572 |
const pjmedia_sdp_session *sdp; |
| 4573 |
status = pjmedia_sdp_neg_get_active_local(inv->neg, &sdp); |
| 4574 |
if (status == PJ_SUCCESS) |
| 4575 |
tdata->msg->body = create_sdp_body(tdata->pool, sdp); |
| 4576 |
pjsip_dlg_send_response(inv->dlg, pjsip_rdata_get_tsx(rdata), tdata); |
| 4577 |
} |
| 4578 |
if (prack_sdp_status != PJ_SUCCESS) { |
| 4579 |
pjsip_tx_data *resp; |
| 4580 |
pj_str_t st_reason = pj_str("PRACK SDP negotiation failed"); |
| 4581 |
|
| 4582 |
|
| 4583 |
|
| 4584 |
neg_state = pjmedia_sdp_neg_get_state(inv->neg); |
| 4585 |
if (neg_state != PJMEDIA_SDP_NEG_STATE_DONE) |
| 4586 |
pjmedia_sdp_neg_cancel_offer(inv->neg); |
| 4587 |
|
| 4588 |
|
| 4589 |
|
| 4590 |
|
| 4591 |
PJ_LOG(4,(THIS_FILE, "Call terminated. PRACK SDP not acceptable")); |
| 4592 |
status = pjsip_inv_end_session(inv, PJSIP_SC_NOT_ACCEPTABLE_HERE, |
| 4593 |
&st_reason, &resp); |
| 4594 |
if (status == PJ_SUCCESS && resp) |
| 4595 |
status = pjsip_inv_send_msg(inv, resp); |
| 4596 |
} |
| 4597 |
return; |
| 4598 |
|
| 4599 |
on_return: |
| 4600 |
if (status == PJ_SUCCESS) |
| 4601 |
pjsip_dlg_send_response(inv->dlg, pjsip_rdata_get_tsx(rdata), tdata); |
| 4602 |
} |
| 4603 |
|
| 4604 |
|
| 4605 |
|
| 4606 |
|
| 4607 |
|
| 4608 |
|
| 4609 |
static pj_bool_t inv_check_secure_dlg(pjsip_inv_session *inv, |
| 4610 |
pjsip_event *e) |
| 4611 |
{ |
| 4612 |
pjsip_transaction *tsx = e->body.tsx_state.tsx; |
| 4613 |
pjsip_dialog *dlg = pjsip_tsx_get_dlg(tsx); |
| 4614 |
|
| 4615 |
if (pjsip_cfg()->endpt.disable_secure_dlg_check == PJ_FALSE && |
| 4616 |
dlg->secure && e->body.tsx_state.type==PJSIP_EVENT_RX_MSG && |
| 4617 |
((tsx->role==PJSIP_ROLE_UAC && tsx->status_code/100 == 2) || |
| 4618 |
(tsx->role==PJSIP_ROLE_UAS && tsx->state == PJSIP_TSX_STATE_TRYING)) |
| 4619 |
&& |
| 4620 |
(tsx->method.id==PJSIP_INVITE_METHOD || |
| 4621 |
pjsip_method_cmp(&tsx->method, &pjsip_update_method)==0)) |
| 4622 |
{ |
| 4623 |
const pjsip_msg *msg = e->body.tsx_state.src.rdata->msg_info.msg; |
| 4624 |
pj_status_t status = PJ_SUCCESS; |
| 4625 |
pjsip_contact_hdr *c; |
| 4626 |
|
| 4627 |
|
| 4628 |
c = (pjsip_contact_hdr*) |
| 4629 |
pjsip_msg_find_hdr(msg,PJSIP_H_CONTACT, NULL); |
| 4630 |
if (!(c && c->uri && PJSIP_URI_SCHEME_IS_SIPS(c->uri))) |
| 4631 |
status = PJSIP_ESESSIONINSECURE; |
| 4632 |
|
| 4633 |
|
| 4634 |
if (status == PJ_SUCCESS) { |
| 4635 |
pjsip_rr_hdr *r = (pjsip_rr_hdr*) |
| 4636 |
pjsip_msg_find_hdr(msg, PJSIP_H_RECORD_ROUTE, |
| 4637 |
NULL); |
| 4638 |
if (r && !PJSIP_URI_SCHEME_IS_SIPS(&r->name_addr)) { |
| 4639 |
|
| 4640 |
|
| 4641 |
|
| 4642 |
if (PJSIP_URI_SCHEME_IS_SIP(&r->name_addr)) { |
| 4643 |
pjsip_sip_uri *sip_uri = (pjsip_sip_uri*) |
| 4644 |
pjsip_uri_get_uri(r->name_addr.uri); |
| 4645 |
if (pj_stricmp2(&sip_uri->transport_param, "tls")!=0) |
| 4646 |
status = PJSIP_ESESSIONINSECURE; |
| 4647 |
} else { |
| 4648 |
|
| 4649 |
status = PJSIP_ESESSIONINSECURE; |
| 4650 |
} |
| 4651 |
} |
| 4652 |
} |
| 4653 |
|
| 4654 |
if (status == PJSIP_ESESSIONINSECURE) { |
| 4655 |
|
| 4656 |
|
| 4657 |
pj_str_t warn_text = pj_str("SIPS Required"); |
| 4658 |
|
| 4659 |
if (tsx->role == PJSIP_ROLE_UAC) { |
| 4660 |
|
| 4661 |
|
| 4662 |
pjsip_tx_data *bye; |
| 4663 |
|
| 4664 |
PJ_LOG(4,(inv->obj_name, |
| 4665 |
"Secure dialog requires SIPS scheme in Contact and " |
| 4666 |
"Record-Route headers, ending the session")); |
| 4667 |
|
| 4668 |
status = pjsip_inv_end_session(inv, 480, &warn_text, &bye); |
| 4669 |
if (status == PJ_SUCCESS && bye) { |
| 4670 |
pjsip_warning_hdr *w; |
| 4671 |
w = pjsip_warning_hdr_create(bye->pool, 381, |
| 4672 |
pjsip_endpt_name(dlg->endpt), |
| 4673 |
&warn_text); |
| 4674 |
if (w) |
| 4675 |
pjsip_msg_add_hdr(bye->msg, (pjsip_hdr*)w); |
| 4676 |
|
| 4677 |
status = pjsip_inv_send_msg(inv, bye); |
| 4678 |
} |
| 4679 |
|
| 4680 |
} else { |
| 4681 |
|
| 4682 |
|
| 4683 |
pjsip_rx_data *rdata = e->body.tsx_state.src.rdata; |
| 4684 |
pjsip_tx_data *tdata; |
| 4685 |
|
| 4686 |
PJ_LOG(4,(inv->obj_name, |
| 4687 |
"Secure dialog requires SIPS scheme in Contact and " |
| 4688 |
"Route headers, rejecting the request")); |
| 4689 |
|
| 4690 |
status = pjsip_dlg_create_response(inv->dlg, rdata, 480, |
| 4691 |
NULL, &tdata); |
| 4692 |
if (status == PJ_SUCCESS) { |
| 4693 |
pjsip_warning_hdr *w; |
| 4694 |
w = pjsip_warning_hdr_create(tdata->pool, 381, |
| 4695 |
pjsip_endpt_name(dlg->endpt), |
| 4696 |
&warn_text); |
| 4697 |
if (w) |
| 4698 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)w); |
| 4699 |
|
| 4700 |
pjsip_dlg_send_response(dlg, tsx, tdata); |
| 4701 |
} |
| 4702 |
|
| 4703 |
} |
| 4704 |
|
| 4705 |
return PJ_FALSE; |
| 4706 |
} |
| 4707 |
} |
| 4708 |
|
| 4709 |
return PJ_TRUE; |
| 4710 |
} |
| 4711 |
|
| 4712 |
|
| 4713 |
|
| 4714 |
|
| 4715 |
|
| 4716 |
|
| 4717 |
static void inv_on_state_null( pjsip_inv_session *inv, pjsip_event *e) |
| 4718 |
{ |
| 4719 |
pjsip_transaction *tsx = e->body.tsx_state.tsx; |
| 4720 |
pjsip_dialog *dlg = pjsip_tsx_get_dlg(tsx); |
| 4721 |
|
| 4722 |
PJ_ASSERT_ON_FAIL(tsx && dlg, return); |
| 4723 |
|
| 4724 |
if (tsx->method.id == PJSIP_INVITE_METHOD) { |
| 4725 |
|
| 4726 |
|
| 4727 |
if (inv->invite_tsx == NULL) |
| 4728 |
inv->invite_tsx = tsx; |
| 4729 |
|
| 4730 |
if (dlg->role == PJSIP_ROLE_UAC) { |
| 4731 |
|
| 4732 |
|
| 4733 |
|
| 4734 |
|
| 4735 |
|
| 4736 |
if (1) { |
| 4737 |
if (inv->invite_req) { |
| 4738 |
pjsip_tx_data_dec_ref(inv->invite_req); |
| 4739 |
inv->invite_req = NULL; |
| 4740 |
} |
| 4741 |
inv->invite_req = tsx->last_tx; |
| 4742 |
pjsip_tx_data_add_ref(inv->invite_req); |
| 4743 |
} |
| 4744 |
|
| 4745 |
switch (tsx->state) { |
| 4746 |
case PJSIP_TSX_STATE_CALLING: |
| 4747 |
inv_set_state(inv, PJSIP_INV_STATE_CALLING, e); |
| 4748 |
break; |
| 4749 |
default: |
| 4750 |
inv_on_state_calling(inv, e); |
| 4751 |
break; |
| 4752 |
} |
| 4753 |
|
| 4754 |
} else { |
| 4755 |
switch (tsx->state) { |
| 4756 |
case PJSIP_TSX_STATE_TRYING: |
| 4757 |
inv_set_state(inv, PJSIP_INV_STATE_INCOMING, e); |
| 4758 |
break; |
| 4759 |
case PJSIP_TSX_STATE_PROCEEDING: |
| 4760 |
inv_set_state(inv, PJSIP_INV_STATE_INCOMING, e); |
| 4761 |
if (tsx->status_code > 100) |
| 4762 |
inv_set_state(inv, PJSIP_INV_STATE_EARLY, e); |
| 4763 |
break; |
| 4764 |
case PJSIP_TSX_STATE_TERMINATED: |
| 4765 |
|
| 4766 |
inv_set_cause(inv, tsx->status_code, &tsx->status_text); |
| 4767 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); |
| 4768 |
break; |
| 4769 |
default: |
| 4770 |
inv_on_state_incoming(inv, e); |
| 4771 |
break; |
| 4772 |
} |
| 4773 |
} |
| 4774 |
|
| 4775 |
} else { |
| 4776 |
pj_assert(!"Unexpected transaction type"); |
| 4777 |
} |
| 4778 |
} |
| 4779 |
|
| 4780 |
|
| 4781 |
|
| 4782 |
|
| 4783 |
|
| 4784 |
|
| 4785 |
|
| 4786 |
static pj_bool_t handle_uac_tsx_response(pjsip_inv_session *inv, |
| 4787 |
pjsip_event *e) |
| 4788 |
{ |
| 4789 |
|
| 4790 |
|
| 4791 |
|
| 4792 |
|
| 4793 |
|
| 4794 |
|
| 4795 |
|
| 4796 |
|
| 4797 |
|
| 4798 |
|
| 4799 |
|
| 4800 |
|
| 4801 |
|
| 4802 |
|
| 4803 |
pjsip_transaction *tsx = e->body.tsx_state.tsx; |
| 4804 |
|
| 4805 |
pj_assert(tsx->role == PJSIP_UAC_ROLE); |
| 4806 |
|
| 4807 |
|
| 4808 |
|
| 4809 |
|
| 4810 |
|
| 4811 |
|
| 4812 |
|
| 4813 |
|
| 4814 |
if (inv->state != PJSIP_INV_STATE_DISCONNECTED && |
| 4815 |
e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED && |
| 4816 |
((tsx->status_code == PJSIP_SC_CALL_TSX_DOES_NOT_EXIST && |
| 4817 |
tsx->method.id != PJSIP_CANCEL_METHOD) || |
| 4818 |
(tsx->status_code == PJSIP_SC_REQUEST_TIMEOUT && |
| 4819 |
!pjsip_cfg()->endpt.keep_inv_after_tsx_timeout))) |
| 4820 |
{ |
| 4821 |
pjsip_tx_data *bye; |
| 4822 |
pj_status_t status; |
| 4823 |
|
| 4824 |
inv_set_cause(inv, tsx->status_code, &tsx->status_text); |
| 4825 |
|
| 4826 |
|
| 4827 |
|
| 4828 |
|
| 4829 |
|
| 4830 |
|
| 4831 |
|
| 4832 |
status = pjsip_dlg_create_request(inv->dlg, pjsip_get_bye_method(), |
| 4833 |
-1, &bye); |
| 4834 |
if (status == PJ_SUCCESS && tsx->status_text.slen) { |
| 4835 |
status = add_reason_warning_hdr(bye, tsx->status_code, |
| 4836 |
&tsx->status_text); |
| 4837 |
} |
| 4838 |
if (status == PJ_SUCCESS) { |
| 4839 |
pjsip_inv_send_msg(inv, bye); |
| 4840 |
} |
| 4841 |
|
| 4842 |
return PJ_TRUE; |
| 4843 |
|
| 4844 |
} |
| 4845 |
|
| 4846 |
else if (tsx->state == PJSIP_TSX_STATE_COMPLETED && |
| 4847 |
(tsx->status_code == PJSIP_SC_UNAUTHORIZED || |
| 4848 |
tsx->status_code == PJSIP_SC_PROXY_AUTHENTICATION_REQUIRED)) |
| 4849 |
{ |
| 4850 |
pjsip_tx_data *tdata; |
| 4851 |
pj_status_t status; |
| 4852 |
pjsip_auth_clt_async_on_chal_param chal_param = { 0 }; |
| 4853 |
struct tsx_inv_data *tsx_inv_data; |
| 4854 |
|
| 4855 |
|
| 4856 |
|
| 4857 |
|
| 4858 |
|
| 4859 |
|
| 4860 |
|
| 4861 |
if (tsx->method.id == PJSIP_INVITE_METHOD) |
| 4862 |
inv->invite_tsx = NULL; |
| 4863 |
|
| 4864 |
|
| 4865 |
|
| 4866 |
|
| 4867 |
|
| 4868 |
pj_bzero(&chal_param, sizeof(chal_param)); |
| 4869 |
{ |
| 4870 |
pjsip_auth_clt_async_impl_token *token; |
| 4871 |
token = PJ_POOL_ZALLOC_T(tsx->pool, |
| 4872 |
pjsip_auth_clt_async_impl_token); |
| 4873 |
token->user_data = inv; |
| 4874 |
token->send_impl = &inv_async_auth_send_impl; |
| 4875 |
token->abandon_impl = NULL; |
| 4876 |
token->grp_lock = tsx->grp_lock; |
| 4877 |
pj_grp_lock_add_ref(tsx->grp_lock); |
| 4878 |
|
| 4879 |
chal_param.rdata = e->body.tsx_state.src.rdata; |
| 4880 |
chal_param.tdata = tsx->last_tx; |
| 4881 |
status = pjsip_auth_clt_async_impl_on_challenge( |
| 4882 |
&inv->dlg->auth_sess, |
| 4883 |
token, &chal_param); |
| 4884 |
if (status != PJ_SUCCESS) |
| 4885 |
pj_grp_lock_dec_ref(tsx->grp_lock); |
| 4886 |
} |
| 4887 |
if (status == PJ_SUCCESS) { |
| 4888 |
tsx_inv_data = |
| 4889 |
(struct tsx_inv_data*)tsx->mod_data[mod_inv.mod.id]; |
| 4890 |
if (tsx_inv_data) |
| 4891 |
tsx_inv_data->retrying = PJ_TRUE; |
| 4892 |
} else { |
| 4893 |
status = pjsip_auth_clt_reinit_req( |
| 4894 |
&inv->dlg->auth_sess, |
| 4895 |
e->body.tsx_state.src.rdata, |
| 4896 |
tsx->last_tx, &tdata); |
| 4897 |
if (status == PJ_SUCCESS) { |
| 4898 |
tsx_inv_data = |
| 4899 |
(struct tsx_inv_data*)tsx->mod_data[mod_inv.mod.id]; |
| 4900 |
if (tsx_inv_data) |
| 4901 |
tsx_inv_data->retrying = PJ_TRUE; |
| 4902 |
|
| 4903 |
|
| 4904 |
status = pjsip_inv_send_msg(inv, tdata); |
| 4905 |
} |
| 4906 |
|
| 4907 |
|
| 4908 |
|
| 4909 |
|
| 4910 |
|
| 4911 |
} |
| 4912 |
|
| 4913 |
return PJ_TRUE; |
| 4914 |
} |
| 4915 |
|
| 4916 |
|
| 4917 |
else if (tsx->state == PJSIP_TSX_STATE_COMPLETED && |
| 4918 |
tsx->status_code == PJSIP_SC_SESSION_TIMER_TOO_SMALL) |
| 4919 |
{ |
| 4920 |
handle_timer_response(inv, e->body.tsx_state.src.rdata, |
| 4921 |
PJ_FALSE); |
| 4922 |
|
| 4923 |
return PJ_TRUE; |
| 4924 |
|
| 4925 |
} |
| 4926 |
|
| 4927 |
else { |
| 4928 |
return PJ_FALSE; |
| 4929 |
} |
| 4930 |
} |
| 4931 |
|
| 4932 |
|
| 4933 |
|
| 4934 |
|
| 4935 |
|
| 4936 |
|
| 4937 |
|
| 4938 |
|
| 4939 |
|
| 4940 |
|
| 4941 |
|
| 4942 |
|
| 4943 |
static void handle_uac_call_rejection(pjsip_inv_session *inv, pjsip_event *e) |
| 4944 |
{ |
| 4945 |
pjsip_transaction *tsx = e->body.tsx_state.tsx; |
| 4946 |
pj_status_t status; |
| 4947 |
|
| 4948 |
if (PJSIP_IS_STATUS_IN_CLASS(tsx->status_code, 300)) { |
| 4949 |
|
| 4950 |
if (mod_inv.cb.on_redirected == NULL) { |
| 4951 |
|
| 4952 |
|
| 4953 |
|
| 4954 |
|
| 4955 |
goto terminate_session; |
| 4956 |
|
| 4957 |
} else { |
| 4958 |
const pjsip_msg *res_msg; |
| 4959 |
|
| 4960 |
res_msg = e->body.tsx_state.src.rdata->msg_info.msg; |
| 4961 |
|
| 4962 |
|
| 4963 |
|
| 4964 |
|
| 4965 |
|
| 4966 |
pjsip_target_set_add_from_msg(&inv->dlg->target_set, |
| 4967 |
inv->dlg->pool, res_msg); |
| 4968 |
|
| 4969 |
|
| 4970 |
if (!inv_uac_recurse(inv, tsx->status_code, &tsx->status_text, e)) |
| 4971 |
{ |
| 4972 |
|
| 4973 |
goto terminate_session; |
| 4974 |
} |
| 4975 |
|
| 4976 |
|
| 4977 |
} |
| 4978 |
|
| 4979 |
} else if ((tsx->status_code==401 || tsx->status_code==407) && |
| 4980 |
!inv->cancelling) |
| 4981 |
{ |
| 4982 |
|
| 4983 |
|
| 4984 |
|
| 4985 |
pjsip_tx_data *tdata; |
| 4986 |
pjsip_auth_clt_async_on_chal_param chal_param = { 0 }; |
| 4987 |
|
| 4988 |
|
| 4989 |
|
| 4990 |
|
| 4991 |
pj_bzero(&chal_param, sizeof(chal_param)); |
| 4992 |
{ |
| 4993 |
pjsip_auth_clt_async_impl_token *token; |
| 4994 |
token = PJ_POOL_ZALLOC_T(tsx->pool, |
| 4995 |
pjsip_auth_clt_async_impl_token); |
| 4996 |
token->user_data = inv; |
| 4997 |
token->send_impl = &inv_async_auth_send_impl; |
| 4998 |
token->abandon_impl = &inv_initial_invite_auth_abandon_impl; |
| 4999 |
token->grp_lock = tsx->grp_lock; |
| 5000 |
pj_grp_lock_add_ref(tsx->grp_lock); |
| 5001 |
|
| 5002 |
chal_param.rdata = e->body.tsx_state.src.rdata; |
| 5003 |
chal_param.tdata = tsx->last_tx; |
| 5004 |
status = pjsip_auth_clt_async_impl_on_challenge( |
| 5005 |
&inv->dlg->auth_sess, |
| 5006 |
token, &chal_param); |
| 5007 |
if (status != PJ_SUCCESS) |
| 5008 |
pj_grp_lock_dec_ref(tsx->grp_lock); |
| 5009 |
} |
| 5010 |
if (status != PJ_SUCCESS) { |
| 5011 |
status = pjsip_auth_clt_reinit_req( |
| 5012 |
&inv->dlg->auth_sess, |
| 5013 |
e->body.tsx_state.src.rdata, |
| 5014 |
tsx->last_tx, &tdata); |
| 5015 |
if (status != PJ_SUCCESS) { |
| 5016 |
|
| 5017 |
|
| 5018 |
|
| 5019 |
|
| 5020 |
|
| 5021 |
if (!inv_uac_recurse(inv, tsx->status_code, |
| 5022 |
&tsx->status_text, e)) |
| 5023 |
{ |
| 5024 |
|
| 5025 |
goto terminate_session; |
| 5026 |
} |
| 5027 |
|
| 5028 |
} else { |
| 5029 |
|
| 5030 |
|
| 5031 |
pjsip_inv_uac_restart(inv, PJ_FALSE); |
| 5032 |
|
| 5033 |
|
| 5034 |
status = pjsip_inv_send_msg(inv, tdata); |
| 5035 |
} |
| 5036 |
} |
| 5037 |
|
| 5038 |
} else if (tsx->state == PJSIP_TSX_STATE_COMPLETED && |
| 5039 |
tsx->status_code == PJSIP_SC_SESSION_TIMER_TOO_SMALL) |
| 5040 |
{ |
| 5041 |
|
| 5042 |
|
| 5043 |
|
| 5044 |
status = handle_timer_response(inv, e->body.tsx_state.src.rdata, |
| 5045 |
PJ_FALSE); |
| 5046 |
if (status != PJ_SUCCESS) |
| 5047 |
goto terminate_session; |
| 5048 |
|
| 5049 |
} else if (PJSIP_IS_STATUS_IN_CLASS(tsx->status_code, 600)) { |
| 5050 |
|
| 5051 |
goto terminate_session; |
| 5052 |
|
| 5053 |
} else { |
| 5054 |
|
| 5055 |
if (!inv_uac_recurse(inv, tsx->status_code, &tsx->status_text, e)) { |
| 5056 |
|
| 5057 |
goto terminate_session; |
| 5058 |
} |
| 5059 |
} |
| 5060 |
return; |
| 5061 |
|
| 5062 |
terminate_session: |
| 5063 |
inv_set_cause(inv, tsx->status_code, &tsx->status_text); |
| 5064 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); |
| 5065 |
} |
| 5066 |
|
| 5067 |
|
| 5068 |
|
| 5069 |
|
| 5070 |
|
| 5071 |
|
| 5072 |
static void inv_on_state_calling( pjsip_inv_session *inv, pjsip_event *e) |
| 5073 |
{ |
| 5074 |
pjsip_transaction *tsx = e->body.tsx_state.tsx; |
| 5075 |
pjsip_dialog *dlg = pjsip_tsx_get_dlg(tsx); |
| 5076 |
pj_status_t status; |
| 5077 |
|
| 5078 |
PJ_ASSERT_ON_FAIL(tsx && dlg, return); |
| 5079 |
|
| 5080 |
if (tsx == inv->invite_tsx) { |
| 5081 |
|
| 5082 |
switch (tsx->state) { |
| 5083 |
|
| 5084 |
case PJSIP_TSX_STATE_CALLING: |
| 5085 |
inv_set_state(inv, PJSIP_INV_STATE_CALLING, e); |
| 5086 |
break; |
| 5087 |
|
| 5088 |
case PJSIP_TSX_STATE_PROCEEDING: |
| 5089 |
if (inv->pending_cancel) { |
| 5090 |
pjsip_tx_data *cancel; |
| 5091 |
|
| 5092 |
inv->pending_cancel = PJ_FALSE; |
| 5093 |
|
| 5094 |
status = pjsip_inv_end_session(inv, 487, NULL, &cancel); |
| 5095 |
if (status == PJ_SUCCESS && cancel) |
| 5096 |
status = pjsip_inv_send_msg(inv, cancel); |
| 5097 |
} |
| 5098 |
|
| 5099 |
if (tsx->status_code != 100) { |
| 5100 |
|
| 5101 |
if (inv->role == PJSIP_ROLE_UAC) { |
| 5102 |
pjsip_rx_data *rdata = e->body.tsx_state.src.rdata; |
| 5103 |
pjsip_allow_hdr *allow = NULL; |
| 5104 |
pjsip_msg *msg = rdata->msg_info.msg; |
| 5105 |
|
| 5106 |
if (msg) { |
| 5107 |
allow = (pjsip_allow_hdr*) pjsip_msg_find_hdr(msg, |
| 5108 |
PJSIP_H_ALLOW, NULL); |
| 5109 |
} |
| 5110 |
if (allow) { |
| 5111 |
unsigned i; |
| 5112 |
const pj_str_t STR_UPDATE = { "UPDATE", 6 }; |
| 5113 |
|
| 5114 |
for (i=0; i<allow->count; ++i) { |
| 5115 |
if (pj_stricmp(&allow->values[i], &STR_UPDATE)==0) { |
| 5116 |
|
| 5117 |
inv->options |= PJSIP_INV_SUPPORT_UPDATE; |
| 5118 |
break; |
| 5119 |
} |
| 5120 |
} |
| 5121 |
} |
| 5122 |
} |
| 5123 |
|
| 5124 |
if (dlg->remote.info->tag.slen) |
| 5125 |
inv_set_state(inv, PJSIP_INV_STATE_EARLY, e); |
| 5126 |
|
| 5127 |
inv_check_sdp_in_incoming_msg(inv, tsx, |
| 5128 |
e->body.tsx_state.src.rdata); |
| 5129 |
|
| 5130 |
if (pjsip_100rel_is_reliable(e->body.tsx_state.src.rdata)) { |
| 5131 |
inv_handle_incoming_reliable_response( |
| 5132 |
inv, e->body.tsx_state.src.rdata); |
| 5133 |
} |
| 5134 |
|
| 5135 |
} else { |
| 5136 |
|
| 5137 |
|
| 5138 |
|
| 5139 |
} |
| 5140 |
break; |
| 5141 |
|
| 5142 |
case PJSIP_TSX_STATE_COMPLETED: |
| 5143 |
if (tsx->status_code/100 == 2) { |
| 5144 |
|
| 5145 |
|
| 5146 |
|
| 5147 |
|
| 5148 |
pj_assert(0); |
| 5149 |
|
| 5150 |
inv_set_state(inv, PJSIP_INV_STATE_CONNECTING, e); |
| 5151 |
|
| 5152 |
|
| 5153 |
if (!inv_check_secure_dlg(inv, e)) |
| 5154 |
break; |
| 5155 |
|
| 5156 |
|
| 5157 |
status = handle_timer_response(inv, |
| 5158 |
e->body.tsx_state.src.rdata, |
| 5159 |
PJ_TRUE); |
| 5160 |
if (status != PJ_SUCCESS) |
| 5161 |
break; |
| 5162 |
|
| 5163 |
inv_check_sdp_in_incoming_msg(inv, tsx, |
| 5164 |
e->body.tsx_state.src.rdata); |
| 5165 |
|
| 5166 |
} else { |
| 5167 |
handle_uac_call_rejection(inv, e); |
| 5168 |
} |
| 5169 |
break; |
| 5170 |
|
| 5171 |
case PJSIP_TSX_STATE_TERMINATED: |
| 5172 |
|
| 5173 |
|
| 5174 |
|
| 5175 |
|
| 5176 |
if (tsx->status_code/100 == 2) { |
| 5177 |
|
| 5178 |
pj_assert(e->body.tsx_state.type == PJSIP_EVENT_RX_MSG); |
| 5179 |
|
| 5180 |
|
| 5181 |
inv_set_state(inv, PJSIP_INV_STATE_CONNECTING, e); |
| 5182 |
|
| 5183 |
|
| 5184 |
if (!inv_check_secure_dlg(inv, e)) |
| 5185 |
break; |
| 5186 |
|
| 5187 |
|
| 5188 |
status = handle_timer_response(inv, |
| 5189 |
e->body.tsx_state.src.rdata, |
| 5190 |
PJ_TRUE); |
| 5191 |
if (status != PJ_SUCCESS) |
| 5192 |
break; |
| 5193 |
|
| 5194 |
inv_check_sdp_in_incoming_msg(inv, tsx, |
| 5195 |
e->body.tsx_state.src.rdata); |
| 5196 |
|
| 5197 |
inv_send_ack(inv, e); |
| 5198 |
|
| 5199 |
} else { |
| 5200 |
inv_set_cause(inv, tsx->status_code, &tsx->status_text); |
| 5201 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); |
| 5202 |
} |
| 5203 |
break; |
| 5204 |
|
| 5205 |
default: |
| 5206 |
break; |
| 5207 |
} |
| 5208 |
|
| 5209 |
} else if (tsx->role == PJSIP_ROLE_UAC) { |
| 5210 |
|
| 5211 |
|
| 5212 |
|
| 5213 |
|
| 5214 |
|
| 5215 |
|
| 5216 |
|
| 5217 |
if ((tsx->status_code == PJSIP_SC_CALL_TSX_DOES_NOT_EXIST && |
| 5218 |
tsx->method.id != PJSIP_CANCEL_METHOD) || |
| 5219 |
tsx->status_code == PJSIP_SC_REQUEST_TIMEOUT || |
| 5220 |
tsx->status_code == PJSIP_SC_TSX_TIMEOUT) |
| 5221 |
{ |
| 5222 |
inv_set_cause(inv, tsx->status_code, &tsx->status_text); |
| 5223 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); |
| 5224 |
} |
| 5225 |
} else if (tsx->role == PJSIP_ROLE_UAS && |
| 5226 |
tsx->state == PJSIP_TSX_STATE_TRYING && |
| 5227 |
pjsip_method_cmp(&tsx->method, &pjsip_update_method)==0) |
| 5228 |
{ |
| 5229 |
|
| 5230 |
|
| 5231 |
|
| 5232 |
inv_respond_incoming_update(inv, e); |
| 5233 |
|
| 5234 |
|
| 5235 |
} |
| 5236 |
} |
| 5237 |
|
| 5238 |
|
| 5239 |
|
| 5240 |
|
| 5241 |
|
| 5242 |
static void inv_on_state_incoming( pjsip_inv_session *inv, pjsip_event *e) |
| 5243 |
{ |
| 5244 |
pjsip_transaction *tsx = e->body.tsx_state.tsx; |
| 5245 |
pjsip_dialog *dlg = pjsip_tsx_get_dlg(tsx); |
| 5246 |
|
| 5247 |
PJ_ASSERT_ON_FAIL(tsx && dlg, return); |
| 5248 |
|
| 5249 |
if (tsx == inv->invite_tsx) { |
| 5250 |
|
| 5251 |
|
| 5252 |
|
| 5253 |
|
| 5254 |
|
| 5255 |
switch (tsx->state) { |
| 5256 |
|
| 5257 |
case PJSIP_TSX_STATE_TRYING: |
| 5258 |
inv_set_state(inv, PJSIP_INV_STATE_INCOMING, e); |
| 5259 |
break; |
| 5260 |
|
| 5261 |
case PJSIP_TSX_STATE_PROCEEDING: |
| 5262 |
|
| 5263 |
|
| 5264 |
|
| 5265 |
if (tsx->status_code > 100) |
| 5266 |
inv_set_state(inv, PJSIP_INV_STATE_EARLY, e); |
| 5267 |
break; |
| 5268 |
|
| 5269 |
case PJSIP_TSX_STATE_COMPLETED: |
| 5270 |
|
| 5271 |
|
| 5272 |
|
| 5273 |
if (tsx->status_code/100 == 2) { |
| 5274 |
inv_set_state(inv, PJSIP_INV_STATE_CONNECTING, e); |
| 5275 |
} else { |
| 5276 |
inv_set_cause(inv, tsx->status_code, &tsx->status_text); |
| 5277 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); |
| 5278 |
} |
| 5279 |
break; |
| 5280 |
|
| 5281 |
case PJSIP_TSX_STATE_TERMINATED: |
| 5282 |
|
| 5283 |
|
| 5284 |
|
| 5285 |
|
| 5286 |
inv_set_cause(inv, tsx->status_code, &tsx->status_text); |
| 5287 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); |
| 5288 |
break; |
| 5289 |
|
| 5290 |
default: |
| 5291 |
pj_assert(!"Unexpected INVITE state"); |
| 5292 |
break; |
| 5293 |
} |
| 5294 |
|
| 5295 |
} else if (tsx->method.id == PJSIP_CANCEL_METHOD && |
| 5296 |
tsx->role == PJSIP_ROLE_UAS && |
| 5297 |
tsx->state < PJSIP_TSX_STATE_COMPLETED && |
| 5298 |
e->body.tsx_state.type == PJSIP_EVENT_RX_MSG ) |
| 5299 |
{ |
| 5300 |
|
| 5301 |
|
| 5302 |
|
| 5303 |
|
| 5304 |
|
| 5305 |
inv_respond_incoming_cancel(inv, tsx, e); |
| 5306 |
|
| 5307 |
} |
| 5308 |
} |
| 5309 |
|
| 5310 |
|
| 5311 |
|
| 5312 |
|
| 5313 |
|
| 5314 |
static void inv_on_state_early( pjsip_inv_session *inv, pjsip_event *e) |
| 5315 |
{ |
| 5316 |
pjsip_transaction *tsx = e->body.tsx_state.tsx; |
| 5317 |
pjsip_dialog *dlg = pjsip_tsx_get_dlg(tsx); |
| 5318 |
|
| 5319 |
PJ_ASSERT_ON_FAIL(tsx && dlg, return); |
| 5320 |
|
| 5321 |
if (tsx == inv->invite_tsx) { |
| 5322 |
|
| 5323 |
|
| 5324 |
|
| 5325 |
|
| 5326 |
|
| 5327 |
switch (tsx->state) { |
| 5328 |
|
| 5329 |
case PJSIP_TSX_STATE_PROCEEDING: |
| 5330 |
|
| 5331 |
inv_set_state(inv, PJSIP_INV_STATE_EARLY, e); |
| 5332 |
|
| 5333 |
if (e->body.tsx_state.type == PJSIP_EVENT_RX_MSG) { |
| 5334 |
inv_check_sdp_in_incoming_msg(inv, tsx, |
| 5335 |
e->body.tsx_state.src.rdata); |
| 5336 |
|
| 5337 |
if (pjsip_100rel_is_reliable(e->body.tsx_state.src.rdata)) { |
| 5338 |
inv_handle_incoming_reliable_response( |
| 5339 |
inv, e->body.tsx_state.src.rdata); |
| 5340 |
} |
| 5341 |
} |
| 5342 |
break; |
| 5343 |
|
| 5344 |
case PJSIP_TSX_STATE_COMPLETED: |
| 5345 |
if (tsx->status_code/100 == 2) { |
| 5346 |
inv_set_state(inv, PJSIP_INV_STATE_CONNECTING, e); |
| 5347 |
if (e->body.tsx_state.type == PJSIP_EVENT_RX_MSG) { |
| 5348 |
pj_status_t status; |
| 5349 |
|
| 5350 |
|
| 5351 |
if (!inv_check_secure_dlg(inv, e)) |
| 5352 |
break; |
| 5353 |
|
| 5354 |
|
| 5355 |
status = handle_timer_response(inv, |
| 5356 |
e->body.tsx_state.src.rdata, |
| 5357 |
PJ_TRUE); |
| 5358 |
if (status != PJ_SUCCESS) |
| 5359 |
break; |
| 5360 |
|
| 5361 |
inv_check_sdp_in_incoming_msg(inv, tsx, |
| 5362 |
e->body.tsx_state.src.rdata); |
| 5363 |
} |
| 5364 |
|
| 5365 |
} else if (tsx->role == PJSIP_ROLE_UAC) { |
| 5366 |
|
| 5367 |
handle_uac_call_rejection(inv, e); |
| 5368 |
|
| 5369 |
} else { |
| 5370 |
inv_set_cause(inv, tsx->status_code, &tsx->status_text); |
| 5371 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); |
| 5372 |
} |
| 5373 |
break; |
| 5374 |
|
| 5375 |
case PJSIP_TSX_STATE_CONFIRMED: |
| 5376 |
|
| 5377 |
|
| 5378 |
|
| 5379 |
case PJSIP_TSX_STATE_TERMINATED: |
| 5380 |
|
| 5381 |
|
| 5382 |
|
| 5383 |
|
| 5384 |
if (tsx->status_code/100 == 2) { |
| 5385 |
|
| 5386 |
|
| 5387 |
|
| 5388 |
|
| 5389 |
inv_set_state(inv, PJSIP_INV_STATE_CONNECTING, e); |
| 5390 |
|
| 5391 |
if (e->body.tsx_state.type == PJSIP_EVENT_RX_MSG) { |
| 5392 |
pj_status_t status; |
| 5393 |
|
| 5394 |
|
| 5395 |
if (!inv_check_secure_dlg(inv, e)) |
| 5396 |
break; |
| 5397 |
|
| 5398 |
|
| 5399 |
status = handle_timer_response(inv, |
| 5400 |
e->body.tsx_state.src.rdata, |
| 5401 |
PJ_TRUE); |
| 5402 |
if (status != PJ_SUCCESS) |
| 5403 |
break; |
| 5404 |
|
| 5405 |
inv_check_sdp_in_incoming_msg(inv, tsx, |
| 5406 |
e->body.tsx_state.src.rdata); |
| 5407 |
} |
| 5408 |
|
| 5409 |
|
| 5410 |
if (tsx->role == PJSIP_ROLE_UAC) { |
| 5411 |
pj_assert(e->body.tsx_state.type == PJSIP_EVENT_RX_MSG); |
| 5412 |
|
| 5413 |
inv_send_ack(inv, e); |
| 5414 |
} |
| 5415 |
|
| 5416 |
} else { |
| 5417 |
inv_set_cause(inv, tsx->status_code, &tsx->status_text); |
| 5418 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); |
| 5419 |
} |
| 5420 |
break; |
| 5421 |
|
| 5422 |
default: |
| 5423 |
pj_assert(!"Unexpected INVITE tsx state"); |
| 5424 |
break; |
| 5425 |
} |
| 5426 |
} else if (tsx->method.id == PJSIP_INVITE_METHOD && |
| 5427 |
tsx->role == PJSIP_ROLE_UAS && |
| 5428 |
tsx->state == PJSIP_TSX_STATE_TRYING) |
| 5429 |
{ |
| 5430 |
|
| 5431 |
pjsip_rx_data *rdata = e->body.tsx_state.src.rdata; |
| 5432 |
pjsip_tx_data *tdata; |
| 5433 |
pj_status_t status; |
| 5434 |
int code; |
| 5435 |
const pj_str_t *reason; |
| 5436 |
|
| 5437 |
if (inv->invite_tsx->role == PJSIP_ROLE_UAC) |
| 5438 |
code = PJSIP_SC_REQUEST_PENDING; |
| 5439 |
else |
| 5440 |
code = PJSIP_SC_INTERNAL_SERVER_ERROR; |
| 5441 |
|
| 5442 |
reason = pjsip_get_status_text(code); |
| 5443 |
|
| 5444 |
|
| 5445 |
status = pjsip_dlg_create_response( inv->dlg, rdata, code, |
| 5446 |
reason, &tdata); |
| 5447 |
if (status != PJ_SUCCESS) |
| 5448 |
return; |
| 5449 |
|
| 5450 |
if (code == PJSIP_SC_INTERNAL_SERVER_ERROR) { |
| 5451 |
|
| 5452 |
|
| 5453 |
|
| 5454 |
pjsip_retry_after_hdr *ra_hdr; |
| 5455 |
int val = (pj_rand() % 10); |
| 5456 |
|
| 5457 |
ra_hdr = pjsip_retry_after_hdr_create(tdata->pool, val); |
| 5458 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)ra_hdr); |
| 5459 |
} |
| 5460 |
|
| 5461 |
pjsip_dlg_send_response( inv->dlg, tsx, tdata); |
| 5462 |
|
| 5463 |
} else if (inv->role == PJSIP_ROLE_UAS && |
| 5464 |
tsx->role == PJSIP_ROLE_UAS && |
| 5465 |
tsx->method.id == PJSIP_CANCEL_METHOD && |
| 5466 |
tsx->state < PJSIP_TSX_STATE_COMPLETED && |
| 5467 |
e->body.tsx_state.type == PJSIP_EVENT_RX_MSG ) |
| 5468 |
{ |
| 5469 |
|
| 5470 |
|
| 5471 |
|
| 5472 |
|
| 5473 |
|
| 5474 |
inv_respond_incoming_cancel(inv, tsx, e); |
| 5475 |
|
| 5476 |
} else if (tsx->role == PJSIP_ROLE_UAS && |
| 5477 |
tsx->state == PJSIP_TSX_STATE_TRYING && |
| 5478 |
pjsip_method_cmp(&tsx->method, &pjsip_update_method)==0) |
| 5479 |
{ |
| 5480 |
|
| 5481 |
|
| 5482 |
|
| 5483 |
inv_respond_incoming_update(inv, e); |
| 5484 |
|
| 5485 |
|
| 5486 |
} else if (tsx->role == PJSIP_ROLE_UAC && |
| 5487 |
(tsx->state == PJSIP_TSX_STATE_COMPLETED || |
| 5488 |
tsx->state == PJSIP_TSX_STATE_TERMINATED) && |
| 5489 |
pjsip_method_cmp(&tsx->method, &pjsip_update_method)==0) |
| 5490 |
{ |
| 5491 |
|
| 5492 |
|
| 5493 |
|
| 5494 |
inv_handle_update_response(inv, e); |
| 5495 |
|
| 5496 |
} else if (tsx->role == PJSIP_ROLE_UAS && |
| 5497 |
tsx->state == PJSIP_TSX_STATE_TRYING && |
| 5498 |
pjsip_method_cmp(&tsx->method, &pjsip_prack_method)==0) |
| 5499 |
{ |
| 5500 |
|
| 5501 |
|
| 5502 |
|
| 5503 |
inv_respond_incoming_prack(inv, e->body.tsx_state.src.rdata); |
| 5504 |
|
| 5505 |
} else if (tsx->role == PJSIP_ROLE_UAC) { |
| 5506 |
|
| 5507 |
|
| 5508 |
handle_uac_tsx_response(inv, e); |
| 5509 |
|
| 5510 |
} else if (tsx->role == PJSIP_ROLE_UAS && |
| 5511 |
tsx->method.id == PJSIP_BYE_METHOD && |
| 5512 |
tsx->status_code < 200 && |
| 5513 |
e->body.tsx_state.type == PJSIP_EVENT_RX_MSG) |
| 5514 |
{ |
| 5515 |
|
| 5516 |
|
| 5517 |
|
| 5518 |
|
| 5519 |
inv_respond_incoming_bye(inv, tsx, e->body.tsx_state.src.rdata, e); |
| 5520 |
|
| 5521 |
if (inv->invite_tsx->role == PJSIP_ROLE_UAC) { |
| 5522 |
|
| 5523 |
|
| 5524 |
|
| 5525 |
pjsip_tsx_set_timeout(inv->invite_tsx, 64*pjsip_cfg()->tsx.t1); |
| 5526 |
} else if (inv->invite_tsx->status_code < 200) { |
| 5527 |
pjsip_tx_data *tdata; |
| 5528 |
pjsip_msg *msg; |
| 5529 |
|
| 5530 |
|
| 5531 |
tdata = inv->invite_tsx->last_tx; |
| 5532 |
PJ_ASSERT_ON_FAIL(tdata != NULL, return); |
| 5533 |
|
| 5534 |
msg = tdata->msg; |
| 5535 |
msg->line.status.code = PJSIP_SC_REQUEST_TERMINATED; |
| 5536 |
msg->line.status.reason = |
| 5537 |
*pjsip_get_status_text(PJSIP_SC_REQUEST_TERMINATED); |
| 5538 |
msg->body = NULL; |
| 5539 |
|
| 5540 |
pjsip_tx_data_invalidate_msg(tdata); |
| 5541 |
pjsip_tx_data_add_ref(tdata); |
| 5542 |
|
| 5543 |
pjsip_dlg_send_response(inv->dlg, inv->invite_tsx, tdata); |
| 5544 |
} |
| 5545 |
} |
| 5546 |
} |
| 5547 |
|
| 5548 |
|
| 5549 |
|
| 5550 |
|
| 5551 |
static void inv_on_state_connecting( pjsip_inv_session *inv, pjsip_event *e) |
| 5552 |
{ |
| 5553 |
pjsip_transaction *tsx = e->body.tsx_state.tsx; |
| 5554 |
pjsip_dialog *dlg = pjsip_tsx_get_dlg(tsx); |
| 5555 |
|
| 5556 |
PJ_ASSERT_ON_FAIL(tsx && dlg, return); |
| 5557 |
|
| 5558 |
if (tsx == inv->invite_tsx) { |
| 5559 |
|
| 5560 |
|
| 5561 |
|
| 5562 |
|
| 5563 |
switch (tsx->state) { |
| 5564 |
|
| 5565 |
case PJSIP_TSX_STATE_CONFIRMED: |
| 5566 |
|
| 5567 |
|
| 5568 |
|
| 5569 |
if (tsx->status_code/100 == 2) { |
| 5570 |
if (e->body.tsx_state.type == PJSIP_EVENT_RX_MSG) { |
| 5571 |
inv_check_sdp_in_incoming_msg(inv, tsx, |
| 5572 |
e->body.tsx_state.src.rdata); |
| 5573 |
} |
| 5574 |
|
| 5575 |
inv_set_state(inv, PJSIP_INV_STATE_CONFIRMED, e); |
| 5576 |
|
| 5577 |
|
| 5578 |
|
| 5579 |
|
| 5580 |
|
| 5581 |
|
| 5582 |
if (inv->pending_bye) |
| 5583 |
inv_perform_pending_bye(inv); |
| 5584 |
|
| 5585 |
} |
| 5586 |
break; |
| 5587 |
|
| 5588 |
case PJSIP_TSX_STATE_TERMINATED: |
| 5589 |
|
| 5590 |
|
| 5591 |
|
| 5592 |
|
| 5593 |
if (tsx->status_code/100 != 2) { |
| 5594 |
if (tsx->role == PJSIP_ROLE_UAC) { |
| 5595 |
inv_set_cause(inv, tsx->status_code, &tsx->status_text); |
| 5596 |
inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); |
| 5597 |
} else { |
| 5598 |
pjsip_tx_data *bye; |
| 5599 |
pj_status_t status; |
| 5600 |
|
| 5601 |
inv_set_cause(inv, tsx->status_code, &tsx->status_text); |
| 5602 |
|
| 5603 |
|
| 5604 |
status = pjsip_dlg_create_request(inv->dlg, |
| 5605 |
pjsip_get_bye_method(), |
| 5606 |
-1, &bye); |
| 5607 |
if (status == PJ_SUCCESS && tsx->status_text.slen) { |
| 5608 |
status = add_reason_warning_hdr(bye, tsx->status_code, |
| 5609 |
&tsx->status_text); |
| 5610 |
} |
| 5611 |
if (status == PJ_SUCCESS) { |
| 5612 |
pjsip_inv_send_msg(inv, bye); |
| 5613 |
|
| 5614 |
if (inv->pending_bye) { |
| 5615 |
pjsip_tx_data_dec_ref(inv->pending_bye); |
| 5616 |
inv->pending_bye = NULL; |
| 5617 |
} |
| 5618 |
} |
| 5619 |
} |
| 5620 |
} |
| 5621 |
break; |
| 5622 |
|
| 5623 |
case PJSIP_TSX_STATE_DESTROYED: |
| 5624 |
|
| 5625 |
break; |
| 5626 |
|
| 5627 |
default: |
| 5628 |
pj_assert(!"Unexpected state"); |
| 5629 |
break; |
| 5630 |
} |
| 5631 |
|
| 5632 |
} else if (tsx->role == PJSIP_ROLE_UAS && |
| 5633 |
tsx->method.id == PJSIP_BYE_METHOD && |
| 5634 |
tsx->status_code < 200 && |
| 5635 |
e->body.tsx_state.type == PJSIP_EVENT_RX_MSG) |
| 5636 |
{ |
| 5637 |
|
| 5638 |
|
| 5639 |
|
| 5640 |
|
| 5641 |
|
| 5642 |
inv_respond_incoming_bye( inv, tsx, e->body.tsx_state.src.rdata, e ); |
| 5643 |
|
| 5644 |
} else if (tsx->method.id == PJSIP_BYE_METHOD && |
| 5645 |
tsx->role == PJSIP_ROLE_UAC && |
| 5646 |
(tsx->state == PJSIP_TSX_STATE_COMPLETED || |
| 5647 |
tsx->state == PJSIP_TSX_STATE_TERMINATED)) |
| 5648 |
{ |
| 5649 |
|
| 5650 |
|
| 5651 |
|
| 5652 |
|
| 5653 |
inv_handle_bye_response( inv, tsx, e->body.tsx_state.src.rdata, e); |
| 5654 |
|
| 5655 |
} |
| 5656 |
else if (tsx->method.id == PJSIP_CANCEL_METHOD && |
| 5657 |
tsx->role == PJSIP_ROLE_UAS && |
| 5658 |
tsx->status_code < 200 && |
| 5659 |
e->body.tsx_state.type == PJSIP_EVENT_RX_MSG) |
| 5660 |
{ |
| 5661 |
|
| 5662 |
|
| 5663 |
|
| 5664 |
|
| 5665 |
inv_respond_incoming_cancel(inv, tsx, e); |
| 5666 |
|
| 5667 |
} else if (tsx->role == PJSIP_ROLE_UAS && |
| 5668 |
tsx->state == PJSIP_TSX_STATE_TRYING && |
| 5669 |
pjsip_method_cmp(&tsx->method, pjsip_get_invite_method())==0) |
| 5670 |
{ |
| 5671 |
pjsip_rx_data *rdata = e->body.tsx_state.src.rdata; |
| 5672 |
pjsip_tx_data *tdata; |
| 5673 |
pj_status_t status; |
| 5674 |
|
| 5675 |
|
| 5676 |
|
| 5677 |
|
| 5678 |
|
| 5679 |
|
| 5680 |
|
| 5681 |
|
| 5682 |
|
| 5683 |
|
| 5684 |
|
| 5685 |
status = pjsip_dlg_create_response(inv->dlg, rdata, |
| 5686 |
PJSIP_SC_REQUEST_PENDING, |
| 5687 |
NULL, &tdata); |
| 5688 |
if (status != PJ_SUCCESS) |
| 5689 |
return; |
| 5690 |
pjsip_timer_update_resp(inv, tdata); |
| 5691 |
status = pjsip_dlg_send_response(dlg, tsx, tdata); |
| 5692 |
|
| 5693 |
} else if (tsx->role == PJSIP_ROLE_UAS && |
| 5694 |
tsx->state == PJSIP_TSX_STATE_TRYING && |
| 5695 |
pjsip_method_cmp(&tsx->method, &pjsip_update_method)==0) |
| 5696 |
{ |
| 5697 |
|
| 5698 |
|
| 5699 |
|
| 5700 |
inv_respond_incoming_update(inv, e); |
| 5701 |
|
| 5702 |
|
| 5703 |
} else if (tsx->role == PJSIP_ROLE_UAC && |
| 5704 |
(tsx->state == PJSIP_TSX_STATE_COMPLETED || |
| 5705 |
tsx->state == PJSIP_TSX_STATE_TERMINATED) && |
| 5706 |
pjsip_method_cmp(&tsx->method, &pjsip_update_method)==0) |
| 5707 |
{ |
| 5708 |
|
| 5709 |
|
| 5710 |
|
| 5711 |
if (inv_handle_update_response(inv, e) == PJ_FALSE) |
| 5712 |
handle_uac_tsx_response(inv, e); |
| 5713 |
|
| 5714 |
} else if (tsx->role == PJSIP_ROLE_UAS && |
| 5715 |
tsx->state == PJSIP_TSX_STATE_TRYING && |
| 5716 |
pjsip_method_cmp(&tsx->method, &pjsip_prack_method)==0) |
| 5717 |
{ |
| 5718 |
|
| 5719 |
|
| 5720 |
|
| 5721 |
inv_respond_incoming_prack(inv, e->body.tsx_state.src.rdata); |
| 5722 |
|
| 5723 |
} else if (tsx->role == PJSIP_ROLE_UAC) { |
| 5724 |
|
| 5725 |
|
| 5726 |
handle_uac_tsx_response(inv, e); |
| 5727 |
|
| 5728 |
} |
| 5729 |
|
| 5730 |
} |
| 5731 |
|
| 5732 |
|
| 5733 |
|
| 5734 |
|
| 5735 |
static void inv_on_state_confirmed( pjsip_inv_session *inv, pjsip_event *e) |
| 5736 |
{ |
| 5737 |
pjsip_transaction *tsx = e->body.tsx_state.tsx; |
| 5738 |
pjsip_dialog *dlg = pjsip_tsx_get_dlg(tsx); |
| 5739 |
|
| 5740 |
PJ_ASSERT_ON_FAIL(tsx && dlg, return); |
| 5741 |
|
| 5742 |
|
| 5743 |
if (tsx->method.id == PJSIP_BYE_METHOD && |
| 5744 |
tsx->role == PJSIP_ROLE_UAC && |
| 5745 |
(tsx->state == PJSIP_TSX_STATE_COMPLETED || |
| 5746 |
tsx->state == PJSIP_TSX_STATE_TERMINATED)) |
| 5747 |
{ |
| 5748 |
|
| 5749 |
|
| 5750 |
|
| 5751 |
|
| 5752 |
|
| 5753 |
inv_handle_bye_response( inv, tsx, e->body.tsx_state.src.rdata, e); |
| 5754 |
|
| 5755 |
} |
| 5756 |
else if (tsx->method.id == PJSIP_BYE_METHOD && |
| 5757 |
tsx->role == PJSIP_ROLE_UAS && |
| 5758 |
tsx->status_code < 200 && |
| 5759 |
e->body.tsx_state.type == PJSIP_EVENT_RX_MSG) |
| 5760 |
{ |
| 5761 |
|
| 5762 |
|
| 5763 |
|
| 5764 |
|
| 5765 |
|
| 5766 |
inv_respond_incoming_bye( inv, tsx, e->body.tsx_state.src.rdata, e ); |
| 5767 |
|
| 5768 |
} |
| 5769 |
else if (tsx->method.id == PJSIP_CANCEL_METHOD && |
| 5770 |
tsx->role == PJSIP_ROLE_UAS && |
| 5771 |
tsx->status_code < 200 && |
| 5772 |
e->body.tsx_state.type == PJSIP_EVENT_RX_MSG) |
| 5773 |
{ |
| 5774 |
|
| 5775 |
|
| 5776 |
|
| 5777 |
|
| 5778 |
inv_respond_incoming_cancel(inv, tsx, e); |
| 5779 |
} |
| 5780 |
else if (tsx->method.id == PJSIP_INVITE_METHOD && |
| 5781 |
tsx->role == PJSIP_ROLE_UAS) |
| 5782 |
{ |
| 5783 |
|
| 5784 |
|
| 5785 |
|
| 5786 |
|
| 5787 |
if (tsx->state == PJSIP_TSX_STATE_TRYING) { |
| 5788 |
|
| 5789 |
pjsip_rx_data *rdata = e->body.tsx_state.src.rdata; |
| 5790 |
pjsip_tx_data *tdata; |
| 5791 |
pj_status_t status; |
| 5792 |
pjsip_rdata_sdp_info *sdp_info = NULL; |
| 5793 |
pjsip_status_code st_code; |
| 5794 |
|
| 5795 |
|
| 5796 |
if (inv->invite_tsx && inv->invite_tsx!=tsx) { |
| 5797 |
int code; |
| 5798 |
pj_str_t reason; |
| 5799 |
|
| 5800 |
reason = pj_str("Another INVITE transaction in progress"); |
| 5801 |
|
| 5802 |
if (inv->invite_tsx->role == PJSIP_ROLE_UAC) |
| 5803 |
code = 491; |
| 5804 |
else |
| 5805 |
code = 500; |
| 5806 |
|
| 5807 |
|
| 5808 |
status = pjsip_dlg_create_response( inv->dlg, rdata, code, |
| 5809 |
&reason, &tdata); |
| 5810 |
if (status != PJ_SUCCESS) |
| 5811 |
return; |
| 5812 |
|
| 5813 |
if (code == 500) { |
| 5814 |
|
| 5815 |
|
| 5816 |
|
| 5817 |
pjsip_retry_after_hdr *ra_hdr; |
| 5818 |
int val = (pj_rand() % 10); |
| 5819 |
|
| 5820 |
ra_hdr = pjsip_retry_after_hdr_create(tdata->pool, val); |
| 5821 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)ra_hdr); |
| 5822 |
} |
| 5823 |
|
| 5824 |
status = pjsip_dlg_send_response( inv->dlg, tsx, tdata); |
| 5825 |
|
| 5826 |
|
| 5827 |
return; |
| 5828 |
} |
| 5829 |
|
| 5830 |
|
| 5831 |
if (!inv_check_secure_dlg(inv, e)) |
| 5832 |
return; |
| 5833 |
|
| 5834 |
|
| 5835 |
inv->invite_tsx = tsx; |
| 5836 |
|
| 5837 |
|
| 5838 |
status = pjsip_timer_process_req(inv, rdata, &st_code); |
| 5839 |
if (status != PJ_SUCCESS) { |
| 5840 |
status = pjsip_dlg_create_response(inv->dlg, rdata, st_code, |
| 5841 |
NULL, &tdata); |
| 5842 |
if (status != PJ_SUCCESS) |
| 5843 |
return; |
| 5844 |
|
| 5845 |
pjsip_timer_update_resp(inv, tdata); |
| 5846 |
status = pjsip_dlg_send_response(dlg, tsx, tdata); |
| 5847 |
return; |
| 5848 |
} |
| 5849 |
|
| 5850 |
|
| 5851 |
|
| 5852 |
|
| 5853 |
if (pjmedia_sdp_neg_get_state(inv->neg) != |
| 5854 |
PJMEDIA_SDP_NEG_STATE_DONE) |
| 5855 |
{ |
| 5856 |
status = pjsip_dlg_create_response(inv->dlg, rdata, |
| 5857 |
PJSIP_SC_REQUEST_PENDING, |
| 5858 |
NULL, &tdata); |
| 5859 |
if (status != PJ_SUCCESS) |
| 5860 |
return; |
| 5861 |
pjsip_timer_update_resp(inv, tdata); |
| 5862 |
status = pjsip_dlg_send_response(dlg, tsx, tdata); |
| 5863 |
return; |
| 5864 |
} |
| 5865 |
|
| 5866 |
|
| 5867 |
status = inv_check_sdp_in_incoming_msg(inv, tsx, rdata); |
| 5868 |
|
| 5869 |
if (status == PJ_SUCCESS && mod_inv.cb.on_rx_reinvite && |
| 5870 |
inv->notify) |
| 5871 |
{ |
| 5872 |
pj_status_t rc; |
| 5873 |
|
| 5874 |
sdp_info = pjsip_rdata_get_sdp_info(rdata); |
| 5875 |
rc = (*mod_inv.cb.on_rx_reinvite)(inv, sdp_info->sdp, |
| 5876 |
rdata); |
| 5877 |
if (rc == PJ_SUCCESS) { |
| 5878 |
|
| 5879 |
|
| 5880 |
PJ_LOG(5,(inv->obj_name, "on_rx_reinvite() returns %d", |
| 5881 |
rc)); |
| 5882 |
return; |
| 5883 |
} |
| 5884 |
|
| 5885 |
|
| 5886 |
|
| 5887 |
|
| 5888 |
|
| 5889 |
if (sdp_info->sdp && |
| 5890 |
(pjmedia_sdp_neg_get_state(inv->neg) != |
| 5891 |
PJMEDIA_SDP_NEG_STATE_WAIT_NEGO)) |
| 5892 |
{ |
| 5893 |
status = PJMEDIA_SDPNEG_EINSTATE; |
| 5894 |
} |
| 5895 |
} |
| 5896 |
|
| 5897 |
if (status != PJ_SUCCESS) { |
| 5898 |
pj_bool_t reject_message = PJ_TRUE; |
| 5899 |
|
| 5900 |
if (status == PJMEDIA_SDP_EINSDP) |
| 5901 |
{ |
| 5902 |
sdp_info = pjsip_rdata_get_sdp_info(rdata); |
| 5903 |
if (sdp_info->body.ptr == NULL && |
| 5904 |
PJSIP_INV_ACCEPT_UNKNOWN_BODY) |
| 5905 |
{ |
| 5906 |
|
| 5907 |
reject_message = PJ_FALSE; |
| 5908 |
} |
| 5909 |
} |
| 5910 |
|
| 5911 |
if (reject_message) { |
| 5912 |
|
| 5913 |
const pjsip_hdr *accept; |
| 5914 |
pj_str_t reason = pj_str("SDP negotiation failed"); |
| 5915 |
|
| 5916 |
if (status == PJMEDIA_SDP_EINSDP) |
| 5917 |
reason = pj_str("Bad SDP"); |
| 5918 |
else if (status == PJMEDIA_SDPNEG_EINSTATE) |
| 5919 |
reason = pj_str("No SDP answer"); |
| 5920 |
|
| 5921 |
|
| 5922 |
|
| 5923 |
|
| 5924 |
|
| 5925 |
if (pjmedia_sdp_neg_get_state(inv->neg) == |
| 5926 |
PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER) |
| 5927 |
{ |
| 5928 |
pjmedia_sdp_neg_cancel_offer(inv->neg); |
| 5929 |
} |
| 5930 |
|
| 5931 |
status = pjsip_dlg_create_response(inv->dlg, rdata, |
| 5932 |
(status == PJMEDIA_SDP_EINSDP)?415:488, |
| 5933 |
NULL, &tdata); |
| 5934 |
|
| 5935 |
if (status != PJ_SUCCESS) |
| 5936 |
return; |
| 5937 |
|
| 5938 |
|
| 5939 |
add_reason_warning_hdr(tdata, 0, &reason); |
| 5940 |
|
| 5941 |
accept = pjsip_endpt_get_capability(dlg->endpt, |
| 5942 |
PJSIP_H_ACCEPT, |
| 5943 |
NULL); |
| 5944 |
if (accept) { |
| 5945 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*) |
| 5946 |
pjsip_hdr_clone(tdata->pool, accept)); |
| 5947 |
} |
| 5948 |
|
| 5949 |
status = pjsip_dlg_send_response(dlg, tsx, tdata); |
| 5950 |
|
| 5951 |
return; |
| 5952 |
} |
| 5953 |
} |
| 5954 |
|
| 5955 |
|
| 5956 |
status = pjsip_dlg_create_response(dlg, rdata, 200, NULL, &tdata); |
| 5957 |
if (status != PJ_SUCCESS) |
| 5958 |
return; |
| 5959 |
|
| 5960 |
|
| 5961 |
|
| 5962 |
|
| 5963 |
if (!sdp_info) |
| 5964 |
sdp_info = pjsip_rdata_get_sdp_info(rdata); |
| 5965 |
if (sdp_info->sdp != NULL) { |
| 5966 |
status = process_answer(inv, 200, tdata, NULL); |
| 5967 |
} else { |
| 5968 |
|
| 5969 |
|
| 5970 |
|
| 5971 |
|
| 5972 |
|
| 5973 |
pjmedia_sdp_session *sdp = NULL; |
| 5974 |
|
| 5975 |
if (mod_inv.cb.on_create_offer) { |
| 5976 |
(*mod_inv.cb.on_create_offer)(inv, &sdp); |
| 5977 |
if (sdp) { |
| 5978 |
|
| 5979 |
|
| 5980 |
|
| 5981 |
status = |
| 5982 |
pjmedia_sdp_neg_modify_local_offer2( |
| 5983 |
inv->pool_prov, inv->neg, |
| 5984 |
inv->sdp_neg_flags, sdp); |
| 5985 |
|
| 5986 |
|
| 5987 |
if (status==PJ_SUCCESS) { |
| 5988 |
const pjmedia_sdp_session *lsdp = NULL; |
| 5989 |
pjmedia_sdp_neg_get_neg_local(inv->neg, &lsdp); |
| 5990 |
sdp = (pjmedia_sdp_session*)lsdp; |
| 5991 |
} |
| 5992 |
} |
| 5993 |
} |
| 5994 |
|
| 5995 |
if (sdp == NULL) { |
| 5996 |
const pjmedia_sdp_session *active_sdp = NULL; |
| 5997 |
status = pjmedia_sdp_neg_send_local_offer(inv->pool_prov, |
| 5998 |
inv->neg, |
| 5999 |
&active_sdp); |
| 6000 |
if (status == PJ_SUCCESS) |
| 6001 |
sdp = (pjmedia_sdp_session*) active_sdp; |
| 6002 |
} |
| 6003 |
|
| 6004 |
if (sdp) { |
| 6005 |
tdata->msg->body = create_sdp_body(tdata->pool, sdp); |
| 6006 |
} |
| 6007 |
} |
| 6008 |
|
| 6009 |
if (status != PJ_SUCCESS) { |
| 6010 |
|
| 6011 |
|
| 6012 |
|
| 6013 |
pj_status_t rc; |
| 6014 |
pj_str_t reason; |
| 6015 |
|
| 6016 |
|
| 6017 |
pjsip_tx_data_dec_ref(tdata); |
| 6018 |
|
| 6019 |
|
| 6020 |
reason = pj_str("SDP negotiation failed"); |
| 6021 |
rc = pjsip_dlg_create_response(dlg, rdata, 500, &reason, |
| 6022 |
&tdata); |
| 6023 |
if (rc == PJ_SUCCESS) { |
| 6024 |
pjsip_warning_hdr *w; |
| 6025 |
const pj_str_t *endpt_name; |
| 6026 |
|
| 6027 |
endpt_name = pjsip_endpt_name(dlg->endpt); |
| 6028 |
w = pjsip_warning_hdr_create_from_status(tdata->pool, |
| 6029 |
endpt_name, |
| 6030 |
status); |
| 6031 |
if (w) |
| 6032 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)w); |
| 6033 |
|
| 6034 |
pjsip_inv_send_msg(inv, tdata); |
| 6035 |
} |
| 6036 |
return; |
| 6037 |
} |
| 6038 |
|
| 6039 |
|
| 6040 |
pjsip_timer_update_resp(inv, tdata); |
| 6041 |
|
| 6042 |
|
| 6043 |
|
| 6044 |
|
| 6045 |
|
| 6046 |
{ |
| 6047 |
const pjsip_hdr *hdr; |
| 6048 |
pjsip_allow_hdr *allow_hdr = NULL; |
| 6049 |
pjsip_supported_hdr *sup_hdr = NULL; |
| 6050 |
|
| 6051 |
if (dlg->add_allow && |
| 6052 |
!pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ALLOW, NULL)) |
| 6053 |
{ |
| 6054 |
hdr = pjsip_endpt_get_capability(dlg->endpt, |
| 6055 |
PJSIP_H_ALLOW, NULL); |
| 6056 |
if (hdr) { |
| 6057 |
allow_hdr = (pjsip_allow_hdr*) |
| 6058 |
pjsip_hdr_clone(tdata->pool, hdr); |
| 6059 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)allow_hdr); |
| 6060 |
} |
| 6061 |
} |
| 6062 |
|
| 6063 |
if (!pjsip_msg_find_hdr(tdata->msg, PJSIP_H_SUPPORTED, NULL)) |
| 6064 |
{ |
| 6065 |
hdr = pjsip_endpt_get_capability(inv->dlg->endpt, |
| 6066 |
PJSIP_H_SUPPORTED, NULL); |
| 6067 |
if (hdr) { |
| 6068 |
sup_hdr = (pjsip_supported_hdr*) |
| 6069 |
pjsip_hdr_clone(tdata->pool, hdr); |
| 6070 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)sup_hdr); |
| 6071 |
} |
| 6072 |
} |
| 6073 |
|
| 6074 |
|
| 6075 |
cleanup_allow_sup_hdr(inv->options, NULL, allow_hdr, sup_hdr); |
| 6076 |
} |
| 6077 |
|
| 6078 |
|
| 6079 |
status = pjsip_inv_send_msg(inv, tdata); |
| 6080 |
|
| 6081 |
} else if (tsx->state == PJSIP_TSX_STATE_CONFIRMED) { |
| 6082 |
|
| 6083 |
|
| 6084 |
|
| 6085 |
if (tsx->status_code/100 == 2 && |
| 6086 |
e->body.tsx_state.type == PJSIP_EVENT_RX_MSG) |
| 6087 |
{ |
| 6088 |
inv_check_sdp_in_incoming_msg(inv, tsx, |
| 6089 |
e->body.tsx_state.src.rdata); |
| 6090 |
|
| 6091 |
|
| 6092 |
if (pjmedia_sdp_neg_get_state(inv->neg)== |
| 6093 |
PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER) |
| 6094 |
{ |
| 6095 |
pjmedia_sdp_neg_cancel_offer(inv->neg); |
| 6096 |
} |
| 6097 |
} |
| 6098 |
|
| 6099 |
} |
| 6100 |
|
| 6101 |
} |
| 6102 |
else if (tsx->method.id == PJSIP_INVITE_METHOD && |
| 6103 |
tsx->role == PJSIP_ROLE_UAC) |
| 6104 |
{ |
| 6105 |
|
| 6106 |
|
| 6107 |
|
| 6108 |
|
| 6109 |
if (tsx->state == PJSIP_TSX_STATE_CALLING) { |
| 6110 |
|
| 6111 |
|
| 6112 |
pj_assert(inv->invite_tsx==NULL || tsx==inv->invite_tsx); |
| 6113 |
|
| 6114 |
|
| 6115 |
inv->invite_tsx = tsx; |
| 6116 |
|
| 6117 |
} else if (tsx->state == PJSIP_TSX_STATE_PROCEEDING) { |
| 6118 |
|
| 6119 |
|
| 6120 |
if (inv->pending_cancel) { |
| 6121 |
pj_status_t status; |
| 6122 |
pjsip_tx_data *cancel; |
| 6123 |
|
| 6124 |
inv->pending_cancel = PJ_FALSE; |
| 6125 |
|
| 6126 |
status = pjsip_inv_cancel_reinvite(inv, &cancel); |
| 6127 |
if (status == PJ_SUCCESS && cancel) |
| 6128 |
status = pjsip_inv_send_msg(inv, cancel); |
| 6129 |
} |
| 6130 |
|
| 6131 |
} else if (tsx->state == PJSIP_TSX_STATE_TERMINATED && |
| 6132 |
tsx->status_code/100 == 2) |
| 6133 |
{ |
| 6134 |
pj_status_t status; |
| 6135 |
|
| 6136 |
|
| 6137 |
|
| 6138 |
|
| 6139 |
if (!inv_check_secure_dlg(inv, e)) |
| 6140 |
return; |
| 6141 |
|
| 6142 |
|
| 6143 |
status = handle_timer_response(inv, |
| 6144 |
e->body.tsx_state.src.rdata, |
| 6145 |
PJ_TRUE); |
| 6146 |
if (status != PJ_SUCCESS) |
| 6147 |
return; |
| 6148 |
|
| 6149 |
|
| 6150 |
inv_check_sdp_in_incoming_msg(inv, tsx, |
| 6151 |
e->body.tsx_state.src.rdata); |
| 6152 |
|
| 6153 |
|
| 6154 |
if (pjmedia_sdp_neg_get_state(inv->neg)== |
| 6155 |
PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER) |
| 6156 |
{ |
| 6157 |
pjmedia_sdp_neg_cancel_offer(inv->neg); |
| 6158 |
} |
| 6159 |
|
| 6160 |
|
| 6161 |
inv_send_ack(inv, e); |
| 6162 |
|
| 6163 |
} else if (handle_uac_tsx_response(inv, e)) { |
| 6164 |
|
| 6165 |
|
| 6166 |
|
| 6167 |
|
| 6168 |
} else if (tsx->status_code >= 300 && tsx->status_code < 700 && |
| 6169 |
e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) |
| 6170 |
{ |
| 6171 |
|
| 6172 |
|
| 6173 |
|
| 6174 |
|
| 6175 |
|
| 6176 |
pjmedia_sdp_neg_state neg_state; |
| 6177 |
struct tsx_inv_data *tsx_inv_data; |
| 6178 |
|
| 6179 |
tsx_inv_data = (struct tsx_inv_data*)tsx->mod_data[mod_inv.mod.id]; |
| 6180 |
|
| 6181 |
|
| 6182 |
neg_state = pjmedia_sdp_neg_get_state(inv->neg); |
| 6183 |
if (neg_state == PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER && |
| 6184 |
tsx_inv_data->retrying == PJ_FALSE) |
| 6185 |
{ |
| 6186 |
pjmedia_sdp_neg_cancel_offer(inv->neg); |
| 6187 |
} |
| 6188 |
|
| 6189 |
if (tsx == inv->invite_tsx) |
| 6190 |
inv->invite_tsx = NULL; |
| 6191 |
|
| 6192 |
|
| 6193 |
if (tsx->status_code == 503 || tsx->status_code == 502) { |
| 6194 |
pjsip_timer_handle_refresh_error(inv, e); |
| 6195 |
} |
| 6196 |
} |
| 6197 |
|
| 6198 |
} else if (tsx->role == PJSIP_ROLE_UAS && |
| 6199 |
tsx->state == PJSIP_TSX_STATE_TRYING && |
| 6200 |
pjsip_method_cmp(&tsx->method, &pjsip_update_method)==0) |
| 6201 |
{ |
| 6202 |
|
| 6203 |
|
| 6204 |
|
| 6205 |
inv_respond_incoming_update(inv, e); |
| 6206 |
|
| 6207 |
} else if (tsx->role == PJSIP_ROLE_UAC && |
| 6208 |
(tsx->state == PJSIP_TSX_STATE_COMPLETED || |
| 6209 |
tsx->state == PJSIP_TSX_STATE_TERMINATED) && |
| 6210 |
pjsip_method_cmp(&tsx->method, &pjsip_update_method)==0) |
| 6211 |
{ |
| 6212 |
|
| 6213 |
|
| 6214 |
|
| 6215 |
if (inv_handle_update_response(inv, e) == PJ_FALSE) |
| 6216 |
handle_uac_tsx_response(inv, e); |
| 6217 |
|
| 6218 |
} else if (tsx->role == PJSIP_ROLE_UAS && |
| 6219 |
tsx->state == PJSIP_TSX_STATE_TRYING && |
| 6220 |
pjsip_method_cmp(&tsx->method, &pjsip_prack_method)==0) |
| 6221 |
{ |
| 6222 |
|
| 6223 |
|
| 6224 |
|
| 6225 |
inv_respond_incoming_prack(inv, e->body.tsx_state.src.rdata); |
| 6226 |
|
| 6227 |
} else if (tsx->role == PJSIP_ROLE_UAC) { |
| 6228 |
|
| 6229 |
|
| 6230 |
|
| 6231 |
handle_uac_tsx_response(inv, e); |
| 6232 |
} |
| 6233 |
|
| 6234 |
} |
| 6235 |
|
| 6236 |
|
| 6237 |
|
| 6238 |
|
| 6239 |
|
| 6240 |
|
| 6241 |
static void inv_on_state_disconnected( pjsip_inv_session *inv, pjsip_event *e) |
| 6242 |
{ |
| 6243 |
pjsip_transaction *tsx = e->body.tsx_state.tsx; |
| 6244 |
pjsip_dialog *dlg = pjsip_tsx_get_dlg(tsx); |
| 6245 |
|
| 6246 |
PJ_ASSERT_ON_FAIL(tsx && dlg, return); |
| 6247 |
|
| 6248 |
if (tsx->role == PJSIP_ROLE_UAS && |
| 6249 |
tsx->status_code < 200 && |
| 6250 |
e->body.tsx_state.type == PJSIP_EVENT_RX_MSG) |
| 6251 |
{ |
| 6252 |
pjsip_rx_data *rdata = e->body.tsx_state.src.rdata; |
| 6253 |
|
| 6254 |
|
| 6255 |
|
| 6256 |
|
| 6257 |
if (tsx->method.id == PJSIP_BYE_METHOD) { |
| 6258 |
inv_respond_incoming_bye( inv, tsx, rdata, e ); |
| 6259 |
} else if (tsx->method.id == PJSIP_CANCEL_METHOD) { |
| 6260 |
|
| 6261 |
|
| 6262 |
|
| 6263 |
pjsip_tx_data *tdata; |
| 6264 |
pj_status_t status; |
| 6265 |
|
| 6266 |
status = pjsip_dlg_create_response(dlg, rdata, 200, NULL, &tdata); |
| 6267 |
if (status != PJ_SUCCESS) return; |
| 6268 |
|
| 6269 |
status = pjsip_dlg_send_response(dlg, tsx, tdata); |
| 6270 |
if (status != PJ_SUCCESS) return; |
| 6271 |
|
| 6272 |
} |
| 6273 |
|
| 6274 |
} else if (tsx->role == PJSIP_ROLE_UAC) { |
| 6275 |
|
| 6276 |
|
| 6277 |
|
| 6278 |
handle_uac_tsx_response(inv, e); |
| 6279 |
} |
| 6280 |
} |
| 6281 |
|