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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 const char* shill_type = shill::kTypeEthernet; | 120 const char* shill_type = shill::kTypeEthernet; |
121 if (authentication == ::onc::ethernet::k8021X) | 121 if (authentication == ::onc::ethernet::k8021X) |
122 shill_type = shill::kTypeEthernetEap; | 122 shill_type = shill::kTypeEthernetEap; |
123 shill_dictionary_->SetStringWithoutPathExpansion(shill::kTypeProperty, | 123 shill_dictionary_->SetStringWithoutPathExpansion(shill::kTypeProperty, |
124 shill_type); | 124 shill_type); |
125 | 125 |
126 CopyFieldsAccordingToSignature(); | 126 CopyFieldsAccordingToSignature(); |
127 } | 127 } |
128 | 128 |
129 | |
130 void LocalTranslator::TranslateOpenVPN() { | 129 void LocalTranslator::TranslateOpenVPN() { |
131 // SaveCredentials needs special handling when translating from Shill -> ONC | 130 // SaveCredentials needs special handling when translating from Shill -> ONC |
132 // so handle it explicitly here. | 131 // so handle it explicitly here. |
133 CopyFieldFromONCToShill(::onc::vpn::kSaveCredentials, | 132 CopyFieldFromONCToShill(::onc::vpn::kSaveCredentials, |
134 shill::kSaveCredentialsProperty); | 133 shill::kSaveCredentialsProperty); |
135 | 134 |
136 std::string user_auth_type; | 135 std::string user_auth_type; |
137 onc_object_->GetStringWithoutPathExpansion( | 136 onc_object_->GetStringWithoutPathExpansion( |
138 ::onc::openvpn::kUserAuthenticationType, &user_auth_type); | 137 ::onc::openvpn::kUserAuthenticationType, &user_auth_type); |
139 // The default behavior (if user_auth_type is empty) is to use both password | 138 // The default behavior (if user_auth_type is empty) is to use both password |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 } | 208 } |
210 } else { | 209 } else { |
211 CopyFieldFromONCToShill(::onc::vpn::kHost, shill::kProviderHostProperty); | 210 CopyFieldFromONCToShill(::onc::vpn::kHost, shill::kProviderHostProperty); |
212 } | 211 } |
213 | 212 |
214 CopyFieldsAccordingToSignature(); | 213 CopyFieldsAccordingToSignature(); |
215 } | 214 } |
216 | 215 |
217 void LocalTranslator::TranslateWiFi() { | 216 void LocalTranslator::TranslateWiFi() { |
218 std::string security; | 217 std::string security; |
219 if (onc_object_->GetStringWithoutPathExpansion( | 218 if (onc_object_->GetStringWithoutPathExpansion(::onc::wifi::kSecurity, |
220 ::onc::wifi::kSecurity, &security)) { | 219 &security)) { |
221 TranslateWithTableAndSet(security, kWiFiSecurityTable, | 220 TranslateWithTableAndSet(security, kWiFiSecurityTable, |
222 shill::kSecurityClassProperty); | 221 shill::kSecurityClassProperty); |
223 } | 222 } |
224 | 223 |
225 // We currently only support managed and no adhoc networks. | 224 // We currently only support managed and no adhoc networks. |
226 shill_dictionary_->SetStringWithoutPathExpansion(shill::kModeProperty, | 225 shill_dictionary_->SetStringWithoutPathExpansion(shill::kModeProperty, |
227 shill::kModeManaged); | 226 shill::kModeManaged); |
228 | 227 |
229 bool allow_gateway_arp_polling; | 228 bool allow_gateway_arp_polling; |
230 if (onc_object_->GetBooleanWithoutPathExpansion( | 229 if (onc_object_->GetBooleanWithoutPathExpansion( |
(...skipping 11 matching lines...) Expand all Loading... |
242 TranslateWithTableAndSet(outer, kEAPOuterTable, shill::kEapMethodProperty); | 241 TranslateWithTableAndSet(outer, kEAPOuterTable, shill::kEapMethodProperty); |
243 | 242 |
244 // Translate the inner protocol only for outer tunneling protocols. | 243 // Translate the inner protocol only for outer tunneling protocols. |
245 if (outer == ::onc::eap::kPEAP || outer == ::onc::eap::kEAP_TTLS) { | 244 if (outer == ::onc::eap::kPEAP || outer == ::onc::eap::kEAP_TTLS) { |
246 // In ONC the Inner protocol defaults to "Automatic". | 245 // In ONC the Inner protocol defaults to "Automatic". |
247 std::string inner = ::onc::eap::kAutomatic; | 246 std::string inner = ::onc::eap::kAutomatic; |
248 // ONC's Inner == "Automatic" translates to omitting the Phase2 property in | 247 // ONC's Inner == "Automatic" translates to omitting the Phase2 property in |
249 // Shill. | 248 // Shill. |
250 onc_object_->GetStringWithoutPathExpansion(::onc::eap::kInner, &inner); | 249 onc_object_->GetStringWithoutPathExpansion(::onc::eap::kInner, &inner); |
251 if (inner != ::onc::eap::kAutomatic) { | 250 if (inner != ::onc::eap::kAutomatic) { |
252 const StringTranslationEntry* table = | 251 const StringTranslationEntry* table = outer == ::onc::eap::kPEAP |
253 outer == ::onc::eap::kPEAP ? kEAP_PEAP_InnerTable : | 252 ? kEAP_PEAP_InnerTable |
254 kEAP_TTLS_InnerTable; | 253 : kEAP_TTLS_InnerTable; |
255 TranslateWithTableAndSet(inner, table, shill::kEapPhase2AuthProperty); | 254 TranslateWithTableAndSet(inner, table, shill::kEapPhase2AuthProperty); |
256 } | 255 } |
257 } | 256 } |
258 | 257 |
259 CopyFieldsAccordingToSignature(); | 258 CopyFieldsAccordingToSignature(); |
260 } | 259 } |
261 | 260 |
262 void LocalTranslator::TranslateNetworkConfiguration() { | 261 void LocalTranslator::TranslateNetworkConfiguration() { |
263 std::string type; | 262 std::string type; |
264 onc_object_->GetStringWithoutPathExpansion(::onc::network_config::kType, | 263 onc_object_->GetStringWithoutPathExpansion(::onc::network_config::kType, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 shill_dictionary_->SetWithoutPathExpansion(shill_property_name, | 320 shill_dictionary_->SetWithoutPathExpansion(shill_property_name, |
322 value->DeepCopy()); | 321 value->DeepCopy()); |
323 } | 322 } |
324 | 323 |
325 void LocalTranslator::AddValueAccordingToSignature( | 324 void LocalTranslator::AddValueAccordingToSignature( |
326 const std::string& onc_name, | 325 const std::string& onc_name, |
327 scoped_ptr<base::Value> value) { | 326 scoped_ptr<base::Value> value) { |
328 if (!value || !field_translation_table_) | 327 if (!value || !field_translation_table_) |
329 return; | 328 return; |
330 std::string shill_property_name; | 329 std::string shill_property_name; |
331 if (!GetShillPropertyName( | 330 if (!GetShillPropertyName(onc_name, field_translation_table_, |
332 onc_name, field_translation_table_, &shill_property_name)) { | 331 &shill_property_name)) { |
333 return; | 332 return; |
334 } | 333 } |
335 | 334 |
336 shill_dictionary_->SetWithoutPathExpansion(shill_property_name, | 335 shill_dictionary_->SetWithoutPathExpansion(shill_property_name, |
337 value.release()); | 336 value.release()); |
338 } | 337 } |
339 | 338 |
340 void LocalTranslator::TranslateWithTableAndSet( | 339 void LocalTranslator::TranslateWithTableAndSet( |
341 const std::string& onc_value, | 340 const std::string& onc_value, |
342 const StringTranslationEntry table[], | 341 const StringTranslationEntry table[], |
(...skipping 16 matching lines...) Expand all Loading... |
359 // applies the local translation using LocalTranslator::TranslateFields. The | 358 // applies the local translation using LocalTranslator::TranslateFields. The |
360 // results are written to |shill_dictionary|. | 359 // results are written to |shill_dictionary|. |
361 void TranslateONCHierarchy(const OncValueSignature& signature, | 360 void TranslateONCHierarchy(const OncValueSignature& signature, |
362 const base::DictionaryValue& onc_object, | 361 const base::DictionaryValue& onc_object, |
363 base::DictionaryValue* shill_dictionary) { | 362 base::DictionaryValue* shill_dictionary) { |
364 base::DictionaryValue* target_shill_dictionary = shill_dictionary; | 363 base::DictionaryValue* target_shill_dictionary = shill_dictionary; |
365 std::vector<std::string> path_to_shill_dictionary = | 364 std::vector<std::string> path_to_shill_dictionary = |
366 GetPathToNestedShillDictionary(signature); | 365 GetPathToNestedShillDictionary(signature); |
367 for (std::vector<std::string>::const_iterator it = | 366 for (std::vector<std::string>::const_iterator it = |
368 path_to_shill_dictionary.begin(); | 367 path_to_shill_dictionary.begin(); |
369 it != path_to_shill_dictionary.end(); | 368 it != path_to_shill_dictionary.end(); ++it) { |
370 ++it) { | |
371 base::DictionaryValue* nested_shill_dict = NULL; | 369 base::DictionaryValue* nested_shill_dict = NULL; |
372 target_shill_dictionary->GetDictionaryWithoutPathExpansion( | 370 target_shill_dictionary->GetDictionaryWithoutPathExpansion( |
373 *it, &nested_shill_dict); | 371 *it, &nested_shill_dict); |
374 if (!nested_shill_dict) { | 372 if (!nested_shill_dict) { |
375 nested_shill_dict = new base::DictionaryValue; | 373 nested_shill_dict = new base::DictionaryValue; |
376 target_shill_dictionary->SetWithoutPathExpansion(*it, nested_shill_dict); | 374 target_shill_dictionary->SetWithoutPathExpansion(*it, nested_shill_dict); |
377 } | 375 } |
378 target_shill_dictionary = nested_shill_dict; | 376 target_shill_dictionary = nested_shill_dict; |
379 } | 377 } |
380 // Translates fields of |onc_object| and writes them to | 378 // Translates fields of |onc_object| and writes them to |
(...skipping 22 matching lines...) Expand all Loading... |
403 const OncValueSignature* onc_signature, | 401 const OncValueSignature* onc_signature, |
404 const base::DictionaryValue& onc_object) { | 402 const base::DictionaryValue& onc_object) { |
405 CHECK(onc_signature != NULL); | 403 CHECK(onc_signature != NULL); |
406 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); | 404 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); |
407 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); | 405 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); |
408 return shill_dictionary.Pass(); | 406 return shill_dictionary.Pass(); |
409 } | 407 } |
410 | 408 |
411 } // namespace onc | 409 } // namespace onc |
412 } // namespace chromeos | 410 } // namespace chromeos |
OLD | NEW |