]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 2874: accept literal IPv6 address in icap_service URL
authorAmos Jeffries <squid3@treenet.co.nz>
Tue, 20 Apr 2010 10:58:34 +0000 (22:58 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 20 Apr 2010 10:58:34 +0000 (22:58 +1200)
NP: This just ports the URL parsing from squid's main parser.
    If host needs to be written out anywhere it will need to be
    re-encoded properly.

src/adaptation/ServiceConfig.cc

index f66ebd5c87f986612203c9085bdf722746fb2a35..4e4dd5d52939c413d37bf4d375c98a2d65f5de94 100644 (file)
@@ -125,6 +125,7 @@ bool
 Adaptation::ServiceConfig::grokUri(const char *value)
 {
     // TODO: find core code that parses URLs and extracts various parts
+    // AYJ: most of this is duplicate of urlParse() in src/url.cc
 
     if (!value || !*value) {
         debugs(3, 0, HERE << cfg_filename << ':' << config_lineno << ": " <<
@@ -153,15 +154,33 @@ Adaptation::ServiceConfig::grokUri(const char *value)
 
     bool have_port = false;
 
-    if ((e = strchr(s, ':')) != NULL) {
-        have_port = true;
-    } else if ((e = strchr(s, '/')) != NULL) {
-        have_port = false;
-    } else {
-        return false;
+    int len = 0;
+    if (*s == '[') {
+        const char *t;
+        if ((t = strchr(s, ']')) == NULL)
+            return false;
+
+        s++;
+        len = t - s;
+        if ((e = strchr(t, ':')) != NULL) {
+            have_port = true;
+        } else if ((e = strchr(t, '/')) != NULL) {
+            have_port = false;
+        } else {
+            return false;
+        }
+    }
+    else {
+        if ((e = strchr(s, ':')) != NULL) {
+            have_port = true;
+        } else if ((e = strchr(s, '/')) != NULL) {
+            have_port = false;
+        } else {
+            return false;
+        }
+        len = e - s;
     }
 
-    int len = e - s;
     host.limitInit(s, len);
     s = e;