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");
38 return VPN_ERROR_OPERATION_FAILED;
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;
55 if (_vpn_deinit() == false) {
56 VPN_LOG(VPN_ERROR, "Deinit failed!\n");
57 return VPN_ERROR_OPERATION_FAILED;
61 VPN_LOG(VPN_INFO, "VPN successfully de-initialized!\n");
63 return VPN_ERROR_NONE;
67 EXPORT_API int vpn_settings_init()
71 if (is_init == false) {
72 VPN_LOG(VPN_ERROR, "Not initialized\n");
73 return VPN_ERROR_INVALID_OPERATION;
76 rv = _vpn_settings_init();
78 if (rv != VPN_ERROR_NONE)
79 VPN_LOG(VPN_ERROR, "Error!! VPN Settings Deinit failed.\n");
84 EXPORT_API int vpn_settings_deinit()
88 if (is_init == false) {
89 VPN_LOG(VPN_ERROR, "Not initialized\n");
90 return VPN_ERROR_INVALID_OPERATION;
93 rv = _vpn_settings_deinit();
95 if (rv != VPN_ERROR_NONE)
96 VPN_LOG(VPN_ERROR, "Error!! VPN Settings Deinit failed.\n");
101 EXPORT_API int vpn_settings_set_specific(const char *key, const char *value)
105 if (is_init == false) {
106 VPN_LOG(VPN_ERROR, "Not initialized\n");
107 return VPN_ERROR_INVALID_OPERATION;
110 rv = _vpn_settings_set_specific(key, value);
112 if (rv != VPN_ERROR_NONE)
113 VPN_LOG(VPN_ERROR, "Error!! VPN Settings Deinit failed.\n");
119 EXPORT_API int vpn_settings_set_type(const char *type)
123 if (is_init == false) {
124 VPN_LOG(VPN_ERROR, "Not initialized\n");
125 return VPN_ERROR_INVALID_OPERATION;
128 rv = _vpn_settings_set_specific("Type", type);
130 if (rv != VPN_ERROR_NONE)
131 VPN_LOG(VPN_ERROR, "Error!! VPN Settings Deinit failed.\n");
136 EXPORT_API int vpn_settings_set_name(const char *name)
140 if (is_init == false) {
141 VPN_LOG(VPN_ERROR, "Not initialized\n");
142 return VPN_ERROR_INVALID_OPERATION;
145 rv = _vpn_settings_set_specific("Name", name);
147 if (rv != VPN_ERROR_NONE)
148 VPN_LOG(VPN_ERROR, "Error!! VPN Settings Deinit failed.\n");
153 EXPORT_API int vpn_settings_set_host(const char *host)
157 if (is_init == false) {
158 VPN_LOG(VPN_ERROR, "Not initialized\n");
159 return VPN_ERROR_INVALID_OPERATION;
162 rv = _vpn_settings_set_specific("Host", host);
164 if (rv != VPN_ERROR_NONE)
165 VPN_LOG(VPN_ERROR, "Error!! VPN Settings Deinit failed.\n");
170 EXPORT_API int vpn_settings_set_domain(const char *domain)
174 if (is_init == false) {
175 VPN_LOG(VPN_ERROR, "Not initialized\n");
176 return VPN_ERROR_INVALID_OPERATION;
179 rv = _vpn_settings_set_specific("Domain", domain);
181 if (rv != VPN_ERROR_NONE)
182 VPN_LOG(VPN_ERROR, "Error!! VPN Settings Deinit failed.\n");
187 EXPORT_API int vpn_create(vpn_created_cb callback, void *user_data)
191 if (is_init == false) {
192 VPN_LOG(VPN_ERROR, "Not initialized\n");
193 return VPN_ERROR_INVALID_OPERATION;
196 rv = _vpn_create(callback, user_data);
198 if (rv != VPN_ERROR_NONE)
199 VPN_LOG(VPN_ERROR, "Error!! VPN Create failed.\n");
205 int vpn_remove(vpn_h handle, vpn_removed_cb callback, void *user_data)
209 if (is_init == false) {
210 VPN_LOG(VPN_ERROR, "Not initialized\n");
211 return VPN_ERROR_INVALID_OPERATION;
214 if (handle == NULL) {
215 VPN_LOG(VPN_ERROR, "VPN Handle is NULL\n");
216 return VPN_ERROR_INVALID_PARAMETER;
219 rv = _vpn_remove(handle, callback, user_data);
221 if (rv != VPN_ERROR_NONE)
222 VPN_LOG(VPN_ERROR, "Error!! VPN Remove failed.\n");
228 int vpn_connect(vpn_h handle, vpn_connect_cb callback, void *user_data)
232 if (is_init == false) {
233 VPN_LOG(VPN_ERROR, "Not initialized\n");
234 return VPN_ERROR_INVALID_OPERATION;
237 if (handle == NULL) {
238 VPN_LOG(VPN_ERROR, "VPN Handle is NULL\n");
239 return VPN_ERROR_INVALID_PARAMETER;
242 rv = _vpn_connect(handle, callback, user_data);
244 if (rv != VPN_ERROR_NONE)
245 VPN_LOG(VPN_ERROR, "Error!! VPN Remove failed.\n");
251 int vpn_disconnect(vpn_h handle, vpn_disconnect_cb callback, void *user_data)
255 if (is_init == false) {
256 VPN_LOG(VPN_ERROR, "Not initialized\n");
257 return VPN_ERROR_INVALID_OPERATION;
260 if (handle == NULL) {
261 VPN_LOG(VPN_ERROR, "VPN Handle is NULL\n");
262 return VPN_ERROR_INVALID_PARAMETER;
265 rv = _vpn_disconnect(handle);
267 if (rv != VPN_ERROR_NONE)
268 VPN_LOG(VPN_ERROR, "Error!! VPN Remove failed.\n");
274 GList *vpn_get_vpn_handle_list(void)
276 if (is_init == false) {
277 VPN_LOG(VPN_ERROR, "Not initialized\n");
281 return _vpn_get_vpn_handle_list();
285 int vpn_get_vpn_handle(const char *host, const char *domain, vpn_h *handle)
289 if (is_init == false) {
290 VPN_LOG(VPN_ERROR, "Not initialized\n");
291 return VPN_ERROR_INVALID_OPERATION;
294 if (host == NULL || domain == NULL || handle == NULL)
295 return VPN_ERROR_INVALID_PARAMETER;
297 rv = _vpn_get_vpn_handle(host, domain, handle);
299 if (rv != VPN_ERROR_NONE)
300 VPN_LOG(VPN_ERROR, "Error!! VPN Get Handle failed.\n");
306 int vpn_get_vpn_info_name(const vpn_h handle, const char **name)
310 if (is_init == false) {
311 VPN_LOG(VPN_ERROR, "Not initialized\n");
312 return VPN_ERROR_INVALID_OPERATION;
315 if (handle == NULL || name == NULL)
316 return VPN_ERROR_INVALID_PARAMETER;
318 rv = _vpn_get_vpn_info_name(handle, name);
320 if (rv != VPN_ERROR_NONE)
321 VPN_LOG(VPN_ERROR, "Error!! VPN Get Info (Name) failed.\n");
327 int vpn_get_vpn_info_type(const vpn_h handle, const char **type)
331 if (is_init == false) {
332 VPN_LOG(VPN_ERROR, "Not initialized\n");
333 return VPN_ERROR_INVALID_OPERATION;
336 if (handle == NULL || type == NULL)
337 return VPN_ERROR_INVALID_PARAMETER;
339 rv = _vpn_get_vpn_info_type(handle, type);
341 if (rv != VPN_ERROR_NONE)
342 VPN_LOG(VPN_ERROR, "Error!! VPN Get Info (Type) failed.\n");
348 int vpn_get_vpn_info_host(const vpn_h handle, const char **host)
352 if (is_init == false) {
353 VPN_LOG(VPN_ERROR, "Not initialized\n");
354 return VPN_ERROR_INVALID_OPERATION;
357 if (handle == NULL || host == NULL)
358 return VPN_ERROR_INVALID_PARAMETER;
360 rv = _vpn_get_vpn_info_host(handle, host);
362 if (rv != VPN_ERROR_NONE)
363 VPN_LOG(VPN_ERROR, "Error!! VPN Get Info (Host) failed.\n");
369 int vpn_get_vpn_info_domain(const vpn_h handle, const char **domain)
373 if (is_init == false) {
374 VPN_LOG(VPN_ERROR, "Not initialized\n");
375 return VPN_ERROR_INVALID_OPERATION;
378 if (handle == NULL || domain == NULL)
379 return VPN_ERROR_INVALID_PARAMETER;
381 rv = _vpn_get_vpn_info_domain(handle, domain);
383 if (rv != VPN_ERROR_NONE)
384 VPN_LOG(VPN_ERROR, "Error!! VPN Get Info (Domain) failed.\n");