Merge branch 'android-client-cert'
[strongswan.git] / src / libcharon / plugins / updown / updown_plugin.c
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "updown_plugin.h"
17 #include "updown_listener.h"
18 #include "updown_handler.h"
19
20 #include <daemon.h>
21 #include <hydra.h>
22
23 typedef struct private_updown_plugin_t private_updown_plugin_t;
24
25 /**
26 * private data of updown plugin
27 */
28 struct private_updown_plugin_t {
29
30 /**
31 * implements plugin interface
32 */
33 updown_plugin_t public;
34
35 /**
36 * Listener interface, listens to CHILD_SA state changes
37 */
38 updown_listener_t *listener;
39
40 /**
41 * Attribute handler, to pass DNS servers to updown
42 */
43 updown_handler_t *handler;
44 };
45
46 METHOD(plugin_t, get_name, char*,
47 private_updown_plugin_t *this)
48 {
49 return "updown";
50 }
51
52 METHOD(plugin_t, destroy, void,
53 private_updown_plugin_t *this)
54 {
55 charon->bus->remove_listener(charon->bus, &this->listener->listener);
56 this->listener->destroy(this->listener);
57 if (this->handler)
58 {
59 hydra->attributes->remove_handler(hydra->attributes,
60 &this->handler->handler);
61 this->handler->destroy(this->handler);
62 }
63 free(this);
64 }
65
66 /*
67 * see header file
68 */
69 plugin_t *updown_plugin_create()
70 {
71 private_updown_plugin_t *this;
72
73 INIT(this,
74 .public = {
75 .plugin = {
76 .get_name = _get_name,
77 .reload = (void*)return_false,
78 .destroy = _destroy,
79 },
80 },
81 );
82
83 if (lib->settings->get_bool(lib->settings,
84 "charon.plugins.updown.dns_handler", FALSE))
85 {
86 this->handler = updown_handler_create();
87 hydra->attributes->add_handler(hydra->attributes,
88 &this->handler->handler);
89 }
90 this->listener = updown_listener_create(this->handler);
91 charon->bus->add_listener(charon->bus, &this->listener->listener);
92
93 return &this->public.plugin;
94 }
95