created process() method for TNCCS messages
[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, process, status_t,
61 private_tnccs_preferred_language_msg_t *this)
62 {
63 return SUCCESS;
64 }
65
66 METHOD(tnccs_msg_t, destroy, void,
67 private_tnccs_preferred_language_msg_t *this)
68 {
69 free(this->preferred_language);
70 free(this);
71 }
72
73 METHOD(tnccs_preferred_language_msg_t, get_preferred_language, char*,
74 private_tnccs_preferred_language_msg_t *this)
75 {
76 return this->preferred_language;
77 }
78
79 /**
80 * See header
81 */
82 tnccs_msg_t *tnccs_preferred_language_msg_create_from_node(xmlNodePtr node)
83 {
84 private_tnccs_preferred_language_msg_t *this;
85
86 INIT(this,
87 .public = {
88 .tnccs_msg_interface = {
89 .get_type = _get_type,
90 .get_node = _get_node,
91 .process = _process,
92 .destroy = _destroy,
93 },
94 .get_preferred_language = _get_preferred_language,
95 },
96 .type = TNCCS_MSG_PREFERRED_LANGUAGE,
97 .node = node,
98 );
99
100 return &this->public.tnccs_msg_interface;
101 }
102
103 /**
104 * See header
105 */
106 tnccs_msg_t *tnccs_preferred_language_msg_create(char *language)
107 {
108 private_tnccs_preferred_language_msg_t *this;
109 xmlNodePtr n, n2;
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_preferred_language = _get_preferred_language,
120 },
121 .type = TNCCS_MSG_PREFERRED_LANGUAGE,
122 .node = xmlNewNode(NULL, BAD_CAST "TNCC-TNCS-Message"),
123 .preferred_language = strdup(language),
124 );
125
126 /* add the message type number in hex */
127 n = xmlNewNode(NULL, BAD_CAST "Type");
128 xmlNodeSetContent(n, BAD_CAST "00000003");
129 xmlAddChild(this->node, n);
130
131 n = xmlNewNode(NULL, BAD_CAST "XML");
132 xmlAddChild(this->node, n);
133
134 n2 = xmlNewNode(NULL, BAD_CAST enum_to_name(tnccs_msg_type_names, this->type));
135 xmlNodeSetContent(n2, BAD_CAST language);
136 xmlAddChild(n, n2);
137
138 return &this->public.tnccs_msg_interface;
139 }