summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2012-05-10 19:00:26 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2012-05-11 13:44:49 +0100
commit792f37a447e49accfef9c66d8e5e655cdaea234f (patch)
treed28e145320590c67ec3c2ed0ed97367f169e41c8
parent34e4109a86992b88d0cc879618e892f3417cb312 (diff)
tp_connection_dup_contact_by_id_async: don't crash without Contacts
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=49735
-rw-r--r--telepathy-glib/contact.c32
-rw-r--r--tests/dbus/contacts-slow-path.c24
2 files changed, 50 insertions, 6 deletions
diff --git a/telepathy-glib/contact.c b/telepathy-glib/contact.c
index a80c7785f..6f17769f7 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 31c22f7e3..fa4b454e2 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 ();
}