diff options
author | Mark Michelson <mmichelson@digium.com> | 2015-01-29 20:58:12 +0000 |
---|---|---|
committer | Mark Michelson <mmichelson@digium.com> | 2015-01-29 20:58:12 +0000 |
commit | e8896ac00845850e9d88dadcd1d6dc30a476c1fc (patch) | |
tree | 92da9788c52242e8fa93c83b23b8a084ee2fe11e /res/res_pjsip.c | |
parent | 22fc3359dabe8b0f6dfaa4073a9380a9fcd31ec7 (diff) |
Use SIPS URIs in Contact headers when appropriate.
RFC 3261 sections 8.1.1.8 and 12.1.1 dictate specific
scenarios when we are required to use SIPS URIs in Contact
headers. Asterisk's non-compliance with this could actually
cause calls to get dropped when communicating with clients
that are strict about checking the Contact header.
Both of the SIP stacks in Asterisk suffered from this issue.
This changeset corrects the behavior in res_pjsip/chan_pjsip.c
Review: https://reviewboard.asterisk.org/r/4345
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@431426 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_pjsip.c')
-rw-r--r-- | res/res_pjsip.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/res/res_pjsip.c b/res/res_pjsip.c index afc383225..fd470b719 100644 --- a/res/res_pjsip.c +++ b/res/res_pjsip.c @@ -2309,6 +2309,42 @@ pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint, return dlg; } +/*! + * \brief Determine if a SIPS Contact header is required. + * + * This uses the guideline provided in RFC 3261 Section 12.1.1 to + * determine if the Contact header must be a sips: URI. + * + * \param rdata The incoming dialog-starting request + * \retval 0 SIPS not required + * \retval 1 SIPS required + */ +static int uas_use_sips_contact(pjsip_rx_data *rdata) +{ + pjsip_rr_hdr *record_route; + + if (PJSIP_URI_SCHEME_IS_SIPS(rdata->msg_info.msg->line.req.uri)) { + return 1; + } + + record_route = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_RECORD_ROUTE, NULL); + if (record_route) { + if (PJSIP_URI_SCHEME_IS_SIPS(&record_route->name_addr)) { + return 1; + } + } else { + pjsip_contact_hdr *contact; + + contact = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL); + ast_assert(contact != NULL); + if (PJSIP_URI_SCHEME_IS_SIPS(contact->uri)) { + return 1; + } + } + + return 0; +} + pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pj_status_t *status) { pjsip_dialog *dlg; @@ -2331,7 +2367,8 @@ pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint, contact.ptr = pj_pool_alloc(rdata->tp_info.pool, PJSIP_MAX_URL_SIZE); contact.slen = pj_ansi_snprintf(contact.ptr, PJSIP_MAX_URL_SIZE, - "<sip:%s%.*s%s:%d%s%s>", + "<%s:%s%.*s%s:%d%s%s>", + uas_use_sips_contact(rdata) ? "sips" : "sip", (type & PJSIP_TRANSPORT_IPV6) ? "[" : "", (int)transport->local_name.host.slen, transport->local_name.host.ptr, |