[Telepathy-commits] [telepathy-glib/master] TpMessageMixin: follow the spec for GetPendingMessageContent

Simon McVittie simon.mcvittie at collabora.co.uk
Thu Dec 18 10:41:41 PST 2008


20080519142209-53eee-3cedb89b343ab40d94dbb9436f481b6fefa45a36.gz
---
 telepathy-glib/message-mixin.c |   28 ++++++++++++++++------------
 1 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/telepathy-glib/message-mixin.c b/telepathy-glib/message-mixin.c
index 7a5cc64..c0c1a2e 100644
--- a/telepathy-glib/message-mixin.c
+++ b/telepathy-glib/message-mixin.c
@@ -1143,10 +1143,6 @@ tp_message_mixin_get_pending_message_content_async (
   TpMessage *item;
   GHashTable *ret;
   guint i;
-  GValue empty = { 0 };
-
-  g_value_init (&empty, G_TYPE_STRING);
-  g_value_set_static_string (&empty, "");
 
   node = g_queue_find_custom (mixin->priv->pending,
       GUINT_TO_POINTER (message_id), pending_item_id_equals_data);
@@ -1168,7 +1164,7 @@ tp_message_mixin_get_pending_message_content_async (
     {
       guint part = g_array_index (part_numbers, guint, i);
 
-      if (part >= item->parts->len)
+      if (part == 0 || part >= item->parts->len)
         {
           GError *error = g_error_new (TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
               "part number %u out of range", part);
@@ -1180,23 +1176,31 @@ tp_message_mixin_get_pending_message_content_async (
         }
     }
 
-  ret = g_hash_table_new (NULL, NULL);
+  /* no free callbacks set - we borrow the content from the message */
+  ret = g_hash_table_new (g_direct_hash, g_direct_equal);
+
+  /* FIXME: later, need a way to support streaming content */
 
   for (i = 0; i < part_numbers->len; i++)
     {
       guint part = g_array_index (part_numbers, guint, i);
       GHashTable *part_data;
-      GValue *content;
+      GValue *value;
 
-      g_assert (part < item->parts->len);
+      g_assert (part != 0 && part < item->parts->len);
       part_data = g_ptr_array_index (item->parts, part);
 
-      content = g_hash_table_lookup (part_data, "content");
+      /* skip parts with no type (reserved) */
+      if (tp_asv_get_string (part_data, "type") == NULL)
+        continue;
+
+      value = g_hash_table_lookup (part_data, "content");
 
-      if (content == NULL)
-        content = &empty;
+      /* skip parts with no content */
+      if (value == NULL)
+        continue;
 
-      g_hash_table_insert (ret, GUINT_TO_POINTER (part), content);
+      g_hash_table_insert (ret, GUINT_TO_POINTER (part), value);
     }
 
   tp_svc_channel_interface_messages_return_from_get_pending_message_content (
-- 
1.5.6.5




More information about the Telepathy-commits mailing list