--------------------- PatchSet 1375 Date: 2005/05/15 14:11:08 Author: rmartinez Branch: squid3-ipv6 Tag: (none) Log: Fixed bug on parsing. Cleaner macros based on regular patterns (sscanf). BRACKETS added on IPv6 addresses. Members: src/url.cc:1.9.8.1->1.9.8.2 Index: squid3/src/url.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/url.cc,v retrieving revision 1.9.8.1 retrieving revision 1.9.8.2 diff -u -r1.9.8.1 -r1.9.8.2 --- squid3/src/url.cc 14 May 2005 18:20:07 -0000 1.9.8.1 +++ squid3/src/url.cc 15 May 2005 14:11:08 -0000 1.9.8.2 @@ -1,6 +1,6 @@ /* - * $Id: url.cc,v 1.9.8.1 2005/05/14 18:20:07 rmartinez Exp $ + * $Id: url.cc,v 1.9.8.2 2005/05/15 14:11:08 rmartinez Exp $ * * DEBUG: section 23 URL Parsing * AUTHOR: Duane Wessels @@ -335,8 +335,10 @@ port = urlDefaultPort(protocol); #ifdef INET6 - if ((t = strchr(host, '['))) strcpy((char *) host, t + 1); + if (sscanf(url, "[%[^]]]:%d", host, &port) < 2) + /* the next "sscanf" is intended nested when INET6 */ #endif + sscanf(url, "%[^:]:%d", host, &port); /* Is there any login informaiton? */ if ((t = strrchr(host, '@'))) { @@ -346,17 +348,6 @@ strcpy((char *) host, t + 1); } - if ((t = strrchr(host, ':'))) { - *t++ = '\0'; - - if (*t != '\0') - port = atoi(t); - } - -#ifdef INET6 - if ((t = strrchr(host, ']'))) *t='\0'; -#endif - } @@ -480,9 +471,9 @@ case METHOD_CONNECT: snprintf(urlbuf, MAX_URL, "%s%s%s:%d", - ((AF_FAMILY==AF_INET6) && (SAFE_INET_ADDR(request->host,NULL))) ? "[" : null_string, + NEEDS_BRACKETS(request->host) ? "[" : null_string, request->host, - ((AF_FAMILY==AF_INET6) && (SAFE_INET_ADDR(request->host,NULL))) ? "]" : null_string, + NEEDS_BRACKETS(request->host) ? "]" : null_string, request->port); break; @@ -495,11 +486,11 @@ snprintf(urlbuf, MAX_URL, "%s://%s%s%s%s%s%s%s", ProtocolStr[request->protocol], - ((AF_FAMILY==AF_INET6) && (SAFE_INET_ADDR(request->host,NULL))) ? "[" : null_string, + NEEDS_BRACKETS(request->host) ? "[" : null_string, request->login, *request->login ? "@" : null_string, request->host, - ((AF_FAMILY==AF_INET6) && (SAFE_INET_ADDR(request->host,NULL))) ? "]" : null_string, + NEEDS_BRACKETS(request->host) ? "]" : null_string, portbuf, request->urlpath.buf()); @@ -525,9 +516,9 @@ case METHOD_CONNECT: snprintf(buf, MAX_URL, "%s%s%s:%d", - ((AF_FAMILY==AF_INET6) && SAFE_INET_ADDR(request->host,NULL)) ? "[" : null_string, + NEEDS_BRACKETS(request->host) ? "[" : null_string, request->host, - ((AF_FAMILY==AF_INET6) && SAFE_INET_ADDR(request->host,NULL)) ? "]" : null_string, + NEEDS_BRACKETS(request->host) ? "]" : null_string, request->port); break; @@ -550,10 +541,10 @@ snprintf(buf, MAX_URL, "%s://%s%s%s%s%s%s", ProtocolStr[request->protocol], - ((AF_FAMILY==AF_INET6) && SAFE_INET_ADDR(request->host,NULL)) ? "[" : null_string, + NEEDS_BRACKETS(request->host) ? "[" : null_string, loginbuf, request->host, - ((AF_FAMILY==AF_INET6) && SAFE_INET_ADDR(request->host,NULL)) ? "]" : null_string, + NEEDS_BRACKETS(request->host) ? "]" : null_string, portbuf, request->urlpath.buf()); /*