abort if one of the IMCs or IMVs fail to initialize
[strongswan.git] / src / libcharon / plugins / tnc_imv / tnc_imv_plugin.c
1 /*
2 * Copyright (C) 2010 Andreas Steffen
3 * HSR 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 "tnc_imv_plugin.h"
17 #include "tnc_imv_manager.h"
18 #include "tnc_imv.h"
19
20 #include <daemon.h>
21
22 METHOD(plugin_t, destroy, void,
23 tnc_imv_plugin_t *this)
24 {
25 charon->imvs->destroy(charon->imvs);
26 free(this);
27 }
28
29 /*
30 * see header file
31 */
32 plugin_t *tnc_imv_plugin_create()
33 {
34 char *tnc_config, *name, *filename;
35 tnc_imv_plugin_t *this;
36 imv_t *imv;
37
38 INIT(this,
39 .plugin = {
40 .destroy = _destroy,
41 },
42 );
43
44 tnc_config = lib->settings->get_str(lib->settings,
45 "charon.plugins.tnc-imv.tnc_config", "/etc/tnc_config");
46
47 /* Create IMV manager */
48 charon->imvs = tnc_imv_manager_create();
49
50 /**
51 * Create, register and initialize IMVs
52 * Abort if one of the IMVs fails to initialize successfully
53 */
54 {
55 name = "Dummy";
56 filename = "/usr/local/lib/libdummyimv.so";
57 imv = tnc_imv_create(name, filename);
58
59 if (!imv)
60 {
61 charon->imvs->destroy(charon->imvs);
62 free(this);
63 return NULL;
64 }
65 if (!charon->imvs->add(charon->imvs, imv))
66 {
67 imv->destroy(imv);
68 charon->imvs->destroy(charon->imvs);
69 free(this);
70 return NULL;
71 }
72 }
73 return &this->plugin;
74 }
75