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