62874b0ba542e31208a15250ccea382f7bdb3975
[strongswan.git] / src / libcharon / plugins / tnccs_11 / messages / tnccs_recommendation_msg.c
1 /*
2 * Copyright (C) 2006 Mike McCauley (mikem@open.com.au)
3 * Copyright (C) 2010 Andreas Steffen, 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 "tnccs_recommendation_msg.h"
17
18 #include <debug.h>
19
20 typedef struct private_tnccs_recommendation_msg_t private_tnccs_recommendation_msg_t;
21
22 /**
23 * Private data of a tnccs_recommendation_msg_t object.
24 *
25 */
26 struct private_tnccs_recommendation_msg_t {
27 /**
28 * Public tnccs_recommendation_msg_t interface.
29 */
30 tnccs_recommendation_msg_t public;
31
32 /**
33 * TNCCS message type
34 */
35 tnccs_msg_type_t type;
36
37 /**
38 * XML-encoded message node
39 */
40 xmlNodePtr node;
41
42 /**
43 * Action Recommendation
44 */
45 TNC_IMV_Action_Recommendation rec;
46 };
47
48 METHOD(tnccs_msg_t, get_type, tnccs_msg_type_t,
49 private_tnccs_recommendation_msg_t *this)
50 {
51 return this->type;
52 }
53
54 METHOD(tnccs_msg_t, get_node, xmlNodePtr,
55 private_tnccs_recommendation_msg_t *this)
56 {
57 return this->node;
58 }
59
60 METHOD(tnccs_msg_t, process, status_t,
61 private_tnccs_recommendation_msg_t *this)
62 {
63 return SUCCESS;
64 }
65
66 METHOD(tnccs_msg_t, destroy, void,
67 private_tnccs_recommendation_msg_t *this)
68 {
69 free(this);
70 }
71
72 METHOD(tnccs_recommendation_msg_t, get_recommendation, TNC_IMV_Action_Recommendation,
73 private_tnccs_recommendation_msg_t *this)
74 {
75 return this->rec;
76 }
77
78 /**
79 * See header
80 */
81 tnccs_msg_t *tnccs_recommendation_msg_create_from_node(xmlNodePtr node)
82 {
83 private_tnccs_recommendation_msg_t *this;
84
85 INIT(this,
86 .public = {
87 .tnccs_msg_interface = {
88 .get_type = _get_type,
89 .get_node = _get_node,
90 .process = _process,
91 .destroy = _destroy,
92 },
93 .get_recommendation = _get_recommendation,
94 },
95 .type = TNCCS_MSG_RECOMMENDATION,
96 .node = node,
97 );
98
99 return &this->public.tnccs_msg_interface;
100 }
101
102 /**
103 * See header
104 */
105 tnccs_msg_t *tnccs_recommendation_msg_create(TNC_IMV_Action_Recommendation rec)
106 {
107 private_tnccs_recommendation_msg_t *this;
108 xmlNodePtr n, n2;
109 char *recommendation_string;
110
111 INIT(this,
112 .public = {
113 .tnccs_msg_interface = {
114 .get_type = _get_type,
115 .get_node = _get_node,
116 .process = _process,
117 .destroy = _destroy,
118 },
119 .get_recommendation = _get_recommendation,
120 },
121 .type = TNCCS_MSG_RECOMMENDATION,
122 .node = xmlNewNode(NULL, BAD_CAST "TNCC-TNCS-Message"),
123 .rec = rec,
124 );
125
126 /* add the message type number in hex */
127 n = xmlNewNode(NULL, BAD_CAST "Type");
128 xmlNodeSetContent(n, BAD_CAST "00000001");
129 xmlAddChild(this->node, n);
130
131 n = xmlNewNode(NULL, BAD_CAST "XML");
132 xmlAddChild(this->node, n);
133
134 switch (rec)
135 {
136 case TNC_IMV_ACTION_RECOMMENDATION_ALLOW:
137 recommendation_string = "allow";
138 break;
139 case TNC_IMV_ACTION_RECOMMENDATION_ISOLATE:
140 recommendation_string = "isolate";
141 break;
142 case TNC_IMV_ACTION_RECOMMENDATION_NO_ACCESS:
143 case TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION:
144 default:
145 recommendation_string = "none";
146 }
147
148 n2 = xmlNewNode(NULL, BAD_CAST enum_to_name(tnccs_msg_type_names, this->type));
149 xmlNodeSetContent(n2, BAD_CAST recommendation_string);
150 xmlAddChild(n, n2);
151
152 return &this->public.tnccs_msg_interface;
153 }