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

Side by Side 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: '' 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_
6 #define CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_ 6 #define CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/compiler_specific.h" // for OVERRIDE 11 #include "base/compiler_specific.h" // for OVERRIDE
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/values.h"
13 #include "chrome/browser/chromeos/cros/network_parser.h" 14 #include "chrome/browser/chromeos/cros/network_parser.h"
14 15
15 namespace base { 16 namespace base {
16 class DictionaryValue; 17 class DictionaryValue;
17 class ListValue; 18 class ListValue;
18 class Value; 19 class Value;
19 } 20 }
20 21
21 namespace chromeos { 22 namespace chromeos {
22 23
24 // This is a simple representation of the signature of an ONC typed
25 // field, used in validation and translation. It could be extended
26 // to include more complex rules of when the field is required/optional,
27 // as well as to handle "enum" types, which are strings with a small
28 // static set of possible values.
29 struct OncValueSignature {
30 const char* field;
31 PropertyIndex index;
32 base::Value::Type type;
33 };
34
23 // This is the network parser that parses the data from an Open Network 35 // This is the network parser that parses the data from an Open Network
24 // Configuration (ONC) file. ONC files are in JSON format that describes 36 // Configuration (ONC) file. ONC files are in JSON format that describes
25 // networks. We will use this parser to parse the ONC JSON blob. 37 // networks. We will use this parser to parse the ONC JSON blob.
26 // 38 //
27 // For ONC file format, see: http://dev.chromium.org/chromium-os/ 39 // For ONC file format, see: http://dev.chromium.org/chromium-os/
28 // chromiumos-design-docs/open-network-configuration 40 // chromiumos-design-docs/open-network-configuration
29 class OncNetworkParser : public NetworkParser { 41 class OncNetworkParser : public NetworkParser {
30 public: 42 public:
43 typedef bool (*ParserPointer)(OncNetworkParser*,
44 PropertyIndex,
45 const base::Value&,
46 Network*);
47
31 explicit OncNetworkParser(const std::string& onc_blob); 48 explicit OncNetworkParser(const std::string& onc_blob);
32 virtual ~OncNetworkParser(); 49 virtual ~OncNetworkParser();
33 static const EnumMapper<PropertyIndex>* property_mapper(); 50 static const EnumMapper<PropertyIndex>* property_mapper();
34 51
35 // Returns the number of networks in the "NetworkConfigs" list. 52 // Returns the number of networks in the "NetworkConfigs" list.
36 int GetNetworkConfigsSize() const; 53 int GetNetworkConfigsSize() const;
37 54
38 // Returns the number of certificates in the "Certificates" list. 55 // Returns the number of certificates in the "Certificates" list.
39 int GetCertificatesSize() const; 56 int GetCertificatesSize() const;
40 57
41 // Call to create the network by parsing network config in the nth position. 58 // Call to create the network by parsing network config in the nth position.
42 // (0-based). Returns NULL if there's a parse error or if n is out of range. 59 // (0-based). Returns NULL if there's a parse error or if n is out of range.
43 Network* ParseNetwork(int n); 60 Network* ParseNetwork(int n);
44 61
45 // Call to parse and import the nth certificate in the certificate 62 // Call to parse and import the nth certificate in the certificate
46 // list. Returns false on failure. 63 // list. Returns false on failure.
47 bool ParseCertificate(int n); 64 bool ParseCertificate(int n);
48 65
49 virtual Network* CreateNetworkFromInfo(const std::string& service_path, 66 virtual Network* CreateNetworkFromInfo(const std::string& service_path,
50 const base::DictionaryValue& info) OVERRIDE; 67 const base::DictionaryValue& info) OVERRIDE;
51 68
69 // Parses a nested ONC object with the given mapper and parser function.
70 // If Value is not the proper type or there is an error in parsing
71 // any individual field, VLOGs diagnostics, and returns false.
72 bool ParseNestedObject(Network* network,
73 const std::string& onc_type,
74 const base::Value& value,
75 OncValueSignature* signature,
76 ParserPointer parser);
77
52 const std::string& parse_error() const { return parse_error_; } 78 const std::string& parse_error() const { return parse_error_; }
53 79
54 protected: 80 protected:
55 OncNetworkParser(); 81 OncNetworkParser();
56 82
57 virtual Network* CreateNewNetwork(ConnectionType type, 83 virtual Network* CreateNewNetwork(ConnectionType type,
58 const std::string& service_path) OVERRIDE; 84 const std::string& service_path) OVERRIDE;
59 virtual ConnectionType ParseType(const std::string& type) OVERRIDE; 85 virtual ConnectionType ParseType(const std::string& type) OVERRIDE;
60 virtual ConnectionType ParseTypeFromDictionary( 86 virtual ConnectionType ParseTypeFromDictionary(
61 const base::DictionaryValue& info) OVERRIDE; 87 const base::DictionaryValue& info) OVERRIDE;
62 88
63 // Returns the type string from the dictionary of network values. 89 // Returns the type string from the dictionary of network values.
64 std::string GetTypeFromDictionary(const base::DictionaryValue& info); 90 std::string GetTypeFromDictionary(const base::DictionaryValue& info);
65 91
66 // Returns the GUID string from the dictionary of network values. 92 // Returns the GUID string from the dictionary of network values.
67 std::string GetGuidFromDictionary(const base::DictionaryValue& info); 93 std::string GetGuidFromDictionary(const base::DictionaryValue& info);
68 94
95 // Parse a field's value in the NetworkConfiguration object.
96 static bool ParseNetworkConfigurationValue(OncNetworkParser* parser,
97 PropertyIndex index,
98 const base::Value& value,
99 Network* network);
100
69 private: 101 private:
70 bool ParseServerOrCaCertificate( 102 bool ParseServerOrCaCertificate(
71 int cert_index, 103 int cert_index,
72 const std::string& cert_type, 104 const std::string& cert_type,
73 base::DictionaryValue* certificate); 105 base::DictionaryValue* certificate);
74 bool ParseClientCertificate( 106 bool ParseClientCertificate(
75 int cert_index, 107 int cert_index,
76 base::DictionaryValue* certificate); 108 base::DictionaryValue* certificate);
77 109
78 // Error message from the JSON parser, if applicable. 110 // Error message from the JSON parser, if applicable.
79 std::string parse_error_; 111 std::string parse_error_;
80 112
81 scoped_ptr<base::DictionaryValue> root_dict_; 113 scoped_ptr<base::DictionaryValue> root_dict_;
82 base::ListValue* network_configs_; 114 base::ListValue* network_configs_;
83 base::ListValue* certificates_; 115 base::ListValue* certificates_;
84 116
85 DISALLOW_COPY_AND_ASSIGN(OncNetworkParser); 117 DISALLOW_COPY_AND_ASSIGN(OncNetworkParser);
86 }; 118 };
87 119
88 // Base for wireless networks. 120 // Base for wireless networks.
89 class OncWirelessNetworkParser : public OncNetworkParser { 121 class OncWirelessNetworkParser : public OncNetworkParser {
90 public: 122 public:
91 OncWirelessNetworkParser(); 123 OncWirelessNetworkParser();
92 virtual ~OncWirelessNetworkParser(); 124 virtual ~OncWirelessNetworkParser();
93 virtual bool ParseValue(PropertyIndex index,
94 const base::Value& value,
95 Network* network) OVERRIDE;
96 private: 125 private:
97 DISALLOW_COPY_AND_ASSIGN(OncWirelessNetworkParser); 126 DISALLOW_COPY_AND_ASSIGN(OncWirelessNetworkParser);
98 }; 127 };
99 128
100 class OncWifiNetworkParser : public OncWirelessNetworkParser { 129 class OncWifiNetworkParser : public OncWirelessNetworkParser {
101 public: 130 public:
102 OncWifiNetworkParser(); 131 OncWifiNetworkParser();
103 virtual ~OncWifiNetworkParser(); 132 virtual ~OncWifiNetworkParser();
104 virtual bool ParseValue(PropertyIndex index, 133 static bool ParseWifiValue(OncNetworkParser* parser,
105 const base::Value& value, 134 PropertyIndex index,
106 Network* network) OVERRIDE; 135 const base::Value& value,
136 Network* wifi_network);
Mattias Nissler (ping if slow) 2011/12/02 12:23:30 nit: as far as my experience goes, we mostly put n
kmixter1 2011/12/03 00:20:34 Done.
107 protected: 137 protected:
108 bool ParseEAPValue(PropertyIndex index, 138 static bool ParseEAPValue(OncNetworkParser* parser,
109 const base::Value& value, 139 PropertyIndex index,
110 WifiNetwork* wifi_network); 140 const base::Value& value,
111 ConnectionSecurity ParseSecurity(const std::string& security); 141 Network* wifi_network);
112 EAPMethod ParseEAPMethod(const std::string& method); 142 static ConnectionSecurity ParseSecurity(const std::string& security);
113 EAPPhase2Auth ParseEAPPhase2Auth(const std::string& auth); 143 static EAPMethod ParseEAPMethod(const std::string& method);
144 static EAPPhase2Auth ParseEAPPhase2Auth(const std::string& auth);
114 private: 145 private:
115 DISALLOW_COPY_AND_ASSIGN(OncWifiNetworkParser); 146 DISALLOW_COPY_AND_ASSIGN(OncWifiNetworkParser);
116 }; 147 };
117 148
149 // Base for virtual private networks.
Mattias Nissler (ping if slow) 2011/12/02 12:23:30 nit: Is it really a base class?
kmixter1 2011/12/03 00:20:34 Done.
118 class OncVirtualNetworkParser : public OncNetworkParser { 150 class OncVirtualNetworkParser : public OncNetworkParser {
119 public: 151 public:
120 OncVirtualNetworkParser(); 152 OncVirtualNetworkParser();
121 virtual ~OncVirtualNetworkParser(); 153 virtual ~OncVirtualNetworkParser();
122 virtual bool ParseValue(PropertyIndex index,
123 const base::Value& value,
124 Network* network) OVERRIDE;
125 virtual bool UpdateNetworkFromInfo( 154 virtual bool UpdateNetworkFromInfo(
126 const base::DictionaryValue& info, Network* network) OVERRIDE; 155 const base::DictionaryValue& info, Network* network) OVERRIDE;
156 static bool ParseVPNValue(OncNetworkParser* parser,
157 PropertyIndex index,
158 const base::Value& value,
159 Network* network);
Mattias Nissler (ping if slow) 2011/12/02 12:23:30 newline before start of comment
kmixter1 2011/12/03 00:20:34 Done.
160 // network_library combines provider type and authentication type
161 // (L2TP-IPsec with PSK vs with Certificates). This function
162 // takes a provider type and adds an authentication type to return
163 // the updated provider type.
164 static ProviderType UpdateProviderTypeWithAuthType(
165 ProviderType provider,
166 const std::string& auth_type);
Mattias Nissler (ping if slow) 2011/12/02 12:23:30 ditto
kmixter1 2011/12/03 00:20:34 Done.
167 // This function takes a provider type (which includes authentication
168 // type) and returns the canonical provider type from it. For instance
169 // for L2TP-IPsec, the PSK provider type is the canonical one.
170 static ProviderType GetCanonicalProviderType(ProviderType provider_type);
171
172 static ProviderType ParseProviderType(const std::string& type);
127 protected: 173 protected:
128 bool ParseProviderValue(PropertyIndex index, 174 static bool ParseIPsecValue(OncNetworkParser* parser,
129 const base::Value& value, 175 PropertyIndex index,
130 VirtualNetwork* network); 176 const base::Value& value,
131 ProviderType ParseProviderType(const std::string& type); 177 Network* network);
178 static bool ParseL2TPValue(OncNetworkParser* parser,
179 PropertyIndex index,
180 const base::Value& value,
181 Network* network);
182 static bool ParseOpenVPNValue(OncNetworkParser* parser,
183 PropertyIndex index,
184 const base::Value& value,
185 Network* network);
132 private: 186 private:
133 DISALLOW_COPY_AND_ASSIGN(OncVirtualNetworkParser); 187 DISALLOW_COPY_AND_ASSIGN(OncVirtualNetworkParser);
134 }; 188 };
135 189
136 } // namespace chromeos 190 } // namespace chromeos
137 191
138 #endif // CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_ 192 #endif // CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698