| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 void TranslateEthernet(); | 77 void TranslateEthernet(); |
| 78 void TranslateOpenVPN(); | 78 void TranslateOpenVPN(); |
| 79 void TranslateIPsec(); | 79 void TranslateIPsec(); |
| 80 void TranslateVPN(); | 80 void TranslateVPN(); |
| 81 void TranslateWiFiWithState(); | 81 void TranslateWiFiWithState(); |
| 82 void TranslateWiMAXWithState(); | 82 void TranslateWiMAXWithState(); |
| 83 void TranslateCellularWithState(); | 83 void TranslateCellularWithState(); |
| 84 void TranslateCellularDevice(); | 84 void TranslateCellularDevice(); |
| 85 void TranslateNetworkWithState(); | 85 void TranslateNetworkWithState(); |
| 86 void TranslateIPConfig(); | 86 void TranslateIPConfig(); |
| 87 void TranslateSavedOrStaticIPConfig(const std::string& nameserver_property); | 87 void TranslateSavedOrStaticIPConfig(); |
| 88 void TranslateSavedIPConfig(); | 88 void TranslateSavedIPConfig(); |
| 89 void TranslateStaticIPConfig(); | 89 void TranslateStaticIPConfig(); |
| 90 | 90 |
| 91 // Creates an ONC object from |dictionary| according to the signature | 91 // Creates an ONC object from |dictionary| according to the signature |
| 92 // associated to |onc_field_name| and adds it to |onc_object_| at | 92 // associated to |onc_field_name| and adds it to |onc_object_| at |
| 93 // |onc_field_name|. | 93 // |onc_field_name|. |
| 94 void TranslateAndAddNestedObject(const std::string& onc_field_name, | 94 void TranslateAndAddNestedObject(const std::string& onc_field_name, |
| 95 const base::DictionaryValue& dictionary); | 95 const base::DictionaryValue& dictionary); |
| 96 | 96 |
| 97 // Creates an ONC object from |shill_dictionary_| according to the signature | 97 // Creates an ONC object from |shill_dictionary_| according to the signature |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 // Shill's Service has an IPConfig property (note the singular), not an | 472 // Shill's Service has an IPConfig property (note the singular), not an |
| 473 // IPConfigs property. However, we require the caller of the translation to | 473 // IPConfigs property. However, we require the caller of the translation to |
| 474 // patch the Shill dictionary before passing it to the translator. | 474 // patch the Shill dictionary before passing it to the translator. |
| 475 const base::ListValue* shill_ipconfigs = NULL; | 475 const base::ListValue* shill_ipconfigs = NULL; |
| 476 if (shill_dictionary_->GetListWithoutPathExpansion(shill::kIPConfigsProperty, | 476 if (shill_dictionary_->GetListWithoutPathExpansion(shill::kIPConfigsProperty, |
| 477 &shill_ipconfigs)) { | 477 &shill_ipconfigs)) { |
| 478 TranslateAndAddListOfObjects(::onc::network_config::kIPConfigs, | 478 TranslateAndAddListOfObjects(::onc::network_config::kIPConfigs, |
| 479 *shill_ipconfigs); | 479 *shill_ipconfigs); |
| 480 } | 480 } |
| 481 | 481 |
| 482 TranslateAndAddNestedObject(::onc::network_config::kSavedIPConfig); | 482 const base::DictionaryValue* saved_ipconfig = nullptr; |
| 483 TranslateAndAddNestedObject(::onc::network_config::kStaticIPConfig); | 483 if (shill_dictionary_->GetDictionaryWithoutPathExpansion( |
| 484 shill::kSavedIPConfigProperty, &saved_ipconfig)) { |
| 485 TranslateAndAddNestedObject(::onc::network_config::kSavedIPConfig, |
| 486 *saved_ipconfig); |
| 487 } |
| 488 |
| 489 const base::DictionaryValue* static_ipconfig = nullptr; |
| 490 if (shill_dictionary_->GetDictionaryWithoutPathExpansion( |
| 491 shill::kStaticIPConfigProperty, &static_ipconfig)) { |
| 492 TranslateAndAddNestedObject(::onc::network_config::kStaticIPConfig, |
| 493 *static_ipconfig); |
| 494 } |
| 484 } | 495 } |
| 485 | 496 |
| 486 void ShillToONCTranslator::TranslateIPConfig() { | 497 void ShillToONCTranslator::TranslateIPConfig() { |
| 487 CopyPropertiesAccordingToSignature(); | 498 CopyPropertiesAccordingToSignature(); |
| 488 std::string shill_ip_method; | 499 std::string shill_ip_method; |
| 489 shill_dictionary_->GetStringWithoutPathExpansion(shill::kMethodProperty, | 500 shill_dictionary_->GetStringWithoutPathExpansion(shill::kMethodProperty, |
| 490 &shill_ip_method); | 501 &shill_ip_method); |
| 491 std::string type; | 502 std::string type; |
| 492 if (shill_ip_method == shill::kTypeIPv4 || | 503 if (shill_ip_method == shill::kTypeIPv4 || |
| 493 shill_ip_method == shill::kTypeDHCP) { | 504 shill_ip_method == shill::kTypeDHCP) { |
| 494 type = ::onc::ipconfig::kIPv4; | 505 type = ::onc::ipconfig::kIPv4; |
| 495 } else if (shill_ip_method == shill::kTypeIPv6 || | 506 } else if (shill_ip_method == shill::kTypeIPv6 || |
| 496 shill_ip_method == shill::kTypeDHCP6) { | 507 shill_ip_method == shill::kTypeDHCP6) { |
| 497 type = ::onc::ipconfig::kIPv6; | 508 type = ::onc::ipconfig::kIPv6; |
| 498 } else { | 509 } else { |
| 499 return; // Ignore unhandled IPConfig types, e.g. bootp, zeroconf, ppp | 510 return; // Ignore unhandled IPConfig types, e.g. bootp, zeroconf, ppp |
| 500 } | 511 } |
| 501 | 512 |
| 502 onc_object_->SetStringWithoutPathExpansion(::onc::ipconfig::kType, type); | 513 onc_object_->SetStringWithoutPathExpansion(::onc::ipconfig::kType, type); |
| 503 } | 514 } |
| 504 | 515 |
| 505 void ShillToONCTranslator::TranslateSavedOrStaticIPConfig( | 516 void ShillToONCTranslator::TranslateSavedOrStaticIPConfig() { |
| 506 const std::string& nameserver_property) { | |
| 507 CopyPropertiesAccordingToSignature(); | 517 CopyPropertiesAccordingToSignature(); |
| 508 // Saved/Static IP config nameservers are stored as a comma separated list. | 518 |
| 509 std::string shill_nameservers; | |
| 510 shill_dictionary_->GetStringWithoutPathExpansion( | |
| 511 nameserver_property, &shill_nameservers); | |
| 512 std::vector<std::string> onc_nameserver_vector; | |
| 513 if (Tokenize(shill_nameservers, ",", &onc_nameserver_vector) > 0) { | |
| 514 scoped_ptr<base::ListValue> onc_nameservers(new base::ListValue); | |
| 515 for (std::vector<std::string>::iterator iter = | |
| 516 onc_nameserver_vector.begin(); | |
| 517 iter != onc_nameserver_vector.end(); ++iter) { | |
| 518 onc_nameservers->AppendString(*iter); | |
| 519 } | |
| 520 onc_object_->SetWithoutPathExpansion(::onc::ipconfig::kNameServers, | |
| 521 onc_nameservers.release()); | |
| 522 } | |
| 523 // Static and Saved IPConfig in Shill are always of type IPv4. Set this type | 519 // Static and Saved IPConfig in Shill are always of type IPv4. Set this type |
| 524 // in ONC, but not if the object would be empty except the type. | 520 // in ONC, but not if the object would be empty except the type. |
| 525 if (!onc_object_->empty()) { | 521 if (!onc_object_->empty()) { |
| 526 onc_object_->SetStringWithoutPathExpansion(::onc::ipconfig::kType, | 522 onc_object_->SetStringWithoutPathExpansion(::onc::ipconfig::kType, |
| 527 ::onc::ipconfig::kIPv4); | 523 ::onc::ipconfig::kIPv4); |
| 528 } | 524 } |
| 529 } | 525 } |
| 530 | 526 |
| 531 void ShillToONCTranslator::TranslateSavedIPConfig() { | 527 void ShillToONCTranslator::TranslateSavedIPConfig() { |
| 532 TranslateSavedOrStaticIPConfig(shill::kSavedIPNameServersProperty); | 528 TranslateSavedOrStaticIPConfig(); |
| 533 } | 529 } |
| 534 | 530 |
| 535 void ShillToONCTranslator::TranslateStaticIPConfig() { | 531 void ShillToONCTranslator::TranslateStaticIPConfig() { |
| 536 TranslateSavedOrStaticIPConfig(shill::kStaticIPNameServersProperty); | 532 TranslateSavedOrStaticIPConfig(); |
| 537 } | 533 } |
| 538 | 534 |
| 539 void ShillToONCTranslator::TranslateAndAddNestedObject( | 535 void ShillToONCTranslator::TranslateAndAddNestedObject( |
| 540 const std::string& onc_field_name) { | 536 const std::string& onc_field_name) { |
| 541 TranslateAndAddNestedObject(onc_field_name, *shill_dictionary_); | 537 TranslateAndAddNestedObject(onc_field_name, *shill_dictionary_); |
| 542 } | 538 } |
| 543 | 539 |
| 544 void ShillToONCTranslator::TranslateAndAddNestedObject( | 540 void ShillToONCTranslator::TranslateAndAddNestedObject( |
| 545 const std::string& onc_field_name, | 541 const std::string& onc_field_name, |
| 546 const base::DictionaryValue& dictionary) { | 542 const base::DictionaryValue& dictionary) { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 ::onc::ONCSource onc_source, | 679 ::onc::ONCSource onc_source, |
| 684 const OncValueSignature* onc_signature) { | 680 const OncValueSignature* onc_signature) { |
| 685 CHECK(onc_signature != NULL); | 681 CHECK(onc_signature != NULL); |
| 686 | 682 |
| 687 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature); | 683 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature); |
| 688 return translator.CreateTranslatedONCObject(); | 684 return translator.CreateTranslatedONCObject(); |
| 689 } | 685 } |
| 690 | 686 |
| 691 } // namespace onc | 687 } // namespace onc |
| 692 } // namespace chromeos | 688 } // namespace chromeos |
| OLD | NEW |