blob: 6264cb84f72ccd3e8558508111fef6bbaf474bf4 [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) {
Darin Petkov7f060332012-03-14 11:46:47 +010050 string host = args.LookupString(flimflam::kProviderHostProperty, "");
Darin Petkov02867712012-03-12 14:25:05 +010051 if (host.empty()) {
52 Error::PopulateAndLog(
53 error, Error::kInvalidProperty, "Missing VPN host.");
54 return "";
55 }
Darin Petkov7f060332012-03-14 11:46:47 +010056 string name = args.LookupString(flimflam::kProviderNameProperty, "");
Darin Petkov02867712012-03-12 14:25:05 +010057 if (name.empty()) {
58 Error::PopulateAndLog(
59 error, Error::kNotSupported, "Missing VPN name.");
60 return "";
61 }
62 string id = StringPrintf("vpn_%s_%s", host.c_str(), name.c_str());
63 replace_if(id.begin(), id.end(), &Service::IllegalChar, '_');
64 return id;
Darin Petkov33af05c2012-02-28 10:10:30 +010065}
66
67string VPNService::GetDeviceRpcId(Error *error) {
68 NOTIMPLEMENTED();
69 error->Populate(Error::kNotSupported);
70 return "/";
71}
72
73} // namespace shill