72c551f0f52d1636a55472301ce78a37591f9872
[strongswan.git] / src / libcharon / plugins / addrblock / addrblock_plugin.c
1 /*
2 * Copyright (C) 2010 Martin Willi
3 * Copyright (C) 2010 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 "addrblock_plugin.h"
17
18 #include <daemon.h>
19
20 #include "addrblock_validator.h"
21 #include "addrblock_narrow.h"
22
23 typedef struct private_addrblock_plugin_t private_addrblock_plugin_t;
24
25 /**
26 * private data of addrblock_plugin
27 */
28 struct private_addrblock_plugin_t {
29
30 /**
31 * public functions
32 */
33 addrblock_plugin_t public;
34
35 /**
36 * Validator implementation instance.
37 */
38 addrblock_validator_t *validator;
39
40 /**
41 * Listener to check TS list
42 */
43 addrblock_narrow_t *narrower;
44 };
45
46 METHOD(plugin_t, get_name, char*,
47 private_addrblock_plugin_t *this)
48 {
49 return "addrblock";
50 }
51
52 METHOD(plugin_t, destroy, void,
53 private_addrblock_plugin_t *this)
54 {
55 charon->bus->remove_listener(charon->bus, &this->narrower->listener);
56 lib->credmgr->remove_validator(lib->credmgr, &this->validator->validator);
57 this->narrower->destroy(this->narrower);
58 this->validator->destroy(this->validator);
59 free(this);
60 }
61
62 /*
63 * see header file
64 */
65 plugin_t *addrblock_plugin_create()
66 {
67 private_addrblock_plugin_t *this;
68
69 INIT(this,
70 .public = {
71 .plugin = {
72 .get_name = _get_name,
73 .reload = (void*)return_false,
74 .destroy = _destroy,
75 },
76 },
77 .validator = addrblock_validator_create(),
78 .narrower = addrblock_narrow_create(),
79 );
80 lib->credmgr->add_validator(lib->credmgr, &this->validator->validator);
81 charon->bus->add_listener(charon->bus, &this->narrower->listener);
82
83 return &this->public.plugin;
84 }