| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 onc_object_(&onc_object), | 48 onc_object_(&onc_object), |
| 49 shill_dictionary_(shill_dictionary) { | 49 shill_dictionary_(shill_dictionary) { |
| 50 field_translation_table_ = GetFieldTranslationTable(onc_signature); | 50 field_translation_table_ = GetFieldTranslationTable(onc_signature); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void TranslateFields(); | 53 void TranslateFields(); |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 void TranslateEthernet(); | 56 void TranslateEthernet(); |
| 57 void TranslateOpenVPN(); | 57 void TranslateOpenVPN(); |
| 58 void TranslateIPsec(); |
| 58 void TranslateVPN(); | 59 void TranslateVPN(); |
| 59 void TranslateWiFi(); | 60 void TranslateWiFi(); |
| 60 void TranslateEAP(); | 61 void TranslateEAP(); |
| 61 void TranslateNetworkConfiguration(); | 62 void TranslateNetworkConfiguration(); |
| 62 | 63 |
| 63 // Copies all entries from |onc_object_| to |shill_dictionary_| for which a | 64 // Copies all entries from |onc_object_| to |shill_dictionary_| for which a |
| 64 // translation (shill_property_name) is defined by |onc_signature_|. | 65 // translation (shill_property_name) is defined by |onc_signature_|. |
| 65 void CopyFieldsAccordingToSignature(); | 66 void CopyFieldsAccordingToSignature(); |
| 66 | 67 |
| 67 // Adds |value| to |shill_dictionary| at the field shill_property_name given | 68 // Adds |value| to |shill_dictionary| at the field shill_property_name given |
| (...skipping 19 matching lines...) Expand all Loading... |
| 87 | 88 |
| 88 void LocalTranslator::TranslateFields() { | 89 void LocalTranslator::TranslateFields() { |
| 89 if (onc_signature_ == &kNetworkConfigurationSignature) | 90 if (onc_signature_ == &kNetworkConfigurationSignature) |
| 90 TranslateNetworkConfiguration(); | 91 TranslateNetworkConfiguration(); |
| 91 else if (onc_signature_ == &kEthernetSignature) | 92 else if (onc_signature_ == &kEthernetSignature) |
| 92 TranslateEthernet(); | 93 TranslateEthernet(); |
| 93 else if (onc_signature_ == &kVPNSignature) | 94 else if (onc_signature_ == &kVPNSignature) |
| 94 TranslateVPN(); | 95 TranslateVPN(); |
| 95 else if (onc_signature_ == &kOpenVPNSignature) | 96 else if (onc_signature_ == &kOpenVPNSignature) |
| 96 TranslateOpenVPN(); | 97 TranslateOpenVPN(); |
| 98 else if (onc_signature_ == &kIPsecSignature) |
| 99 TranslateIPsec(); |
| 97 else if (onc_signature_ == &kWiFiSignature) | 100 else if (onc_signature_ == &kWiFiSignature) |
| 98 TranslateWiFi(); | 101 TranslateWiFi(); |
| 99 else if (onc_signature_ == &kEAPSignature) | 102 else if (onc_signature_ == &kEAPSignature) |
| 100 TranslateEAP(); | 103 TranslateEAP(); |
| 101 else | 104 else |
| 102 CopyFieldsAccordingToSignature(); | 105 CopyFieldsAccordingToSignature(); |
| 103 } | 106 } |
| 104 | 107 |
| 105 void LocalTranslator::TranslateEthernet() { | 108 void LocalTranslator::TranslateEthernet() { |
| 106 std::string authentication; | 109 std::string authentication; |
| 107 onc_object_->GetStringWithoutPathExpansion(::onc::ethernet::kAuthentication, | 110 onc_object_->GetStringWithoutPathExpansion(::onc::ethernet::kAuthentication, |
| 108 &authentication); | 111 &authentication); |
| 109 | 112 |
| 110 const char* shill_type = shill::kTypeEthernet; | 113 const char* shill_type = shill::kTypeEthernet; |
| 111 if (authentication == ::onc::ethernet::k8021X) | 114 if (authentication == ::onc::ethernet::k8021X) |
| 112 shill_type = shill::kTypeEthernetEap; | 115 shill_type = shill::kTypeEthernetEap; |
| 113 shill_dictionary_->SetStringWithoutPathExpansion(shill::kTypeProperty, | 116 shill_dictionary_->SetStringWithoutPathExpansion(shill::kTypeProperty, |
| 114 shill_type); | 117 shill_type); |
| 115 | 118 |
| 116 CopyFieldsAccordingToSignature(); | 119 CopyFieldsAccordingToSignature(); |
| 117 } | 120 } |
| 118 | 121 |
| 119 void LocalTranslator::TranslateOpenVPN() { | 122 void LocalTranslator::TranslateOpenVPN() { |
| 123 // SaveCredentials needs special handling when translating from Shill -> ONC |
| 124 // so handle it explicitly here. |
| 125 bool save_credentials; |
| 126 if (onc_object_->GetBooleanWithoutPathExpansion( |
| 127 ::onc::vpn::kSaveCredentials, &save_credentials)) { |
| 128 shill_dictionary_->SetBooleanWithoutPathExpansion( |
| 129 shill::kSaveCredentialsProperty, save_credentials); |
| 130 } |
| 120 // Shill supports only one RemoteCertKU but ONC a list. | 131 // Shill supports only one RemoteCertKU but ONC a list. |
| 121 // Copy only the first entry if existing. | 132 // Copy only the first entry if existing. |
| 122 const base::ListValue* certKUs = NULL; | 133 const base::ListValue* certKUs = NULL; |
| 123 std::string certKU; | 134 std::string certKU; |
| 124 if (onc_object_->GetListWithoutPathExpansion(::onc::openvpn::kRemoteCertKU, | 135 if (onc_object_->GetListWithoutPathExpansion(::onc::openvpn::kRemoteCertKU, |
| 125 &certKUs) && | 136 &certKUs) && |
| 126 certKUs->GetString(0, &certKU)) { | 137 certKUs->GetString(0, &certKU)) { |
| 127 shill_dictionary_->SetStringWithoutPathExpansion( | 138 shill_dictionary_->SetStringWithoutPathExpansion( |
| 128 shill::kOpenVPNRemoteCertKUProperty, certKU); | 139 shill::kOpenVPNRemoteCertKUProperty, certKU); |
| 129 } | 140 } |
| 130 | 141 |
| 131 for (base::DictionaryValue::Iterator it(*onc_object_); !it.IsAtEnd(); | 142 for (base::DictionaryValue::Iterator it(*onc_object_); !it.IsAtEnd(); |
| 132 it.Advance()) { | 143 it.Advance()) { |
| 133 scoped_ptr<base::Value> translated; | 144 scoped_ptr<base::Value> translated; |
| 134 if (it.key() == ::onc::vpn::kSaveCredentials || | 145 if (it.key() == ::onc::openvpn::kRemoteCertKU || |
| 135 it.key() == ::onc::openvpn::kRemoteCertKU || | |
| 136 it.key() == ::onc::openvpn::kServerCAPEMs) { | 146 it.key() == ::onc::openvpn::kServerCAPEMs) { |
| 137 translated.reset(it.value().DeepCopy()); | 147 translated.reset(it.value().DeepCopy()); |
| 138 } else { | 148 } else { |
| 139 // Shill wants all Provider/VPN fields to be strings. | 149 // Shill wants all Provider/VPN fields to be strings. |
| 140 translated = ConvertValueToString(it.value()); | 150 translated = ConvertValueToString(it.value()); |
| 141 } | 151 } |
| 142 AddValueAccordingToSignature(it.key(), translated.Pass()); | 152 AddValueAccordingToSignature(it.key(), translated.Pass()); |
| 143 } | 153 } |
| 144 } | 154 } |
| 145 | 155 |
| 156 void LocalTranslator::TranslateIPsec() { |
| 157 CopyFieldsAccordingToSignature(); |
| 158 |
| 159 // SaveCredentials needs special handling when translating from Shill -> ONC |
| 160 // so handle it explicitly here. |
| 161 bool save_credentials; |
| 162 if (onc_object_->GetBooleanWithoutPathExpansion( |
| 163 ::onc::vpn::kSaveCredentials, &save_credentials)) { |
| 164 shill_dictionary_->SetBooleanWithoutPathExpansion( |
| 165 shill::kSaveCredentialsProperty, save_credentials); |
| 166 } |
| 167 } |
| 168 |
| 146 void LocalTranslator::TranslateVPN() { | 169 void LocalTranslator::TranslateVPN() { |
| 170 std::string host; |
| 171 if (onc_object_->GetStringWithoutPathExpansion(::onc::vpn::kHost, &host)) { |
| 172 shill_dictionary_->SetStringWithoutPathExpansion( |
| 173 shill::kProviderHostProperty, host); |
| 174 } |
| 147 std::string type; | 175 std::string type; |
| 148 onc_object_->GetStringWithoutPathExpansion(::onc::vpn::kType, &type); | 176 onc_object_->GetStringWithoutPathExpansion(::onc::vpn::kType, &type); |
| 149 TranslateWithTableAndSet(type, kVPNTypeTable, shill::kProviderTypeProperty); | 177 TranslateWithTableAndSet(type, kVPNTypeTable, shill::kProviderTypeProperty); |
| 150 | 178 |
| 151 CopyFieldsAccordingToSignature(); | 179 CopyFieldsAccordingToSignature(); |
| 152 } | 180 } |
| 153 | 181 |
| 154 void LocalTranslator::TranslateWiFi() { | 182 void LocalTranslator::TranslateWiFi() { |
| 155 std::string security; | 183 std::string security; |
| 156 onc_object_->GetStringWithoutPathExpansion(::onc::wifi::kSecurity, &security); | 184 onc_object_->GetStringWithoutPathExpansion(::onc::wifi::kSecurity, &security); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 const OncValueSignature* onc_signature, | 327 const OncValueSignature* onc_signature, |
| 300 const base::DictionaryValue& onc_object) { | 328 const base::DictionaryValue& onc_object) { |
| 301 CHECK(onc_signature != NULL); | 329 CHECK(onc_signature != NULL); |
| 302 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); | 330 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); |
| 303 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); | 331 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); |
| 304 return shill_dictionary.Pass(); | 332 return shill_dictionary.Pass(); |
| 305 } | 333 } |
| 306 | 334 |
| 307 } // namespace onc | 335 } // namespace onc |
| 308 } // namespace chromeos | 336 } // namespace chromeos |
| OLD | NEW |