Merge "Fix crash caused by decryption response delay" into tizen
[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 int vpn_provider_set_boolean(struct vpn_provider *provider, const char *key,
87                                                         bool value,
88                                                         bool force_change);
89 bool vpn_provider_get_boolean(struct vpn_provider *provider, const char *key,
90                                                         bool default_value);
91 bool vpn_provider_setting_key_exists(struct vpn_provider *provider,
92                                                         const char *key);
93 void vpn_provider_set_auth_error_limit(struct vpn_provider *provider,
94                                                         unsigned int limit);
95
96 int vpn_provider_set_state(struct vpn_provider *provider,
97                                         enum vpn_provider_state state);
98
99 void vpn_provider_add_error(struct vpn_provider *provider,
100                                         enum vpn_provider_error error);
101 int vpn_provider_indicate_error(struct vpn_provider *provider,
102                                         enum vpn_provider_error error);
103
104 void vpn_provider_set_index(struct vpn_provider *provider, int index);
105 int vpn_provider_get_index(struct vpn_provider *provider);
106
107 void vpn_provider_set_data(struct vpn_provider *provider, void *data);
108 void *vpn_provider_get_data(struct vpn_provider *provider);
109 void vpn_provider_set_plugin_data(struct vpn_provider *provider, void *data);
110 void *vpn_provider_get_plugin_data(struct vpn_provider *provider);
111 int vpn_provider_set_ipaddress(struct vpn_provider *provider,
112                                         struct connman_ipaddress *ipaddress);
113 int vpn_provider_set_pac(struct vpn_provider *provider,
114                                 const char *pac);
115 int vpn_provider_set_domain(struct vpn_provider *provider,
116                                 const char *domain);
117 int vpn_provider_set_nameservers(struct vpn_provider *provider,
118                                         const char *nameservers);
119 int vpn_provider_append_route(struct vpn_provider *provider,
120                                         const char *key, const char *value);
121
122 const char *vpn_provider_get_driver_name(struct vpn_provider *provider);
123 const char *vpn_provider_get_save_group(struct vpn_provider *provider);
124
125 const char *vpn_provider_get_name(struct vpn_provider *provider);
126 const char *vpn_provider_get_host(struct vpn_provider *provider);
127 const char *vpn_provider_get_path(struct vpn_provider *provider);
128 const char *vpn_provider_get_ident(struct vpn_provider *provider);
129
130 unsigned int vpn_provider_get_authentication_errors(
131                                         struct vpn_provider *provider);
132 unsigned int vpn_provider_get_connection_errors(
133                                         struct vpn_provider *provider);
134
135 void vpn_provider_change_address(struct vpn_provider *provider);
136 void vpn_provider_clear_address(struct vpn_provider *provider, int family);
137
138 typedef void (* vpn_provider_connect_cb_t) (struct vpn_provider *provider,
139                                         void *user_data, int error);
140
141 typedef void (* vpn_provider_auth_cb_t) (struct vpn_provider *provider,
142                                         const char *authenticator,
143                                         const char *error, void *user_data);
144
145 typedef void (* vpn_provider_password_cb_t) (struct vpn_provider *provider,
146                                         const char *username,
147                                         const char *password,
148                                         const char *error, void *user_data);
149
150 struct vpn_provider_driver {
151         const char *name;
152         int (*probe) (struct vpn_provider *provider);
153         int (*remove) (struct vpn_provider *provider);
154         int (*connect) (struct vpn_provider *provider,
155                         vpn_provider_connect_cb_t cb, const char *dbus_sender,
156                         void *user_data);
157         int (*disconnect) (struct vpn_provider *provider);
158         int (*save) (struct vpn_provider *provider, GKeyFile *keyfile);
159         int (*set_state)(struct vpn_provider *provider,
160                                                 enum vpn_provider_state state);
161         int (*route_env_parse) (struct vpn_provider *provider, const char *key,
162                         int *family, unsigned long *idx,
163                         enum vpn_provider_route_type *type);
164 };
165
166 int vpn_provider_driver_register(struct vpn_provider_driver *driver);
167 void vpn_provider_driver_unregister(struct vpn_provider_driver *driver);
168
169 #ifdef __cplusplus
170 }
171 #endif
172
173 #endif /* __VPN_PROVIDER_H */