blob: 3e3a7b91c2339cbedbd93302eb5e93eb1161704a [file] [log] [blame]
Darin Petkov33af05c2012-02-28 10:10:30 +01001// 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/vpn_service.h"
6
Darin Petkov02867712012-03-12 14:25:05 +01007#include <algorithm>
Darin Petkov33af05c2012-02-28 10:10:30 +01008
Darin Petkov02867712012-03-12 14:25:05 +01009#include <base/logging.h>
10#include <base/stringprintf.h>
11#include <chromeos/dbus/service_constants.h>
12
13#include "shill/key_value_store.h"
Darin Petkov33af05c2012-02-28 10:10:30 +010014#include "shill/technology.h"
15#include "shill/vpn_driver.h"
16
Darin Petkov02867712012-03-12 14:25:05 +010017using base::StringPrintf;
18using std::replace_if;
Darin Petkov33af05c2012-02-28 10:10:30 +010019using std::string;
20
21namespace shill {
22
Darin Petkov79d74c92012-03-07 17:20:32 +010023VPNService::VPNService(ControlInterface *control,
Darin Petkov33af05c2012-02-28 10:10:30 +010024 EventDispatcher *dispatcher,
25 Metrics *metrics,
26 Manager *manager,
27 VPNDriver *driver)
Darin Petkov79d74c92012-03-07 17:20:32 +010028 : Service(control, dispatcher, metrics, manager, Technology::kVPN),
Darin Petkov33af05c2012-02-28 10:10:30 +010029 driver_(driver) {}
30
31VPNService::~VPNService() {}
32
33void VPNService::Connect(Error *error) {
Darin Petkov6aa21872012-03-09 16:10:19 +010034 Service::Connect(error);
Darin Petkov79d74c92012-03-07 17:20:32 +010035 driver_->Connect(this, error);
Darin Petkov33af05c2012-02-28 10:10:30 +010036}
37
Darin Petkov6aa21872012-03-09 16:10:19 +010038void VPNService::Disconnect(Error *error) {
39 Service::Disconnect(error);
40 driver_->Disconnect();
41}
42
Darin Petkov33af05c2012-02-28 10:10:30 +010043string VPNService::GetStorageIdentifier() const {
Darin Petkov02867712012-03-12 14:25:05 +010044 return storage_id_;
45}
46
47// static
48string VPNService::CreateStorageIdentifier(const KeyValueStore &args,
49 Error *error) {
50 string host;
51 if (args.ContainsString(flimflam::kProviderHostProperty)) {
52 host = args.GetString(flimflam::kProviderHostProperty);
53 }
54 if (host.empty()) {
55 Error::PopulateAndLog(
56 error, Error::kInvalidProperty, "Missing VPN host.");
57 return "";
58 }
59 string name;
60 if (args.ContainsString(flimflam::kProviderNameProperty)) {
61 name = args.GetString(flimflam::kProviderNameProperty);
62 }
63 if (name.empty()) {
64 Error::PopulateAndLog(
65 error, Error::kNotSupported, "Missing VPN name.");
66 return "";
67 }
68 string id = StringPrintf("vpn_%s_%s", host.c_str(), name.c_str());
69 replace_if(id.begin(), id.end(), &Service::IllegalChar, '_');
70 return id;
Darin Petkov33af05c2012-02-28 10:10:30 +010071}
72
73string VPNService::GetDeviceRpcId(Error *error) {
74 NOTIMPLEMENTED();
75 error->Populate(Error::kNotSupported);
76 return "/";
77}
78
79} // namespace shill