OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <unicode/ucnv.h> | 9 #include <unicode/ucnv.h> |
10 #include <unicode/uidna.h> | 10 #include <unicode/uidna.h> |
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 inline bool IsHostCharAlpha(char c) { | 954 inline bool IsHostCharAlpha(char c) { |
955 // We can just check lowercase because uppercase characters have already been | 955 // We can just check lowercase because uppercase characters have already been |
956 // normalized. | 956 // normalized. |
957 return (c >= 'a') && (c <= 'z'); | 957 return (c >= 'a') && (c <= 'z'); |
958 } | 958 } |
959 | 959 |
960 inline bool IsHostCharDigit(char c) { | 960 inline bool IsHostCharDigit(char c) { |
961 return (c >= '0') && (c <= '9'); | 961 return (c >= '0') && (c <= '9'); |
962 } | 962 } |
963 | 963 |
964 bool IsCanonicalizedHostRFC1738Compliant(const std::string& host) { | 964 bool IsCanonicalizedHostCompliant(const std::string& host) { |
965 if (host.empty()) | 965 if (host.empty()) |
966 return false; | 966 return false; |
967 | 967 |
968 enum State { | 968 enum State { |
969 NOT_IN_COMPONENT, | 969 NOT_IN_COMPONENT, |
970 IN_COMPONENT_STARTED_DIGIT, | 970 IN_COMPONENT_STARTED_DIGIT, |
971 IN_COMPONENT_STARTED_ALPHA | 971 IN_COMPONENT_STARTED_ALPHA |
972 } state = NOT_IN_COMPONENT; | 972 } state = NOT_IN_COMPONENT; |
973 bool last_char_was_hyphen = false; | 973 bool last_char_was_hyphen_or_underscore = false; |
974 | 974 |
975 for (std::string::const_iterator i(host.begin()); i != host.end(); ++i) { | 975 for (std::string::const_iterator i(host.begin()); i != host.end(); ++i) { |
976 const char c = *i; | 976 const char c = *i; |
977 if (state == NOT_IN_COMPONENT) { | 977 if (state == NOT_IN_COMPONENT) { |
978 if (IsHostCharDigit(c)) | 978 if (IsHostCharDigit(c)) |
979 state = IN_COMPONENT_STARTED_DIGIT; | 979 state = IN_COMPONENT_STARTED_DIGIT; |
980 else if (IsHostCharAlpha(c)) | 980 else if (IsHostCharAlpha(c)) |
981 state = IN_COMPONENT_STARTED_ALPHA; | 981 state = IN_COMPONENT_STARTED_ALPHA; |
982 else | 982 else |
983 return false; | 983 return false; |
984 } else { | 984 } else { |
985 if (c == '.') { | 985 if (c == '.') { |
986 if (last_char_was_hyphen) | 986 if (last_char_was_hyphen_or_underscore) |
987 return false; | 987 return false; |
988 state = NOT_IN_COMPONENT; | 988 state = NOT_IN_COMPONENT; |
989 } else if (IsHostCharAlpha(c) || IsHostCharDigit(c)) { | 989 } else if (IsHostCharAlpha(c) || IsHostCharDigit(c)) { |
990 last_char_was_hyphen = false; | 990 last_char_was_hyphen_or_underscore = false; |
991 } else if (c == '-') { | 991 } else if ((c == '-') || (c == '_')) { |
992 last_char_was_hyphen = true; | 992 last_char_was_hyphen_or_underscore = true; |
993 } else { | 993 } else { |
994 return false; | 994 return false; |
995 } | 995 } |
996 } | 996 } |
997 } | 997 } |
998 | 998 |
999 return state == IN_COMPONENT_STARTED_ALPHA; | 999 return state == IN_COMPONENT_STARTED_ALPHA; |
1000 } | 1000 } |
1001 | 1001 |
1002 std::string GetDirectoryListingEntry(const string16& name, | 1002 std::string GetDirectoryListingEntry(const string16& name, |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1451 if (length > 0) | 1451 if (length > 0) |
1452 ports.insert(StringToInt(WideToASCII( | 1452 ports.insert(StringToInt(WideToASCII( |
1453 allowed_ports.substr(last, length)))); | 1453 allowed_ports.substr(last, length)))); |
1454 last = i + 1; | 1454 last = i + 1; |
1455 } | 1455 } |
1456 } | 1456 } |
1457 explicitly_allowed_ports = ports; | 1457 explicitly_allowed_ports = ports; |
1458 } | 1458 } |
1459 | 1459 |
1460 } // namespace net | 1460 } // namespace net |
OLD | NEW |