[asterisk-commits] tilghman: branch 1.6.2 r215569 - in /branches/1.6.2: ./ channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 2 13:50:31 CDT 2009


Author: tilghman
Date: Wed Sep  2 13:50:27 2009
New Revision: 215569

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=215569
Log:
Merged revisions 215222 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

........
  r215222 | tilghman | 2009-09-01 16:19:40 -0500 (Tue, 01 Sep 2009) | 3 lines
  
  Fix register such that lines with a transport string, but without an authuser, parse correctly.
  (AST-228)
........

Modified:
    branches/1.6.2/   (props changed)
    branches/1.6.2/channels/chan_sip.c

Propchange: branches/1.6.2/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.2/channels/chan_sip.c
URL: http://svn.asterisk.org/svn-view/asterisk/branches/1.6.2/channels/chan_sip.c?view=diff&rev=215569&r1=215568&r2=215569
==============================================================================
--- branches/1.6.2/channels/chan_sip.c (original)
+++ branches/1.6.2/channels/chan_sip.c Wed Sep  2 13:50:27 2009
@@ -7101,11 +7101,17 @@
 	int portnum = 0;
 	enum sip_transport transport = SIP_TRANSPORT_UDP;
 	char buf[256] = "";
-	char *username = NULL;
-	char *tmp = NULL, *transport_str = NULL;
 	char *userpart = NULL, *hostpart = NULL;
-	char *peername = NULL;
 	/* register => [peer?][transport://]user[@domain][:secret[:authuser]]@host[:port][/extension][~expiry] */
+	AST_DECLARE_APP_ARGS(pre1,
+		AST_APP_ARG(peer);
+		AST_APP_ARG(userpart);
+	);
+	AST_DECLARE_APP_ARGS(pre2,
+		AST_APP_ARG(transport);
+		AST_APP_ARG(blank);
+		AST_APP_ARG(userpart);
+	);
 	AST_DECLARE_APP_ARGS(user1,
 		AST_APP_ARG(userpart);
 		AST_APP_ARG(secret);
@@ -7139,20 +7145,54 @@
 	}
 
 	if (ast_strlen_zero(userpart) || ast_strlen_zero(hostpart)) {
-		ast_log(LOG_WARNING, "Format for registration is [transport://]user[@domain][:secret[:authuser]]@host[:port][/extension][~expiry] at line %d\n", lineno);
+		ast_log(LOG_WARNING, "Format for registration is [peer?][transport://]user[@domain][:secret[:authuser]]@host[:port][/extension][~expiry] at line %d\n", lineno);
 		return -1;
 	}
 
 	/*!
-	 * user1.userpart => [peer?][transport://]user[@domain]
+	 * pre1.peer => peer
+	 * pre1.userpart => [transport://]user[@domain][:secret[:authuser]]
+	 * hostpart => host[:port][/extension][~expiry]
+	 */
+	AST_NONSTANDARD_RAW_ARGS(pre1, userpart, '?');
+	if (ast_strlen_zero(pre1.userpart)) {
+		pre1.userpart = pre1.peer;
+		pre1.peer = NULL;
+	}
+
+	/*!
+	 * pre1.peer => peer
+	 * pre2.transport = transport
+	 * pre2.userpart => user[@domain][:secret[:authuser]]
+	 * hostpart => host[:port][/extension][~expiry]
+	 */
+	AST_NONSTANDARD_RAW_ARGS(pre2, pre1.userpart, '/');
+	if (ast_strlen_zero(pre2.userpart)) {
+		pre2.userpart = pre2.transport;
+		pre2.transport = NULL;
+	} else {
+		pre2.transport[strlen(pre2.transport) - 1] = '\0'; /* Remove trailing : */
+	}
+
+	if (!ast_strlen_zero(pre2.blank)) {
+		ast_log(LOG_WARNING, "Format for registration is [peer?][transport://]user[@domain][:secret[:authuser]]@host[:port][/extension][~expiry] at line %d\n", lineno);
+		return -1;
+	}
+
+	/*!
+	 * pre1.peer => peer
+	 * pre2.transport = transport
+	 * user1.userpart => user[@domain]
 	 * user1.secret => secret
 	 * user1.authuser => authuser
 	 * hostpart => host[:port][/extension][~expiry]
 	 */
-	AST_NONSTANDARD_RAW_ARGS(user1, userpart, ':');
+	AST_NONSTANDARD_RAW_ARGS(user1, pre2.userpart, ':');
 
 	/*!
-	 * user1.userpart => [peer?][transport://]user[@domain]
+	 * pre1.peer => peer
+	 * pre2.transport = transport
+	 * user1.userpart => user[@domain]
 	 * user1.secret => secret
 	 * user1.authuser => authuser
 	 * host1.hostpart => host[:port][/extension]
@@ -7161,7 +7201,9 @@
 	AST_NONSTANDARD_RAW_ARGS(host1, hostpart, '~');
 
 	/*!
-	 * user1.userpart => [peer?][transport://]user[@domain]
+	 * pre1.peer => peer
+	 * pre2.transport = transport
+	 * user1.userpart => user[@domain]
 	 * user1.secret => secret
 	 * user1.authuser => authuser
 	 * host2.hostpart => host[:port]
@@ -7171,7 +7213,9 @@
 	AST_NONSTANDARD_RAW_ARGS(host2, host1.hostpart, '/');
 
 	/*!
-	 * user1.userpart => [peer?][transport://]user[@domain]
+	 * pre1.peer => peer
+	 * pre2.transport = transport
+	 * user1.userpart => user[@domain]
 	 * user1.secret => secret
 	 * user1.authuser => authuser
 	 * host3.host => host
@@ -7181,41 +7225,6 @@
 	 */
 	AST_NONSTANDARD_RAW_ARGS(host3, host2.hostpart, ':');
 
-	/*!
-	 * peername => peer
-	 * user2.userpart => [transport://]user[@domain]
-	 * user1.secret => secret
-	 * user1.authuser => authuser
-	 * host3.host => host
-	 * host3.port => port
-	 * host2.extension => extension (callback)
-	 * host1.expiry => expiry
-	 */
-	if ((tmp = strchr(user1.userpart, '?'))) {
-		*tmp = '\0';
-		peername = user1.userpart;
-		user1.userpart = tmp + 1;
-	}
-
-	/*!
-	 * peername => peer
-	 * transport_str => transport
-	 * username => user[@domain]
-	 * user1.secret => secret
-	 * user1.authuser => authuser
-	 * host3.host => host
-	 * host3.port => port
-	 * host2.extension => extension (callback)
-	 * host1.expiry => expiry
-	 */
-	if ((tmp = strstr(user1.userpart, "://"))) {
-		*tmp = '\0';
-		transport_str = user1.userpart;
-		username = tmp + 3;
-	} else {
-		username = user1.userpart;
-	}
-
 	if (host3.port) {
 		if (sscanf(host3.port, "%5u", &portnum) != 1 || portnum > 65535) {
 			ast_log(LOG_NOTICE, "'%s' is not a valid port number on line %d of sip.conf. using default.\n", host3.port, lineno);
@@ -7223,19 +7232,19 @@
 		}
 	}
 
-	if (!transport_str) {
+	if (!pre2.transport) {
 		transport = SIP_TRANSPORT_UDP;
-	} else if (!strncasecmp(transport_str, "tcp", 3)) {
+	} else if (!strncasecmp(pre2.transport, "tcp", 3)) {
 		transport = SIP_TRANSPORT_TCP;
-	} else if (!strncasecmp(transport_str, "tls", 3)) {
+	} else if (!strncasecmp(pre2.transport, "tls", 3)) {
 		transport = SIP_TRANSPORT_TLS;
 		if (portnum < 0) {
 			portnum = STANDARD_TLS_PORT;
 		}
-	} else if (!strncasecmp(transport_str, "udp", 3)) {
+	} else if (!strncasecmp(pre2.transport, "udp", 3)) {
 		transport = SIP_TRANSPORT_UDP;
 	} else {
-		ast_log(LOG_NOTICE, "'%.3s' is not a valid transport type on line %d of sip.conf. defaulting to udp.\n", transport_str, lineno);
+		ast_log(LOG_NOTICE, "'%.3s' is not a valid transport type on line %d of sip.conf. defaulting to udp.\n", pre2.transport, lineno);
 	}
 
 	if (portnum < 0) {
@@ -7256,11 +7265,11 @@
 	ast_atomic_fetchadd_int(&regobjs, 1);
 	ASTOBJ_INIT(reg);
 	ast_string_field_set(reg, callback, ast_strip_quoted(S_OR(host2.extension, ""), "\"", "\""));
-	ast_string_field_set(reg, username, ast_strip_quoted(S_OR(username, ""), "\"", "\""));
+	ast_string_field_set(reg, username, ast_strip_quoted(S_OR(user1.userpart, ""), "\"", "\""));
 	ast_string_field_set(reg, hostname, ast_strip_quoted(S_OR(host3.host, ""), "\"", "\""));
 	ast_string_field_set(reg, authuser, ast_strip_quoted(S_OR(user1.authuser, ""), "\"", "\""));
 	ast_string_field_set(reg, secret, ast_strip_quoted(S_OR(user1.secret, ""), "\"", "\""));
-	ast_string_field_set(reg, peername, ast_strip_quoted(S_OR(peername, ""), "\"", "\""));
+	ast_string_field_set(reg, peername, ast_strip_quoted(S_OR(pre1.peer, ""), "\"", "\""));
 
 	reg->transport = transport;
 	reg->timeout = reg->expire = -1;




More information about the asterisk-commits mailing list