]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libcharon/plugins/addrblock/addrblock_plugin.c
Update copyright headers after acquisition by secunet
[thirdparty/strongswan.git] / src / libcharon / plugins / addrblock / addrblock_plugin.c
1 /*
2 * Copyright (C) 2010 Martin Willi
3 *
4 * Copyright (C) secunet Security Networks AG
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 "addrblock_plugin.h"
18
19 #include <daemon.h>
20 #include <plugins/plugin_feature.h>
21
22 #include "addrblock_validator.h"
23 #include "addrblock_narrow.h"
24
25 typedef struct private_addrblock_plugin_t private_addrblock_plugin_t;
26
27 /**
28 * private data of addrblock_plugin
29 */
30 struct private_addrblock_plugin_t {
31
32 /**
33 * public functions
34 */
35 addrblock_plugin_t public;
36
37 /**
38 * Validator implementation instance.
39 */
40 addrblock_validator_t *validator;
41
42 /**
43 * Listener to check TS list
44 */
45 addrblock_narrow_t *narrower;
46 };
47
48 METHOD(plugin_t, get_name, char*,
49 private_addrblock_plugin_t *this)
50 {
51 return "addrblock";
52 }
53
54 /**
55 * Register listener
56 */
57 static bool plugin_cb(private_addrblock_plugin_t *this,
58 plugin_feature_t *feature, bool reg, void *cb_data)
59 {
60 if (reg)
61 {
62 lib->credmgr->add_validator(lib->credmgr, &this->validator->validator);
63 charon->bus->add_listener(charon->bus, &this->narrower->listener);
64 }
65 else
66 {
67 charon->bus->remove_listener(charon->bus, &this->narrower->listener);
68 lib->credmgr->remove_validator(lib->credmgr,
69 &this->validator->validator);
70 }
71 return TRUE;
72 }
73
74 METHOD(plugin_t, get_features, int,
75 private_addrblock_plugin_t *this, plugin_feature_t *features[])
76 {
77 static plugin_feature_t f[] = {
78 PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
79 PLUGIN_PROVIDE(CUSTOM, "addrblock"),
80 PLUGIN_SDEPEND(CERT_DECODE, CERT_X509),
81 };
82 *features = f;
83 return countof(f);
84 }
85
86 METHOD(plugin_t, destroy, void,
87 private_addrblock_plugin_t *this)
88 {
89 this->narrower->destroy(this->narrower);
90 this->validator->destroy(this->validator);
91 free(this);
92 }
93
94 /*
95 * see header file
96 */
97 plugin_t *addrblock_plugin_create()
98 {
99 private_addrblock_plugin_t *this;
100
101 INIT(this,
102 .public = {
103 .plugin = {
104 .get_name = _get_name,
105 .get_features = _get_features,
106 .destroy = _destroy,
107 },
108 },
109 .validator = addrblock_validator_create(),
110 .narrower = addrblock_narrow_create(),
111 );
112
113 return &this->public.plugin;
114 }