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 "chrome/browser/chromeos/cros/onc_network_parser.h" | 5 #include "chrome/browser/chromeos/cros/onc_network_parser.h" |
6 | 6 |
7 #include <keyhi.h> | 7 #include <keyhi.h> |
8 #include <pk11pub.h> | 8 #include <pk11pub.h> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 240 } |
241 | 241 |
242 const bool GetBooleanValue(const base::Value& value) { | 242 const bool GetBooleanValue(const base::Value& value) { |
243 bool bool_value = false; | 243 bool bool_value = false; |
244 value.GetAsBoolean(&bool_value); | 244 value.GetAsBoolean(&bool_value); |
245 return bool_value; | 245 return bool_value; |
246 } | 246 } |
247 | 247 |
248 std::string ConvertValueToString(const base::Value& value) { | 248 std::string ConvertValueToString(const base::Value& value) { |
249 std::string value_json; | 249 std::string value_json; |
250 base::JSONWriter::Write(&value, false, &value_json); | 250 base::JSONWriter::Write(&value, &value_json); |
251 return value_json; | 251 return value_json; |
252 } | 252 } |
253 | 253 |
254 bool GetAsListOfStrings(const base::Value& value, | 254 bool GetAsListOfStrings(const base::Value& value, |
255 std::vector<std::string>* result) { | 255 std::vector<std::string>* result) { |
256 const base::ListValue* list = NULL; | 256 const base::ListValue* list = NULL; |
257 if (!value.GetAsList(&list)) | 257 if (!value.GetAsList(&list)) |
258 return false; | 258 return false; |
259 result->clear(); | 259 result->clear(); |
260 result->reserve(list->GetSize()); | 260 result->reserve(list->GetSize()); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 return info; | 452 return info; |
453 } | 453 } |
454 | 454 |
455 Network* OncNetworkParser::ParseNetwork(int n) { | 455 Network* OncNetworkParser::ParseNetwork(int n) { |
456 const base::DictionaryValue* info = GetNetworkConfig(n); | 456 const base::DictionaryValue* info = GetNetworkConfig(n); |
457 if (!info) | 457 if (!info) |
458 return NULL; | 458 return NULL; |
459 | 459 |
460 if (VLOG_IS_ON(2)) { | 460 if (VLOG_IS_ON(2)) { |
461 std::string network_json; | 461 std::string network_json; |
462 base::JSONWriter::Write(static_cast<const base::Value*>(info), | 462 base::JSONWriter::WriteWithOptions(static_cast<const base::Value*>(info), |
463 true, &network_json); | 463 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 464 &network_json); |
464 VLOG(2) << "Parsing network at index " << n | 465 VLOG(2) << "Parsing network at index " << n |
465 << ": " << network_json; | 466 << ": " << network_json; |
466 } | 467 } |
467 | 468 |
468 return CreateNetworkFromInfo(std::string(), *info); | 469 return CreateNetworkFromInfo(std::string(), *info); |
469 } | 470 } |
470 | 471 |
471 int OncNetworkParser::GetCertificatesSize() const { | 472 int OncNetworkParser::GetCertificatesSize() const { |
472 return certificates_ ? certificates_->GetSize() : 0; | 473 return certificates_ ? certificates_->GetSize() : 0; |
473 } | 474 } |
474 | 475 |
475 scoped_refptr<net::X509Certificate> OncNetworkParser::ParseCertificate( | 476 scoped_refptr<net::X509Certificate> OncNetworkParser::ParseCertificate( |
476 int cert_index) { | 477 int cert_index) { |
477 CHECK(certificates_); | 478 CHECK(certificates_); |
478 CHECK(static_cast<size_t>(cert_index) < certificates_->GetSize()); | 479 CHECK(static_cast<size_t>(cert_index) < certificates_->GetSize()); |
479 CHECK_GE(cert_index, 0); | 480 CHECK_GE(cert_index, 0); |
480 base::DictionaryValue* certificate = NULL; | 481 base::DictionaryValue* certificate = NULL; |
481 if (!certificates_->GetDictionary(cert_index, &certificate)) { | 482 if (!certificates_->GetDictionary(cert_index, &certificate)) { |
482 parse_error_ = l10n_util::GetStringUTF8( | 483 parse_error_ = l10n_util::GetStringUTF8( |
483 IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MALFORMED); | 484 IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MALFORMED); |
484 return NULL; | 485 return NULL; |
485 } | 486 } |
486 | 487 |
487 if (VLOG_IS_ON(2)) { | 488 if (VLOG_IS_ON(2)) { |
488 std::string certificate_json; | 489 std::string certificate_json; |
489 base::JSONWriter::Write(static_cast<base::Value*>(certificate), | 490 base::JSONWriter::WriteWithOptions(static_cast<base::Value*>(certificate), |
490 true, &certificate_json); | 491 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 492 &certificate_json); |
491 VLOG(2) << "Parsing certificate at index " << cert_index | 493 VLOG(2) << "Parsing certificate at index " << cert_index |
492 << ": " << certificate_json; | 494 << ": " << certificate_json; |
493 } | 495 } |
494 | 496 |
495 // Get out the attributes of the given certificate. | 497 // Get out the attributes of the given certificate. |
496 std::string guid; | 498 std::string guid; |
497 bool remove = false; | 499 bool remove = false; |
498 if (!certificate->GetString("GUID", &guid) || guid.empty()) { | 500 if (!certificate->GetString("GUID", &guid) || guid.empty()) { |
499 LOG(WARNING) << "ONC File: certificate missing identifier at index" | 501 LOG(WARNING) << "ONC File: certificate missing identifier at index" |
500 << cert_index; | 502 << cert_index; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 ParseNetworkConfigurationValue)) { | 558 ParseNetworkConfigurationValue)) { |
557 LOG(WARNING) << "Network " << network->name() << " failed to parse."; | 559 LOG(WARNING) << "Network " << network->name() << " failed to parse."; |
558 if (parse_error_.empty()) | 560 if (parse_error_.empty()) |
559 parse_error_ = l10n_util::GetStringUTF8( | 561 parse_error_ = l10n_util::GetStringUTF8( |
560 IDS_NETWORK_CONFIG_ERROR_NETWORK_PROP_DICT_MALFORMED); | 562 IDS_NETWORK_CONFIG_ERROR_NETWORK_PROP_DICT_MALFORMED); |
561 return NULL; | 563 return NULL; |
562 } | 564 } |
563 | 565 |
564 // Update the UI data property. | 566 // Update the UI data property. |
565 std::string ui_data_json; | 567 std::string ui_data_json; |
566 base::JSONWriter::Write(network->ui_data(), false, &ui_data_json); | 568 base::JSONWriter::Write(network->ui_data(), &ui_data_json); |
567 base::StringValue ui_data_string_value(ui_data_json); | 569 base::StringValue ui_data_string_value(ui_data_json); |
568 network->UpdatePropertyMap(PROPERTY_INDEX_UI_DATA, &ui_data_string_value); | 570 network->UpdatePropertyMap(PROPERTY_INDEX_UI_DATA, &ui_data_string_value); |
569 | 571 |
570 if (VLOG_IS_ON(2)) { | 572 if (VLOG_IS_ON(2)) { |
571 VLOG(2) << "Created Network '" << network->name() | 573 VLOG(2) << "Created Network '" << network->name() |
572 << "' from info. Path:" << service_path | 574 << "' from info. Path:" << service_path |
573 << " Type:" << ConnectionTypeToString(type); | 575 << " Type:" << ConnectionTypeToString(type); |
574 } | 576 } |
575 | 577 |
576 return network.release(); | 578 return network.release(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 // change the mapped value. | 627 // change the mapped value. |
626 network->UpdatePropertyMap(index, inner_value); | 628 network->UpdatePropertyMap(index, inner_value); |
627 if (!parser(this, index, *inner_value, network)) { | 629 if (!parser(this, index, *inner_value, network)) { |
628 LOG(ERROR) << network->name() << ": field in " << onc_type | 630 LOG(ERROR) << network->name() << ": field in " << onc_type |
629 << " not parsed: " << key; | 631 << " not parsed: " << key; |
630 any_errors = true; | 632 any_errors = true; |
631 continue; | 633 continue; |
632 } | 634 } |
633 if (VLOG_IS_ON(2)) { | 635 if (VLOG_IS_ON(2)) { |
634 std::string value_json; | 636 std::string value_json; |
635 base::JSONWriter::Write(inner_value, true, &value_json); | 637 base::JSONWriter::WriteWithOptions(inner_value, |
| 638 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 639 &value_json); |
636 VLOG(2) << network->name() << ": Successfully parsed [" << key | 640 VLOG(2) << network->name() << ": Successfully parsed [" << key |
637 << "(" << index << ")] = " << value_json; | 641 << "(" << index << ")] = " << value_json; |
638 } | 642 } |
639 } | 643 } |
640 if (any_errors) { | 644 if (any_errors) { |
641 parse_error_ = l10n_util::GetStringUTF8( | 645 parse_error_ = l10n_util::GetStringUTF8( |
642 IDS_NETWORK_CONFIG_ERROR_NETWORK_PROP_DICT_MALFORMED); | 646 IDS_NETWORK_CONFIG_ERROR_NETWORK_PROP_DICT_MALFORMED); |
643 } | 647 } |
644 return !any_errors; | 648 return !any_errors; |
645 } | 649 } |
(...skipping 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1965 // on the value of AuthenticationType. | 1969 // on the value of AuthenticationType. |
1966 { "L2TP-IPsec", PROVIDER_TYPE_L2TP_IPSEC_PSK }, | 1970 { "L2TP-IPsec", PROVIDER_TYPE_L2TP_IPSEC_PSK }, |
1967 { "OpenVPN", PROVIDER_TYPE_OPEN_VPN }, | 1971 { "OpenVPN", PROVIDER_TYPE_OPEN_VPN }, |
1968 }; | 1972 }; |
1969 CR_DEFINE_STATIC_LOCAL(EnumMapper<ProviderType>, parser, | 1973 CR_DEFINE_STATIC_LOCAL(EnumMapper<ProviderType>, parser, |
1970 (table, arraysize(table), PROVIDER_TYPE_MAX)); | 1974 (table, arraysize(table), PROVIDER_TYPE_MAX)); |
1971 return parser.Get(type); | 1975 return parser.Get(type); |
1972 } | 1976 } |
1973 | 1977 |
1974 } // namespace chromeos | 1978 } // namespace chromeos |
OLD | NEW |