OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <algorithm> | 5 #include <algorithm> |
6 #include <map> | 6 #include <map> |
7 #include <unicode/ucnv.h> | 7 #include <unicode/ucnv.h> |
8 #include <unicode/uidna.h> | 8 #include <unicode/uidna.h> |
9 #include <unicode/ulocdata.h> | 9 #include <unicode/ulocdata.h> |
10 #include <unicode/uniset.h> | 10 #include <unicode/uniset.h> |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 new_parsed->query.begin += kViewSourceLengthPlus1; | 742 new_parsed->query.begin += kViewSourceLengthPlus1; |
743 if (new_parsed->ref.is_nonempty()) | 743 if (new_parsed->ref.is_nonempty()) |
744 new_parsed->ref.begin += kViewSourceLengthPlus1; | 744 new_parsed->ref.begin += kViewSourceLengthPlus1; |
745 return result; | 745 return result; |
746 } | 746 } |
747 | 747 |
748 } // namespace | 748 } // namespace |
749 | 749 |
750 namespace net { | 750 namespace net { |
751 | 751 |
| 752 std::set<int> explicitly_allowed_ports; |
| 753 |
752 // Appends the substring |in_component| inside of the URL |spec| to |output|, | 754 // Appends the substring |in_component| inside of the URL |spec| to |output|, |
753 // and the resulting range will be filled into |out_component|. |unescape_rules| | 755 // and the resulting range will be filled into |out_component|. |unescape_rules| |
754 // defines how to clean the URL for human readability. | 756 // defines how to clean the URL for human readability. |
755 static void AppendFormattedComponent(const std::string& spec, | 757 static void AppendFormattedComponent(const std::string& spec, |
756 const url_parse::Component& in_component, | 758 const url_parse::Component& in_component, |
757 UnescapeRule::Type unescape_rules, | 759 UnescapeRule::Type unescape_rules, |
758 std::wstring* output, | 760 std::wstring* output, |
759 url_parse::Component* out_component); | 761 url_parse::Component* out_component); |
760 | 762 |
761 GURL FilePathToFileURL(const FilePath& path) { | 763 GURL FilePathToFileURL(const FilePath& path) { |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 int array_size = arraysize(kAllowedFtpPorts); | 1036 int array_size = arraysize(kAllowedFtpPorts); |
1035 for (int i = 0; i < array_size; i++) { | 1037 for (int i = 0; i < array_size; i++) { |
1036 if (kAllowedFtpPorts[i] == port) { | 1038 if (kAllowedFtpPorts[i] == port) { |
1037 return true; | 1039 return true; |
1038 } | 1040 } |
1039 } | 1041 } |
1040 // Port not explicitly allowed by FTP, so return the default restrictions. | 1042 // Port not explicitly allowed by FTP, so return the default restrictions. |
1041 return IsPortAllowedByDefault(port); | 1043 return IsPortAllowedByDefault(port); |
1042 } | 1044 } |
1043 | 1045 |
| 1046 bool IsPortAllowedByOverride(int port) { |
| 1047 if (explicitly_allowed_ports.empty()) |
| 1048 return false; |
| 1049 |
| 1050 std::set<int>::const_iterator it = |
| 1051 std::find(explicitly_allowed_ports.begin(), |
| 1052 explicitly_allowed_ports.end(), |
| 1053 port); |
| 1054 |
| 1055 return it != explicitly_allowed_ports.end(); |
| 1056 } |
| 1057 |
1044 int SetNonBlocking(int fd) { | 1058 int SetNonBlocking(int fd) { |
1045 #if defined(OS_WIN) | 1059 #if defined(OS_WIN) |
1046 unsigned long no_block = 1; | 1060 unsigned long no_block = 1; |
1047 return ioctlsocket(fd, FIONBIO, &no_block); | 1061 return ioctlsocket(fd, FIONBIO, &no_block); |
1048 #elif defined(OS_POSIX) | 1062 #elif defined(OS_POSIX) |
1049 int flags = fcntl(fd, F_GETFL, 0); | 1063 int flags = fcntl(fd, F_GETFL, 0); |
1050 if (-1 == flags) | 1064 if (-1 == flags) |
1051 flags = 0; | 1065 flags = 0; |
1052 return fcntl(fd, F_SETFL, flags | O_NONBLOCK); | 1066 return fcntl(fd, F_SETFL, flags | O_NONBLOCK); |
1053 #endif | 1067 #endif |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1309 | 1323 |
1310 GURL SimplifyUrlForRequest(const GURL& url) { | 1324 GURL SimplifyUrlForRequest(const GURL& url) { |
1311 DCHECK(url.is_valid()); | 1325 DCHECK(url.is_valid()); |
1312 GURL::Replacements replacements; | 1326 GURL::Replacements replacements; |
1313 replacements.ClearUsername(); | 1327 replacements.ClearUsername(); |
1314 replacements.ClearPassword(); | 1328 replacements.ClearPassword(); |
1315 replacements.ClearRef(); | 1329 replacements.ClearRef(); |
1316 return url.ReplaceComponents(replacements); | 1330 return url.ReplaceComponents(replacements); |
1317 } | 1331 } |
1318 | 1332 |
| 1333 // Specifies a comma separated list of port numbers that should be accepted |
| 1334 // despite bans. If the string is invalid no allowed ports are stored. |
| 1335 void SetExplicitlyAllowedPorts(const std::wstring& allowed_ports) { |
| 1336 if (allowed_ports.empty()) |
| 1337 return; |
| 1338 |
| 1339 std::set<int> ports; |
| 1340 size_t last = 0; |
| 1341 size_t size = allowed_ports.size(); |
| 1342 // The comma delimiter. |
| 1343 const std::wstring::value_type kComma = L','; |
| 1344 |
| 1345 // Overflow is still possible for evil user inputs. |
| 1346 for (size_t i = 0; i <= size; ++i) { |
| 1347 // The string should be composed of only digits and commas. |
| 1348 if (i != size && !IsAsciiDigit(allowed_ports[i]) && |
| 1349 (allowed_ports[i] != kComma)) |
| 1350 return; |
| 1351 if (i == size || allowed_ports[i] == kComma) { |
| 1352 size_t length = i - last; |
| 1353 if (length > 0) |
| 1354 ports.insert(StringToInt(WideToASCII( |
| 1355 allowed_ports.substr(last, length)))); |
| 1356 last = i + 1; |
| 1357 } |
| 1358 } |
| 1359 explicitly_allowed_ports = ports; |
| 1360 } |
| 1361 |
1319 } // namespace net | 1362 } // namespace net |
OLD | NEW |