telepathy-glib: tp_connection_dup_contact_by_id_async: don' t crash without Contacts
Simon McVittie
smcv at kemper.freedesktop.org
Fri May 11 05:50:32 PDT 2012
Module: telepathy-glib
Branch: master
Commit: 792f37a447e49accfef9c66d8e5e655cdaea234f
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=792f37a447e49accfef9c66d8e5e655cdaea234f
Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date: Thu May 10 19:00:26 2012 +0100
tp_connection_dup_contact_by_id_async: don't crash without Contacts
Signed-off-by: Simon McVittie <simon.mcvittie at collabora.co.uk>
Reviewed-by: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=49735
---
telepathy-glib/contact.c | 32 ++++++++++++++++++++++++++------
tests/dbus/contacts-slow-path.c | 24 ++++++++++++++++++++++++
2 files changed, 50 insertions(+), 6 deletions(-)
diff --git a/telepathy-glib/contact.c b/telepathy-glib/contact.c
index a80c778..6f17769 100644
--- a/telepathy-glib/contact.c
+++ b/telepathy-glib/contact.c
@@ -4738,8 +4738,6 @@ tp_connection_dup_contact_by_id_async (TpConnection *self,
if (!get_feature_flags (n_features, features, &feature_flags))
return;
- supported_interfaces = contacts_bind_to_signals (self, feature_flags);
-
result = g_simple_async_result_new ((GObject *) self, callback, user_data,
tp_connection_dup_contact_by_id_async);
@@ -4748,11 +4746,33 @@ tp_connection_dup_contact_by_id_async (TpConnection *self,
data->features_array = g_array_sized_new (FALSE, FALSE,
sizeof (TpContactFeature), n_features);
g_array_append_vals (data->features_array, features, n_features);
- tp_cli_connection_interface_contacts_call_get_contact_by_id (self, -1,
- id, supported_interfaces, got_contact_by_id_cb,
- data, NULL, NULL);
- g_free (supported_interfaces);
+ if (tp_proxy_has_interface_by_id (self,
+ TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACTS))
+ {
+ supported_interfaces = contacts_bind_to_signals (self, feature_flags);
+
+ tp_cli_connection_interface_contacts_call_get_contact_by_id (self, -1,
+ id, supported_interfaces, got_contact_by_id_cb,
+ data, NULL, NULL);
+
+ g_free (supported_interfaces);
+ }
+ else
+ {
+ /* Proceed directly to the slow path, do not pass Go, do not collect
+ * £200. contacts_bind_to_signals() relies on having Contacts. */
+
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+ tp_connection_get_contacts_by_id (self, 1,
+ (const gchar * const *) &data->id,
+ data->features_array->len,
+ (TpContactFeature *) data->features_array->data,
+ got_contact_by_id_fallback_cb,
+ data, (GDestroyNotify) contacts_async_data_free, NULL);
+ G_GNUC_END_IGNORE_DEPRECATIONS
+ }
+
g_object_unref (result);
}
diff --git a/tests/dbus/contacts-slow-path.c b/tests/dbus/contacts-slow-path.c
index 31c22f7..fa4b454 100644
--- a/tests/dbus/contacts-slow-path.c
+++ b/tests/dbus/contacts-slow-path.c
@@ -1005,6 +1005,28 @@ test_by_id (Fixture *f,
}
static void
+test_one_by_id (Fixture *f,
+ gconstpointer unused G_GNUC_UNUSED)
+{
+ GAsyncResult *result = NULL;
+ GError *error = NULL;
+ TpContact *contact;
+
+ tp_connection_dup_contact_by_id_async (f->legacy_client_conn,
+ "Alice", 0, NULL, tp_tests_result_ready_cb, &result);
+ tp_tests_run_until_result (&result);
+ contact = tp_connection_dup_contact_by_id_finish (f->legacy_client_conn,
+ result, &error);
+
+ g_assert_no_error (error);
+ g_assert (TP_IS_CONTACT (contact));
+ g_assert_cmpstr (tp_contact_get_identifier (contact), ==, "alice");
+
+ g_clear_object (&result);
+ g_clear_object (&contact);
+}
+
+static void
test_by_handle_again (Fixture *f,
gconstpointer unused G_GNUC_UNUSED)
{
@@ -1271,6 +1293,8 @@ main (int argc,
test_by_handle_upgrade, teardown);
g_test_add ("/contacts-slow-path/dup-if-possible", Fixture, NULL, setup,
test_dup_if_possible, teardown);
+ g_test_add ("/contacts-slow-path/one-by-id", Fixture, NULL, setup,
+ test_one_by_id, teardown);
return g_test_run ();
}
More information about the telepathy-commits
mailing list