tnc-pdp: Initialize TNC-PDP in plugin callback with proper dependencies
[strongswan.git] / src / libcharon / plugins / tnc_pdp / tnc_pdp_plugin.c
1 /*
2 * Copyright (C) 2010 Andreas Steffen
3 * HSR 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 "tnc_pdp_plugin.h"
17 #include "tnc_pdp.h"
18
19 #include <daemon.h>
20
21 typedef struct private_tnc_pdp_plugin_t private_tnc_pdp_plugin_t;
22
23 /**
24 * Default RADIUS port, when not configured
25 */
26 #define RADIUS_PORT 1812
27
28 /**
29 * private data of tnc_pdp plugin
30 */
31 struct private_tnc_pdp_plugin_t {
32
33 /**
34 * implements plugin interface
35 */
36 tnc_pdp_plugin_t public;
37
38 /**
39 * Policy Decision Point object
40 */
41 tnc_pdp_t *pdp;
42
43 };
44
45 METHOD(plugin_t, get_name, char*,
46 private_tnc_pdp_plugin_t *this)
47 {
48 return "tnc-pdp";
49 }
50
51 /**
52 * Register listener
53 */
54 static bool plugin_cb(private_tnc_pdp_plugin_t *this,
55 plugin_feature_t *feature, bool reg, void *cb_data)
56 {
57 if (reg)
58 {
59 int port;
60
61 port = lib->settings->get_int(lib->settings,
62 "%s.plugins.tnc_pdp.port", RADIUS_PORT, charon->name);
63 this->pdp = tnc_pdp_create(port);
64 }
65 else
66 {
67 DESTROY_IF(this->pdp);
68 }
69 return TRUE;
70 }
71
72 METHOD(plugin_t, get_features, int,
73 private_tnc_pdp_plugin_t *this, plugin_feature_t *features[])
74 {
75 static plugin_feature_t f[] = {
76 PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
77 PLUGIN_PROVIDE(CUSTOM, "tnc-pdp"),
78 PLUGIN_DEPENDS(CUSTOM, "imv-manager"),
79 PLUGIN_DEPENDS(HASHER, HASH_MD5),
80 PLUGIN_DEPENDS(SIGNER, AUTH_HMAC_MD5_128),
81 PLUGIN_DEPENDS(NONCE_GEN),
82 };
83 *features = f;
84 return countof(f);
85 }
86
87 METHOD(plugin_t, destroy, void,
88 private_tnc_pdp_plugin_t *this)
89 {
90 free(this);
91 }
92
93 /*
94 * see header file
95 */
96 plugin_t *tnc_pdp_plugin_create()
97 {
98 private_tnc_pdp_plugin_t *this;
99
100 INIT(this,
101 .public = {
102 .plugin = {
103 .get_name = _get_name,
104 .get_features = _get_features,
105 .destroy = _destroy,
106 },
107 },
108 );
109
110 return &this->public.plugin;
111 }
112