[asterisk-commits] rizzo: trunk r46003 - /trunk/channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Oct 23 10:41:04 MST 2006


Author: rizzo
Date: Mon Oct 23 12:41:03 2006
New Revision: 46003

URL: http://svn.digium.com/view/asterisk?rev=46003&view=rev
Log:
another use for parse_uri().
On passing, remove a wrong comment (that probably I wrote
myself!) and introduce a temporary variable to avoid a     
misleading cast.


Modified:
    trunk/channels/chan_sip.c

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=46003&r1=46002&r2=46003&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Mon Oct 23 12:41:03 2006
@@ -7634,7 +7634,7 @@
 	char data[BUFSIZ];
 	const char *expires = get_header(req, "Expires");
 	int expiry = atoi(expires);
-	char *curi, *n, *pt;
+	char *curi, *host, *pt;
 	int port;
 	const char *useragent;
 	struct hostent *hp;
@@ -7643,11 +7643,10 @@
 
 	ast_copy_string(contact, get_header(req, "Contact"), sizeof(contact));
 
-	if (ast_strlen_zero(expires)) {	/* No expires header */
-		expires = strcasestr(contact, ";expires=");
-		if (expires) {
-			/* XXX bug here, we overwrite the string */
-			expires = strsep((char **) &expires, ";"); /* trim ; and beyond */
+	if (ast_strlen_zero(expires)) {	/* No expires header, try look in Contact: */
+		char *s = strcasestr(contact, ";expires=");
+		if (s) {
+			expires = strsep(&s, ";"); /* trim ; and beyond */
 			if (sscanf(expires + 9, "%d", &expiry) != 1)
 				expiry = default_expiry;
 		} else {
@@ -7699,31 +7698,15 @@
 	ast_string_field_build(pvt, our_contact, "<%s>", curi);
 
 	/* Make sure it's a SIP URL */
-	if (strncasecmp(curi, "sip:", 4)) {
-		ast_log(LOG_NOTICE, "'%s' is not a valid SIP contact (missing sip:) trying to use anyway\n", curi);
-	} else
-		curi += 4;
-	/* Ditch q */
-	curi = strsep(&curi, ";");
-	/* Grab host */
-	n = strchr(curi, '@');
-	if (!n) {
-		n = curi;
-		curi = NULL;
-	} else
-		*n++ = '\0';
-	pt = strchr(n, ':');
-	if (pt) {
-		*pt++ = '\0';
-		port = atoi(pt);
-	} else
-		port = STANDARD_SIP_PORT;
+	if (parse_uri(curi, "sip:", &curi, NULL, &host, &pt, NULL))
+		ast_log(LOG_NOTICE, "Not a valid SIP contact (missing sip:) trying to use anyway\n");
+	port = !ast_strlen_zero(pt) ? atoi(pt) : STANDARD_SIP_PORT;
 	oldsin = peer->addr;
 	if (!ast_test_flag(&peer->flags[0], SIP_NAT_ROUTE)) {
 		/* XXX This could block for a long time XXX */
-		hp = ast_gethostbyname(n, &ahp);
+		hp = ast_gethostbyname(host, &ahp);
 		if (!hp)  {
-			ast_log(LOG_WARNING, "Invalid host '%s'\n", n);
+			ast_log(LOG_WARNING, "Invalid host '%s'\n", host);
 			return PARSE_REGISTER_FAILED;
 		}
 		peer->addr.sin_family = AF_INET;
@@ -7738,7 +7721,7 @@
 	/* Save SIP options profile */
 	peer->sipoptions = pvt->sipoptions;
 
-	if (curi)	/* Overwrite the default username from config at registration */
+	if (!ast_strlen_zero(curi))	/* Overwrite the default username from config at registration */
 		ast_copy_string(peer->username, curi, sizeof(peer->username));
 	else
 		peer->username[0] = '\0';



More information about the asterisk-commits mailing list