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

Side by Side Diff: chromeos/network/onc/onc_translator_onc_to_shill.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 // The implementation of TranslateONCObjectToShill is structured in two parts: 5 // The implementation of TranslateONCObjectToShill is structured in two parts:
6 // - The recursion through the existing ONC hierarchy 6 // - The recursion through the existing ONC hierarchy
7 // see TranslateONCHierarchy 7 // see TranslateONCHierarchy
8 // - The local translation of an object depending on the associated signature 8 // - The local translation of an object depending on the associated signature
9 // see LocalTranslator::TranslateFields 9 // see LocalTranslator::TranslateFields
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 base::DictionaryValue* shill_dictionary) 45 base::DictionaryValue* shill_dictionary)
46 : onc_signature_(&onc_signature), 46 : onc_signature_(&onc_signature),
47 onc_object_(&onc_object), 47 onc_object_(&onc_object),
48 shill_dictionary_(shill_dictionary) { 48 shill_dictionary_(shill_dictionary) {
49 field_translation_table_ = GetFieldTranslationTable(onc_signature); 49 field_translation_table_ = GetFieldTranslationTable(onc_signature);
50 } 50 }
51 51
52 void TranslateFields(); 52 void TranslateFields();
53 53
54 private: 54 private:
55 void TranslateEthernet();
55 void TranslateOpenVPN(); 56 void TranslateOpenVPN();
56 void TranslateVPN(); 57 void TranslateVPN();
57 void TranslateWiFi(); 58 void TranslateWiFi();
58 void TranslateEAP(); 59 void TranslateEAP();
59 void TranslateNetworkConfiguration(); 60 void TranslateNetworkConfiguration();
60 61
61 // Copies all entries from |onc_object_| to |shill_dictionary_| for which a 62 // Copies all entries from |onc_object_| to |shill_dictionary_| for which a
62 // translation (shill_property_name) is defined by |onc_signature_|. 63 // translation (shill_property_name) is defined by |onc_signature_|.
63 void CopyFieldsAccordingToSignature(); 64 void CopyFieldsAccordingToSignature();
64 65
(...skipping 14 matching lines...) Expand all
79 const FieldTranslationEntry* field_translation_table_; 80 const FieldTranslationEntry* field_translation_table_;
80 const base::DictionaryValue* onc_object_; 81 const base::DictionaryValue* onc_object_;
81 base::DictionaryValue* shill_dictionary_; 82 base::DictionaryValue* shill_dictionary_;
82 83
83 DISALLOW_COPY_AND_ASSIGN(LocalTranslator); 84 DISALLOW_COPY_AND_ASSIGN(LocalTranslator);
84 }; 85 };
85 86
86 void LocalTranslator::TranslateFields() { 87 void LocalTranslator::TranslateFields() {
87 if (onc_signature_ == &kNetworkConfigurationSignature) 88 if (onc_signature_ == &kNetworkConfigurationSignature)
88 TranslateNetworkConfiguration(); 89 TranslateNetworkConfiguration();
90 else if (onc_signature_ == &kEthernetSignature)
91 TranslateEthernet();
89 else if (onc_signature_ == &kVPNSignature) 92 else if (onc_signature_ == &kVPNSignature)
90 TranslateVPN(); 93 TranslateVPN();
91 else if (onc_signature_ == &kOpenVPNSignature) 94 else if (onc_signature_ == &kOpenVPNSignature)
92 TranslateOpenVPN(); 95 TranslateOpenVPN();
93 else if (onc_signature_ == &kWiFiSignature) 96 else if (onc_signature_ == &kWiFiSignature)
94 TranslateWiFi(); 97 TranslateWiFi();
95 else if (onc_signature_ == &kEAPSignature) 98 else if (onc_signature_ == &kEAPSignature)
96 TranslateEAP(); 99 TranslateEAP();
97 else 100 else
98 CopyFieldsAccordingToSignature(); 101 CopyFieldsAccordingToSignature();
99 } 102 }
100 103
104 void LocalTranslator::TranslateEthernet() {
105 std::string authentication;
106 onc_object_->GetStringWithoutPathExpansion(ethernet::kAuthentication,
107 &authentication);
108
109 const char* shill_type = flimflam::kTypeEthernet;
110 if (authentication == ethernet::k8021X)
111 shill_type = shill::kTypeEthernetEap;
112 shill_dictionary_->SetStringWithoutPathExpansion(flimflam::kTypeProperty,
113 shill_type);
114
115 CopyFieldsAccordingToSignature();
116 }
117
101 void LocalTranslator::TranslateOpenVPN() { 118 void LocalTranslator::TranslateOpenVPN() {
102 // Shill supports only one RemoteCertKU but ONC a list. 119 // Shill supports only one RemoteCertKU but ONC a list.
103 // Copy only the first entry if existing. 120 // Copy only the first entry if existing.
104 const base::ListValue* certKUs = NULL; 121 const base::ListValue* certKUs = NULL;
105 std::string certKU; 122 std::string certKU;
106 if (onc_object_->GetListWithoutPathExpansion(openvpn::kRemoteCertKU, 123 if (onc_object_->GetListWithoutPathExpansion(openvpn::kRemoteCertKU,
107 &certKUs) && 124 &certKUs) &&
108 certKUs->GetString(0, &certKU)) { 125 certKUs->GetString(0, &certKU)) {
109 shill_dictionary_->SetStringWithoutPathExpansion( 126 shill_dictionary_->SetStringWithoutPathExpansion(
110 flimflam::kOpenVPNRemoteCertKUProperty, certKU); 127 flimflam::kOpenVPNRemoteCertKUProperty, certKU);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 TranslateWithTableAndSet(inner, table, flimflam::kEapPhase2AuthProperty); 181 TranslateWithTableAndSet(inner, table, flimflam::kEapPhase2AuthProperty);
165 } 182 }
166 } 183 }
167 184
168 CopyFieldsAccordingToSignature(); 185 CopyFieldsAccordingToSignature();
169 } 186 }
170 187
171 void LocalTranslator::TranslateNetworkConfiguration() { 188 void LocalTranslator::TranslateNetworkConfiguration() {
172 std::string type; 189 std::string type;
173 onc_object_->GetStringWithoutPathExpansion(network_config::kType, &type); 190 onc_object_->GetStringWithoutPathExpansion(network_config::kType, &type);
174 TranslateWithTableAndSet(type, kNetworkTypeTable, flimflam::kTypeProperty); 191
192 // Set the type except for Ethernet which is set in TranslateEthernet.
193 if (type != network_type::kEthernet)
194 TranslateWithTableAndSet(type, kNetworkTypeTable, flimflam::kTypeProperty);
175 195
176 // Shill doesn't allow setting the name for non-VPN networks. 196 // Shill doesn't allow setting the name for non-VPN networks.
177 if (type == network_type::kVPN) { 197 if (type == network_type::kVPN) {
178 std::string name; 198 std::string name;
179 onc_object_->GetStringWithoutPathExpansion(network_config::kName, &name); 199 onc_object_->GetStringWithoutPathExpansion(network_config::kName, &name);
180 shill_dictionary_->SetStringWithoutPathExpansion( 200 shill_dictionary_->SetStringWithoutPathExpansion(flimflam::kNameProperty,
181 flimflam::kNameProperty, name); 201 name);
182 } 202 }
183 203
184 CopyFieldsAccordingToSignature(); 204 CopyFieldsAccordingToSignature();
185 } 205 }
186 206
187 void LocalTranslator::CopyFieldsAccordingToSignature() { 207 void LocalTranslator::CopyFieldsAccordingToSignature() {
188 for (base::DictionaryValue::Iterator it(*onc_object_); !it.IsAtEnd(); 208 for (base::DictionaryValue::Iterator it(*onc_object_); !it.IsAtEnd();
189 it.Advance()) { 209 it.Advance()) {
190 AddValueAccordingToSignature(it.key(), 210 AddValueAccordingToSignature(it.key(),
191 make_scoped_ptr(it.value().DeepCopy())); 211 make_scoped_ptr(it.value().DeepCopy()));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 const OncValueSignature* onc_signature, 292 const OncValueSignature* onc_signature,
273 const base::DictionaryValue& onc_object) { 293 const base::DictionaryValue& onc_object) {
274 CHECK(onc_signature != NULL); 294 CHECK(onc_signature != NULL);
275 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); 295 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue);
276 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); 296 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get());
277 return shill_dictionary.Pass(); 297 return shill_dictionary.Pass();
278 } 298 }
279 299
280 } // namespace onc 300 } // namespace onc
281 } // namespace chromeos 301 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/onc/onc_translation_tables.cc ('k') | chromeos/network/onc/onc_translator_shill_to_onc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698