Migrated remaining plugin_t implementations to INIT/METHOD macros
[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, destroy, void,
62 private_uci_plugin_t *this)
63 {
64 charon->backends->remove_backend(charon->backends, &this->config->backend);
65 lib->credmgr->remove_set(lib->credmgr, &this->creds->credential_set);
66 this->config->destroy(this->config);
67 this->creds->destroy(this->creds);
68 this->parser->destroy(this->parser);
69 this->control->destroy(this->control);
70 free(this);
71 }
72
73 /*
74 * see header file
75 */
76 plugin_t *uci_plugin_create()
77 {
78 private_uci_plugin_t *this;
79
80 INIT(this,
81 .public = {
82 .plugin = {
83 .destroy = _destroy,
84 },
85 },
86 .parser = uci_parser_create(UCI_PACKAGE),
87 .config = uci_config_create(this->parser),
88 .creds = uci_creds_create(this->parser),
89 .control = uci_control_create(),
90 );
91
92 charon->backends->add_backend(charon->backends, &this->config->backend);
93 lib->credmgr->add_set(lib->credmgr, &this->creds->credential_set);
94
95 return &this->public.plugin;
96 }
97