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

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

Issue 540613002: Translate Saved/StaticIPConfig properties from ONC to Shill (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
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"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/strings/string_util.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "chromeos/network/network_state.h" 15 #include "chromeos/network/network_state.h"
15 #include "chromeos/network/network_util.h" 16 #include "chromeos/network/network_util.h"
16 #include "chromeos/network/onc/onc_signature.h" 17 #include "chromeos/network/onc/onc_signature.h"
17 #include "chromeos/network/onc/onc_translation_tables.h" 18 #include "chromeos/network/onc/onc_translation_tables.h"
18 #include "chromeos/network/shill_property_util.h" 19 #include "chromeos/network/shill_property_util.h"
19 #include "components/onc/onc_constants.h" 20 #include "components/onc/onc_constants.h"
20 #include "third_party/cros_system_api/dbus/service_constants.h" 21 #include "third_party/cros_system_api/dbus/service_constants.h"
21 22
22 namespace chromeos { 23 namespace chromeos {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 private: 71 private:
71 void TranslateEthernet(); 72 void TranslateEthernet();
72 void TranslateOpenVPN(); 73 void TranslateOpenVPN();
73 void TranslateIPsec(); 74 void TranslateIPsec();
74 void TranslateVPN(); 75 void TranslateVPN();
75 void TranslateWiFiWithState(); 76 void TranslateWiFiWithState();
76 void TranslateCellularWithState(); 77 void TranslateCellularWithState();
77 void TranslateCellularDevice(); 78 void TranslateCellularDevice();
78 void TranslateNetworkWithState(); 79 void TranslateNetworkWithState();
79 void TranslateIPConfig(); 80 void TranslateIPConfig();
81 void TranslateSavedOrStaticIPConfig(const std::string& nameserver_property);
82 void TranslateSavedIPConfig();
83 void TranslateStaticIPConfig();
80 84
81 // Creates an ONC object from |dictionary| according to the signature 85 // Creates an ONC object from |dictionary| according to the signature
82 // associated to |onc_field_name| and adds it to |onc_object_| at 86 // associated to |onc_field_name| and adds it to |onc_object_| at
83 // |onc_field_name|. 87 // |onc_field_name|.
84 void TranslateAndAddNestedObject(const std::string& onc_field_name, 88 void TranslateAndAddNestedObject(const std::string& onc_field_name,
85 const base::DictionaryValue& dictionary); 89 const base::DictionaryValue& dictionary);
86 90
87 // Creates an ONC object from |shill_dictionary_| according to the signature 91 // Creates an ONC object from |shill_dictionary_| according to the signature
88 // associated to |onc_field_name| and adds it to |onc_object_| at 92 // associated to |onc_field_name| and adds it to |onc_object_| at
89 // |onc_field_name|. 93 // |onc_field_name|.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 TranslateIPsec(); 154 TranslateIPsec();
151 } else if (onc_signature_ == &kWiFiWithStateSignature) { 155 } else if (onc_signature_ == &kWiFiWithStateSignature) {
152 TranslateWiFiWithState(); 156 TranslateWiFiWithState();
153 } else if (onc_signature_ == &kCellularWithStateSignature) { 157 } else if (onc_signature_ == &kCellularWithStateSignature) {
154 if (field_translation_table_ == kCellularDeviceTable) 158 if (field_translation_table_ == kCellularDeviceTable)
155 TranslateCellularDevice(); 159 TranslateCellularDevice();
156 else 160 else
157 TranslateCellularWithState(); 161 TranslateCellularWithState();
158 } else if (onc_signature_ == &kIPConfigSignature) { 162 } else if (onc_signature_ == &kIPConfigSignature) {
159 TranslateIPConfig(); 163 TranslateIPConfig();
164 } else if (onc_signature_ == &kSavedIPConfigSignature) {
165 TranslateSavedIPConfig();
166 } else if (onc_signature_ == &kStaticIPConfigSignature) {
167 TranslateStaticIPConfig();
160 } else { 168 } else {
161 CopyPropertiesAccordingToSignature(); 169 CopyPropertiesAccordingToSignature();
162 } 170 }
163 return onc_object_.Pass(); 171 return onc_object_.Pass();
164 } 172 }
165 173
166 void ShillToONCTranslator::TranslateEthernet() { 174 void ShillToONCTranslator::TranslateEthernet() {
167 std::string shill_network_type; 175 std::string shill_network_type;
168 shill_dictionary_->GetStringWithoutPathExpansion(shill::kTypeProperty, 176 shill_dictionary_->GetStringWithoutPathExpansion(shill::kTypeProperty,
169 &shill_network_type); 177 &shill_network_type);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 // Translate nested Cellular, WiFi, etc. properties. 372 // Translate nested Cellular, WiFi, etc. properties.
365 if (!onc_network_type.empty()) { 373 if (!onc_network_type.empty()) {
366 onc_object_->SetStringWithoutPathExpansion(::onc::network_config::kType, 374 onc_object_->SetStringWithoutPathExpansion(::onc::network_config::kType,
367 onc_network_type); 375 onc_network_type);
368 TranslateAndAddNestedObject(onc_network_type); 376 TranslateAndAddNestedObject(onc_network_type);
369 } 377 }
370 378
371 // Since Name is a read only field in Shill unless it's a VPN, it is copied 379 // Since Name is a read only field in Shill unless it's a VPN, it is copied
372 // here, but not when going the other direction (if it's not a VPN). 380 // here, but not when going the other direction (if it's not a VPN).
373 std::string name; 381 std::string name;
374 shill_dictionary_->GetStringWithoutPathExpansion(shill::kNameProperty, 382 shill_dictionary_->GetStringWithoutPathExpansion(shill::kNameProperty, &name);
375 &name);
376 onc_object_->SetStringWithoutPathExpansion(::onc::network_config::kName, 383 onc_object_->SetStringWithoutPathExpansion(::onc::network_config::kName,
377 name); 384 name);
378 385
379 // Limit ONC state to "NotConnected", "Connected", or "Connecting". 386 // Limit ONC state to "NotConnected", "Connected", or "Connecting".
380 std::string state; 387 std::string state;
381 if (shill_dictionary_->GetStringWithoutPathExpansion(shill::kStateProperty, 388 if (shill_dictionary_->GetStringWithoutPathExpansion(shill::kStateProperty,
382 &state)) { 389 &state)) {
383 std::string onc_state = ::onc::connection_state::kNotConnected; 390 std::string onc_state = ::onc::connection_state::kNotConnected;
384 if (NetworkState::StateIsConnected(state)) { 391 if (NetworkState::StateIsConnected(state)) {
385 onc_state = ::onc::connection_state::kConnected; 392 onc_state = ::onc::connection_state::kConnected;
(...skipping 17 matching lines...) Expand all
403 410
404 // Shill's Service has an IPConfig property (note the singular), not an 411 // Shill's Service has an IPConfig property (note the singular), not an
405 // IPConfigs property. However, we require the caller of the translation to 412 // IPConfigs property. However, we require the caller of the translation to
406 // patch the Shill dictionary before passing it to the translator. 413 // patch the Shill dictionary before passing it to the translator.
407 const base::ListValue* shill_ipconfigs = NULL; 414 const base::ListValue* shill_ipconfigs = NULL;
408 if (shill_dictionary_->GetListWithoutPathExpansion(shill::kIPConfigsProperty, 415 if (shill_dictionary_->GetListWithoutPathExpansion(shill::kIPConfigsProperty,
409 &shill_ipconfigs)) { 416 &shill_ipconfigs)) {
410 TranslateAndAddListOfObjects(::onc::network_config::kIPConfigs, 417 TranslateAndAddListOfObjects(::onc::network_config::kIPConfigs,
411 *shill_ipconfigs); 418 *shill_ipconfigs);
412 } 419 }
420
421 TranslateAndAddNestedObject(::onc::network_config::kSavedIPConfig);
422 TranslateAndAddNestedObject(::onc::network_config::kStaticIPConfig);
413 } 423 }
414 424
415 void ShillToONCTranslator::TranslateIPConfig() { 425 void ShillToONCTranslator::TranslateIPConfig() {
416 CopyPropertiesAccordingToSignature(); 426 CopyPropertiesAccordingToSignature();
417 std::string shill_ip_method; 427 std::string shill_ip_method;
418 shill_dictionary_->GetStringWithoutPathExpansion(shill::kMethodProperty, 428 shill_dictionary_->GetStringWithoutPathExpansion(shill::kMethodProperty,
419 &shill_ip_method); 429 &shill_ip_method);
420 std::string type; 430 std::string type;
421 if (shill_ip_method == shill::kTypeIPv4 || 431 if (shill_ip_method == shill::kTypeIPv4 ||
422 shill_ip_method == shill::kTypeDHCP) { 432 shill_ip_method == shill::kTypeDHCP) {
423 type = ::onc::ipconfig::kIPv4; 433 type = ::onc::ipconfig::kIPv4;
424 } else if (shill_ip_method == shill::kTypeIPv6 || 434 } else if (shill_ip_method == shill::kTypeIPv6 ||
425 shill_ip_method == shill::kTypeDHCP6) { 435 shill_ip_method == shill::kTypeDHCP6) {
426 type = ::onc::ipconfig::kIPv6; 436 type = ::onc::ipconfig::kIPv6;
427 } else { 437 } else {
428 return; // Ignore unhandled IPConfig types, e.g. bootp, zeroconf, ppp 438 return; // Ignore unhandled IPConfig types, e.g. bootp, zeroconf, ppp
429 } 439 }
430 440
431 onc_object_->SetStringWithoutPathExpansion(::onc::ipconfig::kType, type); 441 onc_object_->SetStringWithoutPathExpansion(::onc::ipconfig::kType, type);
432 } 442 }
433 443
444 void ShillToONCTranslator::TranslateSavedOrStaticIPConfig(
445 const std::string& nameserver_property) {
446 CopyPropertiesAccordingToSignature();
447 // Saved IP config nameservers are stored as a comma separated list.
pneubeck (no reviews) 2014/09/04 12:38:45 nit: Saved and static ...
stevenjb 2014/09/04 15:26:21 Done.
448 std::string shill_nameservers;
449 shill_dictionary_->GetStringWithoutPathExpansion(
450 nameserver_property, &shill_nameservers);
451 std::vector<std::string> onc_nameserver_vector;
452 if (Tokenize(shill_nameservers, ",", &onc_nameserver_vector) > 0) {
453 scoped_ptr<base::ListValue> onc_nameservers(new base::ListValue);
454 for (std::vector<std::string>::iterator iter =
455 onc_nameserver_vector.begin();
456 iter != onc_nameserver_vector.end(); ++iter) {
457 onc_nameservers->AppendString(*iter);
458 }
459 onc_object_->SetWithoutPathExpansion(::onc::ipconfig::kNameServers,
460 onc_nameservers.release());
461 }
462 }
463
464 void ShillToONCTranslator::TranslateSavedIPConfig() {
465 TranslateSavedOrStaticIPConfig(shill::kSavedIPNameServersProperty);
466 }
467
468 void ShillToONCTranslator::TranslateStaticIPConfig() {
469 TranslateSavedOrStaticIPConfig(shill::kStaticIPNameServersProperty);
470 }
471
434 void ShillToONCTranslator::TranslateAndAddNestedObject( 472 void ShillToONCTranslator::TranslateAndAddNestedObject(
435 const std::string& onc_field_name) { 473 const std::string& onc_field_name) {
436 TranslateAndAddNestedObject(onc_field_name, *shill_dictionary_); 474 TranslateAndAddNestedObject(onc_field_name, *shill_dictionary_);
437 } 475 }
438 476
439 void ShillToONCTranslator::TranslateAndAddNestedObject( 477 void ShillToONCTranslator::TranslateAndAddNestedObject(
440 const std::string& onc_field_name, 478 const std::string& onc_field_name,
441 const base::DictionaryValue& dictionary) { 479 const base::DictionaryValue& dictionary) {
442 const OncFieldSignature* field_signature = 480 const OncFieldSignature* field_signature =
443 GetFieldSignature(*onc_signature_, onc_field_name); 481 GetFieldSignature(*onc_signature_, onc_field_name);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 540 }
503 541
504 void ShillToONCTranslator::CopyPropertiesAccordingToSignature() { 542 void ShillToONCTranslator::CopyPropertiesAccordingToSignature() {
505 CopyPropertiesAccordingToSignature(onc_signature_); 543 CopyPropertiesAccordingToSignature(onc_signature_);
506 } 544 }
507 545
508 void ShillToONCTranslator::CopyPropertiesAccordingToSignature( 546 void ShillToONCTranslator::CopyPropertiesAccordingToSignature(
509 const OncValueSignature* value_signature) { 547 const OncValueSignature* value_signature) {
510 if (value_signature->base_signature) 548 if (value_signature->base_signature)
511 CopyPropertiesAccordingToSignature(value_signature->base_signature); 549 CopyPropertiesAccordingToSignature(value_signature->base_signature);
550 if (!value_signature->fields)
551 return;
512 for (const OncFieldSignature* field_signature = value_signature->fields; 552 for (const OncFieldSignature* field_signature = value_signature->fields;
513 field_signature->onc_field_name != NULL; ++field_signature) { 553 field_signature->onc_field_name != NULL; ++field_signature) {
514 CopyProperty(field_signature); 554 CopyProperty(field_signature);
515 } 555 }
516 } 556 }
517 557
518 void ShillToONCTranslator::CopyProperty( 558 void ShillToONCTranslator::CopyProperty(
519 const OncFieldSignature* field_signature) { 559 const OncFieldSignature* field_signature) {
520 std::string shill_property_name; 560 std::string shill_property_name;
521 const base::Value* shill_value = NULL; 561 const base::Value* shill_value = NULL;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 const base::DictionaryValue& shill_dictionary, 614 const base::DictionaryValue& shill_dictionary,
575 const OncValueSignature* onc_signature) { 615 const OncValueSignature* onc_signature) {
576 CHECK(onc_signature != NULL); 616 CHECK(onc_signature != NULL);
577 617
578 ShillToONCTranslator translator(shill_dictionary, *onc_signature); 618 ShillToONCTranslator translator(shill_dictionary, *onc_signature);
579 return translator.CreateTranslatedONCObject(); 619 return translator.CreateTranslatedONCObject();
580 } 620 }
581 621
582 } // namespace onc 622 } // namespace onc
583 } // namespace chromeos 623 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698