[gnome-keyring/dbus-api] [dbus] Return NoSuchObject when a bad collectiont or item path.



commit c3d0a04397b394c02206caa85268619d866c2f43
Author: Stef Walter <stef memberwebs com>
Date:   Thu Dec 10 21:52:58 2009 +0000

    [dbus] Return NoSuchObject when a bad collectiont or item path.

 daemon/dbus/gkd-dbus-util.c      |   23 +----------------------
 daemon/dbus/gkd-dbus-util.h      |    4 ----
 daemon/dbus/gkd-secret-objects.c |    2 +-
 daemon/dbus/gkd-secret-service.c |   11 ++++++++---
 daemon/dbus/gkd-secret-types.h   |    1 +
 daemon/dbus/gkd-secret-util.c    |    9 +++++++++
 daemon/dbus/gkd-secret-util.h    |    4 ++++
 7 files changed, 24 insertions(+), 30 deletions(-)
---
diff --git a/daemon/dbus/gkd-dbus-util.c b/daemon/dbus/gkd-dbus-util.c
index a92157b..1b094ea 100644
--- a/daemon/dbus/gkd-dbus-util.c
+++ b/daemon/dbus/gkd-dbus-util.c
@@ -24,6 +24,7 @@
 #include "config.h"
 
 #include "gkd-dbus-util.h"
+#include "gkd-secret-types.h"
 
 #include <string.h>
 
@@ -84,25 +85,3 @@ gkd_dbus_introspect_handle (DBusMessage *message, const gchar *type)
 
 	return NULL;
 }
-
-static dbus_int32_t handled_slot = -1;
-
-void
-gkd_dbus_message_mark_handled (DBusMessage *message)
-{
-	g_return_if_fail (message);
-	if (handled_slot == -1) {
-		if (!dbus_message_allocate_data_slot (&handled_slot))
-			g_assert_not_reached ();
-	}
-	dbus_message_set_data (message, handled_slot, "TRUE", NULL);
-}
-
-gboolean
-gkd_dbus_message_is_handled (DBusMessage *message)
-{
-	g_return_val_if_fail (message, FALSE);
-	if (handled_slot == -1)
-		return FALSE;
-	return dbus_message_get_data (message, handled_slot) ? TRUE : FALSE;
-}
diff --git a/daemon/dbus/gkd-dbus-util.h b/daemon/dbus/gkd-dbus-util.h
index 5b90de0..0bc0702 100644
--- a/daemon/dbus/gkd-dbus-util.h
+++ b/daemon/dbus/gkd-dbus-util.h
@@ -36,8 +36,4 @@ gboolean      gkd_dbus_interface_match                    (const gchar *interfac
 
 DBusMessage*  gkd_dbus_introspect_handle                  (DBusMessage *message, const gchar *type);
 
-void          gkd_dbus_message_mark_handled               (DBusMessage *message);
-
-gboolean      gkd_dbus_message_is_handled                 (DBusMessage *message);
-
 #endif /* GKD_DBUS_H */
diff --git a/daemon/dbus/gkd-secret-objects.c b/daemon/dbus/gkd-secret-objects.c
index c8582ee..add8ce8 100644
--- a/daemon/dbus/gkd-secret-objects.c
+++ b/daemon/dbus/gkd-secret-objects.c
@@ -841,7 +841,7 @@ gkd_secret_objects_dispatch (GkdSecretObjects *self, DBusMessage *message)
 
 	object = gkd_secret_util_path_to_object (session, path, &is_item);
 	if (!object)
-		return NULL;
+		return gkd_secret_util_no_such_object (message);
 
 	if (is_item)
 		reply = item_message_handler (self, object, message);
diff --git a/daemon/dbus/gkd-secret-service.c b/daemon/dbus/gkd-secret-service.c
index b6c2f3a..9046f76 100644
--- a/daemon/dbus/gkd-secret-service.c
+++ b/daemon/dbus/gkd-secret-service.c
@@ -30,6 +30,7 @@
 #include "gkd-secret-session.h"
 #include "gkd-secret-types.h"
 #include "gkd-secret-unlock.h"
+#include "gkd-secret-util.h"
 
 #include "egg/egg-unix-credentials.h"
 
@@ -556,13 +557,17 @@ service_dispatch_message (GkdSecretService *self, DBusMessage *message)
 	/* Dispatched to a session, find a session in this client */
 	if (object_path_has_prefix (path, SECRET_SESSION_PREFIX)) {
 		object = g_hash_table_lookup (client->sessions, path);
-		if (object != NULL)
+		if (object == NULL)
+			reply = gkd_secret_util_no_such_object (message);
+		else
 			reply = gkd_secret_session_dispatch (object, message);
 
 	/* Dispatched to a prompt, find a prompt in this client */
 	} else if (object_path_has_prefix (path, SECRET_PROMPT_PREFIX)) {
 		object = g_hash_table_lookup (client->prompts, path);
-		if (object != NULL)
+		if (object == NULL)
+			reply = gkd_secret_util_no_such_object (message);
+		else
 			reply = gkd_secret_prompt_dispatch (object, message);
 
 	/* Dispatched to a collection, off it goes */
@@ -576,7 +581,7 @@ service_dispatch_message (GkdSecretService *self, DBusMessage *message)
 
 	/* Should we send an error? */
 	if (!reply && dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_CALL) {
-		if (!dbus_message_get_no_reply (message) && !gkd_dbus_message_is_handled (message)) {
+		if (!dbus_message_get_no_reply (message)) {
 			reply = dbus_message_new_error_printf (message, DBUS_ERROR_UNKNOWN_METHOD,
 			                                       "Method \"%s\" with signature \"%s\" on interface \"%s\" doesn't exist\n",
 			                                       dbus_message_get_member (message),
diff --git a/daemon/dbus/gkd-secret-types.h b/daemon/dbus/gkd-secret-types.h
index 645ac04..c2b7df9 100644
--- a/daemon/dbus/gkd-secret-types.h
+++ b/daemon/dbus/gkd-secret-types.h
@@ -42,6 +42,7 @@
 #define SECRET_ERROR_IS_LOCKED         "org.freedesktop.Secrets.Error.IsLocked"
 #define SECRET_ERROR_NOT_SUPPORTED     "org.freedesktop.Secrets.Error.NotSupported"
 #define SECRET_ERROR_NO_SESSION        "org.freedesktop.Secrets.Error.NoSession"
+#define SECRET_ERROR_NO_SUCH_OBJECT    "org.freedesktop.Secrets.Error.NoSuchObject"
 
 typedef struct _GkdSecretCollection GkdSecretCollection;
 typedef struct _GkdSecretCreate GkdSecretCreate;
diff --git a/daemon/dbus/gkd-secret-util.c b/daemon/dbus/gkd-secret-util.c
index 10ea9a0..d02f052 100644
--- a/daemon/dbus/gkd-secret-util.c
+++ b/daemon/dbus/gkd-secret-util.c
@@ -433,3 +433,12 @@ gkd_secret_util_attributes_for_item (GP11Object *item)
 	g_free (path);
 	return attrs;
 }
+
+
+DBusMessage*
+gkd_secret_util_no_such_object (DBusMessage *message)
+{
+	g_return_val_if_fail (message, NULL);
+	return dbus_message_new_error_printf (message, SECRET_ERROR_NO_SUCH_OBJECT,
+	                                      "The '%s' object does not exist", dbus_message_get_path (message));
+}
diff --git a/daemon/dbus/gkd-secret-util.h b/daemon/dbus/gkd-secret-util.h
index bf208bb..3d3e74a 100644
--- a/daemon/dbus/gkd-secret-util.h
+++ b/daemon/dbus/gkd-secret-util.h
@@ -26,6 +26,8 @@
 
 #include "gp11/gp11.h"
 
+#include <dbus/dbus.h>
+
 GP11Object*       gkd_secret_util_path_to_collection                    (GP11Session *session,
                                                                          const gchar *path);
 
@@ -44,4 +46,6 @@ gchar*            gkd_secret_util_identifier_for_collection             (GP11Obj
 
 GP11Attributes*   gkd_secret_util_attributes_for_item                   (GP11Object *item);
 
+DBusMessage*      gkd_secret_util_no_such_object                        (DBusMessage *message);
+
 #endif /* __GKD_SECRET_UTIL_H__ */



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