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