Annotation of embedaddon/strongswan/src/libcharon/plugins/vici/vici_plugin.c, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2014 Martin Willi
3: * Copyright (C) 2014 revosec AG
4: *
5: * Copyright (C) 2015-2016 Andreas Steffen
6: * HSR Hochschule fuer Technik Rapperswil
7: *
8: * This program is free software; you can redistribute it and/or modify it
9: * under the terms of the GNU General Public License as published by the
10: * Free Software Foundation; either version 2 of the License, or (at your
11: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
12: *
13: * This program is distributed in the hope that it will be useful, but
14: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: * for more details.
17: */
18:
19: /*
20: * Copyright (C) 2014 Timo Teräs <timo.teras@iki.fi>
21: *
22: * Permission is hereby granted, free of charge, to any person obtaining a copy
23: * of this software and associated documentation files (the "Software"), to deal
24: * in the Software without restriction, including without limitation the rights
25: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26: * copies of the Software, and to permit persons to whom the Software is
27: * furnished to do so, subject to the following conditions:
28: *
29: * The above copyright notice and this permission notice shall be included in
30: * all copies or substantial portions of the Software.
31: *
32: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
38: * THE SOFTWARE.
39: */
40:
41: #include "vici_plugin.h"
42: #include "vici_dispatcher.h"
43: #include "vici_query.h"
44: #include "vici_control.h"
45: #include "vici_cred.h"
46: #include "vici_config.h"
47: #include "vici_attribute.h"
48: #include "vici_authority.h"
49: #include "vici_logger.h"
50:
51: #include <library.h>
52: #include <daemon.h>
53:
54: typedef struct private_vici_plugin_t private_vici_plugin_t;
55:
56: /**
57: * Private members of vici_plugin_t
58: */
59: struct private_vici_plugin_t {
60:
61: /**
62: * public functions
63: */
64: vici_plugin_t public;
65:
66: /**
67: * Dispatcher, creating socket
68: */
69: vici_dispatcher_t *dispatcher;
70:
71: /**
72: * Query commands
73: */
74: vici_query_t *query;
75:
76: /**
77: * Control commands
78: */
79: vici_control_t *control;
80:
81: /**
82: * Credential backend
83: */
84: vici_cred_t *cred;
85:
86: /**
87: * Certification Authority backend
88: */
89: vici_authority_t *authority;
90:
91: /**
92: * Configuration backend
93: */
94: vici_config_t *config;
95:
96: /**
97: * IKE attribute backend
98: */
99: vici_attribute_t *attrs;
100:
101: /**
102: * Generic debug logger
103: */
104: vici_logger_t *logger;
105: };
106:
107: METHOD(plugin_t, get_name, char*,
108: private_vici_plugin_t *this)
109: {
110: return "vici";
111: }
112:
113: /**
114: * Register vici plugin features
115: */
116: static bool register_vici(private_vici_plugin_t *this,
117: plugin_feature_t *feature, bool reg, void *data)
118: {
119: if (reg)
120: {
121: char *uri;
122:
123: uri = lib->settings->get_str(lib->settings, "%s.plugins.vici.socket",
124: VICI_DEFAULT_URI, lib->ns);
125: this->dispatcher = vici_dispatcher_create(uri);
126: if (this->dispatcher)
127: {
128: this->query = vici_query_create(this->dispatcher);
129: this->control = vici_control_create(this->dispatcher);
130: this->cred = vici_cred_create(this->dispatcher);
131: this->authority = vici_authority_create(this->dispatcher,
132: this->cred);
133: lib->credmgr->add_set(lib->credmgr, &this->cred->set);
134: lib->credmgr->add_set(lib->credmgr, &this->authority->set);
135: this->config = vici_config_create(this->dispatcher, this->authority,
136: this->cred);
137: this->attrs = vici_attribute_create(this->dispatcher);
138: this->logger = vici_logger_create(this->dispatcher);
139:
140: charon->backends->add_backend(charon->backends,
141: &this->config->backend);
142: charon->attributes->add_provider(charon->attributes,
143: &this->attrs->provider);
144: charon->bus->add_logger(charon->bus, &this->logger->logger);
145: charon->bus->add_listener(charon->bus, &this->query->listener);
146: return TRUE;
147: }
148: return FALSE;
149: }
150: else
151: {
152: charon->bus->remove_listener(charon->bus, &this->query->listener);
153: charon->bus->remove_logger(charon->bus, &this->logger->logger);
154: charon->attributes->remove_provider(charon->attributes,
155: &this->attrs->provider);
156: charon->backends->remove_backend(charon->backends,
157: &this->config->backend);
158:
159: this->logger->destroy(this->logger);
160: this->attrs->destroy(this->attrs);
161: this->config->destroy(this->config);
162: lib->credmgr->remove_set(lib->credmgr, &this->cred->set);
163: lib->credmgr->remove_set(lib->credmgr, &this->authority->set);
164: this->authority->destroy(this->authority);
165: this->cred->destroy(this->cred);
166: this->control->destroy(this->control);
167: this->query->destroy(this->query);
168: this->dispatcher->destroy(this->dispatcher);
169: }
170: return TRUE;
171: }
172:
173: METHOD(plugin_t, get_features, int,
174: private_vici_plugin_t *this, plugin_feature_t *features[])
175: {
176: static plugin_feature_t f[] = {
177: PLUGIN_CALLBACK((plugin_feature_callback_t)register_vici, NULL),
178: PLUGIN_PROVIDE(CUSTOM, "vici"),
179: PLUGIN_SDEPEND(CUSTOM, "counters"),
180: };
181: *features = f;
182: return countof(f);
183: }
184:
185: METHOD(plugin_t, destroy, void,
186: private_vici_plugin_t *this)
187: {
188: free(this);
189: }
190:
191: /*
192: * see header file
193: */
194: plugin_t *vici_plugin_create()
195: {
196: private_vici_plugin_t *this;
197:
198: INIT(this,
199: .public = {
200: .plugin = {
201: .get_name = _get_name,
202: .reload = (void*)return_false,
203: .get_features = _get_features,
204: .destroy = _destroy,
205: },
206: },
207: );
208:
209: return &this->public.plugin;
210: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>