[rygel/wip/new-gupnp: 6/7] server: Fix client hacks




commit 3ab1e50f1a04cdebea6665a930fade790721ba6b
Author: Jens Georg <mail jensge org>
Date:   Sat May 7 15:41:09 2022 +0200

    server: Fix client hacks

 src/librygel-server/rygel-client-hacks.vala           |  9 ++++-----
 src/librygel-server/rygel-http-byte-seek-request.vala |  2 --
 src/librygel-server/rygel-http-request.vala           | 15 +++++++++++----
 src/librygel-server/rygel-http-time-seek-request.vala |  2 --
 src/librygel-server/rygel-lg-tv-hacks.vala            |  2 +-
 src/librygel-server/rygel-media-query-action.vala     |  2 --
 src/librygel-server/rygel-panasonic-hacks.vala        |  2 +-
 src/librygel-server/rygel-phillips-hacks.vala         |  2 +-
 src/librygel-server/rygel-samsung-tv-hacks.vala       |  2 +-
 src/librygel-server/rygel-seek-hacks.vala             |  2 +-
 src/librygel-server/rygel-wmp-hacks.vala              |  2 +-
 src/librygel-server/rygel-xbmc-hacks.vala             |  2 +-
 src/librygel-server/rygel-xbmc4xbox-hacks.vala        |  2 +-
 src/librygel-server/rygel-xbox-hacks.vala             | 10 ++++------
 14 files changed, 27 insertions(+), 29 deletions(-)
---
diff --git a/src/librygel-server/rygel-client-hacks.vala b/src/librygel-server/rygel-client-hacks.vala
index 82ddaf7e..c8c8b88f 100644
--- a/src/librygel-server/rygel-client-hacks.vala
+++ b/src/librygel-server/rygel-client-hacks.vala
@@ -39,8 +39,8 @@ internal abstract class Rygel.ClientHacks : GLib.Object {
                                       default = CORRECT_OBJECT_ID; }
     protected Regex agent_regex;
 
-    protected ClientHacks (string   agent,
-                           Message? message)
+    protected ClientHacks (string agent,
+                           ServerMessage? message)
                            throws ClientHacksError {
         try {
             this.agent_regex = new Regex (agent,
@@ -57,12 +57,11 @@ internal abstract class Rygel.ClientHacks : GLib.Object {
         }
     }
 
-    public static ClientHacks create (Message? message)
+    public static ClientHacks create (ServerMessage? message)
                                       throws ClientHacksError {
         try {
             return new PanasonicHacks (message);
         } catch (Error error) { }
-
         try {
             return new XBMC4XBoxHacks (message);
         } catch (Error error) { }
@@ -127,7 +126,7 @@ internal abstract class Rygel.ClientHacks : GLib.Object {
                                        out total_matches);
     }
 
-    private void check_headers (Message message)
+    private void check_headers (ServerMessage message)
                                           throws ClientHacksError {
         var headers = message.get_request_headers();
         var remote_ip = "127.0.0.1"; //message.get_remote_host ();
diff --git a/src/librygel-server/rygel-http-byte-seek-request.vala 
b/src/librygel-server/rygel-http-byte-seek-request.vala
index cefd92cf..98ea4121 100644
--- a/src/librygel-server/rygel-http-byte-seek-request.vala
+++ b/src/librygel-server/rygel-http-byte-seek-request.vala
@@ -133,12 +133,10 @@ public class Rygel.HTTPByteSeekRequest : Rygel.HTTPSeekRequest {
                                   Rygel.HTTPGetHandler handler) {
         bool force_seek = false;
 
-#if 0
         try {
             var hack = ClientHacks.create (message);
             force_seek = hack.force_seek ();
         } catch (Error error) { }
-#endif
 
         return force_seek || handler.supports_byte_seek ();
     }
diff --git a/src/librygel-server/rygel-http-request.vala b/src/librygel-server/rygel-http-request.vala
index fd13b06c..283c0cd2 100644
--- a/src/librygel-server/rygel-http-request.vala
+++ b/src/librygel-server/rygel-http-request.vala
@@ -57,19 +57,26 @@ public abstract class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
         this.server = server;
         this.msg = msg;
 
-#if 0
         try {
             this.hack = ClientHacks.create (msg);
         } catch (Error error) { }
-#endif
     }
 
     public async void run () {
         this.server.pause_message (this.msg);
 
         try {
-            this.uri = new HTTPItemURI.from_string (this.msg.get_uri().get_path (),
-                                                    this.http_server);
+            // If a hack as rewritten the request uri, it will have added a
+            // "Location" header, so we use that.
+            var location = this.msg.get_response_headers ().get_one ("Location");
+            string path;
+            if (location != null) {
+                path = GLib.Uri.parse (location, GLib.UriFlags.NONE).get_path ();
+            } else {
+                path = this.msg.get_uri ().get_path ();
+            }
+
+            this.uri = new HTTPItemURI.from_string (path, this.http_server);
 
             yield this.find_item ();
 
diff --git a/src/librygel-server/rygel-http-time-seek-request.vala 
b/src/librygel-server/rygel-http-time-seek-request.vala
index 26e2ce84..97db371a 100644
--- a/src/librygel-server/rygel-http-time-seek-request.vala
+++ b/src/librygel-server/rygel-http-time-seek-request.vala
@@ -209,12 +209,10 @@ public class Rygel.HTTPTimeSeekRequest : Rygel.HTTPSeekRequest {
                                   HTTPGetHandler handler) {
         bool force_seek = false;
 
-#if 0
         try {
             var hack = ClientHacks.create (message);
             force_seek = hack.force_seek ();
         } catch (Error error) { /* Exception means no hack needed */ }
-#endif
 
         return force_seek || handler.supports_time_seek ();
     }
diff --git a/src/librygel-server/rygel-lg-tv-hacks.vala b/src/librygel-server/rygel-lg-tv-hacks.vala
index 9464d4f5..10394f53 100644
--- a/src/librygel-server/rygel-lg-tv-hacks.vala
+++ b/src/librygel-server/rygel-lg-tv-hacks.vala
@@ -26,7 +26,7 @@ using GUPnP;
 internal class Rygel.LGTVHacks : ClientHacks {
     private const string AGENT = ".*LGE_DLNA_SDK.*";
 
-    public LGTVHacks (Message? message = null) throws ClientHacksError {
+    public LGTVHacks (ServerMessage? message = null) throws ClientHacksError {
         base (AGENT, message);
     }
 
diff --git a/src/librygel-server/rygel-media-query-action.vala 
b/src/librygel-server/rygel-media-query-action.vala
index f5eb50f0..af4c2083 100644
--- a/src/librygel-server/rygel-media-query-action.vala
+++ b/src/librygel-server/rygel-media-query-action.vala
@@ -60,11 +60,9 @@ internal abstract class Rygel.MediaQueryAction : GLib.Object, StateMachine {
 
         this.serializer = new Serializer (SerializerType.GENERIC_DIDL);
 
-#if 0
         try {
             this.hacks = ClientHacks.create (this.action.get_message ());
         } catch { /* This just means we need no hacks, yay! */ }
-#endif
     }
 
     public async void run () {
diff --git a/src/librygel-server/rygel-panasonic-hacks.vala b/src/librygel-server/rygel-panasonic-hacks.vala
index 16499b4d..ad7972d0 100644
--- a/src/librygel-server/rygel-panasonic-hacks.vala
+++ b/src/librygel-server/rygel-panasonic-hacks.vala
@@ -38,7 +38,7 @@ internal class Rygel.PanasonicHacks : ClientHacks {
         }
     }
 
-    public PanasonicHacks (Message? message = null) throws ClientHacksError {
+    public PanasonicHacks (ServerMessage? message = null) throws ClientHacksError {
         base (AGENT, message);
     }
 
diff --git a/src/librygel-server/rygel-phillips-hacks.vala b/src/librygel-server/rygel-phillips-hacks.vala
index 2a1984df..7f2fe0a1 100644
--- a/src/librygel-server/rygel-phillips-hacks.vala
+++ b/src/librygel-server/rygel-phillips-hacks.vala
@@ -26,7 +26,7 @@ using GUPnP;
 internal class Rygel.PhillipsHacks : ClientHacks {
     private const string AGENT = ".*IPI/.*";
 
-    public PhillipsHacks (Message? message = null) throws ClientHacksError {
+    public PhillipsHacks (ServerMessage? message = null) throws ClientHacksError {
         base (AGENT, message);
     }
 
diff --git a/src/librygel-server/rygel-samsung-tv-hacks.vala b/src/librygel-server/rygel-samsung-tv-hacks.vala
index 2f096dc6..53370738 100644
--- a/src/librygel-server/rygel-samsung-tv-hacks.vala
+++ b/src/librygel-server/rygel-samsung-tv-hacks.vala
@@ -36,7 +36,7 @@ internal class Rygel.SamsungTVHacks : ClientHacks {
         }
     }
 
-    public SamsungTVHacks (Message? message = null) throws ClientHacksError {
+    public SamsungTVHacks (ServerMessage? message = null) throws ClientHacksError {
         base (AGENT, message);
     }
 
diff --git a/src/librygel-server/rygel-seek-hacks.vala b/src/librygel-server/rygel-seek-hacks.vala
index 956326c8..a38e445a 100644
--- a/src/librygel-server/rygel-seek-hacks.vala
+++ b/src/librygel-server/rygel-seek-hacks.vala
@@ -45,7 +45,7 @@ internal class Rygel.SeekHacks : ClientHacks {
                                  ".*alphanetworks.*|" +
                                  ".*KnOS/3.2.*";
 
-    public SeekHacks (Message? message = null) throws ClientHacksError {
+    public SeekHacks (ServerMessage? message = null) throws ClientHacksError {
         base (AGENT, message);
     }
 
diff --git a/src/librygel-server/rygel-wmp-hacks.vala b/src/librygel-server/rygel-wmp-hacks.vala
index 663afbec..ae51d835 100644
--- a/src/librygel-server/rygel-wmp-hacks.vala
+++ b/src/librygel-server/rygel-wmp-hacks.vala
@@ -25,7 +25,7 @@ using Soup;
 internal class Rygel.WMPHacks : ClientHacks {
     private const string AGENT = ".*Windows-Media-Player/12\\.0.*";
 
-    public WMPHacks (Message? message = null) throws ClientHacksError {
+    public WMPHacks (ServerMessage? message = null) throws ClientHacksError {
         base (AGENT, message);
     }
 
diff --git a/src/librygel-server/rygel-xbmc-hacks.vala b/src/librygel-server/rygel-xbmc-hacks.vala
index e554c2bd..57680115 100644
--- a/src/librygel-server/rygel-xbmc-hacks.vala
+++ b/src/librygel-server/rygel-xbmc-hacks.vala
@@ -28,7 +28,7 @@ internal class Rygel.XBMCHacks : ClientHacks {
     // promised by developers.
     private const string AGENT = ".*Platinum/.*|.*XBMC/.*|.*Kodi.*";
 
-    public XBMCHacks (Message? message = null, string? agent = null) throws ClientHacksError {
+    public XBMCHacks (ServerMessage? message = null, string? agent = null) throws ClientHacksError {
         base (agent == null ? AGENT : agent, message);
     }
 
diff --git a/src/librygel-server/rygel-xbmc4xbox-hacks.vala b/src/librygel-server/rygel-xbmc4xbox-hacks.vala
index a4d0d612..84b1a2a5 100644
--- a/src/librygel-server/rygel-xbmc4xbox-hacks.vala
+++ b/src/librygel-server/rygel-xbmc4xbox-hacks.vala
@@ -29,7 +29,7 @@ internal class Rygel.XBMC4XBoxHacks : XBMCHacks {
 
     private const string AGENT = "(.*XBMC.*Xbox.*)|(Platinum/0.5.3.0)";
 
-    public XBMC4XBoxHacks (Message? message = null) throws ClientHacksError {
+    public XBMC4XBoxHacks (ServerMessage? message = null) throws ClientHacksError {
         base (message, AGENT);
     }
 
diff --git a/src/librygel-server/rygel-xbox-hacks.vala b/src/librygel-server/rygel-xbox-hacks.vala
index 751b520f..fae559c2 100644
--- a/src/librygel-server/rygel-xbox-hacks.vala
+++ b/src/librygel-server/rygel-xbox-hacks.vala
@@ -33,7 +33,7 @@ internal class Rygel.XBoxHacks : ClientHacks {
     private const string MODEL_VERSION = "11";
     private const string CONTAINER_ID = "ContainerID";
 
-    public XBoxHacks (Message? message = null) throws ClientHacksError {
+    public XBoxHacks (ServerMessage? message = null) throws ClientHacksError {
         base (AGENT, message);
 
         this.object_id = CONTAINER_ID;
@@ -43,7 +43,7 @@ internal class Rygel.XBoxHacks : ClientHacks {
             return;
         }
 
-        var query = message.uri.get_query ();
+        var query = message.get_uri ().get_query ();
         if (query == null) {
             return;
         }
@@ -72,14 +72,12 @@ internal class Rygel.XBoxHacks : ClientHacks {
             return;
         }
 
-        var path = message.uri.get_path ();
+        var path = message.get_uri ().get_path ();
         var particles = path.split ("/")[0:4];
         particles += "th";
         particles += "0";
 
-        message.uri = Soup.uri_copy (message.uri,
-                                     Soup.URIComponent.PATH, string.joinv ("/", particles),
-                                     Soup.URIComponent.NONE);
+        message.set_redirect (Soup.Status.MOVED_PERMANENTLY, string.joinv ("/", particles));
     }
 
     public void apply_on_device (RootDevice device,


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