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 "chromeos/network/onc/onc_validator.h" | 5 #include "chromeos/network/onc/onc_validator.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 all_required_exist &= RequireField(*result, kPKCS12); | 1015 all_required_exist &= RequireField(*result, kPKCS12); |
1016 else if (type == kServer || type == kAuthority) | 1016 else if (type == kServer || type == kAuthority) |
1017 all_required_exist &= RequireField(*result, kX509); | 1017 all_required_exist &= RequireField(*result, kX509); |
1018 | 1018 |
1019 return !error_on_missing_field_ || all_required_exist; | 1019 return !error_on_missing_field_ || all_required_exist; |
1020 } | 1020 } |
1021 | 1021 |
1022 bool Validator::ValidateTether(base::DictionaryValue* result) { | 1022 bool Validator::ValidateTether(base::DictionaryValue* result) { |
1023 using namespace ::onc::tether; | 1023 using namespace ::onc::tether; |
1024 | 1024 |
1025 int batteryPercentage; | 1025 int battery_percentage; |
1026 if (!result->GetIntegerWithoutPathExpansion(kBatteryPercentage, | 1026 if (!result->GetIntegerWithoutPathExpansion(kBatteryPercentage, |
1027 &batteryPercentage) || | 1027 &battery_percentage) || |
1028 batteryPercentage < 0 || batteryPercentage > 100) { | 1028 battery_percentage < 0 || battery_percentage > 100) { |
1029 // Battery percentage must be present and within [0, 100]. | 1029 // Battery percentage must be present and within [0, 100]. |
1030 error_or_warning_found_ = true; | 1030 error_or_warning_found_ = true; |
1031 return false; | 1031 return false; |
1032 } | 1032 } |
1033 | 1033 |
1034 int signalStrength; | 1034 int signal_strength; |
1035 if (!result->GetIntegerWithoutPathExpansion(kSignalStrength, | 1035 if (!result->GetIntegerWithoutPathExpansion(kSignalStrength, |
1036 &signalStrength) || | 1036 &signal_strength) || |
1037 signalStrength < 0 || signalStrength > 100) { | 1037 signal_strength < 0 || signal_strength > 100) { |
1038 // Signal strength must be present and within [0, 100]. | 1038 // Signal strength must be present and within [0, 100]. |
1039 error_or_warning_found_ = true; | 1039 error_or_warning_found_ = true; |
1040 return false; | 1040 return false; |
1041 } | 1041 } |
1042 | 1042 |
1043 std::string carrier; | 1043 std::string carrier; |
1044 if (!result->GetStringWithoutPathExpansion(kCarrier, &carrier) || | 1044 if (!result->GetStringWithoutPathExpansion(kCarrier, &carrier) || |
1045 carrier.empty()) { | 1045 carrier.empty()) { |
1046 // Carrier must be a non-empty string. | 1046 // Carrier must be a non-empty string. |
1047 error_or_warning_found_ = true; | 1047 error_or_warning_found_ = true; |
1048 return false; | 1048 return false; |
1049 } | 1049 } |
1050 | 1050 |
1051 // No required fields. | 1051 bool all_required_exist = RequireField(*result, kHasConnectedToHost); |
1052 return true; | 1052 if (!all_required_exist) { |
| 1053 error_or_warning_found_ = true; |
| 1054 } |
| 1055 |
| 1056 return !error_on_missing_field_ || all_required_exist; |
1053 } | 1057 } |
1054 | 1058 |
1055 std::string Validator::MessageHeader() { | 1059 std::string Validator::MessageHeader() { |
1056 std::string path = path_.empty() ? "toplevel" : base::JoinString(path_, "."); | 1060 std::string path = path_.empty() ? "toplevel" : base::JoinString(path_, "."); |
1057 std::string message = "At " + path + ": "; | 1061 std::string message = "At " + path + ": "; |
1058 return message; | 1062 return message; |
1059 } | 1063 } |
1060 | 1064 |
1061 } // namespace onc | 1065 } // namespace onc |
1062 } // namespace chromeos | 1066 } // namespace chromeos |
OLD | NEW |