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

Unified 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: Addressed comments. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/network_settings/onc_validator.h
diff --git a/chrome/browser/chromeos/network_settings/onc_validator.h b/chrome/browser/chromeos/network_settings/onc_validator.h
new file mode 100644
index 0000000000000000000000000000000000000000..fb9929e1daf72e74cab723f111c948caf67dae1a
--- /dev/null
+++ b/chrome/browser/chromeos/network_settings/onc_validator.h
@@ -0,0 +1,139 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_
+#define CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/chromeos/network_settings/onc_mapper.h"
+
+namespace base {
+class Value;
+class DictionaryValue;
+}
+
+namespace chromeos {
+namespace onc {
+
+struct OncValueSignature;
+
+class Validator : public Mapper {
+ public:
+ // Creates a Validator with the following options:
+ // - It is an error if |error_on_unknown_field| is true and a field name is
+ // found that is not part of the signature.
+ // - It is an error if |error_on_wrong_recommended| is true and a kRecommended
+ // array contains a field name that is not part of the enclosing object's
+ // signature.
+ // - It is an error if |error_on_missing_field| is true and a required field
+ // is missing.
+ // Any error stops the validation. Only if no error occurs, a "repaired"
+ // object is created that contains all but the problematic fields and values.
+ // Also, kRecommended fields are removed if managed_onc is false.
+ Validator(bool error_on_unknown_field,
+ bool error_on_wrong_recommended,
+ bool error_on_missing_field,
+ bool managed_onc);
+
+ virtual ~Validator();
+
+ // Validate the given |onc_object| according to |object_signature|. The
+ // |object_signature| has to be a pointer to one of the signatures in
+ // |onc_signature.h|. If possible (no error encountered) a DeepCopy is created
+ // that contains all but the problematic fields and values and returns this
+ // "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.
+ scoped_ptr<base::DictionaryValue> ValidateAndRepairObject(
+ const OncValueSignature* object_signature,
+ const base::DictionaryValue& onc_object);
+
+ private:
+ // Overriden from Mapper:
+ // Compare |onc_value|s type with |onc_type| and validate/repair according to
+ // |signature|. On error returns NULL.
+ virtual scoped_ptr<base::Value> MapValue(
+ const OncValueSignature& signature,
+ const base::Value& onc_value) OVERRIDE;
+
+ // Dispatch to the right validation function according to
+ // |signature|. Iterates over all fields and recursively validates/repairs
+ // these. All valid fields are added to the result dictionary. Returns the
+ // repaired dictionary. On error returns NULL.
+ virtual scoped_ptr<base::DictionaryValue> MapObject(
+ const OncValueSignature& signature,
+ const base::DictionaryValue& onc_object) OVERRIDE;
+
+ // This is the default validation of objects/dictionaries. Validates
+ // |onc_object| according to |object_signature|. |result| must point to a
+ // dictionary into which the repaired fields are written.
+ bool ValidateObjectDefault(
+ const OncValueSignature& object_signature,
+ const base::DictionaryValue& onc_object,
+ base::DictionaryValue* result);
+
+ // Validates/repairs the kRecommended array in |result| according to
+ // |object_signature| of the enclosing object.
+ bool ValidateRecommendedField(
+ const OncValueSignature& object_signature,
+ base::DictionaryValue* result);
+
+ bool ValidateNetworkConfiguration(
+ const base::DictionaryValue& onc_object,
+ base::DictionaryValue* result);
+
+ bool ValidateEthernet(
+ const base::DictionaryValue& onc_object,
+ base::DictionaryValue* result);
+
+ bool ValidateIPConfig(
+ const base::DictionaryValue& onc_object,
+ base::DictionaryValue* result);
+
+ bool ValidateWiFi(
+ const base::DictionaryValue& onc_object,
+ base::DictionaryValue* result);
+
+ bool ValidateVPN(
+ const base::DictionaryValue& onc_object,
+ base::DictionaryValue* result);
+
+ bool ValidateIPsec(
+ const base::DictionaryValue& onc_object,
+ base::DictionaryValue* result);
+
+ bool ValidateOpenVPN(
+ const base::DictionaryValue& onc_object,
+ base::DictionaryValue* result);
+
+ bool ValidateCertificatePattern(
+ const base::DictionaryValue& onc_object,
+ base::DictionaryValue* result);
+
+ bool ValidateProxySettings(
+ const base::DictionaryValue& onc_object,
+ base::DictionaryValue* result);
+
+ bool ValidateProxyLocation(
+ const base::DictionaryValue& onc_object,
+ base::DictionaryValue* result);
+
+ bool ValidateEAP(
+ const base::DictionaryValue& onc_object,
+ base::DictionaryValue* result);
+
+ bool ValidateCertificate(
+ const base::DictionaryValue& onc_object,
+ base::DictionaryValue* result);
+
+ const bool error_on_unknown_field_;
+ const bool error_on_wrong_recommended_;
+ const bool error_on_missing_field_;
+ const bool managed_onc_;
+
+ DISALLOW_COPY_AND_ASSIGN(Validator);
+};
+
+} // namespace onc
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_

Powered by Google App Engine
This is Rietveld 408576698