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_workitem.h"
18 #include <utils/debug.h>
19 #include <tncif_names.h>
21 typedef struct private_imv_workitem_t private_imv_workitem_t
;
23 ENUM(imv_workitem_type_names
, IMV_WORKITEM_PACKAGES
, IMV_WORKITEM_TPM_ATTEST
,
43 * Private data of a imv_workitem_t object.
46 struct private_imv_workitem_t
{
49 * Public imv_workitem_t interface.
51 imv_workitem_t
public;
54 * Primary workitem key
66 imv_workitem_type_t type
;
84 * IMV action recommendation
86 TNC_IMV_Action_Recommendation rec_fail
;
89 * IMV action recommendation
91 TNC_IMV_Action_Recommendation rec_noresult
;
94 * IMV action recommendation
96 TNC_IMV_Action_Recommendation rec_final
;
100 METHOD(imv_workitem_t
, get_id
, int,
101 private_imv_workitem_t
*this)
106 METHOD(imv_workitem_t
, set_imv_id
, void,
107 private_imv_workitem_t
*this, TNC_IMVID imv_id
)
109 this->imv_id
= imv_id
;
111 DBG2(DBG_IMV
, "IMV %d handles %N workitem %d", imv_id
,
112 imv_workitem_type_names
, this->type
, this->id
);
115 METHOD(imv_workitem_t
, get_imv_id
, TNC_IMVID
,
116 private_imv_workitem_t
*this)
121 METHOD(imv_workitem_t
, get_type
, imv_workitem_type_t
,
122 private_imv_workitem_t
*this)
127 METHOD(imv_workitem_t
, get_arg_str
, char*,
128 private_imv_workitem_t
*this)
130 return this->arg_str
;
133 METHOD(imv_workitem_t
, get_arg_int
, int,
134 private_imv_workitem_t
*this)
136 return this->arg_int
;
139 METHOD(imv_workitem_t
, set_result
, TNC_IMV_Action_Recommendation
,
140 private_imv_workitem_t
*this, char *result
, TNC_IMV_Evaluation_Result eval
)
142 this->result
= strdup(result
);
145 case TNC_IMV_EVALUATION_RESULT_COMPLIANT
:
146 this->rec_final
= TNC_IMV_ACTION_RECOMMENDATION_ALLOW
;
148 case TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MINOR
:
149 case TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MAJOR
:
150 this->rec_final
= this->rec_fail
;
152 case TNC_IMV_EVALUATION_RESULT_ERROR
:
153 case TNC_IMV_EVALUATION_RESULT_DONT_KNOW
:
155 this->rec_final
= this->rec_noresult
;
158 DBG2(DBG_IMV
, "IMV %d handled %N workitem %d: %N%s%s", this->imv_id
,
159 imv_workitem_type_names
, this->type
, this->id
,
160 TNC_IMV_Action_Recommendation_names
, this->rec_final
,
161 strlen(result
) ? " - " : "", result
);
163 return this->rec_final
;
166 METHOD(imv_workitem_t
, get_result
, TNC_IMV_Action_Recommendation
,
167 private_imv_workitem_t
*this, char **result
)
171 *result
= this->result
;
173 return this->rec_final
;
176 METHOD(imv_workitem_t
, destroy
, void,
177 private_imv_workitem_t
*this)
187 imv_workitem_t
*imv_workitem_create(int id
, imv_workitem_type_t type
,
188 char *arg_str
, int arg_int
,
189 TNC_IMV_Action_Recommendation rec_fail
,
190 TNC_IMV_Action_Recommendation rec_noresult
)
192 private_imv_workitem_t
*this;
197 .set_imv_id
= _set_imv_id
,
198 .get_imv_id
= _get_imv_id
,
199 .get_type
= _get_type
,
200 .get_arg_str
= _get_arg_str
,
201 .get_arg_int
= _get_arg_int
,
202 .set_result
= _set_result
,
203 .get_result
= _get_result
,
207 .imv_id
= TNC_IMVID_ANY
,
209 .arg_str
= arg_str
? strdup(arg_str
) : NULL
,
211 .rec_fail
= rec_fail
,
212 .rec_noresult
= rec_noresult
,
213 .rec_final
= TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION
,
216 return &this->public;