Chromium Code Reviews| 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 <string> | 5 #include <string> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 void CopyProperty(const OncFieldSignature* field_signature); | 129 void CopyProperty(const OncFieldSignature* field_signature); |
| 130 | 130 |
| 131 // If existent, translates the entry at |shill_property_name| in | 131 // If existent, translates the entry at |shill_property_name| in |
| 132 // |shill_dictionary_| using |table|. It is an error if no matching table | 132 // |shill_dictionary_| using |table|. It is an error if no matching table |
| 133 // entry is found. Writes the result as entry at |onc_field_name| in | 133 // entry is found. Writes the result as entry at |onc_field_name| in |
| 134 // |onc_object_|. | 134 // |onc_object_|. |
| 135 void TranslateWithTableAndSet(const std::string& shill_property_name, | 135 void TranslateWithTableAndSet(const std::string& shill_property_name, |
| 136 const StringTranslationEntry table[], | 136 const StringTranslationEntry table[], |
| 137 const std::string& onc_field_name); | 137 const std::string& onc_field_name); |
| 138 | 138 |
| 139 // Same as above but for nested properties. | |
| 140 bool TranslateWithTableAndSetNested(const std::string& shill_property_name, | |
| 141 const StringTranslationEntry table[], | |
| 142 const std::string& onc_dictionary_name, | |
| 143 const std::string& onc_field_name); | |
| 144 | |
| 139 // Returns the name of the Shill service provided in |shill_dictionary_| | 145 // Returns the name of the Shill service provided in |shill_dictionary_| |
| 140 // for debugging. | 146 // for debugging. |
| 141 std::string GetName(); | 147 std::string GetName(); |
| 142 | 148 |
| 143 const base::DictionaryValue* shill_dictionary_; | 149 const base::DictionaryValue* shill_dictionary_; |
| 144 ::onc::ONCSource onc_source_; | 150 ::onc::ONCSource onc_source_; |
| 145 const OncValueSignature* onc_signature_; | 151 const OncValueSignature* onc_signature_; |
| 146 const FieldTranslationEntry* field_translation_table_; | 152 const FieldTranslationEntry* field_translation_table_; |
| 147 std::unique_ptr<base::DictionaryValue> onc_object_; | 153 std::unique_ptr<base::DictionaryValue> onc_object_; |
| 148 const NetworkState* network_state_; | 154 const NetworkState* network_state_; |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 | 358 |
| 353 bool link_monitor_disable; | 359 bool link_monitor_disable; |
| 354 if (shill_dictionary_->GetBooleanWithoutPathExpansion( | 360 if (shill_dictionary_->GetBooleanWithoutPathExpansion( |
| 355 shill::kLinkMonitorDisableProperty, &link_monitor_disable)) { | 361 shill::kLinkMonitorDisableProperty, &link_monitor_disable)) { |
| 356 onc_object_->SetBooleanWithoutPathExpansion( | 362 onc_object_->SetBooleanWithoutPathExpansion( |
| 357 ::onc::wifi::kAllowGatewayARPPolling, !link_monitor_disable); | 363 ::onc::wifi::kAllowGatewayARPPolling, !link_monitor_disable); |
| 358 } | 364 } |
| 359 | 365 |
| 360 CopyPropertiesAccordingToSignature(); | 366 CopyPropertiesAccordingToSignature(); |
| 361 TranslateAndAddNestedObject(::onc::wifi::kEAP); | 367 TranslateAndAddNestedObject(::onc::wifi::kEAP); |
| 368 | |
| 369 // Translate EAP Outer and Inner values. Note: Shill provides an empty | |
| 370 // EAP property for non EAP networks, so check that before appmpting to | |
| 371 // translate. | |
| 372 std::string eap; | |
|
tbarzic
2017/05/01 18:05:56
Could this be done as part of TranslateAndAddNeste
stevenjb
2017/05/01 20:12:04
Yes, thanks, I've been out of this code for too lo
| |
| 373 shill_dictionary_->GetStringWithoutPathExpansion(shill::kEapMethodProperty, | |
| 374 &eap); | |
| 375 if (!eap.empty() && | |
| 376 TranslateWithTableAndSetNested(shill::kEapMethodProperty, kEAPOuterTable, | |
| 377 ::onc::wifi::kEAP, ::onc::eap::kOuter)) { | |
| 378 TranslateWithTableAndSetNested(shill::kEapPhase2AuthProperty, | |
| 379 kEAP_TTLS_InnerTable, ::onc::wifi::kEAP, | |
| 380 ::onc::eap::kInner); | |
| 381 } | |
| 362 } | 382 } |
| 363 | 383 |
| 364 void ShillToONCTranslator::TranslateWiMAXWithState() { | 384 void ShillToONCTranslator::TranslateWiMAXWithState() { |
| 365 CopyPropertiesAccordingToSignature(); | 385 CopyPropertiesAccordingToSignature(); |
| 366 TranslateAndAddNestedObject(::onc::wimax::kEAP); | 386 TranslateAndAddNestedObject(::onc::wimax::kEAP); |
| 367 } | 387 } |
| 368 | 388 |
| 369 void ShillToONCTranslator::TranslateCellularWithState() { | 389 void ShillToONCTranslator::TranslateCellularWithState() { |
| 370 CopyPropertiesAccordingToSignature(); | 390 CopyPropertiesAccordingToSignature(); |
| 371 TranslateWithTableAndSet(shill::kActivationStateProperty, | 391 TranslateWithTableAndSet(shill::kActivationStateProperty, |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 755 } | 775 } |
| 756 std::string onc_value; | 776 std::string onc_value; |
| 757 if (TranslateStringToONC(table, shill_value, &onc_value)) { | 777 if (TranslateStringToONC(table, shill_value, &onc_value)) { |
| 758 onc_object_->SetStringWithoutPathExpansion(onc_field_name, onc_value); | 778 onc_object_->SetStringWithoutPathExpansion(onc_field_name, onc_value); |
| 759 return; | 779 return; |
| 760 } | 780 } |
| 761 LOG(ERROR) << "Shill property '" << shill_property_name << "' with value " | 781 LOG(ERROR) << "Shill property '" << shill_property_name << "' with value " |
| 762 << shill_value << " couldn't be translated to ONC: " << GetName(); | 782 << shill_value << " couldn't be translated to ONC: " << GetName(); |
| 763 } | 783 } |
| 764 | 784 |
| 785 bool ShillToONCTranslator::TranslateWithTableAndSetNested( | |
| 786 const std::string& shill_property_name, | |
| 787 const StringTranslationEntry table[], | |
| 788 const std::string& onc_dictionary_name, | |
| 789 const std::string& onc_field_name) { | |
| 790 std::string shill_value; | |
| 791 if (!shill_dictionary_->GetStringWithoutPathExpansion(shill_property_name, | |
| 792 &shill_value)) { | |
| 793 return false; | |
| 794 } | |
| 795 std::string onc_value; | |
| 796 if (TranslateStringToONC(table, shill_value, &onc_value)) { | |
| 797 SetNestedOncValue(onc_dictionary_name, onc_field_name, | |
| 798 base::Value(onc_value)); | |
| 799 return true; | |
| 800 } | |
| 801 LOG(ERROR) << "Shill property '" << shill_property_name << "' with value " | |
| 802 << shill_value << " couldn't be translated to ONC: " << GetName(); | |
| 803 return false; | |
| 804 } | |
| 805 | |
| 765 std::string ShillToONCTranslator::GetName() { | 806 std::string ShillToONCTranslator::GetName() { |
| 766 DCHECK(shill_dictionary_); | 807 DCHECK(shill_dictionary_); |
| 767 std::string name; | 808 std::string name; |
| 768 shill_dictionary_->GetStringWithoutPathExpansion(shill::kNameProperty, &name); | 809 shill_dictionary_->GetStringWithoutPathExpansion(shill::kNameProperty, &name); |
| 769 return name; | 810 return name; |
| 770 } | 811 } |
| 771 | 812 |
| 772 } // namespace | 813 } // namespace |
| 773 | 814 |
| 774 std::unique_ptr<base::DictionaryValue> TranslateShillServiceToONCPart( | 815 std::unique_ptr<base::DictionaryValue> TranslateShillServiceToONCPart( |
| 775 const base::DictionaryValue& shill_dictionary, | 816 const base::DictionaryValue& shill_dictionary, |
| 776 ::onc::ONCSource onc_source, | 817 ::onc::ONCSource onc_source, |
| 777 const OncValueSignature* onc_signature, | 818 const OncValueSignature* onc_signature, |
| 778 const NetworkState* network_state) { | 819 const NetworkState* network_state) { |
| 779 CHECK(onc_signature != NULL); | 820 CHECK(onc_signature != NULL); |
| 780 | 821 |
| 781 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature, | 822 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature, |
| 782 network_state); | 823 network_state); |
| 783 return translator.CreateTranslatedONCObject(); | 824 return translator.CreateTranslatedONCObject(); |
| 784 } | 825 } |
| 785 | 826 |
| 786 } // namespace onc | 827 } // namespace onc |
| 787 } // namespace chromeos | 828 } // namespace chromeos |
| OLD | NEW |