| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 } else { | 115 } else { |
| 116 // Shill wants all Provider/VPN fields to be strings. | 116 // Shill wants all Provider/VPN fields to be strings. |
| 117 translated = ConvertValueToString(it.value()); | 117 translated = ConvertValueToString(it.value()); |
| 118 } | 118 } |
| 119 AddValueAccordingToSignature(it.key(), translated.Pass()); | 119 AddValueAccordingToSignature(it.key(), translated.Pass()); |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 | 122 |
| 123 void LocalTranslator::TranslateVPN() { | 123 void LocalTranslator::TranslateVPN() { |
| 124 std::string type; | 124 std::string type; |
| 125 onc_object_->GetStringWithoutPathExpansion(kType, &type); | 125 onc_object_->GetStringWithoutPathExpansion(vpn::kType, &type); |
| 126 TranslateWithTableAndSet(type, kVPNTypeTable, | 126 TranslateWithTableAndSet(type, kVPNTypeTable, |
| 127 flimflam::kProviderTypeProperty); | 127 flimflam::kProviderTypeProperty); |
| 128 | 128 |
| 129 CopyFieldsAccordingToSignature(); | 129 CopyFieldsAccordingToSignature(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void LocalTranslator::TranslateWiFi() { | 132 void LocalTranslator::TranslateWiFi() { |
| 133 std::string security; | 133 std::string security; |
| 134 onc_object_->GetStringWithoutPathExpansion(wifi::kSecurity, &security); | 134 onc_object_->GetStringWithoutPathExpansion(wifi::kSecurity, &security); |
| 135 TranslateWithTableAndSet(security, kWiFiSecurityTable, | 135 TranslateWithTableAndSet(security, kWiFiSecurityTable, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 155 outer == eap::kPEAP ? kEAP_PEAP_InnerTable : kEAP_TTLS_InnerTable; | 155 outer == eap::kPEAP ? kEAP_PEAP_InnerTable : kEAP_TTLS_InnerTable; |
| 156 TranslateWithTableAndSet(inner, table, flimflam::kEapPhase2AuthProperty); | 156 TranslateWithTableAndSet(inner, table, flimflam::kEapPhase2AuthProperty); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 CopyFieldsAccordingToSignature(); | 160 CopyFieldsAccordingToSignature(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void LocalTranslator::TranslateNetworkConfiguration() { | 163 void LocalTranslator::TranslateNetworkConfiguration() { |
| 164 std::string type; | 164 std::string type; |
| 165 onc_object_->GetStringWithoutPathExpansion(kType, &type); | 165 onc_object_->GetStringWithoutPathExpansion(network_config::kType, &type); |
| 166 TranslateWithTableAndSet(type, kNetworkTypeTable, flimflam::kTypeProperty); | 166 TranslateWithTableAndSet(type, kNetworkTypeTable, flimflam::kTypeProperty); |
| 167 | 167 |
| 168 // Shill doesn't allow setting the name for non-VPN networks. | 168 // Shill doesn't allow setting the name for non-VPN networks. |
| 169 if (type == kVPN) { | 169 if (type == network_type::kVPN) { |
| 170 std::string name; | 170 std::string name; |
| 171 onc_object_->GetStringWithoutPathExpansion(kName, &name); | 171 onc_object_->GetStringWithoutPathExpansion(network_config::kName, &name); |
| 172 shill_dictionary_->SetStringWithoutPathExpansion( | 172 shill_dictionary_->SetStringWithoutPathExpansion( |
| 173 flimflam::kNameProperty, name); | 173 flimflam::kNameProperty, name); |
| 174 } | 174 } |
| 175 | 175 |
| 176 CopyFieldsAccordingToSignature(); | 176 CopyFieldsAccordingToSignature(); |
| 177 } | 177 } |
| 178 | 178 |
| 179 void LocalTranslator::CopyFieldsAccordingToSignature() { | 179 void LocalTranslator::CopyFieldsAccordingToSignature() { |
| 180 for (base::DictionaryValue::Iterator it(*onc_object_); it.HasNext(); | 180 for (base::DictionaryValue::Iterator it(*onc_object_); it.HasNext(); |
| 181 it.Advance()) { | 181 it.Advance()) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 196 return; | 196 return; |
| 197 | 197 |
| 198 shill_dictionary_->SetWithoutPathExpansion( | 198 shill_dictionary_->SetWithoutPathExpansion( |
| 199 field_signature->shill_property_name, value.release()); | 199 field_signature->shill_property_name, value.release()); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void LocalTranslator::TranslateWithTableAndSet( | 202 void LocalTranslator::TranslateWithTableAndSet( |
| 203 const std::string& onc_value, | 203 const std::string& onc_value, |
| 204 const StringTranslationEntry table[], | 204 const StringTranslationEntry table[], |
| 205 const std::string& shill_property_name) { | 205 const std::string& shill_property_name) { |
| 206 for (int i = 0; table[i].onc_value != NULL; ++i) { | 206 std::string shill_value; |
| 207 if (onc_value != table[i].onc_value) | 207 if (TranslateStringToShill(table, onc_value, &shill_value)) { |
| 208 continue; | |
| 209 shill_dictionary_->SetStringWithoutPathExpansion(shill_property_name, | 208 shill_dictionary_->SetStringWithoutPathExpansion(shill_property_name, |
| 210 table[i].shill_value); | 209 shill_value); |
| 211 return; | 210 return; |
| 212 } | 211 } |
| 213 // As we previously validate ONC, this case should never occur. If it still | 212 // As we previously validate ONC, this case should never occur. If it still |
| 214 // occurs, we should check here. Otherwise the failure will only show up much | 213 // occurs, we should check here. Otherwise the failure will only show up much |
| 215 // later in Shill. | 214 // later in Shill. |
| 216 LOG(ERROR) << "Value '" << onc_value << "cannot be translated to Shill"; | 215 LOG(ERROR) << "Value '" << onc_value |
| 216 << " cannot be translated to Shill property " |
| 217 << shill_property_name; |
| 217 } | 218 } |
| 218 | 219 |
| 219 // Iterates recursively over |onc_object| and its |signature|. At each object | 220 // Iterates recursively over |onc_object| and its |signature|. At each object |
| 220 // applies the local translation using LocalTranslator::TranslateFields. The | 221 // applies the local translation using LocalTranslator::TranslateFields. The |
| 221 // results are written to |shill_dictionary|. | 222 // results are written to |shill_dictionary|. |
| 222 void TranslateONCHierarchy(const OncValueSignature& signature, | 223 void TranslateONCHierarchy(const OncValueSignature& signature, |
| 223 const base::DictionaryValue& onc_object, | 224 const base::DictionaryValue& onc_object, |
| 224 base::DictionaryValue* shill_dictionary) { | 225 base::DictionaryValue* shill_dictionary) { |
| 225 // Translates fields of |onc_object| and writes them to |shill_dictionary_|. | 226 // Translates fields of |onc_object| and writes them to |shill_dictionary_|. |
| 226 LocalTranslator translator(signature, onc_object, shill_dictionary); | 227 LocalTranslator translator(signature, onc_object, shill_dictionary); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 247 const OncValueSignature* onc_signature, | 248 const OncValueSignature* onc_signature, |
| 248 const base::DictionaryValue& onc_object) { | 249 const base::DictionaryValue& onc_object) { |
| 249 CHECK(onc_signature != NULL); | 250 CHECK(onc_signature != NULL); |
| 250 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); | 251 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); |
| 251 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); | 252 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); |
| 252 return shill_dictionary.Pass(); | 253 return shill_dictionary.Pass(); |
| 253 } | 254 } |
| 254 | 255 |
| 255 } // namespace onc | 256 } // namespace onc |
| 256 } // namespace chromeos | 257 } // namespace chromeos |
| OLD | NEW |