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