[rygel] core,server: Use proper error codes
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] core,server: Use proper error codes
- Date: Tue, 6 Aug 2013 13:17:48 +0000 (UTC)
commit 03811443252b8c4f592a957ff5bf08d66a5d5717
Author: Jens Georg <jensg openismus com>
Date: Mon Aug 5 15:03:35 2013 +0200
core,server: Use proper error codes
There are several places where the wrong error code was used.
https://bugzilla.gnome.org/show_bug.cgi?id=702452
src/librygel-core/rygel-connection-manager.vala | 9 +++--
src/librygel-server/rygel-content-directory.vala | 38 +++++++++++++++-----
src/librygel-server/rygel-import-resource.vala | 17 ++++-----
src/librygel-server/rygel-media-query-action.vala | 4 +-
src/librygel-server/rygel-object-creator.vala | 4 +-
5 files changed, 45 insertions(+), 27 deletions(-)
---
diff --git a/src/librygel-core/rygel-connection-manager.vala b/src/librygel-core/rygel-connection-manager.vala
index 75f1aed..b9a4108 100644
--- a/src/librygel-core/rygel-connection-manager.vala
+++ b/src/librygel-core/rygel-connection-manager.vala
@@ -117,14 +117,15 @@ public class Rygel.ConnectionManager : Service {
string connection_id;
action.get ("ConnectionID", typeof (string), out connection_id);
- if (connection_id == null || connection_id != "0") {
- action.return_error (706, _("Invalid connection reference"));
+ if (connection_id == null || action.get_argument_count () != 1 ||
+ (connection_id != "0" && int.parse (connection_id) == 0)) {
+ action.return_error (402, _("Invalid argument"));
return;
}
- if (action.get_argument_count () != 1) {
- action.return_error (402, _("Invalid argument"));
+ if (connection_id != "0") {
+ action.return_error (706, _("Invalid connection reference"));
return;
}
diff --git a/src/librygel-server/rygel-content-directory.vala
b/src/librygel-server/rygel-content-directory.vala
index 9b9a147..adf2f24 100644
--- a/src/librygel-server/rygel-content-directory.vala
+++ b/src/librygel-server/rygel-content-directory.vala
@@ -41,6 +41,7 @@ internal errordomain Rygel.ContentDirectoryError {
RESTRICTED_OBJECT = 711,
BAD_METADATA = 712,
RESTRICTED_PARENT = 713,
+ NO_SUCH_FILE_TRANSFER = 717,
NO_SUCH_DESTINATION_RESOURCE = 718,
CANT_PROCESS = 720,
OUTDATED_OBJECT_METADATA = 728,
@@ -267,8 +268,9 @@ internal class Rygel.ContentDirectory: Service {
return;
}
- var import = find_import_for_action (action);
- if (import != null) {
+ try {
+ var import = this.find_import_for_action (action);
+
action.set ("TransferStatus",
typeof (string),
import.status_as_string,
@@ -280,8 +282,8 @@ internal class Rygel.ContentDirectory: Service {
import.bytes_total);
action.return ();
- } else {
- action.return_error (717, _("No such file transfer"));
+ } catch (Error error) {
+ action.return_error (error.code, error.message);
}
}
@@ -294,13 +296,13 @@ internal class Rygel.ContentDirectory: Service {
return;
}
- var import = find_import_for_action (action);
- if (import != null) {
+ try {
+ var import = find_import_for_action (action);
import.cancellable.cancel ();
action.return ();
- } else {
- action.return_error (717, _("No such file transfer"));
+ } catch (Error error) {
+ action.return_error (error.code, error.message);
}
}
@@ -596,13 +598,24 @@ internal class Rygel.ContentDirectory: Service {
});
}
- private ImportResource? find_import_for_action (ServiceAction action) {
+ private ImportResource? find_import_for_action (ServiceAction action)
+ throws ContentDirectoryError {
ImportResource ret = null;
uint32 transfer_id;
+ string transfer_id_string;
+ // TODO: Remove string hack once bgo#705516 is fixed
action.get ("TransferID",
typeof (uint32),
- out transfer_id);
+ out transfer_id,
+ "TransferID",
+ typeof (string),
+ out transfer_id_string);
+ if (transfer_id == 0 &&
+ (transfer_id_string == null || transfer_id_string != "0")) {
+ throw new ContentDirectoryError.INVALID_ARGS
+ (_("Invalid argument"));
+ }
foreach (var import in this.active_imports) {
if (import.transfer_id == transfer_id) {
@@ -620,6 +633,11 @@ internal class Rygel.ContentDirectory: Service {
}
}
+ if (ret == null) {
+ throw new ContentDirectoryError.NO_SUCH_FILE_TRANSFER
+ (_("No such file transfer"));
+ }
+
return ret;
}
diff --git a/src/librygel-server/rygel-import-resource.vala b/src/librygel-server/rygel-import-resource.vala
index 06a01f4..69c49f3 100644
--- a/src/librygel-server/rygel-import-resource.vala
+++ b/src/librygel-server/rygel-import-resource.vala
@@ -125,14 +125,7 @@ internal class Rygel.ImportResource : GLib.Object, Rygel.StateMachine {
this.destination_uri,
error.message);
- int code;
- if (error is ContentDirectoryError) {
- code = error.code;
- } else {
- code = 719;
- }
-
- this.action.return_error (code, error.message);
+ this.action.return_error (error.code, error.message);
this.status = TransferStatus.ERROR;
this.completed ();
@@ -174,8 +167,14 @@ internal class Rygel.ImportResource : GLib.Object, Rygel.StateMachine {
}
private async MediaItem fetch_item () throws Error {
- var uri = new HTTPItemURI.from_string (this.destination_uri,
+ HTTPItemURI uri;
+ try {
+ uri = new HTTPItemURI.from_string (this.destination_uri,
this.http_server);
+ } catch (Error error) {
+ throw new ContentDirectoryError.NO_SUCH_DESTINATION_RESOURCE
+ (error.message);
+ }
var media_object = yield this.root_container.find_object (uri.item_id,
null);
string msg = null;
diff --git a/src/librygel-server/rygel-media-query-action.vala
b/src/librygel-server/rygel-media-query-action.vala
index c816f16..774f24c 100644
--- a/src/librygel-server/rygel-media-query-action.vala
+++ b/src/librygel-server/rygel-media-query-action.vala
@@ -111,8 +111,8 @@ internal abstract class Rygel.MediaQueryAction : GLib.Object, StateMachine {
if (this.object_id == null) {
// Sorry we can't do anything without ObjectID
- throw new ContentDirectoryError.NO_SUCH_OBJECT
- (_("No such object"));
+ throw new ContentDirectoryError.INVALID_ARGS
+ (_("ObjectID argument missing"));
}
if (index < 0 || requested_count < 0) {
diff --git a/src/librygel-server/rygel-object-creator.vala b/src/librygel-server/rygel-object-creator.vala
index 4c2cbdf..ce5789c 100644
--- a/src/librygel-server/rygel-object-creator.vala
+++ b/src/librygel-server/rygel-object-creator.vala
@@ -197,8 +197,8 @@ internal class Rygel.ObjectCreator: GLib.Object, Rygel.StateMachine {
if (this.container_id == null) {
// Sorry we can't do anything without ContainerID
- throw new ContentDirectoryError.NO_SUCH_OBJECT
- (_("No such object"));
+ throw new ContentDirectoryError.INVALID_ARGS
+ (_("Missing ContainerID argument"));
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]