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 "chrome/browser/chromeos/cros/network_parser.h" | 13 #include "chrome/browser/chromeos/cros/network_parser.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 class DictionaryValue; | 16 class DictionaryValue; |
17 class ListValue; | 17 class ListValue; |
18 class Value; | 18 class Value; |
19 } | 19 } |
20 | 20 |
| 21 namespace net { |
| 22 class X509Certificate; |
| 23 } |
| 24 |
21 namespace chromeos { | 25 namespace chromeos { |
22 | 26 |
23 // This is the network parser that parses the data from an Open Network | 27 // 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 | 28 // Configuration (ONC) file. ONC files are in JSON format that describes |
25 // networks. We will use this parser to parse the ONC JSON blob. | 29 // networks. We will use this parser to parse the ONC JSON blob. |
26 // | 30 // |
27 // For ONC file format, see: http://dev.chromium.org/chromium-os/ | 31 // For ONC file format, see: http://dev.chromium.org/chromium-os/ |
28 // chromiumos-design-docs/open-network-configuration | 32 // chromiumos-design-docs/open-network-configuration |
29 class OncNetworkParser : public NetworkParser { | 33 class OncNetworkParser : public NetworkParser { |
30 public: | 34 public: |
31 explicit OncNetworkParser(const std::string& onc_blob); | 35 explicit OncNetworkParser(const std::string& onc_blob); |
32 virtual ~OncNetworkParser(); | 36 virtual ~OncNetworkParser(); |
33 static const EnumMapper<PropertyIndex>* property_mapper(); | 37 static const EnumMapper<PropertyIndex>* property_mapper(); |
34 | 38 |
35 // Returns the number of networks in the "NetworkConfigs" list. | 39 // Returns the number of networks in the "NetworkConfigs" list. |
36 int GetNetworkConfigsSize() const; | 40 int GetNetworkConfigsSize() const; |
37 | 41 |
38 // Returns the number of certificates in the "Certificates" list. | |
39 int GetCertificatesSize() const; | |
40 | |
41 // Call to create the network by parsing network config in the nth position. | 42 // 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. | 43 // (0-based). Returns NULL if there's a parse error or if n is out of range. |
43 Network* ParseNetwork(int n); | 44 Network* ParseNetwork(int n); |
44 | 45 |
| 46 // Returns the number of certificates in the "Certificates" list. |
| 47 int GetCertificatesSize() const; |
| 48 |
45 // Call to parse and import the nth certificate in the certificate | 49 // Call to parse and import the nth certificate in the certificate |
46 // list. Returns false on failure. | 50 // list into the certificate store. Returns a NULL refptr if |
47 bool ParseCertificate(int n); | 51 // there's a parse error or if n is out of range. |
| 52 scoped_refptr<net::X509Certificate> ParseCertificate(int n); |
48 | 53 |
49 virtual Network* CreateNetworkFromInfo(const std::string& service_path, | 54 virtual Network* CreateNetworkFromInfo(const std::string& service_path, |
50 const base::DictionaryValue& info) OVERRIDE; | 55 const base::DictionaryValue& info) OVERRIDE; |
51 | 56 |
52 const std::string& parse_error() const { return parse_error_; } | 57 const std::string& parse_error() const { return parse_error_; } |
53 | 58 |
54 protected: | 59 protected: |
55 OncNetworkParser(); | 60 OncNetworkParser(); |
56 | 61 |
57 virtual Network* CreateNewNetwork(ConnectionType type, | 62 virtual Network* CreateNewNetwork(ConnectionType type, |
58 const std::string& service_path) OVERRIDE; | 63 const std::string& service_path) OVERRIDE; |
59 virtual ConnectionType ParseType(const std::string& type) OVERRIDE; | 64 virtual ConnectionType ParseType(const std::string& type) OVERRIDE; |
60 virtual ConnectionType ParseTypeFromDictionary( | 65 virtual ConnectionType ParseTypeFromDictionary( |
61 const base::DictionaryValue& info) OVERRIDE; | 66 const base::DictionaryValue& info) OVERRIDE; |
62 | 67 |
63 // Returns the type string from the dictionary of network values. | 68 // Returns the type string from the dictionary of network values. |
64 std::string GetTypeFromDictionary(const base::DictionaryValue& info); | 69 std::string GetTypeFromDictionary(const base::DictionaryValue& info); |
65 | 70 |
66 private: | 71 private: |
67 bool ParseServerOrCaCertificate( | 72 scoped_refptr<net::X509Certificate> ParseServerOrCaCertificate( |
68 int cert_index, | 73 int cert_index, |
69 const std::string& cert_type, | 74 const std::string& cert_type, |
| 75 const std::string& guid, |
70 base::DictionaryValue* certificate); | 76 base::DictionaryValue* certificate); |
71 bool ParseClientCertificate( | 77 scoped_refptr<net::X509Certificate> ParseClientCertificate( |
72 int cert_index, | 78 int cert_index, |
| 79 const std::string& guid, |
73 base::DictionaryValue* certificate); | 80 base::DictionaryValue* certificate); |
74 | 81 |
75 // Error message from the JSON parser, if applicable. | 82 // Error message from the JSON parser, if applicable. |
76 std::string parse_error_; | 83 std::string parse_error_; |
77 | 84 |
78 scoped_ptr<base::DictionaryValue> root_dict_; | 85 scoped_ptr<base::DictionaryValue> root_dict_; |
79 base::ListValue* network_configs_; | 86 base::ListValue* network_configs_; |
80 base::ListValue* certificates_; | 87 base::ListValue* certificates_; |
81 | 88 |
82 DISALLOW_COPY_AND_ASSIGN(OncNetworkParser); | 89 DISALLOW_COPY_AND_ASSIGN(OncNetworkParser); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 const base::Value& value, | 133 const base::Value& value, |
127 VirtualNetwork* network); | 134 VirtualNetwork* network); |
128 ProviderType ParseProviderType(const std::string& type); | 135 ProviderType ParseProviderType(const std::string& type); |
129 private: | 136 private: |
130 DISALLOW_COPY_AND_ASSIGN(OncVirtualNetworkParser); | 137 DISALLOW_COPY_AND_ASSIGN(OncVirtualNetworkParser); |
131 }; | 138 }; |
132 | 139 |
133 } // namespace chromeos | 140 } // namespace chromeos |
134 | 141 |
135 #endif // CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_ | 142 #endif // CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_ |
OLD | NEW |