Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: net/base/net_util.h

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // Saves the result into |*host| and |*port|. If the input did not have 81 // Saves the result into |*host| and |*port|. If the input did not have
82 // the optional port, sets |*port| to -1. 82 // the optional port, sets |*port| to -1.
83 // Returns true if the parsing was successful, false otherwise. 83 // Returns true if the parsing was successful, false otherwise.
84 // The returned host is NOT canonicalized, and may be invalid. If <host> is 84 // The returned host is NOT canonicalized, and may be invalid. If <host> is
85 // an IPv6 literal address, the returned host includes the square brackets. 85 // an IPv6 literal address, the returned host includes the square brackets.
86 NET_EXPORT bool ParseHostAndPort( 86 NET_EXPORT bool ParseHostAndPort(
87 std::string::const_iterator host_and_port_begin, 87 std::string::const_iterator host_and_port_begin,
88 std::string::const_iterator host_and_port_end, 88 std::string::const_iterator host_and_port_end,
89 std::string* host, 89 std::string* host,
90 int* port); 90 int* port);
91 NET_EXPORT bool ParseHostAndPort( 91 NET_EXPORT bool ParseHostAndPort(const std::string& host_and_port,
92 const std::string& host_and_port, 92 std::string* host,
93 std::string* host, 93 int* port);
94 int* port);
95 94
96 // Returns a host:port string for the given URL. 95 // Returns a host:port string for the given URL.
97 NET_EXPORT std::string GetHostAndPort(const GURL& url); 96 NET_EXPORT std::string GetHostAndPort(const GURL& url);
98 97
99 // Returns a host[:port] string for the given URL, where the port is omitted 98 // Returns a host[:port] string for the given URL, where the port is omitted
100 // if it is the default for the URL's scheme. 99 // if it is the default for the URL's scheme.
101 NET_EXPORT_PRIVATE std::string GetHostAndOptionalPort(const GURL& url); 100 NET_EXPORT_PRIVATE std::string GetHostAndOptionalPort(const GURL& url);
102 101
103 // Returns true if |hostname| contains a non-registerable or non-assignable 102 // Returns true if |hostname| contains a non-registerable or non-assignable
104 // domain name (eg: a gTLD that has not been assigned by IANA) or an IP address 103 // domain name (eg: a gTLD that has not been assigned by IANA) or an IP address
105 // that falls in an IANA-reserved range. 104 // that falls in an IANA-reserved range.
106 NET_EXPORT bool IsHostnameNonUnique(const std::string& hostname); 105 NET_EXPORT bool IsHostnameNonUnique(const std::string& hostname);
107 106
108 // Returns true if an IP address hostname is in a range reserved by the IANA. 107 // Returns true if an IP address hostname is in a range reserved by the IANA.
109 // Works with both IPv4 and IPv6 addresses, and only compares against a given 108 // Works with both IPv4 and IPv6 addresses, and only compares against a given
110 // protocols's reserved ranges. 109 // protocols's reserved ranges.
111 NET_EXPORT bool IsIPAddressReserved(const IPAddressNumber& address); 110 NET_EXPORT bool IsIPAddressReserved(const IPAddressNumber& address);
112 111
113 // Convenience struct for when you need a |struct sockaddr|. 112 // Convenience struct for when you need a |struct sockaddr|.
114 struct SockaddrStorage { 113 struct SockaddrStorage {
115 SockaddrStorage() : addr_len(sizeof(addr_storage)), 114 SockaddrStorage()
116 addr(reinterpret_cast<struct sockaddr*>(&addr_storage)) {} 115 : addr_len(sizeof(addr_storage)),
116 addr(reinterpret_cast<struct sockaddr*>(&addr_storage)) {}
117 struct sockaddr_storage addr_storage; 117 struct sockaddr_storage addr_storage;
118 socklen_t addr_len; 118 socklen_t addr_len;
119 struct sockaddr* const addr; 119 struct sockaddr* const addr;
120 }; 120 };
121 121
122 // Extracts the IP address and port portions of a sockaddr. |port| is optional, 122 // Extracts the IP address and port portions of a sockaddr. |port| is optional,
123 // and will not be filled in if NULL. 123 // and will not be filled in if NULL.
124 bool GetIPAddressFromSockAddr(const struct sockaddr* sock_addr, 124 bool GetIPAddressFromSockAddr(const struct sockaddr* sock_addr,
125 socklen_t sock_addr_len, 125 socklen_t sock_addr_len,
126 const unsigned char** address, 126 const unsigned char** address,
(...skipping 18 matching lines...) Expand all
145 145
146 // Same as IPAddressToStringWithPort() but for a sockaddr. This output will not 146 // Same as IPAddressToStringWithPort() but for a sockaddr. This output will not
147 // include the IPv6 scope ID. 147 // include the IPv6 scope ID.
148 NET_EXPORT std::string NetAddressToStringWithPort(const struct sockaddr* sa, 148 NET_EXPORT std::string NetAddressToStringWithPort(const struct sockaddr* sa,
149 socklen_t sock_addr_len); 149 socklen_t sock_addr_len);
150 150
151 // Same as IPAddressToString() but for an IPAddressNumber. 151 // Same as IPAddressToString() but for an IPAddressNumber.
152 NET_EXPORT std::string IPAddressToString(const IPAddressNumber& addr); 152 NET_EXPORT std::string IPAddressToString(const IPAddressNumber& addr);
153 153
154 // Same as IPAddressToStringWithPort() but for an IPAddressNumber. 154 // Same as IPAddressToStringWithPort() but for an IPAddressNumber.
155 NET_EXPORT std::string IPAddressToStringWithPort( 155 NET_EXPORT std::string IPAddressToStringWithPort(const IPAddressNumber& addr,
156 const IPAddressNumber& addr, uint16 port); 156 uint16 port);
157 157
158 // Returns the address as a sequence of bytes in network-byte-order. 158 // Returns the address as a sequence of bytes in network-byte-order.
159 NET_EXPORT std::string IPAddressToPackedString(const IPAddressNumber& addr); 159 NET_EXPORT std::string IPAddressToPackedString(const IPAddressNumber& addr);
160 160
161 // Returns the hostname of the current system. Returns empty string on failure. 161 // Returns the hostname of the current system. Returns empty string on failure.
162 NET_EXPORT std::string GetHostName(); 162 NET_EXPORT std::string GetHostName();
163 163
164 // Extracts the unescaped username/password from |url|, saving the results 164 // Extracts the unescaped username/password from |url|, saving the results
165 // into |*username| and |*password|. 165 // into |*username| and |*password|.
166 NET_EXPORT_PRIVATE void GetIdentityFromURL(const GURL& url, 166 NET_EXPORT_PRIVATE void GetIdentityFromURL(const GURL& url,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // |addRow|. 229 // |addRow|.
230 // 230 //
231 // |name| is the file name to be displayed. |raw_bytes| will be used 231 // |name| is the file name to be displayed. |raw_bytes| will be used
232 // as the actual target of the link (so for example, ftp links should use 232 // as the actual target of the link (so for example, ftp links should use
233 // server's encoding). If |raw_bytes| is an empty string, UTF-8 encoded |name| 233 // server's encoding). If |raw_bytes| is an empty string, UTF-8 encoded |name|
234 // will be used. 234 // will be used.
235 // 235 //
236 // Both |name| and |raw_bytes| are escaped internally. 236 // Both |name| and |raw_bytes| are escaped internally.
237 NET_EXPORT std::string GetDirectoryListingEntry(const base::string16& name, 237 NET_EXPORT std::string GetDirectoryListingEntry(const base::string16& name,
238 const std::string& raw_bytes, 238 const std::string& raw_bytes,
239 bool is_dir, int64 size, 239 bool is_dir,
240 int64 size,
240 base::Time modified); 241 base::Time modified);
241 242
242 // If text starts with "www." it is removed, otherwise text is returned 243 // If text starts with "www." it is removed, otherwise text is returned
243 // unmodified. 244 // unmodified.
244 NET_EXPORT base::string16 StripWWW(const base::string16& text); 245 NET_EXPORT base::string16 StripWWW(const base::string16& text);
245 246
246 // Runs |url|'s host through StripWWW(). |url| must be valid. 247 // Runs |url|'s host through StripWWW(). |url| must be valid.
247 NET_EXPORT base::string16 StripWWWFromHost(const GURL& url); 248 NET_EXPORT base::string16 StripWWWFromHost(const GURL& url);
248 249
249 // Checks |port| against a list of ports which are restricted by default. 250 // Checks |port| against a list of ports which are restricted by default.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 UnescapeRule::Type unescape_rules, 325 UnescapeRule::Type unescape_rules,
325 url::Parsed* new_parsed, 326 url::Parsed* new_parsed,
326 size_t* prefix_end, 327 size_t* prefix_end,
327 base::OffsetAdjuster::Adjustments* adjustments); 328 base::OffsetAdjuster::Adjustments* adjustments);
328 329
329 // This is a convenience function for FormatUrl() with 330 // This is a convenience function for FormatUrl() with
330 // format_types = kFormatUrlOmitAll and unescape = SPACES. This is the typical 331 // format_types = kFormatUrlOmitAll and unescape = SPACES. This is the typical
331 // set of flags for "URLs to display to the user". You should be cautious about 332 // set of flags for "URLs to display to the user". You should be cautious about
332 // using this for URLs which will be parsed or sent to other applications. 333 // using this for URLs which will be parsed or sent to other applications.
333 inline base::string16 FormatUrl(const GURL& url, const std::string& languages) { 334 inline base::string16 FormatUrl(const GURL& url, const std::string& languages) {
334 return FormatUrl(url, languages, kFormatUrlOmitAll, UnescapeRule::SPACES, 335 return FormatUrl(url,
335 NULL, NULL, NULL); 336 languages,
337 kFormatUrlOmitAll,
338 UnescapeRule::SPACES,
339 NULL,
340 NULL,
341 NULL);
336 } 342 }
337 343
338 // Returns whether FormatUrl() would strip a trailing slash from |url|, given a 344 // Returns whether FormatUrl() would strip a trailing slash from |url|, given a
339 // format flag including kFormatUrlOmitTrailingSlashOnBareHostname. 345 // format flag including kFormatUrlOmitTrailingSlashOnBareHostname.
340 NET_EXPORT bool CanStripTrailingSlash(const GURL& url); 346 NET_EXPORT bool CanStripTrailingSlash(const GURL& url);
341 347
342 // Strip the portions of |url| that aren't core to the network request. 348 // Strip the portions of |url| that aren't core to the network request.
343 // - user name / password 349 // - user name / password
344 // - reference section 350 // - reference section
345 NET_EXPORT_PRIVATE GURL SimplifyUrlForRequest(const GURL& url); 351 NET_EXPORT_PRIVATE GURL SimplifyUrlForRequest(const GURL& url);
(...skipping 10 matching lines...) Expand all
356 362
357 DISALLOW_COPY_AND_ASSIGN(ScopedPortException); 363 DISALLOW_COPY_AND_ASSIGN(ScopedPortException);
358 }; 364 };
359 365
360 // Returns true if it can determine that only loopback addresses are configured. 366 // Returns true if it can determine that only loopback addresses are configured.
361 // i.e. if only 127.0.0.1 and ::1 are routable. 367 // i.e. if only 127.0.0.1 and ::1 are routable.
362 // Also returns false if it cannot determine this. 368 // Also returns false if it cannot determine this.
363 bool HaveOnlyLoopbackAddresses(); 369 bool HaveOnlyLoopbackAddresses();
364 370
365 // Returns AddressFamily of the address. 371 // Returns AddressFamily of the address.
366 NET_EXPORT_PRIVATE AddressFamily GetAddressFamily( 372 NET_EXPORT_PRIVATE AddressFamily
367 const IPAddressNumber& address); 373 GetAddressFamily(const IPAddressNumber& address);
368 374
369 // Maps the given AddressFamily to either AF_INET, AF_INET6 or AF_UNSPEC. 375 // Maps the given AddressFamily to either AF_INET, AF_INET6 or AF_UNSPEC.
370 NET_EXPORT_PRIVATE int ConvertAddressFamily(AddressFamily address_family); 376 NET_EXPORT_PRIVATE int ConvertAddressFamily(AddressFamily address_family);
371 377
372 // Parses an IP address literal (either IPv4 or IPv6) to its numeric value. 378 // Parses an IP address literal (either IPv4 or IPv6) to its numeric value.
373 // Returns true on success and fills |ip_number| with the numeric value. 379 // Returns true on success and fills |ip_number| with the numeric value.
374 NET_EXPORT_PRIVATE bool ParseIPLiteralToNumber(const std::string& ip_literal, 380 NET_EXPORT_PRIVATE bool ParseIPLiteralToNumber(const std::string& ip_literal,
375 IPAddressNumber* ip_number); 381 IPAddressNumber* ip_number);
376 382
377 // Converts an IPv4 address to an IPv4-mapped IPv6 address. 383 // Converts an IPv4 address to an IPv4-mapped IPv6 address.
378 // For example 192.168.0.1 would be converted to ::ffff:192.168.0.1. 384 // For example 192.168.0.1 would be converted to ::ffff:192.168.0.1.
379 NET_EXPORT_PRIVATE IPAddressNumber ConvertIPv4NumberToIPv6Number( 385 NET_EXPORT_PRIVATE IPAddressNumber
380 const IPAddressNumber& ipv4_number); 386 ConvertIPv4NumberToIPv6Number(const IPAddressNumber& ipv4_number);
381 387
382 // Returns true iff |address| is an IPv4-mapped IPv6 address. 388 // Returns true iff |address| is an IPv4-mapped IPv6 address.
383 NET_EXPORT_PRIVATE bool IsIPv4Mapped(const IPAddressNumber& address); 389 NET_EXPORT_PRIVATE bool IsIPv4Mapped(const IPAddressNumber& address);
384 390
385 // Converts an IPv4-mapped IPv6 address to IPv4 address. Should only be called 391 // Converts an IPv4-mapped IPv6 address to IPv4 address. Should only be called
386 // on IPv4-mapped IPv6 addresses. 392 // on IPv4-mapped IPv6 addresses.
387 NET_EXPORT_PRIVATE IPAddressNumber ConvertIPv4MappedToIPv4( 393 NET_EXPORT_PRIVATE IPAddressNumber
388 const IPAddressNumber& address); 394 ConvertIPv4MappedToIPv4(const IPAddressNumber& address);
389 395
390 // Parses an IP block specifier from CIDR notation to an 396 // Parses an IP block specifier from CIDR notation to an
391 // (IP address, prefix length) pair. Returns true on success and fills 397 // (IP address, prefix length) pair. Returns true on success and fills
392 // |*ip_number| with the numeric value of the IP address and sets 398 // |*ip_number| with the numeric value of the IP address and sets
393 // |*prefix_length_in_bits| with the length of the prefix. 399 // |*prefix_length_in_bits| with the length of the prefix.
394 // 400 //
395 // CIDR notation literals can use either IPv4 or IPv6 literals. Some examples: 401 // CIDR notation literals can use either IPv4 or IPv6 literals. Some examples:
396 // 402 //
397 // 10.10.3.1/20 403 // 10.10.3.1/20
398 // a:b:c::/46 404 // a:b:c::/46
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 NetworkInterface(const std::string& name, 443 NetworkInterface(const std::string& name,
438 const std::string& friendly_name, 444 const std::string& friendly_name,
439 uint32 interface_index, 445 uint32 interface_index,
440 NetworkChangeNotifier::ConnectionType type, 446 NetworkChangeNotifier::ConnectionType type,
441 const IPAddressNumber& address, 447 const IPAddressNumber& address,
442 size_t network_prefix); 448 size_t network_prefix);
443 ~NetworkInterface(); 449 ~NetworkInterface();
444 450
445 std::string name; 451 std::string name;
446 std::string friendly_name; // Same as |name| on non-Windows. 452 std::string friendly_name; // Same as |name| on non-Windows.
447 uint32 interface_index; // Always 0 on Android. 453 uint32 interface_index; // Always 0 on Android.
448 NetworkChangeNotifier::ConnectionType type; 454 NetworkChangeNotifier::ConnectionType type;
449 IPAddressNumber address; 455 IPAddressNumber address;
450 size_t network_prefix; 456 size_t network_prefix;
451 }; 457 };
452 458
453 typedef std::vector<NetworkInterface> NetworkInterfaceList; 459 typedef std::vector<NetworkInterface> NetworkInterfaceList;
454 460
455 // Policy settings to include/exclude network interfaces. 461 // Policy settings to include/exclude network interfaces.
456 enum HostAddressSelectionPolicy { 462 enum HostAddressSelectionPolicy {
457 INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES = 0x0, 463 INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES = 0x0,
458 EXCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES = 0x1, 464 EXCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES = 0x1,
459 // Include temp address only when interface has both permanent and 465 // Include temp address only when interface has both permanent and
460 // temp addresses. 466 // temp addresses.
461 INCLUDE_ONLY_TEMP_IPV6_ADDRESS_IF_POSSIBLE = 0x2, 467 INCLUDE_ONLY_TEMP_IPV6_ADDRESS_IF_POSSIBLE = 0x2,
462 }; 468 };
463 469
464 // Returns list of network interfaces except loopback interface. If an 470 // Returns list of network interfaces except loopback interface. If an
465 // interface has more than one address, a separate entry is added to 471 // interface has more than one address, a separate entry is added to
466 // the list for each address. 472 // the list for each address.
467 // Can be called only on a thread that allows IO. 473 // Can be called only on a thread that allows IO.
468 NET_EXPORT bool GetNetworkList(NetworkInterfaceList* networks, 474 NET_EXPORT bool GetNetworkList(NetworkInterfaceList* networks, int policy);
469 int policy);
470 475
471 // General category of the IEEE 802.11 (wifi) physical layer operating mode. 476 // General category of the IEEE 802.11 (wifi) physical layer operating mode.
472 enum WifiPHYLayerProtocol { 477 enum WifiPHYLayerProtocol {
473 // No wifi support or no associated AP. 478 // No wifi support or no associated AP.
474 WIFI_PHY_LAYER_PROTOCOL_NONE, 479 WIFI_PHY_LAYER_PROTOCOL_NONE,
475 // An obsolete modes introduced by the original 802.11, e.g. IR, FHSS. 480 // An obsolete modes introduced by the original 802.11, e.g. IR, FHSS.
476 WIFI_PHY_LAYER_PROTOCOL_ANCIENT, 481 WIFI_PHY_LAYER_PROTOCOL_ANCIENT,
477 // 802.11a, OFDM-based rates. 482 // 802.11a, OFDM-based rates.
478 WIFI_PHY_LAYER_PROTOCOL_A, 483 WIFI_PHY_LAYER_PROTOCOL_A,
479 // 802.11b, DSSS or HR DSSS. 484 // 802.11b, DSSS or HR DSSS.
(...skipping 16 matching lines...) Expand all
496 501
497 // Computes the number of leading 1-bits in |mask|. 502 // Computes the number of leading 1-bits in |mask|.
498 unsigned MaskPrefixLength(const IPAddressNumber& mask); 503 unsigned MaskPrefixLength(const IPAddressNumber& mask);
499 504
500 // Differentiated Services Code Point. 505 // Differentiated Services Code Point.
501 // See http://tools.ietf.org/html/rfc2474 for details. 506 // See http://tools.ietf.org/html/rfc2474 for details.
502 enum DiffServCodePoint { 507 enum DiffServCodePoint {
503 DSCP_NO_CHANGE = -1, 508 DSCP_NO_CHANGE = -1,
504 DSCP_FIRST = DSCP_NO_CHANGE, 509 DSCP_FIRST = DSCP_NO_CHANGE,
505 DSCP_DEFAULT = 0, // Same as DSCP_CS0 510 DSCP_DEFAULT = 0, // Same as DSCP_CS0
506 DSCP_CS0 = 0, // The default 511 DSCP_CS0 = 0, // The default
507 DSCP_CS1 = 8, // Bulk/background traffic 512 DSCP_CS1 = 8, // Bulk/background traffic
508 DSCP_AF11 = 10, 513 DSCP_AF11 = 10,
509 DSCP_AF12 = 12, 514 DSCP_AF12 = 12,
510 DSCP_AF13 = 14, 515 DSCP_AF13 = 14,
511 DSCP_CS2 = 16, 516 DSCP_CS2 = 16,
512 DSCP_AF21 = 18, 517 DSCP_AF21 = 18,
513 DSCP_AF22 = 20, 518 DSCP_AF22 = 20,
514 DSCP_AF23 = 22, 519 DSCP_AF23 = 22,
515 DSCP_CS3 = 24, 520 DSCP_CS3 = 24,
516 DSCP_AF31 = 26, 521 DSCP_AF31 = 26,
517 DSCP_AF32 = 28, 522 DSCP_AF32 = 28,
518 DSCP_AF33 = 30, 523 DSCP_AF33 = 30,
519 DSCP_CS4 = 32, 524 DSCP_CS4 = 32,
520 DSCP_AF41 = 34, // Video 525 DSCP_AF41 = 34, // Video
521 DSCP_AF42 = 36, // Video 526 DSCP_AF42 = 36, // Video
522 DSCP_AF43 = 38, // Video 527 DSCP_AF43 = 38, // Video
523 DSCP_CS5 = 40, // Video 528 DSCP_CS5 = 40, // Video
524 DSCP_EF = 46, // Voice 529 DSCP_EF = 46, // Voice
525 DSCP_CS6 = 48, // Voice 530 DSCP_CS6 = 48, // Voice
526 DSCP_CS7 = 56, // Control messages 531 DSCP_CS7 = 56, // Control messages
527 DSCP_LAST = DSCP_CS7 532 DSCP_LAST = DSCP_CS7
528 }; 533 };
529 534
530 } // namespace net 535 } // namespace net
531 536
532 #endif // NET_BASE_NET_UTIL_H_ 537 #endif // NET_BASE_NET_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698