Annotation of embedaddon/strongswan/src/libcharon/plugins/coupling/coupling_plugin.c, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2011 Martin Willi
3: * Copyright (C) 2011 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 "coupling_plugin.h"
17:
18: #include "coupling_validator.h"
19:
20: #include <daemon.h>
21:
22: typedef struct private_coupling_plugin_t private_coupling_plugin_t;
23:
24: /**
25: * private data of coupling plugin
26: */
27: struct private_coupling_plugin_t {
28:
29: /**
30: * implements plugin interface
31: */
32: coupling_plugin_t public;
33:
34: /**
35: * validator controlling couplings
36: */
37: coupling_validator_t *validator;
38: };
39:
40: METHOD(plugin_t, get_name, char*,
41: private_coupling_plugin_t *this)
42: {
43: return "coupling";
44: }
45:
46: /**
47: * Since the validator instantiates a hasher we create it as plugin feature.
48: * The default is SHA1 which we soft depend but depending on the plugin order
49: * there is no guarantee that the configured algorithm is registered.
50: */
51: static bool plugin_cb(private_coupling_plugin_t *this,
52: plugin_feature_t *feature, bool reg, void *cb_data)
53: {
54: if (reg)
55: {
56: this->validator = coupling_validator_create();
57:
58: if (!this->validator)
59: {
60: return FALSE;
61: }
62: lib->credmgr->add_validator(lib->credmgr, &this->validator->validator);
63: }
64: else
65: {
66: lib->credmgr->remove_validator(lib->credmgr,
67: &this->validator->validator);
68: this->validator->destroy(this->validator);
69: }
70: return TRUE;
71: }
72:
73: METHOD(plugin_t, get_features, int,
74: private_coupling_plugin_t *this, plugin_feature_t *features[])
75: {
76: static plugin_feature_t f[] = {
77: PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
78: PLUGIN_PROVIDE(CUSTOM, "coupling"),
79: PLUGIN_SDEPEND(HASHER, HASH_SHA1),
80: };
81: *features = f;
82: return countof(f);
83: }
84:
85: METHOD(plugin_t, destroy, void,
86: private_coupling_plugin_t *this)
87: {
88: free(this);
89: }
90:
91: /**
92: * Plugin constructor
93: */
94: plugin_t *coupling_plugin_create()
95: {
96: private_coupling_plugin_t *this;
97:
98: INIT(this,
99: .public = {
100: .plugin = {
101: .get_name = _get_name,
102: .get_features = _get_features,
103: .destroy = _destroy,
104: },
105: },
106: );
107:
108: return &this->public.plugin;
109: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>