fixed medsrv database uri key
[strongswan.git] / src / charon / plugins / medsrv / medsrv_plugin.c
1 /*
2 * Copyright (C) 2008 Martin Willi
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 "medsrv_plugin.h"
19
20 #include "medsrv_creds.h"
21 #include "medsrv_config.h"
22
23 #include <daemon.h>
24
25 typedef struct private_medsrv_plugin_t private_medsrv_plugin_t;
26
27 /**
28 * private data of medsrv plugin
29 */
30 struct private_medsrv_plugin_t {
31
32 /**
33 * implements plugin interface
34 */
35 medsrv_plugin_t public;
36
37 /**
38 * database connection instance
39 */
40 database_t *db;
41
42 /**
43 * medsrv credential set instance
44 */
45 medsrv_creds_t *creds;
46
47 /**
48 * medsrv config database
49 */
50 medsrv_config_t *config;
51 };
52
53 /**
54 * Implementation of plugin_t.destroy
55 */
56 static void destroy(private_medsrv_plugin_t *this)
57 {
58 charon->backends->remove_backend(charon->backends, &this->config->backend);
59 charon->credentials->remove_set(charon->credentials, &this->creds->set);
60 this->config->destroy(this->config);
61 this->creds->destroy(this->creds);
62 this->db->destroy(this->db);
63 free(this);
64 }
65
66 /*
67 * see header file
68 */
69 plugin_t *plugin_create()
70 {
71 char *uri;
72 private_medsrv_plugin_t *this = malloc_thing(private_medsrv_plugin_t);
73
74 this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
75
76 uri = lib->settings->get_str(lib->settings,
77 "medsrv.database", NULL);
78 if (!uri)
79 {
80 DBG1(DBG_CFG, "mediation database URI not defined, skipped");
81 free(this);
82 return NULL;
83 }
84
85 this->db = lib->db->create(lib->db, uri);
86 if (this->db == NULL)
87 {
88 DBG1(DBG_CFG, "opening mediation server database failed");
89 free(this);
90 return NULL;
91 }
92
93 this->creds = medsrv_creds_create(this->db);
94 this->config = medsrv_config_create(this->db);
95
96 charon->credentials->add_set(charon->credentials, &this->creds->set);
97 charon->backends->add_backend(charon->backends, &this->config->backend);
98
99 return &this->public.plugin;
100 }
101