2 * Copyright (C) 2011 Sansar Choinyambuu
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_attestation_state.h"
18 #include <utils/lexparser.h>
21 typedef struct private_imv_attestation_state_t private_imv_attestation_state_t
;
24 * Private data of an imv_attestation_state_t object.
26 struct private_imv_attestation_state_t
{
29 * Public members of imv_attestation_state_t
31 imv_attestation_state_t
public;
36 TNC_ConnectionID connection_id
;
39 * TNCCS connection state
41 TNC_ConnectionState state
;
44 * IMV Attestation handshake state
46 imv_attestation_handshake_state_t handshake_state
;
49 * IMV action recommendation
51 TNC_IMV_Action_Recommendation rec
;
54 * IMV evaluation result
56 TNC_IMV_Evaluation_Result eval
;
59 typedef struct entry_t entry_t
;
62 * Define an internal reason string entry
70 * Table of multi-lingual reason string entries
72 static entry_t reasons
[] = {
73 { "en", "IMC Attestation ..." },
74 { "mn", "IMC Attestation ..." },
75 { "de", "IMC Attestation ..." },
78 METHOD(imv_state_t
, get_connection_id
, TNC_ConnectionID
,
79 private_imv_attestation_state_t
*this)
81 return this->connection_id
;
84 METHOD(imv_state_t
, change_state
, void,
85 private_imv_attestation_state_t
*this, TNC_ConnectionState new_state
)
87 this->state
= new_state
;
90 METHOD(imv_state_t
, get_recommendation
, void,
91 private_imv_attestation_state_t
*this, TNC_IMV_Action_Recommendation
*rec
,
92 TNC_IMV_Evaluation_Result
*eval
)
98 METHOD(imv_state_t
, set_recommendation
, void,
99 private_imv_attestation_state_t
*this, TNC_IMV_Action_Recommendation rec
,
100 TNC_IMV_Evaluation_Result eval
)
106 METHOD(imv_state_t
, get_reason_string
, bool,
107 private_imv_attestation_state_t
*this, chunk_t preferred_language
,
108 chunk_t
*reason_string
, chunk_t
*reason_language
)
110 chunk_t pref_lang
, lang
;
114 while (eat_whitespace(&preferred_language
))
116 if (!extract_token(&pref_lang
, ',', &preferred_language
))
118 /* last entry in a comma-separated list or single entry */
119 pref_lang
= preferred_language
;
122 /* eat trailing whitespace */
123 pos
= pref_lang
.ptr
+ pref_lang
.len
- 1;
124 while (pref_lang
.len
&& *pos
-- == ' ')
129 for (i
= 0 ; i
< countof(reasons
); i
++)
131 lang
= chunk_create(reasons
[i
].lang
, strlen(reasons
[i
].lang
));
132 if (chunk_equals(lang
, pref_lang
))
134 *reason_language
= lang
;
135 *reason_string
= chunk_create(reasons
[i
].string
,
136 strlen(reasons
[i
].string
));
142 /* no preferred language match found - use the default language */
143 *reason_string
= chunk_create(reasons
[0].string
,
144 strlen(reasons
[0].string
));
145 *reason_language
= chunk_create(reasons
[0].lang
,
146 strlen(reasons
[0].lang
));
150 METHOD(imv_state_t
, destroy
, void,
151 private_imv_attestation_state_t
*this)
156 METHOD(imv_attestation_state_t
, get_handshake_state
, imv_attestation_handshake_state_t
,
157 private_imv_attestation_state_t
*this)
159 return this->handshake_state
;
162 METHOD(imv_attestation_state_t
, set_handshake_state
, void,
163 private_imv_attestation_state_t
*this, imv_attestation_handshake_state_t new_state
)
165 this->handshake_state
= new_state
;
169 * Described in header.
171 imv_state_t
*imv_attestation_state_create(TNC_ConnectionID connection_id
)
173 private_imv_attestation_state_t
*this;
178 .get_connection_id
= _get_connection_id
,
179 .change_state
= _change_state
,
180 .get_recommendation
= _get_recommendation
,
181 .set_recommendation
= _set_recommendation
,
182 .get_reason_string
= _get_reason_string
,
185 .get_handshake_state
= _get_handshake_state
,
186 .set_handshake_state
= _set_handshake_state
,
188 .state
= TNC_CONNECTION_STATE_CREATE
,
189 .handshake_state
= IMC_ATTESTATION_STATE_INIT
,
190 .rec
= TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION
,
191 .eval
= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
,
194 return &this->public.interface
;