first simple prototype of a UCI configuration plugin for OpenWRT
[strongswan.git] / src / charon / 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 * $Id$
16 */
17
18 #include "uci_plugin.h"
19 #include "uci_config.h"
20 #include "uci_creds.h"
21
22 #include <daemon.h>
23
24 /**
25 * UCI package name to use for lookups
26 */
27 #define UCI_PACKAGE "strongswan"
28
29 typedef struct private_uci_plugin_t private_uci_plugin_t;
30
31 /**
32 * private data of uci plugin
33 */
34 struct private_uci_plugin_t {
35
36 /**
37 * implements plugin interface
38 */
39 uci_plugin_t public;
40
41 /**
42 * UCI configuration backend
43 */
44 uci_config_t *config;
45
46 /**
47 * UCI credential set implementation
48 */
49 uci_creds_t *creds;
50
51 /**
52 * UCI parser wrapper
53 */
54 uci_parser_t *parser;
55 };
56
57 /**
58 * Implementation of plugin_t.destroy
59 */
60 static void destroy(private_uci_plugin_t *this)
61 {
62 charon->backends->remove_backend(charon->backends, &this->config->backend);
63 charon->credentials->remove_set(charon->credentials, &this->creds->credential_set);
64 this->config->destroy(this->config);
65 this->creds->destroy(this->creds);
66 this->parser->destroy(this->parser);
67 free(this);
68 }
69
70 /*
71 * see header file
72 */
73 plugin_t *plugin_create()
74 {
75 private_uci_plugin_t *this = malloc_thing(private_uci_plugin_t);
76
77 this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
78
79 this->parser = uci_parser_create(UCI_PACKAGE);
80 this->config = uci_config_create(this->parser);
81 this->creds = uci_creds_create(this->parser);
82 charon->backends->add_backend(charon->backends, &this->config->backend);
83 charon->credentials->add_set(charon->credentials, &this->creds->credential_set);
84
85 return &this->public.plugin;
86 }
87