[Asterisk-code-review] res pjsip session: Add support for overlap dialling (asterisk[master])

Richard Begg asteriskteam at digium.com
Tue Mar 14 16:50:05 CDT 2017


Richard Begg has uploaded a new change for review. ( https://gerrit.asterisk.org/5202 )

Change subject: res_pjsip_session: Add support for overlap dialling
......................................................................

res_pjsip_session: Add support for overlap dialling

Support for SIP overlap dialling (i.e. 484 Response to partially matched
destinations) as currently provided by chan_sip is missing from res_pjsip.
This patch adds a new endpoint attribute (allow_overlap) [defaults to no]
which when set to yes enables 484 responses to partial destination
matches rather than the current 404.

ASTERISK-26864

Change-Id: Iea444da3ee7c7d4f1fde1d01d138a3d7b0fe40f6
---
M include/asterisk/res_pjsip.h
M res/res_pjsip.c
M res/res_pjsip/pjsip_configuration.c
M res/res_pjsip_session.c
4 files changed, 30 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/02/5202/1

diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index 09ace07..05a1fae 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -761,6 +761,8 @@
 	unsigned int preferred_codec_only;
 	/*! Do we allow an asymmetric RTP codec? */
 	unsigned int asymmetric_rtp_codec;
+	/*! Do we allow overlap dialling? */
+	unsigned int allow_overlap;
 };
 
 /*!
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index 810b6d3..9d7967b 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -100,6 +100,9 @@
 				<configOption name="allow">
 					<synopsis>Media Codec(s) to allow</synopsis>
 				</configOption>
+				<configOption name="allow_overlap" default="no">
+					<synopsis>Allow support for SIP overlap dialling</synopsis>
+				</configOption>
 				<configOption name="aors">
 					<synopsis>AoR(s) to be used with the endpoint</synopsis>
 					<description><para>
@@ -2108,6 +2111,9 @@
 				<parameter name="SubscribeContext">
 					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='subscribe_context']/synopsis/node())"/></para>
 				</parameter>
+				<parameter name="Allowoverlap">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='allow_overlap']/synopsis/node())"/></para>
+				</parameter>
 			</syntax>
 		</managerEventInstance>
 	</managerEvent>
diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c
index 1111664..9b8808b 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -1937,6 +1937,7 @@
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "contact_user", "", contact_user_handler, contact_user_to_str, NULL, 0, 0);
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "preferred_codec_only", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, preferred_codec_only));
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "asymmetric_rtp_codec", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, asymmetric_rtp_codec));
+	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "allow_overlap", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, allow_overlap));
 
 	if (ast_sip_initialize_sorcery_transport()) {
 		ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n");
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index ad9670c..3c394f3 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -2008,10 +2008,17 @@
 
 		return SIP_GET_DEST_EXTEN_FOUND;
 	}
-	/* XXX In reality, we'll likely have further options so that partial matches
-	 * can be indicated here, but for getting something up and running, we're going
-	 * to return a "not exists" error here.
-	 */
+
+	/*
+	 * Check for partial match via overlap dialling (if enabled)
+         */
+	if (session->endpoint->allow_overlap && (
+		!strncmp(session->exten, pickupexten, strlen(session->exten)) ||
+		ast_canmatch_extension(NULL, session->endpoint->context, session->exten, 1, NULL))) {
+		/* Overlap partial match */
+		return SIP_GET_DEST_EXTEN_PARTIAL;
+	}
+
 	return SIP_GET_DEST_EXTEN_NOT_FOUND;
 }
 
@@ -2128,8 +2135,17 @@
 			pjsip_inv_terminate(invite->session->inv_session, 416, PJ_TRUE);
 		}
 		goto end;
-	case SIP_GET_DEST_EXTEN_NOT_FOUND:
 	case SIP_GET_DEST_EXTEN_PARTIAL:
+		ast_debug(1, "Call from '%s' (%s:%s:%d) to extension '%s' - partial match\n", ast_sorcery_object_get_id(invite->session->endpoint),
+			invite->rdata->tp_info.transport->type_name, invite->rdata->pkt_info.src_name, invite->rdata->pkt_info.src_port, invite->session->exten);
+
+		if (pjsip_inv_initial_answer(invite->session->inv_session, invite->rdata, 484, NULL, NULL, &tdata) == PJ_SUCCESS) {
+			ast_sip_session_send_response(invite->session, tdata);
+		} else  {
+			pjsip_inv_terminate(invite->session->inv_session, 484, PJ_TRUE);
+		}
+		goto end;
+	case SIP_GET_DEST_EXTEN_NOT_FOUND:
 	default:
 		ast_log(LOG_NOTICE, "Call from '%s' (%s:%s:%d) to extension '%s' rejected because extension not found in context '%s'.\n",
 			ast_sorcery_object_get_id(invite->session->endpoint), invite->rdata->tp_info.transport->type_name, invite->rdata->pkt_info.src_name,

-- 
To view, visit https://gerrit.asterisk.org/5202
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iea444da3ee7c7d4f1fde1d01d138a3d7b0fe40f6
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Richard Begg <asterisk at meric.id.au>



More information about the asterisk-code-review mailing list