[rygel] core: Use Soup to parse byte ranges



commit d38b0aa01d21ada89cccdffd036d80d7be221232
Author: Jens Georg <mail jensge org>
Date:   Fri Feb 24 14:40:46 2012 +0200

    core: Use Soup to parse byte ranges

 configure.ac                        |    2 +-
 src/rygel/rygel-http-byte-seek.vala |   43 +++++------------------------------
 2 files changed, 7 insertions(+), 38 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8977fb4..3cc5e82 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,7 +29,7 @@ LT_INIT([dlopen disable-static])
 
 dnl Required versions of library packages
 GLIB_REQUIRED=2.31.13
-VALA_REQUIRED=0.15.1
+VALA_REQUIRED=0.15.2
 GSSDP_REQUIRED=0.11.0
 GUPNP_REQUIRED=0.17.1
 GUPNP_AV_REQUIRED=0.9.0
diff --git a/src/rygel/rygel-http-byte-seek.vala b/src/rygel/rygel-http-byte-seek.vala
index d1b2d34..fa5f536 100644
--- a/src/rygel/rygel-http-byte-seek.vala
+++ b/src/rygel/rygel-http-byte-seek.vala
@@ -23,8 +23,7 @@
 
 internal class Rygel.HTTPByteSeek : Rygel.HTTPSeek {
     public HTTPByteSeek (HTTPGet request) throws HTTPSeekError {
-        string range, pos;
-        string[] range_tokens;
+        Soup.Range[] ranges;
         int64 start = 0, total_length;
 
         if (request.thumbnail != null) {
@@ -36,41 +35,11 @@ internal class Rygel.HTTPByteSeek : Rygel.HTTPSeek {
         }
         var stop = total_length - 1;
 
-        range = request.msg.request_headers.get_one ("Range");
-        if (range != null) {
-            // We have a Range header. Parse.
-            if (!range.has_prefix ("bytes=")) {
-                throw new HTTPSeekError.INVALID_RANGE (_("Invalid Range '%s'"),
-                                                       range);
-            }
-
-            range_tokens = range.substring (6).split ("-", 2);
-            if (range_tokens[0] == null || range_tokens[1] == null) {
-                throw new HTTPSeekError.INVALID_RANGE (_("Invalid Range '%s'"),
-                                                       range);
-            }
-
-            // Get first byte position
-            pos = range_tokens[0];
-            if (pos[0].isdigit ()) {
-                start = int64.parse (pos);
-            } else if (pos  != "") {
-                throw new HTTPSeekError.INVALID_RANGE (_("Invalid Range '%s'"),
-                                                       range);
-            }
-
-            // Get last byte position if specified
-            pos = range_tokens[1];
-            if (pos[0].isdigit ()) {
-                stop = int64.parse (pos);
-                if (stop < start) {
-                    throw new HTTPSeekError.INVALID_RANGE
-                                        (_("Invalid Range '%s'"), range);
-                }
-            } else if (pos != "") {
-                throw new HTTPSeekError.INVALID_RANGE (_("Invalid Range '%s'"),
-                                                       range);
-            }
+        if (request.msg.request_headers.get_ranges (total_length,
+                                                    out ranges)) {
+            // TODO: Somehow deal with multipart/byterange properly
+            start = ranges[0].start;
+            stop = ranges[0].end;
         }
 
         base (request.msg, start, stop, 1, total_length);



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