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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 // base signatures. | 106 // base signatures. |
107 void CopyPropertiesAccordingToSignature( | 107 void CopyPropertiesAccordingToSignature( |
108 const OncValueSignature* value_signature); | 108 const OncValueSignature* value_signature); |
109 | 109 |
110 // Applies function CopyProperty to each field of |onc_signature_| and its | 110 // Applies function CopyProperty to each field of |onc_signature_| and its |
111 // base signatures. | 111 // base signatures. |
112 void CopyPropertiesAccordingToSignature(); | 112 void CopyPropertiesAccordingToSignature(); |
113 | 113 |
114 // If |shill_property_name| is defined in |field_signature|, copies this | 114 // If |shill_property_name| is defined in |field_signature|, copies this |
115 // entry from |shill_dictionary_| to |onc_object_| if it exists. | 115 // entry from |shill_dictionary_| to |onc_object_| if it exists. |
116 void CopyProperty(const OncFieldSignature* field_signature); | 116 void CopyProperty(const OncFieldSignature* field_signature); |
armansito
2014/09/03 21:45:02
Can you include the new fields below in the unit t
stevenjb
2014/09/08 18:14:11
Addressed in a separate CL.
| |
117 | 117 |
118 // If |shill_property_name| exists in |shill_dictionary_|, copy it to | |
119 // |onc_field_name| in |dictionary|. | |
120 void CopyPropertyToDictionary(const std::string& shill_property_name, | |
121 const std::string& onc_field_name, | |
122 base::DictionaryValue* dictionary); | |
123 | |
118 // If existent, translates the entry at |shill_property_name| in | 124 // If existent, translates the entry at |shill_property_name| in |
119 // |shill_dictionary_| using |table|. It is an error if no matching table | 125 // |shill_dictionary_| using |table|. It is an error if no matching table |
120 // entry is found. Writes the result as entry at |onc_field_name| in | 126 // entry is found. Writes the result as entry at |onc_field_name| in |
121 // |onc_object_|. | 127 // |onc_object_|. |
122 void TranslateWithTableAndSet(const std::string& shill_property_name, | 128 void TranslateWithTableAndSet(const std::string& shill_property_name, |
123 const StringTranslationEntry table[], | 129 const StringTranslationEntry table[], |
124 const std::string& onc_field_name); | 130 const std::string& onc_field_name); |
125 | 131 |
126 // Returns the name of the Shill service provided in |shill_dictionary_| | 132 // Returns the name of the Shill service provided in |shill_dictionary_| |
127 // for debugging. | 133 // for debugging. |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 | 423 |
418 // Shill's Service has an IPConfig property (note the singular), not an | 424 // Shill's Service has an IPConfig property (note the singular), not an |
419 // IPConfigs property. However, we require the caller of the translation to | 425 // IPConfigs property. However, we require the caller of the translation to |
420 // patch the Shill dictionary before passing it to the translator. | 426 // patch the Shill dictionary before passing it to the translator. |
421 const base::ListValue* shill_ipconfigs = NULL; | 427 const base::ListValue* shill_ipconfigs = NULL; |
422 if (shill_dictionary_->GetListWithoutPathExpansion(shill::kIPConfigsProperty, | 428 if (shill_dictionary_->GetListWithoutPathExpansion(shill::kIPConfigsProperty, |
423 &shill_ipconfigs)) { | 429 &shill_ipconfigs)) { |
424 TranslateAndAddListOfObjects(::onc::network_config::kIPConfigs, | 430 TranslateAndAddListOfObjects(::onc::network_config::kIPConfigs, |
425 *shill_ipconfigs); | 431 *shill_ipconfigs); |
426 } | 432 } |
433 | |
434 // Convert StaticIP and SavedIP properties to dictionary format. | |
435 scoped_ptr<base::DictionaryValue> static_ip(new base::DictionaryValue); | |
436 CopyPropertyToDictionary(shill::kStaticIPAddressProperty, | |
437 ::onc::ipconfig::kIPAddress, | |
438 static_ip.get()); | |
439 CopyPropertyToDictionary(shill::kStaticIPGatewayProperty, | |
440 ::onc::ipconfig::kGateway, | |
441 static_ip.get()); | |
442 CopyPropertyToDictionary(shill::kStaticIPNameServersProperty, | |
443 ::onc::ipconfig::kNameServers, | |
444 static_ip.get()); | |
445 CopyPropertyToDictionary(shill::kStaticIPPrefixlenProperty, | |
446 ::onc::ipconfig::kRoutingPrefix, | |
447 static_ip.get()); | |
448 if (!static_ip->empty()) { | |
449 onc_object_->SetWithoutPathExpansion(::onc::network_config::kStaticIPConfig, | |
450 static_ip.release()); | |
451 } | |
452 | |
453 scoped_ptr<base::DictionaryValue> saved_ip(new base::DictionaryValue); | |
454 CopyPropertyToDictionary(shill::kSavedIPAddressProperty, | |
455 ::onc::ipconfig::kIPAddress, | |
456 saved_ip.get()); | |
457 CopyPropertyToDictionary(shill::kSavedIPGatewayProperty, | |
458 ::onc::ipconfig::kGateway, | |
459 saved_ip.get()); | |
460 CopyPropertyToDictionary(shill::kSavedIPNameServersProperty, | |
461 ::onc::ipconfig::kNameServers, | |
462 saved_ip.get()); | |
463 CopyPropertyToDictionary(shill::kSavedIPPrefixlenProperty, | |
464 ::onc::ipconfig::kRoutingPrefix, | |
465 saved_ip.get()); | |
466 if (!saved_ip->empty()) { | |
467 onc_object_->SetWithoutPathExpansion(::onc::network_config::kSavedIPConfig, | |
468 saved_ip.release()); | |
469 } | |
427 } | 470 } |
428 | 471 |
429 void ShillToONCTranslator::TranslateIPConfig() { | 472 void ShillToONCTranslator::TranslateIPConfig() { |
430 CopyPropertiesAccordingToSignature(); | 473 CopyPropertiesAccordingToSignature(); |
431 std::string shill_ip_method; | 474 std::string shill_ip_method; |
432 shill_dictionary_->GetStringWithoutPathExpansion(shill::kMethodProperty, | 475 shill_dictionary_->GetStringWithoutPathExpansion(shill::kMethodProperty, |
433 &shill_ip_method); | 476 &shill_ip_method); |
434 std::string type; | 477 std::string type; |
435 if (shill_ip_method == shill::kTypeIPv4 || | 478 if (shill_ip_method == shill::kTypeIPv4 || |
436 shill_ip_method == shill::kTypeDHCP) { | 479 shill_ip_method == shill::kTypeDHCP) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
550 << "' requires type " | 593 << "' requires type " |
551 << field_signature->value_signature->onc_type | 594 << field_signature->value_signature->onc_type |
552 << ": " << GetName(); | 595 << ": " << GetName(); |
553 return; | 596 return; |
554 } | 597 } |
555 | 598 |
556 onc_object_->SetWithoutPathExpansion(field_signature->onc_field_name, | 599 onc_object_->SetWithoutPathExpansion(field_signature->onc_field_name, |
557 shill_value->DeepCopy()); | 600 shill_value->DeepCopy()); |
558 } | 601 } |
559 | 602 |
603 void ShillToONCTranslator::CopyPropertyToDictionary( | |
604 const std::string& shill_property_name, | |
605 const std::string& onc_field_name, | |
606 base::DictionaryValue* dictionary) { | |
607 const base::Value* shill_value; | |
608 if (!shill_dictionary_->GetWithoutPathExpansion(shill_property_name, | |
609 &shill_value)) { | |
610 return; | |
611 } | |
612 dictionary->SetWithoutPathExpansion(onc_field_name, | |
613 shill_value->DeepCopy()); | |
614 } | |
615 | |
560 void ShillToONCTranslator::TranslateWithTableAndSet( | 616 void ShillToONCTranslator::TranslateWithTableAndSet( |
561 const std::string& shill_property_name, | 617 const std::string& shill_property_name, |
562 const StringTranslationEntry table[], | 618 const StringTranslationEntry table[], |
563 const std::string& onc_field_name) { | 619 const std::string& onc_field_name) { |
564 std::string shill_value; | 620 std::string shill_value; |
565 if (!shill_dictionary_->GetStringWithoutPathExpansion(shill_property_name, | 621 if (!shill_dictionary_->GetStringWithoutPathExpansion(shill_property_name, |
566 &shill_value)) { | 622 &shill_value)) { |
567 return; | 623 return; |
568 } | 624 } |
569 std::string onc_value; | 625 std::string onc_value; |
(...skipping 18 matching lines...) Expand all Loading... | |
588 const base::DictionaryValue& shill_dictionary, | 644 const base::DictionaryValue& shill_dictionary, |
589 const OncValueSignature* onc_signature) { | 645 const OncValueSignature* onc_signature) { |
590 CHECK(onc_signature != NULL); | 646 CHECK(onc_signature != NULL); |
591 | 647 |
592 ShillToONCTranslator translator(shill_dictionary, *onc_signature); | 648 ShillToONCTranslator translator(shill_dictionary, *onc_signature); |
593 return translator.CreateTranslatedONCObject(); | 649 return translator.CreateTranslatedONCObject(); |
594 } | 650 } |
595 | 651 |
596 } // namespace onc | 652 } // namespace onc |
597 } // namespace chromeos | 653 } // namespace chromeos |
OLD | NEW |