[gupnp-av/wip/didl-s: 2/2] Add tag-only filter function to writer



commit 47125b184127829c129d5ab303204c2eec986556
Author: Jens Georg <mail jensge org>
Date:   Wed Oct 31 15:26:05 2012 +0100

    Add tag-only filter function to writer
    
    This is used for DIDL-S playlist generation that allows a certain subset of
    tags but all attributes on those.

 libgupnp-av/gupnp-didl-lite-writer.c |   86 +++++++++++++++++++++++----------
 libgupnp-av/gupnp-didl-lite-writer.h |    4 ++
 2 files changed, 64 insertions(+), 26 deletions(-)
---
diff --git a/libgupnp-av/gupnp-didl-lite-writer.c b/libgupnp-av/gupnp-didl-lite-writer.c
index 5f7812d..dea0ad7 100644
--- a/libgupnp-av/gupnp-didl-lite-writer.c
+++ b/libgupnp-av/gupnp-didl-lite-writer.c
@@ -198,7 +198,8 @@ filter_attributes (xmlNode             *node,
 static void
 filter_node (xmlNode             *node,
              GList               *allowed,
-             GUPnPDIDLLiteWriter *writer)
+             GUPnPDIDLLiteWriter *writer,
+             gboolean             tags_only)
 {
         xmlNode *child;
         GList   *forbidden = NULL;
@@ -206,7 +207,8 @@ filter_node (xmlNode             *node,
         gboolean is_container;
         const char *container_class = NULL;
 
-        filter_attributes (node, allowed, writer);
+        if (!tags_only)
+                filter_attributes (node, allowed, writer);
 
         if (strcmp ((const char *) node->name, "container") == 0) {
             is_container = TRUE;
@@ -250,10 +252,42 @@ filter_node (xmlNode             *node,
         /* Recurse */
         for (child = node->children; child != NULL; child = child->next)
                 if (!xmlNodeIsText (child))
-                        filter_node (child, allowed, writer);
+                        filter_node (child, allowed, writer, tags_only);
 }
 
 static void
+apply_filter (GUPnPDIDLLiteWriter *writer,
+              const char          *filter,
+              gboolean             tags_only)
+{
+        char **tokens;
+        GList *allowed = NULL;
+        unsigned short i;
+        xmlNode *node;
+
+        g_return_if_fail (GUPNP_IS_DIDL_LITE_WRITER (writer));
+        g_return_if_fail (filter != NULL);
+
+        if (filter[0] == '*')
+                return;         /* Wildcard */
+
+        tokens = g_strsplit (filter, ",", -1);
+        g_return_if_fail (tokens != NULL);
+
+        for (i = 0; tokens[i] != NULL; i++)
+                allowed = g_list_append (allowed, tokens[i]);
+
+        for (node = writer->priv->xml_node->children;
+             node != NULL;
+             node = node->next)
+                filter_node (node, allowed, writer, tags_only);
+
+        g_list_free (allowed);
+        g_strfreev (tokens);
+}
+
+
+static void
 gupnp_didl_lite_writer_init (GUPnPDIDLLiteWriter *writer)
 {
         writer->priv = G_TYPE_INSTANCE_GET_PRIVATE (writer,
@@ -651,28 +685,28 @@ void
 gupnp_didl_lite_writer_filter (GUPnPDIDLLiteWriter *writer,
                                const char          *filter)
 {
-        char **tokens;
-        GList *allowed = NULL;
-        unsigned short i;
-        xmlNode *node;
-
-        g_return_if_fail (GUPNP_IS_DIDL_LITE_WRITER (writer));
-        g_return_if_fail (filter != NULL);
-
-        if (filter[0] == '*')
-                return;         /* Wildcard */
-
-        tokens = g_strsplit (filter, ",", -1);
-        g_return_if_fail (tokens != NULL);
-
-        for (i = 0; tokens[i] != NULL; i++)
-                allowed = g_list_append (allowed, tokens[i]);
-
-        for (node = writer->priv->xml_node->children;
-             node != NULL;
-             node = node->next)
-                filter_node (node, allowed, writer);
+        apply_filter (writer, filter, FALSE);
+}
 
-        g_list_free (allowed);
-        g_strfreev (tokens);
+/**
+ * gupnp_didl_lite_writer_filter_tags:
+ * @writer: A #GUPnPDIDLLiteWriter
+ * @filter: A filter string
+ *
+ * Clears the DIDL-Lite XML document of the properties not specified in the
+ * @filter. The passed filter string would typically come from the 'Filter'
+ * argument of Browse or Search actions from a ContentDirectory control point.
+ * Please refer to Section 2.3.15 of UPnP AV ContentDirectory version 3
+ * specification for details on this string.
+ *
+ * In contrast to gupnp_didl_lite_writer_filter(), this function only removes
+ * unwanted tags but leaves all attributes in-place.
+ *
+ * Return value: None.
+ **/
+void
+gupnp_didl_lite_writer_filter_tags (GUPnPDIDLLiteWriter *writer,
+                                    const char          *filter)
+{
+        apply_filter (writer, filter, TRUE);
 }
diff --git a/libgupnp-av/gupnp-didl-lite-writer.h b/libgupnp-av/gupnp-didl-lite-writer.h
index 123ead8..3dbaa7c 100644
--- a/libgupnp-av/gupnp-didl-lite-writer.h
+++ b/libgupnp-av/gupnp-didl-lite-writer.h
@@ -111,6 +111,10 @@ void
 gupnp_didl_lite_writer_filter           (GUPnPDIDLLiteWriter   *writer,
                                          const char            *filter);
 
+void
+gupnp_didl_lite_writer_filter_tags      (GUPnPDIDLLiteWriter   *writer,
+                                         const char            *filter);
+
 G_END_DECLS
 
 #endif /* __GUPNP_DIDL_LITE_WRITER_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]