4 * Copyright (c) 2014-2015 Samsung Electronics. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #include <vconf/vconf.h>
25 #include "vpn-internal.h"
27 static bool is_init = false;
29 EXPORT_API int vpn_initialize(void)
32 VPN_LOG(VPN_ERROR, "Already initialized\n");
33 return VPN_ERROR_INVALID_OPERATION;
36 if (_vpn_init() == false) {
37 VPN_LOG(VPN_ERROR, "Init failed!\n"); //LCOV_EXCL_LINE
38 return VPN_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
43 VPN_LOG(VPN_INFO, "VPN successfully initialized!\n");
45 return VPN_ERROR_NONE;
48 EXPORT_API int vpn_deinitialize(void)
50 if (is_init == false) {
51 VPN_LOG(VPN_ERROR, "Not initialized\n");
52 return VPN_ERROR_INVALID_OPERATION;
58 VPN_LOG(VPN_INFO, "VPN successfully de-initialized!\n");
60 return VPN_ERROR_NONE;
64 EXPORT_API int vpn_settings_init()
68 if (is_init == false) {
69 VPN_LOG(VPN_ERROR, "Not initialized\n");
70 return VPN_ERROR_INVALID_OPERATION;
73 rv = _vpn_settings_init();
75 if (rv != VPN_ERROR_NONE)
76 VPN_LOG(VPN_ERROR, "Error!! VPN Settings Deinit failed.\n"); //LCOV_EXCL_LINE
81 EXPORT_API int vpn_settings_deinit()
85 if (is_init == false) {
86 VPN_LOG(VPN_ERROR, "Not initialized\n");
87 return VPN_ERROR_INVALID_OPERATION;
90 rv = _vpn_settings_deinit();
92 if (rv != VPN_ERROR_NONE)
93 VPN_LOG(VPN_ERROR, "Error!! VPN Settings Deinit failed.\n");
98 EXPORT_API int vpn_settings_set_specific(const char *key, const char *value)
102 if (is_init == false) {
103 VPN_LOG(VPN_ERROR, "Not initialized\n");
104 return VPN_ERROR_INVALID_OPERATION;
107 rv = _vpn_settings_set_specific(key, value);
109 if (rv != VPN_ERROR_NONE)
110 VPN_LOG(VPN_ERROR, "Error!! VPN Settings Deinit failed.\n");
116 EXPORT_API int vpn_settings_set_type(const char *type)
120 if (is_init == false) {
121 VPN_LOG(VPN_ERROR, "Not initialized\n");
122 return VPN_ERROR_INVALID_OPERATION;
125 rv = _vpn_settings_set_specific("Type", type);
127 if (rv != VPN_ERROR_NONE)
128 VPN_LOG(VPN_ERROR, "Error!! VPN Settings Deinit failed.\n");
133 EXPORT_API int vpn_settings_set_name(const char *name)
137 if (is_init == false) {
138 VPN_LOG(VPN_ERROR, "Not initialized\n");
139 return VPN_ERROR_INVALID_OPERATION;
142 rv = _vpn_settings_set_specific("Name", name);
144 if (rv != VPN_ERROR_NONE)
145 VPN_LOG(VPN_ERROR, "Error!! VPN Settings Deinit failed.\n");
150 EXPORT_API int vpn_settings_set_host(const char *host)
154 if (is_init == false) {
155 VPN_LOG(VPN_ERROR, "Not initialized\n");
156 return VPN_ERROR_INVALID_OPERATION;
159 rv = _vpn_settings_set_specific("Host", host);
161 if (rv != VPN_ERROR_NONE)
162 VPN_LOG(VPN_ERROR, "Error!! VPN Settings Deinit failed.\n");
167 EXPORT_API int vpn_settings_set_domain(const char *domain)
171 if (is_init == false) {
172 VPN_LOG(VPN_ERROR, "Not initialized\n");
173 return VPN_ERROR_INVALID_OPERATION;
176 rv = _vpn_settings_set_specific("Domain", domain);
178 if (rv != VPN_ERROR_NONE)
179 VPN_LOG(VPN_ERROR, "Error!! VPN Settings Deinit failed.\n");
184 EXPORT_API int vpn_create(vpn_created_cb callback, void *user_data)
188 if (is_init == false) {
189 VPN_LOG(VPN_ERROR, "Not initialized\n");
190 return VPN_ERROR_INVALID_OPERATION;
193 rv = _vpn_create(callback, user_data);
195 if (rv != VPN_ERROR_NONE)
196 VPN_LOG(VPN_ERROR, "Error!! VPN Create failed.\n");
202 int vpn_remove(vpn_h handle, vpn_removed_cb callback, void *user_data)
206 if (is_init == false) {
207 VPN_LOG(VPN_ERROR, "Not initialized\n");
208 return VPN_ERROR_INVALID_OPERATION;
211 if (handle == NULL) {
212 VPN_LOG(VPN_ERROR, "VPN Handle is NULL\n");
213 return VPN_ERROR_INVALID_PARAMETER;
216 rv = _vpn_remove(handle, callback, user_data);
218 if (rv != VPN_ERROR_NONE)
219 VPN_LOG(VPN_ERROR, "Error!! VPN Remove failed.\n");
225 int vpn_connect(vpn_h handle, vpn_connect_cb callback, void *user_data)
229 if (is_init == false) {
230 VPN_LOG(VPN_ERROR, "Not initialized\n");
231 return VPN_ERROR_INVALID_OPERATION;
234 if (handle == NULL) {
235 VPN_LOG(VPN_ERROR, "VPN Handle is NULL\n");
236 return VPN_ERROR_INVALID_PARAMETER;
239 rv = _vpn_connect(handle, callback, user_data);
241 if (rv != VPN_ERROR_NONE)
242 VPN_LOG(VPN_ERROR, "Error!! VPN Remove failed.\n");
248 int vpn_disconnect(vpn_h handle, vpn_disconnect_cb callback, void *user_data)
252 if (is_init == false) {
253 VPN_LOG(VPN_ERROR, "Not initialized\n");
254 return VPN_ERROR_INVALID_OPERATION;
257 if (handle == NULL) {
258 VPN_LOG(VPN_ERROR, "VPN Handle is NULL\n");
259 return VPN_ERROR_INVALID_PARAMETER;
262 rv = _vpn_disconnect(handle);
264 if (rv != VPN_ERROR_NONE)
265 VPN_LOG(VPN_ERROR, "Error!! VPN Remove failed.\n");
271 GList *vpn_get_vpn_handle_list(void)
273 if (is_init == false) {
274 VPN_LOG(VPN_ERROR, "Not initialized\n");
278 return _vpn_get_vpn_handle_list();
282 int vpn_get_vpn_handle(const char *name, const char *host, const char *domain, vpn_h *handle)
286 if (is_init == false) {
287 VPN_LOG(VPN_ERROR, "Not initialized\n");
288 return VPN_ERROR_INVALID_OPERATION;
291 // Note: Domain is optional parameter at connman
292 if (name == NULL || host == NULL || handle == NULL)
293 return VPN_ERROR_INVALID_PARAMETER;
295 rv = _vpn_get_vpn_handle(name, host, domain, handle);
297 if (rv != VPN_ERROR_NONE)
298 VPN_LOG(VPN_ERROR, "Error!! VPN Get Handle failed.\n");
304 int vpn_get_vpn_info_name(const vpn_h handle, const char **name)
308 if (is_init == false) {
309 VPN_LOG(VPN_ERROR, "Not initialized\n");
310 return VPN_ERROR_INVALID_OPERATION;
313 if (handle == NULL || name == NULL)
314 return VPN_ERROR_INVALID_PARAMETER;
316 rv = _vpn_get_vpn_info_name(handle, name);
318 if (rv != VPN_ERROR_NONE)
319 VPN_LOG(VPN_ERROR, "Error!! VPN Get Info (Name) failed.\n");
325 int vpn_get_vpn_info_type(const vpn_h handle, const char **type)
329 if (is_init == false) {
330 VPN_LOG(VPN_ERROR, "Not initialized\n");
331 return VPN_ERROR_INVALID_OPERATION;
334 if (handle == NULL || type == NULL)
335 return VPN_ERROR_INVALID_PARAMETER;
337 rv = _vpn_get_vpn_info_type(handle, type);
339 if (rv != VPN_ERROR_NONE)
340 VPN_LOG(VPN_ERROR, "Error!! VPN Get Info (Type) failed.\n");
346 int vpn_get_vpn_info_host(const vpn_h handle, const char **host)
350 if (is_init == false) {
351 VPN_LOG(VPN_ERROR, "Not initialized\n");
352 return VPN_ERROR_INVALID_OPERATION;
355 if (handle == NULL || host == NULL)
356 return VPN_ERROR_INVALID_PARAMETER;
358 rv = _vpn_get_vpn_info_host(handle, host);
360 if (rv != VPN_ERROR_NONE)
361 VPN_LOG(VPN_ERROR, "Error!! VPN Get Info (Host) failed.\n");
367 int vpn_get_vpn_info_domain(const vpn_h handle, const char **domain)
371 if (is_init == false) {
372 VPN_LOG(VPN_ERROR, "Not initialized\n");
373 return VPN_ERROR_INVALID_OPERATION;
376 if (handle == NULL || domain == NULL)
377 return VPN_ERROR_INVALID_PARAMETER;
379 rv = _vpn_get_vpn_info_domain(handle, domain);
381 if (rv != VPN_ERROR_NONE)
382 VPN_LOG(VPN_ERROR, "Error!! VPN Get Info (Domain) failed.\n");
388 int vpn_set_state_callback(const vpn_h handle, vpn_state_cb cb, void *user_data)
392 if (is_init == false) {
393 VPN_LOG(VPN_ERROR, "Not initialized\n");
394 return VPN_ERROR_INVALID_OPERATION;
397 if (handle == NULL || cb == NULL)
398 return VPN_ERROR_INVALID_PARAMETER;
400 rv = _vpn_set_state_callback(handle, cb, user_data);
402 if (rv != VPN_ERROR_NONE)
403 VPN_LOG(VPN_ERROR, "Error!! VPN Set state callback failed.\n");
409 int vpn_unset_state_callback(const vpn_h handle)
413 if (is_init == false) {
414 VPN_LOG(VPN_ERROR, "Not initialized\n");
415 return VPN_ERROR_INVALID_OPERATION;
419 return VPN_ERROR_INVALID_PARAMETER;
421 rv = _vpn_unset_state_callback(handle);
423 if (rv != VPN_ERROR_NONE)
424 VPN_LOG(VPN_ERROR, "Error!! VPN Unset state callback failed.\n");