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(); | 87 void TranslateSavedOrStaticIPConfig(const std::string& nameserver_property); |
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 const base::DictionaryValue* saved_ipconfig = nullptr; | 482 TranslateAndAddNestedObject(::onc::network_config::kSavedIPConfig); |
483 if (shill_dictionary_->GetDictionaryWithoutPathExpansion( | 483 TranslateAndAddNestedObject(::onc::network_config::kStaticIPConfig); |
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 } | |
495 } | 484 } |
496 | 485 |
497 void ShillToONCTranslator::TranslateIPConfig() { | 486 void ShillToONCTranslator::TranslateIPConfig() { |
498 CopyPropertiesAccordingToSignature(); | 487 CopyPropertiesAccordingToSignature(); |
499 std::string shill_ip_method; | 488 std::string shill_ip_method; |
500 shill_dictionary_->GetStringWithoutPathExpansion(shill::kMethodProperty, | 489 shill_dictionary_->GetStringWithoutPathExpansion(shill::kMethodProperty, |
501 &shill_ip_method); | 490 &shill_ip_method); |
502 std::string type; | 491 std::string type; |
503 if (shill_ip_method == shill::kTypeIPv4 || | 492 if (shill_ip_method == shill::kTypeIPv4 || |
504 shill_ip_method == shill::kTypeDHCP) { | 493 shill_ip_method == shill::kTypeDHCP) { |
505 type = ::onc::ipconfig::kIPv4; | 494 type = ::onc::ipconfig::kIPv4; |
506 } else if (shill_ip_method == shill::kTypeIPv6 || | 495 } else if (shill_ip_method == shill::kTypeIPv6 || |
507 shill_ip_method == shill::kTypeDHCP6) { | 496 shill_ip_method == shill::kTypeDHCP6) { |
508 type = ::onc::ipconfig::kIPv6; | 497 type = ::onc::ipconfig::kIPv6; |
509 } else { | 498 } else { |
510 return; // Ignore unhandled IPConfig types, e.g. bootp, zeroconf, ppp | 499 return; // Ignore unhandled IPConfig types, e.g. bootp, zeroconf, ppp |
511 } | 500 } |
512 | 501 |
513 onc_object_->SetStringWithoutPathExpansion(::onc::ipconfig::kType, type); | 502 onc_object_->SetStringWithoutPathExpansion(::onc::ipconfig::kType, type); |
514 } | 503 } |
515 | 504 |
516 void ShillToONCTranslator::TranslateSavedOrStaticIPConfig() { | 505 void ShillToONCTranslator::TranslateSavedOrStaticIPConfig( |
| 506 const std::string& nameserver_property) { |
517 CopyPropertiesAccordingToSignature(); | 507 CopyPropertiesAccordingToSignature(); |
518 | 508 // Saved/Static IP config nameservers are stored as a comma separated list. |
| 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 } |
519 // Static and Saved IPConfig in Shill are always of type IPv4. Set this type | 523 // Static and Saved IPConfig in Shill are always of type IPv4. Set this type |
520 // in ONC, but not if the object would be empty except the type. | 524 // in ONC, but not if the object would be empty except the type. |
521 if (!onc_object_->empty()) { | 525 if (!onc_object_->empty()) { |
522 onc_object_->SetStringWithoutPathExpansion(::onc::ipconfig::kType, | 526 onc_object_->SetStringWithoutPathExpansion(::onc::ipconfig::kType, |
523 ::onc::ipconfig::kIPv4); | 527 ::onc::ipconfig::kIPv4); |
524 } | 528 } |
525 } | 529 } |
526 | 530 |
527 void ShillToONCTranslator::TranslateSavedIPConfig() { | 531 void ShillToONCTranslator::TranslateSavedIPConfig() { |
528 TranslateSavedOrStaticIPConfig(); | 532 TranslateSavedOrStaticIPConfig(shill::kSavedIPNameServersProperty); |
529 } | 533 } |
530 | 534 |
531 void ShillToONCTranslator::TranslateStaticIPConfig() { | 535 void ShillToONCTranslator::TranslateStaticIPConfig() { |
532 TranslateSavedOrStaticIPConfig(); | 536 TranslateSavedOrStaticIPConfig(shill::kStaticIPNameServersProperty); |
533 } | 537 } |
534 | 538 |
535 void ShillToONCTranslator::TranslateAndAddNestedObject( | 539 void ShillToONCTranslator::TranslateAndAddNestedObject( |
536 const std::string& onc_field_name) { | 540 const std::string& onc_field_name) { |
537 TranslateAndAddNestedObject(onc_field_name, *shill_dictionary_); | 541 TranslateAndAddNestedObject(onc_field_name, *shill_dictionary_); |
538 } | 542 } |
539 | 543 |
540 void ShillToONCTranslator::TranslateAndAddNestedObject( | 544 void ShillToONCTranslator::TranslateAndAddNestedObject( |
541 const std::string& onc_field_name, | 545 const std::string& onc_field_name, |
542 const base::DictionaryValue& dictionary) { | 546 const base::DictionaryValue& dictionary) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 ::onc::ONCSource onc_source, | 683 ::onc::ONCSource onc_source, |
680 const OncValueSignature* onc_signature) { | 684 const OncValueSignature* onc_signature) { |
681 CHECK(onc_signature != NULL); | 685 CHECK(onc_signature != NULL); |
682 | 686 |
683 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature); | 687 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature); |
684 return translator.CreateTranslatedONCObject(); | 688 return translator.CreateTranslatedONCObject(); |
685 } | 689 } |
686 | 690 |
687 } // namespace onc | 691 } // namespace onc |
688 } // namespace chromeos | 692 } // namespace chromeos |
OLD | NEW |