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