2 * Copyright (C) 2009 Nokia Corporation.
3 * Copyright (C) 2012 Intel Corporation
5 * Authors: Zeeshan Ali (Khattak) <zeeshan.ali@nokia.com>
6 * <zeeshanak@gnome.org>
7 * Krzesimir Nowak <krnowak@openismus.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
26 * SECTION:gupnp-didl-lite-object
27 * @short_description: DIDL-Lite Object
29 * #GUPnPDIDLLiteObject respresent a DIDL-Lite object element.
33 #include <libgupnp/gupnp.h>
35 #include "gupnp-didl-lite-object.h"
36 #include "gupnp-didl-lite-object-private.h"
37 #include "gupnp-didl-lite-resource-private.h"
38 #include "gupnp-didl-lite-descriptor-private.h"
39 #include "gupnp-didl-lite-container.h"
40 #include "gupnp-didl-lite-item.h"
41 #include "gupnp-didl-lite-contributor-private.h"
43 #include "fragment-util.h"
46 G_DEFINE_ABSTRACT_TYPE (GUPnPDIDLLiteObject,
47 gupnp_didl_lite_object,
50 struct _GUPnPDIDLLiteObjectPrivate {
60 static XSDData *didl_lite_xsd;
90 is_non_transcoded_resource (GUPnPDIDLLiteResource *resource)
92 GUPnPProtocolInfo *info;
94 info = gupnp_didl_lite_resource_get_protocol_info (resource);
95 if (G_UNLIKELY (info == NULL))
98 return gupnp_protocol_info_get_dlna_conversion (info) &
99 GUPNP_DLNA_CONVERSION_TRANSCODED;
103 gupnp_didl_lite_object_init (GUPnPDIDLLiteObject *object)
105 object->priv = G_TYPE_INSTANCE_GET_PRIVATE
107 GUPNP_TYPE_DIDL_LITE_OBJECT,
108 GUPnPDIDLLiteObjectPrivate);
112 gupnp_didl_lite_object_set_property (GObject *object,
118 GUPnPDIDLLiteObject *didl_object;
120 didl_object = GUPNP_DIDL_LITE_OBJECT (object);
122 switch (property_id) {
124 didl_object->priv->xml_node = g_value_get_pointer (value);
127 didl_object->priv->xml_doc = g_value_dup_object (value);
129 case PROP_UPNP_NAMESPACE:
130 didl_object->priv->upnp_ns = g_value_get_pointer (value);
132 case PROP_DC_NAMESPACE:
133 didl_object->priv->dc_ns = g_value_get_pointer (value);
135 case PROP_DLNA_NAMESPACE:
136 didl_object->priv->dlna_ns = g_value_get_pointer (value);
138 case PROP_PV_NAMESPACE:
139 didl_object->priv->pv_ns = g_value_get_pointer (value);
142 gupnp_didl_lite_object_set_id (didl_object,
143 g_value_get_string (value));
146 gupnp_didl_lite_object_set_parent_id
148 g_value_get_string (value));
150 case PROP_RESTRICTED:
151 gupnp_didl_lite_object_set_restricted
153 g_value_get_boolean (value));
156 gupnp_didl_lite_object_set_title
158 g_value_get_string (value));
160 case PROP_UPNP_CLASS:
161 gupnp_didl_lite_object_set_upnp_class
163 g_value_get_string (value));
166 gupnp_didl_lite_object_set_creator
168 g_value_get_string (value));
171 gupnp_didl_lite_object_set_artist
173 g_value_get_string (value));
176 gupnp_didl_lite_object_set_author
178 g_value_get_string (value));
181 gupnp_didl_lite_object_set_genre
183 g_value_get_string (value));
185 case PROP_WRITE_STATUS:
186 gupnp_didl_lite_object_set_write_status
188 g_value_get_string (value));
191 gupnp_didl_lite_object_set_album
193 g_value_get_string (value));
196 gupnp_didl_lite_object_set_album_art
198 g_value_get_string (value));
200 case PROP_DESCRIPTION:
201 gupnp_didl_lite_object_set_description
203 g_value_get_string (value));
206 gupnp_didl_lite_object_set_date
208 g_value_get_string (value));
210 case PROP_TRACK_NUMBER:
211 gupnp_didl_lite_object_set_track_number
213 g_value_get_int (value));
215 case PROP_DLNA_MANAGED:
216 gupnp_didl_lite_object_set_dlna_managed
218 g_value_get_flags (value));
221 gupnp_didl_lite_object_set_update_id
223 g_value_get_uint (value));
226 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
232 gupnp_didl_lite_object_get_property (GObject *object,
237 GUPnPDIDLLiteObject *didl_object;
239 didl_object = GUPNP_DIDL_LITE_OBJECT (object);
241 switch (property_id) {
245 gupnp_didl_lite_object_get_xml_node (didl_object));
247 case PROP_UPNP_NAMESPACE:
250 gupnp_didl_lite_object_get_upnp_namespace
253 case PROP_DC_NAMESPACE:
256 gupnp_didl_lite_object_get_dc_namespace
259 case PROP_DLNA_NAMESPACE:
262 gupnp_didl_lite_object_get_dlna_namespace
265 case PROP_PV_NAMESPACE:
268 gupnp_didl_lite_object_get_pv_namespace
274 gupnp_didl_lite_object_get_id (didl_object));
279 gupnp_didl_lite_object_get_parent_id (didl_object));
281 case PROP_RESTRICTED:
284 gupnp_didl_lite_object_get_restricted (didl_object));
289 gupnp_didl_lite_object_get_title (didl_object));
291 case PROP_UPNP_CLASS:
294 gupnp_didl_lite_object_get_upnp_class (didl_object));
299 gupnp_didl_lite_object_get_creator (didl_object));
304 gupnp_didl_lite_object_get_artist (didl_object));
309 gupnp_didl_lite_object_get_author (didl_object));
314 gupnp_didl_lite_object_get_genre (didl_object));
316 case PROP_WRITE_STATUS:
319 gupnp_didl_lite_object_get_write_status (didl_object));
324 gupnp_didl_lite_object_get_album (didl_object));
329 gupnp_didl_lite_object_get_album_art (didl_object));
331 case PROP_DESCRIPTION:
334 gupnp_didl_lite_object_get_description (didl_object));
339 gupnp_didl_lite_object_get_date (didl_object));
341 case PROP_TRACK_NUMBER:
344 gupnp_didl_lite_object_get_track_number (didl_object));
346 case PROP_DLNA_MANAGED:
349 gupnp_didl_lite_object_get_dlna_managed (didl_object));
354 gupnp_didl_lite_object_get_update_id (didl_object));
357 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
363 gupnp_didl_lite_object_dispose (GObject *object)
365 GObjectClass *object_class;
366 GUPnPDIDLLiteObjectPrivate *priv;
368 priv = GUPNP_DIDL_LITE_OBJECT (object)->priv;
371 g_object_unref (priv->xml_doc);
372 priv->xml_doc = NULL;
375 object_class = G_OBJECT_CLASS (gupnp_didl_lite_object_parent_class);
376 object_class->dispose (object);
380 gupnp_didl_lite_object_class_init (GUPnPDIDLLiteObjectClass *klass)
382 GObjectClass *object_class;
384 object_class = G_OBJECT_CLASS (klass);
386 object_class->set_property = gupnp_didl_lite_object_set_property;
387 object_class->get_property = gupnp_didl_lite_object_get_property;
388 object_class->dispose = gupnp_didl_lite_object_dispose;
390 g_type_class_add_private (klass, sizeof (GUPnPDIDLLiteObjectPrivate));
393 * GUPnPDIDLLiteObject:xml-node:
395 * The pointer to object node in XML document.
397 g_object_class_install_property
400 g_param_spec_pointer ("xml-node",
402 "The pointer to object node in XML"
405 G_PARAM_CONSTRUCT_ONLY |
406 G_PARAM_STATIC_NAME |
407 G_PARAM_STATIC_NICK |
408 G_PARAM_STATIC_BLURB));
411 * GUPnPDIDLLiteObject:xml-doc:
413 * The reference to XML document containing this object.
419 g_object_class_install_property
422 g_param_spec_object ("xml-doc",
424 "The reference to XML document"
425 " containing this object.",
428 G_PARAM_CONSTRUCT_ONLY |
429 G_PARAM_STATIC_NAME |
430 G_PARAM_STATIC_NICK |
431 G_PARAM_STATIC_BLURB));
434 * GUPnPDIDLLiteObject:upnp-namespace:
436 * Pointer to the UPnP namespace registered with the XML document
437 * containing this object.
440 g_object_class_install_property
443 g_param_spec_pointer ("upnp-namespace",
445 "Pointer to the UPnP XML namespace "
446 "registered with the XML document "
447 "containing this object.",
449 G_PARAM_CONSTRUCT_ONLY |
450 G_PARAM_STATIC_NAME |
451 G_PARAM_STATIC_NICK |
452 G_PARAM_STATIC_BLURB));
455 * GUPnPDIDLLiteObject:dc-namespace:
457 * Pointer to the DublinCore namespace registered with the XML document
458 * containing this object.
461 g_object_class_install_property
464 g_param_spec_pointer ("dc-namespace",
466 "Pointer to the Dublin Core XML "
467 "namespace registered with the XML "
468 "document containing this object.",
470 G_PARAM_CONSTRUCT_ONLY |
471 G_PARAM_STATIC_NAME |
472 G_PARAM_STATIC_NICK |
473 G_PARAM_STATIC_BLURB));
476 * GUPnPDIDLLiteObject:dlna-namespace:
478 * Pointer to the DLNA metadata namespace registered with the XML
479 * document containing this object.
482 g_object_class_install_property
485 g_param_spec_pointer ("dlna-namespace",
487 "Pointer to the DLNA metadata namespace "
488 "registered with the XML document "
489 "containing this object.",
491 G_PARAM_CONSTRUCT_ONLY |
492 G_PARAM_STATIC_NAME |
493 G_PARAM_STATIC_NICK |
494 G_PARAM_STATIC_BLURB));
497 * GUPnPDIDLLiteObject:pv-namespace:
499 * Pointer to the PV metadata namespace registered with the XML
500 * document containing this object.
503 g_object_class_install_property
506 g_param_spec_pointer ("pv-namespace",
508 "Pointer to the PV metadata namespace "
509 "registered with the XML document "
510 "containing this object.",
512 G_PARAM_CONSTRUCT_ONLY |
513 G_PARAM_STATIC_STRINGS));
516 * GUPnPDIDLLiteObject:id:
518 * The ID of this object.
520 g_object_class_install_property
523 g_param_spec_string ("id",
525 "The ID of this object.",
528 G_PARAM_STATIC_NAME |
529 G_PARAM_STATIC_NICK |
530 G_PARAM_STATIC_BLURB));
533 * GUPnPDIDLLiteObject:parent-id:
535 * The ID of the parent container of this object.
537 g_object_class_install_property
540 g_param_spec_string ("parent-id",
542 "The ID of the parent container of"
546 G_PARAM_STATIC_NAME |
547 G_PARAM_STATIC_NICK |
548 G_PARAM_STATIC_BLURB));
551 * GUPnPDIDLLiteObject:restricted:
553 * Whether this object is restricted.
555 g_object_class_install_property
558 g_param_spec_boolean ("restricted",
560 "Whether this object is restricted.",
563 G_PARAM_STATIC_NAME |
564 G_PARAM_STATIC_NICK |
565 G_PARAM_STATIC_BLURB));
568 * GUPnPDIDLLiteObject:title:
570 * The title of this object.
572 g_object_class_install_property
575 g_param_spec_string ("title",
577 "The title of this object.",
580 G_PARAM_STATIC_NAME |
581 G_PARAM_STATIC_NICK |
582 G_PARAM_STATIC_BLURB));
585 * GUPnPDIDLLiteObject:upnp-class:
587 * The UPnP class of this object.
589 g_object_class_install_property
592 g_param_spec_string ("upnp-class",
594 "The UPnP class of this object.",
597 G_PARAM_STATIC_NAME |
598 G_PARAM_STATIC_NICK |
599 G_PARAM_STATIC_BLURB));
602 * GUPnPDIDLLiteObject:creator:
604 * The creator of this object.
607 g_object_class_install_property
610 g_param_spec_string ("creator",
612 "The creator of this object.",
615 G_PARAM_STATIC_NAME |
616 G_PARAM_STATIC_NICK |
617 G_PARAM_STATIC_BLURB));
620 * GUPnPDIDLLiteObject:artist:
622 * The artist of this object.
624 * Deprecated: 0.5.3: Use #gupnp_didl_lite_object_get_artists and
625 * #gupnp_didl_lite_object_add_artist instead since unlike this
626 * property, they are capable of dealing with multiple artist nodes.
628 g_object_class_install_property
631 g_param_spec_string ("artist",
633 "The artist of this object.",
636 G_PARAM_STATIC_NAME |
637 G_PARAM_STATIC_NICK |
638 G_PARAM_STATIC_BLURB));
641 * GUPnPDIDLLiteObject:author:
643 * The author of this object.
645 * Deprecated: 0.5.3: Use #gupnp_didl_lite_object_get_authors and
646 * #gupnp_didl_lite_object_add_author instead since unlike this
647 * property, they are capable of dealing with multiple author nodes.
649 g_object_class_install_property
652 g_param_spec_string ("author",
654 "The author of this object.",
657 G_PARAM_STATIC_NAME |
658 G_PARAM_STATIC_NICK |
659 G_PARAM_STATIC_BLURB));
662 * GUPnPDIDLLiteObject:genre:
664 * The genre of this object.
666 g_object_class_install_property
669 g_param_spec_string ("genre",
671 "The genre of this object.",
674 G_PARAM_STATIC_NAME |
675 G_PARAM_STATIC_NICK |
676 G_PARAM_STATIC_BLURB));
679 * GUPnPDIDLLiteObject:write-status:
681 * The write status of this object.
683 g_object_class_install_property
686 g_param_spec_string ("write-status",
688 "The write status of this object.",
691 G_PARAM_STATIC_NAME |
692 G_PARAM_STATIC_NICK |
693 G_PARAM_STATIC_BLURB));
696 * GUPnPDIDLLiteObject:album:
698 * The album of this object.
700 g_object_class_install_property
703 g_param_spec_string ("album",
705 "The album of this object.",
708 G_PARAM_STATIC_NAME |
709 G_PARAM_STATIC_NICK |
710 G_PARAM_STATIC_BLURB));
713 * GUPnPDIDLLiteObject:album-art:
715 * The URI to album art of this object.
717 g_object_class_install_property
720 g_param_spec_string ("album-art",
722 "The URI to album art of this object.",
725 G_PARAM_STATIC_NAME |
726 G_PARAM_STATIC_NICK |
727 G_PARAM_STATIC_BLURB));
730 * GUPnPDIDLLiteObject:description:
732 * The description of this object.
734 g_object_class_install_property
737 g_param_spec_string ("description",
739 "The description of this object.",
742 G_PARAM_STATIC_NAME |
743 G_PARAM_STATIC_NICK |
744 G_PARAM_STATIC_BLURB));
747 * GUPnPDIDLLiteObject:date:
749 * The date of this object.
751 g_object_class_install_property
754 g_param_spec_string ("date",
756 "The date of this object.",
759 G_PARAM_STATIC_NAME |
760 G_PARAM_STATIC_NICK |
761 G_PARAM_STATIC_BLURB));
764 * GUPnPDIDLLiteObject:track-number:
766 * The original track number of this object.
768 g_object_class_install_property
771 g_param_spec_int ("track-number",
773 "The original track number of this object.",
776 G_PARAM_STATIC_NAME |
777 G_PARAM_STATIC_NICK |
778 G_PARAM_STATIC_BLURB));
781 * GUPnPDIDLLiteObject:dlna-managed:
783 * The 'dlna:dlnaManaged' attribute.
785 g_object_class_install_property
788 g_param_spec_flags ("dlna-managed",
790 "The 'dlna:dlnaManaged' attribute",
791 GUPNP_TYPE_OCM_FLAGS,
792 GUPNP_OCM_FLAGS_NONE,
794 G_PARAM_STATIC_NAME |
795 G_PARAM_STATIC_NICK |
796 G_PARAM_STATIC_BLURB));
799 * GUPnPDIDLLiteObject:update-id:
801 * Update ID of this object.
803 g_object_class_install_property
806 g_param_spec_uint ("update-id",
808 "Update ID of this object.",
813 G_PARAM_STATIC_NAME |
814 G_PARAM_STATIC_NICK |
815 G_PARAM_STATIC_BLURB));
817 if (didl_lite_xsd == NULL)
818 didl_lite_xsd = fragment_util_get_didl_lite_xsd_data ();
822 is_resource_compatible (GUPnPDIDLLiteResource *resource,
825 gboolean ret = FALSE;
828 for (it = protocols; *it != NULL && !ret; it++) {
829 GUPnPProtocolInfo *info;
830 GUPnPProtocolInfo *res_info;
832 info = gupnp_protocol_info_new_from_string (*it, NULL);
836 res_info = gupnp_didl_lite_resource_get_protocol_info
838 ret = gupnp_protocol_info_is_compatible (info, res_info);
840 g_object_unref (info);
847 get_contributor_list_by_name (GUPnPDIDLLiteObject *object,
850 GList *contributors = NULL;
854 contributors = gupnp_didl_lite_object_get_properties (object, name);
856 for (l = contributors; l; l = l->next) {
857 GUPnPDIDLLiteContributor *contributor;
858 xmlNode *contributor_node;
860 contributor_node = (xmlNode *) l->data;
861 if (!contributor_node->children)
864 contributor = gupnp_didl_lite_contributor_new_from_xml
866 object->priv->xml_doc);
868 ret = g_list_append (ret, contributor);
871 g_list_free (contributors);
877 get_contributors_xml_string_by_name (GUPnPDIDLLiteObject *object,
880 GList *contributors = NULL;
885 contributors = gupnp_didl_lite_object_get_properties (object, name);
886 if (contributors == NULL)
889 buffer = xmlBufferCreate ();
891 for (l = contributors; l; l = l->next) {
894 node = (xmlNode *) l->data;
899 object->priv->xml_doc->doc,
905 ret = g_strndup ((char *) xmlBufferContent (buffer),
906 xmlBufferLength (buffer));
907 xmlBufferFree (buffer);
909 g_list_free (contributors);
915 unset_contributors_by_name (GUPnPDIDLLiteObject *object, const char *name)
917 GList *contributors = NULL;
920 contributors = gupnp_didl_lite_object_get_properties (object, name);
921 if (contributors == NULL)
924 for (l = contributors; l; l = l->next) {
927 node = (xmlNode *) l->data;
931 xmlUnlinkNode (node);
935 g_list_free (contributors);
941 * gupnp_didl_lite_object_new_from_xml:
942 * @xml_node: The pointer to 'res' node in XML document
943 * @xml_doc: The reference to XML document containing this object
944 * @upnp_ns: The pointer to 'upnp' namespace in XML document
945 * @dc_ns: The pointer to 'dc' namespace in XML document
946 * @dlna_ns: The pointer to 'dlna' namespace in XML document
947 * @pv_ns: The pointer to 'pv' namespace in XML document
949 * Creates a new #GUPnPDIDLLiteObject for the @xml_node.
951 * Return value: A new #GUPnPDIDLLiteObject object. Unref after usage.
953 GUPnPDIDLLiteObject *
954 gupnp_didl_lite_object_new_from_xml (xmlNode *xml_node,
955 GUPnPXMLDoc *xml_doc,
961 g_return_val_if_fail (xml_node != NULL, NULL);
962 g_return_val_if_fail (xml_node->name != NULL, NULL);
963 g_return_val_if_fail (upnp_ns != NULL, NULL);
964 g_return_val_if_fail (dc_ns != NULL, NULL);
965 g_return_val_if_fail (dlna_ns != NULL, NULL);
967 if (g_ascii_strcasecmp ((char *) xml_node->name, "container") == 0)
968 return g_object_new (GUPNP_TYPE_DIDL_LITE_CONTAINER,
969 "xml-node", xml_node,
971 "upnp-namespace", upnp_ns,
972 "dc-namespace", dc_ns,
973 "dlna-namespace", dlna_ns,
974 "pv-namespace", pv_ns,
976 else if (g_ascii_strcasecmp ((char *) xml_node->name, "item") == 0)
977 return g_object_new (GUPNP_TYPE_DIDL_LITE_ITEM,
978 "xml-node", xml_node,
980 "upnp-namespace", upnp_ns,
981 "dc-namespace", dc_ns,
982 "dlna-namespace", dlna_ns,
983 "pv-namespace", pv_ns,
990 * gupnp_didl_lite_object_get_gupnp_xml_doc:
991 * @object: The #GUPnPDIDLLiteObject
993 * Get the pointer to the XML document containing this object.
995 * Returns: (transfer none): The pointer to the XML document containing this
999 gupnp_didl_lite_object_get_gupnp_xml_doc (GUPnPDIDLLiteObject *object)
1001 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1003 return object->priv->xml_doc;
1007 * gupnp_didl_lite_object_get_xml_node:
1008 * @object: The #GUPnPDIDLLiteObject
1010 * Get the pointer to object node in XML document.
1012 * Returns: (transfer none): The pointer to object node in XML document.
1015 gupnp_didl_lite_object_get_xml_node (GUPnPDIDLLiteObject *object)
1017 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1019 return object->priv->xml_node;
1023 * gupnp_didl_lite_object_get_upnp_namespace:
1024 * @object: The #GUPnPDIDLLiteObject
1026 * Get the pointer to the UPnP namespace registered with the XML document.
1028 * Returns: (transfer none): The pointer to UPnP namespace in XML document.
1031 gupnp_didl_lite_object_get_upnp_namespace (GUPnPDIDLLiteObject *object)
1033 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1035 return object->priv->upnp_ns;
1039 * gupnp_didl_lite_object_get_dc_namespace:
1040 * @object: The #GUPnPDIDLLiteObject
1042 * Get the pointer to the DublinCore namespace registered with the XML document
1043 * containing this object.
1045 * Returns: (transfer none): The pointer to DublinCore namespace in XML document.
1048 gupnp_didl_lite_object_get_dc_namespace (GUPnPDIDLLiteObject *object)
1050 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1052 return object->priv->dc_ns;
1056 * gupnp_didl_lite_object_get_upnp_class:
1057 * @object: The #GUPnPDIDLLiteObject
1059 * Get the UPnP class of the @object.
1061 * Return value: The class of @object, or %NULL.
1064 gupnp_didl_lite_object_get_upnp_class (GUPnPDIDLLiteObject *object)
1066 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1068 return xml_util_get_child_element_content (object->priv->xml_node,
1073 * gupnp_didl_lite_object_get_dlna_namespace:
1074 * @object: The #GUPnPDIDLLiteObject
1076 * Get the pointer to the DLNA metadata namespace registered with the XML
1077 * document containing this object.
1079 * Returns: (transfer none): The pointer to DLNA namespace in XML document.
1082 gupnp_didl_lite_object_get_dlna_namespace (GUPnPDIDLLiteObject *object)
1084 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1086 return object->priv->dlna_ns;
1090 * gupnp_didl_lite_object_get_pv_namespace:
1091 * @object: The #GUPnPDIDLLiteObject
1093 * Get the pointer to the PV metadata namespace registered with the XML
1094 * document containing this object.
1096 * Returns: (transfer none): The pointer to PV namespace in XML document.
1099 gupnp_didl_lite_object_get_pv_namespace (GUPnPDIDLLiteObject *object)
1101 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1103 return object->priv->pv_ns;
1108 * gupnp_didl_lite_object_get_id:
1109 * @object: #GUPnPDIDLLiteObject
1111 * Get the ID of the @object.
1113 * Return value: The ID of the @object, or %NULL.
1116 gupnp_didl_lite_object_get_id (GUPnPDIDLLiteObject *object)
1118 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1120 return xml_util_get_attribute_content (object->priv->xml_node, "id");
1124 * gupnp_didl_lite_object_get_parent_id:
1125 * @object: #GUPnPDIDLLiteObject
1127 * Get the ID of the parent of the @object.
1129 * Return value: The ID of parent of the @object, or %NULL.
1132 gupnp_didl_lite_object_get_parent_id (GUPnPDIDLLiteObject *object)
1134 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1136 return xml_util_get_attribute_content (object->priv->xml_node,
1141 * gupnp_didl_lite_object_get_properties:
1142 * @object: #GUPnPDIDLLiteObject
1143 * @name: name of the properties
1145 * Use this function to retreive property nodes by name.
1147 * Return value: (element-type xmlNode*) (transfer container): The list of
1148 * property nodes by the name @property_name belonging to @object, or %NULL.
1149 * #g_list_free the returned list after usage but do not modify the contents.
1152 gupnp_didl_lite_object_get_properties (GUPnPDIDLLiteObject *object,
1155 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1156 g_return_val_if_fail (name != NULL, NULL);
1158 return xml_util_get_child_elements_by_name (object->priv->xml_node,
1163 * gupnp_didl_lite_object_get_restricted:
1164 * @object: #GUPnPDIDLLiteObject
1166 * Whether the @object is restricted or not.
1168 * Return value: #TRUE if @object is restricted.
1171 gupnp_didl_lite_object_get_restricted (GUPnPDIDLLiteObject *object)
1173 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), FALSE);
1175 return xml_util_get_boolean_attribute (object->priv->xml_node,
1180 * gupnp_didl_lite_object_get_title:
1181 * @object: #GUPnPDIDLLiteObject
1183 * Get the title of the @object.
1185 * Return value: The title of the @object, or %NULL.
1188 gupnp_didl_lite_object_get_title (GUPnPDIDLLiteObject *object)
1190 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1192 return xml_util_get_child_element_content (object->priv->xml_node,
1197 * gupnp_didl_lite_object_get_creator:
1198 * @object: #GUPnPDIDLLiteObject
1200 * Get the creator of the @object.
1202 * Return value: The creator of the @object, or %NULL.
1205 gupnp_didl_lite_object_get_creator (GUPnPDIDLLiteObject *object)
1207 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1209 return xml_util_get_child_element_content (object->priv->xml_node,
1214 * gupnp_didl_lite_object_get_creators:
1215 * @object: #GUPnPDIDLLiteObject
1217 * Get the creators of the @object.
1219 * Returns: (element-type GUPnPDIDLLiteContributor*) (transfer full): The list
1220 * of creators belonging to @object, or %NULL.
1221 * #g_list_free the returned list after usage and unref each object in it.
1224 gupnp_didl_lite_object_get_creators (GUPnPDIDLLiteObject *object)
1226 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1228 return get_contributor_list_by_name (object, "creator");
1232 * gupnp_didl_lite_object_get_artist:
1233 * @object: #GUPnPDIDLLiteObject
1235 * Get the artist of the @object. If role is not %NULL, it is set to the role
1236 * of the artist if available.
1238 * Return value: The artist of the @object, or %NULL.
1240 * Deprecated: 0.5.3: Use #gupnp_didl_lite_object_get_artists instead.
1243 gupnp_didl_lite_object_get_artist (GUPnPDIDLLiteObject *object)
1245 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1247 return xml_util_get_child_element_content (object->priv->xml_node,
1252 * gupnp_didl_lite_object_get_artists:
1253 * @object: #GUPnPDIDLLiteObject
1255 * Get the artists of the @object.
1257 * Returns: (element-type GUPnPDIDLLiteContributor*) (transfer full): The list
1258 * of artists belonging to @object, or %NULL.
1259 * #g_list_free the returned list after usage and unref each object in it.
1262 gupnp_didl_lite_object_get_artists (GUPnPDIDLLiteObject *object)
1264 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1266 return get_contributor_list_by_name (object, "artist");
1270 * gupnp_didl_lite_object_get_author:
1271 * @object: #GUPnPDIDLLiteObject
1273 * Get the author of the @object.
1275 * Return value: The author of the @object, or %NULL.
1277 * Deprecated: 0.5.3: Use #gupnp_didl_lite_object_get_authors instead.
1280 gupnp_didl_lite_object_get_author (GUPnPDIDLLiteObject *object)
1282 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1284 return xml_util_get_child_element_content (object->priv->xml_node,
1289 * gupnp_didl_lite_object_get_authors:
1290 * @object: #GUPnPDIDLLiteObject
1292 * Get the authors of the @object.
1294 * Returns: (element-type GUPnPDIDLLiteContributor*) (transfer full): The list
1295 * of authors belonging to @object, or %NULL.
1296 * #g_list_free the returned list after usage and unref each object in it.
1299 gupnp_didl_lite_object_get_authors (GUPnPDIDLLiteObject *object)
1301 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1303 return get_contributor_list_by_name (object, "author");
1307 * gupnp_didl_lite_object_get_descriptors:
1308 * @object: #GUPnPDIDLLiteObject
1310 * Get the descriptors of the @object.
1312 * Returns: (element-type GUPnPDIDLLiteDescriptor*) (transfer full): The list of
1313 * descriptors belonging to @object, or %NULL.
1314 * #g_list_free the returned list after usage and unref each object in it.
1317 gupnp_didl_lite_object_get_descriptors (GUPnPDIDLLiteObject *object)
1319 GList *descriptors = NULL;
1323 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1325 descriptors = gupnp_didl_lite_object_get_properties (object, "desc");
1327 for (l = descriptors; l; l = l->next) {
1328 GUPnPDIDLLiteDescriptor *descriptor;
1329 xmlNode *descriptor_node;
1331 descriptor_node = (xmlNode *) l->data;
1333 descriptor = gupnp_didl_lite_descriptor_new_from_xml
1335 object->priv->xml_doc);
1337 ret = g_list_append (ret, descriptor);
1340 g_list_free (descriptors);
1346 * gupnp_didl_lite_object_get_genre:
1347 * @object: #GUPnPDIDLLiteObject
1349 * Get the genre of the @object.
1351 * Return value: The genre of the @object, or %NULL.
1354 gupnp_didl_lite_object_get_genre (GUPnPDIDLLiteObject *object)
1356 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1358 return xml_util_get_child_element_content (object->priv->xml_node,
1363 * gupnp_didl_lite_object_get_write_status:
1364 * @object: #GUPnPDIDLLiteObject
1366 * Get the write status of the @object.
1368 * Return value: The write status of the @object, or %NULL.
1371 gupnp_didl_lite_object_get_write_status (GUPnPDIDLLiteObject *object)
1373 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1375 return xml_util_get_child_element_content (object->priv->xml_node,
1380 * gupnp_didl_lite_object_get_album:
1381 * @object: #GUPnPDIDLLiteObject
1383 * Get the album of the @object.
1385 * Return value: The album of the @object, or %NULL.
1388 gupnp_didl_lite_object_get_album (GUPnPDIDLLiteObject *object)
1390 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1392 return xml_util_get_child_element_content (object->priv->xml_node,
1397 * gupnp_didl_lite_object_get_album_art:
1398 * @object: #GUPnPDIDLLiteObject
1400 * Get the URI to album art of the @object.
1402 * Return value: The URI to album art of the @object, or %NULL.
1405 gupnp_didl_lite_object_get_album_art (GUPnPDIDLLiteObject *object)
1407 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1409 return xml_util_get_child_element_content (object->priv->xml_node,
1414 * gupnp_didl_lite_object_get_description:
1415 * @object: #GUPnPDIDLLiteObject
1417 * Get the description of the @object.
1419 * Return value: The description of the @object, or %NULL.
1422 gupnp_didl_lite_object_get_description (GUPnPDIDLLiteObject *object)
1424 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1426 return xml_util_get_child_element_content (object->priv->xml_node,
1431 * gupnp_didl_lite_object_get_date:
1432 * @object: #GUPnPDIDLLiteObject
1434 * Get the date of the @object.
1436 * Return value: The date of the @object, or %NULL.
1439 gupnp_didl_lite_object_get_date (GUPnPDIDLLiteObject *object)
1441 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1443 return xml_util_get_child_element_content (object->priv->xml_node,
1448 * gupnp_didl_lite_object_get_track_number:
1449 * @object: #GUPnPDIDLLiteObject
1451 * Get the original track number of the @object.
1453 * Return value: The original track number of the @object, or -1.
1456 gupnp_didl_lite_object_get_track_number (GUPnPDIDLLiteObject *object)
1460 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), -1);
1462 str = xml_util_get_child_element_content (object->priv->xml_node,
1463 "originalTrackNumber");
1471 * gupnp_didl_lite_object_get_dlna_managed:
1472 * @object: #GUPnPDIDLLiteObject
1474 * Get the 'dlna:dlnaManaged' attribute of the @object.
1476 * Return value: The 'dlna:dlnaManaged' attribute of the @object.
1479 gupnp_didl_lite_object_get_dlna_managed (GUPnPDIDLLiteObject *object)
1482 GUPnPOCMFlags dlna_managed;
1484 g_return_val_if_fail (object != NULL, GUPNP_OCM_FLAGS_NONE);
1485 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object),
1486 GUPNP_OCM_FLAGS_NONE);
1488 str = xml_util_get_attribute_content (object->priv->xml_node,
1491 return GUPNP_OCM_FLAGS_NONE;
1493 sscanf (str, "%08x", &dlna_managed);
1495 return dlna_managed;
1499 * gupnp_didl_lite_object_get_update_id:
1500 * @object: #GUPnPDIDLLiteObject
1502 * Get the update ID of the @object.
1504 * Return value: The update ID of the @object.
1507 gupnp_didl_lite_object_get_update_id (GUPnPDIDLLiteObject *object)
1509 g_return_val_if_fail (object != NULL, 0);
1510 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), 0);
1512 return xml_util_get_uint_child_element (object->priv->xml_node,
1518 * gupnp_didl_lite_object_update_id_is_set:
1519 * @object: #GUPnPDIDLLiteObject
1521 * Get whether the update ID of the @object is set.
1523 * Return value: %TRUE if update ID is set, otherwise %FALSE
1526 gupnp_didl_lite_object_update_id_is_set (GUPnPDIDLLiteObject *object)
1528 const char *content;
1530 g_return_val_if_fail (object != NULL, FALSE);
1531 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), FALSE);
1533 content = xml_util_get_child_element_content (object->priv->xml_node,
1535 return content != NULL;
1539 * gupnp_didl_lite_object_get_resources:
1540 * @object: #GUPnPDIDLLiteObject
1542 * Use this function to retreive resources from the @object.
1544 * Return value: (element-type GUPnPDIDLLiteResource*) (transfer full): The list
1545 * of resources belonging to @object, or %NULL. #g_list_free the
1546 * returned list after usage and unref each resource in it.
1549 gupnp_didl_lite_object_get_resources (GUPnPDIDLLiteObject *object)
1551 GList *resources = NULL;
1555 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1557 resources = gupnp_didl_lite_object_get_properties (object, "res");
1559 for (res = resources; res; res = res->next) {
1560 GUPnPDIDLLiteResource *resource;
1563 res_node = (xmlNode *) res->data;
1565 /* Create a resource struct out of DIDLLite XML */
1566 resource = gupnp_didl_lite_resource_new_from_xml
1568 object->priv->xml_doc,
1569 object->priv->dlna_ns,
1570 object->priv->pv_ns);
1572 ret = g_list_append (ret, resource);
1575 g_list_free (resources);
1581 * gupnp_didl_lite_object_get_compat_resource:
1582 * @object: #GUPnPDIDLLiteObject
1583 * @sink_protocol_info: The SinkProtocolInfo string from MediaRenderer
1584 * @lenient: Enable lenient mode
1586 * Use this function to get a resource from the @object that is compatible with
1587 * any of the protocols specified in the @sink_protocol_info. The value of
1588 * @sink_protocol_info will typically be acquired from 'Sink' argument of
1589 * 'GetProtocolInfo' action or 'SinkProtocolInfo' state-variable of a
1590 * ConnectionManager service.
1592 * If @lenient is #TRUE, the first resource in the list is returned instead of
1593 * %NULL if none of resources and protocols are found to be compatible.
1595 * Returns: (transfer full): The resource belonging to @object that is comaptible with
1596 * any of the protocols specified in @sink_protocol_info, or %NULL. Unref after
1599 GUPnPDIDLLiteResource *
1600 gupnp_didl_lite_object_get_compat_resource
1601 (GUPnPDIDLLiteObject *object,
1602 const char *sink_protocol_info,
1605 GUPnPDIDLLiteResource *resource = NULL;
1606 GList *resources = NULL;
1607 GList *compat_resources = NULL;
1609 char **protocols = NULL;
1611 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1612 g_return_val_if_fail (sink_protocol_info != NULL, NULL);
1614 resources = gupnp_didl_lite_object_get_resources (object);
1615 if (resources == NULL)
1618 protocols = g_strsplit (sink_protocol_info, ",", -1);
1619 for (res = resources;
1622 resource = (GUPnPDIDLLiteResource *) res->data;
1624 if (is_resource_compatible (resource, protocols))
1625 compat_resources = g_list_append (compat_resources,
1628 g_strfreev (protocols);
1633 if (compat_resources != NULL) {
1634 /* Try to find non-transcoded resource */
1635 res = g_list_find_custom (compat_resources,
1638 is_non_transcoded_resource);
1641 resource = (GUPnPDIDLLiteResource *) res->data;
1643 /* Just use the first compatible resource */
1644 resource = (GUPnPDIDLLiteResource *)
1645 compat_resources->data;
1648 /* Just use the first resource */
1649 resource = (GUPnPDIDLLiteResource *) resources->data;
1651 /* Unref all resources except for the one we just took */
1652 for (res = resources; res; res = res->next)
1653 if (res->data != resource)
1654 g_object_unref (res->data);
1655 g_list_free (resources);
1656 g_list_free (compat_resources);
1662 * gupnp_didl_lite_object_set_upnp_class:
1663 * @object: The #GUPnPDIDLLiteObject
1664 * @upnp_class: The UPnP class as string.
1666 * Set the UPnP class of the @object to @upnp_class.
1669 gupnp_didl_lite_object_set_upnp_class (GUPnPDIDLLiteObject *object,
1670 const char *upnp_class)
1672 g_return_if_fail (object != NULL);
1673 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
1675 xml_util_set_child (object->priv->xml_node,
1676 object->priv->upnp_ns,
1677 object->priv->xml_doc->doc,
1681 g_object_notify (G_OBJECT (object), "upnp-class");
1685 * gupnp_didl_lite_object_set_id:
1686 * @object: #GUPnPDIDLLiteObject
1689 * Set the ID of the @object to @id.
1692 gupnp_didl_lite_object_set_id (GUPnPDIDLLiteObject *object,
1695 g_return_if_fail (object != NULL);
1696 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
1698 xmlSetProp (object->priv->xml_node,
1699 (unsigned char *) "id",
1700 (unsigned char *) id);
1702 g_object_notify (G_OBJECT (object), "id");
1706 * gupnp_didl_lite_object_set_parent_id:
1707 * @object: #GUPnPDIDLLiteObject
1708 * @parent_id: The parent ID
1710 * Set the ID of the parent of the @object to @parent_id.
1713 gupnp_didl_lite_object_set_parent_id (GUPnPDIDLLiteObject *object,
1714 const char *parent_id)
1716 g_return_if_fail (object != NULL);
1717 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
1719 xmlSetProp (object->priv->xml_node,
1720 (unsigned char *) "parentID",
1721 (unsigned char *) parent_id);
1723 g_object_notify (G_OBJECT (object), "parent-id");
1727 * gupnp_didl_lite_object_set_restricted:
1728 * @object: #GUPnPDIDLLiteObject
1729 * @restricted: The restricted status
1731 * Set the restricted status of @object to @restricted.
1734 gupnp_didl_lite_object_set_restricted (GUPnPDIDLLiteObject *object,
1735 gboolean restricted)
1739 g_return_if_fail (object != NULL);
1740 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
1746 xmlSetProp (object->priv->xml_node,
1747 (unsigned char *) "restricted",
1748 (unsigned char *) str);
1750 g_object_notify (G_OBJECT (object), "restricted");
1754 * gupnp_didl_lite_object_set_title:
1755 * @object: #GUPnPDIDLLiteObject
1758 * Set the title of the @object to @title.
1761 gupnp_didl_lite_object_set_title (GUPnPDIDLLiteObject *object,
1764 g_return_if_fail (object != NULL);
1765 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
1767 xml_util_set_child (object->priv->xml_node,
1768 object->priv->dc_ns,
1769 object->priv->xml_doc->doc,
1773 g_object_notify (G_OBJECT (object), "title");
1777 * gupnp_didl_lite_object_set_creator:
1778 * @object: #GUPnPDIDLLiteObject
1779 * @creator: The creator
1781 * Set the creator of the @object to @creator.
1784 gupnp_didl_lite_object_set_creator (GUPnPDIDLLiteObject *object,
1785 const char *creator)
1787 g_return_if_fail (object != NULL);
1788 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
1790 xml_util_set_child (object->priv->xml_node,
1791 object->priv->dc_ns,
1792 object->priv->xml_doc->doc,
1796 g_object_notify (G_OBJECT (object), "creator");
1800 * gupnp_didl_lite_object_add_creator:
1801 * @object: The #GUPnPDIDLLiteObject
1803 * Add a new creator node to the @object and return the associated
1804 * #GUPnPDIDLLiteContributor object.
1806 * Returns: (transfer full): A new #GUPnPDIDLLiteContributor object. Unref after usage.
1808 GUPnPDIDLLiteContributor *
1809 gupnp_didl_lite_object_add_creator (GUPnPDIDLLiteObject *object)
1813 g_return_val_if_fail (object != NULL, NULL);
1814 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1816 res_node = xmlNewChild (object->priv->xml_node,
1817 object->priv->dc_ns,
1818 (unsigned char *) "creator",
1821 return gupnp_didl_lite_contributor_new_from_xml (res_node,
1822 object->priv->xml_doc);
1827 * gupnp_didl_lite_object_set_artist:
1828 * @object: The #GUPnPDIDLLiteObject
1829 * @artist: The Artist
1831 * Set the Artist of the @object to @artist.
1833 * Deprecated: 0.5.3: Use #gupnp_didl_lite_object_add_artist instead.
1836 gupnp_didl_lite_object_set_artist (GUPnPDIDLLiteObject *object,
1839 g_return_if_fail (object != NULL);
1840 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
1842 xml_util_set_child (object->priv->xml_node,
1843 object->priv->upnp_ns,
1844 object->priv->xml_doc->doc,
1848 g_object_notify (G_OBJECT (object), "artist");
1852 * gupnp_didl_lite_object_add_artist:
1853 * @object: The #GUPnPDIDLLiteObject
1855 * Add a new Artist node to the @object and return the associated
1856 * #GUPnPDIDLLiteContributor object.
1858 * Returns: (transfer full): A new #GUPnPDIDLLiteContributor object. Unref after usage.
1860 GUPnPDIDLLiteContributor *
1861 gupnp_didl_lite_object_add_artist (GUPnPDIDLLiteObject *object)
1865 g_return_val_if_fail (object != NULL, NULL);
1866 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1868 res_node = xmlNewChild (object->priv->xml_node,
1869 object->priv->upnp_ns,
1870 (unsigned char *) "artist",
1873 return gupnp_didl_lite_contributor_new_from_xml (res_node,
1874 object->priv->xml_doc);
1878 * gupnp_didl_lite_object_set_author:
1879 * @object: The #GUPnPDIDLLiteObject
1880 * @author: The Author
1882 * Set the Author of the @object to @author.
1884 * Deprecated: 0.5.3: Use #gupnp_didl_lite_object_add_author instead.
1887 gupnp_didl_lite_object_set_author (GUPnPDIDLLiteObject *object,
1890 g_return_if_fail (object != NULL);
1891 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
1893 xml_util_set_child (object->priv->xml_node,
1894 object->priv->upnp_ns,
1895 object->priv->xml_doc->doc,
1899 g_object_notify (G_OBJECT (object), "author");
1903 * gupnp_didl_lite_object_add_author:
1904 * @object: The #GUPnPDIDLLiteObject
1906 * Add a new author node to the @object and return the associated
1907 * #GUPnPDIDLLiteContributor object.
1909 * Returns: (transfer full): A new #GUPnPDIDLLiteContributor object. Unref after usage.
1911 GUPnPDIDLLiteContributor *
1912 gupnp_didl_lite_object_add_author (GUPnPDIDLLiteObject *object)
1916 g_return_val_if_fail (object != NULL, NULL);
1917 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
1919 res_node = xmlNewChild (object->priv->xml_node,
1920 object->priv->upnp_ns,
1921 (unsigned char *) "author",
1924 return gupnp_didl_lite_contributor_new_from_xml (res_node,
1925 object->priv->xml_doc);
1929 * gupnp_didl_lite_object_set_genre:
1930 * @object: The #GUPnPDIDLLiteObject
1933 * Set the genre of the @object to @genre.
1936 gupnp_didl_lite_object_set_genre (GUPnPDIDLLiteObject *object,
1939 g_return_if_fail (object != NULL);
1940 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
1942 xml_util_set_child (object->priv->xml_node,
1943 object->priv->upnp_ns,
1944 object->priv->xml_doc->doc,
1948 g_object_notify (G_OBJECT (object), "genre");
1952 * gupnp_didl_lite_object_set_write_status:
1953 * @object: #GUPnPDIDLLiteObject
1954 * @write_status: The write status string
1956 * Set the write status of the @object to @write_status.
1959 gupnp_didl_lite_object_set_write_status (GUPnPDIDLLiteObject *object,
1960 const char *write_status)
1962 g_return_if_fail (object != NULL);
1963 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
1965 xml_util_set_child (object->priv->xml_node,
1966 object->priv->dc_ns,
1967 object->priv->xml_doc->doc,
1971 g_object_notify (G_OBJECT (object), "write-status");
1975 * gupnp_didl_lite_object_set_album:
1976 * @object: #GUPnPDIDLLiteObject
1977 * @album: The album string
1979 * Set the album of the @object to @album.
1982 gupnp_didl_lite_object_set_album (GUPnPDIDLLiteObject *object,
1985 g_return_if_fail (object != NULL);
1986 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
1988 xml_util_set_child (object->priv->xml_node,
1989 object->priv->upnp_ns,
1990 object->priv->xml_doc->doc,
1994 g_object_notify (G_OBJECT (object), "album");
1998 * gupnp_didl_lite_object_set_album_art:
1999 * @object: #GUPnPDIDLLiteObject
2000 * @album_art: The URI of album art
2002 * Set the URI to album art of the @object to @album_art.
2005 gupnp_didl_lite_object_set_album_art (GUPnPDIDLLiteObject *object,
2006 const char *album_art)
2010 g_return_if_fail (object != NULL);
2011 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
2013 node = xml_util_set_child (object->priv->xml_node,
2014 object->priv->upnp_ns,
2015 object->priv->xml_doc->doc,
2019 object->priv->dlna_ns,
2020 (const unsigned char *) "profileID",
2021 (const unsigned char *) "JPEG_TN");
2023 g_object_notify (G_OBJECT (object), "album-art");
2027 * gupnp_didl_lite_object_set_description:
2028 * @object: #GUPnPDIDLLiteObject
2029 * @description: The description string
2031 * Set the description of the @object to @description.
2034 gupnp_didl_lite_object_set_description (GUPnPDIDLLiteObject *object,
2035 const char *description)
2037 g_return_if_fail (object != NULL);
2038 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
2040 xml_util_set_child (object->priv->xml_node,
2041 object->priv->dc_ns,
2042 object->priv->xml_doc->doc,
2046 g_object_notify (G_OBJECT (object), "description");
2050 * gupnp_didl_lite_object_set_date:
2051 * @object: #GUPnPDIDLLiteObject
2052 * @date: The date string
2054 * Set the date of the @object to @date.
2057 gupnp_didl_lite_object_set_date (GUPnPDIDLLiteObject *object,
2060 g_return_if_fail (object != NULL);
2061 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
2063 xml_util_set_child (object->priv->xml_node,
2064 object->priv->dc_ns,
2065 object->priv->xml_doc->doc,
2069 g_object_notify (G_OBJECT (object), "date");
2073 * gupnp_didl_lite_object_set_track_number:
2074 * @object: #GUPnPDIDLLiteObject
2075 * @track_number: The original track number
2077 * Set the original track number of the @object to @track_number.
2080 gupnp_didl_lite_object_set_track_number (GUPnPDIDLLiteObject *object,
2085 g_return_if_fail (object != NULL);
2086 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
2088 str = g_strdup_printf ("%d", track_number);
2089 xml_util_set_child (object->priv->xml_node,
2090 object->priv->upnp_ns,
2091 object->priv->xml_doc->doc,
2092 "originalTrackNumber",
2096 g_object_notify (G_OBJECT (object), "track-number");
2100 * gupnp_didl_lite_object_set_dlna_managed:
2101 * @object: #GUPnPDIDLLiteObject
2102 * @dlna_managed: The #GUPnPOCMFlags.
2104 * Set the 'dlna:dlnaManaged' attribute of the @object to @dlna_managed.
2107 gupnp_didl_lite_object_set_dlna_managed (GUPnPDIDLLiteObject *object,
2108 GUPnPOCMFlags dlna_managed)
2112 g_return_if_fail (object != NULL);
2113 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
2115 str = g_strdup_printf ("%08x", dlna_managed);
2116 xmlSetNsProp (object->priv->xml_node,
2117 object->priv->dlna_ns,
2118 (const unsigned char *) "dlnaManaged",
2119 (const unsigned char *) str);
2122 g_object_notify (G_OBJECT (object), "dlna-managed");
2126 * gupnp_didl_lite_object_set_update_id:
2127 * @object: #GUPnPDIDLLiteObject
2128 * @update_id: Update ID
2130 * Set the update ID of the @object.
2133 gupnp_didl_lite_object_set_update_id (GUPnPDIDLLiteObject *object,
2138 g_return_if_fail (object != NULL);
2139 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
2141 str = g_strdup_printf ("%u", update_id);
2142 xml_util_set_child (object->priv->xml_node,
2143 object->priv->upnp_ns,
2144 object->priv->xml_doc->doc,
2149 g_object_notify (G_OBJECT (object), "update-id");
2153 * gupnp_didl_lite_object_unset_update_id:
2154 * @object: #GUPnPDIDLLiteObject
2156 * Unset the update ID property of the @object.
2159 gupnp_didl_lite_object_unset_update_id (GUPnPDIDLLiteObject *object)
2161 g_return_if_fail (object != NULL);
2162 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
2164 xml_util_unset_child (object->priv->xml_node,
2167 g_object_notify (G_OBJECT (object), "update-id");
2171 * gupnp_didl_lite_object_add_resource:
2172 * @object: A #GUPnPDIDLLiteObject
2174 * Creates a new resource, attaches it to @object and returns it.
2176 * Returns: (transfer full): A new #GUPnPDIDLLiteResource object. Unref after usage.
2178 GUPnPDIDLLiteResource *
2179 gupnp_didl_lite_object_add_resource (GUPnPDIDLLiteObject *object)
2183 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
2185 res_node = xmlNewChild (object->priv->xml_node,
2187 (unsigned char *) "res",
2190 return gupnp_didl_lite_resource_new_from_xml (res_node,
2191 object->priv->xml_doc,
2192 object->priv->dlna_ns,
2193 object->priv->pv_ns);
2197 * gupnp_didl_lite_object_add_descriptor:
2198 * @object: A #GUPnPDIDLLiteObject
2200 * Creates a new descriptor, attaches it to @object and returns it.
2202 * Returns: (transfer full): A new #GUPnPDIDLLiteDescriptor object. Unref after usage.
2204 GUPnPDIDLLiteDescriptor *
2205 gupnp_didl_lite_object_add_descriptor (GUPnPDIDLLiteObject *object)
2209 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
2211 desc_node = xmlNewChild (object->priv->xml_node,
2213 (unsigned char *) "desc",
2216 return gupnp_didl_lite_descriptor_new_from_xml (desc_node,
2217 object->priv->xml_doc);
2221 * gupnp_didl_lite_object_get_title_xml_string:
2222 * @object: A #GUPnPDIDLLiteObject
2224 * Creates a string representation of the DIDL-Lite XML fragment related to the
2227 * Return value: A DIDL-Lite XML fragment string, or %NULL. #g_free after usage.
2230 gupnp_didl_lite_object_get_title_xml_string (GUPnPDIDLLiteObject *object)
2232 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
2234 return xml_util_get_child_string (object->priv->xml_node,
2235 object->priv->xml_doc->doc,
2240 * gupnp_didl_lite_object_get_date_xml_string:
2241 * @object: A #GUPnPDIDLLiteObject
2243 * Creates a string representation of the DIDL-Lite XML fragment related to the
2246 * Return value: A DIDL-Lite XML fragment string, or %NULL. #g_free after usage.
2249 gupnp_didl_lite_object_get_date_xml_string (GUPnPDIDLLiteObject *object)
2251 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
2253 return xml_util_get_child_string (object->priv->xml_node,
2254 object->priv->xml_doc->doc,
2259 * gupnp_didl_lite_object_get_upnp_class_xml_string:
2260 * @object: A #GUPnPDIDLLiteObject
2262 * Creates a string representation of the DIDL-Lite XML fragment related to the
2263 * object UPnP class.
2265 * Return value: A DIDL-Lite XML fragment string, or %NULL. #g_free after usage.
2268 gupnp_didl_lite_object_get_upnp_class_xml_string (GUPnPDIDLLiteObject *object)
2270 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
2272 return xml_util_get_child_string (object->priv->xml_node,
2273 object->priv->xml_doc->doc,
2278 * gupnp_didl_lite_object_get_album_xml_string:
2279 * @object: A #GUPnPDIDLLiteObject
2281 * Creates a string representation of the DIDL-Lite XML fragment related to the
2284 * Return value: A DIDL-Lite XML fragment string, or %NULL. #g_free after usage.
2287 gupnp_didl_lite_object_get_album_xml_string (GUPnPDIDLLiteObject *object)
2289 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
2291 return xml_util_get_child_string (object->priv->xml_node,
2292 object->priv->xml_doc->doc,
2297 * gupnp_didl_lite_object_get_track_number_xml_string:
2298 * @object: A #GUPnPDIDLLiteObject
2300 * Creates a string representation of the DIDL-Lite XML fragment related to the
2301 * object track number.
2303 * Return value: A DIDL-Lite XML fragment string, or %NULL. #g_free after usage.
2306 gupnp_didl_lite_object_get_track_number_xml_string (GUPnPDIDLLiteObject *object)
2308 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
2310 return xml_util_get_child_string (object->priv->xml_node,
2311 object->priv->xml_doc->doc,
2312 "originalTrackNumber");
2316 * gupnp_didl_lite_object_get_artists_xml_string:
2317 * @object: A #GUPnPDIDLLiteObject
2319 * Creates a string representation of the DIDL-Lite XML fragments related to the
2322 * Return value: A DIDL-Lite XML fragment string, or %NULL. #g_free after usage.
2325 gupnp_didl_lite_object_get_artists_xml_string (GUPnPDIDLLiteObject *object)
2327 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
2329 return get_contributors_xml_string_by_name (object, "artist");
2333 * gupnp_didl_lite_object_unset_artists:
2334 * @object: #GUPnPDIDLLiteObject
2336 * Unset the artists properties of the @object.
2339 gupnp_didl_lite_object_unset_artists (GUPnPDIDLLiteObject *object)
2341 g_return_if_fail (object != NULL);
2342 g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
2344 unset_contributors_by_name (object, "artist");
2346 g_object_notify (G_OBJECT (object), "artist");
2349 /* GENERAL DOCS ABOUT FRAGMENT APPLYING.
2351 * The function applying fragments takes two arrays of fragments. One
2352 * array contains current fragments and another one contains new
2353 * fragments. Both arrays have to be of equal length and have more
2354 * then zero elements. Each of fragments in both arrays make a pair
2355 * (i.e. first/second/third/... fragment in current array and
2356 * first/second/third/... fragment in new array form a pair). Each
2357 * fragment can have zero, one or more XML elements.
2359 * For each fragment pair first we check if current fragment is indeed
2360 * a part of this object's document. If it is then we check validity
2361 * of new fragment for applying. If it is then we replace the current
2362 * fragment with new fragment in object's document copy and validate
2363 * the modified document against didl-lite schema. After all fragment
2364 * pairs are processed we replace a part describing this object in
2365 * original document with respective one in modified document.
2367 * Checking if current fragment is a part of object's document is in
2368 * essence checking for deep equality of document's node and this
2369 * fragment (i.e. element name and properties have to be equal, same
2372 * Checking if new fragment is valid for applying is about checking
2373 * whether element in new fragment is either a context (i.e. both
2374 * current element and new element are deep equal) or element
2375 * modification (i.e. changes attributes but element name is still the
2376 * same). There may be a case when there are more elements in current
2377 * fragment than in new fragment then those excessive elements are
2378 * checked whether they can be really removed. The other case is when
2379 * there are more elements in new fragments than in current fragment -
2380 * in such situation we check if additions are valid.
2382 * By checking validity of modification, removals or additions we mean
2383 * that no read-only properties are changed. Additionaly, for
2384 * removals, we check if required properties are not removed.
2386 * This approach may fail in some more twisted cases.
2390 * gupnp_didl_lite_object_apply_fragments:
2391 * @object: The #GUPnPDIDLLiteObject
2392 * @current_fragments: (array length=current_size) (transfer none): XML
2393 * fragments of @object.
2394 * @current_size: Size of @current_fragments or -1.
2395 * @new_fragments: (array length=new_size) (transfer none): Substitutes
2396 * for @current_fragments.
2397 * @new_size: Size of @new_fragments or -1.
2399 * Updates object by applying @new_fragments in places of
2400 * @current_fragments. For @current_size and @new_size -1 can be
2401 * passed when respectively @current_fragments and @new_fragments are
2404 * Returns: Result of operation.
2406 GUPnPDIDLLiteFragmentResult
2407 gupnp_didl_lite_object_apply_fragments (GUPnPDIDLLiteObject *object,
2408 gchar **current_fragments,
2410 gchar **new_fragments,
2415 GUPnPDIDLLiteFragmentResult result;
2418 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object),
2419 GUPNP_DIDL_LITE_FRAGMENT_RESULT_UNKNOWN_ERROR);
2420 g_return_val_if_fail (current_fragments != NULL,
2421 GUPNP_DIDL_LITE_FRAGMENT_RESULT_CURRENT_INVALID);
2422 g_return_val_if_fail (new_fragments != NULL,
2423 GUPNP_DIDL_LITE_FRAGMENT_RESULT_NEW_INVALID);
2425 result = GUPNP_DIDL_LITE_FRAGMENT_RESULT_OK;
2426 modified.doc = NULL;
2428 if (current_size < 0)
2429 current_size = g_strv_length (current_fragments);
2431 new_size = g_strv_length (new_fragments);
2433 if (current_size != new_size) {
2434 result = GUPNP_DIDL_LITE_FRAGMENT_RESULT_MISMATCH;
2439 if (!current_size) {
2440 result = GUPNP_DIDL_LITE_FRAGMENT_RESULT_CURRENT_INVALID;
2445 original.doc = object->priv->xml_doc->doc;
2446 original.node = object->priv->xml_node;
2447 modified.doc = xmlCopyDoc (original.doc, 1);
2449 if (modified.doc == NULL) {
2450 result = GUPNP_DIDL_LITE_FRAGMENT_RESULT_UNKNOWN_ERROR;
2455 modified.node = xml_util_find_node (modified.doc->children,
2458 if (modified.node == NULL) {
2459 result = GUPNP_DIDL_LITE_FRAGMENT_RESULT_UNKNOWN_ERROR;
2464 for (iter = 0; iter < new_size; ++iter) {
2465 const gchar *current_fragment = current_fragments[iter];
2466 const gchar *new_fragment = new_fragments[iter];
2468 result = fragment_util_check_fragments (&original,
2474 if (result != GUPNP_DIDL_LITE_FRAGMENT_RESULT_OK)
2478 if (!fragment_util_apply_modification (&object->priv->xml_node,
2480 result = GUPNP_DIDL_LITE_FRAGMENT_RESULT_UNKNOWN_ERROR;
2482 if (modified.doc != NULL)
2483 xmlFreeDoc (modified.doc);
2488 * gupnp_didl_lite_object_get_xml_string:
2489 * @object: #GUPnPDIDLLiteObject
2491 * Get the representation of this object as an XML string.
2492 * Returns: (transfer full): XML representation of this object as string.
2495 gupnp_didl_lite_object_get_xml_string (GUPnPDIDLLiteObject *object)
2497 xmlBuffer *buffer = NULL;
2500 buffer = xmlBufferCreate ();
2501 xmlNodeDump (buffer,
2502 object->priv->xml_doc->doc,
2503 object->priv->xml_node,
2507 ret = g_strndup ((char *) xmlBufferContent (buffer),
2508 xmlBufferLength (buffer));
2509 xmlBufferFree (buffer);