Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: chromeos/network/onc/onc_translator_shill_to_onc.cc

Issue 23506040: Add ethernet to ONC validation and Shill translation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed networkingPrivate api test on non-chromeos. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 : shill_dictionary_(&shill_dictionary), 51 : shill_dictionary_(&shill_dictionary),
52 onc_signature_(&onc_signature) { 52 onc_signature_(&onc_signature) {
53 field_translation_table_ = GetFieldTranslationTable(onc_signature); 53 field_translation_table_ = GetFieldTranslationTable(onc_signature);
54 } 54 }
55 55
56 // Translates the associated Shill dictionary and creates an ONC object of the 56 // Translates the associated Shill dictionary and creates an ONC object of the
57 // given signature. 57 // given signature.
58 scoped_ptr<base::DictionaryValue> CreateTranslatedONCObject(); 58 scoped_ptr<base::DictionaryValue> CreateTranslatedONCObject();
59 59
60 private: 60 private:
61 void TranslateEthernet();
61 void TranslateOpenVPN(); 62 void TranslateOpenVPN();
62 void TranslateVPN(); 63 void TranslateVPN();
63 void TranslateWiFiWithState(); 64 void TranslateWiFiWithState();
64 void TranslateCellularWithState(); 65 void TranslateCellularWithState();
65 void TranslateNetworkWithState(); 66 void TranslateNetworkWithState();
66 67
67 // Creates an ONC object from |dictionary| according to the signature 68 // Creates an ONC object from |dictionary| according to the signature
68 // associated to |onc_field_name| and adds it to |onc_object_| at 69 // associated to |onc_field_name| and adds it to |onc_object_| at
69 // |onc_field_name|. 70 // |onc_field_name|.
70 void TranslateAndAddNestedObject(const std::string& onc_field_name, 71 void TranslateAndAddNestedObject(const std::string& onc_field_name,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 scoped_ptr<base::DictionaryValue> onc_object_; 103 scoped_ptr<base::DictionaryValue> onc_object_;
103 104
104 DISALLOW_COPY_AND_ASSIGN(ShillToONCTranslator); 105 DISALLOW_COPY_AND_ASSIGN(ShillToONCTranslator);
105 }; 106 };
106 107
107 scoped_ptr<base::DictionaryValue> 108 scoped_ptr<base::DictionaryValue>
108 ShillToONCTranslator::CreateTranslatedONCObject() { 109 ShillToONCTranslator::CreateTranslatedONCObject() {
109 onc_object_.reset(new base::DictionaryValue); 110 onc_object_.reset(new base::DictionaryValue);
110 if (onc_signature_ == &kNetworkWithStateSignature) { 111 if (onc_signature_ == &kNetworkWithStateSignature) {
111 TranslateNetworkWithState(); 112 TranslateNetworkWithState();
113 } else if (onc_signature_ == &kEthernetSignature) {
114 TranslateEthernet();
112 } else if (onc_signature_ == &kVPNSignature) { 115 } else if (onc_signature_ == &kVPNSignature) {
113 TranslateVPN(); 116 TranslateVPN();
114 } else if (onc_signature_ == &kOpenVPNSignature) { 117 } else if (onc_signature_ == &kOpenVPNSignature) {
115 TranslateOpenVPN(); 118 TranslateOpenVPN();
116 } else if (onc_signature_ == &kWiFiWithStateSignature) { 119 } else if (onc_signature_ == &kWiFiWithStateSignature) {
117 TranslateWiFiWithState(); 120 TranslateWiFiWithState();
118 } else if (onc_signature_ == &kCellularWithStateSignature) { 121 } else if (onc_signature_ == &kCellularWithStateSignature) {
119 TranslateCellularWithState(); 122 TranslateCellularWithState();
120 } else { 123 } else {
121 CopyPropertiesAccordingToSignature(); 124 CopyPropertiesAccordingToSignature();
122 } 125 }
123 return onc_object_.Pass(); 126 return onc_object_.Pass();
124 } 127 }
125 128
129 void ShillToONCTranslator::TranslateEthernet() {
130 std::string shill_network_type;
131 shill_dictionary_->GetStringWithoutPathExpansion(flimflam::kTypeProperty,
132 &shill_network_type);
133 const char* onc_auth = ethernet::kNone;
134 if (shill_network_type == shill::kTypeEthernetEap)
135 onc_auth = ethernet::k8021X;
136 onc_object_->SetStringWithoutPathExpansion(ethernet::kAuthentication,
137 onc_auth);
138 }
139
126 void ShillToONCTranslator::TranslateOpenVPN() { 140 void ShillToONCTranslator::TranslateOpenVPN() {
127 // Shill supports only one RemoteCertKU but ONC requires a list. If existing, 141 // Shill supports only one RemoteCertKU but ONC requires a list. If existing,
128 // wraps the value into a list. 142 // wraps the value into a list.
129 std::string certKU; 143 std::string certKU;
130 if (shill_dictionary_->GetStringWithoutPathExpansion( 144 if (shill_dictionary_->GetStringWithoutPathExpansion(
131 flimflam::kOpenVPNRemoteCertKUProperty, &certKU)) { 145 flimflam::kOpenVPNRemoteCertKUProperty, &certKU)) {
132 scoped_ptr<base::ListValue> certKUs(new base::ListValue); 146 scoped_ptr<base::ListValue> certKUs(new base::ListValue);
133 certKUs->AppendString(certKU); 147 certKUs->AppendString(certKU);
134 onc_object_->SetWithoutPathExpansion(openvpn::kRemoteCertKU, 148 onc_object_->SetWithoutPathExpansion(openvpn::kRemoteCertKU,
135 certKUs.release()); 149 certKUs.release());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 flimflam::kServingOperatorProperty, &dictionary)) { 226 flimflam::kServingOperatorProperty, &dictionary)) {
213 TranslateAndAddNestedObject(cellular::kServingOperator, *dictionary); 227 TranslateAndAddNestedObject(cellular::kServingOperator, *dictionary);
214 } 228 }
215 if (shill_dictionary_->GetDictionaryWithoutPathExpansion( 229 if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
216 flimflam::kCellularApnProperty, &dictionary)) { 230 flimflam::kCellularApnProperty, &dictionary)) {
217 TranslateAndAddNestedObject(cellular::kAPN, *dictionary); 231 TranslateAndAddNestedObject(cellular::kAPN, *dictionary);
218 } 232 }
219 } 233 }
220 234
221 void ShillToONCTranslator::TranslateNetworkWithState() { 235 void ShillToONCTranslator::TranslateNetworkWithState() {
222 TranslateWithTableAndSet(flimflam::kTypeProperty, kNetworkTypeTable,
223 network_config::kType);
224 CopyPropertiesAccordingToSignature(); 236 CopyPropertiesAccordingToSignature();
225 237
226 std::string network_type; 238 std::string shill_network_type;
227 if (onc_object_->GetStringWithoutPathExpansion(network_config::kType, 239 shill_dictionary_->GetStringWithoutPathExpansion(flimflam::kTypeProperty,
228 &network_type)) { 240 &shill_network_type);
229 TranslateAndAddNestedObject(network_type); 241 std::string onc_network_type = network_type::kEthernet;
242 if (shill_network_type != flimflam::kTypeEthernet &&
243 shill_network_type != shill::kTypeEthernetEap) {
244 TranslateStringToONC(
245 kNetworkTypeTable, shill_network_type, &onc_network_type);
246 }
247 if (!onc_network_type.empty()) {
248 onc_object_->SetStringWithoutPathExpansion(network_config::kType,
249 onc_network_type);
250 TranslateAndAddNestedObject(onc_network_type);
230 } 251 }
231 252
232 // Since Name is a read only field in Shill unless it's a VPN, it is copied 253 // Since Name is a read only field in Shill unless it's a VPN, it is copied
233 // here, but not when going the other direction (if it's not a VPN). 254 // here, but not when going the other direction (if it's not a VPN).
234 std::string name; 255 std::string name;
235 shill_dictionary_->GetStringWithoutPathExpansion(flimflam::kNameProperty, 256 shill_dictionary_->GetStringWithoutPathExpansion(flimflam::kNameProperty,
236 &name); 257 &name);
237 onc_object_->SetStringWithoutPathExpansion(network_config::kName, name); 258 onc_object_->SetStringWithoutPathExpansion(network_config::kName, name);
238 259
239 std::string state; 260 std::string state;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 const base::DictionaryValue& shill_dictionary, 359 const base::DictionaryValue& shill_dictionary,
339 const OncValueSignature* onc_signature) { 360 const OncValueSignature* onc_signature) {
340 CHECK(onc_signature != NULL); 361 CHECK(onc_signature != NULL);
341 362
342 ShillToONCTranslator translator(shill_dictionary, *onc_signature); 363 ShillToONCTranslator translator(shill_dictionary, *onc_signature);
343 return translator.CreateTranslatedONCObject(); 364 return translator.CreateTranslatedONCObject();
344 } 365 }
345 366
346 } // namespace onc 367 } // namespace onc
347 } // namespace chromeos 368 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/onc/onc_translator_onc_to_shill.cc ('k') | chromeos/network/onc/onc_translator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698