[asterisk-commits] chan sip: Optionally supply fromuser/fromdomain in SIP dial ... (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Feb 25 17:56:43 CST 2016


Anonymous Coward #1000019 has submitted this change and it was merged.

Change subject: chan_sip: Optionally supply fromuser/fromdomain in SIP dial string.
......................................................................


chan_sip: Optionally supply fromuser/fromdomain in SIP dial string.

Previously you could add [!dnid] to the SIP dial string to alter the To:
header. This change allows you to alter the From header as well.

SIP dial string extra options now look like this:

    [![touser[@todomain]][![fromuser][@fromdomain]]]

INCOMPATIBLE CHANGE: If you were using an exclamation mark in your To:
header, that is no longer possible.

ASTERISK-25803 #close

Change-Id: I2457e9ba7a89eb1da22084bab5a4d4328e189db7
---
M CHANGES
M UPGRADE.txt
M channels/chan_sip.c
M configs/samples/sip.conf.sample
4 files changed, 63 insertions(+), 3 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Mark Michelson: Looks good to me, approved
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/CHANGES b/CHANGES
index 5e4c428..002ddb7 100644
--- a/CHANGES
+++ b/CHANGES
@@ -81,6 +81,11 @@
  * DTLS related configuration options can now be set at a general level.
    Enabling DTLS support, though, requires enabling it at the user
    or peer level.
+ * Added the possibility to set the From: header through the the SIP dial
+   string (populating the fromuser/fromdomain fields), complementing the
+   [!dnid] option for the To: header that has existed since 1.6.0 (1d6b192).
+   NOTE: This is again separated by an exclamation mark, so the To: header may
+   not contain one of those.
 
 chan_pjsip
 ------------------
diff --git a/UPGRADE.txt b/UPGRADE.txt
index 6fb82c4..131ce6c 100644
--- a/UPGRADE.txt
+++ b/UPGRADE.txt
@@ -31,6 +31,11 @@
    ring-ring-ring pattern would exceed the pattern limits and stop
    Caller-ID detection.
 
+chan_sip:
+ - The SIP dial string has been extended past the [!dnid] option by another
+   exclamation mark: [!dnid[!fromuri].  An exclamation mark in the To-URI
+   will now mean changes to the From-URI.
+
 Core:
  - The REF_DEBUG compiler flag is now used to enable refdebug by default.
    The setting can be overridden in asterisk.conf by setting refdebug in
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index aaf0b6d..2e9a6d1 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -29680,7 +29680,8 @@
  *	or	SIP/devicename/extension/IPorHost
  *	or	SIP/username at domain//IPorHost
  *	and there is an optional [!dnid] argument you can append to alter the
- *	To: header.
+ *	To: header. And after that, a [![fromuser][@fromdomain]] argument.
+ *	Leave those blank to use the defaults.
  * \endverbatim
  */
 static struct ast_channel *sip_request_call(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *dest, int *cause)
@@ -29752,11 +29753,49 @@
 	/* Save the destination, the SIP dial string */
 	ast_copy_string(tmp, dest, sizeof(tmp));
 
-	/* Find DNID and take it away */
+	/* Find optional DNID (SIP to-uri) and From-CLI (SIP from-uri)
+	 * and strip it from the dial string:
+	 *   [!touser[@todomain][![fromuser][@fromdomain]]]
+	 * For historical reasons, the touser at todomain is passed as dnid
+	 * while fromuser at fromdomain are split immediately. Passing a
+	 * todomain without touser will create an invalid SIP message. */
 	dnid = strchr(tmp, '!');
 	if (dnid != NULL) {
+		char *fromuser_and_domain;
+
 		*dnid++ = '\0';
-		ast_string_field_set(p, todnid, dnid);
+		if ((fromuser_and_domain = strchr(dnid, '!'))) {
+			char *forward_compat;
+			char *fromdomain;
+
+			*fromuser_and_domain++ = '\0';
+
+			/* Cut it at a trailing NUL or trailing '!' for
+			 * forward compatibility with extra arguments
+			 * in the future. */
+			if ((forward_compat = strchr(fromuser_and_domain, '!'))) {
+				/* Ignore the rest.. */
+				*forward_compat = '\0';
+			}
+
+			if ((fromdomain = strchr(fromuser_and_domain, '@'))) {
+				*fromdomain++ = '\0';
+				/* Set fromdomain. */
+				if (!ast_strlen_zero(fromdomain)) {
+					ast_string_field_set(p, fromdomain, fromdomain);
+				}
+			}
+
+			/* Set fromuser. */
+			if (!ast_strlen_zero(fromuser_and_domain)) {
+				ast_string_field_set(p, fromuser, fromuser_and_domain);
+			}
+		}
+
+		/* Set DNID (touser/todomain). */
+		if (!ast_strlen_zero(dnid)) {
+			ast_string_field_set(p, todnid, dnid);
+		}
 	}
 
 	/* Divvy up the items separated by slashes */
diff --git a/configs/samples/sip.conf.sample b/configs/samples/sip.conf.sample
index fe68514..d89a2a1 100644
--- a/configs/samples/sip.conf.sample
+++ b/configs/samples/sip.conf.sample
@@ -24,6 +24,9 @@
 ;        SIP/devicename/extension
 ;        SIP/devicename/extension/IPorHost
 ;        SIP/username at domain//IPorHost
+; And to alter the To: or the From: header, you can additionally append
+; the following to any of the above strings:
+;        [![touser[@todomain]][![fromuser][@fromdomain]]]
 ;
 ;
 ; Devicename
@@ -57,6 +60,14 @@
 ;
 ;         SIP/sales at mysipproxy!sales at edvina.net
 ;
+; (Specifying only @todomain without touser will create an invalid SIP
+; request.)
+;
+; Similarly, you can specify the From header as well, after a second
+; exclamation mark:
+;
+;         SIP/customer at mysipproxy!!customersupport at wearespindle.com
+;
 ; A new feature for 1.8 allows one to specify a host or IP address to use
 ; when routing the call. This is typically used in tandem with func_srv if
 ; multiple methods of reaching the same domain exist. The host or IP address

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I2457e9ba7a89eb1da22084bab5a4d4328e189db7
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Walter Doekes <walter+asterisk at wjd.nu>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-commits mailing list