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