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" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" |
12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "chromeos/network/network_profile_handler.h" | 15 #include "chromeos/network/network_profile_handler.h" |
15 #include "chromeos/network/network_state.h" | 16 #include "chromeos/network/network_state.h" |
16 #include "chromeos/network/network_util.h" | 17 #include "chromeos/network/network_util.h" |
17 #include "chromeos/network/onc/onc_signature.h" | 18 #include "chromeos/network/onc/onc_signature.h" |
18 #include "chromeos/network/onc/onc_translation_tables.h" | 19 #include "chromeos/network/onc/onc_translation_tables.h" |
19 #include "chromeos/network/onc/onc_translator.h" | 20 #include "chromeos/network/onc/onc_translator.h" |
20 #include "chromeos/network/onc/onc_utils.h" | 21 #include "chromeos/network/onc/onc_utils.h" |
21 #include "chromeos/network/shill_property_util.h" | 22 #include "chromeos/network/shill_property_util.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 TranslateAndAddNestedObject(::onc::openvpn::kVerifyX509); | 203 TranslateAndAddNestedObject(::onc::openvpn::kVerifyX509); |
203 | 204 |
204 // Shill supports only one RemoteCertKU but ONC requires a list. If existing, | 205 // Shill supports only one RemoteCertKU but ONC requires a list. If existing, |
205 // wraps the value into a list. | 206 // wraps the value into a list. |
206 std::string certKU; | 207 std::string certKU; |
207 if (shill_dictionary_->GetStringWithoutPathExpansion( | 208 if (shill_dictionary_->GetStringWithoutPathExpansion( |
208 shill::kOpenVPNRemoteCertKUProperty, &certKU)) { | 209 shill::kOpenVPNRemoteCertKUProperty, &certKU)) { |
209 std::unique_ptr<base::ListValue> certKUs(new base::ListValue); | 210 std::unique_ptr<base::ListValue> certKUs(new base::ListValue); |
210 certKUs->AppendString(certKU); | 211 certKUs->AppendString(certKU); |
211 onc_object_->SetWithoutPathExpansion(::onc::openvpn::kRemoteCertKU, | 212 onc_object_->SetWithoutPathExpansion(::onc::openvpn::kRemoteCertKU, |
212 certKUs.release()); | 213 std::move(certKUs)); |
213 } | 214 } |
214 | 215 |
215 for (const OncFieldSignature* field_signature = onc_signature_->fields; | 216 for (const OncFieldSignature* field_signature = onc_signature_->fields; |
216 field_signature->onc_field_name != NULL; ++field_signature) { | 217 field_signature->onc_field_name != NULL; ++field_signature) { |
217 const std::string& onc_field_name = field_signature->onc_field_name; | 218 const std::string& onc_field_name = field_signature->onc_field_name; |
218 if (onc_field_name == ::onc::openvpn::kRemoteCertKU || | 219 if (onc_field_name == ::onc::openvpn::kRemoteCertKU || |
219 onc_field_name == ::onc::openvpn::kServerCAPEMs) { | 220 onc_field_name == ::onc::openvpn::kServerCAPEMs) { |
220 CopyProperty(field_signature); | 221 CopyProperty(field_signature); |
221 continue; | 222 continue; |
222 } | 223 } |
(...skipping 17 matching lines...) Expand all Loading... |
240 shill_str, field_signature->value_signature->onc_type); | 241 shill_str, field_signature->value_signature->onc_type); |
241 | 242 |
242 if (translated.get() == NULL) { | 243 if (translated.get() == NULL) { |
243 LOG(ERROR) << "Shill property '" << shill_property_name | 244 LOG(ERROR) << "Shill property '" << shill_property_name |
244 << "' with value " << *shill_value | 245 << "' with value " << *shill_value |
245 << " couldn't be converted to base::Value::Type " | 246 << " couldn't be converted to base::Value::Type " |
246 << field_signature->value_signature->onc_type << ": " | 247 << field_signature->value_signature->onc_type << ": " |
247 << GetName(); | 248 << GetName(); |
248 } else { | 249 } else { |
249 onc_object_->SetWithoutPathExpansion(onc_field_name, | 250 onc_object_->SetWithoutPathExpansion(onc_field_name, |
250 translated.release()); | 251 std::move(translated)); |
251 } | 252 } |
252 } else { | 253 } else { |
253 LOG(ERROR) << "Shill property '" << shill_property_name << "' has value " | 254 LOG(ERROR) << "Shill property '" << shill_property_name << "' has value " |
254 << *shill_value << ", but expected a string: " << GetName(); | 255 << *shill_value << ", but expected a string: " << GetName(); |
255 } | 256 } |
256 } | 257 } |
257 } | 258 } |
258 | 259 |
259 void ShillToONCTranslator::TranslateIPsec() { | 260 void ShillToONCTranslator::TranslateIPsec() { |
260 CopyPropertiesAccordingToSignature(); | 261 CopyPropertiesAccordingToSignature(); |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 if (shill_dictionary_->GetStringWithoutPathExpansion( | 580 if (shill_dictionary_->GetStringWithoutPathExpansion( |
580 shill::kProxyConfigProperty, &proxy_config_str) && | 581 shill::kProxyConfigProperty, &proxy_config_str) && |
581 !proxy_config_str.empty()) { | 582 !proxy_config_str.empty()) { |
582 std::unique_ptr<base::DictionaryValue> proxy_config_value( | 583 std::unique_ptr<base::DictionaryValue> proxy_config_value( |
583 ReadDictionaryFromJson(proxy_config_str)); | 584 ReadDictionaryFromJson(proxy_config_str)); |
584 if (proxy_config_value) { | 585 if (proxy_config_value) { |
585 std::unique_ptr<base::DictionaryValue> proxy_settings = | 586 std::unique_ptr<base::DictionaryValue> proxy_settings = |
586 ConvertProxyConfigToOncProxySettings(std::move(proxy_config_value)); | 587 ConvertProxyConfigToOncProxySettings(std::move(proxy_config_value)); |
587 if (proxy_settings) { | 588 if (proxy_settings) { |
588 onc_object_->SetWithoutPathExpansion( | 589 onc_object_->SetWithoutPathExpansion( |
589 ::onc::network_config::kProxySettings, proxy_settings.release()); | 590 ::onc::network_config::kProxySettings, std::move(proxy_settings)); |
590 } | 591 } |
591 } | 592 } |
592 } | 593 } |
593 } | 594 } |
594 | 595 |
595 void ShillToONCTranslator::TranslateIPConfig() { | 596 void ShillToONCTranslator::TranslateIPConfig() { |
596 CopyPropertiesAccordingToSignature(); | 597 CopyPropertiesAccordingToSignature(); |
597 std::string shill_ip_method; | 598 std::string shill_ip_method; |
598 shill_dictionary_->GetStringWithoutPathExpansion(shill::kMethodProperty, | 599 shill_dictionary_->GetStringWithoutPathExpansion(shill::kMethodProperty, |
599 &shill_ip_method); | 600 &shill_ip_method); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 NOTREACHED() << "Unable to find signature for field: " << onc_field_name; | 645 NOTREACHED() << "Unable to find signature for field: " << onc_field_name; |
645 return; | 646 return; |
646 } | 647 } |
647 ShillToONCTranslator nested_translator(dictionary, onc_source_, | 648 ShillToONCTranslator nested_translator(dictionary, onc_source_, |
648 *field_signature->value_signature, | 649 *field_signature->value_signature, |
649 network_state_); | 650 network_state_); |
650 std::unique_ptr<base::DictionaryValue> nested_object = | 651 std::unique_ptr<base::DictionaryValue> nested_object = |
651 nested_translator.CreateTranslatedONCObject(); | 652 nested_translator.CreateTranslatedONCObject(); |
652 if (nested_object->empty()) | 653 if (nested_object->empty()) |
653 return; | 654 return; |
654 onc_object_->SetWithoutPathExpansion(onc_field_name, nested_object.release()); | 655 onc_object_->SetWithoutPathExpansion(onc_field_name, |
| 656 std::move(nested_object)); |
655 } | 657 } |
656 | 658 |
657 void ShillToONCTranslator::SetNestedOncValue( | 659 void ShillToONCTranslator::SetNestedOncValue( |
658 const std::string& onc_dictionary_name, | 660 const std::string& onc_dictionary_name, |
659 const std::string& onc_field_name, | 661 const std::string& onc_field_name, |
660 const base::Value& value) { | 662 const base::Value& value) { |
661 base::DictionaryValue* nested; | 663 base::DictionaryValue* nested; |
662 if (!onc_object_->GetDictionaryWithoutPathExpansion(onc_dictionary_name, | 664 if (!onc_object_->GetDictionaryWithoutPathExpansion(onc_dictionary_name, |
663 &nested)) { | 665 &nested)) { |
664 nested = new base::DictionaryValue; | 666 onc_object_->SetWithoutPathExpansion( |
665 onc_object_->SetWithoutPathExpansion(onc_dictionary_name, nested); | 667 onc_dictionary_name, base::MakeUnique<base::DictionaryValue>()); |
| 668 onc_object_->GetDictionaryWithoutPathExpansion(onc_dictionary_name, |
| 669 &nested); |
666 } | 670 } |
667 nested->SetWithoutPathExpansion(onc_field_name, value.DeepCopy()); | 671 nested->SetWithoutPathExpansion(onc_field_name, value.CreateDeepCopy()); |
668 } | 672 } |
669 | 673 |
670 void ShillToONCTranslator::TranslateAndAddListOfObjects( | 674 void ShillToONCTranslator::TranslateAndAddListOfObjects( |
671 const std::string& onc_field_name, | 675 const std::string& onc_field_name, |
672 const base::ListValue& list) { | 676 const base::ListValue& list) { |
673 const OncFieldSignature* field_signature = | 677 const OncFieldSignature* field_signature = |
674 GetFieldSignature(*onc_signature_, onc_field_name); | 678 GetFieldSignature(*onc_signature_, onc_field_name); |
675 if (field_signature->value_signature->onc_type != base::Value::Type::LIST) { | 679 if (field_signature->value_signature->onc_type != base::Value::Type::LIST) { |
676 LOG(ERROR) << "ONC Field name: '" << onc_field_name << "' has type '" | 680 LOG(ERROR) << "ONC Field name: '" << onc_field_name << "' has type '" |
677 << field_signature->value_signature->onc_type | 681 << field_signature->value_signature->onc_type |
(...skipping 14 matching lines...) Expand all Loading... |
692 std::unique_ptr<base::DictionaryValue> nested_object = | 696 std::unique_ptr<base::DictionaryValue> nested_object = |
693 nested_translator.CreateTranslatedONCObject(); | 697 nested_translator.CreateTranslatedONCObject(); |
694 // If the nested object couldn't be parsed, simply omit it. | 698 // If the nested object couldn't be parsed, simply omit it. |
695 if (nested_object->empty()) | 699 if (nested_object->empty()) |
696 continue; | 700 continue; |
697 result->Append(std::move(nested_object)); | 701 result->Append(std::move(nested_object)); |
698 } | 702 } |
699 // If there are no entries in the list, there is no need to expose this field. | 703 // If there are no entries in the list, there is no need to expose this field. |
700 if (result->empty()) | 704 if (result->empty()) |
701 return; | 705 return; |
702 onc_object_->SetWithoutPathExpansion(onc_field_name, result.release()); | 706 onc_object_->SetWithoutPathExpansion(onc_field_name, std::move(result)); |
703 } | 707 } |
704 | 708 |
705 void ShillToONCTranslator::CopyPropertiesAccordingToSignature() { | 709 void ShillToONCTranslator::CopyPropertiesAccordingToSignature() { |
706 CopyPropertiesAccordingToSignature(onc_signature_); | 710 CopyPropertiesAccordingToSignature(onc_signature_); |
707 } | 711 } |
708 | 712 |
709 void ShillToONCTranslator::CopyPropertiesAccordingToSignature( | 713 void ShillToONCTranslator::CopyPropertiesAccordingToSignature( |
710 const OncValueSignature* value_signature) { | 714 const OncValueSignature* value_signature) { |
711 if (value_signature->base_signature) | 715 if (value_signature->base_signature) |
712 CopyPropertiesAccordingToSignature(value_signature->base_signature); | 716 CopyPropertiesAccordingToSignature(value_signature->base_signature); |
(...skipping 21 matching lines...) Expand all Loading... |
734 LOG(ERROR) << "Shill property '" << shill_property_name << "' with value " | 738 LOG(ERROR) << "Shill property '" << shill_property_name << "' with value " |
735 << *shill_value << " has base::Value::Type " | 739 << *shill_value << " has base::Value::Type " |
736 << shill_value->GetType() << " but ONC field '" | 740 << shill_value->GetType() << " but ONC field '" |
737 << field_signature->onc_field_name << "' requires type " | 741 << field_signature->onc_field_name << "' requires type " |
738 << field_signature->value_signature->onc_type << ": " | 742 << field_signature->value_signature->onc_type << ": " |
739 << GetName(); | 743 << GetName(); |
740 return; | 744 return; |
741 } | 745 } |
742 | 746 |
743 onc_object_->SetWithoutPathExpansion(field_signature->onc_field_name, | 747 onc_object_->SetWithoutPathExpansion(field_signature->onc_field_name, |
744 shill_value->DeepCopy()); | 748 shill_value->CreateDeepCopy()); |
745 } | 749 } |
746 | 750 |
747 void ShillToONCTranslator::TranslateWithTableAndSet( | 751 void ShillToONCTranslator::TranslateWithTableAndSet( |
748 const std::string& shill_property_name, | 752 const std::string& shill_property_name, |
749 const StringTranslationEntry table[], | 753 const StringTranslationEntry table[], |
750 const std::string& onc_field_name) { | 754 const std::string& onc_field_name) { |
751 std::string shill_value; | 755 std::string shill_value; |
752 if (!shill_dictionary_->GetStringWithoutPathExpansion(shill_property_name, | 756 if (!shill_dictionary_->GetStringWithoutPathExpansion(shill_property_name, |
753 &shill_value)) { | 757 &shill_value)) { |
754 return; | 758 return; |
(...skipping 23 matching lines...) Expand all Loading... |
778 const NetworkState* network_state) { | 782 const NetworkState* network_state) { |
779 CHECK(onc_signature != NULL); | 783 CHECK(onc_signature != NULL); |
780 | 784 |
781 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature, | 785 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature, |
782 network_state); | 786 network_state); |
783 return translator.CreateTranslatedONCObject(); | 787 return translator.CreateTranslatedONCObject(); |
784 } | 788 } |
785 | 789 |
786 } // namespace onc | 790 } // namespace onc |
787 } // namespace chromeos | 791 } // namespace chromeos |
OLD | NEW |