Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: chrome/browser/chromeos/network_settings/onc_validator.h

Issue 10944009: Implementation of ONC signature, validator and normalizer. (Closed) Base URL: http://git.chromium.org/chromium/src.git@gperffix
Patch Set: Fixed minor issues. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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"
Mattias Nissler (ping if slow) 2012/11/06 13:49:19 nit: no need to break the line here?
pneubeck (no reviews) 2012/11/06 14:45:21 Done.
54 // object.
55 // That means, if not handled as an error, then the following are ignored:
56 // - unknown fields
57 // - invalid field names in kRecommended arrays
58 // - kRecommended fields in an unmanaged ONC
59 // For details, see the comment at the Constructor.
60 scoped_ptr<base::DictionaryValue> ValidateAndRepairObject(
61 const OncValueSignature* object_signature,
62 const base::DictionaryValue& onc_object);
63
64 private:
65 // Overriden from Mapper:
66 // Compare |onc_value|s type with |onc_type| and validate/repair according to
67 // |signature|. On error returns NULL.
68 virtual scoped_ptr<base::Value> MapValue(
69 const OncValueSignature& signature,
70 const base::Value& onc_value) OVERRIDE;
71
72 // Dispatch to the right validation function according to
73 // |signature|. Iterates over all fields and recursively validates/repairs
74 // these. All valid fields are added to the result dictionary. Returns the
75 // repaired dictionary. On error returns NULL.
76 virtual scoped_ptr<base::DictionaryValue> MapObject(
77 const OncValueSignature& signature,
78 const base::DictionaryValue& onc_object) OVERRIDE;
79
80 // This is the default validation of objects/dictionaries. Validates
81 // |onc_object| according to |object_signature|. |result| must point to a
82 // dictionary into which the repaired fields are written.
83 bool ValidateObjectDefault(
84 const OncValueSignature& object_signature,
85 const base::DictionaryValue& onc_object,
86 base::DictionaryValue* result);
87
88 // Validates/repairs the kRecommended array in |result| according to
89 // |object_signature| of the enclosing object.
90 bool ValidateRecommendedField(
91 const OncValueSignature& object_signature,
92 base::DictionaryValue* result);
93
94 bool ValidateNetworkConfiguration(
95 const base::DictionaryValue& onc_object,
96 base::DictionaryValue* result);
97
98 bool ValidateEthernet(
99 const base::DictionaryValue& onc_object,
100 base::DictionaryValue* result);
101
102 bool ValidateIPConfig(
103 const base::DictionaryValue& onc_object,
104 base::DictionaryValue* result);
105
106 bool ValidateWiFi(
107 const base::DictionaryValue& onc_object,
108 base::DictionaryValue* result);
109
110 bool ValidateVPN(
111 const base::DictionaryValue& onc_object,
112 base::DictionaryValue* result);
113
114 bool ValidateIPsec(
115 const base::DictionaryValue& onc_object,
116 base::DictionaryValue* result);
117
118 bool ValidateOpenVPN(
119 const base::DictionaryValue& onc_object,
120 base::DictionaryValue* result);
121
122 bool ValidateCertificatePattern(
123 const base::DictionaryValue& onc_object,
124 base::DictionaryValue* result);
125
126 bool ValidateProxySettings(
127 const base::DictionaryValue& onc_object,
128 base::DictionaryValue* result);
129
130 bool ValidateProxyLocation(
131 const base::DictionaryValue& onc_object,
132 base::DictionaryValue* result);
133
134 bool ValidateEAP(
135 const base::DictionaryValue& onc_object,
136 base::DictionaryValue* result);
137
138 bool ValidateCertificate(
139 const base::DictionaryValue& onc_object,
140 base::DictionaryValue* result);
141
142 const bool error_on_unknown_field_;
143 const bool error_on_wrong_recommended_;
144 const bool error_on_missing_field_;
145 const bool managed_onc_;
146
147 DISALLOW_COPY_AND_ASSIGN(Validator);
148 };
149
150 } // namespace onc
151 } // namespace chromeos
152
153 #endif // CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698