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

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: Completed validator for complete ONC. Integrated into OncNetworkParser. 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 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 // - It is an error if |managed_onc| is false and a kRecommended field is set.
32 // Any error stops the validation. Only if no error occurs, a repaired object
33 // is created that contains all but the problematic fields and values.
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 // Shortcut to create a strict validator: every error option is true.
42 static scoped_ptr<Validator> CreateStrictValidator(bool managed_onc);
43 // Shortcut to create a liberal validator: every error option is false.
44 static scoped_ptr<Validator> CreateLiberalValidator(bool managed_onc);
Mattias Nissler (ping if slow) 2012/11/02 10:10:00 I think you only ever use these convenience helper
pneubeck (no reviews) 2012/11/05 12:04:48 Done.
45
46 // Validate and repair the given |onc_object| according to
47 // |object_signature|. The |object_signature| has to be a pointer to one of
48 // the signatures in |onc_signature.h|. If repair is possible (no error
49 // encountered), returns the repaired object, otherwise returns NULL.
Mattias Nissler (ping if slow) 2012/11/02 10:10:00 What exactly does this "repair"?
pneubeck (no reviews) 2012/11/05 12:04:48 Done.
50 scoped_ptr<base::DictionaryValue> ValidateAndRepairObject(
51 const OncValueSignature* object_signature,
52 const base::DictionaryValue& onc_object);
53
54 private:
55 // Overriden from Mapper:
56 // Compare |onc_value|s type with |onc_type| and validate/repair according to
57 // |signature|. On error returns NULL.
58 virtual scoped_ptr<base::Value> MapValue(
59 const OncValueSignature& signature,
60 const base::Value& onc_value) OVERRIDE;
61
62 // Dispatch to the right validation function according to
63 // |signature|. Iterates over all fields and recursively validates/repairs
64 // these. All valid fields are added to the result dictionary. Returns the
65 // repaired dictionary. On error returns NULL.
66 virtual scoped_ptr<base::DictionaryValue> MapObject(
67 const OncValueSignature& signature,
68 const base::DictionaryValue& onc_object) OVERRIDE;
69
70 // This is the default validation of objects/dictionaries. Validates
71 // |onc_object| according to |object_signature|. |result| must point to a
72 // dictionary into which the repaired fields are written.
73 bool ValidateObjectDefault(
74 const OncValueSignature& object_signature,
75 const base::DictionaryValue& onc_object,
76 base::DictionaryValue* result);
77
78 // Validates/repairs the kRecommended array in |result| according to
79 // |object_signature| of the enclosing object.
80 bool ValidateRecommendedField(
81 const OncValueSignature& object_signature,
82 base::DictionaryValue* result);
83
84 bool ValidateNetworkConfiguration(
85 const base::DictionaryValue& onc_object,
86 base::DictionaryValue* result);
87
88 bool ValidateEthernet(
89 const base::DictionaryValue& onc_object,
90 base::DictionaryValue* result);
91
92 bool ValidateIPConfig(
93 const base::DictionaryValue& onc_object,
94 base::DictionaryValue* result);
95
96 bool ValidateWiFi(
97 const base::DictionaryValue& onc_object,
98 base::DictionaryValue* result);
99
100 bool ValidateVPN(
101 const base::DictionaryValue& onc_object,
102 base::DictionaryValue* result);
103
104 bool ValidateIPsec(
105 const base::DictionaryValue& onc_object,
106 base::DictionaryValue* result);
107
108 bool ValidateOpenVPN(
109 const base::DictionaryValue& onc_object,
110 base::DictionaryValue* result);
111
112 bool ValidateCertificatePattern(
113 const base::DictionaryValue& onc_object,
114 base::DictionaryValue* result);
115
116 bool ValidateProxySettings(
117 const base::DictionaryValue& onc_object,
118 base::DictionaryValue* result);
119
120 bool ValidateProxyLocation(
121 const base::DictionaryValue& onc_object,
122 base::DictionaryValue* result);
123
124 bool ValidateEAP(
125 const base::DictionaryValue& onc_object,
126 base::DictionaryValue* result);
127
128 bool ValidateCertificate(
129 const base::DictionaryValue& onc_object,
130 base::DictionaryValue* result);
131
132 const bool error_on_unknown_field_;
133 const bool error_on_wrong_recommended_;
134 const bool error_on_missing_field_;
135 const bool managed_onc_;
136
137 DISALLOW_COPY_AND_ASSIGN(Validator);
138 };
139
140 } // namespace onc
141 } // namespace chromeos
142
143 #endif // CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698