diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-23 22:52:42 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-23 22:52:42 +0000 |
commit | 01dbd931735c7b7497b7b83664462512f272bf58 (patch) | |
tree | 39eaf9d56354fa8b45aadedd6faaf03aec000b98 /net/base/net_util.cc | |
parent | 99224582c3e56f3cb354f633baf06caa5b98e751 (diff) | |
download | chromium_src-01dbd931735c7b7497b7b83664462512f272bf58.zip chromium_src-01dbd931735c7b7497b7b83664462512f272bf58.tar.gz chromium_src-01dbd931735c7b7497b7b83664462512f272bf58.tar.bz2 |
Original patch by pmarks@google.com (see http://codereview.chromium.org/113944)
- Pull in googleurl r107, which includes the new CanonicalizeHostVerbose()
function:
http://code.google.com/p/google-url/source/detail?r=107
- Atomically update Chromium to make use of this new function. This allows us
to extract better information about IP addresses using fewer, and cleaner, calls
to googleurl.
- Also, change a call to CanonicalizeIPAddress() to stay compatible with r107.
The upshot of all this is, Chrome will no longer try to connect to IPv4
addresses with overflow "http://192.168.0.257", or hostnames surrounded by
square brackets "http://[google.com]"
BUG=none
TEST={unit_tests,googleurl_unittests,net_unittests}
Review URL: http://codereview.chromium.org/146053
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19076 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util.cc')
-rw-r--r-- | net/base/net_util.cc | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc index 0b2f243..d7fa844 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -829,43 +829,34 @@ void IDNToUnicode(const char* host, #endif } -std::string CanonicalizeHost(const std::string& host, bool* is_ip_address) { +std::string CanonicalizeHost(const std::string& host, + url_canon::CanonHostInfo* host_info) { // Try to canonicalize the host. - const url_parse::Component raw_host_component(0, - static_cast<int>(host.length())); + const url_parse::Component raw_host_component( + 0, static_cast<int>(host.length())); std::string canon_host; url_canon::StdStringCanonOutput canon_host_output(&canon_host); - url_parse::Component canon_host_component; - if (!url_canon::CanonicalizeHost(host.c_str(), raw_host_component, - &canon_host_output, &canon_host_component)) { - if (is_ip_address) - *is_ip_address = false; - return std::string(); - } - canon_host_output.Complete(); - - if (is_ip_address) { - // See if the host is an IP address. - url_canon::RawCanonOutputT<char, 128> ignored_output; - url_parse::Component ignored_component; - *is_ip_address = url_canon::CanonicalizeIPAddress(canon_host.c_str(), - canon_host_component, - &ignored_output, - &ignored_component); + url_canon::CanonicalizeHostVerbose(host.c_str(), raw_host_component, + &canon_host_output, host_info); + + if (host_info->out_host.is_nonempty() && + host_info->family != url_canon::CanonHostInfo::BROKEN) { + // Success! Assert that there's no extra garbage. + canon_host_output.Complete(); + DCHECK_EQ(host_info->out_host.len, static_cast<int>(canon_host.length())); + } else { + // Empty host, or canonicalization failed. We'll return empty. + canon_host.clear(); } - // Return the host as a string, stripping any unnecessary bits off the ends. - if ((canon_host_component.begin == 0) && - (static_cast<size_t>(canon_host_component.len) == canon_host.length())) - return canon_host; - return canon_host.substr(canon_host_component.begin, - canon_host_component.len); + return canon_host; } -std::string CanonicalizeHost(const std::wstring& host, bool* is_ip_address) { +std::string CanonicalizeHost(const std::wstring& host, + url_canon::CanonHostInfo* host_info) { std::string converted_host; WideToUTF8(host.c_str(), host.length(), &converted_host); - return CanonicalizeHost(converted_host, is_ip_address); + return CanonicalizeHost(converted_host, host_info); } std::string GetDirectoryListingHeader(const std::string& title) { |