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
16 #include "tnc_imv_manager.h"
18 #include <tnc/imv/imv_manager.h>
19 #include <tnc/tncifimv.h>
23 #include <utils/linked_list.h>
25 typedef struct private_tnc_imv_manager_t private_tnc_imv_manager_t
;
28 * Private data of an imv_manager_t object.
30 struct private_tnc_imv_manager_t
{
33 * Public members of imv_manager_t.
43 * Next IMV ID to be assigned
45 TNC_IMVID next_imv_id
;
48 METHOD(imv_manager_t
, add
, bool,
49 private_tnc_imv_manager_t
*this, imv_t
*imv
)
53 /* Initialize the IMV module */
54 imv
->set_id(imv
, this->next_imv_id
);
55 if (imv
->initialize(imv
->get_id(imv
), TNC_IFIMV_VERSION_1
,
56 TNC_IFIMV_VERSION_1
, &version
) != TNC_RESULT_SUCCESS
)
58 DBG1(DBG_TNC
, "could not initialize IMV '%s'",
62 this->imvs
->insert_last(this->imvs
, imv
);
65 if (imv
->provide_bind_function(imv
->get_id(imv
), TNC_TNCS_BindFunction
)
66 != TNC_RESULT_SUCCESS
)
68 DBG1(DBG_TNC
, "could not provide bind function for IMV '%s'",
70 this->imvs
->remove_last(this->imvs
, (void**)&imv
);
77 METHOD(imv_manager_t
, remove_
, imv_t
*,
78 private_tnc_imv_manager_t
*this, TNC_IMVID id
)
80 enumerator_t
*enumerator
;
83 enumerator
= this->imvs
->create_enumerator(this->imvs
);
84 while (enumerator
->enumerate(enumerator
, &imv
))
86 if (id
== imv
->get_id(imv
))
88 this->imvs
->remove_at(this->imvs
, enumerator
);
92 enumerator
->destroy(enumerator
);
96 METHOD(imv_manager_t
, get_count
, int,
97 private_tnc_imv_manager_t
*this)
99 return this->imvs
->get_count(this->imvs
);
102 METHOD(imv_manager_t
, notify_connection_change
, void,
103 private_tnc_imv_manager_t
*this, TNC_ConnectionID id
,
104 TNC_ConnectionState state
)
106 enumerator_t
*enumerator
;
109 enumerator
= this->imvs
->create_enumerator(this->imvs
);
110 while (enumerator
->enumerate(enumerator
, &imv
))
112 if (imv
->notify_connection_change
)
114 imv
->notify_connection_change(imv
->get_id(imv
), id
, state
);
117 enumerator
->destroy(enumerator
);
120 METHOD(imv_manager_t
, set_message_types
, TNC_Result
,
121 private_tnc_imv_manager_t
*this, TNC_IMVID id
,
122 TNC_MessageTypeList supported_types
,
123 TNC_UInt32 type_count
)
125 enumerator_t
*enumerator
;
127 TNC_Result result
= TNC_RESULT_FATAL
;
129 enumerator
= this->imvs
->create_enumerator(this->imvs
);
130 while (enumerator
->enumerate(enumerator
, &imv
))
132 if (id
== imv
->get_id(imv
))
134 imv
->set_message_types(imv
, supported_types
, type_count
);
135 result
= TNC_RESULT_SUCCESS
;
139 enumerator
->destroy(enumerator
);
143 METHOD(imv_manager_t
, receive_message
, void,
144 private_tnc_imv_manager_t
*this, TNC_ConnectionID connection_id
,
145 TNC_BufferReference message
,
146 TNC_UInt32 message_len
,
147 TNC_MessageType message_type
)
149 enumerator_t
*enumerator
;
152 enumerator
= this->imvs
->create_enumerator(this->imvs
);
153 while (enumerator
->enumerate(enumerator
, &imv
))
155 if (imv
->receive_message
&& imv
->type_supported(imv
, message_type
))
157 imv
->receive_message(imv
->get_id(imv
), connection_id
,
158 message
, message_len
, message_type
);
161 enumerator
->destroy(enumerator
);
164 METHOD(imv_manager_t
, destroy
, void,
165 private_tnc_imv_manager_t
*this)
169 while (this->imvs
->remove_last(this->imvs
, (void**)&imv
) == SUCCESS
)
171 if (imv
->terminate
&&
172 imv
->terminate(imv
->get_id(imv
)) != TNC_RESULT_SUCCESS
)
174 DBG1(DBG_TNC
, "IMV '%s' not terminated successfully",
179 this->imvs
->destroy(this->imvs
);
184 * Described in header.
186 imv_manager_t
* tnc_imv_manager_create(void)
188 private_tnc_imv_manager_t
*this;
193 .remove
= _remove_
, /* avoid name conflict with stdio.h */
194 .get_count
= _get_count
,
195 .notify_connection_change
= _notify_connection_change
,
196 .set_message_types
= _set_message_types
,
197 .receive_message
= _receive_message
,
200 .imvs
= linked_list_create(),
204 return &this->public;