2 * Copyright (C) 2006 Mike McCauley (mikem@open.com.au)
3 * Copyright (C) 2010 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
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>.
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
16 #include "tnccs_reason_strings_msg.h"
20 typedef struct private_tnccs_reason_strings_msg_t private_tnccs_reason_strings_msg_t
;
23 * Private data of a tnccs_reason_strings_msg_t object.
26 struct private_tnccs_reason_strings_msg_t
{
28 * Public tnccs_reason_strings_msg_t interface.
30 tnccs_reason_strings_msg_t
public;
35 tnccs_msg_type_t type
;
38 * XML-encoded message node
53 METHOD(tnccs_msg_t
, get_type
, tnccs_msg_type_t
,
54 private_tnccs_reason_strings_msg_t
*this)
59 METHOD(tnccs_msg_t
, get_node
, xmlNodePtr
,
60 private_tnccs_reason_strings_msg_t
*this)
65 METHOD(tnccs_msg_t
, destroy
, void,
66 private_tnccs_reason_strings_msg_t
*this)
68 free(this->reason
.ptr
);
69 free(this->language
.ptr
);
73 METHOD(tnccs_reason_strings_msg_t
, get_reason
, chunk_t
,
74 private_tnccs_reason_strings_msg_t
*this, chunk_t
*language
)
76 *language
= this->language
;
84 tnccs_msg_t
*tnccs_reason_strings_msg_create_from_node(xmlNodePtr node
,
85 linked_list_t
*errors
)
87 private_tnccs_reason_strings_msg_t
*this;
91 .tnccs_msg_interface
= {
92 .get_type
= _get_type
,
93 .get_node
= _get_node
,
96 .get_reason
= _get_reason
,
98 .type
= TNCCS_MSG_REASON_STRINGS
,
102 return &this->public.tnccs_msg_interface
;
108 tnccs_msg_t
*tnccs_reason_strings_msg_create(chunk_t reason
, chunk_t language
)
110 private_tnccs_reason_strings_msg_t
*this;
111 xmlNodePtr n
, n2
, n3
;
115 .tnccs_msg_interface
= {
116 .get_type
= _get_type
,
117 .get_node
= _get_node
,
120 .get_reason
= _get_reason
,
122 .type
= TNCCS_MSG_REASON_STRINGS
,
123 .node
= xmlNewNode(NULL
, BAD_CAST
"TNCC-TNCS-Message"),
124 .reason
= chunk_create_clone(malloc(reason
.len
+ 1), reason
),
125 .language
= chunk_create_clone(malloc(language
.len
+ 1), language
),
128 /* add NULL termination for XML string representation */
129 this->reason
.ptr
[this->reason
.len
] = '\0';
130 this->language
.ptr
[this->language
.len
] = '\0';
132 /* add the message type number in hex */
133 n
= xmlNewNode(NULL
, BAD_CAST
"Type");
134 xmlNodeSetContent(n
, BAD_CAST
"00000004");
135 xmlAddChild(this->node
, n
);
137 n
= xmlNewNode(NULL
, BAD_CAST
"XML");
138 xmlAddChild(this->node
, n
);
140 n2
= xmlNewNode(NULL
, BAD_CAST
enum_to_name(tnccs_msg_type_names
, this->type
));
142 /* could add multiple reasons here, if we had them */
143 n3
= xmlNewNode(NULL
, BAD_CAST
"ReasonString");
144 xmlNewProp(n3
, BAD_CAST
"xml:lang", BAD_CAST
this->language
.ptr
);
145 xmlNodeSetContent(n3
, BAD_CAST
this->reason
.ptr
);
148 return &this->public.tnccs_msg_interface
;