2 * Copyright (C) 2013 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_session.h"
18 #include <utils/debug.h>
20 typedef struct private_imv_session_t private_imv_session_t
;
23 * Private data of a imv_session_t object.
25 struct private_imv_session_t
{
28 * Public imv_session_t interface.
50 TNC_ConnectionID conn_id
;
53 * Session creation time
58 * Access Requestor ID type
63 * Access Requestor ID value
70 imv_os_info_t
*os_info
;
78 * Is Device ID trusted?
83 * Have the workitems been generated?
88 * List of worklist items
90 linked_list_t
*workitems
;
99 METHOD(imv_session_t
, set_session_id
, void,
100 private_imv_session_t
*this, int session_id
, int pid
, int did
)
102 this->session_id
= session_id
;
107 METHOD(imv_session_t
, get_session_id
, int,
108 private_imv_session_t
*this, int *pid
, int *did
)
118 return this->session_id
;
121 METHOD(imv_session_t
, get_connection_id
, TNC_ConnectionID
,
122 private_imv_session_t
*this)
124 return this->conn_id
;
127 METHOD(imv_session_t
, get_creation_time
, time_t,
128 private_imv_session_t
*this)
130 return this->created
;
133 METHOD(imv_session_t
, get_ar_id
, chunk_t
,
134 private_imv_session_t
*this, uint32_t *ar_id_type
)
138 *ar_id_type
= this->ar_id_type
;
140 return this->ar_id_value
;
143 METHOD(imv_session_t
, get_os_info
, imv_os_info_t
*,
144 private_imv_session_t
*this)
146 return this->os_info
;
149 METHOD(imv_session_t
, set_device_id
, void,
150 private_imv_session_t
*this, chunk_t device_id
)
152 if (device_id
.len
== 0)
154 device_id
= chunk_from_str("unknown");
156 if (this->device_id
.len
)
158 if (chunk_equals(device_id
, this->device_id
))
162 free(this->device_id
.ptr
);
164 this->device_id
= chunk_clone(device_id
);
167 METHOD(imv_session_t
, get_device_id
, bool,
168 private_imv_session_t
*this, chunk_t
*device_id
)
170 if (this->device_id
.len
== 0)
176 *device_id
= this->device_id
;
181 METHOD(imv_session_t
, set_device_trust
, void,
182 private_imv_session_t
*this, bool trusted
)
184 this->trusted
= trusted
;
187 METHOD(imv_session_t
, get_device_trust
, bool,
188 private_imv_session_t
*this)
190 return this->trusted
;
193 METHOD(imv_session_t
, set_policy_started
, void,
194 private_imv_session_t
*this, bool start
)
196 this->policy_started
= start
;
199 METHOD(imv_session_t
, get_policy_started
, bool,
200 private_imv_session_t
*this)
202 return this->policy_started
;
205 METHOD(imv_session_t
, insert_workitem
, void,
206 private_imv_session_t
*this, imv_workitem_t
*workitem
)
208 this->workitems
->insert_last(this->workitems
, workitem
);
211 METHOD(imv_session_t
, remove_workitem
, void,
212 private_imv_session_t
*this, enumerator_t
*enumerator
)
214 this->workitems
->remove_at(this->workitems
, enumerator
);
217 METHOD(imv_session_t
, create_workitem_enumerator
, enumerator_t
*,
218 private_imv_session_t
*this)
220 return this->workitems
->create_enumerator(this->workitems
);
223 METHOD(imv_session_t
, get_workitem_count
, int,
224 private_imv_session_t
*this, TNC_IMVID imv_id
)
226 enumerator_t
*enumerator
;
227 imv_workitem_t
*workitem
;
230 enumerator
= this->workitems
->create_enumerator(this->workitems
);
231 while (enumerator
->enumerate(enumerator
, &workitem
))
233 if (workitem
->get_imv_id(workitem
) == imv_id
)
238 enumerator
->destroy(enumerator
);
243 METHOD(imv_session_t
, get_ref
, imv_session_t
*,
244 private_imv_session_t
*this)
248 return &this->public;
251 METHOD(imv_session_t
, destroy
, void,
252 private_imv_session_t
*this)
254 if (ref_put(&this->ref
))
256 this->workitems
->destroy_offset(this->workitems
,
257 offsetof(imv_workitem_t
, destroy
));
258 this->os_info
->destroy(this->os_info
);
259 free(this->ar_id_value
.ptr
);
260 free(this->device_id
.ptr
);
268 imv_session_t
*imv_session_create(TNC_ConnectionID conn_id
, time_t created
,
269 uint32_t ar_id_type
, chunk_t ar_id_value
)
271 private_imv_session_t
*this;
275 .set_session_id
= _set_session_id
,
276 .get_session_id
= _get_session_id
,
277 .get_connection_id
= _get_connection_id
,
278 .get_creation_time
= _get_creation_time
,
279 .get_ar_id
= _get_ar_id
,
280 .get_os_info
= _get_os_info
,
281 .set_device_id
= _set_device_id
,
282 .get_device_id
= _get_device_id
,
283 .set_device_trust
= _set_device_trust
,
284 .get_device_trust
= _get_device_trust
,
285 .set_policy_started
= _set_policy_started
,
286 .get_policy_started
= _get_policy_started
,
287 .insert_workitem
= _insert_workitem
,
288 .remove_workitem
= _remove_workitem
,
289 .create_workitem_enumerator
= _create_workitem_enumerator
,
290 .get_workitem_count
= _get_workitem_count
,
296 .ar_id_type
= ar_id_type
,
297 .ar_id_value
= chunk_clone(ar_id_value
),
298 .os_info
= imv_os_info_create(),
299 .workitems
= linked_list_create(),
303 return &this->public;