Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS 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 "shill/profile_dbus_property_exporter.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include <base/basictypes.h> |
| 10 | #include <chromeos/dbus/service_constants.h> |
| 11 | #include <dbus-c++/dbus.h> |
| 12 | |
| 13 | #include "shill/dbus_adaptor.h" |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 14 | #include "shill/eap_credentials.h" |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 15 | #include "shill/error.h" |
| 16 | #include "shill/service.h" |
| 17 | #include "shill/store_interface.h" |
| 18 | #include "shill/technology.h" |
| 19 | #include "shill/wifi_service.h" |
| 20 | |
| 21 | using std::string; |
| 22 | |
| 23 | namespace shill { |
| 24 | |
| 25 | ProfileDBusPropertyExporter::ProfileDBusPropertyExporter( |
| 26 | const StoreInterface *storage, const string &entry_name) |
| 27 | : storage_(storage), entry_name_(entry_name) {} |
| 28 | |
| 29 | ProfileDBusPropertyExporter::~ProfileDBusPropertyExporter() {} |
| 30 | |
| 31 | bool ProfileDBusPropertyExporter::LoadServiceProperties( |
| 32 | PropertyList *properties, Error *error) { |
| 33 | if (!storage_->ContainsGroup(entry_name_)) { |
| 34 | Error::PopulateAndLog( |
| 35 | error, Error::kNotFound, |
| 36 | "Could not find profile entry: " + entry_name_); |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | Technology::Identifier technology = |
| 41 | Technology::IdentifierFromStorageGroup(entry_name_); |
| 42 | |
| 43 | if (technology == Technology::kUnknown) { |
| 44 | Error::PopulateAndLog( |
| 45 | error, Error::kInternalError, |
| 46 | "Could not determine technology for entry: " + entry_name_); |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | if (technology == Technology::kWifi) { |
| 51 | LoadWiFiServiceProperties(properties, error); |
| 52 | } |
| 53 | |
| 54 | LoadBool(properties, Service::kStorageAutoConnect, |
| 55 | flimflam::kAutoConnectProperty); |
| 56 | LoadString(properties, Service::kStorageError, flimflam::kErrorProperty); |
| 57 | LoadString(properties, Service::kStorageGUID, flimflam::kGuidProperty); |
| 58 | LoadString(properties, Service::kStorageName, flimflam::kNameProperty); |
| 59 | if (!LoadString(properties, Service::kStorageType, flimflam::kTypeProperty)) { |
| 60 | SetString(properties, flimflam::kTypeProperty, |
| 61 | Technology::NameFromIdentifier(technology)); |
| 62 | } |
| 63 | LoadString(properties, Service::kStorageUIData, flimflam::kUIDataProperty); |
| 64 | return true; |
| 65 | } |
| 66 | |
Paul Stewart | 4ebbdec | 2012-12-13 12:15:46 -0800 | [diff] [blame] | 67 | bool ProfileDBusPropertyExporter::LoadEapServiceProperties( |
| 68 | PropertyList *properties, |
| 69 | Error */*error*/) { |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 70 | LoadString(properties, EapCredentials::kStorageEapCACertID, |
Paul Stewart | 4ebbdec | 2012-12-13 12:15:46 -0800 | [diff] [blame] | 71 | flimflam::kEapCaCertIDProperty); |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 72 | LoadString(properties, EapCredentials::kStorageEapCertID, |
Paul Stewart | 4ebbdec | 2012-12-13 12:15:46 -0800 | [diff] [blame] | 73 | flimflam::kEAPCertIDProperty); |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 74 | LoadString(properties, EapCredentials::kStorageEapKeyID, |
Paul Stewart | 4ebbdec | 2012-12-13 12:15:46 -0800 | [diff] [blame] | 75 | flimflam::kEAPKeyIDProperty); |
| 76 | return true; |
| 77 | } |
| 78 | |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 79 | bool ProfileDBusPropertyExporter::LoadWiFiServiceProperties( |
| 80 | PropertyList *properties, |
| 81 | Error */*error*/) { |
| 82 | LoadBool(properties, WiFiService::kStorageHiddenSSID, |
| 83 | flimflam::kWifiHiddenSsid); |
| 84 | |
| 85 | // Support the old and busted technique for storing "Mode" and "Security" |
| 86 | // within the entry name. |
| 87 | string address; |
| 88 | string mode; |
| 89 | string security; |
| 90 | bool parsed_identifier = WiFiService::ParseStorageIdentifier( |
| 91 | entry_name_, &address, &mode, &security); |
| 92 | |
| 93 | if (!LoadString(properties, WiFiService::kStorageMode, |
| 94 | flimflam::kModeProperty) && parsed_identifier) { |
| 95 | SetString(properties, flimflam::kModeProperty, mode); |
| 96 | } |
| 97 | |
| 98 | if (!LoadString(properties, WiFiService::kStorageSecurity, |
| 99 | flimflam::kSecurityProperty) && parsed_identifier) { |
| 100 | SetString(properties, flimflam::kSecurityProperty, security); |
| 101 | } |
Paul Stewart | 4ebbdec | 2012-12-13 12:15:46 -0800 | [diff] [blame] | 102 | |
| 103 | LoadEapServiceProperties(properties, NULL); |
| 104 | |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 105 | return true; |
| 106 | } |
| 107 | |
| 108 | bool ProfileDBusPropertyExporter::LoadBool(PropertyList *properties, |
| 109 | const string &storage_name, |
| 110 | const string &dbus_name) { |
| 111 | bool value; |
| 112 | if (!storage_->GetBool(entry_name_, storage_name, &value)) { |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | SetBool(properties, dbus_name, value); |
| 117 | return true; |
| 118 | } |
| 119 | |
| 120 | bool ProfileDBusPropertyExporter::LoadString(PropertyList *properties, |
| 121 | const string &storage_name, |
| 122 | const string &dbus_name) { |
| 123 | string value; |
| 124 | if (!storage_->GetString(entry_name_, storage_name, &value)) { |
| 125 | return false; |
| 126 | } |
| 127 | |
| 128 | SetString(properties, dbus_name, value); |
| 129 | return true; |
| 130 | } |
| 131 | |
| 132 | void ProfileDBusPropertyExporter::SetBool(PropertyList *properties, |
| 133 | const string &dbus_name, |
| 134 | bool value) { |
| 135 | (*properties)[dbus_name] = DBusAdaptor::BoolToVariant(value); |
| 136 | } |
| 137 | |
| 138 | void ProfileDBusPropertyExporter::SetString(PropertyList *properties, |
| 139 | const string &dbus_name, |
| 140 | const string &value) { |
| 141 | (*properties)[dbus_name] = DBusAdaptor::StringToVariant(value); |
| 142 | } |
| 143 | |
| 144 | } // namespace shill |