corrected naming of tnccs_reason_strings_msg_t object
[strongswan.git] / src / libcharon / plugins / tnccs_11 / messages / tnccs_reason_strings_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_reason_strings_msg.h"
17
18 #include <debug.h>
19
20 typedef struct private_tnccs_reason_strings_msg_t private_tnccs_reason_strings_msg_t;
21
22 /**
23 * Private data of a tnccs_reason_strings_msg_t object.
24 *
25 */
26 struct private_tnccs_reason_strings_msg_t {
27 /**
28 * Public tnccs_reason_strings_msg_t interface.
29 */
30 tnccs_reason_strings_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 * Reason Language
44 */
45 char* language;
46
47 /**
48 * Reason String
49 */
50 char* reason;
51 };
52
53 METHOD(tnccs_msg_t, get_type, tnccs_msg_type_t,
54 private_tnccs_reason_strings_msg_t *this)
55 {
56 return this->type;
57 }
58
59 METHOD(tnccs_msg_t, get_node, xmlNodePtr,
60 private_tnccs_reason_strings_msg_t *this)
61 {
62 return this->node;
63 }
64
65 METHOD(tnccs_msg_t, destroy, void,
66 private_tnccs_reason_strings_msg_t *this)
67 {
68 free(this->language);
69 free(this->reason);
70 free(this);
71 }
72
73 METHOD(tnccs_reason_strings_msg_t, get_reason, char*,
74 private_tnccs_reason_strings_msg_t *this, char **language)
75 {
76 *language = this->language;
77
78 return this->reason;
79 }
80
81 /**
82 * See header
83 */
84 tnccs_msg_t *tnccs_reason_strings_msg_create_from_node(xmlNodePtr node)
85 {
86 private_tnccs_reason_strings_msg_t *this;
87
88 INIT(this,
89 .public = {
90 .tnccs_msg_interface = {
91 .get_type = _get_type,
92 .get_node = _get_node,
93 .destroy = _destroy,
94 },
95 .get_reason = _get_reason,
96 },
97 .type = TNCCS_MSG_REASON_STRINGS,
98 .node = node,
99 );
100
101 return &this->public.tnccs_msg_interface;
102 }
103
104 /**
105 * See header
106 */
107 tnccs_msg_t *tnccs_reason_strings_msg_create(char *language, char *reason)
108 {
109 private_tnccs_reason_strings_msg_t *this;
110 xmlNodePtr n, n2, n3;
111
112 INIT(this,
113 .public = {
114 .tnccs_msg_interface = {
115 .get_type = _get_type,
116 .get_node = _get_node,
117 .destroy = _destroy,
118 },
119 .get_reason = _get_reason,
120 },
121 .type = TNCCS_MSG_REASON_STRINGS,
122 .node = xmlNewNode(NULL, BAD_CAST "TNCC-TNCS-Message"),
123 .language = strdup(language),
124 .reason = strdup(reason),
125 );
126
127 /* add the message type number in hex */
128 n = xmlNewNode(NULL, BAD_CAST "Type");
129 xmlNodeSetContent(n, BAD_CAST "00000004");
130 xmlAddChild(this->node, n);
131
132 n = xmlNewNode(NULL, BAD_CAST "XML");
133 xmlAddChild(this->node, n);
134
135 n2 = xmlNewNode(NULL, BAD_CAST enum_to_name(tnccs_msg_type_names, this->type));
136 xmlNodeSetContent(n2, BAD_CAST language);
137 xmlAddChild(n, n2);
138
139 /* could add multiple reasons here, if we had them */
140 n3 = xmlNewNode(NULL, BAD_CAST "ReasonString");
141 xmlNewProp(n3, BAD_CAST "xml:lang", BAD_CAST language);
142 xmlNodeSetContent(n3, BAD_CAST reason);
143 xmlAddChild(n2, n3);
144
145 return &this->public.tnccs_msg_interface;
146 }