2008-09-12 17:06:58 +02:00
|
|
|
/* $Id$
|
2004-11-30 12:23:26 +01:00
|
|
|
*
|
|
|
|
* Lasso - A free implementation of the Liberty Alliance specifications.
|
|
|
|
*
|
2007-05-30 19:17:45 +02:00
|
|
|
* Copyright (C) 2004-2007 Entr'ouvert
|
2004-11-30 12:23:26 +01:00
|
|
|
* http://lasso.entrouvert.org
|
2008-09-12 17:06:58 +02:00
|
|
|
*
|
2005-01-22 16:57:56 +01:00
|
|
|
* Authors: See AUTHORS file in top-level directory.
|
2004-11-30 12:23:26 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2008-09-12 17:06:58 +02:00
|
|
|
*
|
2004-11-30 12:23:26 +01:00
|
|
|
* 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.
|
2008-09-12 17:06:58 +02:00
|
|
|
*
|
2004-11-30 12:23:26 +01:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2009-03-27 16:04:26 +01:00
|
|
|
#include "private.h"
|
2009-08-26 17:14:32 +02:00
|
|
|
#include "dst_query.h"
|
2004-11-30 12:23:26 +01:00
|
|
|
|
2008-05-15 23:17:44 +02:00
|
|
|
/**
|
|
|
|
* SECTION:dst_query
|
|
|
|
* @short_description: <dst:Query>
|
|
|
|
*
|
|
|
|
* <figure><title>Schema fragment for dst:Query</title>
|
|
|
|
* <programlisting><![CDATA[
|
2004-12-07 16:22:12 +01:00
|
|
|
*
|
2004-12-03 12:10:51 +01:00
|
|
|
* <xs:element name="Query" type="QueryType"/>
|
|
|
|
* <xs:complexType name="QueryType">
|
|
|
|
* <xs:sequence>
|
|
|
|
* <xs:group ref="ResourceIDGroup" minOccurs="0"/>
|
|
|
|
* <xs:element name="QueryItem" maxOccurs="unbounded"/>
|
|
|
|
* <xs:element ref="Extension" minOccurs="0" maxOccurs="unbounded"/>
|
|
|
|
* </xs:sequence>
|
|
|
|
* <xs:attribute name="id" type="xs:ID"/>
|
|
|
|
* <xs:attribute name="itemID" type="IDType"/>
|
|
|
|
* </xs:complexType>
|
2004-12-07 16:22:12 +01:00
|
|
|
*
|
|
|
|
* <xs:simpleType name="IDReferenceType">
|
|
|
|
* <xs:annotation>
|
|
|
|
* <xs:documentation> This type can be used when referring to elements that are
|
|
|
|
* identified using an IDType </xs:documentation>
|
|
|
|
* </xs:annotation>
|
|
|
|
* <xs:restriction base="xs:string"/>
|
|
|
|
* </xs:simpleType>
|
2008-05-15 23:17:44 +02:00
|
|
|
* ]]></programlisting>
|
|
|
|
* </figure>
|
2004-12-07 16:22:12 +01:00
|
|
|
*/
|
2004-11-30 12:23:26 +01:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* private methods */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2004-12-03 12:10:51 +01:00
|
|
|
static struct XmlSnippet schema_snippets[] = {
|
2009-01-24 10:33:40 +01:00
|
|
|
{ "ResourceID", SNIPPET_NODE, G_STRUCT_OFFSET(LassoDstQuery, ResourceID), NULL, NULL, NULL},
|
2004-12-10 15:30:22 +01:00
|
|
|
{ "EncryptedResourceID", SNIPPET_NODE, G_STRUCT_OFFSET(LassoDstQuery,
|
2009-01-24 10:33:40 +01:00
|
|
|
EncryptedResourceID), NULL, NULL, NULL },
|
|
|
|
{ "QueryItem", SNIPPET_LIST_NODES, G_STRUCT_OFFSET(LassoDstQuery, QueryItem), NULL, NULL, NULL},
|
|
|
|
{ "Extension", SNIPPET_EXTENSION, G_STRUCT_OFFSET(LassoDstQuery, Extension), NULL, NULL, NULL},
|
|
|
|
{ "id", SNIPPET_ATTRIBUTE, G_STRUCT_OFFSET(LassoDstQuery, id), NULL, NULL, NULL},
|
|
|
|
{ "itemID", SNIPPET_ATTRIBUTE, G_STRUCT_OFFSET(LassoDstQuery, itemID), NULL, NULL, NULL},
|
|
|
|
{NULL, 0, 0, NULL, NULL, NULL}
|
2004-12-03 12:10:51 +01:00
|
|
|
};
|
2004-11-30 12:23:26 +01:00
|
|
|
|
|
|
|
static LassoNodeClass *parent_class = NULL;
|
|
|
|
|
2004-12-07 12:12:24 +01:00
|
|
|
static void
|
|
|
|
insure_namespace(xmlNode *xmlnode, xmlNs *ns)
|
|
|
|
{
|
2004-12-20 18:26:13 +01:00
|
|
|
xmlNode *t = xmlnode->children;
|
2004-12-07 12:12:24 +01:00
|
|
|
|
2004-12-20 18:26:13 +01:00
|
|
|
xmlSetNs(xmlnode, ns);
|
2004-12-07 12:12:24 +01:00
|
|
|
while (t) {
|
2007-09-21 17:12:18 +02:00
|
|
|
if (t->type == XML_ELEMENT_NODE && t->ns == NULL) {
|
2004-12-20 18:26:13 +01:00
|
|
|
insure_namespace(t, ns);
|
2007-09-21 17:12:18 +02:00
|
|
|
}
|
2004-12-07 12:12:24 +01:00
|
|
|
t = t->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static xmlNode*
|
2004-12-19 21:34:22 +01:00
|
|
|
get_xmlNode(LassoNode *node, gboolean lasso_dump)
|
2004-12-07 12:12:24 +01:00
|
|
|
{
|
|
|
|
xmlNode *xmlnode;
|
|
|
|
xmlNs *ns;
|
|
|
|
|
2004-12-19 21:34:22 +01:00
|
|
|
xmlnode = parent_class->get_xmlNode(node, lasso_dump);
|
2005-07-31 00:36:54 +02:00
|
|
|
ns = xmlNewNs(xmlnode, (xmlChar*)LASSO_DST_QUERY(node)->hrefServiceType,
|
|
|
|
(xmlChar*)LASSO_DST_QUERY(node)->prefixServiceType);
|
2004-12-07 12:12:24 +01:00
|
|
|
insure_namespace(xmlnode, ns);
|
|
|
|
|
|
|
|
return xmlnode;
|
|
|
|
}
|
|
|
|
|
2005-08-12 16:25:44 +02:00
|
|
|
static int
|
|
|
|
init_from_xml(LassoNode *node, xmlNode *xmlnode)
|
|
|
|
{
|
|
|
|
LassoDstQuery *query = LASSO_DST_QUERY(node);
|
2010-04-30 11:23:01 +02:00
|
|
|
int rc = 0;
|
2005-08-12 16:25:44 +02:00
|
|
|
|
|
|
|
rc = parent_class->init_from_xml(node, xmlnode);
|
2007-09-21 17:12:18 +02:00
|
|
|
if (rc) {
|
2008-08-05 16:53:29 +02:00
|
|
|
return rc;
|
2007-09-21 17:12:18 +02:00
|
|
|
}
|
2005-08-12 16:25:44 +02:00
|
|
|
|
2005-09-11 11:08:31 +02:00
|
|
|
query->hrefServiceType = g_strdup((char*)xmlnode->ns->href);
|
|
|
|
query->prefixServiceType = lasso_get_prefix_for_dst_service_href(
|
|
|
|
query->hrefServiceType);
|
|
|
|
if (query->prefixServiceType == NULL) {
|
|
|
|
/* XXX: what to do here ? */
|
2005-08-12 16:25:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-11-30 12:23:26 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* instance and class init functions */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
class_init(LassoDstQueryClass *klass)
|
|
|
|
{
|
2005-08-12 16:25:44 +02:00
|
|
|
LassoNodeClass *nclass = LASSO_NODE_CLASS(klass);
|
2004-11-30 12:23:26 +01:00
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent(klass);
|
2005-08-12 16:25:44 +02:00
|
|
|
nclass->get_xmlNode = get_xmlNode;
|
|
|
|
nclass->init_from_xml = init_from_xml;
|
|
|
|
nclass->node_data = g_new0(LassoNodeClassData, 1);
|
|
|
|
lasso_node_class_set_nodename(nclass, "Query");
|
|
|
|
lasso_node_class_add_snippets(nclass, schema_snippets);
|
2004-11-30 12:23:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GType
|
|
|
|
lasso_dst_query_get_type()
|
|
|
|
{
|
|
|
|
static GType this_type = 0;
|
|
|
|
|
|
|
|
if (!this_type) {
|
|
|
|
static const GTypeInfo this_info = {
|
|
|
|
sizeof (LassoDstQueryClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(LassoDstQuery),
|
|
|
|
0,
|
2009-08-26 17:14:48 +02:00
|
|
|
NULL,
|
2009-01-24 10:33:40 +01:00
|
|
|
NULL
|
2004-11-30 12:23:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this_type = g_type_register_static(LASSO_TYPE_NODE,
|
|
|
|
"LassoDstQuery", &this_info, 0);
|
|
|
|
}
|
|
|
|
return this_type;
|
|
|
|
}
|
|
|
|
|
2005-09-10 21:36:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* lasso_dst_query_new:
|
|
|
|
* @query_item: query item to embed in request (optional)
|
|
|
|
*
|
|
|
|
* Creates a new #LassoDstQuery object. If @query_item is set it is added to
|
|
|
|
* the requested query items.
|
|
|
|
*
|
|
|
|
* Return value: a newly created #LassoDstQuery object.
|
|
|
|
**/
|
2004-11-30 12:23:26 +01:00
|
|
|
LassoDstQuery*
|
2004-12-07 16:22:12 +01:00
|
|
|
lasso_dst_query_new(LassoDstQueryItem *queryItem)
|
2004-11-30 12:23:26 +01:00
|
|
|
{
|
|
|
|
LassoDstQuery *query;
|
|
|
|
|
|
|
|
query = g_object_new(LASSO_TYPE_DST_QUERY, NULL);
|
|
|
|
|
2007-09-21 17:12:18 +02:00
|
|
|
if (queryItem) {
|
2005-09-10 21:36:33 +02:00
|
|
|
query->QueryItem = g_list_append(query->QueryItem, queryItem);
|
2007-09-21 17:12:18 +02:00
|
|
|
}
|
2004-11-30 12:23:26 +01:00
|
|
|
|
|
|
|
return query;
|
|
|
|
}
|
|
|
|
|