From 11c25e380bfe1646bb382959137e1749a2c427e3 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 20 Apr 2011 14:59:28 +0100 Subject: [PATCH 1/2] dbus-gobject: return empty from GetAll if there are no known properties Bug: https://bugs.freedesktop.org/show_bug.cgi?id=22156 --- dbus/dbus-gobject.c | 21 ++++++++++++++------- test/core/test-dbus-glib.c | 10 ++++++++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/dbus/dbus-gobject.c b/dbus/dbus-gobject.c index bddcd1b..cc84910 100644 --- a/dbus/dbus-gobject.c +++ b/dbus/dbus-gobject.c @@ -1130,7 +1130,6 @@ dbus_g_object_type_register_shadow_property (GType iface_type, static DBusMessage* get_all_object_properties (DBusConnection *connection, DBusMessage *message, - const DBusGObjectInfo *object_info, const char *wincaps_propiface, GObject *object) { @@ -1141,6 +1140,7 @@ get_all_object_properties (DBusConnection *connection, DBusMessageIter iter_dict_value; const char *p; char *uscore_propname; + const DBusGObjectInfo *object_info; ret = dbus_message_new_method_return (message); if (ret == NULL) @@ -1157,7 +1157,18 @@ get_all_object_properties (DBusConnection *connection, &iter_dict)) goto oom; - p = object_info->exported_properties; + object_info = lookup_object_info_by_iface (object, wincaps_propiface, TRUE, + NULL); + + /* If we don't know about the given interface, clearly it doesn't have + * any properties (we can't actually distinguish between this and GetAll + * for an unimplemented interface, but it seems reasonable to return + * empty either way). */ + if (object_info == NULL) + p = NULL; + else + p = object_info->exported_properties; + while (p != NULL && *p != '\0') { const char *prop_ifname; @@ -1978,11 +1989,7 @@ object_registration_message (DBusConnection *connection, if (getall) { - object_info = lookup_object_info_by_iface (object, wincaps_propiface, TRUE, NULL); - if (object_info != NULL) - ret = get_all_object_properties (connection, message, object_info, wincaps_propiface, object); - else - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + ret = get_all_object_properties (connection, message, wincaps_propiface, object); } else if (getter || setter) { diff --git a/test/core/test-dbus-glib.c b/test/core/test-dbus-glib.c index f86cba9..f761683 100644 --- a/test/core/test-dbus-glib.c +++ b/test/core/test-dbus-glib.c @@ -306,12 +306,18 @@ test_base_class_get_all (DBusGConnection *connection, g_print ("%s: Calling GetAll for unknown interface\n", object_path); { + /* Unexpectedly, this has to succeed: we can't distinguish between an + * unimplemented interface, and an interface with no properties. + * Either way it seems reasonable to return an empty set. */ if (dbus_g_proxy_call (proxy, "GetAll", &error, G_TYPE_STRING, "org.freedesktop.DBus.foobar.blahblah", G_TYPE_INVALID, DBUS_TYPE_G_MAP_OF_VARIANT, &hash, G_TYPE_INVALID)) - lose ("Unexpected success for GetAll call of unknown interface\n"); - g_clear_error (&error); + g_assert_cmpuint (g_hash_table_size (hash), ==, 0); + else + lose ("Unexpected error for GetAll call of unknown interface\n"); + + g_hash_table_unref (hash); hash = NULL; } -- 1.7.4.4