9e21bd9ed67b0639618108e286915f3b405b7ecb
[strongswan.git] / src / libcharon / plugins / unity / unity_plugin.c
1 /*
2 * Copyright (C) 2012 Martin Willi
3 * Copyright (C) 2012 revosec AG
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 "unity_plugin.h"
17 #include "unity_handler.h"
18 #include "unity_narrow.h"
19 #include "unity_provider.h"
20
21 #include <daemon.h>
22 #include <hydra.h>
23
24 typedef struct private_unity_plugin_t private_unity_plugin_t;
25
26 /**
27 * private data of unity_plugin
28 */
29 struct private_unity_plugin_t {
30
31 /**
32 * public functions
33 */
34 unity_plugin_t public;
35
36 /**
37 * Handler for UNITY configuration attributes
38 */
39 unity_handler_t *handler;
40
41 /**
42 * Responder Unity configuration attribute provider
43 */
44 unity_provider_t *provider;
45
46 /**
47 * Traffic selector narrower, for Unity Split-Includes
48 */
49 unity_narrow_t *narrower;
50 };
51
52 METHOD(plugin_t, get_name, char*,
53 private_unity_plugin_t *this)
54 {
55 return "unity";
56 }
57
58 METHOD(plugin_t, destroy, void,
59 private_unity_plugin_t *this)
60 {
61 charon->bus->remove_listener(charon->bus, &this->narrower->listener);
62 this->narrower->destroy(this->narrower);
63 hydra->attributes->remove_handler(hydra->attributes, &this->handler->handler);
64 hydra->attributes->remove_provider(hydra->attributes,
65 &this->provider->provider);
66 this->handler->destroy(this->handler);
67 this->provider->destroy(this->provider);
68 free(this);
69 }
70
71 /*
72 * see header file
73 */
74 plugin_t *unity_plugin_create()
75 {
76 private_unity_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 .handler = unity_handler_create(),
87 .provider = unity_provider_create(),
88 );
89 hydra->attributes->add_handler(hydra->attributes, &this->handler->handler);
90 hydra->attributes->add_provider(hydra->attributes, &this->provider->provider);
91
92 this->narrower = unity_narrow_create(this->handler),
93 charon->bus->add_listener(charon->bus, &this->narrower->listener);
94
95 return &this->public.plugin;
96 }