implemented TNCCS 1.1 without libtnc
[strongswan.git] / src / libcharon / plugins / tnccs_11 / messages / tnccs_preferred_language_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_preferred_language_msg.h"
17
18 #include <debug.h>
19
20 typedef struct private_tnccs_preferred_language_msg_t private_tnccs_preferred_language_msg_t;
21
22 /**
23 * Private data of a tnccs_preferred_language_msg_t object.
24 *
25 */
26 struct private_tnccs_preferred_language_msg_t {
27 /**
28 * Public tnccs_preferred_language_msg_t interface.
29 */
30 tnccs_preferred_language_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 * Preferred language
44 */
45 char *preferred_language;
46 };
47
48 METHOD(tnccs_msg_t, get_type, tnccs_msg_type_t,
49 private_tnccs_preferred_language_msg_t *this)
50 {
51 return this->type;
52 }
53
54 METHOD(tnccs_msg_t, get_node, xmlNodePtr,
55 private_tnccs_preferred_language_msg_t *this)
56 {
57 return this->node;
58 }
59
60 METHOD(tnccs_msg_t, destroy, void,
61 private_tnccs_preferred_language_msg_t *this)
62 {
63 free(this->preferred_language);
64 free(this);
65 }
66
67 METHOD(tnccs_preferred_language_msg_t, get_preferred_language, char*,
68 private_tnccs_preferred_language_msg_t *this)
69 {
70 return this->preferred_language;
71 }
72
73 /**
74 * See header
75 */
76 tnccs_msg_t *tnccs_preferred_language_msg_create_from_node(xmlNodePtr node)
77 {
78 private_tnccs_preferred_language_msg_t *this;
79
80 INIT(this,
81 .public = {
82 .tnccs_msg_interface = {
83 .get_type = _get_type,
84 .get_node = _get_node,
85 .destroy = _destroy,
86 },
87 .get_preferred_language = _get_preferred_language,
88 },
89 .type = TNCCS_MSG_PREFERRED_LANGUAGE,
90 .node = node,
91 );
92
93 return &this->public.tnccs_msg_interface;
94 }
95
96 /**
97 * See header
98 */
99 tnccs_msg_t *tnccs_preferred_language_msg_create(char *language)
100 {
101 private_tnccs_preferred_language_msg_t *this;
102 xmlNodePtr n, n2;
103
104 INIT(this,
105 .public = {
106 .tnccs_msg_interface = {
107 .get_type = _get_type,
108 .get_node = _get_node,
109 .destroy = _destroy,
110 },
111 .get_preferred_language = _get_preferred_language,
112 },
113 .type = TNCCS_MSG_PREFERRED_LANGUAGE,
114 .node = xmlNewNode(NULL, BAD_CAST "TNCC-TNCS-Message"),
115 .preferred_language = strdup(language),
116 );
117
118 /* add the message type number in hex */
119 n = xmlNewNode(NULL, BAD_CAST "Type");
120 xmlNodeSetContent(n, BAD_CAST "00000003");
121 xmlAddChild(this->node, n);
122
123 n = xmlNewNode(NULL, BAD_CAST "XML");
124 xmlAddChild(this->node, n);
125
126 n2 = xmlNewNode(NULL, BAD_CAST enum_to_name(tnccs_msg_type_names, this->type));
127 xmlNodeSetContent(n2, BAD_CAST language);
128 xmlAddChild(n, n2);
129
130 return &this->public.tnccs_msg_interface;
131 }