--------------------- PatchSet 1367 Date: 2005/05/14 18:20:07 Author: rmartinez Branch: squid3-ipv6 Tag: (none) Log: Adapted to IPv6 URL parsing. Module ready unless error Members: src/url.cc:1.9->1.9.8.1 Index: squid3/src/url.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/url.cc,v retrieving revision 1.9 retrieving revision 1.9.8.1 diff -u -r1.9 -r1.9.8.1 --- squid3/src/url.cc 11 Aug 2003 02:13:03 -0000 1.9 +++ squid3/src/url.cc 14 May 2005 18:20:07 -0000 1.9.8.1 @@ -1,6 +1,6 @@ /* - * $Id: url.cc,v 1.9 2003/08/11 02:13:03 squidadm Exp $ + * $Id: url.cc,v 1.9.8.1 2005/05/14 18:20:07 rmartinez Exp $ * * DEBUG: section 23 URL Parsing * AUTHOR: Duane Wessels @@ -112,11 +112,19 @@ #if ALLOW_HOSTNAME_UNDERSCORES "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" +#ifdef INET6 + "0123456789-._:"; // AaBbCcDdEeFf Hex digits included above. +#else "0123456789-._"; +#endif #else "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" +#ifdef INET6 + "0123456789-.:" +#else "0123456789-." +#endif ; #endif #endif /* CHECK_HOSTNAMES */ @@ -309,32 +317,47 @@ if (method == METHOD_CONNECT) { port = CONNECT_PORT; - if (sscanf(url, "%[^:]:%d", host, &port) < 1) - return NULL; +#ifdef INET6 + if (sscanf(url, "[%[^]]]:%d", host, &port) < 1) + /* the next "if" is intended nested when INET6 */ +#endif + if (sscanf(url, "%[^:]:%d", host, &port) < 1) + return NULL; } else if (!strncmp(url, "urn:", 4)) { return urnParse(method, url); } else { - if (sscanf(url, "%[^:]://%[^/]%[^\r\n]", proto, host, urlpath) < 2) - return NULL; + + if (sscanf(url, "%[^:]://%[^/]%[^\r\n]", proto, host, urlpath) < 2) + return NULL; protocol = urlParseProtocol(proto); port = urlDefaultPort(protocol); - /* Is there any login informaiton? */ - if ((t = strrchr(host, '@'))) { - strcpy((char *) login, (char *) host); - t = strrchr(login, '@'); - *t = 0; - strcpy((char *) host, t + 1); - } +#ifdef INET6 + if ((t = strchr(host, '['))) strcpy((char *) host, t + 1); +#endif - if ((t = strrchr(host, ':'))) { - *t++ = '\0'; + /* Is there any login informaiton? */ + if ((t = strrchr(host, '@'))) { + strcpy((char *) login, (char *) host); + t = strrchr(login, '@'); + *t = 0; + strcpy((char *) host, t + 1); + } + + if ((t = strrchr(host, ':'))) { + *t++ = '\0'; + + if (*t != '\0') + port = atoi(t); + } - if (*t != '\0') - port = atoi(t); - } +#ifdef INET6 + if ((t = strrchr(host, ']'))) *t='\0'; +#endif + + } for (t = host; *t; t++) @@ -449,13 +472,18 @@ if (request->canonical) return request->canonical; + if (request->protocol == PROTO_URN) { snprintf(urlbuf, MAX_URL, "urn:%s", request->urlpath.buf()); } else { switch (request->method) { case METHOD_CONNECT: - snprintf(urlbuf, MAX_URL, "%s:%d", request->host, request->port); + snprintf(urlbuf, MAX_URL, "%s%s%s:%d", + ((AF_FAMILY==AF_INET6) && (SAFE_INET_ADDR(request->host,NULL))) ? "[" : null_string, + request->host, + ((AF_FAMILY==AF_INET6) && (SAFE_INET_ADDR(request->host,NULL))) ? "]" : null_string, + request->port); break; default: @@ -464,11 +492,14 @@ if (request->port != urlDefaultPort(request->protocol)) snprintf(portbuf, 32, ":%d", request->port); - snprintf(urlbuf, MAX_URL, "%s://%s%s%s%s%s", + + 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, request->login, *request->login ? "@" : null_string, request->host, + ((AF_FAMILY==AF_INET6) && (SAFE_INET_ADDR(request->host,NULL))) ? "]" : null_string, portbuf, request->urlpath.buf()); @@ -493,7 +524,11 @@ switch (request->method) { case METHOD_CONNECT: - snprintf(buf, MAX_URL, "%s:%d", request->host, request->port); + snprintf(buf, MAX_URL, "%s%s%s:%d", + ((AF_FAMILY==AF_INET6) && SAFE_INET_ADDR(request->host,NULL)) ? "[" : null_string, + request->host, + ((AF_FAMILY==AF_INET6) && SAFE_INET_ADDR(request->host,NULL)) ? "]" : null_string, + request->port); break; default: @@ -513,10 +548,12 @@ strcat(loginbuf, "@"); } - snprintf(buf, MAX_URL, "%s://%s%s%s%s", + 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, loginbuf, request->host, + ((AF_FAMILY==AF_INET6) && SAFE_INET_ADDR(request->host,NULL)) ? "]" : null_string, portbuf, request->urlpath.buf()); /* @@ -748,6 +785,12 @@ while (*hostStart != '\0' && *hostStart == '/') ++hostStart; + +#ifdef INET6 + if (*hostStart == ']') + ++hostStart; +#endif + } void @@ -758,8 +801,14 @@ if ((t = strchr(Host, '/'))) *t = '\0'; - if ((t = strchr(Host, ':'))) + if ((t = strrchr(Host, ':'))) + *t = '\0'; + +#ifdef INET6 + if ((t = strchr(Host, ']'))) *t = '\0'; +#endif + } void