summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Guiraud <christophe.guiraud@intel.com>2012-10-19 14:48:01 +0200
committerJens Georg <mail@jensge.org>2012-10-24 20:41:21 +0200
commitfa3e122287ac3a2c917d5fd07e538e4f35aaf6e6 (patch)
treeef9b1a0f78293a01f4b2c2a8974b5c515786ef5c
parent2a47233d60502fd09df8b2fc65754513391b3114 (diff)
downloadgupnp-av-fa3e122287ac3a2c917d5fd07e538e4f35aaf6e6.tar.gz
Add XML fragments getter methods to GUPnPDIDLLiteObject
CDS UpdateObject action works with property xml element fragments. - Add public functions to GUPnPDIDLLiteObject to get the xml fragments string related to some properties. char * gupnp_didl_lite_object_get_title_xml_string (...); char * gupnp_didl_lite_object_get_date_xml_string (...); char * gupnp_didl_lite_object_get_upnp_class_xml_string (...); char * gupnp_didl_lite_object_get_album_xml_string (...); char * gupnp_didl_lite_object_get_track_number_xml_string (...); char * gupnp_didl_lite_object_get_artists_xml_string (...); - Add a public function to GUPnPDIDLLiteObject to unset all the artists properties. void gupnp_didl_lite_object_unset_artists (...); - Add a helper function XML utils for xml node string extraction. char * xml_util_get_child_string (...) https://bugzilla.gnome.org/show_bug.cgi?id=686464
-rw-r--r--libgupnp-av/gupnp-didl-lite-object.c193
-rw-r--r--libgupnp-av/gupnp-didl-lite-object.h35
-rw-r--r--libgupnp-av/xml-util.c25
-rw-r--r--libgupnp-av/xml-util.h4
4 files changed, 253 insertions, 4 deletions
diff --git a/libgupnp-av/gupnp-didl-lite-object.c b/libgupnp-av/gupnp-didl-lite-object.c
index 21ad1af..e60cbe2 100644
--- a/libgupnp-av/gupnp-didl-lite-object.c
+++ b/libgupnp-av/gupnp-didl-lite-object.c
@@ -844,6 +844,70 @@ get_contributor_list_by_name (GUPnPDIDLLiteObject *object,
return ret;
}
+static char *
+get_contributors_xml_string_by_name (GUPnPDIDLLiteObject *object,
+ const char *name)
+{
+ GList *contributors = NULL;
+ char *ret = NULL;
+ GList *l;
+ xmlBuffer *buffer;
+
+ contributors = gupnp_didl_lite_object_get_properties (object, name);
+ if (contributors == NULL)
+ return NULL;
+
+ buffer = xmlBufferCreate ();
+
+ for (l = contributors; l; l = l->next) {
+ xmlNode *node;
+
+ node = (xmlNode *) l->data;
+ if (!node->children)
+ continue;
+
+ xmlNodeDump (buffer,
+ object->priv->xml_doc->doc,
+ node,
+ 0,
+ 0);
+ }
+
+ ret = g_strndup ((char *) xmlBufferContent (buffer),
+ xmlBufferLength (buffer));
+ xmlBufferFree (buffer);
+
+ g_list_free (contributors);
+
+ return ret;
+}
+
+static void
+unset_contributors_by_name (GUPnPDIDLLiteObject *object, const char *name)
+{
+ GList *contributors = NULL;
+ GList *l;
+
+ contributors = gupnp_didl_lite_object_get_properties (object, name);
+ if (contributors == NULL)
+ return;
+
+ for (l = contributors; l; l = l->next) {
+ xmlNode *node;
+
+ node = (xmlNode *) l->data;
+ if (!node->children)
+ continue;
+
+ xmlUnlinkNode (node);
+ xmlFreeNode (node);
+ }
+
+ g_list_free (contributors);
+
+ return;
+}
+
/**
* gupnp_didl_lite_object_new_from_xml:
* @xml_node: The pointer to 'res' node in XML document
@@ -2097,3 +2161,132 @@ gupnp_didl_lite_object_add_descriptor (GUPnPDIDLLiteObject *object)
return gupnp_didl_lite_descriptor_new_from_xml (desc_node,
object->priv->xml_doc);
}
+
+/**
+ * gupnp_didl_lite_object_get_title_xml_string:
+ * @object: A #GUPnPDIDLLiteObject
+ *
+ * Creates a string representation of the DIDL-Lite XML fragment related to the
+ * object title.
+ *
+ * Return value: A DIDL-Lite XML fragment string, or %NULL. #g_free after usage.
+ **/
+char *
+gupnp_didl_lite_object_get_title_xml_string (GUPnPDIDLLiteObject *object)
+{
+ g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
+
+ return xml_util_get_child_string (object->priv->xml_node,
+ object->priv->xml_doc->doc,
+ "title");
+}
+
+/**
+ * gupnp_didl_lite_object_get_date_xml_string:
+ * @object: A #GUPnPDIDLLiteObject
+ *
+ * Creates a string representation of the DIDL-Lite XML fragment related to the
+ * object date.
+ *
+ * Return value: A DIDL-Lite XML fragment string, or %NULL. #g_free after usage.
+ **/
+char *
+gupnp_didl_lite_object_get_date_xml_string (GUPnPDIDLLiteObject *object)
+{
+ g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
+
+ return xml_util_get_child_string (object->priv->xml_node,
+ object->priv->xml_doc->doc,
+ "date");
+}
+
+/**
+ * gupnp_didl_lite_object_get_upnp_class_xml_string:
+ * @object: A #GUPnPDIDLLiteObject
+ *
+ * Creates a string representation of the DIDL-Lite XML fragment related to the
+ * object UPnP class.
+ *
+ * Return value: A DIDL-Lite XML fragment string, or %NULL. #g_free after usage.
+ **/
+char *
+gupnp_didl_lite_object_get_upnp_class_xml_string (GUPnPDIDLLiteObject *object)
+{
+ g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
+
+ return xml_util_get_child_string (object->priv->xml_node,
+ object->priv->xml_doc->doc,
+ "class");
+}
+
+/**
+ * gupnp_didl_lite_object_get_album_xml_string:
+ * @object: A #GUPnPDIDLLiteObject
+ *
+ * Creates a string representation of the DIDL-Lite XML fragment related to the
+ * object album.
+ *
+ * Return value: A DIDL-Lite XML fragment string, or %NULL. #g_free after usage.
+ **/
+char *
+gupnp_didl_lite_object_get_album_xml_string (GUPnPDIDLLiteObject *object)
+{
+ g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
+
+ return xml_util_get_child_string (object->priv->xml_node,
+ object->priv->xml_doc->doc,
+ "album");
+}
+
+/**
+ * gupnp_didl_lite_object_get_track_number_xml_string:
+ * @object: A #GUPnPDIDLLiteObject
+ *
+ * Creates a string representation of the DIDL-Lite XML fragment related to the
+ * object track number.
+ *
+ * Return value: A DIDL-Lite XML fragment string, or %NULL. #g_free after usage.
+ **/
+char *
+gupnp_didl_lite_object_get_track_number_xml_string (GUPnPDIDLLiteObject *object)
+{
+ g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
+
+ return xml_util_get_child_string (object->priv->xml_node,
+ object->priv->xml_doc->doc,
+ "originalTrackNumber");
+}
+
+/**
+ * gupnp_didl_lite_object_get_artists_xml_string:
+ * @object: A #GUPnPDIDLLiteObject
+ *
+ * Creates a string representation of the DIDL-Lite XML fragments related to the
+ * object artists.
+ *
+ * Return value: A DIDL-Lite XML fragment string, or %NULL. #g_free after usage.
+ **/
+char *
+gupnp_didl_lite_object_get_artists_xml_string (GUPnPDIDLLiteObject *object)
+{
+ g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object), NULL);
+
+ return get_contributors_xml_string_by_name (object, "artist");
+}
+
+/**
+ * gupnp_didl_lite_object_unset_artists:
+ * @object: #GUPnPDIDLLiteObject
+ *
+ * Unset the artists properties of the @object.
+ **/
+void
+gupnp_didl_lite_object_unset_artists (GUPnPDIDLLiteObject *object)
+{
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object));
+
+ unset_contributors_by_name (object, "artist");
+
+ g_object_notify (G_OBJECT (object), "artist");
+}
diff --git a/libgupnp-av/gupnp-didl-lite-object.h b/libgupnp-av/gupnp-didl-lite-object.h
index 8c66df1..45325d9 100644
--- a/libgupnp-av/gupnp-didl-lite-object.h
+++ b/libgupnp-av/gupnp-didl-lite-object.h
@@ -243,12 +243,12 @@ gupnp_didl_lite_object_set_album_art (GUPnPDIDLLiteObject *object,
const char *album_art);
void
-gupnp_didl_lite_object_set_description (GUPnPDIDLLiteObject *object,
- const char *description);
+gupnp_didl_lite_object_set_description (GUPnPDIDLLiteObject *object,
+ const char *description);
void
-gupnp_didl_lite_object_set_date (GUPnPDIDLLiteObject *object,
- const char *date);
+gupnp_didl_lite_object_set_date (GUPnPDIDLLiteObject *object,
+ const char *date);
void
gupnp_didl_lite_object_set_track_number (GUPnPDIDLLiteObject *object,
@@ -265,6 +265,33 @@ gupnp_didl_lite_object_set_update_id (GUPnPDIDLLiteObject *object,
void
gupnp_didl_lite_object_unset_update_id (GUPnPDIDLLiteObject *object);
+char *
+gupnp_didl_lite_object_get_title_xml_string
+ (GUPnPDIDLLiteObject *object);
+
+char *
+gupnp_didl_lite_object_get_date_xml_string
+ (GUPnPDIDLLiteObject *object);
+
+char *
+gupnp_didl_lite_object_get_upnp_class_xml_string
+ (GUPnPDIDLLiteObject *object);
+
+char *
+gupnp_didl_lite_object_get_album_xml_string
+ (GUPnPDIDLLiteObject *object);
+
+char *
+gupnp_didl_lite_object_get_track_number_xml_string
+ (GUPnPDIDLLiteObject *object);
+
+char *
+gupnp_didl_lite_object_get_artists_xml_string
+ (GUPnPDIDLLiteObject *object);
+
+void
+gupnp_didl_lite_object_unset_artists (GUPnPDIDLLiteObject *object);
+
G_END_DECLS
#endif /* __GUPNP_DIDL_LITE_OBJECT_H__ */
diff --git a/libgupnp-av/xml-util.c b/libgupnp-av/xml-util.c
index a2cfc16..4c9b100 100644
--- a/libgupnp-av/xml-util.c
+++ b/libgupnp-av/xml-util.c
@@ -275,3 +275,28 @@ xml_util_verify_attribute_is_boolean (xmlNode *node,
g_ascii_strcasecmp (str, "1") == 0;
}
+char *
+xml_util_get_child_string (xmlNode *parent_node,
+ xmlDoc *doc,
+ const char *name)
+{
+ xmlBuffer *buffer;
+ char *ret;
+ xmlNode *node;
+
+ node = xml_util_get_element (parent_node, name, NULL);
+ if (!node)
+ return NULL;
+
+ buffer = xmlBufferCreate ();
+ xmlNodeDump (buffer,
+ doc,
+ node,
+ 0,
+ 0);
+ ret = g_strndup ((char *) xmlBufferContent (buffer),
+ xmlBufferLength (buffer));
+ xmlBufferFree (buffer);
+
+ return ret;
+}
diff --git a/libgupnp-av/xml-util.h b/libgupnp-av/xml-util.h
index 4d63dc7..0bb42a8 100644
--- a/libgupnp-av/xml-util.h
+++ b/libgupnp-av/xml-util.h
@@ -96,4 +96,8 @@ G_GNUC_INTERNAL gboolean
xml_util_verify_attribute_is_boolean (xmlNode *node,
const char *attribute_name);
+G_GNUC_INTERNAL char *
+xml_util_get_child_string (xmlNode *parent_node,
+ xmlDoc *doc,
+ const char *name);
#endif /* __XML_UTIL_H__ */