| 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 #ifndef NET_BASE_NET_UTIL_H_ | 5 #ifndef NET_BASE_NET_UTIL_H_ |
| 6 #define NET_BASE_NET_UTIL_H_ | 6 #define NET_BASE_NET_UTIL_H_ |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 typedef std::vector<unsigned char> IPAddressNumber; | 51 typedef std::vector<unsigned char> IPAddressNumber; |
| 52 typedef std::vector<IPAddressNumber> IPAddressList; | 52 typedef std::vector<IPAddressNumber> IPAddressList; |
| 53 | 53 |
| 54 static const size_t kIPv4AddressSize = 4; | 54 static const size_t kIPv4AddressSize = 4; |
| 55 static const size_t kIPv6AddressSize = 16; | 55 static const size_t kIPv6AddressSize = 16; |
| 56 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
| 57 // Bluetooth address size. Windows Bluetooth is supported via winsock. | 57 // Bluetooth address size. Windows Bluetooth is supported via winsock. |
| 58 static const size_t kBluetoothAddressSize = 6; | 58 static const size_t kBluetoothAddressSize = 6; |
| 59 #endif | 59 #endif |
| 60 | 60 |
| 61 // Nothing is ommitted. | 61 // Nothing is omitted. |
| 62 NET_EXPORT extern const FormatUrlType kFormatUrlOmitNothing; | 62 NET_EXPORT extern const FormatUrlType kFormatUrlOmitNothing; |
| 63 | 63 |
| 64 // If set, any username and password are removed. | 64 // If set, any username and password are removed. |
| 65 NET_EXPORT extern const FormatUrlType kFormatUrlOmitUsernamePassword; | 65 NET_EXPORT extern const FormatUrlType kFormatUrlOmitUsernamePassword; |
| 66 | 66 |
| 67 // If the scheme is 'http://', it's removed. | 67 // If the scheme is 'http://', it's removed. |
| 68 NET_EXPORT extern const FormatUrlType kFormatUrlOmitHTTP; | 68 NET_EXPORT extern const FormatUrlType kFormatUrlOmitHTTP; |
| 69 | 69 |
| 70 // Omits the path if it is just a slash and there is no query or ref. This is | 70 // Omits the path if it is just a slash and there is no query or ref. This is |
| 71 // meaningful for non-file "standard" URLs. | 71 // meaningful for non-file "standard" URLs. |
| 72 NET_EXPORT extern const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname; | 72 NET_EXPORT extern const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname; |
| 73 | 73 |
| 74 // Convenience for omitting all unecessary types. | 74 // Convenience for omitting all unnecessary types. |
| 75 NET_EXPORT extern const FormatUrlType kFormatUrlOmitAll; | 75 NET_EXPORT extern const FormatUrlType kFormatUrlOmitAll; |
| 76 | 76 |
| 77 // Remove the scheme. Callers should only specify this when it is safe to do so |
| 78 // (e.g. in contexts where the origin is always secure by necessity). Not part |
| 79 // of |kFormatUrlOmitAll|. |
| 80 NET_EXPORT extern const FormatUrlType kFormatUrlOmitScheme; |
| 81 |
| 82 // Remove the port. The caller should only specify this when the port is the |
| 83 // default for the scheme. Not part of |kFormatUrlOmitAll|. |
| 84 NET_EXPORT extern const FormatUrlType kFormatUrlOmitPort; |
| 85 |
| 77 // Returns the number of explicitly allowed ports; for testing. | 86 // Returns the number of explicitly allowed ports; for testing. |
| 78 NET_EXPORT_PRIVATE extern size_t GetCountOfExplicitlyAllowedPorts(); | 87 NET_EXPORT_PRIVATE extern size_t GetCountOfExplicitlyAllowedPorts(); |
| 79 | 88 |
| 80 // Splits an input of the form <host>[":"<port>] into its consitituent parts. | 89 // Splits an input of the form <host>[":"<port>] into its constituent parts. |
| 81 // Saves the result into |*host| and |*port|. If the input did not have | 90 // Saves the result into |*host| and |*port|. If the input did not have |
| 82 // the optional port, sets |*port| to -1. | 91 // the optional port, sets |*port| to -1. |
| 83 // Returns true if the parsing was successful, false otherwise. | 92 // Returns true if the parsing was successful, false otherwise. |
| 84 // The returned host is NOT canonicalized, and may be invalid. | 93 // The returned host is NOT canonicalized, and may be invalid. |
| 85 // | 94 // |
| 86 // IPv6 literals must be specified in a bracketed form, for instance: | 95 // IPv6 literals must be specified in a bracketed form, for instance: |
| 87 // [::1]:90 and [::1] | 96 // [::1]:90 and [::1] |
| 88 // | 97 // |
| 89 // The resultant |*host| in both cases will be "::1" (not bracketed). | 98 // The resultant |*host| in both cases will be "::1" (not bracketed). |
| 90 NET_EXPORT bool ParseHostAndPort( | 99 NET_EXPORT bool ParseHostAndPort( |
| 91 std::string::const_iterator host_and_port_begin, | 100 std::string::const_iterator host_and_port_begin, |
| 92 std::string::const_iterator host_and_port_end, | 101 std::string::const_iterator host_and_port_end, |
| 93 std::string* host, | 102 std::string* host, |
| 94 int* port); | 103 int* port); |
| 95 NET_EXPORT bool ParseHostAndPort( | 104 NET_EXPORT bool ParseHostAndPort( |
| 96 const std::string& host_and_port, | 105 const std::string& host_and_port, |
| 97 std::string* host, | 106 std::string* host, |
| 98 int* port); | 107 int* port); |
| 99 | 108 |
| 100 // Returns a host:port string for the given URL. | 109 // Returns a host:port string for the given URL. |
| 101 NET_EXPORT std::string GetHostAndPort(const GURL& url); | 110 NET_EXPORT std::string GetHostAndPort(const GURL& url); |
| 102 | 111 |
| 103 // Returns a host[:port] string for the given URL, where the port is omitted | 112 // Returns a host[:port] string for the given URL, where the port is omitted |
| 104 // if it is the default for the URL's scheme. | 113 // if it is the default for the URL's scheme. |
| 105 NET_EXPORT_PRIVATE std::string GetHostAndOptionalPort(const GURL& url); | 114 NET_EXPORT_PRIVATE std::string GetHostAndOptionalPort(const GURL& url); |
| 106 | 115 |
| 107 // Returns true if |hostname| contains a non-registerable or non-assignable | 116 // Returns true if |hostname| contains a non-registerable or non-assignable |
| 108 // domain name (eg: a gTLD that has not been assigned by IANA) or an IP address | 117 // domain name (e.g.: a gTLD that has not been assigned by IANA) or an IP |
| 109 // that falls in an IANA-reserved range. | 118 // address that falls in an IANA-reserved range. |
| 110 NET_EXPORT bool IsHostnameNonUnique(const std::string& hostname); | 119 NET_EXPORT bool IsHostnameNonUnique(const std::string& hostname); |
| 111 | 120 |
| 112 // Returns true if an IP address hostname is in a range reserved by the IANA. | 121 // Returns true if an IP address hostname is in a range reserved by the IANA. |
| 113 // Works with both IPv4 and IPv6 addresses, and only compares against a given | 122 // Works with both IPv4 and IPv6 addresses, and only compares against a given |
| 114 // protocols's reserved ranges. | 123 // protocol's reserved ranges. |
| 115 NET_EXPORT bool IsIPAddressReserved(const IPAddressNumber& address); | 124 NET_EXPORT bool IsIPAddressReserved(const IPAddressNumber& address); |
| 116 | 125 |
| 117 // Convenience struct for when you need a |struct sockaddr|. | 126 // Convenience struct for when you need a |struct sockaddr|. |
| 118 struct SockaddrStorage { | 127 struct SockaddrStorage { |
| 119 SockaddrStorage() : addr_len(sizeof(addr_storage)), | 128 SockaddrStorage() : addr_len(sizeof(addr_storage)), |
| 120 addr(reinterpret_cast<struct sockaddr*>(&addr_storage)) {} | 129 addr(reinterpret_cast<struct sockaddr*>(&addr_storage)) {} |
| 121 SockaddrStorage(const SockaddrStorage& other); | 130 SockaddrStorage(const SockaddrStorage& other); |
| 122 void operator=(const SockaddrStorage& other); | 131 void operator=(const SockaddrStorage& other); |
| 123 | 132 |
| 124 struct sockaddr_storage addr_storage; | 133 struct sockaddr_storage addr_storage; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 | 341 |
| 333 // This is a convenience function for FormatUrl() with | 342 // This is a convenience function for FormatUrl() with |
| 334 // format_types = kFormatUrlOmitAll and unescape = SPACES. This is the typical | 343 // format_types = kFormatUrlOmitAll and unescape = SPACES. This is the typical |
| 335 // set of flags for "URLs to display to the user". You should be cautious about | 344 // set of flags for "URLs to display to the user". You should be cautious about |
| 336 // using this for URLs which will be parsed or sent to other applications. | 345 // using this for URLs which will be parsed or sent to other applications. |
| 337 inline base::string16 FormatUrl(const GURL& url, const std::string& languages) { | 346 inline base::string16 FormatUrl(const GURL& url, const std::string& languages) { |
| 338 return FormatUrl(url, languages, kFormatUrlOmitAll, UnescapeRule::SPACES, | 347 return FormatUrl(url, languages, kFormatUrlOmitAll, UnescapeRule::SPACES, |
| 339 NULL, NULL, NULL); | 348 NULL, NULL, NULL); |
| 340 } | 349 } |
| 341 | 350 |
| 351 // This is a convenience function for formatting a URL as an origin in a concise |
| 352 // and human-friendly way. Use this instead of |FormatUrl| when the reader needs |
| 353 // only to understand the origin (rather than the entire URL). |
| 354 // |
| 355 // - Omits the path for standard schemes, excepting file and filesystem. |
| 356 // - Omits the port if it is the default for the scheme. |
| 357 // |
| 358 // Do not use this for URLs which will be parsed or sent to other applications. |
| 359 // |
| 360 // Callers should only set |omit_scheme| to true when it is safe to do so (e.g. |
| 361 // in contexts where the origin is always secure by necessity). |
| 362 NET_EXPORT base::string16 FormatOriginForDisplay(const GURL& origin, |
| 363 const std::string& languages, |
| 364 bool omit_scheme); |
| 365 |
| 342 // Returns whether FormatUrl() would strip a trailing slash from |url|, given a | 366 // Returns whether FormatUrl() would strip a trailing slash from |url|, given a |
| 343 // format flag including kFormatUrlOmitTrailingSlashOnBareHostname. | 367 // format flag including kFormatUrlOmitTrailingSlashOnBareHostname. |
| 344 NET_EXPORT bool CanStripTrailingSlash(const GURL& url); | 368 NET_EXPORT bool CanStripTrailingSlash(const GURL& url); |
| 345 | 369 |
| 346 // Strip the portions of |url| that aren't core to the network request. | 370 // Strip the portions of |url| that aren't core to the network request. |
| 347 // - user name / password | 371 // - user name / password |
| 348 // - reference section | 372 // - reference section |
| 349 NET_EXPORT_PRIVATE GURL SimplifyUrlForRequest(const GURL& url); | 373 NET_EXPORT_PRIVATE GURL SimplifyUrlForRequest(const GURL& url); |
| 350 | 374 |
| 351 NET_EXPORT void SetExplicitlyAllowedPorts(const std::string& allowed_ports); | 375 NET_EXPORT void SetExplicitlyAllowedPorts(const std::string& allowed_ports); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 // Returns true if |host| is one of the names (e.g. "localhost") or IP | 458 // Returns true if |host| is one of the names (e.g. "localhost") or IP |
| 435 // addresses (IPv4 127.0.0.0/8 or IPv6 ::1) that indicate a loopback. | 459 // addresses (IPv4 127.0.0.0/8 or IPv6 ::1) that indicate a loopback. |
| 436 // | 460 // |
| 437 // Note that this function does not check for IP addresses other than | 461 // Note that this function does not check for IP addresses other than |
| 438 // the above, although other IP addresses may point to the local | 462 // the above, although other IP addresses may point to the local |
| 439 // machine. | 463 // machine. |
| 440 NET_EXPORT_PRIVATE bool IsLocalhost(const std::string& host); | 464 NET_EXPORT_PRIVATE bool IsLocalhost(const std::string& host); |
| 441 | 465 |
| 442 NET_EXPORT_PRIVATE bool IsLocalhostTLD(const std::string& host); | 466 NET_EXPORT_PRIVATE bool IsLocalhostTLD(const std::string& host); |
| 443 | 467 |
| 444 // Returns true if the url's host is a Google server. This should only be used | 468 // Returns true if the URL's host is a Google server. This should only be used |
| 445 // for histograms and shouldn't be used to affect behavior. | 469 // for histograms and shouldn't be used to affect behavior. |
| 446 NET_EXPORT_PRIVATE bool HasGoogleHost(const GURL& url); | 470 NET_EXPORT_PRIVATE bool HasGoogleHost(const GURL& url); |
| 447 | 471 |
| 448 // A subset of IP address attributes which are actionable by the | 472 // A subset of IP address attributes which are actionable by the |
| 449 // application layer. Currently unimplemented for all hosts; | 473 // application layer. Currently unimplemented for all hosts; |
| 450 // IP_ADDRESS_ATTRIBUTE_NONE is always returned. | 474 // IP_ADDRESS_ATTRIBUTE_NONE is always returned. |
| 451 enum IPAddressAttributes { | 475 enum IPAddressAttributes { |
| 452 IP_ADDRESS_ATTRIBUTE_NONE = 0, | 476 IP_ADDRESS_ATTRIBUTE_NONE = 0, |
| 453 | 477 |
| 454 // A temporary address is dynamic by nature and will not contain MAC | 478 // A temporary address is dynamic by nature and will not contain MAC |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 DSCP_CS5 = 40, // Video | 606 DSCP_CS5 = 40, // Video |
| 583 DSCP_EF = 46, // Voice | 607 DSCP_EF = 46, // Voice |
| 584 DSCP_CS6 = 48, // Voice | 608 DSCP_CS6 = 48, // Voice |
| 585 DSCP_CS7 = 56, // Control messages | 609 DSCP_CS7 = 56, // Control messages |
| 586 DSCP_LAST = DSCP_CS7 | 610 DSCP_LAST = DSCP_CS7 |
| 587 }; | 611 }; |
| 588 | 612 |
| 589 } // namespace net | 613 } // namespace net |
| 590 | 614 |
| 591 #endif // NET_BASE_NET_UTIL_H_ | 615 #endif // NET_BASE_NET_UTIL_H_ |
| OLD | NEW |