Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [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/vpn_service.h" |
| 6 | |
Darin Petkov | 0286771 | 2012-03-12 14:25:05 +0100 | [diff] [blame] | 7 | #include <algorithm> |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 8 | |
Darin Petkov | 0286771 | 2012-03-12 14:25:05 +0100 | [diff] [blame] | 9 | #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 Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 14 | #include "shill/technology.h" |
| 15 | #include "shill/vpn_driver.h" |
| 16 | |
Darin Petkov | 0286771 | 2012-03-12 14:25:05 +0100 | [diff] [blame] | 17 | using base::StringPrintf; |
| 18 | using std::replace_if; |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 19 | using std::string; |
| 20 | |
| 21 | namespace shill { |
| 22 | |
Darin Petkov | 79d74c9 | 2012-03-07 17:20:32 +0100 | [diff] [blame] | 23 | VPNService::VPNService(ControlInterface *control, |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 24 | EventDispatcher *dispatcher, |
| 25 | Metrics *metrics, |
| 26 | Manager *manager, |
| 27 | VPNDriver *driver) |
Darin Petkov | 79d74c9 | 2012-03-07 17:20:32 +0100 | [diff] [blame] | 28 | : Service(control, dispatcher, metrics, manager, Technology::kVPN), |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 29 | driver_(driver) {} |
| 30 | |
| 31 | VPNService::~VPNService() {} |
| 32 | |
| 33 | void VPNService::Connect(Error *error) { |
Darin Petkov | 6aa2187 | 2012-03-09 16:10:19 +0100 | [diff] [blame] | 34 | Service::Connect(error); |
Darin Petkov | 79d74c9 | 2012-03-07 17:20:32 +0100 | [diff] [blame] | 35 | driver_->Connect(this, error); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 36 | } |
| 37 | |
Darin Petkov | 6aa2187 | 2012-03-09 16:10:19 +0100 | [diff] [blame] | 38 | void VPNService::Disconnect(Error *error) { |
| 39 | Service::Disconnect(error); |
| 40 | driver_->Disconnect(); |
| 41 | } |
| 42 | |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 43 | string VPNService::GetStorageIdentifier() const { |
Darin Petkov | 0286771 | 2012-03-12 14:25:05 +0100 | [diff] [blame] | 44 | return storage_id_; |
| 45 | } |
| 46 | |
| 47 | // static |
| 48 | string VPNService::CreateStorageIdentifier(const KeyValueStore &args, |
| 49 | Error *error) { |
Darin Petkov | 7f06033 | 2012-03-14 11:46:47 +0100 | [diff] [blame^] | 50 | string host = args.LookupString(flimflam::kProviderHostProperty, ""); |
Darin Petkov | 0286771 | 2012-03-12 14:25:05 +0100 | [diff] [blame] | 51 | if (host.empty()) { |
| 52 | Error::PopulateAndLog( |
| 53 | error, Error::kInvalidProperty, "Missing VPN host."); |
| 54 | return ""; |
| 55 | } |
Darin Petkov | 7f06033 | 2012-03-14 11:46:47 +0100 | [diff] [blame^] | 56 | string name = args.LookupString(flimflam::kProviderNameProperty, ""); |
Darin Petkov | 0286771 | 2012-03-12 14:25:05 +0100 | [diff] [blame] | 57 | 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 Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | string VPNService::GetDeviceRpcId(Error *error) { |
| 68 | NOTIMPLEMENTED(); |
| 69 | error->Populate(Error::kNotSupported); |
| 70 | return "/"; |
| 71 | } |
| 72 | |
| 73 | } // namespace shill |