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 that searches for the following invalid cases: | |
24 // - a field name is found that is not part of the signature | |
25 // (controlled by |error_on_unknown_field|) | |
26 // | |
27 // - a kRecommended array contains a field name that is not part of the | |
28 // enclosing object's signature or if that field is dictionary typed | |
29 // (controlled by |error_on_wrong_recommended|) | |
30 // | |
31 // - |managed_onc| is false and a field with name kRecommended is found | |
32 // (always ignored) | |
33 // | |
34 // - a required field is missing (controlled by |error_on_missing_field|) | |
35 // | |
36 // If one of these invalid cases occurs and the controlling flag is true, then | |
37 // it is an error and the validation stops. The function | |
38 // ValidateAndRepairObject returns NULL. | |
39 // | |
40 // If no error occurred, then a DeepCopy of the validated object is created, | |
41 // which contains all but the invalid fields and values. | |
42 Validator(bool error_on_unknown_field, | |
43 bool error_on_wrong_recommended, | |
44 bool error_on_missing_field, | |
45 bool managed_onc); | |
46 | |
47 virtual ~Validator(); | |
48 | |
49 // Validate the given |onc_object| according to |object_signature|. The | |
50 // |object_signature| has to be a pointer to one of the signatures in | |
51 // |onc_signature.h|. If an error is found, the function returns NULL. If | |
52 // possible (no error encountered) a DeepCopy is created that contains all but | |
53 // the invalid fields and values and returns this "repaired" object. | |
54 // That means, if not handled as an error, then the following are ignored: | |
55 // - unknown fields | |
56 // - invalid field names in kRecommended arrays | |
57 // - kRecommended fields in an unmanaged ONC | |
58 // For details, see the comment at the Constructor. | |
59 scoped_ptr<base::DictionaryValue> ValidateAndRepairObject( | |
60 const OncValueSignature* object_signature, | |
61 const base::DictionaryValue& onc_object); | |
62 | |
63 private: | |
64 // Overriden from Mapper: | |
65 // Compare |onc_value|s type with |onc_type| and validate/repair according to | |
66 // |signature|. On error returns NULL. | |
67 virtual scoped_ptr<base::Value> MapValue( | |
68 const OncValueSignature& signature, | |
69 const base::Value& onc_value) OVERRIDE; | |
70 | |
71 // Dispatch to the right validation function according to | |
72 // |signature|. Iterates over all fields and recursively validates/repairs | |
73 // these. All valid fields are added to the result dictionary. Returns the | |
74 // repaired dictionary. On error returns NULL. | |
75 virtual scoped_ptr<base::DictionaryValue> MapObject( | |
76 const OncValueSignature& signature, | |
77 const base::DictionaryValue& onc_object) OVERRIDE; | |
78 | |
79 // This is the default validation of objects/dictionaries. Validates | |
80 // |onc_object| according to |object_signature|. |result| must point to a | |
81 // dictionary into which the repaired fields are written. | |
82 bool ValidateObjectDefault( | |
83 const OncValueSignature& object_signature, | |
84 const base::DictionaryValue& onc_object, | |
85 base::DictionaryValue* result); | |
86 | |
87 // Validates/repairs the kRecommended array in |result| according to | |
88 // |object_signature| of the enclosing object. | |
89 bool ValidateRecommendedField( | |
90 const OncValueSignature& object_signature, | |
91 base::DictionaryValue* result); | |
92 | |
93 bool ValidateNetworkConfiguration( | |
94 const base::DictionaryValue& onc_object, | |
95 base::DictionaryValue* result); | |
96 | |
97 bool ValidateEthernet( | |
98 const base::DictionaryValue& onc_object, | |
99 base::DictionaryValue* result); | |
100 | |
101 bool ValidateIPConfig( | |
102 const base::DictionaryValue& onc_object, | |
103 base::DictionaryValue* result); | |
104 | |
105 bool ValidateWiFi( | |
106 const base::DictionaryValue& onc_object, | |
107 base::DictionaryValue* result); | |
108 | |
109 bool ValidateVPN( | |
110 const base::DictionaryValue& onc_object, | |
111 base::DictionaryValue* result); | |
112 | |
113 bool ValidateIPsec( | |
114 const base::DictionaryValue& onc_object, | |
115 base::DictionaryValue* result); | |
116 | |
117 bool ValidateOpenVPN( | |
118 const base::DictionaryValue& onc_object, | |
119 base::DictionaryValue* result); | |
120 | |
121 bool ValidateCertificatePattern( | |
122 const base::DictionaryValue& onc_object, | |
123 base::DictionaryValue* result); | |
124 | |
125 bool ValidateProxySettings( | |
126 const base::DictionaryValue& onc_object, | |
127 base::DictionaryValue* result); | |
128 | |
129 bool ValidateProxyLocation( | |
130 const base::DictionaryValue& onc_object, | |
131 base::DictionaryValue* result); | |
132 | |
133 bool ValidateEAP( | |
134 const base::DictionaryValue& onc_object, | |
135 base::DictionaryValue* result); | |
136 | |
137 bool ValidateCertificate( | |
138 const base::DictionaryValue& onc_object, | |
139 base::DictionaryValue* result); | |
140 | |
141 const bool error_on_unknown_field_; | |
142 const bool error_on_wrong_recommended_; | |
143 const bool error_on_missing_field_; | |
144 const bool managed_onc_; | |
145 | |
146 DISALLOW_COPY_AND_ASSIGN(Validator); | |
147 }; | |
148 | |
149 } // namespace onc | |
150 } // namespace chromeos | |
151 | |
152 #endif // CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_ | |
OLD | NEW |