OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // The implementation of TranslateONCObjectToShill is structured in two parts: | 5 // The implementation of TranslateONCObjectToShill is structured in two parts: |
6 // - The recursion through the existing ONC hierarchy | 6 // - The recursion through the existing ONC hierarchy |
7 // see TranslateONCHierarchy | 7 // see TranslateONCHierarchy |
8 // - The local translation of an object depending on the associated signature | 8 // - The local translation of an object depending on the associated signature |
9 // see LocalTranslator::TranslateFields | 9 // see LocalTranslator::TranslateFields |
10 | 10 |
11 #include "chromeos/network/onc/onc_translator.h" | 11 #include "chromeos/network/onc/onc_translator.h" |
12 | 12 |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
16 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chromeos/network/onc/onc_constants.h" | 19 #include "chromeos/network/onc/onc_constants.h" |
20 #include "chromeos/network/onc/onc_signature.h" | 20 #include "chromeos/network/onc/onc_signature.h" |
21 #include "chromeos/network/onc/onc_translation_tables.h" | 21 #include "chromeos/network/onc/onc_translation_tables.h" |
22 #include "third_party/cros_system_api/dbus/service_constants.h" | 22 #include "third_party/cros_system_api/dbus/service_constants.h" |
23 | 23 |
24 namespace chromeos { | 24 namespace chromeos { |
25 namespace onc { | 25 namespace onc { |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 scoped_ptr<base::ListValue> SingletonStringList(const std::string& str) { | |
Greg Spencer (Chromium)
2013/06/28 18:25:50
Singleton seems misleading here: people will assum
pneubeck (no reviews)
2013/07/01 15:12:14
Done.
| |
30 base::ListValue* list = new base::ListValue; | |
31 list->AppendString(str); | |
32 return make_scoped_ptr(list); | |
33 } | |
34 | |
29 scoped_ptr<base::StringValue> ConvertValueToString(const base::Value& value) { | 35 scoped_ptr<base::StringValue> ConvertValueToString(const base::Value& value) { |
30 std::string str; | 36 std::string str; |
31 if (!value.GetAsString(&str)) | 37 if (!value.GetAsString(&str)) |
32 base::JSONWriter::Write(&value, &str); | 38 base::JSONWriter::Write(&value, &str); |
33 return make_scoped_ptr(base::Value::CreateStringValue(str)); | 39 return make_scoped_ptr(base::Value::CreateStringValue(str)); |
34 } | 40 } |
35 | 41 |
36 // This class is responsible to translate the local fields of the given | 42 // This class is responsible to translate the local fields of the given |
37 // |onc_object| according to |onc_signature| into |shill_dictionary|. This | 43 // |onc_object| according to |onc_signature| into |shill_dictionary|. This |
38 // translation should consider (if possible) only fields of this ONC object and | 44 // translation should consider (if possible) only fields of this ONC object and |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 TranslateWiFi(); | 100 TranslateWiFi(); |
95 else if (onc_signature_ == &kEAPSignature) | 101 else if (onc_signature_ == &kEAPSignature) |
96 TranslateEAP(); | 102 TranslateEAP(); |
97 else | 103 else |
98 CopyFieldsAccordingToSignature(); | 104 CopyFieldsAccordingToSignature(); |
99 } | 105 } |
100 | 106 |
101 void LocalTranslator::TranslateOpenVPN() { | 107 void LocalTranslator::TranslateOpenVPN() { |
102 // Shill supports only one RemoteCertKU but ONC a list. | 108 // Shill supports only one RemoteCertKU but ONC a list. |
103 // Copy only the first entry if existing. | 109 // Copy only the first entry if existing. |
104 const base::ListValue* certKUs = NULL; | 110 const base::ListValue* cert_kus = NULL; |
105 std::string certKU; | 111 std::string cert_ku; |
106 if (onc_object_->GetListWithoutPathExpansion(vpn::kRemoteCertKU, &certKUs) && | 112 if (onc_object_->GetListWithoutPathExpansion(vpn::kRemoteCertKU, &cert_kus) && |
107 certKUs->GetString(0, &certKU)) { | 113 cert_kus->GetString(0, &cert_ku)) { |
108 shill_dictionary_->SetStringWithoutPathExpansion( | 114 shill_dictionary_->SetStringWithoutPathExpansion( |
109 flimflam::kOpenVPNRemoteCertKUProperty, certKU); | 115 flimflam::kOpenVPNRemoteCertKUProperty, cert_ku); |
110 } | 116 } |
111 | 117 |
112 for (base::DictionaryValue::Iterator it(*onc_object_); !it.IsAtEnd(); | 118 for (base::DictionaryValue::Iterator it(*onc_object_); !it.IsAtEnd(); |
113 it.Advance()) { | 119 it.Advance()) { |
114 scoped_ptr<base::Value> translated; | 120 scoped_ptr<base::Value> translated; |
115 if (it.key() == vpn::kSaveCredentials || it.key() == vpn::kRemoteCertKU) { | 121 if (it.key() == vpn::kSaveCredentials || |
122 it.key() == vpn::kRemoteCertKU || | |
123 it.key() == openvpn::kServerCAPEMs) { | |
116 translated.reset(it.value().DeepCopy()); | 124 translated.reset(it.value().DeepCopy()); |
117 } else { | 125 } else { |
118 // Shill wants all Provider/VPN fields to be strings. | 126 // Shill wants all Provider/VPN fields to be strings. |
119 translated = ConvertValueToString(it.value()); | 127 translated = ConvertValueToString(it.value()); |
120 } | 128 } |
121 AddValueAccordingToSignature(it.key(), translated.Pass()); | 129 AddValueAccordingToSignature(it.key(), translated.Pass()); |
122 } | 130 } |
123 } | 131 } |
124 | 132 |
125 void LocalTranslator::TranslateVPN() { | 133 void LocalTranslator::TranslateVPN() { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 const OncValueSignature* onc_signature, | 262 const OncValueSignature* onc_signature, |
255 const base::DictionaryValue& onc_object) { | 263 const base::DictionaryValue& onc_object) { |
256 CHECK(onc_signature != NULL); | 264 CHECK(onc_signature != NULL); |
257 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); | 265 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); |
258 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); | 266 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); |
259 return shill_dictionary.Pass(); | 267 return shill_dictionary.Pass(); |
260 } | 268 } |
261 | 269 |
262 } // namespace onc | 270 } // namespace onc |
263 } // namespace chromeos | 271 } // namespace chromeos |
OLD | NEW |