From d83535cc0a9f2d0b75ecba17a97db51cb49affb0 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 17 Sep 2013 16:13:25 +0100 Subject: Return UNKNOWN status for non-buddies, rather than raising an error This is consistent with Gabble. Also, don't crash if libpurple gives us a PurpleStatusPrimitive outside the range we understand; guess wildly that it's probably AVAILABLE. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=69474 Reviewed-by: Xavier Claessens --- src/connection-presence.c | 53 +++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/src/connection-presence.c b/src/connection-presence.c index 74ba730..871d212 100644 --- a/src/connection-presence.c +++ b/src/connection-presence.c @@ -36,10 +36,12 @@ typedef enum { HAZE_STATUS_EXT_AWAY, HAZE_STATUS_INVISIBLE, HAZE_STATUS_OFFLINE, + HAZE_STATUS_UNKNOWN, HAZE_NUM_STATUSES } HazeStatusIndex; +/* Indexed by HazeStatusIndex */ static const TpPresenceStatusSpec statuses[] = { { "available", TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, TRUE, arg_specs, NULL, NULL }, @@ -51,6 +53,7 @@ static const TpPresenceStatusSpec statuses[] = { arg_specs, NULL, NULL }, { "hidden", TP_CONNECTION_PRESENCE_TYPE_HIDDEN, TRUE, NULL, NULL, NULL }, { "offline", TP_CONNECTION_PRESENCE_TYPE_OFFLINE, FALSE, NULL, NULL, NULL }, + { "unknown", TP_CONNECTION_PRESENCE_TYPE_UNKNOWN, FALSE, NULL, NULL, NULL }, { NULL, TP_CONNECTION_PRESENCE_TYPE_UNSET, FALSE, NULL, NULL, NULL } }; @@ -61,7 +64,7 @@ static const PurpleStatusPrimitive primitives[] = { PURPLE_STATUS_AWAY, PURPLE_STATUS_EXTENDED_AWAY, PURPLE_STATUS_INVISIBLE, - PURPLE_STATUS_OFFLINE + PURPLE_STATUS_UNSET, }; /* Indexed by PurpleStatusPrimitive */ @@ -87,22 +90,36 @@ _get_tp_status (PurpleStatus *p_status) gchar *message; TpPresenceStatus *tp_status; - g_assert (p_status != NULL); + if (p_status == NULL) + { + status_ix = HAZE_STATUS_UNKNOWN; + } + else + { + type = purple_status_get_type (p_status); + prim = purple_status_type_get_primitive (type); - type = purple_status_get_type (p_status); - prim = purple_status_type_get_primitive (type); - status_ix = status_indices[prim]; + if (prim <= 0 || prim >= G_N_ELEMENTS (status_indices)) + { + /* guess wildly rather than crashing */ + status_ix = HAZE_STATUS_AVAILABLE; + } + else + { + status_ix = status_indices[prim]; + } - xhtml_message = purple_status_get_attr_string (p_status, "message"); - if (xhtml_message) - { - GValue *message_v = g_slice_new0 (GValue); + xhtml_message = purple_status_get_attr_string (p_status, "message"); + if (xhtml_message) + { + GValue *message_v = g_slice_new0 (GValue); - message = purple_markup_strip_html (xhtml_message); - g_value_init (message_v, G_TYPE_STRING); - g_value_set_string (message_v, message); - g_hash_table_insert (arguments, "message", message_v); - g_free (message); + message = purple_markup_strip_html (xhtml_message); + g_value_init (message_v, G_TYPE_STRING); + g_value_set_string (message_v, message); + g_hash_table_insert (arguments, "message", message_v); + g_free (message); + } } tp_status = tp_presence_status_new (status_ix, arguments); @@ -178,22 +195,18 @@ _get_contact_statuses (GObject *obj, if (buddy) { PurplePresence *presence = purple_buddy_get_presence (buddy); + p_status = purple_presence_get_active_status (presence); } else { DEBUG ("[%s] %s isn't on the blist, ergo no status!", conn->account->username, bname); - g_set_error (error, TP_ERROR, TP_ERROR_NOT_AVAILABLE, - "Presence for %u unknown; subscribe to them first", handle); - g_hash_table_destroy (status_table); - status_table = NULL; - break; + p_status = NULL; } } tp_status = _get_tp_status (p_status); - g_hash_table_insert (status_table, GINT_TO_POINTER (handle), tp_status); } -- cgit v1.2.3 From 8442417b414d4144392f1d11cd2a2454bedd1826 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 17 Sep 2013 16:19:23 +0100 Subject: Test unknown presences Bug: https://bugs.freedesktop.org/show_bug.cgi?id=69474 Reviewed-by: Xavier Claessens --- tests/twisted/constants.py | 1 + tests/twisted/presence/presence.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/twisted/constants.py b/tests/twisted/constants.py index d541c75..37d6d52 100644 --- a/tests/twisted/constants.py +++ b/tests/twisted/constants.py @@ -195,6 +195,7 @@ CONN_IFACE_CONTACT_BLOCKING = CONN + '.Interface.ContactBlocking' CONN_IFACE_ADDRESSING = CONN + '.Interface.Addressing1' ATTR_CONTACT_CAPABILITIES = CONN_IFACE_CONTACT_CAPS + '/capabilities' +ATTR_PRESENCE = CONN_IFACE_SIMPLE_PRESENCE + '/presence' STREAM_HANDLER = 'org.freedesktop.Telepathy.Media.StreamHandler' diff --git a/tests/twisted/presence/presence.py b/tests/twisted/presence/presence.py index a3c5854..e35616e 100644 --- a/tests/twisted/presence/presence.py +++ b/tests/twisted/presence/presence.py @@ -1,7 +1,5 @@ """ A simple smoke-test for C.I.SimplePresence - -FIXME: test C.I.Presence too """ import dbus @@ -9,7 +7,9 @@ import dbus from twisted.words.xish import domish, xpath from twisted.words.protocols.jabber.client import IQ +from servicetest import assertEquals from hazetest import exec_test +import constants as cs def test(q, bus, conn, stream): amy_handle = conn.RequestHandles(1, ['amy@foo.com'])[0] @@ -48,6 +48,15 @@ def test(q, bus, conn, stream): # produces. assert event.args[0] == { amy_handle: (2, 'available', 'I may have been drinking') } + amy_handle, asv = conn.Contacts.GetContactByID('amy@foo.com', + [cs.CONN_IFACE_SIMPLE_PRESENCE]) + assertEquals(event.args[0][amy_handle], asv.get(cs.ATTR_PRESENCE)) + + bob_handle, asv = conn.Contacts.GetContactByID('bob@foo.com', + [cs.CONN_IFACE_SIMPLE_PRESENCE]) + assertEquals((cs.PRESENCE_UNKNOWN, 'unknown', ''), + asv.get(cs.ATTR_PRESENCE)) + conn.Disconnect() q.expect('dbus-signal', signal='StatusChanged', args=[2, 1]) -- cgit v1.2.3 From 254a277868df1adb1b1db62f43a3c19944f3bf80 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 17 Sep 2013 17:54:14 +0100 Subject: NEWS --- NEWS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/NEWS b/NEWS index 284b5ba..1d6d5cf 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,12 @@ +telepathy-haze 0.7.2 (UNRELEASED) +================================= + +Fixes: + +• Report contacts with unknown presence as 'unknown' rather than raising + an error, and don't crash if libpurple reports a "primitive status" + that we don't understand (fd.o #69474, Simon) + telepathy-haze 0.7.1 (2013-09-17) ================================= -- cgit v1.2.3