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
;
27 struct private_tnc_imv_manager_t
{
30 * Public members of imv_manager_t.
40 * Next IMV ID to be assigned
42 TNC_IMVID next_imv_id
;
45 METHOD(imv_manager_t
, add
, bool,
46 private_tnc_imv_manager_t
*this, imv_t
*imv
)
50 /* Initialize the IMV module */
51 imv
->set_id(imv
, this->next_imv_id
);
52 if (imv
->initialize(imv
->get_id(imv
), TNC_IFIMV_VERSION_1
,
53 TNC_IFIMV_VERSION_1
, &version
) != TNC_RESULT_SUCCESS
)
55 DBG1(DBG_TNC
, "could not initialize IMV '%s'",
59 if (imv
->provide_bind_function(imv
->get_id(imv
), TNC_TNCS_BindFunction
)
60 != TNC_RESULT_SUCCESS
)
62 DBG1(DBG_TNC
, "could not provide bind function for IMV '%s'",
66 this->imvs
->insert_last(this->imvs
, imv
);
71 METHOD(imv_manager_t
, notify_connection_change
, void,
72 private_tnc_imv_manager_t
*this, TNC_ConnectionID id
,
73 TNC_ConnectionState state
)
75 enumerator_t
*enumerator
;
78 enumerator
= this->imvs
->create_enumerator(this->imvs
);
79 while (enumerator
->enumerate(enumerator
, &imv
))
81 if (imv
->notify_connection_change
)
83 imv
->notify_connection_change(imv
->get_id(imv
), id
, state
);
86 enumerator
->destroy(enumerator
);
89 METHOD(imv_manager_t
, set_message_types
, TNC_Result
,
90 private_tnc_imv_manager_t
*this, TNC_IMVID id
,
91 TNC_MessageTypeList supported_types
,
92 TNC_UInt32 type_count
)
94 enumerator_t
*enumerator
;
96 TNC_Result result
= TNC_RESULT_FATAL
;
98 enumerator
= this->imvs
->create_enumerator(this->imvs
);
99 while (enumerator
->enumerate(enumerator
, &imv
))
101 if (id
== imv
->get_id(imv
))
103 imv
->set_message_types(imv
, supported_types
, type_count
);
104 result
= TNC_RESULT_SUCCESS
;
108 enumerator
->destroy(enumerator
);
112 METHOD(imv_manager_t
, destroy
, void,
113 private_tnc_imv_manager_t
*this)
117 while (this->imvs
->remove_last(this->imvs
, (void**)&imv
) == SUCCESS
)
119 if (imv
->terminate
&&
120 imv
->terminate(imv
->get_id(imv
)) != TNC_RESULT_SUCCESS
)
122 DBG1(DBG_TNC
, "IMV '%s' not terminated successfully",
127 this->imvs
->destroy(this->imvs
);
132 * Described in header.
134 imv_manager_t
* tnc_imv_manager_create(void)
136 private_tnc_imv_manager_t
*this;
141 .notify_connection_change
= _notify_connection_change
,
142 .set_message_types
= _set_message_types
,
145 .imvs
= linked_list_create(),
150 return &this->public;