5 * Copyright (C) 2007-2013 Intel Corporation. All rights reserved.
6 * Copyright (C) 2019 Jolla Ltd. All rights reserved.
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.
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.
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
23 #ifndef __VPN_PROVIDER_H
24 #define __VPN_PROVIDER_H
36 * @title: Provider premitives
37 * @short_description: Functions for handling providers
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,
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,
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,
64 struct connman_ipaddress;
66 #define vpn_provider_ref(provider) \
67 vpn_provider_ref_debug(provider, __FILE__, __LINE__, __func__)
69 #define vpn_provider_unref(provider) \
70 vpn_provider_unref_debug(provider, __FILE__, __LINE__, __func__)
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);
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,
84 bool vpn_provider_get_string_immutable(struct vpn_provider *provider,
86 int vpn_provider_set_boolean(struct vpn_provider *provider, const char *key,
89 bool vpn_provider_get_boolean(struct vpn_provider *provider, const char *key,
92 int vpn_provider_set_state(struct vpn_provider *provider,
93 enum vpn_provider_state state);
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);
100 void vpn_provider_set_index(struct vpn_provider *provider, int index);
101 int vpn_provider_get_index(struct vpn_provider *provider);
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,
111 int vpn_provider_set_domain(struct vpn_provider *provider,
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);
118 const char *vpn_provider_get_driver_name(struct vpn_provider *provider);
119 const char *vpn_provider_get_save_group(struct vpn_provider *provider);
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);
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);
131 void vpn_provider_change_address(struct vpn_provider *provider);
132 void vpn_provider_clear_address(struct vpn_provider *provider, int family);
134 typedef void (* vpn_provider_connect_cb_t) (struct vpn_provider *provider,
135 void *user_data, int error);
137 typedef void (* vpn_provider_auth_cb_t) (struct vpn_provider *provider,
138 const char *authenticator,
139 const char *error, void *user_data);
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);
146 struct vpn_provider_driver {
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,
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);
162 int vpn_provider_driver_register(struct vpn_provider_driver *driver);
163 void vpn_provider_driver_unregister(struct vpn_provider_driver *driver);
169 #endif /* __VPN_PROVIDER_H */