1 /* $Id$
2  *
3  * Lasso - A free implementation of the Liberty Alliance specifications.
4  *
5  * Copyright (C) 2004-2007 Entr'ouvert
6  * http://lasso.entrouvert.org
7  *
8  * Authors: See AUTHORS file in top-level directory.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include "private.h"
25 #include "dst_modify_response.h"
26 #include "idwsf_strings.h"
27 
28 /**
29  * SECTION:dst_modify_response
30  * @short_description: &lt;dst:ModifyResponse&gt;
31  *
32  * <figure><title>Schema fragment for dst:ModifyResponse</title>
33  * <programlisting><![CDATA[
34  *
35  * <xs:element name="ModifyResponse" type="ResponseType"/>
36  * <xs:complexType name="ResponseType">
37  *     <xs:sequence>
38  *         <xs:element ref="Status"/>
39  *         <xs:element ref="Extension" minOccurs="0" maxOccurs="unbounded"/>
40  *     </xs:sequence>
41  *     <xs:attribute name="id" type="xs:ID"/>
42  *     <xs:attribute name="itemIDRef" type="IDReferenceType"/>
43  *     <xs:attribute name="timeStamp" type="xs:dateTime"/>
44  * </xs:complexType>
45  * ]]></programlisting>
46  * </figure>
47  */
48 
49 /*****************************************************************************/
50 /* private methods                                                           */
51 /*****************************************************************************/
52 
53 static struct XmlSnippet schema_snippets[] = {
54 	{ "Status", SNIPPET_NODE, G_STRUCT_OFFSET(LassoDstModifyResponse, Status), NULL, NULL, NULL},
55 	{ "Extension", SNIPPET_EXTENSION, G_STRUCT_OFFSET(LassoDstModifyResponse, Extension), NULL, NULL, NULL},
56 	{ "id", SNIPPET_ATTRIBUTE, G_STRUCT_OFFSET(LassoDstModifyResponse, id), NULL, NULL, NULL},
57 	{ "itemIDRef", SNIPPET_ATTRIBUTE, G_STRUCT_OFFSET(LassoDstModifyResponse, itemIDRef), NULL, NULL, NULL},
58 	{ "timeStamp", SNIPPET_ATTRIBUTE, G_STRUCT_OFFSET(LassoDstModifyResponse, timeStamp), NULL, NULL, NULL},
59 	{NULL, 0, 0, NULL, NULL, NULL}
60 };
61 
62 static LassoNodeClass *parent_class = NULL;
63 
64 static void
insure_namespace(xmlNode * xmlnode,xmlNs * ns)65 insure_namespace(xmlNode *xmlnode, xmlNs *ns)
66 {
67 	xmlNode *t = xmlnode->children;
68 
69 	xmlSetNs(xmlnode, ns);
70 	while (t) {
71 		if (t->type == XML_ELEMENT_NODE && t->ns == NULL)
72 			insure_namespace(t, ns);
73 		t = t->next;
74 	}
75 }
76 
77 static xmlNode*
get_xmlNode(LassoNode * node,gboolean lasso_dump)78 get_xmlNode(LassoNode *node, gboolean lasso_dump)
79 {
80 	xmlNode *xmlnode;
81 	xmlNs *ns;
82 
83 	xmlnode = parent_class->get_xmlNode(node, lasso_dump);
84 	ns = xmlNewNs(xmlnode, (xmlChar*)LASSO_DST_MODIFY_RESPONSE(node)->hrefServiceType,
85 			(xmlChar*)LASSO_DST_MODIFY_RESPONSE(node)->prefixServiceType);
86 	insure_namespace(xmlnode, ns);
87 
88 	return xmlnode;
89 }
90 
91 static int
init_from_xml(LassoNode * node,xmlNode * xmlnode)92 init_from_xml(LassoNode *node, xmlNode *xmlnode)
93 {
94 	int rc = 0;
95 	LassoDstModifyResponse *response = LASSO_DST_MODIFY_RESPONSE(node);
96 
97 	rc = parent_class->init_from_xml(node, xmlnode);
98 	if (rc) return rc;
99 
100 	response->hrefServiceType = g_strdup((char*)xmlnode->ns->href);
101 	response->prefixServiceType = lasso_get_prefix_for_dst_service_href(
102 			response->hrefServiceType);
103 	if (response->prefixServiceType == NULL) {
104 		/* XXX: what to do here ? */
105 	}
106 
107 	return 0;
108 }
109 
110 /*****************************************************************************/
111 /* instance and class init functions                                         */
112 /*****************************************************************************/
113 
114 
115 static void
class_init(LassoDstModifyResponseClass * klass,void * unused G_GNUC_UNUSED)116 class_init(LassoDstModifyResponseClass *klass, void *unused G_GNUC_UNUSED)
117 {
118 	LassoNodeClass *nclass = LASSO_NODE_CLASS(klass);
119 
120 	parent_class = g_type_class_peek_parent(klass);
121 	nclass->get_xmlNode = get_xmlNode;
122 	nclass->node_data = g_new0(LassoNodeClassData, 1);
123 	nclass->init_from_xml = init_from_xml;
124 	lasso_node_class_set_nodename(nclass, "ModifyResponse");
125 	lasso_node_class_add_snippets(nclass, schema_snippets);
126 }
127 
128 GType
lasso_dst_modify_response_get_type()129 lasso_dst_modify_response_get_type()
130 {
131 	static GType this_type = 0;
132 
133 	if (!this_type) {
134 		static const GTypeInfo this_info = {
135 			sizeof (LassoDstModifyResponseClass),
136 			NULL,
137 			NULL,
138 			(GClassInitFunc) class_init,
139 			NULL,
140 			NULL,
141 			sizeof(LassoDstModifyResponse),
142 			0,
143 			NULL,
144 			NULL
145 		};
146 
147 		this_type = g_type_register_static(LASSO_TYPE_NODE,
148 				"LassoDstModifyResponse", &this_info, 0);
149 	}
150 	return this_type;
151 }
152 
153 LassoDstModifyResponse*
lasso_dst_modify_response_new(LassoUtilityStatus * status)154 lasso_dst_modify_response_new(LassoUtilityStatus *status)
155 {
156 	LassoDstModifyResponse *modify_response;
157 
158 	g_return_val_if_fail(LASSO_IS_UTILITY_STATUS(status) == TRUE, NULL);
159 
160 	modify_response = g_object_new(LASSO_TYPE_DST_MODIFY_RESPONSE, NULL);
161 
162 	modify_response->Status = status;
163 
164 	return modify_response;
165 }
166 
167