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 <errno.h> | 7 #include <errno.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 } else if (!IsHostCharAlphanumeric(c) && (c != '-') && (c != '_')) { | 273 } else if (!IsHostCharAlphanumeric(c) && (c != '-') && (c != '_')) { |
274 return false; | 274 return false; |
275 } | 275 } |
276 } | 276 } |
277 | 277 |
278 return most_recent_component_started_alphanumeric; | 278 return most_recent_component_started_alphanumeric; |
279 } | 279 } |
280 | 280 |
281 base::string16 StripWWW(const base::string16& text) { | 281 base::string16 StripWWW(const base::string16& text) { |
282 const base::string16 www(base::ASCIIToUTF16("www.")); | 282 const base::string16 www(base::ASCIIToUTF16("www.")); |
283 return StartsWith(text, www, true) ? text.substr(www.length()) : text; | 283 return base::StartsWith(text, www, base::CompareCase::SENSITIVE) |
| 284 ? text.substr(www.length()) |
| 285 : text; |
284 } | 286 } |
285 | 287 |
286 base::string16 StripWWWFromHost(const GURL& url) { | 288 base::string16 StripWWWFromHost(const GURL& url) { |
287 DCHECK(url.is_valid()); | 289 DCHECK(url.is_valid()); |
288 return StripWWW(base::ASCIIToUTF16(url.host())); | 290 return StripWWW(base::ASCIIToUTF16(url.host())); |
289 } | 291 } |
290 | 292 |
291 bool IsPortValid(int port) { | 293 bool IsPortValid(int port) { |
292 return port >= 0 && port <= std::numeric_limits<uint16>::max(); | 294 return port >= 0 && port <= std::numeric_limits<uint16>::max(); |
293 } | 295 } |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 | 702 |
701 std::multiset<int> ports; | 703 std::multiset<int> ports; |
702 size_t last = 0; | 704 size_t last = 0; |
703 size_t size = allowed_ports.size(); | 705 size_t size = allowed_ports.size(); |
704 // The comma delimiter. | 706 // The comma delimiter. |
705 const std::string::value_type kComma = ','; | 707 const std::string::value_type kComma = ','; |
706 | 708 |
707 // Overflow is still possible for evil user inputs. | 709 // Overflow is still possible for evil user inputs. |
708 for (size_t i = 0; i <= size; ++i) { | 710 for (size_t i = 0; i <= size; ++i) { |
709 // The string should be composed of only digits and commas. | 711 // The string should be composed of only digits and commas. |
710 if (i != size && !IsAsciiDigit(allowed_ports[i]) && | 712 if (i != size && !base::IsAsciiDigit(allowed_ports[i]) && |
711 (allowed_ports[i] != kComma)) | 713 (allowed_ports[i] != kComma)) |
712 return; | 714 return; |
713 if (i == size || allowed_ports[i] == kComma) { | 715 if (i == size || allowed_ports[i] == kComma) { |
714 if (i > last) { | 716 if (i > last) { |
715 int port; | 717 int port; |
716 base::StringToInt(base::StringPiece(allowed_ports.begin() + last, | 718 base::StringToInt(base::StringPiece(allowed_ports.begin() + last, |
717 allowed_ports.begin() + i), | 719 allowed_ports.begin() + i), |
718 &port); | 720 &port); |
719 ports.insert(port); | 721 ports.insert(port); |
720 } | 722 } |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 if (host.empty()) | 1015 if (host.empty()) |
1014 return false; | 1016 return false; |
1015 | 1017 |
1016 size_t host_len = host.size(); | 1018 size_t host_len = host.size(); |
1017 if (*host.rbegin() == '.') | 1019 if (*host.rbegin() == '.') |
1018 --host_len; | 1020 --host_len; |
1019 if (host_len < kLocalhostTLDLength) | 1021 if (host_len < kLocalhostTLDLength) |
1020 return false; | 1022 return false; |
1021 | 1023 |
1022 const char* host_suffix = host.data() + host_len - kLocalhostTLDLength; | 1024 const char* host_suffix = host.data() + host_len - kLocalhostTLDLength; |
1023 return base::strncasecmp(host_suffix, kLocalhostTLD, kLocalhostTLDLength) == | 1025 return strncasecmp(host_suffix, kLocalhostTLD, kLocalhostTLDLength) == 0; |
1024 0; | |
1025 } | 1026 } |
1026 | 1027 |
1027 bool HasGoogleHost(const GURL& url) { | 1028 bool HasGoogleHost(const GURL& url) { |
1028 static const char* kGoogleHostSuffixes[] = { | 1029 static const char* kGoogleHostSuffixes[] = { |
1029 ".google.com", | 1030 ".google.com", |
1030 ".youtube.com", | 1031 ".youtube.com", |
1031 ".gmail.com", | 1032 ".gmail.com", |
1032 ".doubleclick.net", | 1033 ".doubleclick.net", |
1033 ".gstatic.com", | 1034 ".gstatic.com", |
1034 ".googlevideo.com", | 1035 ".googlevideo.com", |
1035 ".googleusercontent.com", | 1036 ".googleusercontent.com", |
1036 ".googlesyndication.com", | 1037 ".googlesyndication.com", |
1037 ".google-analytics.com", | 1038 ".google-analytics.com", |
1038 ".googleadservices.com", | 1039 ".googleadservices.com", |
1039 ".googleapis.com", | 1040 ".googleapis.com", |
1040 ".ytimg.com", | 1041 ".ytimg.com", |
1041 }; | 1042 }; |
1042 const std::string& host = url.host(); | 1043 const std::string& host = url.host(); |
1043 for (const char* suffix : kGoogleHostSuffixes) { | 1044 for (const char* suffix : kGoogleHostSuffixes) { |
1044 if (EndsWith(host, suffix, false)) | 1045 if (base::EndsWith(host, suffix, base::CompareCase::INSENSITIVE_ASCII)) |
1045 return true; | 1046 return true; |
1046 } | 1047 } |
1047 return false; | 1048 return false; |
1048 } | 1049 } |
1049 | 1050 |
1050 NetworkInterface::NetworkInterface() | 1051 NetworkInterface::NetworkInterface() |
1051 : type(NetworkChangeNotifier::CONNECTION_UNKNOWN), prefix_length(0) { | 1052 : type(NetworkChangeNotifier::CONNECTION_UNKNOWN), prefix_length(0) { |
1052 } | 1053 } |
1053 | 1054 |
1054 NetworkInterface::NetworkInterface(const std::string& name, | 1055 NetworkInterface::NetworkInterface(const std::string& name, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 | 1090 |
1090 unsigned MaskPrefixLength(const IPAddressNumber& mask) { | 1091 unsigned MaskPrefixLength(const IPAddressNumber& mask) { |
1091 IPAddressNumber all_ones(mask.size(), 0xFF); | 1092 IPAddressNumber all_ones(mask.size(), 0xFF); |
1092 return CommonPrefixLength(mask, all_ones); | 1093 return CommonPrefixLength(mask, all_ones); |
1093 } | 1094 } |
1094 | 1095 |
1095 ScopedWifiOptions::~ScopedWifiOptions() { | 1096 ScopedWifiOptions::~ScopedWifiOptions() { |
1096 } | 1097 } |
1097 | 1098 |
1098 } // namespace net | 1099 } // namespace net |
OLD | NEW |