• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _VPN_CONTROLLER_H
18 #define _VPN_CONTROLLER_H
19 
20 #include <netinet/in.h>
21 
22 #include "Controller.h"
23 
24 class IControllerHandler;
25 
26 class VpnController : public Controller {
27     class VpnIntegerProperty : public IntegerProperty {
28     protected:
29         VpnController *mVc;
30     public:
31         VpnIntegerProperty(VpnController *c, const char *name, bool ro,
32                             int elements);
~VpnIntegerProperty()33         virtual ~VpnIntegerProperty() {}
34         virtual int set(int idx, int value) = 0;
35         virtual int get(int idx, int *buffer) = 0;
36     };
37     friend class VpnController::VpnIntegerProperty;
38 
39     class VpnStringProperty : public StringProperty {
40     protected:
41         VpnController *mVc;
42     public:
43         VpnStringProperty(VpnController *c, const char *name, bool ro,
44                             int elements);
~VpnStringProperty()45         virtual ~VpnStringProperty() {}
46         virtual int set(int idx, const char *value) = 0;
47         virtual int get(int idx, char *buffer, size_t max) = 0;
48     };
49     friend class VpnController::VpnStringProperty;
50 
51     class VpnIPV4AddressProperty : public IPV4AddressProperty {
52     protected:
53         VpnController *mVc;
54     public:
55         VpnIPV4AddressProperty(VpnController *c, const char *name, bool ro,
56                           int elements);
~VpnIPV4AddressProperty()57         virtual ~VpnIPV4AddressProperty() {}
58         virtual int set(int idx, struct in_addr *value) = 0;
59         virtual int get(int idx, struct in_addr *buffer) = 0;
60     };
61     friend class VpnController::VpnIPV4AddressProperty;
62 
63     class VpnEnabledProperty : public VpnIntegerProperty {
64     public:
65         VpnEnabledProperty(VpnController *c);
~VpnEnabledProperty()66         virtual ~VpnEnabledProperty() {};
67         int set(int idx, int value);
68         int get(int idx, int *buffer);
69     };
70 
71     bool           mEnabled;
72     /*
73      * Gateway of the VPN server to connect to
74      */
75     struct in_addr mGateway;
76 
77     struct {
78         VpnEnabledProperty *propEnabled;
79     } mStaticProperties;
80 
81     struct {
82         IPV4AddressPropertyHelper *propGateway;
83     } mDynamicProperties;
84 
85 public:
86     VpnController(PropertyManager *propmngr, IControllerHandler *handlers);
~VpnController()87     virtual ~VpnController() {}
88 
89     virtual int start();
90     virtual int stop();
91 
92 protected:
93     virtual int enable() = 0;
94     virtual int disable() = 0;
95 };
96 
97 #endif
98