[asterisk-commits] mmichelson: trunk r168575 - in /trunk: ./ channels/ configs/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 13 15:18:13 CST 2009


Author: mmichelson
Date: Tue Jan 13 15:18:13 2009
New Revision: 168575

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=168575
Log:
Allow specifying a port number in the user portion of a register => line in sip.conf

With this commit, a register => line in sip.conf may contain a port number in the
"user" section of the line. Please see CHANGES and sip.conf.sample for more
details regarding this.

(closes issue #14198)
Reported by: Nick_Lewis
Patches:
      chan_sip.c-domainport2.patch uploaded by Nick (license 657)
Tested by: Nick_Lewis


Modified:
    trunk/CHANGES
    trunk/channels/chan_sip.c
    trunk/configs/sip.conf.sample

Modified: trunk/CHANGES
URL: http://svn.digium.com/svn-view/asterisk/trunk/CHANGES?view=diff&rev=168575&r1=168574&r2=168575
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Tue Jan 13 15:18:13 2009
@@ -41,6 +41,9 @@
    option is required to interoperate with devices that have non-standard SDP
    session version implementations (observed with Microsoft OCS).  This option
    is diabled by default.
+ * The parsing of register => lines in sip.conf has been modified to allow a port
+   to be present in the "user" portion. Please see the sip.conf.sample file for more
+   information
 
 Skinny Changes
 --------------

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/channels/chan_sip.c?view=diff&rev=168575&r1=168574&r2=168575
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Tue Jan 13 15:18:13 2009
@@ -6852,14 +6852,23 @@
 		ast_log(LOG_WARNING, "Format for registration is [transport://]user[:secret[:authuser]]@host[:port][/contact][~expiry] at line %d\n", lineno);
 		return -1;
 	}
-	/* split user[:secret[:authuser]] */
-	secret = strchr(username, ':');
-	if (secret) {
-		*secret++ = '\0';
-		authuser = strchr(secret, ':');
-		if (authuser)
-			*authuser++ = '\0';
-	}
+
+	/* split user[:secret[:authuser]] from the end to allow : character in user portion*/
+	authuser = strrchr(username, ':');
+	if (authuser) {
+		*authuser++ = '\0';
+		secret = strrchr(username, ':');
+		if (secret)
+			*secret++ = '\0';
+		else {
+			secret = authuser;
+			authuser = NULL;
+		}
+	}
+ 	if ((authuser) && (ast_strlen_zero(authuser)))
+		authuser = NULL;
+ 	if ((secret) && (ast_strlen_zero(secret)))
+		secret = NULL;
 
 	/* split host[:port][/contact] */
 	expire = strchr(hostname, '~');
@@ -10475,6 +10484,7 @@
 	struct sip_pvt *p;
 	int res;
 	char *fromdomain;
+	char *domainport = NULL;
 
 	/* exit if we are already in process with this registrar ?*/
 	if (r == NULL || ((auth == NULL) && (r->regstate == REG_STATE_REGSENT || r->regstate == REG_STATE_AUTHSENT))) {
@@ -10622,10 +10632,23 @@
 	/* Fromdomain is what we are registering to, regardless of actual
 	   host name from SRV */
 	if (!ast_strlen_zero(p->fromdomain)) {
-		if (r->portno && r->portno != STANDARD_SIP_PORT)
-			snprintf(addr, sizeof(addr), "sip:%s:%d", p->fromdomain, r->portno);
-		else
-			snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain);
+		domainport = strrchr(p->fromdomain, ':');
+		if (domainport) {
+			*domainport++ = '\0'; /* trim off domainport from p->fromdomain */
+			if (ast_strlen_zero(domainport))
+				domainport = NULL;
+		}		
+		if (domainport) {			
+			if (atoi(domainport) != STANDARD_SIP_PORT)
+				snprintf(addr, sizeof(addr), "sip:%s:%s", p->fromdomain, domainport);
+			else
+				snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain);
+		} else {
+			if (r->portno && r->portno != STANDARD_SIP_PORT)
+				snprintf(addr, sizeof(addr), "sip:%s:%d", p->fromdomain, r->portno);
+			else
+				snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain);
+		}
 	} else {
 		if (r->portno && r->portno != STANDARD_SIP_PORT)
 			snprintf(addr, sizeof(addr), "sip:%s:%d", r->hostname, r->portno);

Modified: trunk/configs/sip.conf.sample
URL: http://svn.digium.com/svn-view/asterisk/trunk/configs/sip.conf.sample?view=diff&rev=168575&r1=168574&r2=168575
==============================================================================
--- trunk/configs/sip.conf.sample (original)
+++ trunk/configs/sip.conf.sample Tue Jan 13 15:18:13 2009
@@ -432,6 +432,14 @@
 ; and more readable because you don't have to write the parameters in two places
 ; (note that the "port" is ignored - this is a bug that should be fixed).
 ;
+; Beginning with Asterisk version 1.6.2, the "user" portion of the register line may
+; contain a port number. Since the logical separator between a host and port number is a
+; ':' character, and this character is already used to separate between the optional "secret"
+; and "authuser" portions of the line, there is a bit of a hoop to jump through if you wish
+; to use a port here. That is, you must explicitly provide a "secret" and "authuser" even if
+; they are blank. See the third example below for an illustration.
+;
+;
 ; Examples:
 ;
 ;register => 1234:password at mysipprovider.com        
@@ -448,6 +456,11 @@
 ;    Tip 1: Avoid assigning hostname to a sip.conf section like [provider.com]
 ;    Tip 2: Use separate inbound and outbound sections for SIP providers
 ;           (instead of type=friend) if you have calls in both directions
+;
+;register => 3456 at mydomain:5082::@mysipprovider.com
+;
+;    Note that in this example, the optional authuser and secret portions have
+;    been left blank because we have specified a port in the user section
   
 ;registertimeout=20             ; retry registration calls every 20 seconds (default)
 ;registerattempts=10            ; Number of registration attempts before we give up




More information about the asterisk-commits mailing list