[telepathy-glib/master] Make GetGroupFlags() failing abort introspection.

Will Thompson will.thompson at collabora.co.uk
Mon Jul 27 01:29:51 PDT 2009


If we get as far as introspecting the Group interface of a non-existant
channel, or a channel which exists but was lying about having the Group
interface, introspection fails rather than assuming all the group
properties have empty values.

GetGroupFlags() has been around in its current form for a very long
time, so I think it's safe to assume that any channel which doesn't
implement it properly needs fixing.
---
 telepathy-glib/channel-group.c    |   23 ++++++++-------
 telepathy-glib/channel-internal.h |    3 ++
 telepathy-glib/channel.c          |    2 +-
 tests/dbus/channel-introspect.c   |   54 +++++++++++++++++++++++++++++++++++++
 4 files changed, 70 insertions(+), 12 deletions(-)

diff --git a/telepathy-glib/channel-group.c b/telepathy-glib/channel-group.c
index 0e65edc..0d54891 100644
--- a/telepathy-glib/channel-group.c
+++ b/telepathy-glib/channel-group.c
@@ -372,19 +372,20 @@ tp_channel_got_group_flags_0_16_cb (TpChannel *self,
 
   if (error != NULL)
     {
-      DEBUG ("%p GetGroupFlags() failed, assuming initial flags 0: %s", self,
-          error->message);
-      flags = 0;
+      /* GetGroupFlags() has existed with its current signature since November
+       * 2005. I think it's reasonable to say that if it doesn't work, the
+       * channel is broken.
+       */
+      _tp_channel_abort_introspection (self, "GetGroupFlags() failed", error);
+      return;
     }
-  else
+
+  /* If we reach this point, GetAll has already failed... */
+  if (flags & TP_CHANNEL_GROUP_FLAG_PROPERTIES)
     {
-      /* If we reach this point, GetAll has already failed... */
-      if (flags & TP_CHANNEL_GROUP_FLAG_PROPERTIES)
-        {
-          DEBUG ("Treason uncloaked! The channel claims to support Group "
-              "properties, but GetAll didn't work");
-          flags &= ~TP_CHANNEL_GROUP_FLAG_PROPERTIES;
-        }
+      DEBUG ("Treason uncloaked! The channel claims to support Group "
+          "properties, but GetAll didn't work");
+      flags &= ~TP_CHANNEL_GROUP_FLAG_PROPERTIES;
     }
 
   _got_initial_group_flags (self, flags);
diff --git a/telepathy-glib/channel-internal.h b/telepathy-glib/channel-internal.h
index 1d1fb0b..e97d4b2 100644
--- a/telepathy-glib/channel-internal.h
+++ b/telepathy-glib/channel-internal.h
@@ -84,6 +84,9 @@ struct _TpChannelPrivate {
 /* channel.c internals */
 
 void _tp_channel_continue_introspection (TpChannel *self);
+void _tp_channel_abort_introspection (TpChannel *self,
+    const gchar *debug,
+    const GError *error);
 
 /* channel-group.c internals */
 
diff --git a/telepathy-glib/channel.c b/telepathy-glib/channel.c
index a853cb1..de565bb 100644
--- a/telepathy-glib/channel.c
+++ b/telepathy-glib/channel.c
@@ -502,7 +502,7 @@ tp_channel_set_property (GObject *object,
 /* Introspection etc. */
 
 
-static void
+void
 _tp_channel_abort_introspection (TpChannel *self,
                                  const gchar *debug,
                                  const GError *error)
diff --git a/tests/dbus/channel-introspect.c b/tests/dbus/channel-introspect.c
index 1b12037..4cbc7d0 100644
--- a/tests/dbus/channel-introspect.c
+++ b/tests/dbus/channel-introspect.c
@@ -401,6 +401,60 @@ main (int argc,
   g_free (bad_chan_path);
   bad_chan_path = NULL;
 
+  g_message ("Channel doesn't actually implement Group (preloading immutable "
+      "properties)");
+
+  test_connection_run_until_dbus_queue_processed (conn);
+
+  service_chan->get_handle_called = 0;
+  service_chan->get_interfaces_called = 0;
+  service_chan->get_channel_type_called = 0;
+
+  {
+    const gchar *interfaces[] = {
+        TP_IFACE_CHANNEL_INTERFACE_GROUP,
+        NULL
+    };
+
+    asv = tp_asv_new (
+        TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING,
+            TP_IFACE_CHANNEL_TYPE_TEXT,
+        TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_UINT,
+            TP_HANDLE_TYPE_CONTACT,
+        TP_IFACE_CHANNEL ".TargetHandle", G_TYPE_UINT, handle,
+        TP_IFACE_CHANNEL ".TargetID", G_TYPE_STRING, IDENTIFIER,
+        TP_IFACE_CHANNEL ".InitiatorHandle", G_TYPE_UINT, handle,
+        TP_IFACE_CHANNEL ".InitiatorID", G_TYPE_STRING, IDENTIFIER,
+        TP_IFACE_CHANNEL ".Interfaces", G_TYPE_STRV, interfaces,
+        TP_IFACE_CHANNEL ".Requested", G_TYPE_BOOLEAN, FALSE,
+        NULL);
+  }
+
+  /* We lie and say that the basic Text channel has the Group interface; this
+   * should make introspection fail.
+   */
+  chan = tp_channel_new_from_properties (conn, chan_path, asv, &error);
+  test_assert_no_error (error);
+
+  g_hash_table_destroy (asv);
+  asv = NULL;
+
+  MYASSERT (!tp_channel_run_until_ready (chan, &error, NULL), "");
+  MYASSERT (error != NULL, "");
+  MYASSERT (error->domain == DBUS_GERROR,
+      "%s", g_quark_to_string (error->domain));
+  MYASSERT (error->code == DBUS_GERROR_UNKNOWN_METHOD,
+      "%u", error->code);
+  g_error_free (error);
+  error = NULL;
+
+  MYASSERT_SAME_UINT (service_chan->get_handle_called, 0);
+  MYASSERT_SAME_UINT (service_chan->get_channel_type_called, 0);
+  MYASSERT_SAME_UINT (service_chan->get_interfaces_called, 0);
+
+  g_object_unref (chan);
+  chan = NULL;
+
   g_message ("Channel becomes ready and we are called back");
 
   test_connection_run_until_dbus_queue_processed (conn);
-- 
1.5.6.5




More information about the telepathy-commits mailing list