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 | |
Darin Petkov | a42afe3 | 2013-02-05 16:53:52 +0100 | [diff] [blame] | 5 | #ifndef SHILL_VPN_DRIVER_H_ |
| 6 | #define SHILL_VPN_DRIVER_H_ |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 7 | |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 10 | #include <base/basictypes.h> |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 11 | #include <base/cancelable_callback.h> |
| 12 | #include <base/memory/weak_ptr.h> |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 13 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 14 | |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 15 | #include "shill/accessor_interface.h" |
| 16 | #include "shill/key_value_store.h" |
Darin Petkov | 79d74c9 | 2012-03-07 17:20:32 +0100 | [diff] [blame] | 17 | #include "shill/refptr_types.h" |
| 18 | |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 19 | namespace shill { |
| 20 | |
| 21 | class Error; |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 22 | class EventDispatcher; |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 23 | class Manager; |
Paul Stewart | ebd3856 | 2012-03-23 13:06:40 -0700 | [diff] [blame] | 24 | class PropertyStore; |
Darin Petkov | f3c71d7 | 2012-03-21 12:32:15 +0100 | [diff] [blame] | 25 | class StoreInterface; |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 26 | |
| 27 | class VPNDriver { |
| 28 | public: |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 29 | virtual ~VPNDriver(); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 30 | |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 31 | virtual bool ClaimInterface(const std::string &link_name, |
| 32 | int interface_index) = 0; |
Darin Petkov | 79d74c9 | 2012-03-07 17:20:32 +0100 | [diff] [blame] | 33 | virtual void Connect(const VPNServiceRefPtr &service, Error *error) = 0; |
Darin Petkov | 6aa2187 | 2012-03-09 16:10:19 +0100 | [diff] [blame] | 34 | virtual void Disconnect() = 0; |
Paul Stewart | 39964fa | 2012-04-04 09:50:25 -0700 | [diff] [blame] | 35 | virtual std::string GetProviderType() const = 0; |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 36 | |
Darin Petkov | a42afe3 | 2013-02-05 16:53:52 +0100 | [diff] [blame] | 37 | // Invoked by VPNService when the underlying connection disconnects. |
| 38 | virtual void OnConnectionDisconnected() = 0; |
| 39 | |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 40 | virtual void InitPropertyStore(PropertyStore *store); |
| 41 | |
| 42 | virtual bool Load(StoreInterface *storage, const std::string &storage_id); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 43 | virtual bool Save(StoreInterface *storage, |
| 44 | const std::string &storage_id, |
| 45 | bool save_credentials); |
| 46 | virtual void UnloadCredentials(); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 47 | |
Darin Petkov | 9c6e981 | 2013-03-26 13:49:07 +0100 | [diff] [blame] | 48 | std::string GetHost() const; |
| 49 | |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 50 | KeyValueStore *args() { return &args_; } |
| 51 | |
| 52 | protected: |
| 53 | struct Property { |
| 54 | enum Flags { |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 55 | kEphemeral = 1 << 0, // Never load or save. |
| 56 | kCredential = 1 << 1, // Save if saving credentials (crypted). |
| 57 | kWriteOnly = 1 << 2, // Never read over RPC. |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | const char *property; |
| 61 | int flags; |
| 62 | }; |
| 63 | |
Darin Petkov | 0cd0d1e | 2013-02-11 12:49:10 +0100 | [diff] [blame] | 64 | static const int kDefaultConnectTimeoutSeconds; |
| 65 | |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 66 | VPNDriver(EventDispatcher *dispatcher, |
| 67 | Manager *manager, |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 68 | const Property *properties, |
| 69 | size_t property_count); |
| 70 | |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 71 | EventDispatcher *dispatcher() const { return dispatcher_; } |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 72 | Manager *manager() const { return manager_; } |
| 73 | |
Darin Petkov | b536a74 | 2012-04-26 11:31:28 +0200 | [diff] [blame] | 74 | virtual KeyValueStore GetProvider(Error *error); |
| 75 | |
Darin Petkov | 0cd0d1e | 2013-02-11 12:49:10 +0100 | [diff] [blame] | 76 | // Initializes a callback that will invoke OnConnectTimeout after |
| 77 | // |timeout_seconds|. The timeout will not be restarted if it's already |
| 78 | // scheduled. |
| 79 | void StartConnectTimeout(int timeout_seconds); |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 80 | // Cancels the connect timeout callback, if any, previously scheduled through |
| 81 | // StartConnectTimeout. |
| 82 | void StopConnectTimeout(); |
| 83 | // Returns true if a connect timeout is scheduled, false otherwise. |
| 84 | bool IsConnectTimeoutStarted() const; |
| 85 | |
Darin Petkov | a42afe3 | 2013-02-05 16:53:52 +0100 | [diff] [blame] | 86 | // Called if a connect timeout scheduled through StartConnectTimeout |
| 87 | // fires. Cancels the timeout callback. |
| 88 | virtual void OnConnectTimeout(); |
| 89 | |
Darin Petkov | 0cd0d1e | 2013-02-11 12:49:10 +0100 | [diff] [blame] | 90 | int connect_timeout_seconds() const { return connect_timeout_seconds_; } |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 91 | |
Darin Petkov | 0cd0d1e | 2013-02-11 12:49:10 +0100 | [diff] [blame] | 92 | private: |
| 93 | friend class VPNDriverTest; |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 94 | |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 95 | void ClearMappedProperty(const size_t &index, Error *error); |
| 96 | std::string GetMappedProperty(const size_t &index, Error *error); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 97 | bool SetMappedProperty( |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 98 | const size_t &index, const std::string &value, Error *error); |
| 99 | |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 100 | base::WeakPtrFactory<VPNDriver> weak_ptr_factory_; |
| 101 | EventDispatcher *dispatcher_; |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 102 | Manager *manager_; |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 103 | const Property * const properties_; |
| 104 | const size_t property_count_; |
| 105 | KeyValueStore args_; |
| 106 | |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 107 | base::CancelableClosure connect_timeout_callback_; |
| 108 | int connect_timeout_seconds_; |
| 109 | |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 110 | DISALLOW_COPY_AND_ASSIGN(VPNDriver); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | } // namespace shill |
| 114 | |
Darin Petkov | a42afe3 | 2013-02-05 16:53:52 +0100 | [diff] [blame] | 115 | #endif // SHILL_VPN_DRIVER_H_ |