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

Unified Diff: net/base/net_util.cc

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 side-by-side diff with in-line comments
Download patch
Index: net/base/net_util.cc
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 5b3d65e515b2a060c9eabc31458b3dde0b156e32..dfe76407eb24d39811c1d066a974d3797387a8b5 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -67,79 +67,79 @@ namespace {
// The general list of blocked ports. Will be blocked unless a specific
// protocol overrides it. (Ex: ftp can use ports 20 and 21)
static const int kRestrictedPorts[] = {
- 1, // tcpmux
- 7, // echo
- 9, // discard
- 11, // systat
- 13, // daytime
- 15, // netstat
- 17, // qotd
- 19, // chargen
- 20, // ftp data
- 21, // ftp access
- 22, // ssh
- 23, // telnet
- 25, // smtp
- 37, // time
- 42, // name
- 43, // nicname
- 53, // domain
- 77, // priv-rjs
- 79, // finger
- 87, // ttylink
- 95, // supdup
- 101, // hostriame
- 102, // iso-tsap
- 103, // gppitnp
- 104, // acr-nema
- 109, // pop2
- 110, // pop3
- 111, // sunrpc
- 113, // auth
- 115, // sftp
- 117, // uucp-path
- 119, // nntp
- 123, // NTP
- 135, // loc-srv /epmap
- 139, // netbios
- 143, // imap2
- 179, // BGP
- 389, // ldap
- 465, // smtp+ssl
- 512, // print / exec
- 513, // login
- 514, // shell
- 515, // printer
- 526, // tempo
- 530, // courier
- 531, // chat
- 532, // netnews
- 540, // uucp
- 556, // remotefs
- 563, // nntp+ssl
- 587, // stmp?
- 601, // ??
- 636, // ldap+ssl
- 993, // ldap+ssl
- 995, // pop3+ssl
- 2049, // nfs
- 3659, // apple-sasl / PasswordServer
- 4045, // lockd
- 6000, // X11
- 6665, // Alternate IRC [Apple addition]
- 6666, // Alternate IRC [Apple addition]
- 6667, // Standard IRC [Apple addition]
- 6668, // Alternate IRC [Apple addition]
- 6669, // Alternate IRC [Apple addition]
- 0xFFFF, // Used to block all invalid port numbers (see
- // third_party/WebKit/Source/platform/weborigin/KURL.cpp,
- // KURL::port())
+ 1, // tcpmux
+ 7, // echo
+ 9, // discard
+ 11, // systat
+ 13, // daytime
+ 15, // netstat
+ 17, // qotd
+ 19, // chargen
+ 20, // ftp data
+ 21, // ftp access
+ 22, // ssh
+ 23, // telnet
+ 25, // smtp
+ 37, // time
+ 42, // name
+ 43, // nicname
+ 53, // domain
+ 77, // priv-rjs
+ 79, // finger
+ 87, // ttylink
+ 95, // supdup
+ 101, // hostriame
+ 102, // iso-tsap
+ 103, // gppitnp
+ 104, // acr-nema
+ 109, // pop2
+ 110, // pop3
+ 111, // sunrpc
+ 113, // auth
+ 115, // sftp
+ 117, // uucp-path
+ 119, // nntp
+ 123, // NTP
+ 135, // loc-srv /epmap
+ 139, // netbios
+ 143, // imap2
+ 179, // BGP
+ 389, // ldap
+ 465, // smtp+ssl
+ 512, // print / exec
+ 513, // login
+ 514, // shell
+ 515, // printer
+ 526, // tempo
+ 530, // courier
+ 531, // chat
+ 532, // netnews
+ 540, // uucp
+ 556, // remotefs
+ 563, // nntp+ssl
+ 587, // stmp?
+ 601, // ??
+ 636, // ldap+ssl
+ 993, // ldap+ssl
+ 995, // pop3+ssl
+ 2049, // nfs
+ 3659, // apple-sasl / PasswordServer
+ 4045, // lockd
+ 6000, // X11
+ 6665, // Alternate IRC [Apple addition]
+ 6666, // Alternate IRC [Apple addition]
+ 6667, // Standard IRC [Apple addition]
+ 6668, // Alternate IRC [Apple addition]
+ 6669, // Alternate IRC [Apple addition]
+ 0xFFFF, // Used to block all invalid port numbers (see
+ // third_party/WebKit/Source/platform/weborigin/KURL.cpp,
+ // KURL::port())
};
// FTP overrides the following restricted ports.
static const int kAllowedFtpPorts[] = {
- 21, // ftp data
- 22, // ssh
+ 21, // ftp data
+ 22, // ssh
};
bool IPNumberPrefixCheck(const IPAddressNumber& ip_number,
@@ -189,8 +189,11 @@ std::string GetSpecificHeader(const std::string& headers,
std::string match('\n' + name + ':');
std::string::const_iterator begin =
- std::search(headers.begin(), headers.end(), match.begin(), match.end(),
- base::CaseInsensitiveCompareASCII<char>());
+ std::search(headers.begin(),
+ headers.end(),
+ match.begin(),
+ match.end(),
+ base::CaseInsensitiveCompareASCII<char>());
if (begin == headers.end())
return std::string();
@@ -198,9 +201,10 @@ std::string GetSpecificHeader(const std::string& headers,
begin += match.length();
std::string ret;
- base::TrimWhitespace(std::string(begin,
- std::find(begin, headers.end(), '\n')),
- base::TRIM_ALL, &ret);
+ base::TrimWhitespace(
+ std::string(begin, std::find(begin, headers.end(), '\n')),
+ base::TRIM_ALL,
+ &ret);
return ret;
}
@@ -210,8 +214,8 @@ std::string CanonicalizeHost(const std::string& host,
const url::Component raw_host_component(0, static_cast<int>(host.length()));
std::string canon_host;
url::StdStringCanonOutput canon_host_output(&canon_host);
- url::CanonicalizeHostVerbose(host.c_str(), raw_host_component,
- &canon_host_output, host_info);
+ url::CanonicalizeHostVerbose(
+ host.c_str(), raw_host_component, &canon_host_output, host_info);
if (host_info->out_host.is_nonempty() &&
host_info->family != url::CanonHostInfo::BROKEN) {
@@ -230,8 +234,8 @@ std::string GetDirectoryListingHeader(const base::string16& title) {
static const base::StringPiece header(
NetModule::GetResource(IDR_DIR_HEADER_HTML));
// This can be null in unit tests.
- DLOG_IF(WARNING, header.empty()) <<
- "Missing resource: directory listing header";
+ DLOG_IF(WARNING, header.empty())
+ << "Missing resource: directory listing header";
std::string result;
if (!header.empty())
@@ -282,7 +286,7 @@ bool IsCanonicalizedHostCompliant(const std::string& host,
}
return most_recent_component_started_alphanumeric ||
- (!desired_tld.empty() && IsHostCharAlphanumeric(desired_tld[0]));
+ (!desired_tld.empty() && IsHostCharAlphanumeric(desired_tld[0]));
}
base::string16 StripWWW(const base::string16& text) {
@@ -309,7 +313,7 @@ bool IsPortAllowedByFtp(int port) {
int array_size = arraysize(kAllowedFtpPorts);
for (int i = 0; i < array_size; i++) {
if (kAllowedFtpPorts[i] == port) {
- return true;
+ return true;
}
}
// Port not explicitly allowed by FTP, so return the default restrictions.
@@ -352,8 +356,12 @@ bool ParseHostAndPort(std::string::const_iterator host_and_port_begin,
url::Component hostname_component;
url::Component port_component;
- url::ParseAuthority(auth_begin, auth_component, &username_component,
- &password_component, &hostname_component, &port_component);
+ url::ParseAuthority(auth_begin,
+ auth_component,
+ &username_component,
+ &password_component,
+ &hostname_component,
+ &port_component);
// There shouldn't be a username/password.
if (username_component.is_valid() || password_component.is_valid())
@@ -392,8 +400,8 @@ bool ParseHostAndPort(const std::string& host_and_port,
std::string GetHostAndPort(const GURL& url) {
// For IPv6 literals, GURL::host() already includes the brackets so it is
// safe to just append a colon.
- return base::StringPrintf("%s:%d", url.host().c_str(),
- url.EffectiveIntPort());
+ return base::StringPrintf(
+ "%s:%d", url.host().c_str(), url.EffectiveIntPort());
}
std::string GetHostAndOptionalPort(const GURL& url) {
@@ -406,8 +414,8 @@ std::string GetHostAndOptionalPort(const GURL& url) {
bool IsHostnameNonUnique(const std::string& hostname) {
// CanonicalizeHost requires surrounding brackets to parse an IPv6 address.
- const std::string host_or_ip = hostname.find(':') != std::string::npos ?
- "[" + hostname + "]" : hostname;
+ const std::string host_or_ip =
+ hostname.find(':') != std::string::npos ? "[" + hostname + "]" : hostname;
url::CanonHostInfo host_info;
std::string canonical_name = CanonicalizeHost(host_or_ip, &host_info);
@@ -420,9 +428,9 @@ bool IsHostnameNonUnique(const std::string& hostname) {
// range.
if (host_info.IsIPAddress()) {
IPAddressNumber host_addr;
- if (!ParseIPLiteralToNumber(hostname.substr(host_info.out_host.begin,
- host_info.out_host.len),
- &host_addr)) {
+ if (!ParseIPLiteralToNumber(
+ hostname.substr(host_info.out_host.begin, host_info.out_host.len),
+ &host_addr)) {
return false;
}
switch (host_info.family) {
@@ -460,24 +468,31 @@ bool IsHostnameNonUnique(const std::string& hostname) {
// They're formatted here with the prefix as the last element. For example:
// 10.0.0.0/8 becomes 10,0,0,0,8 and fec0::/10 becomes 0xfe,0xc0,0,0,0...,10.
bool IsIPAddressReserved(const IPAddressNumber& host_addr) {
- static const unsigned char kReservedIPv4[][5] = {
- { 0,0,0,0,8 }, { 10,0,0,0,8 }, { 100,64,0,0,10 }, { 127,0,0,0,8 },
- { 169,254,0,0,16 }, { 172,16,0,0,12 }, { 192,0,2,0,24 },
- { 192,88,99,0,24 }, { 192,168,0,0,16 }, { 198,18,0,0,15 },
- { 198,51,100,0,24 }, { 203,0,113,0,24 }, { 224,0,0,0,3 }
- };
+ static const unsigned char kReservedIPv4[][5] = {{0, 0, 0, 0, 8},
+ {10, 0, 0, 0, 8},
+ {100, 64, 0, 0, 10},
+ {127, 0, 0, 0, 8},
+ {169, 254, 0, 0, 16},
+ {172, 16, 0, 0, 12},
+ {192, 0, 2, 0, 24},
+ {192, 88, 99, 0, 24},
+ {192, 168, 0, 0, 16},
+ {198, 18, 0, 0, 15},
+ {198, 51, 100, 0, 24},
+ {203, 0, 113, 0, 24},
+ {224, 0, 0, 0, 3}};
static const unsigned char kReservedIPv6[][17] = {
- { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8 },
- { 0x40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2 },
- { 0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2 },
- { 0xc0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3 },
- { 0xe0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
- { 0xf0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5 },
- { 0xf8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6 },
- { 0xfc,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7 },
- { 0xfe,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9 },
- { 0xfe,0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10 },
- { 0xfe,0xc0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10 },
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8},
+ {0x40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2},
+ {0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2},
+ {0xc0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3},
+ {0xe0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4},
+ {0xf0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5},
+ {0xf8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6},
+ {0xfc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7},
+ {0xfe, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9},
+ {0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10},
+ {0xfe, 0xc0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10},
};
size_t array_size = 0;
const unsigned char* array = NULL;
@@ -495,7 +510,7 @@ bool IsIPAddressReserved(const IPAddressNumber& host_addr) {
return false;
size_t width = host_addr.size() + 1;
for (size_t i = 0; i < array_size; ++i, array += width) {
- if (IPNumberPrefixCheck(host_addr, array, array[width-1]))
+ if (IPNumberPrefixCheck(host_addr, array, array[width - 1]))
return true;
}
return false;
@@ -535,8 +550,7 @@ bool GetIPAddressFromSockAddr(const struct sockaddr* sock_addr,
if (sock_addr->sa_family == AF_BTH) {
if (sock_addr_len < static_cast<socklen_t>(sizeof(SOCKADDR_BTH)))
return false;
- const SOCKADDR_BTH* addr =
- reinterpret_cast<const SOCKADDR_BTH*>(sock_addr);
+ const SOCKADDR_BTH* addr = reinterpret_cast<const SOCKADDR_BTH*>(sock_addr);
*address = reinterpret_cast<const uint8*>(&addr->btAddr);
*address_len = kBluetoothAddressSize;
if (port)
@@ -548,8 +562,7 @@ bool GetIPAddressFromSockAddr(const struct sockaddr* sock_addr,
return false; // Unrecognized |sa_family|.
}
-std::string IPAddressToString(const uint8* address,
- size_t address_len) {
+std::string IPAddressToString(const uint8* address, size_t address_len) {
std::string str;
url::StdStringCanonOutput output(&str);
@@ -581,8 +594,8 @@ std::string NetAddressToString(const struct sockaddr* sa,
socklen_t sock_addr_len) {
const uint8* address;
size_t address_len;
- if (!GetIPAddressFromSockAddr(sa, sock_addr_len, &address,
- &address_len, NULL)) {
+ if (!GetIPAddressFromSockAddr(
+ sa, sock_addr_len, &address, &address_len, NULL)) {
NOTREACHED();
return std::string();
}
@@ -594,8 +607,8 @@ std::string NetAddressToStringWithPort(const struct sockaddr* sa,
const uint8* address;
size_t address_len;
uint16 port;
- if (!GetIPAddressFromSockAddr(sa, sock_addr_len, &address,
- &address_len, &port)) {
+ if (!GetIPAddressFromSockAddr(
+ sa, sock_addr_len, &address, &address_len, &port)) {
NOTREACHED();
return std::string();
}
@@ -612,8 +625,7 @@ std::string IPAddressToStringWithPort(const IPAddressNumber& addr,
}
std::string IPAddressToPackedString(const IPAddressNumber& addr) {
- return std::string(reinterpret_cast<const char *>(&addr.front()),
- addr.size());
+ return std::string(reinterpret_cast<const char*>(&addr.front()), addr.size());
}
std::string GetHostName() {
@@ -652,9 +664,8 @@ std::string GetHostOrSpecFromURL(const GURL& url) {
bool CanStripTrailingSlash(const GURL& url) {
// Omit the path only for standard, non-file URLs with nothing but "/" after
// the hostname.
- return url.IsStandard() && !url.SchemeIsFile() &&
- !url.SchemeIsFileSystem() && !url.has_query() && !url.has_ref()
- && url.path() == "/";
+ return url.IsStandard() && !url.SchemeIsFile() && !url.SchemeIsFileSystem() &&
+ !url.has_query() && !url.has_ref() && url.path() == "/";
}
GURL SimplifyUrlForRequest(const GURL& url) {
@@ -726,8 +737,7 @@ bool HaveOnlyLoopbackAddresses() {
}
bool result = true;
- for (struct ifaddrs* interface = interface_addr;
- interface != NULL;
+ for (struct ifaddrs* interface = interface_addr; interface != NULL;
interface = interface->ifa_next) {
if (!(IFF_UP & interface->ifa_flags))
continue;
@@ -797,8 +807,8 @@ bool ParseIPLiteralToNumber(const std::string& ip_literal,
// Try parsing the hostname as an IPv6 literal.
ip_number->resize(16); // 128 bits.
- return url::IPv6AddressToNumber(host_brackets.data(), host_comp,
- &(*ip_number)[0]);
+ return url::IPv6AddressToNumber(
+ host_brackets.data(), host_comp, &(*ip_number)[0]);
}
// Otherwise the string is an IPv4 address.
@@ -812,8 +822,8 @@ bool ParseIPLiteralToNumber(const std::string& ip_literal,
namespace {
-const unsigned char kIPv4MappedPrefix[] =
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF };
+const unsigned char kIPv4MappedPrefix[] = {0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0xFF, 0xFF};
}
IPAddressNumber ConvertIPv4NumberToIPv6Number(
@@ -890,7 +900,8 @@ bool IPNumberMatchesPrefix(const IPAddressNumber& ip_number,
if (ip_number.size() != ip_prefix.size()) {
if (ip_number.size() == 4) {
return IPNumberMatchesPrefix(ConvertIPv4NumberToIPv6Number(ip_number),
- ip_prefix, prefix_length_in_bits);
+ ip_prefix,
+ prefix_length_in_bits);
}
return IPNumberMatchesPrefix(ip_number,
ConvertIPv4NumberToIPv6Number(ip_prefix),
@@ -926,10 +937,8 @@ int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) {
}
bool IsLocalhost(const std::string& host) {
- if (host == "localhost" ||
- host == "localhost.localdomain" ||
- host == "localhost6" ||
- host == "localhost6.localdomain6")
+ if (host == "localhost" || host == "localhost.localdomain" ||
+ host == "localhost6" || host == "localhost6.localdomain6")
return true;
IPAddressNumber ip_number;
@@ -960,8 +969,7 @@ bool IsLocalhost(const std::string& host) {
}
NetworkInterface::NetworkInterface()
- : type(NetworkChangeNotifier::CONNECTION_UNKNOWN),
- network_prefix(0) {
+ : type(NetworkChangeNotifier::CONNECTION_UNKNOWN), network_prefix(0) {
}
NetworkInterface::NetworkInterface(const std::string& name,

Powered by Google App Engine
This is Rietveld 408576698