[asterisk-commits] mmichelson: trunk r275385 - /trunk/channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jul 9 15:58:56 CDT 2010


Author: mmichelson
Date: Fri Jul  9 15:58:52 2010
New Revision: 275385

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=275385
Log:
Fix error in parsing SIP registry strings from ASTdb.

It was essentially an off-by-one error. The easiest way
to fix this was to use the handy-dandy AST_NONSTANDARD_RAW_ARGS
macro to parse the pieces of the registration string out. Tested
and it works wonderfully.


Modified:
    trunk/channels/chan_sip.c

Modified: trunk/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_sip.c?view=diff&rev=275385&r1=275384&r2=275385
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Fri Jul  9 15:58:52 2010
@@ -12304,36 +12304,40 @@
 	char data[256];
 	struct ast_sockaddr sa;
 	int expire;
-	char *scan, *addr, *expiry_str, *username, *contact;
+	char full_addr[128];
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(addr);
+		AST_APP_ARG(port);
+		AST_APP_ARG(expiry_str);
+		AST_APP_ARG(username);
+		AST_APP_ARG(contact);
+	);
 
 	if (peer->rt_fromcontact)
 		return;
 	if (ast_db_get("SIP/Registry", peer->name, data, sizeof(data)))
 		return;
 
-	addr = scan = data;
-	if ('[' == scan[0]) {
-		/* It must be a bracket enclosed IPv6 address */
-		scan = strchr(scan, ']') + 1;
-	}
-	scan = strchr(scan, ':') + 1;
-	expiry_str = strsep(&scan, ":");
-	username = strsep(&scan, ":");
-	contact = scan;	/* Contact include sip: and has to be the last part of the database entry as long as we use : as a separator */
-
-	if (!ast_sockaddr_parse(&sa, addr, 0)) {
+	AST_NONSTANDARD_RAW_ARGS(args, data, ':');
+
+	snprintf(full_addr, sizeof(full_addr), "%s:%s", args.addr, args.port);
+
+	if (!ast_sockaddr_parse(&sa, full_addr, 0)) {
 		return;
 	}
 
-	if (expiry_str)
-		expire = atoi(expiry_str);
-	else
+	if (args.expiry_str) {
+		expire = atoi(args.expiry_str);
+	} else {
 		return;
-
-	if (username)
-		ast_string_field_set(peer, username, username);
-	if (contact)
-		ast_string_field_set(peer, fullcontact, contact);
+	}
+
+	if (args.username) {
+		ast_string_field_set(peer, username, args.username);
+	}
+	if (args.contact) {
+		ast_string_field_set(peer, fullcontact, args.contact);
+	}
 
 	ast_debug(2, "SIP Seeding peer from astdb: '%s' at %s@%s for %d\n",
 	    peer->name, peer->username, ast_sockaddr_stringify_host(&sa), expire);




More information about the asterisk-commits mailing list