[Asterisk-code-review] res_pjsip: Add 100rel option "use_if_supported" (asterisk[16])

Maximilian Fridrich asteriskteam at digium.com
Tue Jul 26 08:44:31 CDT 2022


Maximilian Fridrich has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/18838 )


Change subject: res_pjsip: Add 100rel option "use_if_supported"
......................................................................

res_pjsip: Add 100rel option "use_if_supported"

This patch adds a new option to the 100rel parameter for pjsip
endpoints called "use_if_supported". When an endpoint with this option
receives an incoming request and the request indicated support for the
100rel extension, then Asterisk will send 1xx responses reliably. If
the request did not indicate 100rel support, Asterisk sends 1xx
responses normally.

ASTERISK-30158

Change-Id: Id6d95ffa8f00dab118e0b386146e99f254f287ad
---
M include/asterisk/res_pjsip.h
M res/res_pjsip/pjsip_config.xml
M res/res_pjsip/pjsip_configuration.c
M res/res_pjsip_session.c
4 files changed, 39 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/38/18838/1

diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index 1714cff..0325dfd 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -413,6 +413,20 @@
 };
 
 /*!
+ * \brief 100rel modes for SIP endpoints
+ */
+enum ast_sip_100rel_mode {
+	/*! Do not support 100rel */
+	AST_SIP_100REL_UNSUPPORTED = 0,
+	/*! Indicate 100rel support in Supported header */
+	AST_SIP_100REL_SUPPORTED,
+	/*! As UAS, send 1xx responses reliable, if the UAC indicated its support. Otherwise same as AST_SIP_100REL_SUPPORTED. */
+	AST_SIP_100REL_USE_IF_SUPPORTED,
+	/*! Require the use 100rel */
+	AST_SIP_100REL_REQUIRED,
+};
+
+/*!
  * \brief DTMF modes for SIP endpoints
  */
 enum ast_sip_dtmf_mode {
@@ -878,6 +892,8 @@
 	unsigned int trust_connected_line;
 	/*! Do we send connected line updates to this endpoint? */
 	unsigned int send_connected_line;
+	/*! 100rel mode to use with this endpoint */
+	enum ast_sip_100rel_mode rel100;
 	/*! Ignore 183 if no SDP is present */
 	unsigned int ignore_183_without_sdp;
 	/*! Set which STIR/SHAKEN behaviors we want on this endpoint */
diff --git a/res/res_pjsip/pjsip_config.xml b/res/res_pjsip/pjsip_config.xml
index e9abc86..b8f33c8 100644
--- a/res/res_pjsip/pjsip_config.xml
+++ b/res/res_pjsip/pjsip_config.xml
@@ -34,6 +34,7 @@
 						<enumlist>
 							<enum name="no" />
 							<enum name="required" />
+							<enum name="use_if_supported" />
 							<enum name="yes" />
 						</enumlist>
 					</description>
diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c
index b514cea..cab4b87 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -182,9 +182,16 @@
 
 	if (ast_true(var->value)) {
 		endpoint->extensions.flags |= PJSIP_INV_SUPPORT_100REL;
+		endpoint->rel100 = AST_SIP_100REL_SUPPORTED;
+	} else if (!strcasecmp(var->value, "use_if_supported")) {
+		endpoint->extensions.flags |= PJSIP_INV_SUPPORT_100REL;
+		endpoint->rel100 = AST_SIP_100REL_USE_IF_SUPPORTED;
 	} else if (!strcasecmp(var->value, "required")) {
 		endpoint->extensions.flags |= PJSIP_INV_REQUIRE_100REL;
-	} else if (!ast_false(var->value)){
+		endpoint->rel100 = AST_SIP_100REL_REQUIRED;
+	} else if (ast_false(var->value)){
+		endpoint->rel100 = AST_SIP_100REL_UNSUPPORTED;
+	} else {
 		return -1;
 	}
 
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 3c55af7..3ff3000 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -3797,8 +3797,22 @@
 	pjsip_dialog *dlg;
 	pjsip_inv_session *inv_session;
 	unsigned int options = endpoint->extensions.flags;
+	const pj_str_t STR_100REL = { "100rel", 6};
+	unsigned int peer_100rel = 0;
+	unsigned int i;
 	pj_status_t dlg_status = PJ_EUNKNOWN;
 
+	for (i = 0; i < rdata->msg_info.supported->count; ++i) {
+	    if (pj_stricmp(&rdata->msg_info.supported->values[i], &STR_100REL) == 0) {
+		peer_100rel = 1;
+		break;
+	    }
+	}
+
+	if (peer_100rel && endpoint->rel100 == AST_SIP_100REL_USE_IF_SUPPORTED) {
+		options |= PJSIP_INV_REQUIRE_100REL;
+	}
+
 	if (pjsip_inv_verify_request(rdata, &options, NULL, NULL, ast_sip_get_pjsip_endpoint(), &tdata) != PJ_SUCCESS) {
 		if (tdata) {
 			if (pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL) != PJ_SUCCESS) {

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/18838
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Id6d95ffa8f00dab118e0b386146e99f254f287ad
Gerrit-Change-Number: 18838
Gerrit-PatchSet: 1
Gerrit-Owner: Maximilian Fridrich <m.fridrich at commend.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220726/3369e75b/attachment.html>


More information about the asterisk-code-review mailing list