Chromium Code Reviews| Index: chrome/browser/chromeos/cros/onc_network_parser.h |
| =================================================================== |
| --- chrome/browser/chromeos/cros/onc_network_parser.h (revision 112277) |
| +++ chrome/browser/chromeos/cros/onc_network_parser.h (working copy) |
| @@ -10,6 +10,7 @@ |
| #include "base/compiler_specific.h" // for OVERRIDE |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/values.h" |
| #include "chrome/browser/chromeos/cros/network_parser.h" |
| namespace base { |
| @@ -20,6 +21,17 @@ |
| namespace chromeos { |
| +// This is a simple representation of the signature of an ONC typed |
| +// field, used in validation and translation. It could be extended |
| +// to include more complex rules of when the field is required/optional, |
| +// as well as to handle "enum" types, which are strings with a small |
| +// static set of possible values. |
| +struct OncValueSignature { |
| + const char* field; |
| + PropertyIndex property; |
| + base::Value::Type type; |
| +}; |
| + |
| // This is the network parser that parses the data from an Open Network |
| // Configuration (ONC) file. ONC files are in JSON format that describes |
| // networks. We will use this parser to parse the ONC JSON blob. |
| @@ -52,6 +64,11 @@ |
| const std::string& parse_error() const { return parse_error_; } |
| protected: |
| + typedef bool (*ParserPointer)(OncNetworkParser*, |
| + PropertyIndex, |
| + const base::Value&, |
| + Network*); |
| + |
| OncNetworkParser(); |
| virtual Network* CreateNewNetwork(ConnectionType type, |
| @@ -66,6 +83,13 @@ |
| // Returns the GUID string from the dictionary of network values. |
| std::string GetGuidFromDictionary(const base::DictionaryValue& info); |
| + // Parses a nested ONC object with the given mapper and parser function. |
|
Mattias Nissler (ping if slow)
2011/12/01 13:09:10
You should mention how it handles errors and such.
kmixter1
2011/12/01 19:48:41
Done.
|
| + bool ParseNestedObject(Network* network, |
| + const std::string& onc_type, |
| + const base::Value& value, |
| + OncValueSignature* signature, |
| + ParserPointer parser); |
| + |
| private: |
| bool ParseServerOrCaCertificate( |
| int cert_index, |
| @@ -105,16 +129,22 @@ |
| const base::Value& value, |
| Network* network) OVERRIDE; |
| protected: |
| - bool ParseEAPValue(PropertyIndex index, |
| - const base::Value& value, |
| - WifiNetwork* wifi_network); |
| - ConnectionSecurity ParseSecurity(const std::string& security); |
| - EAPMethod ParseEAPMethod(const std::string& method); |
| - EAPPhase2Auth ParseEAPPhase2Auth(const std::string& auth); |
| + static bool ParseWifiValue(OncNetworkParser* parser, |
| + PropertyIndex index, |
| + const base::Value& value, |
| + Network* wifi_network); |
| + static bool ParseEAPValue(OncNetworkParser* parser, |
| + PropertyIndex index, |
| + const base::Value& value, |
| + Network* wifi_network); |
| + static ConnectionSecurity ParseSecurity(const std::string& security); |
| + static EAPMethod ParseEAPMethod(const std::string& method); |
| + static EAPPhase2Auth ParseEAPPhase2Auth(const std::string& auth); |
| private: |
| DISALLOW_COPY_AND_ASSIGN(OncWifiNetworkParser); |
| }; |
| +// Base for virtual private networks. |
| class OncVirtualNetworkParser : public OncNetworkParser { |
| public: |
| OncVirtualNetworkParser(); |
| @@ -125,10 +155,25 @@ |
| virtual bool UpdateNetworkFromInfo( |
| const base::DictionaryValue& info, Network* network) OVERRIDE; |
| protected: |
| - bool ParseProviderValue(PropertyIndex index, |
| - const base::Value& value, |
| - VirtualNetwork* network); |
| + static bool ParseIPsecValue(OncNetworkParser* parser, |
| + PropertyIndex index, |
| + const base::Value& value, |
| + Network* network); |
| + static bool ParseL2TPValue(OncNetworkParser* parser, |
| + PropertyIndex index, |
| + const base::Value& value, |
| + Network* network); |
| + static bool ParseOpenVPNValue(OncNetworkParser* parser, |
| + PropertyIndex index, |
| + const base::Value& value, |
| + Network* network); |
| + static bool ParseVPNValue(OncNetworkParser* parser, |
| + PropertyIndex index, |
| + const base::Value& value, |
| + Network* network); |
| ProviderType ParseProviderType(const std::string& type); |
| + ProviderType UpdateProviderTypeWithAuth(ProviderType provider, |
| + const std::string& auth_type); |
| private: |
| DISALLOW_COPY_AND_ASSIGN(OncVirtualNetworkParser); |
| }; |