From: Amos Jeffries Date: Tue, 20 Apr 2010 10:58:34 +0000 (+1200) Subject: Bug 2874: accept literal IPv6 address in icap_service URL X-Git-Tag: SQUID_3_2_0_1~283 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5957a4c9fda5f0b67f92da6e5e6c5bbf50d86445;p=thirdparty%2Fsquid.git Bug 2874: accept literal IPv6 address in icap_service URL 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. --- diff --git a/src/adaptation/ServiceConfig.cc b/src/adaptation/ServiceConfig.cc index f66ebd5c87..4e4dd5d529 100644 --- a/src/adaptation/ServiceConfig.cc +++ b/src/adaptation/ServiceConfig.cc @@ -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;