From 483805f79570115ab95c69698792d238c1719b1b Mon Sep 17 00:00:00 2001 From: Jason Parker Date: Mon, 11 Mar 2013 15:09:56 -0500 Subject: Import pjproject-2.1 --- pjsip/src/pjsip-ua/sip_100rel.c | 6 +-- pjsip/src/pjsip-ua/sip_inv.c | 100 +++++++++++++++++++++++++++++++------- pjsip/src/pjsip-ua/sip_reg.c | 11 +++-- pjsip/src/pjsip-ua/sip_replaces.c | 19 ++++++-- pjsip/src/pjsip-ua/sip_timer.c | 29 ++++++++++- 5 files changed, 135 insertions(+), 30 deletions(-) (limited to 'pjsip/src/pjsip-ua') diff --git a/pjsip/src/pjsip-ua/sip_100rel.c b/pjsip/src/pjsip-ua/sip_100rel.c index 07122c4..f64ef19 100644 --- a/pjsip/src/pjsip-ua/sip_100rel.c +++ b/pjsip/src/pjsip-ua/sip_100rel.c @@ -1,4 +1,4 @@ -/* $Id: sip_100rel.c 3841 2011-10-24 09:28:13Z ming $ */ +/* $Id: sip_100rel.c 4208 2012-07-18 07:52:33Z ming $ */ /* * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) * Copyright (C) 2003-2008 Benny Prijono @@ -273,7 +273,7 @@ PJ_DEF(pj_status_t) pjsip_100rel_create_prack( pjsip_inv_session *inv, /* Find UAC state for the specified call leg */ uac_state = dd->uac_state_list; while (uac_state) { - if (pj_strcmp(&uac_state->tag, to_tag)==0) + if (pj_stricmp(&uac_state->tag, to_tag)==0) break; uac_state = uac_state->next; } @@ -320,7 +320,7 @@ PJ_DEF(pj_status_t) pjsip_100rel_create_prack( pjsip_inv_session *inv, /* If this response is a forked response from a different call-leg, * update the req URI (https://trac.pjsip.org/repos/ticket/1364) */ - if (pj_strcmp(&uac_state->tag, &dd->inv->dlg->remote.info->tag)) { + if (pj_stricmp(&uac_state->tag, &dd->inv->dlg->remote.info->tag)) { const pjsip_contact_hdr *mhdr; mhdr = (const pjsip_contact_hdr*) diff --git a/pjsip/src/pjsip-ua/sip_inv.c b/pjsip/src/pjsip-ua/sip_inv.c index 8db5308..dec4ee5 100644 --- a/pjsip/src/pjsip-ua/sip_inv.c +++ b/pjsip/src/pjsip-ua/sip_inv.c @@ -1,4 +1,4 @@ -/* $Id: sip_inv.c 4156 2012-06-06 07:24:08Z bennylp $ */ +/* $Id: sip_inv.c 4367 2013-02-21 20:49:19Z nanang $ */ /* * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) * Copyright (C) 2003-2008 Benny Prijono @@ -829,7 +829,7 @@ PJ_DEF(pjsip_rdata_sdp_info*) pjsip_rdata_get_sdp_info(pjsip_rx_data *rdata) sdp_info->body.slen, &sdp_info->sdp); if (status == PJ_SUCCESS) - status = pjmedia_sdp_validate(sdp_info->sdp); + status = pjmedia_sdp_validate2(sdp_info->sdp, PJ_FALSE); if (status != PJ_SUCCESS) { sdp_info->sdp = NULL; @@ -1745,7 +1745,7 @@ static pj_status_t inv_check_sdp_in_incoming_msg( pjsip_inv_session *inv, if (tsx->role == PJSIP_ROLE_UAC && rdata->msg_info.msg->line.status.code/100 == 2 && tsx_inv_data->done_early && - pj_strcmp(&tsx_inv_data->done_tag, &res_tag)) + pj_stricmp(&tsx_inv_data->done_tag, &res_tag)) { const pjmedia_sdp_session *reoffer_sdp = NULL; @@ -2329,6 +2329,7 @@ static pj_bool_t inv_uac_recurse(pjsip_inv_session *inv, int code, /* Check what the application wants to do now */ switch (op) { case PJSIP_REDIRECT_ACCEPT: + case PJSIP_REDIRECT_ACCEPT_REPLACE: case PJSIP_REDIRECT_STOP: /* Must increment session counter, that's the convention of the * pjsip_inv_process_redirect(). @@ -2394,6 +2395,7 @@ PJ_DEF(pj_status_t) pjsip_inv_process_redirect( pjsip_inv_session *inv, /* See what the application wants to do now */ switch (op) { case PJSIP_REDIRECT_ACCEPT: + case PJSIP_REDIRECT_ACCEPT_REPLACE: /* User accept the redirection. Reset the session and resend the * INVITE request. */ @@ -2419,6 +2421,51 @@ PJ_DEF(pj_status_t) pjsip_inv_process_redirect( pjsip_inv_session *inv, pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL); via->branch_param.slen = 0; + /* Process PJSIP_REDIRECT_ACCEPT_REPLACE */ + if (op == PJSIP_REDIRECT_ACCEPT_REPLACE) { + pjsip_to_hdr *to; + pjsip_dialog *dlg = inv->dlg; + enum { TMP_LEN = 128 }; + char tmp[TMP_LEN]; + int len; + + /* Replace To header */ + to = PJSIP_MSG_TO_HDR(tdata->msg); + to->uri = (pjsip_uri*) + pjsip_uri_clone(tdata->pool, + dlg->target_set.current->uri); + to->tag.slen = 0; + pj_list_init(&to->other_param); + + /* Re-init dialog remote info */ + dlg->remote.info = (pjsip_to_hdr*) + pjsip_hdr_clone(dlg->pool, to); + + /* Remove header param from remote info */ + if (PJSIP_URI_SCHEME_IS_SIP(dlg->remote.info->uri) || + PJSIP_URI_SCHEME_IS_SIPS(dlg->remote.info->uri)) + { + pjsip_sip_uri *sip_uri = (pjsip_sip_uri *) + pjsip_uri_get_uri(dlg->remote.info->uri); + if (!pj_list_empty(&sip_uri->header_param)) { + /* Remove all header param */ + pj_list_init(&sip_uri->header_param); + } + } + + /* Print the remote info. */ + len = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, + dlg->remote.info->uri, tmp, TMP_LEN); + if (len < 1) { + pj_ansi_strcpy(tmp, "<-error: uri too long->"); + len = pj_ansi_strlen(tmp); + } + pj_strdup2_with_null(dlg->pool, &dlg->remote.info_str, tmp); + + /* Secure? */ + dlg->secure = PJSIP_URI_SCHEME_IS_SIPS(to->uri); + } + /* Reset message destination info (see #1248). */ pj_bzero(&tdata->dest_info, sizeof(tdata->dest_info)); @@ -2572,6 +2619,7 @@ PJ_DEF(pj_status_t) pjsip_inv_update ( pjsip_inv_session *inv, pjsip_contact_hdr *contact_hdr = NULL; pjsip_tx_data *tdata = NULL; pjmedia_sdp_session *sdp_copy; + const pjsip_hdr *hdr; pj_status_t status = PJ_SUCCESS; /* Verify arguments. */ @@ -2640,13 +2688,24 @@ PJ_DEF(pj_status_t) pjsip_inv_update ( pjsip_inv_session *inv, pjsip_create_sdp_body(tdata->pool, sdp_copy, &tdata->msg->body); } - /* Unlock dialog. */ - pjsip_dlg_dec_lock(inv->dlg); + /* Session Timers spec (RFC 4028) says that Supported header MUST be put + * in refresh requests. So here we'll just put the Supported header in + * all cases regardless of whether session timers is used or not, just + * in case this is a common behavior. + */ + hdr = pjsip_endpt_get_capability(inv->dlg->endpt, PJSIP_H_SUPPORTED, NULL); + if (hdr) { + pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*) + pjsip_hdr_shallow_clone(tdata->pool, hdr)); + } status = pjsip_timer_update_req(inv, tdata); if (status != PJ_SUCCESS) goto on_error; + /* Unlock dialog. */ + pjsip_dlg_dec_lock(inv->dlg); + *p_tdata = tdata; pj_log_pop_indent(); @@ -2957,8 +3016,16 @@ static void inv_respond_incoming_update(pjsip_inv_session *inv, neg_state = pjmedia_sdp_neg_get_state(inv->neg); + /* If UPDATE doesn't contain SDP, just respond with 200/OK. + * This is a valid scenario according to session-timer draft. + */ + if (rdata->msg_info.msg->body == NULL) { + + status = pjsip_dlg_create_response(inv->dlg, rdata, + 200, NULL, &tdata); + } /* Send 491 if we receive UPDATE while we're waiting for an answer */ - if (neg_state == PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER) { + else if (neg_state == PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER) { status = pjsip_dlg_create_response(inv->dlg, rdata, PJSIP_SC_REQUEST_PENDING, NULL, &tdata); @@ -2967,18 +3034,18 @@ static void inv_respond_incoming_update(pjsip_inv_session *inv, * receive UPDATE while we haven't sent answer. */ else if (neg_state == PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER || - neg_state == PJMEDIA_SDP_NEG_STATE_WAIT_NEGO) { - status = pjsip_dlg_create_response(inv->dlg, rdata, + neg_state == PJMEDIA_SDP_NEG_STATE_WAIT_NEGO) + { + pjsip_retry_after_hdr *ra_hdr; + int val; + + status = pjsip_dlg_create_response(inv->dlg, rdata, PJSIP_SC_INTERNAL_SERVER_ERROR, NULL, &tdata); - /* If UPDATE doesn't contain SDP, just respond with 200/OK. - * This is a valid scenario according to session-timer draft. - */ - } else if (rdata->msg_info.msg->body == NULL) { - - status = pjsip_dlg_create_response(inv->dlg, rdata, - 200, NULL, &tdata); + val = (pj_rand() % 10); + ra_hdr = pjsip_retry_after_hdr_create(tdata->pool, val); + pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)ra_hdr); } else { /* We receive new offer from remote */ @@ -3305,8 +3372,7 @@ static pj_bool_t handle_uac_tsx_response(pjsip_inv_session *inv, ((tsx->status_code == PJSIP_SC_CALL_TSX_DOES_NOT_EXIST && tsx->method.id != PJSIP_CANCEL_METHOD) || tsx->status_code == PJSIP_SC_REQUEST_TIMEOUT || - tsx->status_code == PJSIP_SC_TSX_TIMEOUT || - tsx->status_code == PJSIP_SC_TSX_TRANSPORT_ERROR)) + tsx->status_code == PJSIP_SC_TSX_TIMEOUT)) { pjsip_tx_data *bye; pj_status_t status; diff --git a/pjsip/src/pjsip-ua/sip_reg.c b/pjsip/src/pjsip-ua/sip_reg.c index bd1fb21..b76a1f6 100644 --- a/pjsip/src/pjsip-ua/sip_reg.c +++ b/pjsip/src/pjsip-ua/sip_reg.c @@ -1,4 +1,4 @@ -/* $Id: sip_reg.c 4173 2012-06-20 10:39:05Z ming $ */ +/* $Id: sip_reg.c 4319 2013-01-16 10:20:55Z bennylp $ */ /* * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) * Copyright (C) 2003-2008 Benny Prijono @@ -336,7 +336,7 @@ PJ_DEF(pj_status_t) pjsip_regc_init( pjsip_regc *regc, pj_status_t status; PJ_ASSERT_RETURN(regc && srv_url && from_url && to_url && - contact_cnt && contact && expires, PJ_EINVAL); + expires, PJ_EINVAL); /* Copy server URL. */ pj_strdup_with_null(regc->pool, ®c->str_srv_url, srv_url); @@ -818,8 +818,11 @@ PJ_DEF(pj_status_t) pjsip_regc_set_via_sent_by( pjsip_regc *regc, if (!via_addr) pj_bzero(®c->via_addr, sizeof(regc->via_addr)); - else - regc->via_addr = *via_addr; + else { + if (pj_strcmp(®c->via_addr.host, &via_addr->host)) + pj_strdup(regc->pool, ®c->via_addr.host, &via_addr->host); + regc->via_addr.port = via_addr->port; + } regc->via_tp = via_tp; return PJ_SUCCESS; diff --git a/pjsip/src/pjsip-ua/sip_replaces.c b/pjsip/src/pjsip-ua/sip_replaces.c index b961cf9..a37546f 100644 --- a/pjsip/src/pjsip-ua/sip_replaces.c +++ b/pjsip/src/pjsip-ua/sip_replaces.c @@ -1,4 +1,4 @@ -/* $Id: sip_replaces.c 3999 2012-03-30 07:10:13Z bennylp $ */ +/* $Id: sip_replaces.c 4268 2012-09-28 08:56:08Z nanang $ */ /* * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) * Copyright (C) 2003-2008 Benny Prijono @@ -305,10 +305,19 @@ PJ_DEF(pj_status_t) pjsip_replaces_verify_request( pjsip_rx_data *rdata, * initiated by this UA, it returns a 481 (Call/Transaction Does Not * Exist) response to the new INVITE. */ - if (inv->state <= PJSIP_INV_STATE_EARLY && inv->role != PJSIP_ROLE_UAC) { - code = PJSIP_SC_CALL_TSX_DOES_NOT_EXIST; - warn_text = "Found early INVITE session but not initiated by this UA"; - goto on_return; + if (inv->state <= PJSIP_INV_STATE_EARLY && inv->role != PJSIP_ROLE_UAC) + { + /* Really return 481 only if call haven't reached early state or + * accept-replace-in-early-state (ticket #1587) is not allowed. + */ + if (inv->state != PJSIP_INV_STATE_EARLY || + pjsip_cfg()->endpt.accept_replace_in_early_state == PJ_FALSE) + { + code = PJSIP_SC_CALL_TSX_DOES_NOT_EXIST; + warn_text = "Found early INVITE session but not initiated by " + "this UA"; + goto on_return; + } } diff --git a/pjsip/src/pjsip-ua/sip_timer.c b/pjsip/src/pjsip-ua/sip_timer.c index 2c70791..a48c71d 100644 --- a/pjsip/src/pjsip-ua/sip_timer.c +++ b/pjsip/src/pjsip-ua/sip_timer.c @@ -1,4 +1,4 @@ -/* $Id: sip_timer.c 3999 2012-03-30 07:10:13Z bennylp $ */ +/* $Id: sip_timer.c 4213 2012-07-23 13:31:26Z nanang $ */ /* * Copyright (C) 2009-2011 Teluu Inc. (http://www.teluu.com) * @@ -1030,6 +1030,33 @@ PJ_DEF(pj_status_t) pjsip_timer_update_resp(pjsip_inv_session *inv, if (inv->timer && inv->timer->active) { /* Add Session-Expires header and start the timer */ add_timer_headers(inv, tdata, PJ_TRUE, PJ_FALSE); + + /* Add 'timer' to Require header (see ticket #1560). */ + if (inv->timer->refresher == TR_UAC) { + pjsip_require_hdr *req_hdr; + pj_bool_t req_hdr_has_timer = PJ_FALSE; + + req_hdr = (pjsip_require_hdr*) + pjsip_msg_find_hdr(tdata->msg, PJSIP_H_REQUIRE, + NULL); + if (req_hdr == NULL) { + req_hdr = pjsip_require_hdr_create(tdata->pool); + PJ_ASSERT_RETURN(req_hdr, PJ_ENOMEM); + pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)req_hdr); + } else { + unsigned i; + for (i = 0; i < req_hdr->count; ++i) { + if (pj_stricmp(&req_hdr->values[i], &STR_TIMER)) { + req_hdr_has_timer = PJ_TRUE; + break; + } + } + } + if (!req_hdr_has_timer) + req_hdr->values[req_hdr->count++] = STR_TIMER; + } + + /* Finally, start timer. */ start_timer(inv); } } -- cgit v1.2.3