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 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 TranslateEAP(); | 99 TranslateEAP(); |
100 else | 100 else |
101 CopyFieldsAccordingToSignature(); | 101 CopyFieldsAccordingToSignature(); |
102 } | 102 } |
103 | 103 |
104 void LocalTranslator::TranslateEthernet() { | 104 void LocalTranslator::TranslateEthernet() { |
105 std::string authentication; | 105 std::string authentication; |
106 onc_object_->GetStringWithoutPathExpansion(ethernet::kAuthentication, | 106 onc_object_->GetStringWithoutPathExpansion(ethernet::kAuthentication, |
107 &authentication); | 107 &authentication); |
108 | 108 |
109 const char* shill_type = flimflam::kTypeEthernet; | 109 const char* shill_type = shill::kTypeEthernet; |
110 if (authentication == ethernet::k8021X) | 110 if (authentication == ethernet::k8021X) |
111 shill_type = shill::kTypeEthernetEap; | 111 shill_type = shill::kTypeEthernetEap; |
112 shill_dictionary_->SetStringWithoutPathExpansion(flimflam::kTypeProperty, | 112 shill_dictionary_->SetStringWithoutPathExpansion(shill::kTypeProperty, |
113 shill_type); | 113 shill_type); |
114 | 114 |
115 CopyFieldsAccordingToSignature(); | 115 CopyFieldsAccordingToSignature(); |
116 } | 116 } |
117 | 117 |
118 void LocalTranslator::TranslateOpenVPN() { | 118 void LocalTranslator::TranslateOpenVPN() { |
119 // Shill supports only one RemoteCertKU but ONC a list. | 119 // Shill supports only one RemoteCertKU but ONC a list. |
120 // Copy only the first entry if existing. | 120 // Copy only the first entry if existing. |
121 const base::ListValue* certKUs = NULL; | 121 const base::ListValue* certKUs = NULL; |
122 std::string certKU; | 122 std::string certKU; |
123 if (onc_object_->GetListWithoutPathExpansion(openvpn::kRemoteCertKU, | 123 if (onc_object_->GetListWithoutPathExpansion(openvpn::kRemoteCertKU, |
124 &certKUs) && | 124 &certKUs) && |
125 certKUs->GetString(0, &certKU)) { | 125 certKUs->GetString(0, &certKU)) { |
126 shill_dictionary_->SetStringWithoutPathExpansion( | 126 shill_dictionary_->SetStringWithoutPathExpansion( |
127 flimflam::kOpenVPNRemoteCertKUProperty, certKU); | 127 shill::kOpenVPNRemoteCertKUProperty, certKU); |
128 } | 128 } |
129 | 129 |
130 for (base::DictionaryValue::Iterator it(*onc_object_); !it.IsAtEnd(); | 130 for (base::DictionaryValue::Iterator it(*onc_object_); !it.IsAtEnd(); |
131 it.Advance()) { | 131 it.Advance()) { |
132 scoped_ptr<base::Value> translated; | 132 scoped_ptr<base::Value> translated; |
133 if (it.key() == vpn::kSaveCredentials || | 133 if (it.key() == vpn::kSaveCredentials || |
134 it.key() == openvpn::kRemoteCertKU || | 134 it.key() == openvpn::kRemoteCertKU || |
135 it.key() == openvpn::kServerCAPEMs) { | 135 it.key() == openvpn::kServerCAPEMs) { |
136 translated.reset(it.value().DeepCopy()); | 136 translated.reset(it.value().DeepCopy()); |
137 } else { | 137 } else { |
138 // Shill wants all Provider/VPN fields to be strings. | 138 // Shill wants all Provider/VPN fields to be strings. |
139 translated = ConvertValueToString(it.value()); | 139 translated = ConvertValueToString(it.value()); |
140 } | 140 } |
141 AddValueAccordingToSignature(it.key(), translated.Pass()); | 141 AddValueAccordingToSignature(it.key(), translated.Pass()); |
142 } | 142 } |
143 } | 143 } |
144 | 144 |
145 void LocalTranslator::TranslateVPN() { | 145 void LocalTranslator::TranslateVPN() { |
146 std::string type; | 146 std::string type; |
147 onc_object_->GetStringWithoutPathExpansion(vpn::kType, &type); | 147 onc_object_->GetStringWithoutPathExpansion(vpn::kType, &type); |
148 TranslateWithTableAndSet(type, kVPNTypeTable, | 148 TranslateWithTableAndSet(type, kVPNTypeTable, shill::kProviderTypeProperty); |
149 flimflam::kProviderTypeProperty); | |
150 | 149 |
151 CopyFieldsAccordingToSignature(); | 150 CopyFieldsAccordingToSignature(); |
152 } | 151 } |
153 | 152 |
154 void LocalTranslator::TranslateWiFi() { | 153 void LocalTranslator::TranslateWiFi() { |
155 std::string security; | 154 std::string security; |
156 onc_object_->GetStringWithoutPathExpansion(wifi::kSecurity, &security); | 155 onc_object_->GetStringWithoutPathExpansion(wifi::kSecurity, &security); |
157 TranslateWithTableAndSet(security, kWiFiSecurityTable, | 156 TranslateWithTableAndSet(security, kWiFiSecurityTable, |
158 flimflam::kSecurityProperty); | 157 shill::kSecurityProperty); |
159 | 158 |
160 // We currently only support managed and no adhoc networks. | 159 // We currently only support managed and no adhoc networks. |
161 shill_dictionary_->SetStringWithoutPathExpansion(flimflam::kModeProperty, | 160 shill_dictionary_->SetStringWithoutPathExpansion(shill::kModeProperty, |
162 flimflam::kModeManaged); | 161 shill::kModeManaged); |
163 CopyFieldsAccordingToSignature(); | 162 CopyFieldsAccordingToSignature(); |
164 } | 163 } |
165 | 164 |
166 void LocalTranslator::TranslateEAP() { | 165 void LocalTranslator::TranslateEAP() { |
167 std::string outer; | 166 std::string outer; |
168 onc_object_->GetStringWithoutPathExpansion(eap::kOuter, &outer); | 167 onc_object_->GetStringWithoutPathExpansion(eap::kOuter, &outer); |
169 TranslateWithTableAndSet(outer, kEAPOuterTable, flimflam::kEapMethodProperty); | 168 TranslateWithTableAndSet(outer, kEAPOuterTable, shill::kEapMethodProperty); |
170 | 169 |
171 // Translate the inner protocol only for outer tunneling protocols. | 170 // Translate the inner protocol only for outer tunneling protocols. |
172 if (outer == eap::kPEAP || outer == eap::kEAP_TTLS) { | 171 if (outer == eap::kPEAP || outer == eap::kEAP_TTLS) { |
173 // In ONC the Inner protocol defaults to "Automatic". | 172 // In ONC the Inner protocol defaults to "Automatic". |
174 std::string inner = eap::kAutomatic; | 173 std::string inner = eap::kAutomatic; |
175 // ONC's Inner == "Automatic" translates to omitting the Phase2 property in | 174 // ONC's Inner == "Automatic" translates to omitting the Phase2 property in |
176 // Shill. | 175 // Shill. |
177 onc_object_->GetStringWithoutPathExpansion(eap::kInner, &inner); | 176 onc_object_->GetStringWithoutPathExpansion(eap::kInner, &inner); |
178 if (inner != eap::kAutomatic) { | 177 if (inner != eap::kAutomatic) { |
179 const StringTranslationEntry* table = | 178 const StringTranslationEntry* table = |
180 outer == eap::kPEAP ? kEAP_PEAP_InnerTable : kEAP_TTLS_InnerTable; | 179 outer == eap::kPEAP ? kEAP_PEAP_InnerTable : kEAP_TTLS_InnerTable; |
181 TranslateWithTableAndSet(inner, table, flimflam::kEapPhase2AuthProperty); | 180 TranslateWithTableAndSet(inner, table, shill::kEapPhase2AuthProperty); |
182 } | 181 } |
183 } | 182 } |
184 | 183 |
185 CopyFieldsAccordingToSignature(); | 184 CopyFieldsAccordingToSignature(); |
186 } | 185 } |
187 | 186 |
188 void LocalTranslator::TranslateNetworkConfiguration() { | 187 void LocalTranslator::TranslateNetworkConfiguration() { |
189 std::string type; | 188 std::string type; |
190 onc_object_->GetStringWithoutPathExpansion(network_config::kType, &type); | 189 onc_object_->GetStringWithoutPathExpansion(network_config::kType, &type); |
191 | 190 |
192 // Set the type except for Ethernet which is set in TranslateEthernet. | 191 // Set the type except for Ethernet which is set in TranslateEthernet. |
193 if (type != network_type::kEthernet) | 192 if (type != network_type::kEthernet) |
194 TranslateWithTableAndSet(type, kNetworkTypeTable, flimflam::kTypeProperty); | 193 TranslateWithTableAndSet(type, kNetworkTypeTable, shill::kTypeProperty); |
195 | 194 |
196 // Shill doesn't allow setting the name for non-VPN networks. | 195 // Shill doesn't allow setting the name for non-VPN networks. |
197 if (type == network_type::kVPN) { | 196 if (type == network_type::kVPN) { |
198 std::string name; | 197 std::string name; |
199 onc_object_->GetStringWithoutPathExpansion(network_config::kName, &name); | 198 onc_object_->GetStringWithoutPathExpansion(network_config::kName, &name); |
200 shill_dictionary_->SetStringWithoutPathExpansion(flimflam::kNameProperty, | 199 shill_dictionary_->SetStringWithoutPathExpansion(shill::kNameProperty, |
201 name); | 200 name); |
202 } | 201 } |
203 | 202 |
204 CopyFieldsAccordingToSignature(); | 203 CopyFieldsAccordingToSignature(); |
205 } | 204 } |
206 | 205 |
207 void LocalTranslator::CopyFieldsAccordingToSignature() { | 206 void LocalTranslator::CopyFieldsAccordingToSignature() { |
208 for (base::DictionaryValue::Iterator it(*onc_object_); !it.IsAtEnd(); | 207 for (base::DictionaryValue::Iterator it(*onc_object_); !it.IsAtEnd(); |
209 it.Advance()) { | 208 it.Advance()) { |
210 AddValueAccordingToSignature(it.key(), | 209 AddValueAccordingToSignature(it.key(), |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 const OncValueSignature* onc_signature, | 291 const OncValueSignature* onc_signature, |
293 const base::DictionaryValue& onc_object) { | 292 const base::DictionaryValue& onc_object) { |
294 CHECK(onc_signature != NULL); | 293 CHECK(onc_signature != NULL); |
295 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); | 294 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); |
296 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); | 295 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); |
297 return shill_dictionary.Pass(); | 296 return shill_dictionary.Pass(); |
298 } | 297 } |
299 | 298 |
300 } // namespace onc | 299 } // namespace onc |
301 } // namespace chromeos | 300 } // namespace chromeos |
OLD | NEW |