c0f58e9b40a8c9b71b4396147ec1a963a7aced30
[strongswan.git] / src / libcharon / plugins / android / android_plugin.c
1 /*
2 * Copyright (C) 2010 Tobias Brunner
3 * Copyright (C) 2010 Martin Willi
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include "android_plugin.h"
18 #include "android_handler.h"
19 #include "android_creds.h"
20 #include "android_service.h"
21
22 #include <hydra.h>
23 #include <daemon.h>
24
25 typedef struct private_android_plugin_t private_android_plugin_t;
26
27 /**
28 * Private data of an android_plugin_t object.
29 */
30 struct private_android_plugin_t {
31
32 /**
33 * Public android_plugin_t interface.
34 */
35 android_plugin_t public;
36
37 /**
38 * Android specific DNS handler
39 */
40 android_handler_t *handler;
41
42 /**
43 * Android specific credential set
44 */
45 android_creds_t *creds;
46
47 /**
48 * Service that interacts with the Android Settings frontend
49 */
50 android_service_t *service;
51 };
52
53 METHOD(plugin_t, get_name, char*,
54 private_android_plugin_t *this)
55 {
56 return "android";
57 }
58
59 METHOD(plugin_t, destroy, void,
60 private_android_plugin_t *this)
61 {
62 hydra->attributes->remove_handler(hydra->attributes,
63 &this->handler->handler);
64 lib->credmgr->remove_set(lib->credmgr, &this->creds->set);
65 this->creds->destroy(this->creds);
66 this->handler->destroy(this->handler);
67 DESTROY_IF(this->service);
68 free(this);
69 }
70
71 /**
72 * See header
73 */
74 plugin_t *android_plugin_create()
75 {
76 private_android_plugin_t *this;
77
78 INIT(this,
79 .public = {
80 .plugin = {
81 .get_name = _get_name,
82 .reload = (void*)return_false,
83 .destroy = _destroy,
84 },
85 },
86 .creds = android_creds_create(),
87 );
88
89 this->service = android_service_create(this->creds);
90 this->handler = android_handler_create(this->service != NULL);
91
92 lib->credmgr->add_set(lib->credmgr, &this->creds->set);
93 hydra->attributes->add_handler(hydra->attributes, &this->handler->handler);
94
95 return &this->public.plugin;
96 }
97