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

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

Issue 11415148: Adding error handling to ONC validation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@extract_onc_certificate
Patch Set: Initial patch. Created 8 years 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
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 CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_
6 #define CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_ 6 #define CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_
7 7
8 #include <sstream>
9 #include <vector>
10
8 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/string16.h"
9 #include "chrome/browser/chromeos/network_settings/onc_mapper.h" 14 #include "chrome/browser/chromeos/network_settings/onc_mapper.h"
10 15
11 namespace base { 16 namespace base {
12 class Value; 17 class Value;
13 class DictionaryValue; 18 class DictionaryValue;
14 } 19 }
15 20
16 namespace chromeos { 21 namespace chromeos {
17 namespace onc { 22 namespace onc {
18 23
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // |onc_signature.h|. If an error is found, the function returns NULL. If 56 // |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 57 // possible (no error encountered) a DeepCopy is created that contains all but
53 // the invalid fields and values and returns this "repaired" object. 58 // the invalid fields and values and returns this "repaired" object.
54 // That means, if not handled as an error, then the following are ignored: 59 // That means, if not handled as an error, then the following are ignored:
55 // - unknown fields 60 // - unknown fields
56 // - invalid field names in kRecommended arrays 61 // - invalid field names in kRecommended arrays
57 // - kRecommended fields in an unmanaged ONC 62 // - kRecommended fields in an unmanaged ONC
58 // For details, see the comment at the Constructor. 63 // For details, see the comment at the Constructor.
59 scoped_ptr<base::DictionaryValue> ValidateAndRepairObject( 64 scoped_ptr<base::DictionaryValue> ValidateAndRepairObject(
60 const OncValueSignature* object_signature, 65 const OncValueSignature* object_signature,
61 const base::DictionaryValue& onc_object); 66 const base::DictionaryValue& onc_object,
67 std::string* messages);
62 68
63 private: 69 private:
64 // Overriden from Mapper: 70 // Overridden from Mapper:
65 // Compare |onc_value|s type with |onc_type| and validate/repair according to 71 // Compare |onc_value|s type with |onc_type| and validate/repair according to
66 // |signature|. On error returns NULL. 72 // |signature|. On error returns NULL.
67 virtual scoped_ptr<base::Value> MapValue( 73 virtual scoped_ptr<base::Value> MapValue(
68 const OncValueSignature& signature, 74 const OncValueSignature& signature,
69 const base::Value& onc_value) OVERRIDE; 75 const base::Value& onc_value,
76 bool* error) OVERRIDE;
70 77
71 // Dispatch to the right validation function according to 78 // Dispatch to the right validation function according to
72 // |signature|. Iterates over all fields and recursively validates/repairs 79 // |signature|. Iterates over all fields and recursively validates/repairs
73 // these. All valid fields are added to the result dictionary. Returns the 80 // these. All valid fields are added to the result dictionary. Returns the
74 // repaired dictionary. On error returns NULL. 81 // repaired dictionary. On error returns NULL.
75 virtual scoped_ptr<base::DictionaryValue> MapObject( 82 virtual scoped_ptr<base::DictionaryValue> MapObject(
76 const OncValueSignature& signature, 83 const OncValueSignature& signature,
77 const base::DictionaryValue& onc_object) OVERRIDE; 84 const base::DictionaryValue& onc_object,
85 bool* error) OVERRIDE;
86
87 // Pushes/pops the |field_name| to |path_|, otherwise like |Mapper::MapField|.
88 virtual scoped_ptr<base::Value> MapField(
89 const std::string& field_name,
90 const OncValueSignature& object_signature,
91 const base::Value& onc_value,
92 bool* found_unknown_field,
93 bool* error) OVERRIDE;
94
95 // Pushes/pops the index to |path_|, otherwise like |Mapper::MapEntry|.
96 virtual scoped_ptr<base::Value> MapEntry(
97 int index,
98 const OncValueSignature& signature,
99 const base::Value& onc_value,
100 bool* error) OVERRIDE;
78 101
79 // This is the default validation of objects/dictionaries. Validates 102 // This is the default validation of objects/dictionaries. Validates
80 // |onc_object| according to |object_signature|. |result| must point to a 103 // |onc_object| according to |object_signature|. |result| must point to a
81 // dictionary into which the repaired fields are written. 104 // dictionary into which the repaired fields are written.
82 bool ValidateObjectDefault( 105 bool ValidateObjectDefault(
83 const OncValueSignature& object_signature, 106 const OncValueSignature& object_signature,
84 const base::DictionaryValue& onc_object, 107 const base::DictionaryValue& onc_object,
85 base::DictionaryValue* result); 108 base::DictionaryValue* result);
86 109
87 // Validates/repairs the kRecommended array in |result| according to 110 // Validates/repairs the kRecommended array in |result| according to
88 // |object_signature| of the enclosing object. 111 // |object_signature| of the enclosing object.
89 bool ValidateRecommendedField( 112 bool ValidateRecommendedField(
90 const OncValueSignature& object_signature, 113 const OncValueSignature& object_signature,
91 base::DictionaryValue* result); 114 base::DictionaryValue* result);
92 115
116 bool ValidateToplevelConfiguration(
117 const base::DictionaryValue& onc_object,
118 base::DictionaryValue* result);
119
93 bool ValidateNetworkConfiguration( 120 bool ValidateNetworkConfiguration(
94 const base::DictionaryValue& onc_object, 121 const base::DictionaryValue& onc_object,
95 base::DictionaryValue* result); 122 base::DictionaryValue* result);
96 123
97 bool ValidateEthernet( 124 bool ValidateEthernet(
98 const base::DictionaryValue& onc_object, 125 const base::DictionaryValue& onc_object,
99 base::DictionaryValue* result); 126 base::DictionaryValue* result);
100 127
101 bool ValidateIPConfig( 128 bool ValidateIPConfig(
102 const base::DictionaryValue& onc_object, 129 const base::DictionaryValue& onc_object,
(...skipping 28 matching lines...) Expand all
131 base::DictionaryValue* result); 158 base::DictionaryValue* result);
132 159
133 bool ValidateEAP( 160 bool ValidateEAP(
134 const base::DictionaryValue& onc_object, 161 const base::DictionaryValue& onc_object,
135 base::DictionaryValue* result); 162 base::DictionaryValue* result);
136 163
137 bool ValidateCertificate( 164 bool ValidateCertificate(
138 const base::DictionaryValue& onc_object, 165 const base::DictionaryValue& onc_object,
139 base::DictionaryValue* result); 166 base::DictionaryValue* result);
140 167
168 bool FieldExistsAndHasNoValueOf(const base::DictionaryValue& object,
169 const std::string &field_name,
170 const char** valid_values);
171
172 bool FieldExistsAndIsNotInRange(const base::DictionaryValue& object,
173 const std::string &field_name,
174 int lower_bound,
175 int upper_bound);
176
177 bool RequireField(const base::DictionaryValue& dict, const std::string& key);
178
179 void AddWarning(const std::string& msg);
180 void AddError(const std::string& msg);
181 void AddMessage(bool is_error, const std::string& msg);
182
183 std::string JoinMessages();
184
141 const bool error_on_unknown_field_; 185 const bool error_on_unknown_field_;
142 const bool error_on_wrong_recommended_; 186 const bool error_on_wrong_recommended_;
143 const bool error_on_missing_field_; 187 const bool error_on_missing_field_;
144 const bool managed_onc_; 188 const bool managed_onc_;
145 189
190 // The path of field names and indices to the current value. Indices
191 // are stored as strings in decimal notation.
192 std::vector<std::string> path_;
193
194 // A list of warning/error messages accumulated up to the current entry.
195 // ScopedVector<std::ostringstream> messages_;
196 std::vector<std::string> messages_;
197
146 DISALLOW_COPY_AND_ASSIGN(Validator); 198 DISALLOW_COPY_AND_ASSIGN(Validator);
147 }; 199 };
148 200
149 } // namespace onc 201 } // namespace onc
150 } // namespace chromeos 202 } // namespace chromeos
151 203
152 #endif // CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_ 204 #endif // CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698