summaryrefslogtreecommitdiffstats
path: root/lasso/xml/sa_sasl_response.c
blob: 3b7cd04f545f75fc77d33a69b4236c26e1963755 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/* $Id$
 *
 * Lasso - A free implementation of the Liberty Alliance specifications.
 *
 * Copyright (C) 2004-2007 Entr'ouvert
 * http://lasso.entrouvert.org
 *
 * Authors: See AUTHORS file in top-level directory.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "private.h"
#include <lasso/xml/sa_sasl_response.h>

/**
 * SECTION:sa_sasl_response
 * @short_description: &lt;sa:SASLResponse&gt;
 *
 * <figure><title>Schema fragment for sa:SASLResponse</title>
 * <programlisting><![CDATA[
 *
 * <xs:element name="SASLResponse">
 * <xs:complexType>
 *   <xs:sequence>
 *     <xs:element ref="Status"/>
 *     <xs:element ref="PasswordTransforms" minOccurs="0"/>
 *     <xs:element name="Data" minOccurs="0">
 *     <xs:complexType>
 *       <xs:simpleContent>
 *         <xs:extension base="xs:base64Binary"/>
 *       </xs:simpleContent>
 *     </xs:complexType>
 *     </xs:element>
 *     <xs:element ref="disco:ResourceOffering" minOccurs="0" maxOccurs="unbounded"/>
 *     <xs:element name="Credentials" minOccurs="0">
 *     <xs:complexType>
 *       <xs:sequence>
 *         <xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
 *       </xs:sequence>
 *     </xs:complexType>
 *     </xs:element>
 *   </xs:sequence>
 *   <xs:attribute name="serverMechanism" type="xs:string" ="optional"/>
 *   <xs:attribute name="id" type="xs:ID" use="optional"/>
 * </xs:complexType>
 * </xs:element>
 *
 * ]]></programlisting>
 * </figure>
 */

/*****************************************************************************/
/* private methods                                                           */
/*****************************************************************************/

static struct XmlSnippet schema_snippets[] = {
	{ "Status", SNIPPET_NODE, G_STRUCT_OFFSET(LassoSaSASLResponse, Status), NULL, NULL, NULL},
	{ "PasswordTransforms", SNIPPET_LIST_NODES,
		G_STRUCT_OFFSET(LassoSaSASLResponse, PasswordTransforms), NULL, NULL, NULL},
	{ "Data", SNIPPET_LIST_CONTENT,
		G_STRUCT_OFFSET(LassoSaSASLResponse, Data), NULL, NULL, NULL},
	{ "ResourceOffering", SNIPPET_LIST_NODES,
		G_STRUCT_OFFSET(LassoSaSASLResponse, ResourceOffering), NULL, NULL, NULL},
	{ "Credentials", SNIPPET_LIST_NODES, G_STRUCT_OFFSET(LassoSaSASLResponse, Credentials), NULL, NULL, NULL},
	{ "serverMechanism", SNIPPET_ATTRIBUTE,
		G_STRUCT_OFFSET(LassoSaSASLResponse, serverMechanism), NULL, NULL, NULL},
	{ "id", SNIPPET_ATTRIBUTE,
		G_STRUCT_OFFSET(LassoSaSASLResponse, id), NULL, NULL, NULL},
	{NULL, 0, 0, NULL, NULL, NULL}
};

static LassoNodeClass *parent_class = NULL;

static void
insure_namespace(xmlNode *xmlnode, xmlNs *ns)
{
	xmlNode *t = xmlnode->children;

	xmlSetNs(xmlnode, ns);
	while (t) {
		if (t->type == XML_ELEMENT_NODE && t->ns == NULL)
			insure_namespace(t, ns);
		t = t->next;
	}
}

static xmlNode*
get_xmlNode(LassoNode *node, gboolean lasso_dump)
{
	xmlNode *xmlnode;
	xmlNs *ns;

	xmlnode = parent_class->get_xmlNode(node, lasso_dump);
	ns = xmlNewNs(xmlnode, (xmlChar*)LASSO_SA_HREF, (xmlChar*)LASSO_SA_PREFIX);
	insure_namespace(xmlnode, ns);

	return xmlnode;
}

/*****************************************************************************/
/* instance and class init functions                                         */
/*****************************************************************************/

static void
instance_init(LassoSaSASLResponse *node)
{
	node->Status = NULL;
	node->PasswordTransforms = NULL;
	node->Data = NULL;
	node->ResourceOffering = NULL;
	node->Credentials = NULL;
	node->any = NULL;
	node->serverMechanism = NULL;
	node->id = NULL;
}

static void
class_init(LassoSaSASLResponseClass *klass)
{
	LassoNodeClass *nodeClass = LASSO_NODE_CLASS(klass);

	parent_class = g_type_class_peek_parent(klass);
	nodeClass->get_xmlNode = get_xmlNode;
	nodeClass->node_data = g_new0(LassoNodeClassData, 1);
	lasso_node_class_set_nodename(nodeClass, "SASLResponse");
	lasso_node_class_add_snippets(nodeClass, schema_snippets);
}

GType
lasso_sa_sasl_response_get_type()
{
	static GType this_type = 0;

	if (!this_type) {
		static const GTypeInfo this_info = {
			sizeof (LassoSaSASLResponseClass),
			NULL,
			NULL,
			(GClassInitFunc) class_init,
			NULL,
			NULL,
			sizeof(LassoSaSASLResponse),
			0,
			(GInstanceInitFunc) instance_init,
			NULL
		};

		this_type = g_type_register_static(LASSO_TYPE_NODE,
				"LassoSaSASLResponse", &this_info, 0);
	}
	return this_type;
}

LassoSaSASLResponse*
lasso_sa_sasl_response_new(LassoUtilityStatus *status)
{
	LassoSaSASLResponse *node;

	node = g_object_new(LASSO_TYPE_SA_SASL_RESPONSE, NULL);

	g_object_ref(status);
	node->Status = status;

	return node;
}

LassoSaSASLResponse*
lasso_sa_sasl_response_new_from_message(const gchar *message)
{
	LassoSaSASLResponse *node;

	g_return_val_if_fail(message != NULL, NULL);

	node = g_object_new(LASSO_TYPE_SA_SASL_RESPONSE, NULL);
	lasso_node_init_from_message(LASSO_NODE(node), message);

	return node;
}

gint
lasso_sa_sasl_response_add_credentials(LassoSaSASLResponse *response,
		LassoSaCredentials *credentials)
{
	g_return_val_if_fail(LASSO_IS_SA_SASL_RESPONSE(response),
			LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ);
	g_return_val_if_fail(LASSO_IS_SA_CREDENTIALS(credentials),
			LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ);

	g_object_ref(credentials);
	response->Credentials = g_list_append(response->Credentials, credentials);

	return 0;
}

gint
lasso_sa_sasl_response_add_resource_offering(LassoSaSASLResponse *response,
		LassoDiscoResourceOffering *resourceOffering)
{
	g_return_val_if_fail(LASSO_IS_SA_SASL_RESPONSE(response),
			LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ);
	g_return_val_if_fail(LASSO_IS_DISCO_RESOURCE_OFFERING(resourceOffering),
			LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ);

	g_object_ref(resourceOffering);
	response->ResourceOffering = g_list_append(response->ResourceOffering, resourceOffering);

	return 0;
}