cleaned up whitespace
[strongswan.git] / src / libcharon / plugins / tnc_imv / tnc_imv.c
1 /*
2 * Copyright (C) 2006 Mike McCauley
3 * Copyright (C) 2010 Andreas Steffen, 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.h"
17
18 #include <dlfcn.h>
19
20 #include <debug.h>
21 #include <library.h>
22
23 typedef struct private_tnc_imv_t private_tnc_imv_t;
24
25 struct private_tnc_imv_t {
26
27 /**
28 * Public members of imv_t.
29 */
30 imv_t public;
31
32 /**
33 * Name of loaded IMV
34 */
35 char *name;
36
37 /**
38 * ID of loaded IMV
39 */
40 TNC_IMVID id;
41 };
42
43 METHOD(imv_t, get_id, TNC_IMVID,
44 private_tnc_imv_t *this)
45 {
46 return this->id;
47 }
48
49 METHOD(imv_t, destroy, void,
50 private_tnc_imv_t *this)
51 {
52 free(this->name);
53 free(this);
54 }
55
56 /**
57 * Described in header.
58 */
59 imv_t* tnc_imv_create(char *name, char *filename, TNC_IMVID id)
60 {
61 private_tnc_imv_t *this;
62 void *handle;
63
64 INIT(this,
65 .public = {
66 .get_id = _get_id,
67 .destroy = _destroy,
68 },
69 );
70
71 handle = dlopen(filename, RTLD_NOW);
72 if (handle == NULL)
73 {
74 DBG1(DBG_TNC, "IMV '%s' failed to load from '%s': %s",
75 name, filename, dlerror());
76 free(this);
77 return NULL;
78 }
79
80 /* we do not store or free dlopen() handles, leak_detective requires
81 * the modules to keep loaded until leak report */
82
83 this->public.initialize = dlsym(handle, "TNC_IMV_Initialize");
84 if (!this->public.initialize)
85 {
86 DBG1(DBG_TNC, "could not resolve TNC_IMV_Initialize in %s: %s\n",
87 filename, dlerror());
88 free(this);
89 return NULL;
90 }
91 this->public.notify_connection_change =
92 dlsym(handle, "TNC_IMV_NotifyConnectionChange");
93 this->public.solicit_recommendation =
94 dlsym(handle, "TNC_IMV_SolicitRecommendation");
95 if (!this->public.solicit_recommendation)
96 {
97 DBG1(DBG_TNC, "could not resolve TNC_IMV_SolicitRecommendation in %s: %s\n",
98 filename, dlerror());
99 free(this);
100 return NULL;
101 }
102 this->public.receive_message =
103 dlsym(handle, "TNC_IMV_ReceiveMessage");
104 this->public.batch_ending =
105 dlsym(handle, "TNC_IMV_BatchEnding");
106 this->public.terminate =
107 dlsym(handle, "TNC_IMV_Terminate");
108 this->public.provide_bind_function =
109 dlsym(handle, "TNC_IMV_ProvideBindFunction");
110 if (!this->public.provide_bind_function)
111 {
112 DBG1(DBG_TNC, "could not resolve TNC_IMV_ProvideBindFunction in %s: %s\n",
113 filename, dlerror());
114 free(this);
115 return NULL;
116 }
117 DBG2(DBG_TNC, "IMV '%s' loaded successfully with ID %u", name, id);
118 this->name = strdup(name);
119 this->id = id;
120
121 return &this->public;
122 }
123