Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_ | |
| 7 | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "chrome/browser/chromeos/network_settings/onc_mapper.h" | |
| 10 | |
| 11 namespace base { | |
| 12 class Value; | |
| 13 class DictionaryValue; | |
| 14 } | |
| 15 | |
| 16 namespace chromeos { | |
| 17 namespace onc { | |
| 18 | |
| 19 struct OncValueSignature; | |
| 20 | |
| 21 class Validator : public Mapper { | |
| 22 public: | |
| 23 // Creates a Validator with the following options: | |
| 24 // - It is an error if |error_on_unknown_field| is true and a field name is | |
| 25 // found that is not part of the signature. | |
| 26 // - It is an error if |error_on_wrong_recommended| is true and a kRecommended | |
| 27 // array contains a field name that is not part of the enclosing object's | |
| 28 // signature. | |
| 29 // - It is an error if |error_on_missing_field| is true and a required field | |
| 30 // is missing. | |
| 31 // Any error stops the validation. Only if no error occurs, a "repaired" | |
| 32 // object is created that contains all but the problematic fields and values. | |
| 33 // Also, kRecommended fields are removed if managed_onc is false. | |
| 34 Validator(bool error_on_unknown_field, | |
| 35 bool error_on_wrong_recommended, | |
| 36 bool error_on_missing_field, | |
| 37 bool managed_onc); | |
| 38 | |
| 39 virtual ~Validator(); | |
| 40 | |
| 41 // Validate the given |onc_object| according to |object_signature|. The | |
| 42 // |object_signature| has to be a pointer to one of the signatures in | |
| 43 // |onc_signature.h|. If possible (no error encountered) a DeepCopy is created | |
| 44 // that contains all but the problematic fields and values and returns this | |
| 45 // "repaired" object. Otherwise, on error, returns NULL. | |
|
Mattias Nissler (ping if slow)
2012/11/06 09:30:56
This still doesn't make it very clear what "repair
pneubeck (no reviews)
2012/11/06 13:32:22
Done.
| |
| 46 scoped_ptr<base::DictionaryValue> ValidateAndRepairObject( | |
| 47 const OncValueSignature* object_signature, | |
| 48 const base::DictionaryValue& onc_object); | |
| 49 | |
| 50 private: | |
| 51 // Overriden from Mapper: | |
| 52 // Compare |onc_value|s type with |onc_type| and validate/repair according to | |
| 53 // |signature|. On error returns NULL. | |
| 54 virtual scoped_ptr<base::Value> MapValue( | |
| 55 const OncValueSignature& signature, | |
| 56 const base::Value& onc_value) OVERRIDE; | |
| 57 | |
| 58 // Dispatch to the right validation function according to | |
| 59 // |signature|. Iterates over all fields and recursively validates/repairs | |
| 60 // these. All valid fields are added to the result dictionary. Returns the | |
| 61 // repaired dictionary. On error returns NULL. | |
| 62 virtual scoped_ptr<base::DictionaryValue> MapObject( | |
| 63 const OncValueSignature& signature, | |
| 64 const base::DictionaryValue& onc_object) OVERRIDE; | |
| 65 | |
| 66 // This is the default validation of objects/dictionaries. Validates | |
| 67 // |onc_object| according to |object_signature|. |result| must point to a | |
| 68 // dictionary into which the repaired fields are written. | |
| 69 bool ValidateObjectDefault( | |
| 70 const OncValueSignature& object_signature, | |
| 71 const base::DictionaryValue& onc_object, | |
| 72 base::DictionaryValue* result); | |
| 73 | |
| 74 // Validates/repairs the kRecommended array in |result| according to | |
| 75 // |object_signature| of the enclosing object. | |
| 76 bool ValidateRecommendedField( | |
| 77 const OncValueSignature& object_signature, | |
| 78 base::DictionaryValue* result); | |
| 79 | |
| 80 bool ValidateNetworkConfiguration( | |
| 81 const base::DictionaryValue& onc_object, | |
| 82 base::DictionaryValue* result); | |
| 83 | |
| 84 bool ValidateEthernet( | |
| 85 const base::DictionaryValue& onc_object, | |
| 86 base::DictionaryValue* result); | |
| 87 | |
| 88 bool ValidateIPConfig( | |
| 89 const base::DictionaryValue& onc_object, | |
| 90 base::DictionaryValue* result); | |
| 91 | |
| 92 bool ValidateWiFi( | |
| 93 const base::DictionaryValue& onc_object, | |
| 94 base::DictionaryValue* result); | |
| 95 | |
| 96 bool ValidateVPN( | |
| 97 const base::DictionaryValue& onc_object, | |
| 98 base::DictionaryValue* result); | |
| 99 | |
| 100 bool ValidateIPsec( | |
| 101 const base::DictionaryValue& onc_object, | |
| 102 base::DictionaryValue* result); | |
| 103 | |
| 104 bool ValidateOpenVPN( | |
| 105 const base::DictionaryValue& onc_object, | |
| 106 base::DictionaryValue* result); | |
| 107 | |
| 108 bool ValidateCertificatePattern( | |
| 109 const base::DictionaryValue& onc_object, | |
| 110 base::DictionaryValue* result); | |
| 111 | |
| 112 bool ValidateProxySettings( | |
| 113 const base::DictionaryValue& onc_object, | |
| 114 base::DictionaryValue* result); | |
| 115 | |
| 116 bool ValidateProxyLocation( | |
| 117 const base::DictionaryValue& onc_object, | |
| 118 base::DictionaryValue* result); | |
| 119 | |
| 120 bool ValidateEAP( | |
| 121 const base::DictionaryValue& onc_object, | |
| 122 base::DictionaryValue* result); | |
| 123 | |
| 124 bool ValidateCertificate( | |
| 125 const base::DictionaryValue& onc_object, | |
| 126 base::DictionaryValue* result); | |
| 127 | |
| 128 const bool error_on_unknown_field_; | |
| 129 const bool error_on_wrong_recommended_; | |
| 130 const bool error_on_missing_field_; | |
| 131 const bool managed_onc_; | |
| 132 | |
| 133 DISALLOW_COPY_AND_ASSIGN(Validator); | |
| 134 }; | |
| 135 | |
| 136 } // namespace onc | |
| 137 } // namespace chromeos | |
| 138 | |
| 139 #endif // CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_ | |
| OLD | NEW |