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