[Asterisk-code-review] chan_pjsip: Assign SIPDOMAIN after creating a channel (asterisk[master])

Ivan Poddubny asteriskteam at digium.com
Sun Jan 10 11:59:45 CST 2021


Ivan Poddubny has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/15342 )


Change subject: chan_pjsip: Assign SIPDOMAIN after creating a channel
......................................................................

chan_pjsip: Assign SIPDOMAIN after creating a channel

session->channel doesn't exist until chan_pjsip creates it, so intead of
setting a channel variable every new incoming call sets one and the same
global variable.

This patch moves the code to chan_pjsip so that SIPDOMAIN is set on
a newly created channel, it also removes a misleading reference to
channel->session used to fetch call pickup configuraion.

ASTERISK-29240

Change-Id: I90c9bbbed01f5d8863585631a29322ae4e046755
---
M channels/chan_pjsip.c
M res/res_pjsip_session.c
2 files changed, 16 insertions(+), 7 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/42/15342/1

diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index bb04d73..d91fe42 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -2978,6 +2978,18 @@
 	SCOPE_EXIT_RTN();
 }
 
+static void set_sipdomain_variable(struct ast_sip_session *session)
+{
+	pjsip_sip_uri *sip_ruri = pjsip_uri_get_uri(session->request_uri);
+	size_t size = pj_strlen(&sip_ruri->host) + 1;
+	char *domain = ast_alloca(size);
+
+	ast_copy_pj_str(domain, &sip_ruri->host, size);
+
+	pbx_builtin_setvar_helper(session->channel, "SIPDOMAIN", domain);
+	return;
+}
+
 /*! \brief Function called when a request is received on the session */
 static int chan_pjsip_incoming_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
 {
@@ -3029,6 +3041,9 @@
 		SCOPE_EXIT_LOG_RTN_VALUE(-1, LOG_ERROR, "%s: Failed to allocate new PJSIP channel on incoming SIP INVITE\n",
 			 ast_sip_session_get_name(session));
 	}
+
+	set_sipdomain_variable(session);
+
 	/* channel gets created on incoming request, but we wait to call start
            so other supplements have a chance to run */
 	SCOPE_EXIT_RTN_VALUE(0, "%s\n", ast_sip_session_get_name(session));
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 82ef2aa..b09e513 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -3733,7 +3733,7 @@
 	 */
 	AST_SIP_USER_OPTIONS_TRUNCATE_CHECK(session->exten);
 
-	pickup_cfg = ast_get_chan_features_pickup_config(session->channel);
+	pickup_cfg = ast_get_chan_features_pickup_config(NULL); /* session->channel doesn't exist yet, using NULL */
 	if (!pickup_cfg) {
 		ast_log(LOG_ERROR, "%s: Unable to retrieve pickup configuration options. Unable to detect call pickup extension\n",
 			ast_sip_session_get_name(session));
@@ -3745,12 +3745,6 @@
 
 	if (!strcmp(session->exten, pickupexten) ||
 		ast_exists_extension(NULL, session->endpoint->context, session->exten, 1, NULL)) {
-		size_t size = pj_strlen(&sip_ruri->host) + 1;
-		char *domain = ast_alloca(size);
-
-		ast_copy_pj_str(domain, &sip_ruri->host, size);
-		pbx_builtin_setvar_helper(session->channel, "SIPDOMAIN", domain);
-
 		/*
 		 * Save off the INVITE Request-URI in case it is
 		 * needed: CHANNEL(pjsip,request_uri)

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I90c9bbbed01f5d8863585631a29322ae4e046755
Gerrit-Change-Number: 15342
Gerrit-PatchSet: 1
Gerrit-Owner: Ivan Poddubny <ivan.poddubny at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210110/de3b3767/attachment.html>


More information about the asterisk-code-review mailing list