[rygel] core: Modify URI generation scheme



commit fb0e0f3eee7134ba921ed58a8b7ab0d5049c128a
Author: Jens Georg <mail jensge org>
Date:   Wed Nov 4 12:52:48 2009 +0100

    core: Modify URI generation scheme
    
    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 |   47 +++++++++++++++++++------------------
 src/rygel/rygel-http-server.vala  |   11 ++++----
 2 files changed, 29 insertions(+), 29 deletions(-)
---
diff --git a/src/rygel/rygel-http-request.vala b/src/rygel/rygel-http-request.vala
index f3a499b..0bd12f6 100644
--- a/src/rygel/rygel-http-request.vala
+++ b/src/rygel/rygel-http-request.vala
@@ -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;
+                }
+            }
         }
     }
 
diff --git a/src/rygel/rygel-http-server.vala b/src/rygel/rygel-http-server.vala
index d67a9e3..7455875 100644
--- a/src/rygel/rygel-http-server.vala
+++ b/src/rygel/rygel-http-server.vala
@@ -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";



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