[PATCH] protocol: introduce new errors UnknownObject and UnknownInterface
Lennart Poettering
mzqohf at 0pointer.de
Tue Feb 15 04:37:35 PST 2011
As discussed on dbus devel we want these two error standardized. Hence
add them to dbus-protocol.h and hook the core up to them in a few
places.
Unfortunately we cannot distuingish UnknownInterface from UnknownMethod
if people install vtables since they don't pass this information back to
us. Changing this would be a change of API.
---
bus/driver.c | 5 ++++-
dbus/dbus-connection.c | 6 ++++--
dbus/dbus-object-tree.c | 8 ++++++--
dbus/dbus-object-tree.h | 3 ++-
dbus/dbus-protocol.h | 4 ++++
5 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/bus/driver.c b/bus/driver.c
index cc8d1f2..6016b23 100644
--- a/bus/driver.c
+++ b/bus/driver.c
@@ -1963,7 +1963,10 @@ bus_driver_handle_message (DBusConnection *connection,
{
_dbus_verbose ("Driver got message to unknown interface \"%s\"\n",
interface);
- goto unknown;
+ dbus_set_error (error, DBUS_ERROR_UNKNOWN_INTERFACE,
+ "%s does not understand message to interface %s",
+ DBUS_SERVICE_DBUS, interface);
+ return FALSE;
}
_dbus_verbose ("Driver got a method call: %s\n",
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index 6779b6a..8968e03 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -4522,6 +4522,7 @@ dbus_connection_dispatch (DBusConnection *connection)
DBusPendingCall *pending;
dbus_int32_t reply_serial;
DBusDispatchStatus status;
+ dbus_bool_t found_object;
_dbus_return_val_if_fail (connection != NULL, DBUS_DISPATCH_COMPLETE);
@@ -4686,7 +4687,8 @@ dbus_connection_dispatch (DBusConnection *connection)
HAVE_LOCK_CHECK (connection);
result = _dbus_object_tree_dispatch_and_unlock (connection->objects,
- message);
+ message,
+ &found_object);
CONNECTION_LOCK (connection);
@@ -4725,7 +4727,7 @@ dbus_connection_dispatch (DBusConnection *connection)
}
reply = dbus_message_new_error (message,
- DBUS_ERROR_UNKNOWN_METHOD,
+ found_object ? DBUS_ERROR_UNKNOWN_METHOD : DBUS_ERROR_UNKNOWN_OBJECT,
_dbus_string_get_const_data (&str));
_dbus_string_free (&str);
diff --git a/dbus/dbus-object-tree.c b/dbus/dbus-object-tree.c
index 28cfc8b..f907c12 100644
--- a/dbus/dbus-object-tree.c
+++ b/dbus/dbus-object-tree.c
@@ -745,7 +745,8 @@ handle_default_introspect_and_unlock (DBusObjectTree *tree,
*/
DBusHandlerResult
_dbus_object_tree_dispatch_and_unlock (DBusObjectTree *tree,
- DBusMessage *message)
+ DBusMessage *message,
+ dbus_bool_t *found_object)
{
char **path;
dbus_bool_t exact_match;
@@ -791,6 +792,9 @@ _dbus_object_tree_dispatch_and_unlock (DBusObjectTree *tree,
/* Find the deepest path that covers the path in the message */
subtree = find_handler (tree, (const char**) path, &exact_match);
+ if (found_object)
+ *found_object = !!subtree;
+
/* Build a list of all paths that cover the path in the message */
list = NULL;
@@ -1382,7 +1386,7 @@ do_test_dispatch (DBusObjectTree *tree,
++j;
}
- result = _dbus_object_tree_dispatch_and_unlock (tree, message);
+ result = _dbus_object_tree_dispatch_and_unlock (tree, message, NULL);
if (result == DBUS_HANDLER_RESULT_NEED_MEMORY)
goto oom;
diff --git a/dbus/dbus-object-tree.h b/dbus/dbus-object-tree.h
index 022dd93..1cba2a0 100644
--- a/dbus/dbus-object-tree.h
+++ b/dbus/dbus-object-tree.h
@@ -42,7 +42,8 @@ dbus_bool_t _dbus_object_tree_register (DBusObjectTree
void _dbus_object_tree_unregister_and_unlock (DBusObjectTree *tree,
const char **path);
DBusHandlerResult _dbus_object_tree_dispatch_and_unlock (DBusObjectTree *tree,
- DBusMessage *message);
+ DBusMessage *message,
+ dbus_bool_t *found_object);
void* _dbus_object_tree_get_user_data_unlocked (DBusObjectTree *tree,
const char **path);
void _dbus_object_tree_free_all_unlocked (DBusObjectTree *tree);
diff --git a/dbus/dbus-protocol.h b/dbus/dbus-protocol.h
index 17798e9..5a63aec 100644
--- a/dbus/dbus-protocol.h
+++ b/dbus/dbus-protocol.h
@@ -390,6 +390,10 @@ extern "C" {
#define DBUS_ERROR_FILE_EXISTS "org.freedesktop.DBus.Error.FileExists"
/** Method name you invoked isn't known by the object you invoked it on. */
#define DBUS_ERROR_UNKNOWN_METHOD "org.freedesktop.DBus.Error.UnknownMethod"
+/** Object you invoked a method on isn't known. */
+#define DBUS_ERROR_UNKNOWN_OBJECT "org.freedesktop.DBus.Error.UnknownObject"
+/** Interface you invoked a method on isn't known by the object. */
+#define DBUS_ERROR_UNKNOWN_INTERFACE "org.freedesktop.DBus.Error.UnknownInterface"
/** Certain timeout errors, e.g. while starting a service.
* @warning this is confusingly-named given that #DBUS_ERROR_TIMEOUT also exists. We can't fix
* it for compatibility reasons so just be careful.
--
1.7.4
Lennart
--
Lennart Poettering - Red Hat, Inc.
More information about the dbus
mailing list