| 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 #include "chromeos/network/onc/onc_translator.h" | 5 #include "chromeos/network/onc/onc_translator.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 70 } |
| 71 | 71 |
| 72 // Translates the associated Shill dictionary and creates an ONC object of the | 72 // Translates the associated Shill dictionary and creates an ONC object of the |
| 73 // given signature. | 73 // given signature. |
| 74 scoped_ptr<base::DictionaryValue> CreateTranslatedONCObject(); | 74 scoped_ptr<base::DictionaryValue> CreateTranslatedONCObject(); |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 void TranslateEthernet(); | 77 void TranslateEthernet(); |
| 78 void TranslateOpenVPN(); | 78 void TranslateOpenVPN(); |
| 79 void TranslateIPsec(); | 79 void TranslateIPsec(); |
| 80 void TranslateThirdPartyVPN(); |
| 80 void TranslateVPN(); | 81 void TranslateVPN(); |
| 81 void TranslateWiFiWithState(); | 82 void TranslateWiFiWithState(); |
| 82 void TranslateWiMAXWithState(); | 83 void TranslateWiMAXWithState(); |
| 83 void TranslateCellularWithState(); | 84 void TranslateCellularWithState(); |
| 84 void TranslateCellularDevice(); | 85 void TranslateCellularDevice(); |
| 85 void TranslateNetworkWithState(); | 86 void TranslateNetworkWithState(); |
| 86 void TranslateIPConfig(); | 87 void TranslateIPConfig(); |
| 87 void TranslateSavedOrStaticIPConfig(); | 88 void TranslateSavedOrStaticIPConfig(); |
| 88 void TranslateSavedIPConfig(); | 89 void TranslateSavedIPConfig(); |
| 89 void TranslateStaticIPConfig(); | 90 void TranslateStaticIPConfig(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 if (onc_signature_ == &kNetworkWithStateSignature) { | 153 if (onc_signature_ == &kNetworkWithStateSignature) { |
| 153 TranslateNetworkWithState(); | 154 TranslateNetworkWithState(); |
| 154 } else if (onc_signature_ == &kEthernetSignature) { | 155 } else if (onc_signature_ == &kEthernetSignature) { |
| 155 TranslateEthernet(); | 156 TranslateEthernet(); |
| 156 } else if (onc_signature_ == &kVPNSignature) { | 157 } else if (onc_signature_ == &kVPNSignature) { |
| 157 TranslateVPN(); | 158 TranslateVPN(); |
| 158 } else if (onc_signature_ == &kOpenVPNSignature) { | 159 } else if (onc_signature_ == &kOpenVPNSignature) { |
| 159 TranslateOpenVPN(); | 160 TranslateOpenVPN(); |
| 160 } else if (onc_signature_ == &kIPsecSignature) { | 161 } else if (onc_signature_ == &kIPsecSignature) { |
| 161 TranslateIPsec(); | 162 TranslateIPsec(); |
| 163 } else if (onc_signature_ == &kThirdPartyVPNSignature) { |
| 164 TranslateThirdPartyVPN(); |
| 162 } else if (onc_signature_ == &kWiFiWithStateSignature) { | 165 } else if (onc_signature_ == &kWiFiWithStateSignature) { |
| 163 TranslateWiFiWithState(); | 166 TranslateWiFiWithState(); |
| 164 } else if (onc_signature_ == &kWiMAXWithStateSignature) { | 167 } else if (onc_signature_ == &kWiMAXWithStateSignature) { |
| 165 TranslateWiMAXWithState(); | 168 TranslateWiMAXWithState(); |
| 166 } else if (onc_signature_ == &kCellularWithStateSignature) { | 169 } else if (onc_signature_ == &kCellularWithStateSignature) { |
| 167 if (field_translation_table_ == kCellularDeviceTable) | 170 if (field_translation_table_ == kCellularDeviceTable) |
| 168 TranslateCellularDevice(); | 171 TranslateCellularDevice(); |
| 169 else | 172 else |
| 170 TranslateCellularWithState(); | 173 TranslateCellularWithState(); |
| 171 } else if (onc_signature_ == &kIPConfigSignature) { | 174 } else if (onc_signature_ == &kIPConfigSignature) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 TranslateAndAddNestedObject(::onc::ipsec::kXAUTH); | 262 TranslateAndAddNestedObject(::onc::ipsec::kXAUTH); |
| 260 std::string client_cert_id; | 263 std::string client_cert_id; |
| 261 shill_dictionary_->GetStringWithoutPathExpansion( | 264 shill_dictionary_->GetStringWithoutPathExpansion( |
| 262 shill::kL2tpIpsecClientCertIdProperty, &client_cert_id); | 265 shill::kL2tpIpsecClientCertIdProperty, &client_cert_id); |
| 263 std::string authentication_type = | 266 std::string authentication_type = |
| 264 client_cert_id.empty() ? ::onc::ipsec::kPSK : ::onc::ipsec::kCert; | 267 client_cert_id.empty() ? ::onc::ipsec::kPSK : ::onc::ipsec::kCert; |
| 265 onc_object_->SetStringWithoutPathExpansion(::onc::ipsec::kAuthenticationType, | 268 onc_object_->SetStringWithoutPathExpansion(::onc::ipsec::kAuthenticationType, |
| 266 authentication_type); | 269 authentication_type); |
| 267 } | 270 } |
| 268 | 271 |
| 272 void ShillToONCTranslator::TranslateThirdPartyVPN() { |
| 273 CopyPropertiesAccordingToSignature(); |
| 274 |
| 275 // For third-party VPNs, |shill::kProviderHostProperty| is used to store the |
| 276 // provider's extension ID. |
| 277 std::string shill_extension_id; |
| 278 shill_dictionary_->GetStringWithoutPathExpansion(shill::kHostProperty, |
| 279 &shill_extension_id); |
| 280 onc_object_->SetStringWithoutPathExpansion( |
| 281 ::onc::third_party_vpn::kExtensionID, shill_extension_id); |
| 282 } |
| 283 |
| 269 void ShillToONCTranslator::TranslateVPN() { | 284 void ShillToONCTranslator::TranslateVPN() { |
| 270 CopyPropertiesAccordingToSignature(); | 285 CopyPropertiesAccordingToSignature(); |
| 271 | 286 |
| 272 // Parse Shill Provider dictionary. Note, this may not exist, e.g. if we are | 287 // Parse Shill Provider dictionary. Note, this may not exist, e.g. if we are |
| 273 // just translating network state in network_util::TranslateNetworkStateToONC. | 288 // just translating network state in network_util::TranslateNetworkStateToONC. |
| 274 const base::DictionaryValue* provider = NULL; | 289 const base::DictionaryValue* provider = NULL; |
| 275 if (!shill_dictionary_->GetDictionaryWithoutPathExpansion( | 290 if (!shill_dictionary_->GetDictionaryWithoutPathExpansion( |
| 276 shill::kProviderProperty, &provider)) { | 291 shill::kProviderProperty, &provider)) { |
| 277 return; | 292 return; |
| 278 } | 293 } |
| 279 std::string shill_provider_type, onc_provider_type; | 294 std::string shill_provider_type, onc_provider_type; |
| 280 provider->GetStringWithoutPathExpansion(shill::kTypeProperty, | 295 provider->GetStringWithoutPathExpansion(shill::kTypeProperty, |
| 281 &shill_provider_type); | 296 &shill_provider_type); |
| 282 if (!TranslateStringToONC( | 297 if (!TranslateStringToONC( |
| 283 kVPNTypeTable, shill_provider_type, &onc_provider_type)) { | 298 kVPNTypeTable, shill_provider_type, &onc_provider_type)) { |
| 284 return; | 299 return; |
| 285 } | 300 } |
| 286 onc_object_->SetStringWithoutPathExpansion(::onc::vpn::kType, | 301 onc_object_->SetStringWithoutPathExpansion(::onc::vpn::kType, |
| 287 onc_provider_type); | 302 onc_provider_type); |
| 288 std::string provider_host; | 303 std::string shill_provider_host; |
| 289 if (provider->GetStringWithoutPathExpansion(shill::kHostProperty, | 304 if (onc_provider_type != ::onc::vpn::kThirdPartyVpn && |
| 290 &provider_host)) { | 305 provider->GetStringWithoutPathExpansion(shill::kHostProperty, |
| 306 &shill_provider_host)) { |
| 291 onc_object_->SetStringWithoutPathExpansion(::onc::vpn::kHost, | 307 onc_object_->SetStringWithoutPathExpansion(::onc::vpn::kHost, |
| 292 provider_host); | 308 shill_provider_host); |
| 293 } | 309 } |
| 294 | 310 |
| 295 // Translate the nested dictionary. | 311 // Translate the nested dictionary. |
| 296 std::string provider_type_dictionary; | 312 std::string provider_type_dictionary; |
| 297 if (onc_provider_type == ::onc::vpn::kTypeL2TP_IPsec) { | 313 if (onc_provider_type == ::onc::vpn::kTypeL2TP_IPsec) { |
| 298 TranslateAndAddNestedObject(::onc::vpn::kIPsec, *provider); | 314 TranslateAndAddNestedObject(::onc::vpn::kIPsec, *provider); |
| 299 TranslateAndAddNestedObject(::onc::vpn::kL2TP, *provider); | 315 TranslateAndAddNestedObject(::onc::vpn::kL2TP, *provider); |
| 300 provider_type_dictionary = ::onc::vpn::kIPsec; | 316 provider_type_dictionary = ::onc::vpn::kIPsec; |
| 301 } else if (onc_provider_type != ::onc::vpn::kThirdPartyVpn) { | 317 } else { |
| 302 TranslateAndAddNestedObject(onc_provider_type, *provider); | 318 TranslateAndAddNestedObject(onc_provider_type, *provider); |
| 303 provider_type_dictionary = onc_provider_type; | 319 provider_type_dictionary = onc_provider_type; |
| 304 } | 320 } |
| 305 | 321 |
| 306 bool save_credentials; | 322 bool save_credentials; |
| 307 if (shill_dictionary_->GetBooleanWithoutPathExpansion( | 323 if (onc_provider_type != ::onc::vpn::kThirdPartyVpn && |
| 324 shill_dictionary_->GetBooleanWithoutPathExpansion( |
| 308 shill::kSaveCredentialsProperty, &save_credentials)) { | 325 shill::kSaveCredentialsProperty, &save_credentials)) { |
| 309 SetNestedOncValue(provider_type_dictionary, | 326 SetNestedOncValue(provider_type_dictionary, |
| 310 ::onc::vpn::kSaveCredentials, | 327 ::onc::vpn::kSaveCredentials, |
| 311 base::FundamentalValue(save_credentials)); | 328 base::FundamentalValue(save_credentials)); |
| 312 } | 329 } |
| 313 } | 330 } |
| 314 | 331 |
| 315 void ShillToONCTranslator::TranslateWiFiWithState() { | 332 void ShillToONCTranslator::TranslateWiFiWithState() { |
| 316 TranslateWithTableAndSet(shill::kSecurityClassProperty, | 333 TranslateWithTableAndSet(shill::kSecurityClassProperty, |
| 317 kWiFiSecurityTable, | 334 kWiFiSecurityTable, |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 ::onc::ONCSource onc_source, | 731 ::onc::ONCSource onc_source, |
| 715 const OncValueSignature* onc_signature) { | 732 const OncValueSignature* onc_signature) { |
| 716 CHECK(onc_signature != NULL); | 733 CHECK(onc_signature != NULL); |
| 717 | 734 |
| 718 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature); | 735 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature); |
| 719 return translator.CreateTranslatedONCObject(); | 736 return translator.CreateTranslatedONCObject(); |
| 720 } | 737 } |
| 721 | 738 |
| 722 } // namespace onc | 739 } // namespace onc |
| 723 } // namespace chromeos | 740 } // namespace chromeos |
| OLD | NEW |