summaryrefslogtreecommitdiffstats
path: root/net/base/net_util.cc
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-19 08:11:42 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-19 08:11:42 +0000
commitf6fb2de77993bbd88931ba205b0cc1e3423111f6 (patch)
tree831dbc093048f60b7d3cfa6548d42cedc340b4d7 /net/base/net_util.cc
parent77c846f5d8043e56543668971fff356d58380cf7 (diff)
downloadchromium_src-f6fb2de77993bbd88931ba205b0cc1e3423111f6.zip
chromium_src-f6fb2de77993bbd88931ba205b0cc1e3423111f6.tar.gz
chromium_src-f6fb2de77993bbd88931ba205b0cc1e3423111f6.tar.bz2
Add parsing for PAC result strings -- ProxyInfo::UsePacString().
Added the support class ProxyServer to avoid losing the proxy server's type information (http, socks) when populating the list. The format of the configuration strings has been extended accordingly to include an optional [<scheme>"://"] prefix. (i.e. "http://", "socks4://", "socks5://"). Review URL: http://codereview.chromium.org/20398 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10010 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util.cc')
-rw-r--r--net/base/net_util.cc46
1 files changed, 46 insertions, 0 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 16adb8a..3158f46 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -958,4 +958,50 @@ bool FileURLToFilePath(const GURL& gurl, std::wstring* file_path) {
return rv;
}
+bool GetHostAndPort(std::string::const_iterator host_and_port_begin,
+ std::string::const_iterator host_and_port_end,
+ std::string* host,
+ int* port) {
+ if (host_and_port_begin >= host_and_port_end)
+ return false;
+
+ // TODO(eroman): support IPv6 literals.
+ std::string::const_iterator colon =
+ std::find(host_and_port_begin, host_and_port_end, ':');
+
+ if (colon == host_and_port_end) {
+ // No colon.
+ host->assign(host_and_port_begin, host_and_port_end);
+ *port = -1;
+ return true;
+ }
+
+ if (colon == host_and_port_begin)
+ return false; // No host.
+
+ if (colon == host_and_port_end - 1)
+ return false; // There is nothing past the colon.
+
+ // Parse the port number to an integer.
+ std::string port_string(colon + 1, host_and_port_end);
+ int parsed_port_number = url_parse::ParsePort(port_string.data(),
+ url_parse::Component(0, port_string.size()));
+
+ // If parsing failed, port_number will be either PORT_INVALID or
+ // PORT_UNSPECIFIED, both of which are negative.
+ if (parsed_port_number < 0)
+ return false; // Failed parsing the port number.
+
+ // Else successfully parsed port number.
+ *port = parsed_port_number;
+ host->assign(host_and_port_begin, colon);
+ return true;
+}
+
+bool GetHostAndPort(const std::string& host_and_port,
+ std::string* host,
+ int* port) {
+ return GetHostAndPort(host_and_port.begin(), host_and_port.end(), host, port);
+}
+
} // namespace net