[gupnp-av] Sanity check for @restricted DIDL attribute



commit 766604c84c4c058f02a02f1b4eb03a2456bd0a2b
Author: Santakivi Topi <Topi Santakivi digia com>
Date:   Mon Jun 13 09:46:53 2011 +0300

    Sanity check for @restricted DIDL attribute
    
    Added sanity check for the @restricted DIDL-Lite XML attribute into the
    DIDL-Lite parser.
    
    This is needed for satisfying DLNA guideline 7.3.134.1.
    
    Co-author: Zeeshan Ali (Khattak) <zeeshanak gnome org>

 libgupnp-av/gupnp-didl-lite-parser.c |   23 ++++++++++++++++++++++-
 libgupnp-av/xml-util.c               |   19 +++++++++++++++++++
 libgupnp-av/xml-util.h               |    4 ++++
 3 files changed, 45 insertions(+), 1 deletions(-)
---
diff --git a/libgupnp-av/gupnp-didl-lite-parser.c b/libgupnp-av/gupnp-didl-lite-parser.c
index 18e4c89..aa2d07a 100644
--- a/libgupnp-av/gupnp-didl-lite-parser.c
+++ b/libgupnp-av/gupnp-didl-lite-parser.c
@@ -45,6 +45,12 @@ enum {
 
 static guint signals[SIGNAL_LAST];
 
+static gboolean
+verify_didl_attributes (xmlNode *node)
+{
+    return xml_util_verify_attribute_is_boolean (node, "restricted");
+}
+
 static void
 gupnp_didl_lite_parser_init (GUPnPDIDLLiteParser *parser)
 {
@@ -165,6 +171,7 @@ gupnp_didl_lite_parser_parse_didl (GUPnPDIDLLiteParser *parser,
 {
         xmlDoc       *doc;
         xmlNode      *element;
+        xmlNode      *node;
         xmlNs       **ns_list;
         xmlNs        *upnp_ns = NULL;
         xmlNs        *dc_ns   = NULL;
@@ -271,11 +278,25 @@ gupnp_didl_lite_parser_parse_didl (GUPnPDIDLLiteParser *parser,
                                         signals[CONTAINER_AVAILABLE],
                                         0,
                                         object);
-                else if (GUPNP_IS_DIDL_LITE_ITEM (object))
+                else if (GUPNP_IS_DIDL_LITE_ITEM (object)) {
+                        node = gupnp_didl_lite_object_get_xml_node(object);
+                        if (!verify_didl_attributes(node)) {
+                            g_object_unref (object);
+                            g_object_unref (xml_doc);
+                            g_set_error (error,
+                                         GUPNP_XML_ERROR,
+                                         GUPNP_XML_ERROR_INVALID_ATTRIBUTE,
+                                         "Could not parse DIDL-Lite XML:\n%s",
+                                         didl);
+
+                            return FALSE;
+                        }
+
                         g_signal_emit (parser,
                                         signals[ITEM_AVAILABLE],
                                         0,
                                         object);
+                }
 
                 g_signal_emit (parser,
                                 signals[OBJECT_AVAILABLE],
diff --git a/libgupnp-av/xml-util.c b/libgupnp-av/xml-util.c
index c927821..3f8bca3 100644
--- a/libgupnp-av/xml-util.c
+++ b/libgupnp-av/xml-util.c
@@ -213,3 +213,22 @@ xml_util_set_child (xmlNode    *parent_node,
         return node;
 }
 
+gboolean
+xml_util_verify_attribute_is_boolean (xmlNode    *node,
+                                      const char *attribute_name)
+{
+        const char *content;
+        char *str;
+
+        content = xml_util_get_attribute_content (node, attribute_name);
+        if (content == NULL)
+            return FALSE;
+
+        str = (char *) content;
+
+        return g_ascii_strcasecmp (str, "true") == 0 ||
+               g_ascii_strcasecmp (str, "yes") == 0 ||
+               g_ascii_strcasecmp (str, "false") == 0 ||
+               g_ascii_strcasecmp (str, "no") == 0;
+}
+
diff --git a/libgupnp-av/xml-util.h b/libgupnp-av/xml-util.h
index f7912d7..0d603b3 100644
--- a/libgupnp-av/xml-util.h
+++ b/libgupnp-av/xml-util.h
@@ -76,4 +76,8 @@ xml_util_set_child                      (xmlNode    *parent_node,
                                          const char *name,
                                          const char *value);
 
+G_GNUC_INTERNAL gboolean
+xml_util_verify_attribute_is_boolean    (xmlNode    *node,
+                                         const char *attribute_name);
+
 #endif /* __XML_UTIL_H__ */



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