[rygel] core: Clean & correct seek-deciding code
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] core: Clean & correct seek-deciding code
- Date: Sat, 14 Aug 2010 01:53:10 +0000 (UTC)
commit 475507e372cff85db170da47d80038efcbc09ed0
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Sat Aug 14 04:31:00 2010 +0300
core: Clean & correct seek-deciding code
Clean & correct code that decides whether to seek or not and creates the
relavent HTTPSeek object.
This also enables us to comply with DLNA (7.3.33.5).
src/rygel/rygel-http-byte-seek.vala | 25 +++++++++++--------------
src/rygel/rygel-http-get.vala | 12 ++++++++++--
src/rygel/rygel-http-time-seek.vala | 23 ++++++++++-------------
3 files changed, 31 insertions(+), 29 deletions(-)
---
diff --git a/src/rygel/rygel-http-byte-seek.vala b/src/rygel/rygel-http-byte-seek.vala
index 90b36bf..fbded5e 100644
--- a/src/rygel/rygel-http-byte-seek.vala
+++ b/src/rygel/rygel-http-byte-seek.vala
@@ -77,21 +77,18 @@ internal class Rygel.HTTPByteSeek : Rygel.HTTPSeek {
base (request.msg, start, stop, total_length);
}
- public static bool needed (HTTPGet request) throws HTTPRequestError {
- var needed = (request.item.size > 0 &&
- request.handler is HTTPIdentityHandler) ||
- (request.thumbnail != null &&
- request.thumbnail.size > 0) ||
- (request.subtitle != null && request.subtitle.size > 0);
-
- var range = request.msg.request_headers.get_one ("Range");
- var agent = request.msg.request_headers.get_one ("User-Agent");
-
- if (!needed && range != null && agent != "PLAYSTATION 3") {
- throw new HTTPRequestError.UNACCEPTABLE ("Invalid seek request");
- }
+ public static bool needed (HTTPGet request) {
+ return (request.item.size > 0 &&
+ request.handler is HTTPIdentityHandler) ||
+ (request.thumbnail != null &&
+ request.thumbnail.size > 0) ||
+ (request.subtitle != null && request.subtitle.size > 0) ||
+ request.msg.request_headers.get_one ("User-Agent") ==
+ "PLAYSTATION 3";
+ }
- return needed;
+ public static bool requested (HTTPGet request) {
+ return request.msg.request_headers.get_one ("Range") != null;
}
public override void add_response_headers () {
diff --git a/src/rygel/rygel-http-get.vala b/src/rygel/rygel-http-get.vala
index eeadeb5..1b24b2c 100644
--- a/src/rygel/rygel-http-get.vala
+++ b/src/rygel/rygel-http-get.vala
@@ -83,9 +83,17 @@ internal class Rygel.HTTPGet : HTTPRequest {
}
private async void handle_item_request () throws Error {
- if (HTTPTimeSeek.needed (this)) {
+ var need_time_seek = HTTPTimeSeek.needed (this);
+ var need_byte_seek = HTTPByteSeek.needed (this);
+
+ if ((HTTPTimeSeek.requested (this) && !need_time_seek) ||
+ (HTTPByteSeek.requested (this) && !need_byte_seek)) {
+ throw new HTTPRequestError.UNACCEPTABLE ("Invalid seek request");
+ }
+
+ if (need_time_seek) {
this.seek = new HTTPTimeSeek (this);
- } else if (HTTPByteSeek.needed (this)) {
+ } else if (need_byte_seek) {
this.seek = new HTTPByteSeek (this);
}
diff --git a/src/rygel/rygel-http-time-seek.vala b/src/rygel/rygel-http-time-seek.vala
index 7a7ee3e..2f9cc22 100644
--- a/src/rygel/rygel-http-time-seek.vala
+++ b/src/rygel/rygel-http-time-seek.vala
@@ -78,20 +78,17 @@ internal class Rygel.HTTPTimeSeek : Rygel.HTTPSeek {
base (request.msg, start, stop, duration);
}
- public static bool needed (HTTPGet request) throws HTTPRequestError {
- var needed = request.item.duration > 0 &&
- (request.handler is HTTPTranscodeHandler ||
- (request.thumbnail == null &&
- request.subtitle == null &&
- request.item.should_stream ()));
-
- if (!needed &&
- request.msg.request_headers.get_one ("TimeSeekRange.dlna.org") !=
- null) {
- throw new HTTPRequestError.UNACCEPTABLE ("Invalid seek request");
- }
+ public static bool needed (HTTPGet request) {
+ return request.item.duration > 0 &&
+ (request.handler is HTTPTranscodeHandler ||
+ (request.thumbnail == null &&
+ request.subtitle == null &&
+ request.item.should_stream ()));
+ }
- return needed;
+ public static bool requested (HTTPGet request) {
+ return request.msg.request_headers.get_one ("TimeSeekRange.dlna.org") !=
+ null;
}
public override void add_response_headers () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]