]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libcharon/plugins/android/android_plugin.c
Correctly install DNS servers on Android if frontend is not used.
[thirdparty/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_logger.h"
19 #include "android_handler.h"
20 #include "android_creds.h"
21 #include "android_service.h"
22
23 #include <hydra.h>
24 #include <daemon.h>
25
26 typedef struct private_android_plugin_t private_android_plugin_t;
27
28 /**
29 * Private data of an android_plugin_t object.
30 */
31 struct private_android_plugin_t {
32
33 /**
34 * Public android_plugin_t interface.
35 */
36 android_plugin_t public;
37
38 /**
39 * Android specific logger
40 */
41 android_logger_t *logger;
42
43 /**
44 * Android specific DNS handler
45 */
46 android_handler_t *handler;
47
48 /**
49 * Android specific credential set
50 */
51 android_creds_t *creds;
52
53 /**
54 * Service that interacts with the Android Settings frontend
55 */
56 android_service_t *service;
57 };
58
59 METHOD(plugin_t, get_name, char*,
60 private_android_plugin_t *this)
61 {
62 return "android";
63 }
64
65 METHOD(plugin_t, destroy, void,
66 private_android_plugin_t *this)
67 {
68 hydra->attributes->remove_handler(hydra->attributes,
69 &this->handler->handler);
70 lib->credmgr->remove_set(lib->credmgr, &this->creds->set);
71 charon->bus->remove_listener(charon->bus, &this->logger->listener);
72 this->creds->destroy(this->creds);
73 this->handler->destroy(this->handler);
74 this->logger->destroy(this->logger);
75 DESTROY_IF(this->service);
76 free(this);
77 }
78
79 /**
80 * See header
81 */
82 plugin_t *android_plugin_create()
83 {
84 private_android_plugin_t *this;
85
86 INIT(this,
87 .public = {
88 .plugin = {
89 .get_name = _get_name,
90 .reload = (void*)return_false,
91 .destroy = _destroy,
92 },
93 },
94 .logger = android_logger_create(),
95 .creds = android_creds_create(),
96 );
97
98 charon->bus->add_listener(charon->bus, &this->logger->listener);
99 lib->credmgr->add_set(lib->credmgr, &this->creds->set);
100 hydra->attributes->add_handler(hydra->attributes, &this->handler->handler);
101
102 this->service = android_service_create(this->creds);
103 this->handler = android_handler_create(this->service != NULL);
104
105 return &this->public.plugin;
106 }
107