core: Modify URI generation scheme
authorJens Georg <mail@jensge.org>
Wed, 4 Nov 2009 11:52:48 +0000 (12:52 +0100)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Mon, 28 Dec 2009 15:52:03 +0000 (17:52 +0200)
Some UPnP devices cannot cope with urls containing GET parameters and just
skip everything after the "?". This commit modifies the uris to use different
paths instead of GET parameters.

src/rygel/rygel-http-request.vala
src/rygel/rygel-http-server.vala

index f3a499b..0bd12f6 100644 (file)
@@ -80,11 +80,7 @@ internal class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
             return;
         }
 
-        try {
-            this.parse_query ();
-        } catch (Error err) {
-            warning ("Failed to parse query: %s", err.message);
-        }
+        this.parse_uri ();
 
         if (this.item_id == null) {
             this.handle_error (new HTTPRequestError.NOT_FOUND ("Not Found"));
@@ -159,24 +155,29 @@ internal class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
         }
     }
 
-    private void parse_query () throws Error {
-        if (this.query == null) {
-            return;
-        }
-
-        this.item_id = this.query.lookup ("itemid");
-        var target = this.query.lookup ("transcode");
-        if (target != null) {
-            debug ("Transcoding target: %s", target);
-
-            var transcoder = this.http_server.get_transcoder (target);
-            this.handler = new HTTPTranscodeHandler (transcoder,
-                                                     this.cancellable);
-        }
-
-        var index = this.query.lookup ("thumbnail");
-        if (index != null) {
-            this.thumbnail_index = index.to_int ();
+    private void parse_uri () {
+        // do not decode the path here as it may contain encoded slashes
+        var request_uri = this.msg.get_uri ().path.replace (this.http_server.path_root, "");
+        var parts = request_uri.split ("/");
+        if (parts.length < 2 && parts.length % 2 != 0)
+            warning ("Invalid uri %s", request_uri);
+        else {
+            this.item_id = Soup.URI.decode (parts[1]);
+            for (int i = 2; i < parts.length - 1; i += 2) {
+                switch (parts[i]) {
+                    case "transcoded":
+                        var transcoder = this.http_server.get_transcoder (
+                                               Soup.URI.decode (parts[i + 1]));
+                        this.handler = new HTTPTranscodeHandler (transcoder,
+                                                                 this.cancellable);
+                    break;
+                    case "thumbnail":
+                        this.thumbnail_index = parts[i + 1].to_int ();
+                        break;
+                    default:
+                        break;
+                }
+            }
         }
     }
 
index d67a9e3..7455875 100644 (file)
@@ -27,7 +27,7 @@ using Gee;
 
 internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine {
     private const string SERVER_PATH_PREFIX = "/RygelHTTPServer";
-    private string path_root;
+    public string path_root { get; private set; }
 
     // Reference to root container of associated ContentDirectory
     public MediaContainer root_container;
@@ -129,14 +129,13 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine {
                                                   string?   transcode_target,
                                                   out string protocol) {
         string escaped = Uri.escape_string (item.id, "", true);
-        string query = "?itemid=" + escaped;
-        if (thumbnail_index >= 0) {
-            query += "&thumbnail=" + thumbnail_index.to_string ();
-        }
+        string query = "/" + escaped;
 
         if (transcode_target != null) {
             escaped = Uri.escape_string (transcode_target, "", true);
-            query += "&transcode=" + escaped;
+            query += "/transcoded/" + escaped;
+        } else if (thumbnail_index >= 0) {
+            query += "/thumbnail/" + thumbnail_index.to_string ();
         }
 
         protocol = "http-get";