96452c1150f5183231591e26c366585b1dc5c48a
[platform/upstream/connman.git] / vpn / vpn-provider.h
1 /*
2  *
3  *  ConnMan VPN daemon
4  *
5  *  Copyright (C) 2007-2013  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifndef __VPN_PROVIDER_H
23 #define __VPN_PROVIDER_H
24
25 #include <stdbool.h>
26
27 #include <glib.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 /**
34  * SECTION:provider
35  * @title: Provider premitives
36  * @short_description: Functions for handling providers
37  */
38
39 enum vpn_provider_type {
40         VPN_PROVIDER_TYPE_UNKNOWN = 0,
41         VPN_PROVIDER_TYPE_VPN     = 1,
42 };
43
44 enum vpn_provider_state {
45         VPN_PROVIDER_STATE_UNKNOWN       = 0,
46         VPN_PROVIDER_STATE_IDLE          = 1,
47         VPN_PROVIDER_STATE_CONNECT       = 2,
48         VPN_PROVIDER_STATE_READY         = 3,
49         VPN_PROVIDER_STATE_DISCONNECT    = 4,
50         VPN_PROVIDER_STATE_FAILURE       = 5,
51 };
52
53 enum vpn_provider_error {
54         VPN_PROVIDER_ERROR_UNKNOWN              = 0,
55         VPN_PROVIDER_ERROR_CONNECT_FAILED       = 1,
56         VPN_PROVIDER_ERROR_LOGIN_FAILED = 2,
57         VPN_PROVIDER_ERROR_AUTH_FAILED  = 3,
58 };
59
60 enum vpn_provider_route_type {
61         VPN_PROVIDER_ROUTE_TYPE_NONE = 0,
62         VPN_PROVIDER_ROUTE_TYPE_MASK = 1,
63         VPN_PROVIDER_ROUTE_TYPE_ADDR = 2,
64         VPN_PROVIDER_ROUTE_TYPE_GW   = 3,
65 };
66
67 struct vpn_provider;
68 struct connman_ipaddress;
69
70 #define vpn_provider_ref(provider) \
71         vpn_provider_ref_debug(provider, __FILE__, __LINE__, __func__)
72
73 #define vpn_provider_unref(provider) \
74         vpn_provider_unref_debug(provider, __FILE__, __LINE__, __func__)
75
76 struct vpn_provider *
77 vpn_provider_ref_debug(struct vpn_provider *provider,
78                         const char *file, int line, const char *caller);
79 void vpn_provider_unref_debug(struct vpn_provider *provider,
80                         const char *file, int line, const char *caller);
81
82 int vpn_provider_set_string(struct vpn_provider *provider,
83                                         const char *key, const char *value);
84 int vpn_provider_set_string_hide_value(struct vpn_provider *provider,
85                                         const char *key, const char *value);
86 const char *vpn_provider_get_string(struct vpn_provider *provider,
87                                                         const char *key);
88
89 int vpn_provider_set_state(struct vpn_provider *provider,
90                                         enum vpn_provider_state state);
91
92 int vpn_provider_indicate_error(struct vpn_provider *provider,
93                                         enum vpn_provider_error error);
94
95 void vpn_provider_set_index(struct vpn_provider *provider, int index);
96 int vpn_provider_get_index(struct vpn_provider *provider);
97
98 void vpn_provider_set_data(struct vpn_provider *provider, void *data);
99 void *vpn_provider_get_data(struct vpn_provider *provider);
100 int vpn_provider_set_ipaddress(struct vpn_provider *provider,
101                                         struct connman_ipaddress *ipaddress);
102 int vpn_provider_set_pac(struct vpn_provider *provider,
103                                 const char *pac);
104 int vpn_provider_set_domain(struct vpn_provider *provider,
105                                 const char *domain);
106 int vpn_provider_set_nameservers(struct vpn_provider *provider,
107                                         const char *nameservers);
108 int vpn_provider_append_route(struct vpn_provider *provider,
109                                         const char *key, const char *value);
110
111 const char *vpn_provider_get_driver_name(struct vpn_provider *provider);
112 const char *vpn_provider_get_save_group(struct vpn_provider *provider);
113
114 const char *vpn_provider_get_name(struct vpn_provider *provider);
115 const char *vpn_provider_get_host(struct vpn_provider *provider);
116 const char *vpn_provider_get_path(struct vpn_provider *provider);
117 void vpn_provider_change_address(struct vpn_provider *provider);
118 void vpn_provider_clear_address(struct vpn_provider *provider, int family);
119
120 typedef void (* vpn_provider_connect_cb_t) (struct vpn_provider *provider,
121                                         void *user_data, int error);
122
123 typedef void (* vpn_provider_auth_cb_t) (struct vpn_provider *provider,
124                                         const char *authenticator,
125                                         const char *error, void *user_data);
126
127 typedef void (* vpn_provider_password_cb_t) (struct vpn_provider *provider,
128                                         const char *username,
129                                         const char *password,
130                                         const char *error, void *user_data);
131
132 struct vpn_provider_driver {
133         const char *name;
134         enum vpn_provider_type type;
135         int (*probe) (struct vpn_provider *provider);
136         int (*remove) (struct vpn_provider *provider);
137         int (*connect) (struct vpn_provider *provider,
138                         vpn_provider_connect_cb_t cb, const char *dbus_sender,
139                         void *user_data);
140         int (*disconnect) (struct vpn_provider *provider);
141         int (*save) (struct vpn_provider *provider, GKeyFile *keyfile);
142         int (*set_state)(struct vpn_provider *provider,
143                                                 enum vpn_provider_state state);
144         int (*route_env_parse) (struct vpn_provider *provider, const char *key,
145                         int *family, unsigned long *idx,
146                         enum vpn_provider_route_type *type);
147 };
148
149 int vpn_provider_driver_register(struct vpn_provider_driver *driver);
150 void vpn_provider_driver_unregister(struct vpn_provider_driver *driver);
151
152 #ifdef __cplusplus
153 }
154 #endif
155
156 #endif /* __VPN_PROVIDER_H */