2 * Copyright (C) 2011-2012 Andreas Steffen
3 * 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 "imv_test_state.h"
18 #include <utils/lexparser.h>
19 #include <collections/linked_list.h>
20 #include <utils/debug.h>
22 typedef struct private_imv_test_state_t private_imv_test_state_t
;
25 * Private data of an imv_test_state_t object.
27 struct private_imv_test_state_t
{
30 * Public members of imv_test_state_t
32 imv_test_state_t
public;
37 TNC_ConnectionID connection_id
;
40 * TNCCS connection state
42 TNC_ConnectionState state
;
45 * Does the TNCCS connection support long message types?
50 * Does the TNCCS connection support exclusive delivery?
55 * Maximum PA-TNC message size for this TNCCS connection
57 u_int32_t max_msg_len
;
60 * IMV action recommendation
62 TNC_IMV_Action_Recommendation rec
;
65 * IMV evaluation result
67 TNC_IMV_Evaluation_Result eval
;
76 typedef struct imc_entry_t imc_entry_t
;
79 * Define an internal IMC entry
86 typedef struct entry_t entry_t
;
89 * Define an internal reason string entry
97 * Table of multi-lingual reason string entries
99 static entry_t reasons
[] = {
100 { "en", "IMC Test was not configured with \"command = allow\"" },
101 { "de", "IMC Test wurde nicht mit \"command = allow\" konfiguriert" },
102 { "fr", "IMC Test n'etait pas configuré avec \"command = allow\"" },
103 { "pl", "IMC Test nie zostało skonfigurowany z \"command = allow\"" }
106 METHOD(imv_state_t
, get_connection_id
, TNC_ConnectionID
,
107 private_imv_test_state_t
*this)
109 return this->connection_id
;
112 METHOD(imv_state_t
, has_long
, bool,
113 private_imv_test_state_t
*this)
115 return this->has_long
;
118 METHOD(imv_state_t
, has_excl
, bool,
119 private_imv_test_state_t
*this)
121 return this->has_excl
;
124 METHOD(imv_state_t
, set_flags
, void,
125 private_imv_test_state_t
*this, bool has_long
, bool has_excl
)
127 this->has_long
= has_long
;
128 this->has_excl
= has_excl
;
131 METHOD(imv_state_t
, set_max_msg_len
, void,
132 private_imv_test_state_t
*this, u_int32_t max_msg_len
)
134 this->max_msg_len
= max_msg_len
;
137 METHOD(imv_state_t
, get_max_msg_len
, u_int32_t
,
138 private_imv_test_state_t
*this)
140 return this->max_msg_len
;
143 METHOD(imv_state_t
, change_state
, void,
144 private_imv_test_state_t
*this, TNC_ConnectionState new_state
)
146 this->state
= new_state
;
149 METHOD(imv_state_t
, get_recommendation
, void,
150 private_imv_test_state_t
*this, TNC_IMV_Action_Recommendation
*rec
,
151 TNC_IMV_Evaluation_Result
*eval
)
157 METHOD(imv_state_t
, set_recommendation
, void,
158 private_imv_test_state_t
*this, TNC_IMV_Action_Recommendation rec
,
159 TNC_IMV_Evaluation_Result eval
)
165 METHOD(imv_state_t
, get_reason_string
, bool,
166 private_imv_test_state_t
*this, enumerator_t
*language_enumerator
,
167 char **reason_string
, char **reason_language
)
173 /* set the default language */
174 *reason_language
= reasons
[0].lang
;
175 *reason_string
= reasons
[0].string
;
177 while (language_enumerator
->enumerate(language_enumerator
, &lang
))
179 for (i
= 0 ; i
< countof(reasons
); i
++)
181 if (streq(lang
, reasons
[i
].lang
))
184 *reason_language
= reasons
[i
].lang
;
185 *reason_string
= reasons
[i
].string
;
198 METHOD(imv_state_t
, get_remediation_instructions
, bool,
199 private_imv_test_state_t
*this, enumerator_t
*language_enumerator
,
200 char **string
, char **lang_code
)
205 METHOD(imv_state_t
, destroy
, void,
206 private_imv_test_state_t
*this)
208 this->imcs
->destroy_function(this->imcs
, free
);
212 METHOD(imv_test_state_t
, add_imc
, void,
213 private_imv_test_state_t
*this, TNC_UInt32 imc_id
, int rounds
)
215 enumerator_t
*enumerator
;
216 imc_entry_t
*imc_entry
;
219 enumerator
= this->imcs
->create_enumerator(this->imcs
);
220 while (enumerator
->enumerate(enumerator
, &imc_entry
))
222 if (imc_entry
->imc_id
== imc_id
)
228 enumerator
->destroy(enumerator
);
232 imc_entry
= malloc_thing(imc_entry_t
);
233 imc_entry
->imc_id
= imc_id
;
234 imc_entry
->rounds
= rounds
;
235 this->imcs
->insert_last(this->imcs
, imc_entry
);
239 METHOD(imv_test_state_t
, set_rounds
, void,
240 private_imv_test_state_t
*this, int rounds
)
242 enumerator_t
*enumerator
;
243 imc_entry_t
*imc_entry
;
245 enumerator
= this->imcs
->create_enumerator(this->imcs
);
246 while (enumerator
->enumerate(enumerator
, &imc_entry
))
248 imc_entry
->rounds
= rounds
;
250 enumerator
->destroy(enumerator
);
253 METHOD(imv_test_state_t
, another_round
, bool,
254 private_imv_test_state_t
*this, TNC_UInt32 imc_id
)
256 enumerator_t
*enumerator
;
257 imc_entry_t
*imc_entry
;
258 bool not_finished
= FALSE
;
260 enumerator
= this->imcs
->create_enumerator(this->imcs
);
261 while (enumerator
->enumerate(enumerator
, &imc_entry
))
263 if (imc_entry
->rounds
> 0)
267 if (imc_entry
->imc_id
== imc_id
)
272 enumerator
->destroy(enumerator
);
278 * Described in header.
280 imv_state_t
*imv_test_state_create(TNC_ConnectionID connection_id
)
282 private_imv_test_state_t
*this;
287 .get_connection_id
= _get_connection_id
,
288 .has_long
= _has_long
,
289 .has_excl
= _has_excl
,
290 .set_flags
= _set_flags
,
291 .set_max_msg_len
= _set_max_msg_len
,
292 .get_max_msg_len
= _get_max_msg_len
,
293 .change_state
= _change_state
,
294 .get_recommendation
= _get_recommendation
,
295 .set_recommendation
= _set_recommendation
,
296 .get_reason_string
= _get_reason_string
,
297 .get_remediation_instructions
= _get_remediation_instructions
,
301 .set_rounds
= _set_rounds
,
302 .another_round
= _another_round
,
304 .state
= TNC_CONNECTION_STATE_CREATE
,
305 .rec
= TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION
,
306 .eval
= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
,
307 .connection_id
= connection_id
,
308 .imcs
= linked_list_create(),
311 return &this->public.interface
;