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

Unified Diff: chrome/browser/chromeos/cros/onc_network_parser.h

Issue 8759014: Add ONC VPN support for OpenVPN and L2TP/IPsec VPNs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: tiny tweak to error message Created 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/cros/onc_network_parser.h
===================================================================
--- chrome/browser/chromeos/cros/onc_network_parser.h (revision 112958)
+++ 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,17 @@
// 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);
+
private:
bool ParseServerOrCaCertificate(
int cert_index,
@@ -90,45 +127,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);
};

Powered by Google App Engine
This is Rietveld 408576698