Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/net_util.h" | 5 #include "net/base/net_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 #include "url/url_canon.h" | 57 #include "url/url_canon.h" |
| 58 #include "url/url_canon_ip.h" | 58 #include "url/url_canon_ip.h" |
| 59 #include "url/url_parse.h" | 59 #include "url/url_parse.h" |
| 60 #if defined(OS_ANDROID) | 60 #if defined(OS_ANDROID) |
| 61 #include "net/android/network_library.h" | 61 #include "net/android/network_library.h" |
| 62 #endif | 62 #endif |
| 63 #include "net/base/dns_util.h" | 63 #include "net/base/dns_util.h" |
| 64 #include "net/base/escape.h" | 64 #include "net/base/escape.h" |
| 65 #include "net/base/mime_util.h" | 65 #include "net/base/mime_util.h" |
| 66 #include "net/base/net_module.h" | 66 #include "net/base/net_module.h" |
| 67 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | |
| 67 #if defined(OS_WIN) | 68 #if defined(OS_WIN) |
| 68 #include "net/base/winsock_init.h" | 69 #include "net/base/winsock_init.h" |
| 69 #endif | 70 #endif |
| 70 #include "net/http/http_content_disposition.h" | 71 #include "net/http/http_content_disposition.h" |
| 71 #include "third_party/icu/source/common/unicode/uidna.h" | 72 #include "third_party/icu/source/common/unicode/uidna.h" |
| 72 #include "third_party/icu/source/common/unicode/uniset.h" | 73 #include "third_party/icu/source/common/unicode/uniset.h" |
| 73 #include "third_party/icu/source/common/unicode/uscript.h" | 74 #include "third_party/icu/source/common/unicode/uscript.h" |
| 74 #include "third_party/icu/source/common/unicode/uset.h" | 75 #include "third_party/icu/source/common/unicode/uset.h" |
| 75 #include "third_party/icu/source/i18n/unicode/datefmt.h" | 76 #include "third_party/icu/source/i18n/unicode/datefmt.h" |
| 76 #include "third_party/icu/source/i18n/unicode/regex.h" | 77 #include "third_party/icu/source/i18n/unicode/regex.h" |
| (...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1383 } | 1384 } |
| 1384 | 1385 |
| 1385 std::string GetHostAndOptionalPort(const GURL& url) { | 1386 std::string GetHostAndOptionalPort(const GURL& url) { |
| 1386 // For IPv6 literals, GURL::host() already includes the brackets | 1387 // For IPv6 literals, GURL::host() already includes the brackets |
| 1387 // so it is safe to just append a colon. | 1388 // so it is safe to just append a colon. |
| 1388 if (url.has_port()) | 1389 if (url.has_port()) |
| 1389 return base::StringPrintf("%s:%s", url.host().c_str(), url.port().c_str()); | 1390 return base::StringPrintf("%s:%s", url.host().c_str(), url.port().c_str()); |
| 1390 return url.host(); | 1391 return url.host(); |
| 1391 } | 1392 } |
| 1392 | 1393 |
| 1394 // static | |
| 1395 bool IsHostnameNonUnique(const std::string& hostname) { | |
| 1396 // CanonicalizeHost requires surrounding brackets to parse an IPv6 address. | |
| 1397 const std::string host_or_ip = hostname.find(':') != std::string::npos ? | |
| 1398 "[" + hostname + "]" : hostname; | |
| 1399 url_canon::CanonHostInfo host_info; | |
| 1400 std::string canonical_name = CanonicalizeHost(host_or_ip, &host_info); | |
| 1401 | |
| 1402 // If canonicalization fails, then the input is truly malformed. However, | |
| 1403 // to avoid mis-reporting bad inputs as "non-unique", treat them as unique. | |
| 1404 if (canonical_name.empty()) | |
| 1405 return false; | |
| 1406 | |
| 1407 // If |hostname| is an IP address, presume it's unique. | |
| 1408 // TODO(rsleevi): In the future, this should also reject IP addresses in | |
| 1409 // IANA-reserved ranges, since those are also non-unique among publicly | |
| 1410 // trusted CAs. | |
|
Ryan Sleevi
2013/08/01 21:37:55
nit: comment update re: "trusted CAs"
felt
2013/08/01 22:00:25
Not entirely sure what you want here -- I removed
| |
| 1411 if (host_info.IsIPAddress()) | |
| 1412 return false; | |
| 1413 | |
| 1414 // Check for a registry controlled portion of |hostname|, ignoring private | |
| 1415 // registries, as they already chain to ICANN-administered registries, | |
| 1416 // and explicitly ignoring unknown registries. | |
| 1417 // | |
| 1418 // Note: This means that as new gTLDs are introduced on the Internet, they | |
| 1419 // will be treated as non-unique until the registry controlled domain list | |
| 1420 // is updated. However, because gTLDs are expected to provide significant | |
| 1421 // advance notice to deprecate older versions of this code, this an | |
| 1422 // acceptable tradeoff. | |
| 1423 return 0 == registry_controlled_domains::GetRegistryLength( | |
| 1424 canonical_name, | |
| 1425 registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | |
| 1426 registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | |
| 1427 } | |
| 1428 | |
| 1393 // Extracts the address and port portions of a sockaddr. | 1429 // Extracts the address and port portions of a sockaddr. |
| 1394 bool GetIPAddressFromSockAddr(const struct sockaddr* sock_addr, | 1430 bool GetIPAddressFromSockAddr(const struct sockaddr* sock_addr, |
| 1395 socklen_t sock_addr_len, | 1431 socklen_t sock_addr_len, |
| 1396 const uint8** address, | 1432 const uint8** address, |
| 1397 size_t* address_len, | 1433 size_t* address_len, |
| 1398 uint16* port) { | 1434 uint16* port) { |
| 1399 if (sock_addr->sa_family == AF_INET) { | 1435 if (sock_addr->sa_family == AF_INET) { |
| 1400 if (sock_addr_len < static_cast<socklen_t>(sizeof(struct sockaddr_in))) | 1436 if (sock_addr_len < static_cast<socklen_t>(sizeof(struct sockaddr_in))) |
| 1401 return false; | 1437 return false; |
| 1402 const struct sockaddr_in* addr = | 1438 const struct sockaddr_in* addr = |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2046 | 2082 |
| 2047 NetworkInterface::NetworkInterface(const std::string& name, | 2083 NetworkInterface::NetworkInterface(const std::string& name, |
| 2048 const IPAddressNumber& address) | 2084 const IPAddressNumber& address) |
| 2049 : name(name), address(address) { | 2085 : name(name), address(address) { |
| 2050 } | 2086 } |
| 2051 | 2087 |
| 2052 NetworkInterface::~NetworkInterface() { | 2088 NetworkInterface::~NetworkInterface() { |
| 2053 } | 2089 } |
| 2054 | 2090 |
| 2055 } // namespace net | 2091 } // namespace net |
| OLD | NEW |