[rygel] media-export: Workaround XBox ID length limit



commit c7d3691b6ea84a43cd5097e19a5758c5bd5d8748
Author: Jens Georg <mail jensge org>
Date:   Sat Jan 2 21:10:29 2010 +0100

    media-export: Workaround XBox ID length limit
    
    XBox 360 seems to have a 64 character ID limit.

 .../rygel-media-export-query-container.vala        |   40 ++++++++++++++++---
 .../rygel-media-export-root-container.vala         |   16 +++++--
 2 files changed, 44 insertions(+), 12 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-query-container.vala b/src/plugins/media-export/rygel-media-export-query-container.vala
index 482afd0..cc2159e 100644
--- a/src/plugins/media-export/rygel-media-export-query-container.vala
+++ b/src/plugins/media-export/rygel-media-export-query-container.vala
@@ -26,6 +26,8 @@ internal class Rygel.MediaExportQueryContainer : Rygel.MediaDBContainer {
     private bool item_container;
     private string attribute;
     private SearchExpression expression;
+    private static HashMap<string,string> virtual_container_map = null;
+    public string plaintext_id;
 
     public MediaExportQueryContainer (MediaDB media_db,
                                       string  id,
@@ -45,9 +47,9 @@ internal class Rygel.MediaExportQueryContainer : Rygel.MediaDBContainer {
         //          the parts not prefixed by virtual-folder: are URL-escaped
         base (media_db, id, name);
 
-        var args = id.split(",");
-
-
+        this.plaintext_id = get_virtual_container_definition (id);
+        debug ("plaintext id is: %s", this.plaintext_id);
+        var args = this.plaintext_id.split(",");
 
         // build SearchExpression from container-id
         int i = args.length - 1 - args.length % 2;
@@ -132,11 +134,12 @@ internal class Rygel.MediaExportQueryContainer : Rygel.MediaDBContainer {
                                     offset,
                                     max_objects);
         foreach (var meta_data in data) {
-                if (meta_data == null) {
-                    continue;
-                }
+            if (meta_data == null) {
+                continue;
+            }
 
-            var new_id = this.id + "," + meta_data;
+            var new_id = this.plaintext_id + "," + meta_data;
+            new_id = register_virtual_container (new_id);
             var container = new MediaExportQueryContainer (this.media_db,
                                                            new_id,
                                                            meta_data);
@@ -147,4 +150,27 @@ internal class Rygel.MediaExportQueryContainer : Rygel.MediaDBContainer {
 
         return children;
     }
+
+    public static string register_virtual_container (string id) {
+        var md5 = Checksum.compute_for_string (ChecksumType.MD5, id);
+        if (virtual_container_map == null) {
+            virtual_container_map = new HashMap<string,string> ();
+        }
+        if (!virtual_container_map.has_key (md5)) {
+            virtual_container_map[md5] = id;
+            debug ("registering %s for %s", md5, id);
+        }
+
+        return PREFIX + md5;
+    }
+
+    public static string? get_virtual_container_definition (string hash) {
+        var id = hash.replace(PREFIX, "");
+        if (virtual_container_map != null &&
+            virtual_container_map.has_key (id)) {
+            return virtual_container_map[id];
+        }
+
+        return null;
+    }
 }
diff --git a/src/plugins/media-export/rygel-media-export-root-container.vala b/src/plugins/media-export/rygel-media-export-root-container.vala
index 442357b..f67f27e 100644
--- a/src/plugins/media-export/rygel-media-export-root-container.vala
+++ b/src/plugins/media-export/rygel-media-export-root-container.vala
@@ -108,13 +108,15 @@ public class Rygel.MediaExportRootContainer : Rygel.MediaDBContainer {
                 case "object.container.album.musicAlbum":
                     return new MediaExportQueryContainer (
                                        this.media_db,
-                                       "virtual-container:upnp:album",
+                                       MediaExportQueryContainer.register_virtual_container
+                                       ("virtual-container:upnp:album"),
                                        "Albums");
 
                 case "object.container.person.musicArtist":
                     return new MediaExportQueryContainer (
                                        this.media_db,
-                                       "virtual-container:dc:creator",
+                                       MediaExportQueryContainer.register_virtual_container
+                                       ("virtual-container:dc:creator"),
                                        "Artists");
                 default:
                     return null;
@@ -149,7 +151,9 @@ public class Rygel.MediaExportRootContainer : Rygel.MediaDBContainer {
             if (exp.operand1 == "@id" &&
                 exp.op == SearchCriteriaOp.EQ &&
                 exp.operand2.has_prefix ("virtual-container:")) {
-                var args = exp.operand2.split(",");
+                var real_id = MediaExportQueryContainer.get_virtual_container_definition
+                (exp.operand2);
+                var args = real_id.split(",");
                 query_cont = new MediaExportQueryContainer (this.media_db,
                                                             exp.operand2,
                                                             args[args.length-1]);
@@ -181,14 +185,16 @@ public class Rygel.MediaExportRootContainer : Rygel.MediaDBContainer {
             if (cont != null) {
                 string new_id = "virtual-container:" + exp_.operand1 +
                                 "," + exp_.operand2 +
-                                cont.id.replace ("virtual-container:", ",");
+                                cont.plaintext_id.replace ("virtual-container:", ",");
                 debug ("Translated search request to %s", new_id);
+                new_id = MediaExportQueryContainer.register_virtual_container
+                (new_id);
                 var query_cont_ = new MediaExportQueryContainer (this.media_db,
                                                             new_id,
                                                             exp_.operand2);
                 var list_ = yield query_cont_.get_children (offset, max_count, cancellable);
                 foreach (MediaObject o2 in list_) {
-                    o2.upnp_class = exp_.operand1;
+                    o2.upnp_class = expa.operand2;
                 }
                 total_matches = list_.size;
                 return list_;



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