Implemented SWID Tag Inventory attribute
[strongswan.git] / src / libimcv / imv / imv_workitem.c
1 /*
2 * Copyright (C) 2013 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
4 *
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>.
9 *
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
13 * for more details.
14 */
15
16 #include "imv_workitem.h"
17
18 #include <utils/debug.h>
19 #include <tncif_names.h>
20
21 typedef struct private_imv_workitem_t private_imv_workitem_t;
22
23 ENUM(imv_workitem_type_names, IMV_WORKITEM_PACKAGES, IMV_WORKITEM_SWID_TAGS,
24 "PCKGS",
25 "UNSRC",
26 "FWDEN",
27 "PWDEN",
28 "FREFM",
29 "FMEAS",
30 "FMETA",
31 "DREFM",
32 "DMEAS",
33 "DMETA",
34 "TCPOP",
35 "TCPBL",
36 "UDPOP",
37 "UDPBL",
38 "SWIDT"
39 );
40
41 /**
42 * Private data of a imv_workitem_t object.
43 *
44 */
45 struct private_imv_workitem_t {
46
47 /**
48 * Public imv_workitem_t interface.
49 */
50 imv_workitem_t public;
51
52 /**
53 * Primary workitem key
54 */
55 int id;
56
57 /**
58 * IMV ID
59 */
60 TNC_IMVID imv_id;
61
62 /**
63 * Workitem type
64 */
65 imv_workitem_type_t type;
66
67 /**
68 * Argument string
69 */
70 char *arg_str;
71
72 /**
73 * Argument integer
74 */
75 int arg_int;
76
77 /**
78 * Result string
79 */
80 char *result;
81
82 /**
83 * IMV action recommendation
84 */
85 TNC_IMV_Action_Recommendation rec_fail;
86
87 /**
88 * IMV action recommendation
89 */
90 TNC_IMV_Action_Recommendation rec_noresult;
91
92 /**
93 * IMV action recommendation
94 */
95 TNC_IMV_Action_Recommendation rec_final;
96
97 };
98
99 METHOD(imv_workitem_t, get_id, int,
100 private_imv_workitem_t *this)
101 {
102 return this->id;
103 }
104
105 METHOD(imv_workitem_t, set_imv_id, void,
106 private_imv_workitem_t *this, TNC_IMVID imv_id)
107 {
108 this->imv_id = imv_id;
109 }
110
111 METHOD(imv_workitem_t, get_imv_id, TNC_IMVID,
112 private_imv_workitem_t *this)
113 {
114 return this->imv_id;
115 }
116
117 METHOD(imv_workitem_t, get_type, imv_workitem_type_t,
118 private_imv_workitem_t *this)
119 {
120 return this->type;
121 }
122
123 METHOD(imv_workitem_t, get_arg_str, char*,
124 private_imv_workitem_t *this)
125 {
126 return this->arg_str;
127 }
128
129 METHOD(imv_workitem_t, get_arg_int, int,
130 private_imv_workitem_t *this)
131 {
132 return this->arg_int;
133 }
134
135 METHOD(imv_workitem_t, set_result, TNC_IMV_Action_Recommendation,
136 private_imv_workitem_t *this, char *result, TNC_IMV_Evaluation_Result eval)
137 {
138 this->result = strdup(result);
139 switch (eval)
140 {
141 case TNC_IMV_EVALUATION_RESULT_COMPLIANT:
142 this->rec_final = TNC_IMV_ACTION_RECOMMENDATION_ALLOW;
143 break;
144 case TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MINOR:
145 case TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MAJOR:
146 this->rec_final = this->rec_fail;
147 break;
148 case TNC_IMV_EVALUATION_RESULT_ERROR:
149 case TNC_IMV_EVALUATION_RESULT_DONT_KNOW:
150 default:
151 this->rec_final = this->rec_noresult;
152 break;
153 }
154 DBG2(DBG_IMV, "IMV %d handled %N workitem %d: %N%s%s", this->imv_id,
155 imv_workitem_type_names, this->type, this->id,
156 TNC_IMV_Action_Recommendation_names, this->rec_final,
157 strlen(result) ? " - " : "", result);
158
159 return this->rec_final;
160 }
161
162 METHOD(imv_workitem_t, get_result, TNC_IMV_Action_Recommendation,
163 private_imv_workitem_t *this, char **result)
164 {
165 if (result)
166 {
167 *result = this->result;
168 }
169 return this->rec_final;
170 }
171
172 METHOD(imv_workitem_t, destroy, void,
173 private_imv_workitem_t *this)
174 {
175 free(this->arg_str);
176 free(this->result);
177 free(this);
178 }
179
180 /**
181 * See header
182 */
183 imv_workitem_t *imv_workitem_create(int id, imv_workitem_type_t type,
184 char *arg_str, int arg_int,
185 TNC_IMV_Action_Recommendation rec_fail,
186 TNC_IMV_Action_Recommendation rec_noresult)
187 {
188 private_imv_workitem_t *this;
189
190 INIT(this,
191 .public = {
192 .get_id = _get_id,
193 .set_imv_id = _set_imv_id,
194 .get_imv_id = _get_imv_id,
195 .get_type = _get_type,
196 .get_arg_str = _get_arg_str,
197 .get_arg_int = _get_arg_int,
198 .set_result = _set_result,
199 .get_result = _get_result,
200 .destroy = _destroy,
201 },
202 .id = id,
203 .imv_id = TNC_IMVID_ANY,
204 .type = type,
205 .arg_str = arg_str ? strdup(arg_str) : NULL,
206 .arg_int = arg_int,
207 .rec_fail = rec_fail,
208 .rec_noresult = rec_noresult,
209 .rec_final = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
210 );
211
212 return &this->public;
213 }
214