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

Unified 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, 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
index cee5d07e4a242356c681ab19e96253e27375dc90..2859e96899274ecb9c2a628ca917bdc962485afe 100644
--- a/chrome/browser/chromeos/network_settings/onc_validator.h
+++ b/chrome/browser/chromeos/network_settings/onc_validator.h
@@ -5,7 +5,12 @@
#ifndef CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_
#define CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_
+#include <sstream>
+#include <vector>
+
#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_vector.h"
+#include "base/string16.h"
#include "chrome/browser/chromeos/network_settings/onc_mapper.h"
namespace base {
@@ -58,15 +63,17 @@ class Validator : public Mapper {
// For details, see the comment at the Constructor.
scoped_ptr<base::DictionaryValue> ValidateAndRepairObject(
const OncValueSignature* object_signature,
- const base::DictionaryValue& onc_object);
+ const base::DictionaryValue& onc_object,
+ std::string* messages);
private:
- // Overriden from Mapper:
+ // Overridden 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;
+ const base::Value& onc_value,
+ bool* error) OVERRIDE;
// Dispatch to the right validation function according to
// |signature|. Iterates over all fields and recursively validates/repairs
@@ -74,7 +81,23 @@ class Validator : public Mapper {
// repaired dictionary. On error returns NULL.
virtual scoped_ptr<base::DictionaryValue> MapObject(
const OncValueSignature& signature,
- const base::DictionaryValue& onc_object) OVERRIDE;
+ const base::DictionaryValue& onc_object,
+ bool* error) OVERRIDE;
+
+ // Pushes/pops the |field_name| to |path_|, otherwise like |Mapper::MapField|.
+ virtual scoped_ptr<base::Value> MapField(
+ const std::string& field_name,
+ const OncValueSignature& object_signature,
+ const base::Value& onc_value,
+ bool* found_unknown_field,
+ bool* error) OVERRIDE;
+
+ // Pushes/pops the index to |path_|, otherwise like |Mapper::MapEntry|.
+ virtual scoped_ptr<base::Value> MapEntry(
+ int index,
+ const OncValueSignature& signature,
+ const base::Value& onc_value,
+ bool* error) OVERRIDE;
// This is the default validation of objects/dictionaries. Validates
// |onc_object| according to |object_signature|. |result| must point to a
@@ -90,6 +113,10 @@ class Validator : public Mapper {
const OncValueSignature& object_signature,
base::DictionaryValue* result);
+ bool ValidateToplevelConfiguration(
+ const base::DictionaryValue& onc_object,
+ base::DictionaryValue* result);
+
bool ValidateNetworkConfiguration(
const base::DictionaryValue& onc_object,
base::DictionaryValue* result);
@@ -138,11 +165,36 @@ class Validator : public Mapper {
const base::DictionaryValue& onc_object,
base::DictionaryValue* result);
+ bool FieldExistsAndHasNoValueOf(const base::DictionaryValue& object,
+ const std::string &field_name,
+ const char** valid_values);
+
+ bool FieldExistsAndIsNotInRange(const base::DictionaryValue& object,
+ const std::string &field_name,
+ int lower_bound,
+ int upper_bound);
+
+ bool RequireField(const base::DictionaryValue& dict, const std::string& key);
+
+ void AddWarning(const std::string& msg);
+ void AddError(const std::string& msg);
+ void AddMessage(bool is_error, const std::string& msg);
+
+ std::string JoinMessages();
+
const bool error_on_unknown_field_;
const bool error_on_wrong_recommended_;
const bool error_on_missing_field_;
const bool managed_onc_;
+ // The path of field names and indices to the current value. Indices
+ // are stored as strings in decimal notation.
+ std::vector<std::string> path_;
+
+ // A list of warning/error messages accumulated up to the current entry.
+ // ScopedVector<std::ostringstream> messages_;
+ std::vector<std::string> messages_;
+
DISALLOW_COPY_AND_ASSIGN(Validator);
};

Powered by Google App Engine
This is Rietveld 408576698