Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 property; | |
| 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: |
| 31 explicit OncNetworkParser(const std::string& onc_blob); | 43 explicit OncNetworkParser(const std::string& onc_blob); |
| 32 virtual ~OncNetworkParser(); | 44 virtual ~OncNetworkParser(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 45 // Call to parse and import the nth certificate in the certificate | 57 // Call to parse and import the nth certificate in the certificate |
| 46 // list. Returns false on failure. | 58 // list. Returns false on failure. |
| 47 bool ParseCertificate(int n); | 59 bool ParseCertificate(int n); |
| 48 | 60 |
| 49 virtual Network* CreateNetworkFromInfo(const std::string& service_path, | 61 virtual Network* CreateNetworkFromInfo(const std::string& service_path, |
| 50 const base::DictionaryValue& info) OVERRIDE; | 62 const base::DictionaryValue& info) OVERRIDE; |
| 51 | 63 |
| 52 const std::string& parse_error() const { return parse_error_; } | 64 const std::string& parse_error() const { return parse_error_; } |
| 53 | 65 |
| 54 protected: | 66 protected: |
| 67 typedef bool (*ParserPointer)(OncNetworkParser*, | |
| 68 PropertyIndex, | |
| 69 const base::Value&, | |
| 70 Network*); | |
| 71 | |
| 55 OncNetworkParser(); | 72 OncNetworkParser(); |
| 56 | 73 |
| 57 virtual Network* CreateNewNetwork(ConnectionType type, | 74 virtual Network* CreateNewNetwork(ConnectionType type, |
| 58 const std::string& service_path) OVERRIDE; | 75 const std::string& service_path) OVERRIDE; |
| 59 virtual ConnectionType ParseType(const std::string& type) OVERRIDE; | 76 virtual ConnectionType ParseType(const std::string& type) OVERRIDE; |
| 60 virtual ConnectionType ParseTypeFromDictionary( | 77 virtual ConnectionType ParseTypeFromDictionary( |
| 61 const base::DictionaryValue& info) OVERRIDE; | 78 const base::DictionaryValue& info) OVERRIDE; |
| 62 | 79 |
| 63 // Returns the type string from the dictionary of network values. | 80 // Returns the type string from the dictionary of network values. |
| 64 std::string GetTypeFromDictionary(const base::DictionaryValue& info); | 81 std::string GetTypeFromDictionary(const base::DictionaryValue& info); |
| 65 | 82 |
| 66 // Returns the GUID string from the dictionary of network values. | 83 // Returns the GUID string from the dictionary of network values. |
| 67 std::string GetGuidFromDictionary(const base::DictionaryValue& info); | 84 std::string GetGuidFromDictionary(const base::DictionaryValue& info); |
| 68 | 85 |
| 86 // 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.
| |
| 87 bool ParseNestedObject(Network* network, | |
| 88 const std::string& onc_type, | |
| 89 const base::Value& value, | |
| 90 OncValueSignature* signature, | |
| 91 ParserPointer parser); | |
| 92 | |
| 69 private: | 93 private: |
| 70 bool ParseServerOrCaCertificate( | 94 bool ParseServerOrCaCertificate( |
| 71 int cert_index, | 95 int cert_index, |
| 72 const std::string& cert_type, | 96 const std::string& cert_type, |
| 73 base::DictionaryValue* certificate); | 97 base::DictionaryValue* certificate); |
| 74 bool ParseClientCertificate( | 98 bool ParseClientCertificate( |
| 75 int cert_index, | 99 int cert_index, |
| 76 base::DictionaryValue* certificate); | 100 base::DictionaryValue* certificate); |
| 77 | 101 |
| 78 // Error message from the JSON parser, if applicable. | 102 // Error message from the JSON parser, if applicable. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 98 }; | 122 }; |
| 99 | 123 |
| 100 class OncWifiNetworkParser : public OncWirelessNetworkParser { | 124 class OncWifiNetworkParser : public OncWirelessNetworkParser { |
| 101 public: | 125 public: |
| 102 OncWifiNetworkParser(); | 126 OncWifiNetworkParser(); |
| 103 virtual ~OncWifiNetworkParser(); | 127 virtual ~OncWifiNetworkParser(); |
| 104 virtual bool ParseValue(PropertyIndex index, | 128 virtual bool ParseValue(PropertyIndex index, |
| 105 const base::Value& value, | 129 const base::Value& value, |
| 106 Network* network) OVERRIDE; | 130 Network* network) OVERRIDE; |
| 107 protected: | 131 protected: |
| 108 bool ParseEAPValue(PropertyIndex index, | 132 static bool ParseWifiValue(OncNetworkParser* parser, |
| 109 const base::Value& value, | 133 PropertyIndex index, |
| 110 WifiNetwork* wifi_network); | 134 const base::Value& value, |
| 111 ConnectionSecurity ParseSecurity(const std::string& security); | 135 Network* wifi_network); |
| 112 EAPMethod ParseEAPMethod(const std::string& method); | 136 static bool ParseEAPValue(OncNetworkParser* parser, |
| 113 EAPPhase2Auth ParseEAPPhase2Auth(const std::string& auth); | 137 PropertyIndex index, |
| 138 const base::Value& value, | |
| 139 Network* wifi_network); | |
| 140 static ConnectionSecurity ParseSecurity(const std::string& security); | |
| 141 static EAPMethod ParseEAPMethod(const std::string& method); | |
| 142 static EAPPhase2Auth ParseEAPPhase2Auth(const std::string& auth); | |
| 114 private: | 143 private: |
| 115 DISALLOW_COPY_AND_ASSIGN(OncWifiNetworkParser); | 144 DISALLOW_COPY_AND_ASSIGN(OncWifiNetworkParser); |
| 116 }; | 145 }; |
| 117 | 146 |
| 147 // Base for virtual private networks. | |
| 118 class OncVirtualNetworkParser : public OncNetworkParser { | 148 class OncVirtualNetworkParser : public OncNetworkParser { |
| 119 public: | 149 public: |
| 120 OncVirtualNetworkParser(); | 150 OncVirtualNetworkParser(); |
| 121 virtual ~OncVirtualNetworkParser(); | 151 virtual ~OncVirtualNetworkParser(); |
| 122 virtual bool ParseValue(PropertyIndex index, | 152 virtual bool ParseValue(PropertyIndex index, |
| 123 const base::Value& value, | 153 const base::Value& value, |
| 124 Network* network) OVERRIDE; | 154 Network* network) OVERRIDE; |
| 125 virtual bool UpdateNetworkFromInfo( | 155 virtual bool UpdateNetworkFromInfo( |
| 126 const base::DictionaryValue& info, Network* network) OVERRIDE; | 156 const base::DictionaryValue& info, Network* network) OVERRIDE; |
| 127 protected: | 157 protected: |
| 128 bool ParseProviderValue(PropertyIndex index, | 158 static bool ParseIPsecValue(OncNetworkParser* parser, |
| 129 const base::Value& value, | 159 PropertyIndex index, |
| 130 VirtualNetwork* network); | 160 const base::Value& value, |
| 161 Network* network); | |
| 162 static bool ParseL2TPValue(OncNetworkParser* parser, | |
| 163 PropertyIndex index, | |
| 164 const base::Value& value, | |
| 165 Network* network); | |
| 166 static bool ParseOpenVPNValue(OncNetworkParser* parser, | |
| 167 PropertyIndex index, | |
| 168 const base::Value& value, | |
| 169 Network* network); | |
| 170 static bool ParseVPNValue(OncNetworkParser* parser, | |
| 171 PropertyIndex index, | |
| 172 const base::Value& value, | |
| 173 Network* network); | |
| 131 ProviderType ParseProviderType(const std::string& type); | 174 ProviderType ParseProviderType(const std::string& type); |
| 175 ProviderType UpdateProviderTypeWithAuth(ProviderType provider, | |
| 176 const std::string& auth_type); | |
| 132 private: | 177 private: |
| 133 DISALLOW_COPY_AND_ASSIGN(OncVirtualNetworkParser); | 178 DISALLOW_COPY_AND_ASSIGN(OncVirtualNetworkParser); |
| 134 }; | 179 }; |
| 135 | 180 |
| 136 } // namespace chromeos | 181 } // namespace chromeos |
| 137 | 182 |
| 138 #endif // CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_ | 183 #endif // CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_ |
| OLD | NEW |