2 * Copyright (C) 2010 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include <utils/linked_list.h>
17 #include <threading/mutex.h>
18 #include <tnc/tncifimv_names.h>
19 #include <tnc/imv/imv_recommendations.h>
21 typedef struct private_tnc_imv_recommendations_t private_tnc_imv_recommendations_t
;
22 typedef struct recommendation_entry_t recommendation_entry_t
;
25 * Recommendation entry
27 struct recommendation_entry_t
{
35 * Action Recommendation provided by IMV instance
37 TNC_IMV_Action_Recommendation rec
;
40 * Evaluation Result provided by IMV instance
42 TNC_IMV_Evaluation_Result eval
;
46 * Private data of a recommendations_t object.
48 struct private_tnc_imv_recommendations_t
{
51 * Public members of recommendations_t.
53 recommendations_t
public;
56 * list of recommendations and evaluations provided by IMVs
61 METHOD(recommendations_t
, provide_recommendation
, TNC_Result
,
62 private_tnc_imv_recommendations_t
* this, TNC_IMVID id
,
63 TNC_IMV_Action_Recommendation rec
,
64 TNC_IMV_Evaluation_Result eval
)
66 enumerator_t
*enumerator
;
67 recommendation_entry_t
*entry
;
70 DBG2(DBG_TNC
, "IMV %u provides recommendation '%N' and evaluation '%N'",
71 id
, action_recommendation_names
, rec
, evaluation_result_names
, eval
);
73 enumerator
= this->recs
->create_enumerator(this->recs
);
74 while (enumerator
->enumerate(enumerator
, &entry
))
84 enumerator
->destroy(enumerator
);
85 return found ? TNC_RESULT_SUCCESS
: TNC_RESULT_FATAL
;
88 METHOD(recommendations_t
, have_recommendation
, bool,
89 private_tnc_imv_recommendations_t
*this, TNC_IMV_Action_Recommendation
*rec
,
90 TNC_IMV_Evaluation_Result
*eval
)
93 *rec
= TNC_IMV_ACTION_RECOMMENDATION_ALLOW
;
94 *eval
= TNC_IMV_EVALUATION_RESULT_COMPLIANT
;
98 METHOD(recommendations_t
, destroy
, void,
99 private_tnc_imv_recommendations_t
*this)
101 this->recs
->destroy_function(this->recs
, free
);
106 * Described in header.
108 recommendations_t
* tnc_imv_recommendations_create(linked_list_t
*imv_list
)
110 private_tnc_imv_recommendations_t
*this;
111 recommendation_entry_t
*entry
;
112 enumerator_t
*enumerator
;
117 .provide_recommendation
= _provide_recommendation
,
118 .have_recommendation
= _have_recommendation
,
121 .recs
= linked_list_create(),
124 enumerator
= imv_list
->create_enumerator(imv_list
);
125 while (enumerator
->enumerate(enumerator
, &id
))
127 entry
= malloc_thing(recommendation_entry_t
);
129 entry
->rec
= TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION
;
130 entry
->eval
= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
;
131 this->recs
->insert_last(this->recs
, entry
);
133 enumerator
->destroy(enumerator
);
135 return &this->public;