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