a6d24c32b19f87bf443aa88f6bc335970a1db91d
[strongswan.git] / src / libcharon / plugins / uci / uci_plugin.c
1 /*
2 * Copyright (C) 2008 Thomas Kallenberg
3 * 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 "uci_plugin.h"
17 #include "uci_config.h"
18 #include "uci_creds.h"
19 #include "uci_control.h"
20
21 #include <daemon.h>
22
23 /**
24 * UCI package name to use for lookups
25 */
26 #define UCI_PACKAGE "strongswan"
27
28 typedef struct private_uci_plugin_t private_uci_plugin_t;
29
30 /**
31 * private data of uci plugin
32 */
33 struct private_uci_plugin_t {
34
35 /**
36 * implements plugin interface
37 */
38 uci_plugin_t public;
39
40 /**
41 * UCI configuration backend
42 */
43 uci_config_t *config;
44
45 /**
46 * UCI credential set implementation
47 */
48 uci_creds_t *creds;
49
50 /**
51 * UCI parser wrapper
52 */
53 uci_parser_t *parser;
54
55 /**
56 * UCI control interface
57 */
58 uci_control_t *control;
59 };
60
61 METHOD(plugin_t, get_name, char*,
62 private_uci_plugin_t *this)
63 {
64 return "uci";
65 }
66
67 METHOD(plugin_t, destroy, void,
68 private_uci_plugin_t *this)
69 {
70 charon->backends->remove_backend(charon->backends, &this->config->backend);
71 lib->credmgr->remove_set(lib->credmgr, &this->creds->credential_set);
72 this->config->destroy(this->config);
73 this->creds->destroy(this->creds);
74 this->parser->destroy(this->parser);
75 this->control->destroy(this->control);
76 free(this);
77 }
78
79 /*
80 * see header file
81 */
82 plugin_t *uci_plugin_create()
83 {
84 private_uci_plugin_t *this;
85
86 INIT(this,
87 .public = {
88 .plugin = {
89 .get_name = _get_name,
90 .reload = (void*)return_false,
91 .destroy = _destroy,
92 },
93 },
94 .parser = uci_parser_create(UCI_PACKAGE),
95 .config = uci_config_create(this->parser),
96 .creds = uci_creds_create(this->parser),
97 .control = uci_control_create(),
98 );
99
100 charon->backends->add_backend(charon->backends, &this->config->backend);
101 lib->credmgr->add_set(lib->credmgr, &this->creds->credential_set);
102
103 return &this->public.plugin;
104 }
105