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/strings/string_util.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 #include "chromeos/network/onc/onc_signature.h" | 20 #include "chromeos/network/onc/onc_signature.h" |
20 #include "chromeos/network/onc/onc_translation_tables.h" | 21 #include "chromeos/network/onc/onc_translation_tables.h" |
21 #include "chromeos/network/shill_property_util.h" | 22 #include "chromeos/network/shill_property_util.h" |
22 #include "components/onc/onc_constants.h" | 23 #include "components/onc/onc_constants.h" |
23 #include "third_party/cros_system_api/dbus/service_constants.h" | 24 #include "third_party/cros_system_api/dbus/service_constants.h" |
24 | 25 |
25 namespace chromeos { | 26 namespace chromeos { |
26 namespace onc { | 27 namespace onc { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
| 31 bool ConvertListValueToStringVector(const base::ListValue& string_list, |
| 32 std::vector<std::string>* result) { |
| 33 for (size_t i = 0; i < string_list.GetSize(); ++i) { |
| 34 std::string str; |
| 35 if (!string_list.GetString(i, &str)) |
| 36 return false; |
| 37 result->push_back(str); |
| 38 } |
| 39 return true; |
| 40 } |
| 41 |
30 scoped_ptr<base::StringValue> ConvertValueToString(const base::Value& value) { | 42 scoped_ptr<base::StringValue> ConvertValueToString(const base::Value& value) { |
31 std::string str; | 43 std::string str; |
32 if (!value.GetAsString(&str)) | 44 if (!value.GetAsString(&str)) |
33 base::JSONWriter::Write(&value, &str); | 45 base::JSONWriter::Write(&value, &str); |
34 return make_scoped_ptr(new base::StringValue(str)); | 46 return make_scoped_ptr(new base::StringValue(str)); |
35 } | 47 } |
36 | 48 |
37 // This class is responsible to translate the local fields of the given | 49 // This class is responsible to translate the local fields of the given |
38 // |onc_object| according to |onc_signature| into |shill_dictionary|. This | 50 // |onc_object| according to |onc_signature| into |shill_dictionary|. This |
39 // translation should consider (if possible) only fields of this ONC object and | 51 // translation should consider (if possible) only fields of this ONC object and |
(...skipping 12 matching lines...) Expand all Loading... |
52 | 64 |
53 void TranslateFields(); | 65 void TranslateFields(); |
54 | 66 |
55 private: | 67 private: |
56 void TranslateEthernet(); | 68 void TranslateEthernet(); |
57 void TranslateOpenVPN(); | 69 void TranslateOpenVPN(); |
58 void TranslateIPsec(); | 70 void TranslateIPsec(); |
59 void TranslateVPN(); | 71 void TranslateVPN(); |
60 void TranslateWiFi(); | 72 void TranslateWiFi(); |
61 void TranslateEAP(); | 73 void TranslateEAP(); |
| 74 void TranslateStaticIPConfig(); |
62 void TranslateNetworkConfiguration(); | 75 void TranslateNetworkConfiguration(); |
63 | 76 |
64 // Copies all entries from |onc_object_| to |shill_dictionary_| for which a | 77 // Copies all entries from |onc_object_| to |shill_dictionary_| for which a |
65 // translation (shill_property_name) is defined by |onc_signature_|. | 78 // translation (shill_property_name) is defined by |onc_signature_|. |
66 void CopyFieldsAccordingToSignature(); | 79 void CopyFieldsAccordingToSignature(); |
67 | 80 |
68 // Adds |value| to |shill_dictionary| at the field shill_property_name given | 81 // Adds |value| to |shill_dictionary| at the field shill_property_name given |
69 // by the associated signature. Takes ownership of |value|. Does nothing if | 82 // by the associated signature. Takes ownership of |value|. Does nothing if |
70 // |value| is NULL or the property name cannot be read from the signature. | 83 // |value| is NULL or the property name cannot be read from the signature. |
71 void AddValueAccordingToSignature(const std::string& onc_field_name, | 84 void AddValueAccordingToSignature(const std::string& onc_field_name, |
(...skipping 10 matching lines...) Expand all Loading... |
82 const FieldTranslationEntry* field_translation_table_; | 95 const FieldTranslationEntry* field_translation_table_; |
83 const base::DictionaryValue* onc_object_; | 96 const base::DictionaryValue* onc_object_; |
84 base::DictionaryValue* shill_dictionary_; | 97 base::DictionaryValue* shill_dictionary_; |
85 | 98 |
86 DISALLOW_COPY_AND_ASSIGN(LocalTranslator); | 99 DISALLOW_COPY_AND_ASSIGN(LocalTranslator); |
87 }; | 100 }; |
88 | 101 |
89 void LocalTranslator::TranslateFields() { | 102 void LocalTranslator::TranslateFields() { |
90 if (onc_signature_ == &kNetworkConfigurationSignature) | 103 if (onc_signature_ == &kNetworkConfigurationSignature) |
91 TranslateNetworkConfiguration(); | 104 TranslateNetworkConfiguration(); |
| 105 else if (onc_signature_ == &kStaticIPConfigSignature) |
| 106 TranslateStaticIPConfig(); |
92 else if (onc_signature_ == &kEthernetSignature) | 107 else if (onc_signature_ == &kEthernetSignature) |
93 TranslateEthernet(); | 108 TranslateEthernet(); |
94 else if (onc_signature_ == &kVPNSignature) | 109 else if (onc_signature_ == &kVPNSignature) |
95 TranslateVPN(); | 110 TranslateVPN(); |
96 else if (onc_signature_ == &kOpenVPNSignature) | 111 else if (onc_signature_ == &kOpenVPNSignature) |
97 TranslateOpenVPN(); | 112 TranslateOpenVPN(); |
98 else if (onc_signature_ == &kIPsecSignature) | 113 else if (onc_signature_ == &kIPsecSignature) |
99 TranslateIPsec(); | 114 TranslateIPsec(); |
100 else if (onc_signature_ == &kWiFiSignature) | 115 else if (onc_signature_ == &kWiFiSignature) |
101 TranslateWiFi(); | 116 TranslateWiFi(); |
(...skipping 10 matching lines...) Expand all Loading... |
112 | 127 |
113 const char* shill_type = shill::kTypeEthernet; | 128 const char* shill_type = shill::kTypeEthernet; |
114 if (authentication == ::onc::ethernet::k8021X) | 129 if (authentication == ::onc::ethernet::k8021X) |
115 shill_type = shill::kTypeEthernetEap; | 130 shill_type = shill::kTypeEthernetEap; |
116 shill_dictionary_->SetStringWithoutPathExpansion(shill::kTypeProperty, | 131 shill_dictionary_->SetStringWithoutPathExpansion(shill::kTypeProperty, |
117 shill_type); | 132 shill_type); |
118 | 133 |
119 CopyFieldsAccordingToSignature(); | 134 CopyFieldsAccordingToSignature(); |
120 } | 135 } |
121 | 136 |
| 137 |
| 138 void LocalTranslator::TranslateStaticIPConfig() { |
| 139 const base::ListValue* onc_nameservers = NULL; |
| 140 if (onc_object_->GetListWithoutPathExpansion(::onc::ipconfig::kNameServers, |
| 141 &onc_nameservers)) { |
| 142 std::vector<std::string> onc_nameservers_vector; |
| 143 ConvertListValueToStringVector(*onc_nameservers, &onc_nameservers_vector); |
| 144 std::string shill_nameservers = JoinString(onc_nameservers_vector, ','); |
| 145 shill_dictionary_->SetStringWithoutPathExpansion( |
| 146 shill::kStaticIPNameServersProperty, shill_nameservers); |
| 147 } |
| 148 |
| 149 CopyFieldsAccordingToSignature(); |
| 150 } |
| 151 |
122 void LocalTranslator::TranslateOpenVPN() { | 152 void LocalTranslator::TranslateOpenVPN() { |
123 // SaveCredentials needs special handling when translating from Shill -> ONC | 153 // SaveCredentials needs special handling when translating from Shill -> ONC |
124 // so handle it explicitly here. | 154 // so handle it explicitly here. |
125 bool save_credentials; | 155 bool save_credentials; |
126 if (onc_object_->GetBooleanWithoutPathExpansion( | 156 if (onc_object_->GetBooleanWithoutPathExpansion( |
127 ::onc::vpn::kSaveCredentials, &save_credentials)) { | 157 ::onc::vpn::kSaveCredentials, &save_credentials)) { |
128 shill_dictionary_->SetBooleanWithoutPathExpansion( | 158 shill_dictionary_->SetBooleanWithoutPathExpansion( |
129 shill::kSaveCredentialsProperty, save_credentials); | 159 shill::kSaveCredentialsProperty, save_credentials); |
130 } | 160 } |
131 // Shill supports only one RemoteCertKU but ONC a list. | 161 // Shill supports only one RemoteCertKU but ONC a list. |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 const OncValueSignature* onc_signature, | 357 const OncValueSignature* onc_signature, |
328 const base::DictionaryValue& onc_object) { | 358 const base::DictionaryValue& onc_object) { |
329 CHECK(onc_signature != NULL); | 359 CHECK(onc_signature != NULL); |
330 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); | 360 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); |
331 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); | 361 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); |
332 return shill_dictionary.Pass(); | 362 return shill_dictionary.Pass(); |
333 } | 363 } |
334 | 364 |
335 } // namespace onc | 365 } // namespace onc |
336 } // namespace chromeos | 366 } // namespace chromeos |
OLD | NEW |