check if optional terminate() function exists
[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.h"
18
19 #include <daemon.h>
20
21 METHOD(plugin_t, destroy, void,
22 tnc_imv_plugin_t *this)
23 {
24 imv_t *imv;
25
26 while (charon->imvs->remove_last(charon->imvs, (void**)&imv) == SUCCESS)
27 {
28 if (imv->terminate &&
29 imv->terminate(imv->get_id(imv)) != TNC_RESULT_SUCCESS)
30 {
31 DBG1(DBG_TNC, "IMV '%s' not terminated successfully",
32 imv->get_name(imv));
33 }
34 imv->destroy(imv);
35 }
36 free(this);
37 }
38
39 /*
40 * see header file
41 */
42 plugin_t *tnc_imv_plugin_create()
43 {
44 TNC_IMVID next_id = 1;
45 TNC_Version version;
46 char *tnc_config, *name, *filename;
47 tnc_imv_plugin_t *this;
48 imv_t *imv;
49
50 INIT(this,
51 .plugin = {
52 .destroy = _destroy,
53 },
54 );
55
56 tnc_config = lib->settings->get_str(lib->settings,
57 "charon.plugins.tnc-imv.tnc_config", "/etc/tnc_config");
58
59 name = "Dummy";
60 filename = "/usr/local/lib/libdummyimv.so";
61 imv = tnc_imv_create(name, filename, next_id);
62 if (imv)
63 {
64 /* Initialize the module */
65 if (imv->initialize(next_id, TNC_IFIMV_VERSION_1, TNC_IFIMV_VERSION_1,
66 &version) != TNC_RESULT_SUCCESS)
67 {
68 DBG1(DBG_TNC, "could not initialize IMV '%s'\n",
69 imv->get_name(imv));
70 imv->destroy(imv);
71 }
72 else
73 {
74 charon->imvs->insert_last(charon->imvs, imv);
75 next_id++;
76 }
77 }
78 return &this->plugin;
79 }
80