From 1f078e909127f841faefe6664db738092aff862a Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 27 Feb 2014 12:09:16 +0100 Subject: [PATCH 08/11] stop using tp_message_peek() internally --- telepathy-glib/message-mixin.c | 9 ++-- telepathy-glib/message.c | 88 ++++++++++++++++++++++++-------------- telepathy-glib/signalled-message.c | 13 ++++-- 3 files changed, 70 insertions(+), 40 deletions(-) diff --git a/telepathy-glib/message-mixin.c b/telepathy-glib/message-mixin.c index 128fe66..6dc7c44 100644 --- a/telepathy-glib/message-mixin.c +++ b/telepathy-glib/message-mixin.c @@ -685,14 +685,15 @@ tp_message_mixin_has_pending_messages (GObject *object, if (msg != NULL && first_sender != NULL) { - const GHashTable *header = tp_message_peek (msg, 0); - gboolean valid = TRUE; - TpHandle h = tp_asv_get_uint32 (header, "message-sender", &valid); + GVariant *header = tp_message_dup_part (msg, 0); + TpHandle h; - if (valid) + if (g_variant_lookup (header, "message-sender", "u", &h)) *first_sender = h; else WARNING ("oldest message's message-sender is mistyped"); + + g_variant_unref (header); } return (msg != NULL); diff --git a/telepathy-glib/message.c b/telepathy-glib/message.c index ab80365..869574c 100644 --- a/telepathy-glib/message.c +++ b/telepathy-glib/message.c @@ -735,6 +735,22 @@ tp_message_is_mutable (TpMessage *self) return self->priv->mutable; } +static gboolean +lookup_in_header (TpMessage *self, + const gchar *key, + const gchar *type, + gpointer out) +{ + GVariant *header; + gboolean result; + + header = tp_message_dup_part (self, 0); + result = g_variant_lookup (header, key, type, out); + + g_variant_unref (header); + return result; +} + /** * tp_message_dup_token: * @self: a message @@ -753,16 +769,12 @@ tp_message_is_mutable (TpMessage *self) gchar * tp_message_dup_token (TpMessage *self) { - const gchar *token; + gchar *token = NULL; g_return_val_if_fail (TP_IS_MESSAGE (self), NULL); - token = tp_asv_get_string (tp_message_peek (self, 0), "message-token"); - - if (tp_str_empty (token)) - return NULL; - else - return g_strdup (token); + lookup_in_header (self, "message-token", "s", &token); + return token; } /** @@ -778,10 +790,11 @@ tp_message_dup_token (TpMessage *self) TpChannelTextMessageType tp_message_get_message_type (TpMessage *self) { - g_return_val_if_fail (TP_IS_MESSAGE (self), - TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL); + TpChannelTextMessageType msg_type = TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL; + /* if message-type is absent or invalid we just return 0, which is NORMAL */ - return tp_asv_get_uint32 (tp_message_peek (self, 0), "message-type", NULL); + lookup_in_header (self, "message-type", "u", &msg_type); + return msg_type; } /** @@ -803,8 +816,12 @@ tp_message_get_message_type (TpMessage *self) gint64 tp_message_get_sent_timestamp (TpMessage *self) { + gint64 sent = 0; + g_return_val_if_fail (TP_IS_MESSAGE (self), 0); - return tp_asv_get_int64 (tp_message_peek (self, 0), "message-sent", NULL); + + lookup_in_header (self, "message-sent", "x", &sent); + return sent; } /** @@ -822,9 +839,12 @@ tp_message_get_sent_timestamp (TpMessage *self) gint64 tp_message_get_received_timestamp (TpMessage *self) { + gint64 received = 0; + g_return_val_if_fail (TP_IS_MESSAGE (self), 0); - return tp_asv_get_int64 (tp_message_peek (self, 0), "message-received", - NULL); + + lookup_in_header (self, "message-received", "x", &received); + return received; } /** @@ -841,8 +861,12 @@ tp_message_get_received_timestamp (TpMessage *self) gboolean tp_message_is_scrollback (TpMessage *self) { + gboolean scrollback = FALSE; + g_return_val_if_fail (TP_IS_MESSAGE (self), FALSE); - return tp_asv_get_boolean (tp_message_peek (self, 0), "scrollback", NULL); + + lookup_in_header (self, "scrollback", "b", &scrollback); + return scrollback; } /** @@ -864,8 +888,12 @@ tp_message_is_scrollback (TpMessage *self) gboolean tp_message_is_rescued (TpMessage *self) { + gboolean rescued = FALSE; + g_return_val_if_fail (TP_IS_MESSAGE (self), FALSE); - return tp_asv_get_boolean (tp_message_peek (self, 0), "rescued", NULL); + + lookup_in_header (self, "rescued", "b", &rescued); + return rescued; } /** @@ -883,16 +911,12 @@ tp_message_is_rescued (TpMessage *self) gchar * tp_message_dup_supersedes (TpMessage *self) { - const gchar *token; + gchar *token = NULL; g_return_val_if_fail (TP_IS_MESSAGE (self), NULL); - token = tp_asv_get_string (tp_message_peek (self, 0), "supersedes"); - - if (tp_str_empty (token)) - return NULL; - else - return g_strdup (token); + lookup_in_header (self, "supersedes", "s", &token); + return token; } /** @@ -911,15 +935,12 @@ tp_message_dup_supersedes (TpMessage *self) gchar * tp_message_dup_specific_to_interface (TpMessage *self) { - const gchar *interface; + gchar *interface = NULL; g_return_val_if_fail (TP_IS_MESSAGE (self), NULL); - interface = tp_asv_get_string (tp_message_peek (self, 0), "interface"); - if (interface == NULL) - return NULL; - - return g_strdup (interface); + lookup_in_header (self, "supersedes", "s", &interface); + return interface; } /** @@ -936,12 +957,11 @@ tp_message_dup_specific_to_interface (TpMessage *self) gboolean tp_message_is_delivery_report (TpMessage *self) { - gboolean valid; + TpDeliveryStatus status = TP_DELIVERY_STATUS_UNKNOWN; g_return_val_if_fail (TP_IS_MESSAGE (self), FALSE); - tp_asv_get_uint32 (tp_message_peek (self, 0), "delivery-status", &valid); - return valid; + return lookup_in_header (self, "delivery-status", "u", &status); } /** @@ -961,10 +981,12 @@ guint32 tp_message_get_pending_message_id (TpMessage *self, gboolean *valid) { + guint32 id = 0; + g_return_val_if_fail (TP_IS_MESSAGE (self), FALSE); - return tp_asv_get_uint32 (tp_message_peek (self, 0), - "pending-message-id", valid); + lookup_in_header (self, "pending-message-id", "u", &id); + return id; } /* diff --git a/telepathy-glib/signalled-message.c b/telepathy-glib/signalled-message.c index fc34ee7..55ac107 100644 --- a/telepathy-glib/signalled-message.c +++ b/telepathy-glib/signalled-message.c @@ -242,17 +242,24 @@ guint _tp_signalled_message_get_pending_message_id (TpMessage *message, gboolean *valid) { - const GHashTable *part0; + guint id; + GVariant *part0; + gboolean ok; g_return_val_if_fail (TP_IS_SIGNALLED_MESSAGE (message), 0); g_return_val_if_fail (valid != NULL, 0); - part0 = tp_message_peek (message, 0); + part0 = tp_message_dup_part (message, 0); if (part0 == NULL) { *valid = FALSE; return 0; } - return tp_asv_get_uint32 (part0, "pending-message-id", valid); + ok = g_variant_lookup (part0, "pending-message-id", "u", &id); + if (valid != NULL) + *valid = ok; + + g_variant_unref (part0); + return id; } -- 1.8.5.3