blob: a9881eff7306a80f748bc08a71f8d6e9182edf06 [file] [log] [blame]
Paul Stewart0756db92012-01-27 08:34:47 -08001// 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 Stewartc43cbbe2013-04-11 06:29:30 -070014#include "shill/eap_credentials.h"
Paul Stewart0756db92012-01-27 08:34:47 -080015#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
21using std::string;
22
23namespace shill {
24
25ProfileDBusPropertyExporter::ProfileDBusPropertyExporter(
26 const StoreInterface *storage, const string &entry_name)
27 : storage_(storage), entry_name_(entry_name) {}
28
29ProfileDBusPropertyExporter::~ProfileDBusPropertyExporter() {}
30
31bool 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 Stewart4ebbdec2012-12-13 12:15:46 -080067bool ProfileDBusPropertyExporter::LoadEapServiceProperties(
68 PropertyList *properties,
69 Error */*error*/) {
Paul Stewartc43cbbe2013-04-11 06:29:30 -070070 LoadString(properties, EapCredentials::kStorageEapCACertID,
Paul Stewart4ebbdec2012-12-13 12:15:46 -080071 flimflam::kEapCaCertIDProperty);
Paul Stewartc43cbbe2013-04-11 06:29:30 -070072 LoadString(properties, EapCredentials::kStorageEapCertID,
Paul Stewart4ebbdec2012-12-13 12:15:46 -080073 flimflam::kEAPCertIDProperty);
Paul Stewartc43cbbe2013-04-11 06:29:30 -070074 LoadString(properties, EapCredentials::kStorageEapKeyID,
Paul Stewart4ebbdec2012-12-13 12:15:46 -080075 flimflam::kEAPKeyIDProperty);
76 return true;
77}
78
Paul Stewart0756db92012-01-27 08:34:47 -080079bool 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 Stewart4ebbdec2012-12-13 12:15:46 -0800102
103 LoadEapServiceProperties(properties, NULL);
104
Paul Stewart0756db92012-01-27 08:34:47 -0800105 return true;
106}
107
108bool 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
120bool 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
132void ProfileDBusPropertyExporter::SetBool(PropertyList *properties,
133 const string &dbus_name,
134 bool value) {
135 (*properties)[dbus_name] = DBusAdaptor::BoolToVariant(value);
136}
137
138void 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