| 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 #ifndef CHROMEOS_NETWORK_ONC_ONC_VALIDATOR_H_ | 5 #ifndef CHROMEOS_NETWORK_ONC_ONC_VALIDATOR_H_ |
| 6 #define CHROMEOS_NETWORK_ONC_ONC_VALIDATOR_H_ | 6 #define CHROMEOS_NETWORK_ONC_ONC_VALIDATOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "chromeos/chromeos_export.h" | 12 #include "chromeos/chromeos_export.h" |
| 13 #include "chromeos/network/onc/onc_constants.h" |
| 13 #include "chromeos/network/onc/onc_mapper.h" | 14 #include "chromeos/network/onc/onc_mapper.h" |
| 14 | 15 |
| 15 namespace base { | 16 namespace base { |
| 16 class DictionaryValue; | 17 class DictionaryValue; |
| 17 class Value; | 18 class Value; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace chromeos { | 21 namespace chromeos { |
| 21 namespace onc { | 22 namespace onc { |
| 22 | 23 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 // See the class comment. | 63 // See the class comment. |
| 63 Validator(bool error_on_unknown_field, | 64 Validator(bool error_on_unknown_field, |
| 64 bool error_on_wrong_recommended, | 65 bool error_on_wrong_recommended, |
| 65 bool error_on_missing_field, | 66 bool error_on_missing_field, |
| 66 bool managed_onc); | 67 bool managed_onc); |
| 67 | 68 |
| 68 virtual ~Validator(); | 69 virtual ~Validator(); |
| 69 | 70 |
| 71 // Sets the ONC source to |source|. If not set, defaults to ONC_SOURCE_NONE. |
| 72 // If the source is set to ONC_SOURCE_DEVICE_POLICY, validation additionally |
| 73 // checks: |
| 74 // - only the network types Wifi and Ethernet are allowed |
| 75 // - client certificate patterns are disallowed |
| 76 void SetOncSource(ONCSource source) { |
| 77 onc_source_ = source; |
| 78 } |
| 79 |
| 70 // Validate the given |onc_object| according to |object_signature|. The | 80 // Validate the given |onc_object| according to |object_signature|. The |
| 71 // |object_signature| has to be a pointer to one of the signatures in | 81 // |object_signature| has to be a pointer to one of the signatures in |
| 72 // |onc_signature.h|. If an error is found, the function returns NULL and sets | 82 // |onc_signature.h|. If an error is found, the function returns NULL and sets |
| 73 // |result| to INVALID. If possible (no error encountered) a DeepCopy is | 83 // |result| to INVALID. If possible (no error encountered) a DeepCopy is |
| 74 // created that contains all but the invalid fields and values and returns | 84 // created that contains all but the invalid fields and values and returns |
| 75 // this "repaired" object. That means, if not handled as an error, then the | 85 // this "repaired" object. That means, if not handled as an error, then the |
| 76 // following are dropped from the copy: | 86 // following are dropped from the copy: |
| 77 // - unknown fields | 87 // - unknown fields |
| 78 // - invalid field names in kRecommended arrays | 88 // - invalid field names in kRecommended arrays |
| 79 // - kRecommended fields in an unmanaged ONC | 89 // - kRecommended fields in an unmanaged ONC |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 const std::string &field_name, | 205 const std::string &field_name, |
| 196 const char** valid_values); | 206 const char** valid_values); |
| 197 | 207 |
| 198 bool FieldExistsAndIsNotInRange(const base::DictionaryValue& object, | 208 bool FieldExistsAndIsNotInRange(const base::DictionaryValue& object, |
| 199 const std::string &field_name, | 209 const std::string &field_name, |
| 200 int lower_bound, | 210 int lower_bound, |
| 201 int upper_bound); | 211 int upper_bound); |
| 202 | 212 |
| 203 bool RequireField(const base::DictionaryValue& dict, const std::string& key); | 213 bool RequireField(const base::DictionaryValue& dict, const std::string& key); |
| 204 | 214 |
| 215 bool CertPatternInDevicePolicy(const std::string& cert_type); |
| 216 |
| 205 std::string WarningHeader(); | 217 std::string WarningHeader(); |
| 206 std::string ErrorHeader(); | 218 std::string ErrorHeader(); |
| 207 std::string MessageHeader(bool is_error); | 219 std::string MessageHeader(bool is_error); |
| 208 | 220 |
| 209 const bool error_on_unknown_field_; | 221 const bool error_on_unknown_field_; |
| 210 const bool error_on_wrong_recommended_; | 222 const bool error_on_wrong_recommended_; |
| 211 const bool error_on_missing_field_; | 223 const bool error_on_missing_field_; |
| 212 const bool managed_onc_; | 224 const bool managed_onc_; |
| 213 | 225 |
| 226 ONCSource onc_source_; |
| 227 |
| 214 // The path of field names and indices to the current value. Indices | 228 // The path of field names and indices to the current value. Indices |
| 215 // are stored as strings in decimal notation. | 229 // are stored as strings in decimal notation. |
| 216 std::vector<std::string> path_; | 230 std::vector<std::string> path_; |
| 217 | 231 |
| 218 // Tracks if an error or warning occurred within validation initiated by | 232 // Tracks if an error or warning occurred within validation initiated by |
| 219 // function ValidateAndRepairObject. | 233 // function ValidateAndRepairObject. |
| 220 bool error_or_warning_found_; | 234 bool error_or_warning_found_; |
| 221 | 235 |
| 222 DISALLOW_COPY_AND_ASSIGN(Validator); | 236 DISALLOW_COPY_AND_ASSIGN(Validator); |
| 223 }; | 237 }; |
| 224 | 238 |
| 225 } // namespace onc | 239 } // namespace onc |
| 226 } // namespace chromeos | 240 } // namespace chromeos |
| 227 | 241 |
| 228 #endif // CHROMEOS_NETWORK_ONC_ONC_VALIDATOR_H_ | 242 #endif // CHROMEOS_NETWORK_ONC_ONC_VALIDATOR_H_ |
| OLD | NEW |