| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 << "', but type '" << ValueTypeToString(signature.onc_type) | 89 << "', but type '" << ValueTypeToString(signature.onc_type) |
| 90 << "' is required."; | 90 << "' is required."; |
| 91 error_or_warning_found_ = *error = true; | 91 error_or_warning_found_ = *error = true; |
| 92 return scoped_ptr<base::Value>(); | 92 return scoped_ptr<base::Value>(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 scoped_ptr<base::Value> repaired = | 95 scoped_ptr<base::Value> repaired = |
| 96 Mapper::MapValue(signature, onc_value, error); | 96 Mapper::MapValue(signature, onc_value, error); |
| 97 if (repaired) | 97 if (repaired) |
| 98 CHECK_EQ(repaired->GetType(), signature.onc_type); | 98 CHECK_EQ(repaired->GetType(), signature.onc_type); |
| 99 return repaired.Pass(); | 99 return repaired; |
| 100 } | 100 } |
| 101 | 101 |
| 102 scoped_ptr<base::DictionaryValue> Validator::MapObject( | 102 scoped_ptr<base::DictionaryValue> Validator::MapObject( |
| 103 const OncValueSignature& signature, | 103 const OncValueSignature& signature, |
| 104 const base::DictionaryValue& onc_object, | 104 const base::DictionaryValue& onc_object, |
| 105 bool* error) { | 105 bool* error) { |
| 106 scoped_ptr<base::DictionaryValue> repaired(new base::DictionaryValue); | 106 scoped_ptr<base::DictionaryValue> repaired(new base::DictionaryValue); |
| 107 | 107 |
| 108 bool valid = ValidateObjectDefault(signature, onc_object, repaired.get()); | 108 bool valid = ValidateObjectDefault(signature, onc_object, repaired.get()); |
| 109 if (valid) { | 109 if (valid) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 138 } else if (&signature == &kProxyLocationSignature) { | 138 } else if (&signature == &kProxyLocationSignature) { |
| 139 valid = ValidateProxyLocation(repaired.get()); | 139 valid = ValidateProxyLocation(repaired.get()); |
| 140 } else if (&signature == &kEAPSignature) { | 140 } else if (&signature == &kEAPSignature) { |
| 141 valid = ValidateEAP(repaired.get()); | 141 valid = ValidateEAP(repaired.get()); |
| 142 } else if (&signature == &kCertificateSignature) { | 142 } else if (&signature == &kCertificateSignature) { |
| 143 valid = ValidateCertificate(repaired.get()); | 143 valid = ValidateCertificate(repaired.get()); |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 | 146 |
| 147 if (valid) { | 147 if (valid) { |
| 148 return repaired.Pass(); | 148 return repaired; |
| 149 } else { | 149 } else { |
| 150 DCHECK(error_or_warning_found_); | 150 DCHECK(error_or_warning_found_); |
| 151 error_or_warning_found_ = *error = true; | 151 error_or_warning_found_ = *error = true; |
| 152 return scoped_ptr<base::DictionaryValue>(); | 152 return scoped_ptr<base::DictionaryValue>(); |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 | 155 |
| 156 scoped_ptr<base::Value> Validator::MapField( | 156 scoped_ptr<base::Value> Validator::MapField( |
| 157 const std::string& field_name, | 157 const std::string& field_name, |
| 158 const OncValueSignature& object_signature, | 158 const OncValueSignature& object_signature, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 170 if (current_field_unknown) { | 170 if (current_field_unknown) { |
| 171 error_or_warning_found_ = *found_unknown_field = true; | 171 error_or_warning_found_ = *found_unknown_field = true; |
| 172 std::string message = MessageHeader() + "Field name '" + field_name + | 172 std::string message = MessageHeader() + "Field name '" + field_name + |
| 173 "' is unknown."; | 173 "' is unknown."; |
| 174 if (error_on_unknown_field_) | 174 if (error_on_unknown_field_) |
| 175 LOG(ERROR) << message; | 175 LOG(ERROR) << message; |
| 176 else | 176 else |
| 177 LOG(WARNING) << message; | 177 LOG(WARNING) << message; |
| 178 } | 178 } |
| 179 | 179 |
| 180 return result.Pass(); | 180 return result; |
| 181 } | 181 } |
| 182 | 182 |
| 183 scoped_ptr<base::ListValue> Validator::MapArray( | 183 scoped_ptr<base::ListValue> Validator::MapArray( |
| 184 const OncValueSignature& array_signature, | 184 const OncValueSignature& array_signature, |
| 185 const base::ListValue& onc_array, | 185 const base::ListValue& onc_array, |
| 186 bool* nested_error) { | 186 bool* nested_error) { |
| 187 bool nested_error_in_current_array = false; | 187 bool nested_error_in_current_array = false; |
| 188 scoped_ptr<base::ListValue> result = Mapper::MapArray( | 188 scoped_ptr<base::ListValue> result = Mapper::MapArray( |
| 189 array_signature, onc_array, &nested_error_in_current_array); | 189 array_signature, onc_array, &nested_error_in_current_array); |
| 190 | 190 |
| 191 // Drop individual networks and certificates instead of rejecting all of | 191 // Drop individual networks and certificates instead of rejecting all of |
| 192 // the configuration. | 192 // the configuration. |
| 193 if (nested_error_in_current_array && | 193 if (nested_error_in_current_array && |
| 194 &array_signature != &kNetworkConfigurationListSignature && | 194 &array_signature != &kNetworkConfigurationListSignature && |
| 195 &array_signature != &kCertificateListSignature) { | 195 &array_signature != &kCertificateListSignature) { |
| 196 *nested_error = nested_error_in_current_array; | 196 *nested_error = nested_error_in_current_array; |
| 197 } | 197 } |
| 198 return result.Pass(); | 198 return result; |
| 199 } | 199 } |
| 200 | 200 |
| 201 scoped_ptr<base::Value> Validator::MapEntry(int index, | 201 scoped_ptr<base::Value> Validator::MapEntry(int index, |
| 202 const OncValueSignature& signature, | 202 const OncValueSignature& signature, |
| 203 const base::Value& onc_value, | 203 const base::Value& onc_value, |
| 204 bool* error) { | 204 bool* error) { |
| 205 std::string str = base::IntToString(index); | 205 std::string str = base::IntToString(index); |
| 206 path_.push_back(str); | 206 path_.push_back(str); |
| 207 scoped_ptr<base::Value> result = | 207 scoped_ptr<base::Value> result = |
| 208 Mapper::MapEntry(index, signature, onc_value, error); | 208 Mapper::MapEntry(index, signature, onc_value, error); |
| 209 DCHECK_EQ(str, path_.back()); | 209 DCHECK_EQ(str, path_.back()); |
| 210 path_.pop_back(); | 210 path_.pop_back(); |
| 211 return result.Pass(); | 211 return result; |
| 212 } | 212 } |
| 213 | 213 |
| 214 bool Validator::ValidateObjectDefault(const OncValueSignature& signature, | 214 bool Validator::ValidateObjectDefault(const OncValueSignature& signature, |
| 215 const base::DictionaryValue& onc_object, | 215 const base::DictionaryValue& onc_object, |
| 216 base::DictionaryValue* result) { | 216 base::DictionaryValue* result) { |
| 217 bool found_unknown_field = false; | 217 bool found_unknown_field = false; |
| 218 bool nested_error_occured = false; | 218 bool nested_error_occured = false; |
| 219 MapFields(signature, onc_object, &found_unknown_field, &nested_error_occured, | 219 MapFields(signature, onc_object, &found_unknown_field, &nested_error_occured, |
| 220 result); | 220 result); |
| 221 | 221 |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 } | 1030 } |
| 1031 | 1031 |
| 1032 std::string Validator::MessageHeader() { | 1032 std::string Validator::MessageHeader() { |
| 1033 std::string path = path_.empty() ? "toplevel" : base::JoinString(path_, "."); | 1033 std::string path = path_.empty() ? "toplevel" : base::JoinString(path_, "."); |
| 1034 std::string message = "At " + path + ": "; | 1034 std::string message = "At " + path + ": "; |
| 1035 return message; | 1035 return message; |
| 1036 } | 1036 } |
| 1037 | 1037 |
| 1038 } // namespace onc | 1038 } // namespace onc |
| 1039 } // namespace chromeos | 1039 } // namespace chromeos |
| OLD | NEW |