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 bool vpn_provider_get_boolean(struct vpn_provider *provider, const char *key,
89 int vpn_provider_set_state(struct vpn_provider *provider,
90 enum vpn_provider_state state);
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);
97 void vpn_provider_set_index(struct vpn_provider *provider, int index);
98 int vpn_provider_get_index(struct vpn_provider *provider);
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,
108 int vpn_provider_set_domain(struct vpn_provider *provider,
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);
115 const char *vpn_provider_get_driver_name(struct vpn_provider *provider);
116 const char *vpn_provider_get_save_group(struct vpn_provider *provider);
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);
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);
127 void vpn_provider_change_address(struct vpn_provider *provider);
128 void vpn_provider_clear_address(struct vpn_provider *provider, int family);
130 typedef void (* vpn_provider_connect_cb_t) (struct vpn_provider *provider,
131 void *user_data, int error);
133 typedef void (* vpn_provider_auth_cb_t) (struct vpn_provider *provider,
134 const char *authenticator,
135 const char *error, void *user_data);
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);
142 struct vpn_provider_driver {
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,
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);
158 int vpn_provider_driver_register(struct vpn_provider_driver *driver);
159 void vpn_provider_driver_unregister(struct vpn_provider_driver *driver);
165 #endif /* __VPN_PROVIDER_H */