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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 // associated to |onc_field_name| and adds it to |onc_object_| at | 82 // associated to |onc_field_name| and adds it to |onc_object_| at |
83 // |onc_field_name|. | 83 // |onc_field_name|. |
84 void TranslateAndAddNestedObject(const std::string& onc_field_name, | 84 void TranslateAndAddNestedObject(const std::string& onc_field_name, |
85 const base::DictionaryValue& dictionary); | 85 const base::DictionaryValue& dictionary); |
86 | 86 |
87 // Creates an ONC object from |shill_dictionary_| according to the signature | 87 // Creates an ONC object from |shill_dictionary_| according to the signature |
88 // associated to |onc_field_name| and adds it to |onc_object_| at | 88 // associated to |onc_field_name| and adds it to |onc_object_| at |
89 // |onc_field_name|. | 89 // |onc_field_name|. |
90 void TranslateAndAddNestedObject(const std::string& onc_field_name); | 90 void TranslateAndAddNestedObject(const std::string& onc_field_name); |
91 | 91 |
92 // Sets |onc_field_name| in dictionary |onc_dictionary_name| in |onc_object_| | |
93 // to |value| if the dictionary exists. | |
94 void SetNestedOncValue(const std::string& onc_dictionary_name, | |
95 const std::string& onc_field_name, | |
96 const base::Value& value); | |
97 | |
92 // Translates a list of nested objects and adds the list to |onc_object_| at | 98 // Translates a list of nested objects and adds the list to |onc_object_| at |
93 // |onc_field_name|. If there are errors while parsing individual objects or | 99 // |onc_field_name|. If there are errors while parsing individual objects or |
94 // if the resulting list contains no entries, the result will not be added to | 100 // if the resulting list contains no entries, the result will not be added to |
95 // |onc_object_|. | 101 // |onc_object_|. |
96 void TranslateAndAddListOfObjects(const std::string& onc_field_name, | 102 void TranslateAndAddListOfObjects(const std::string& onc_field_name, |
97 const base::ListValue& list); | 103 const base::ListValue& list); |
98 | 104 |
99 // Applies function CopyProperty to each field of |value_signature| and its | 105 // Applies function CopyProperty to each field of |value_signature| and its |
100 // base signatures. | 106 // base signatures. |
101 void CopyPropertiesAccordingToSignature( | 107 void CopyPropertiesAccordingToSignature( |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 shill::kOpenVPNRemoteCertKUProperty, &certKU)) { | 181 shill::kOpenVPNRemoteCertKUProperty, &certKU)) { |
176 scoped_ptr<base::ListValue> certKUs(new base::ListValue); | 182 scoped_ptr<base::ListValue> certKUs(new base::ListValue); |
177 certKUs->AppendString(certKU); | 183 certKUs->AppendString(certKU); |
178 onc_object_->SetWithoutPathExpansion(::onc::openvpn::kRemoteCertKU, | 184 onc_object_->SetWithoutPathExpansion(::onc::openvpn::kRemoteCertKU, |
179 certKUs.release()); | 185 certKUs.release()); |
180 } | 186 } |
181 | 187 |
182 for (const OncFieldSignature* field_signature = onc_signature_->fields; | 188 for (const OncFieldSignature* field_signature = onc_signature_->fields; |
183 field_signature->onc_field_name != NULL; ++field_signature) { | 189 field_signature->onc_field_name != NULL; ++field_signature) { |
184 const std::string& onc_field_name = field_signature->onc_field_name; | 190 const std::string& onc_field_name = field_signature->onc_field_name; |
185 if (onc_field_name == ::onc::vpn::kSaveCredentials || | 191 if (onc_field_name == ::onc::openvpn::kRemoteCertKU || |
pneubeck (no reviews)
2014/08/19 19:26:38
Why?
These exceptions are for OpenVPN properties t
stevenjb
2014/08/19 23:20:18
SaveCredentials is a Service property, not a Servi
| |
186 onc_field_name == ::onc::openvpn::kRemoteCertKU || | |
187 onc_field_name == ::onc::openvpn::kServerCAPEMs) { | 192 onc_field_name == ::onc::openvpn::kServerCAPEMs) { |
188 CopyProperty(field_signature); | 193 CopyProperty(field_signature); |
189 continue; | 194 continue; |
190 } | 195 } |
191 | 196 |
192 std::string shill_property_name; | 197 std::string shill_property_name; |
193 const base::Value* shill_value = NULL; | 198 const base::Value* shill_value = NULL; |
194 if (!field_translation_table_ || | 199 if (!field_translation_table_ || |
195 !GetShillPropertyName(field_signature->onc_field_name, | 200 !GetShillPropertyName(field_signature->onc_field_name, |
196 field_translation_table_, | 201 field_translation_table_, |
(...skipping 28 matching lines...) Expand all Loading... | |
225 } | 230 } |
226 } | 231 } |
227 } | 232 } |
228 | 233 |
229 void ShillToONCTranslator::TranslateIPsec() { | 234 void ShillToONCTranslator::TranslateIPsec() { |
230 CopyPropertiesAccordingToSignature(); | 235 CopyPropertiesAccordingToSignature(); |
231 if (shill_dictionary_->HasKey(shill::kL2tpIpsecXauthUserProperty)) | 236 if (shill_dictionary_->HasKey(shill::kL2tpIpsecXauthUserProperty)) |
232 TranslateAndAddNestedObject(::onc::ipsec::kXAUTH); | 237 TranslateAndAddNestedObject(::onc::ipsec::kXAUTH); |
233 } | 238 } |
234 | 239 |
235 void ShillToONCTranslator::TranslateVPN() { | 240 void ShillToONCTranslator::TranslateVPN() { |
pneubeck (no reviews)
2014/08/19 19:26:38
I'll take a more thorough look at this part tomorr
stevenjb
2014/08/19 23:20:18
OK, hopefully the need for these changes will be m
| |
236 TranslateWithTableAndSet( | |
237 shill::kProviderTypeProperty, kVPNTypeTable, ::onc::vpn::kType); | |
238 CopyPropertiesAccordingToSignature(); | 241 CopyPropertiesAccordingToSignature(); |
239 | 242 |
240 std::string vpn_type; | 243 // Parse Shill Provider dictionary. |
241 if (onc_object_->GetStringWithoutPathExpansion(::onc::vpn::kType, | 244 const base::DictionaryValue* provider = NULL; |
242 &vpn_type)) { | 245 if (!shill_dictionary_->GetDictionaryWithoutPathExpansion( |
243 if (vpn_type == ::onc::vpn::kTypeL2TP_IPsec) { | 246 shill::kProviderProperty, &provider)) { |
244 TranslateAndAddNestedObject(::onc::vpn::kIPsec); | 247 LOG(ERROR) << "Shill VPN object with no Provider dictionary"; |
245 TranslateAndAddNestedObject(::onc::vpn::kL2TP); | 248 return; |
246 } else { | 249 } |
247 TranslateAndAddNestedObject(vpn_type); | 250 std::string shill_provider_type, onc_provider_type; |
251 if (!provider->GetStringWithoutPathExpansion( | |
252 shill::kTypeProperty, &shill_provider_type)) { | |
253 LOG(ERROR) << "Shill VPN object with no Provider.Type"; | |
254 return; | |
255 } | |
256 TranslateStringToONC(kVPNTypeTable, shill_provider_type, &onc_provider_type); | |
257 onc_object_->SetStringWithoutPathExpansion( | |
258 ::onc::vpn::kType, onc_provider_type); | |
259 std::string provider_host; | |
260 provider->GetStringWithoutPathExpansion(shill::kHostProperty, &provider_host); | |
261 onc_object_->SetStringWithoutPathExpansion(::onc::vpn::kHost, provider_host); | |
262 | |
263 const base::Value* save_credentials = NULL; | |
264 shill_dictionary_->GetWithoutPathExpansion( | |
265 shill::kSaveCredentialsProperty, &save_credentials); | |
266 | |
267 // Translate the nested dictionary. | |
268 if (onc_provider_type == ::onc::vpn::kTypeL2TP_IPsec) { | |
269 TranslateAndAddNestedObject(::onc::vpn::kIPsec, *provider); | |
270 TranslateAndAddNestedObject(::onc::vpn::kL2TP, *provider); | |
271 if (save_credentials) { | |
272 SetNestedOncValue( | |
273 ::onc::vpn::kIPsec, ::onc::vpn::kSaveCredentials, *save_credentials); | |
274 SetNestedOncValue( | |
275 ::onc::vpn::kL2TP, ::onc::vpn::kSaveCredentials, *save_credentials); | |
276 } | |
277 } else { | |
278 TranslateAndAddNestedObject(onc_provider_type, *provider); | |
279 if (save_credentials) { | |
280 SetNestedOncValue( | |
281 onc_provider_type, ::onc::vpn::kSaveCredentials, *save_credentials); | |
248 } | 282 } |
249 } | 283 } |
250 } | 284 } |
251 | 285 |
252 void ShillToONCTranslator::TranslateWiFiWithState() { | 286 void ShillToONCTranslator::TranslateWiFiWithState() { |
253 TranslateWithTableAndSet( | 287 TranslateWithTableAndSet( |
254 shill::kSecurityProperty, kWiFiSecurityTable, ::onc::wifi::kSecurity); | 288 shill::kSecurityProperty, kWiFiSecurityTable, ::onc::wifi::kSecurity); |
255 std::string ssid = shill_property_util::GetSSIDFromProperties( | 289 std::string ssid = shill_property_util::GetSSIDFromProperties( |
256 *shill_dictionary_, NULL /* ignore unknown encoding */); | 290 *shill_dictionary_, NULL /* ignore unknown encoding */); |
257 if (!ssid.empty()) | 291 if (!ssid.empty()) |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 const std::string& onc_field_name, | 431 const std::string& onc_field_name, |
398 const base::DictionaryValue& dictionary) { | 432 const base::DictionaryValue& dictionary) { |
399 const OncFieldSignature* field_signature = | 433 const OncFieldSignature* field_signature = |
400 GetFieldSignature(*onc_signature_, onc_field_name); | 434 GetFieldSignature(*onc_signature_, onc_field_name); |
401 DCHECK(field_signature) << "Unable to find signature for field " | 435 DCHECK(field_signature) << "Unable to find signature for field " |
402 << onc_field_name << "."; | 436 << onc_field_name << "."; |
403 ShillToONCTranslator nested_translator(dictionary, | 437 ShillToONCTranslator nested_translator(dictionary, |
404 *field_signature->value_signature); | 438 *field_signature->value_signature); |
405 scoped_ptr<base::DictionaryValue> nested_object = | 439 scoped_ptr<base::DictionaryValue> nested_object = |
406 nested_translator.CreateTranslatedONCObject(); | 440 nested_translator.CreateTranslatedONCObject(); |
407 if (nested_object->empty()) | 441 // Note: this may create an empty nested object which is necessary in case |
408 return; | 442 // properties are added later with SetNestedOncValue. |
409 onc_object_->SetWithoutPathExpansion(onc_field_name, nested_object.release()); | 443 onc_object_->SetWithoutPathExpansion(onc_field_name, nested_object.release()); |
410 } | 444 } |
411 | 445 |
446 void ShillToONCTranslator::SetNestedOncValue( | |
447 const std::string& onc_dictionary_name, | |
448 const std::string& onc_field_name, | |
449 const base::Value& value) { | |
450 base::DictionaryValue* nested; | |
451 if (!onc_object_->GetDictionaryWithoutPathExpansion( | |
452 onc_dictionary_name, &nested)) { | |
453 NOTREACHED(); | |
454 } | |
455 nested->SetWithoutPathExpansion(onc_field_name, value.DeepCopy()); | |
456 } | |
457 | |
412 void ShillToONCTranslator::TranslateAndAddListOfObjects( | 458 void ShillToONCTranslator::TranslateAndAddListOfObjects( |
413 const std::string& onc_field_name, | 459 const std::string& onc_field_name, |
414 const base::ListValue& list) { | 460 const base::ListValue& list) { |
415 const OncFieldSignature* field_signature = | 461 const OncFieldSignature* field_signature = |
416 GetFieldSignature(*onc_signature_, onc_field_name); | 462 GetFieldSignature(*onc_signature_, onc_field_name); |
417 if (field_signature->value_signature->onc_type != base::Value::TYPE_LIST) { | 463 if (field_signature->value_signature->onc_type != base::Value::TYPE_LIST) { |
418 LOG(ERROR) << "ONC Field name: '" << onc_field_name << "' has type '" | 464 LOG(ERROR) << "ONC Field name: '" << onc_field_name << "' has type '" |
419 << field_signature->value_signature->onc_type | 465 << field_signature->value_signature->onc_type |
420 << "', expected: base::Value::TYPE_LIST."; | 466 << "', expected: base::Value::TYPE_LIST."; |
421 return; | 467 return; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 const base::DictionaryValue& shill_dictionary, | 554 const base::DictionaryValue& shill_dictionary, |
509 const OncValueSignature* onc_signature) { | 555 const OncValueSignature* onc_signature) { |
510 CHECK(onc_signature != NULL); | 556 CHECK(onc_signature != NULL); |
511 | 557 |
512 ShillToONCTranslator translator(shill_dictionary, *onc_signature); | 558 ShillToONCTranslator translator(shill_dictionary, *onc_signature); |
513 return translator.CreateTranslatedONCObject(); | 559 return translator.CreateTranslatedONCObject(); |
514 } | 560 } |
515 | 561 |
516 } // namespace onc | 562 } // namespace onc |
517 } // namespace chromeos | 563 } // namespace chromeos |
OLD | NEW |