From 1514044a96d8b3cd369e993ff5667bb66ec456cb Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 17 Sep 2013 16:13:25 +0100 Subject: [PATCH 1/2] 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. --- 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); } -- 1.8.4.rc3