[svn-commits] mmichelson: branch 13 r431426 - /branches/13/res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jan 29 14:58:18 CST 2015


Author: mmichelson
Date: Thu Jan 29 14:58:12 2015
New Revision: 431426

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=431426
Log:
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


Added:
    branches/13/res/res_pjsip_sips_contact.c   (with props)
Modified:
    branches/13/res/res_pjsip.c

Modified: branches/13/res/res_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/res/res_pjsip.c?view=diff&rev=431426&r1=431425&r2=431426
==============================================================================
--- branches/13/res/res_pjsip.c (original)
+++ branches/13/res/res_pjsip.c Thu Jan 29 14:58:12 2015
@@ -2309,6 +2309,42 @@
 	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 @@
 
 	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,

Added: branches/13/res/res_pjsip_sips_contact.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/res/res_pjsip_sips_contact.c?view=auto&rev=431426
==============================================================================
--- branches/13/res/res_pjsip_sips_contact.c (added)
+++ branches/13/res/res_pjsip_sips_contact.c Thu Jan 29 14:58:12 2015
@@ -1,0 +1,107 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2015, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*** MODULEINFO
+	<depend>pjproject</depend>
+	<depend>res_pjsip</depend>
+	<support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+#include <pjsip.h>
+
+#include "asterisk/res_pjsip.h"
+#include "asterisk/module.h"
+
+/*!
+ * \brief Upgrade Contact URIs on outgoing SIP requests to SIPS if required.
+ *
+ * The rules being used here are according to RFC 3261 section 8.1.1.8. In
+ * brief, if the request URI is SIPS or the topmost Route header is SIPS,
+ * then the Contact header we send must also be SIPS.
+ */
+static pj_status_t sips_contact_on_tx_request(pjsip_tx_data *tdata)
+{
+	pjsip_contact_hdr *contact;
+	pjsip_route_hdr *route;
+	pjsip_sip_uri *contact_uri;
+
+	contact = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL);
+	if (!contact) {
+		return PJ_SUCCESS;
+	}
+
+	contact_uri = pjsip_uri_get_uri(contact->uri);
+	if (PJSIP_URI_SCHEME_IS_SIPS(contact_uri)) {
+		/* If the Contact header is already SIPS, then we don't need to do anything */
+		return PJ_SUCCESS;
+	}
+
+	if (PJSIP_URI_SCHEME_IS_SIPS(tdata->msg->line.req.uri)) {
+		ast_debug(1, "Upgrading contact URI on outgoing SIP request to SIPS due to SIPS Request URI\n");
+		pjsip_sip_uri_set_secure(contact_uri, PJ_TRUE);
+		return PJ_SUCCESS;
+	}
+
+	route = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ROUTE, NULL);
+	if (!route) {
+		return PJ_SUCCESS;
+	}
+
+	if (!PJSIP_URI_SCHEME_IS_SIPS(&route->name_addr)) {
+		return PJ_SUCCESS;
+	}
+
+	/* Our Contact header is not a SIPS URI, but our topmost Route header is. */
+	ast_debug(1, "Upgrading contact URI on outgoing SIP request to SIPS due to SIPS Route header\n");
+	pjsip_sip_uri_set_secure(contact_uri, PJ_TRUE);
+
+	return PJ_SUCCESS;
+}
+
+static pjsip_module sips_contact_module = {
+	.name = {"SIPS Contact", 12 },
+	.id = -1,
+	.priority = PJSIP_MOD_PRIORITY_TSX_LAYER - 2,
+	.on_tx_request = sips_contact_on_tx_request,
+};
+
+static int unload_module(void)
+{
+	ast_sip_unregister_service(&sips_contact_module);
+	return 0;
+}
+
+static int load_module(void)
+{
+	CHECK_PJSIP_MODULE_LOADED();
+
+	if (ast_sip_register_service(&sips_contact_module)) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "UAC SIPS Contact support",
+		.support_level = AST_MODULE_SUPPORT_CORE,
+		.load = load_module,
+		.unload = unload_module,
+		.load_pri = AST_MODPRI_APP_DEPEND,
+	       );

Propchange: branches/13/res/res_pjsip_sips_contact.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: branches/13/res/res_pjsip_sips_contact.c
------------------------------------------------------------------------------
    svn:keywords = 'Author Date Id Revision'

Propchange: branches/13/res/res_pjsip_sips_contact.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the svn-commits mailing list