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