[rygel] external: Guard against empty mandatory properties



commit 95352d2ab695ef3fd4e39ee4b7ad60e132f8cb07
Author: Jens Georg <mail jensge org>
Date:   Sat Jul 14 00:01:12 2012 +0200

    external: Guard against empty mandatory properties
    
    Also do fingerpointing against the offending service.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=644491

 src/plugins/external/Makefile.am                   |    3 +-
 src/plugins/external/rygel-external-container.vala |   21 ++++---
 .../external/rygel-external-item-factory.vala      |   11 +++-
 .../external/rygel-external-variant-util.vala      |   58 ++++++++++++++++++++
 4 files changed, 80 insertions(+), 13 deletions(-)
---
diff --git a/src/plugins/external/Makefile.am b/src/plugins/external/Makefile.am
index c6ce7c1..0cc7dc1 100644
--- a/src/plugins/external/Makefile.am
+++ b/src/plugins/external/Makefile.am
@@ -13,7 +13,8 @@ librygel_external_la_SOURCES = \
 	rygel-external-plugin.vala \
 	rygel-external-interfaces.vala \
 	rygel-external-plugin-factory.vala \
-	rygel-external-icon-factory.vala
+	rygel-external-icon-factory.vala \
+	rygel-external-variant-util.vala
 
 librygel_external_la_VALAFLAGS = $(RYGEL_COMMON_PLUGIN_VALAFLAGS)
 librygel_external_la_LIBADD = $(RYGEL_COMMON_LIBS)
diff --git a/src/plugins/external/rygel-external-container.vala b/src/plugins/external/rygel-external-container.vala
index 6bb7d5d..964faca 100644
--- a/src/plugins/external/rygel-external-container.vala
+++ b/src/plugins/external/rygel-external-container.vala
@@ -175,10 +175,10 @@ public class Rygel.External.Container : Rygel.MediaContainer,
                 var searchable = (bool) props.lookup ("Searchable");
                 props = yield props_iface.get_all (MediaObjectProxy.IFACE);
                 var path = (string) props.lookup ("Path");
-                var title = (string) props.lookup ("DisplayName");
-                if (title == null) {
-                    title = path;
-                }
+                title = get_mandatory_string_value (props,
+                                                    "DisplayName",
+                                                    path,
+                                                    this.service_name);
 
                 media_object = new Container (path,
                                               title,
@@ -244,7 +244,10 @@ public class Rygel.External.Container : Rygel.MediaContainer,
             }
 
             if (media_object == null) {
-                var title = (string) props.lookup ("DisplayName");
+                title = get_mandatory_string_value (props,
+                                                    "DisplayName",
+                                                    id,
+                                                    this.service_name);
 
                 if (type == "container") {
                     var child_count = (uint) props.lookup ("ChildCount");
@@ -312,10 +315,10 @@ public class Rygel.External.Container : Rygel.MediaContainer,
                                          DBusProxyFlags.DO_NOT_LOAD_PROPERTIES);
             var props = yield props_iface.get_all (MediaContainerProxy.IFACE);
             var child_count = (uint) props.lookup ("ChildCount");
-            var title = props.lookup ("DisplayName");
-            if (title != null) {
-                this.title = (string) title;
-            }
+            this.title = get_mandatory_string_value (props,
+                                                     "DisplayName",
+                                                     this.id,
+                                                     this.service_name);
             this.child_count = (int) child_count;
         } catch (GLib.Error property_error) {
             warning ("Failed to update information about container '%s': %s",
diff --git a/src/plugins/external/rygel-external-item-factory.vala b/src/plugins/external/rygel-external-item-factory.vala
index c3ed283..9a764a9 100644
--- a/src/plugins/external/rygel-external-item-factory.vala
+++ b/src/plugins/external/rygel-external-item-factory.vala
@@ -134,9 +134,14 @@ public class Rygel.External.ItemFactory {
     private void set_generic_metadata (MediaItem                 item,
                                        HashTable<string,Variant> props,
                                        string                    service_name) {
-        item.mime_type = this.get_string (props, "MIMEType");
-
-        var uris = (string[]) props.lookup ("URLs");
+        item.mime_type = get_mandatory_string_value (props,
+                                                     "MIMEType",
+                                                     "image/jpeg",
+                                                     service_name);
+        var uris = get_mandatory_string_list_value (props,
+                                                    "URLs",
+                                                    null,
+                                                    service_name);
         if (uris != null) {
             for (var i = 0; uris[i] != null; i++) {
                 item.add_uri (uris[i]);
diff --git a/src/plugins/external/rygel-external-variant-util.vala b/src/plugins/external/rygel-external-variant-util.vala
new file mode 100644
index 0000000..1f564c1
--- /dev/null
+++ b/src/plugins/external/rygel-external-variant-util.vala
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2012 Jens Georg <mail jensge org>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+namespace Rygel.External {
+    public static string get_mandatory_string_value
+                                    (HashTable<string, Variant> props,
+                                     string                     key,
+                                     string                     default,
+                                     string                     service_name) {
+        var value = props.lookup (key);
+        if (value == null) {
+            warning (_("External provider %s did not provide mandatory " +
+                       "property \"%s\""),
+                     service_name,
+                     key);
+
+            return default;
+        }
+
+        return (string) value;
+    }
+
+    public static string[] get_mandatory_string_list_value
+                                    (HashTable<string, Variant> props,
+                                     string                     key,
+                                     string[]?                  default,
+                                     string                     service_name) {
+        var value = props.lookup (key);
+        if (value == null) {
+            warning (_("External provider %s did not provide mandatory " +
+                       "property \"%s\""),
+                     service_name,
+                     key);
+
+            return default;
+        }
+
+        return (string[]) value;
+    }
+
+}



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