2 * Copyright (C) 2006 Mike McCauley
3 * Copyright (C) 2010 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
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>.
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
23 typedef struct private_tnc_imc_t private_tnc_imc_t
;
25 struct private_tnc_imc_t
{
28 * Public members of imc_t.
43 * List of message types supported by IMC
45 TNC_MessageTypeList supported_types
;
48 * Number of supported message types
50 TNC_UInt32 type_count
;
53 METHOD(imc_t
, set_id
, void,
54 private_tnc_imc_t
*this, TNC_IMCID id
)
59 METHOD(imc_t
, get_id
, TNC_IMCID
,
60 private_tnc_imc_t
*this)
65 METHOD(imc_t
, get_name
, char*,
66 private_tnc_imc_t
*this)
71 METHOD(imc_t
, set_message_types
, void,
72 private_tnc_imc_t
*this, TNC_MessageTypeList supported_types
,
73 TNC_UInt32 type_count
)
75 free(this->supported_types
);
76 this->supported_types
= NULL
;
77 this->type_count
= type_count
;
78 if (type_count
&& supported_types
)
80 size_t size
= type_count
* sizeof(TNC_MessageType
);
82 this->supported_types
= malloc(size
);
83 memcpy(this->supported_types
, supported_types
, size
);
87 METHOD(imc_t
, destroy
, void,
88 private_tnc_imc_t
*this)
91 free(this->supported_types
);
96 * Described in header.
98 imc_t
* tnc_imc_create(char* name
, char *filename
)
100 private_tnc_imc_t
*this;
107 .get_name
= _get_name
,
108 .set_message_types
= _set_message_types
,
113 handle
= dlopen(filename
, RTLD_NOW
);
116 DBG1(DBG_TNC
, "IMC '%s' failed to load from '%s': %s",
117 name
, filename
, dlerror());
122 /* we do not store or free dlopen() handles, leak_detective requires
123 * the modules to keep loaded until leak report */
125 this->public.initialize
= dlsym(handle
, "TNC_IMC_Initialize");
126 if (!this->public.initialize
)
128 DBG1(DBG_TNC
, "could not resolve TNC_IMC_Initialize in %s: %s\n",
129 filename
, dlerror());
133 this->public.notify_connection_change
=
134 dlsym(handle
, "TNC_IMC_NotifyConnectionChange");
135 this->public.begin_handshake
= dlsym(handle
, "TNC_IMC_BeginHandshake");
136 if (!this->public.begin_handshake
)
138 DBG1(DBG_TNC
, "could not resolve TNC_IMC_BeginHandshake in %s: %s\n",
139 filename
, dlerror());
143 this->public.receive_message
=
144 dlsym(handle
, "TNC_IMC_ReceiveMessage");
145 this->public.batch_ending
=
146 dlsym(handle
, "TNC_IMC_BatchEnding");
147 this->public.terminate
=
148 dlsym(handle
, "TNC_IMC_Terminate");
149 this->public.provide_bind_function
=
150 dlsym(handle
, "TNC_IMC_ProvideBindFunction");
151 if (!this->public.provide_bind_function
)
153 DBG1(DBG_TNC
, "could not resolve TNC_IMC_ProvideBindFunction in %s: %s\n",
154 filename
, dlerror());
158 this->name
= strdup(name
);
160 return &this->public;