[PATCH 2/2] Sanity check for @restricted DIDL attribute



Added sanity check for the @restricted
DIDL-Lite XML attribute into the DIDL parser,
needed for satisfying DLNA guideline 7.3.134.1.
---
 libgupnp-av/gupnp-didl-lite-parser.c |   33 ++++++++++++++++++++++++++++++++-
 libgupnp-av/xml-util.c               |   21 +++++++++++++++++++++
 libgupnp-av/xml-util.h               |    4 ++++
 3 files changed, 57 insertions(+), 1 deletions(-)

diff --git a/libgupnp-av/gupnp-didl-lite-parser.c b/libgupnp-av/gupnp-didl-lite-parser.c
index 18e4c89..eb140ce 100644
--- a/libgupnp-av/gupnp-didl-lite-parser.c
+++ b/libgupnp-av/gupnp-didl-lite-parser.c
@@ -147,6 +147,22 @@ gupnp_didl_lite_parser_new (void)
 }
 
 /**
+ * gupnp_didl_lite_parser_verify_didl_attributes
+ *
+ * Return value: TRUE on attributes having appropriate values
+ **/
+gboolean
+gupnp_didl_lite_parser_verify_didl_attributes (xmlNode *node)
+{
+    if (!xml_util_verify_attribute_is_boolean
+        (node, "restricted")) {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+/**
  * gupnp_didl_lite_parser_parse_didl
  * @parser: A #GUPnPDIDLLiteParser
  * @didl: The DIDL-Lite XML string to be parsed
@@ -165,6 +181,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 +288,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 (!gupnp_didl_lite_parser_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..da6f7cf 100644
--- a/libgupnp-av/xml-util.c
+++ b/libgupnp-av/xml-util.c
@@ -213,3 +213,24 @@ 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;
+        gchar   *str;
+
+        content = xml_util_get_attribute_content (node, attribute_name);
+        if (!content)
+            return FALSE;
+
+        str = (char *) content;
+        if (g_ascii_strcasecmp (str, "true") == 0 ||
+            g_ascii_strcasecmp (str, "yes") == 0 ||
+            g_ascii_strcasecmp (str, "false") == 0 ||
+            g_ascii_strcasecmp (str, "no") == 0) {
+            return TRUE;
+        }
+        return FALSE;
+}
+
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__ */
-- 
1.7.1


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