moved recommendation handling to the tnc_imv plugin
[strongswan.git] / src / libcharon / plugins / tnc_imv / tnc_imv_recommendations.c
1 /*
2 * Copyright (C) 2010 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
3 *
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>.
8 *
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
12 * for more details.
13 */
14
15 #include <debug.h>
16 #include <utils/linked_list.h>
17 #include <threading/mutex.h>
18 #include <tnc/tncifimv_names.h>
19 #include <tnc/imv/imv_recommendations.h>
20
21 typedef struct private_tnc_imv_recommendations_t private_tnc_imv_recommendations_t;
22 typedef struct recommendation_entry_t recommendation_entry_t;
23
24 /**
25 * Recommendation entry
26 */
27 struct recommendation_entry_t {
28
29 /**
30 * IMV ID
31 */
32 TNC_IMVID id;
33
34 /**
35 * Action Recommendation provided by IMV instance
36 */
37 TNC_IMV_Action_Recommendation rec;
38
39 /**
40 * Evaluation Result provided by IMV instance
41 */
42 TNC_IMV_Evaluation_Result eval;
43 };
44
45 /**
46 * Private data of a recommendations_t object.
47 */
48 struct private_tnc_imv_recommendations_t {
49
50 /**
51 * Public members of recommendations_t.
52 */
53 recommendations_t public;
54
55 /**
56 * list of recommendations and evaluations provided by IMVs
57 */
58 linked_list_t *recs;
59 };
60
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)
65 {
66 enumerator_t *enumerator;
67 recommendation_entry_t *entry;
68 bool found = FALSE;
69
70 DBG2(DBG_TNC, "IMV %u provides recommendation '%N' and evaluation '%N'",
71 id, action_recommendation_names, rec, evaluation_result_names, eval);
72
73 enumerator = this->recs->create_enumerator(this->recs);
74 while (enumerator->enumerate(enumerator, &entry))
75 {
76 if (entry->id == id)
77 {
78 found = TRUE;
79 entry->rec = rec;
80 entry->eval = eval;
81 break;
82 }
83 }
84 enumerator->destroy(enumerator);
85 return found ? TNC_RESULT_SUCCESS : TNC_RESULT_FATAL;
86 }
87
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)
91 {
92 /* TODO */
93 *rec = TNC_IMV_ACTION_RECOMMENDATION_ALLOW;
94 *eval = TNC_IMV_EVALUATION_RESULT_COMPLIANT;
95 return TRUE;
96 }
97
98 METHOD(recommendations_t, destroy, void,
99 private_tnc_imv_recommendations_t *this)
100 {
101 this->recs->destroy_function(this->recs, free);
102 free(this);
103 }
104
105 /**
106 * Described in header.
107 */
108 recommendations_t* tnc_imv_recommendations_create(linked_list_t *imv_list)
109 {
110 private_tnc_imv_recommendations_t *this;
111 recommendation_entry_t *entry;
112 enumerator_t *enumerator;
113 TNC_IMVID id;
114
115 INIT(this,
116 .public = {
117 .provide_recommendation = _provide_recommendation,
118 .have_recommendation = _have_recommendation,
119 .destroy = _destroy,
120 },
121 .recs = linked_list_create(),
122 );
123
124 enumerator = imv_list->create_enumerator(imv_list);
125 while (enumerator->enumerate(enumerator, &id))
126 {
127 entry = malloc_thing(recommendation_entry_t);
128 entry->id = id;
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);
132 }
133 enumerator->destroy(enumerator);
134
135 return &this->public;
136 }