| 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 index;
|
| + 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.
|
| @@ -28,6 +40,11 @@
|
| // chromiumos-design-docs/open-network-configuration
|
| class OncNetworkParser : public NetworkParser {
|
| public:
|
| + typedef bool (*ParserPointer)(OncNetworkParser*,
|
| + PropertyIndex,
|
| + const base::Value&,
|
| + Network*);
|
| +
|
| explicit OncNetworkParser(const std::string& onc_blob);
|
| virtual ~OncNetworkParser();
|
| static const EnumMapper<PropertyIndex>* property_mapper();
|
| @@ -49,6 +66,15 @@
|
| virtual Network* CreateNetworkFromInfo(const std::string& service_path,
|
| const base::DictionaryValue& info) OVERRIDE;
|
|
|
| + // Parses a nested ONC object with the given mapper and parser function.
|
| + // If Value is not the proper type or there is an error in parsing
|
| + // any individual field, VLOGs diagnostics, and returns false.
|
| + bool ParseNestedObject(Network* network,
|
| + const std::string& onc_type,
|
| + const base::Value& value,
|
| + OncValueSignature* signature,
|
| + ParserPointer parser);
|
| +
|
| const std::string& parse_error() const { return parse_error_; }
|
|
|
| protected:
|
| @@ -66,6 +92,29 @@
|
| // Returns the GUID string from the dictionary of network values.
|
| std::string GetGuidFromDictionary(const base::DictionaryValue& info);
|
|
|
| + // Parse a field's value in the NetworkConfiguration object.
|
| + static bool ParseNetworkConfigurationValue(OncNetworkParser* parser,
|
| + PropertyIndex index,
|
| + const base::Value& value,
|
| + Network* network);
|
| +
|
| + // Issue a diagnostic and return false if a type mismatch is found.
|
| + static bool CheckNetworkType(Network* network,
|
| + ConnectionType expected,
|
| + const std::string& onc_type);
|
| +
|
| + // Return the string value of |value|. If not a string, returns empty
|
| + // string.
|
| + static std::string GetStringValue(const base::Value& value);
|
| +
|
| + // Return the boolean value of |value|. If not a boolean, returns false.
|
| + static const bool GetBooleanValue(const base::Value& value);
|
| +
|
| + // Convert the value of |value| to its string representation. Integers
|
| + // convert to base10 strings, bools convert to true/false. Strings
|
| + // remains as is.
|
| + static std::string ConvertValueToString(const base::Value& value);
|
| +
|
| private:
|
| bool ParseServerOrCaCertificate(
|
| int cert_index,
|
| @@ -90,45 +139,75 @@
|
| public:
|
| OncWirelessNetworkParser();
|
| virtual ~OncWirelessNetworkParser();
|
| - virtual bool ParseValue(PropertyIndex index,
|
| - const base::Value& value,
|
| - Network* network) OVERRIDE;
|
| +
|
| private:
|
| DISALLOW_COPY_AND_ASSIGN(OncWirelessNetworkParser);
|
| };
|
|
|
| +// Class for parsing Wi-Fi networks.
|
| class OncWifiNetworkParser : public OncWirelessNetworkParser {
|
| public:
|
| OncWifiNetworkParser();
|
| virtual ~OncWifiNetworkParser();
|
| - virtual bool ParseValue(PropertyIndex index,
|
| - const base::Value& value,
|
| - Network* network) OVERRIDE;
|
| + static bool ParseWifiValue(OncNetworkParser* parser,
|
| + PropertyIndex index,
|
| + const base::Value& value,
|
| + Network* wifi_network);
|
| +
|
| 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 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);
|
| };
|
|
|
| +// Class for parsing virtual private networks.
|
| class OncVirtualNetworkParser : public OncNetworkParser {
|
| public:
|
| OncVirtualNetworkParser();
|
| virtual ~OncVirtualNetworkParser();
|
| - virtual bool ParseValue(PropertyIndex index,
|
| - const base::Value& value,
|
| - Network* network) OVERRIDE;
|
| virtual bool UpdateNetworkFromInfo(
|
| const base::DictionaryValue& info, Network* network) OVERRIDE;
|
| + static bool ParseVPNValue(OncNetworkParser* parser,
|
| + PropertyIndex index,
|
| + const base::Value& value,
|
| + Network* network);
|
| +
|
| + // network_library combines provider type and authentication type
|
| + // (L2TP-IPsec with PSK vs with Certificates). This function
|
| + // takes a provider type and adds an authentication type to return
|
| + // the updated provider type.
|
| + static ProviderType UpdateProviderTypeWithAuthType(
|
| + ProviderType provider,
|
| + const std::string& auth_type);
|
| +
|
| + // This function takes a provider type (which includes authentication
|
| + // type) and returns the canonical provider type from it. For instance
|
| + // for L2TP-IPsec, the PSK provider type is the canonical one.
|
| + static ProviderType GetCanonicalProviderType(ProviderType provider_type);
|
| +
|
| + static ProviderType ParseProviderType(const std::string& type);
|
| +
|
| protected:
|
| - bool ParseProviderValue(PropertyIndex index,
|
| - const base::Value& value,
|
| - VirtualNetwork* network);
|
| - ProviderType ParseProviderType(const std::string& type);
|
| + 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);
|
| +
|
| private:
|
| DISALLOW_COPY_AND_ASSIGN(OncVirtualNetworkParser);
|
| };
|
|
|