| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/network_settings/onc_normalizer.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "base/values.h" |
| 11 #include "chrome/browser/chromeos/cros/onc_constants.h" |
| 12 #include "chrome/browser/chromeos/network_settings/onc_signature.h" |
| 13 |
| 14 namespace chromeos { |
| 15 namespace onc { |
| 16 |
| 17 Normalizer::Normalizer(bool remove_recommended_fields) |
| 18 : remove_recommended_fields_(remove_recommended_fields) { |
| 19 } |
| 20 |
| 21 Normalizer::~Normalizer() { |
| 22 } |
| 23 |
| 24 scoped_ptr<base::DictionaryValue> Normalizer::NormalizeObject( |
| 25 const OncValueSignature* object_signature, |
| 26 const base::DictionaryValue& onc_object) { |
| 27 CHECK(object_signature != NULL); |
| 28 return MapObject(*object_signature, onc_object); |
| 29 } |
| 30 |
| 31 scoped_ptr<base::DictionaryValue> Normalizer::MapObject( |
| 32 const OncValueSignature& signature, |
| 33 const base::DictionaryValue& onc_object) { |
| 34 scoped_ptr<base::DictionaryValue> normalized = |
| 35 Mapper::MapObject(signature, onc_object); |
| 36 |
| 37 if (normalized.get() == NULL) |
| 38 return scoped_ptr<base::DictionaryValue>(); |
| 39 |
| 40 if (remove_recommended_fields_) |
| 41 normalized->RemoveWithoutPathExpansion(kRecommended, NULL); |
| 42 |
| 43 if (&signature == &kNetworkConfigurationSignature) |
| 44 NormalizeNetworkConfiguration(normalized.get()); |
| 45 else if (&signature == &kVPNSignature) |
| 46 NormalizeVPN(normalized.get()); |
| 47 else if (&signature == &kIPsecSignature) |
| 48 NormalizeIPsec(normalized.get()); |
| 49 |
| 50 return normalized.Pass(); |
| 51 } |
| 52 |
| 53 namespace { |
| 54 void RemoveEntryUnless(base::DictionaryValue* dict, |
| 55 const std::string path, |
| 56 bool condition) { |
| 57 if (!condition) |
| 58 dict->RemoveWithoutPathExpansion(path, NULL); |
| 59 } |
| 60 } // namespace |
| 61 |
| 62 void Normalizer::NormalizeIPsec(base::DictionaryValue* ipsec) { |
| 63 using namespace vpn; |
| 64 |
| 65 std::string auth_type; |
| 66 ipsec->GetStringWithoutPathExpansion(kAuthenticationType, &auth_type); |
| 67 RemoveEntryUnless(ipsec, kClientCertType, auth_type == kCert); |
| 68 RemoveEntryUnless(ipsec, kServerCARef, auth_type == kCert); |
| 69 RemoveEntryUnless(ipsec, kPSK, auth_type == kPSK); |
| 70 RemoveEntryUnless(ipsec, kSaveCredentials, auth_type == kPSK); |
| 71 |
| 72 std::string clientcert_type; |
| 73 ipsec->GetStringWithoutPathExpansion(kClientCertType, &clientcert_type); |
| 74 RemoveEntryUnless(ipsec, kClientCertPattern, |
| 75 clientcert_type == certificate::kPattern); |
| 76 RemoveEntryUnless(ipsec, kClientCertRef, |
| 77 clientcert_type == certificate::kRef); |
| 78 |
| 79 int ike_version = -1; |
| 80 ipsec->GetIntegerWithoutPathExpansion(kIKEVersion, &ike_version); |
| 81 RemoveEntryUnless(ipsec, kEAP, ike_version == 2); |
| 82 RemoveEntryUnless(ipsec, kGroup, ike_version == 1); |
| 83 RemoveEntryUnless(ipsec, kXAUTH, ike_version == 1); |
| 84 } |
| 85 |
| 86 void Normalizer::NormalizeVPN(base::DictionaryValue* vpn) { |
| 87 using namespace vpn; |
| 88 std::string type; |
| 89 vpn->GetStringWithoutPathExpansion(vpn::kType, &type); |
| 90 RemoveEntryUnless(vpn, kOpenVPN, type == kOpenVPN); |
| 91 RemoveEntryUnless(vpn, kIPsec, type == kIPsec || type == kTypeL2TP_IPsec); |
| 92 RemoveEntryUnless(vpn, kL2TP, type == kTypeL2TP_IPsec); |
| 93 } |
| 94 |
| 95 void Normalizer::NormalizeNetworkConfiguration(base::DictionaryValue* network) { |
| 96 std::string type; |
| 97 network->GetStringWithoutPathExpansion(kType, &type); |
| 98 RemoveEntryUnless(network, kEthernet, type == kEthernet); |
| 99 RemoveEntryUnless(network, kVPN, type == kVPN); |
| 100 RemoveEntryUnless(network, kWiFi, type == kWiFi); |
| 101 } |
| 102 |
| 103 } // namespace onc |
| 104 } // namespace chromeos |
| OLD | NEW |