[Telepathy-commits] [telepathy-salut/master] send/receive the content-type and description to/from the OOB stanza

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Fri Nov 21 03:46:43 PST 2008


---
 lib/gibber/gibber-file-transfer.c        |   30 ++++++++++++++++++++++++++++++
 lib/gibber/gibber-file-transfer.h        |    2 ++
 lib/gibber/gibber-oob-file-transfer.c    |   26 +++++++++++++++++++++++---
 src/salut-file-transfer-channel.c        |    5 ++++-
 tests/twisted/avahi/test-receive-file.py |    8 +++-----
 tests/twisted/avahi/test-send-file.py    |    5 ++++-
 6 files changed, 66 insertions(+), 10 deletions(-)

diff --git a/lib/gibber/gibber-file-transfer.c b/lib/gibber/gibber-file-transfer.c
index 954acdd..b5f2fe2 100644
--- a/lib/gibber/gibber-file-transfer.c
+++ b/lib/gibber/gibber-file-transfer.c
@@ -56,6 +56,8 @@ enum
   PROP_FILENAME,
   PROP_DIRECTION,
   PROP_CONNECTION,
+  PROP_DESCRIPTION,
+  PROP_CONTENT_TYPE,
   LAST_PROPERTY
 };
 
@@ -115,6 +117,12 @@ gibber_file_transfer_get_property (GObject *object,
       case PROP_CONNECTION:
         g_value_set_object (value, self->priv->connection);
         break;
+      case PROP_DESCRIPTION:
+        g_value_set_string (value, self->description);
+        break;
+      case PROP_CONTENT_TYPE:
+        g_value_set_string (value, self->content_type);
+        break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
         break;
@@ -169,6 +177,12 @@ gibber_file_transfer_set_property (GObject *object,
           g_signal_connect (self->priv->connection, "received-stanza",
               G_CALLBACK (received_stanza_cb), self);
         break;
+      case PROP_DESCRIPTION:
+        self->description = g_value_dup_string (value);
+        break;
+      case PROP_CONTENT_TYPE:
+        self->content_type = g_value_dup_string (value);
+        break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
         break;
@@ -232,6 +246,20 @@ gibber_file_transfer_class_init (GibberFileTransferClass *gibber_file_transfer_c
       G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
   g_object_class_install_property (object_class, PROP_CONNECTION, param_spec);
 
+  param_spec = g_param_spec_string ("description",
+      "Description",
+      "The description of the transferred file", "",
+      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
+      G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
+  g_object_class_install_property (object_class, PROP_DESCRIPTION, param_spec);
+
+  param_spec = g_param_spec_string ("content-type",
+      "Content type",
+      "The content type of the transferred file", "application/octet-stream",
+      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
+      G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
+  g_object_class_install_property (object_class, PROP_CONTENT_TYPE, param_spec);
+
   signals[REMOTE_ACCEPTED] = g_signal_new ("remote-accepted",
       G_OBJECT_CLASS_TYPE (gibber_file_transfer_class),
       G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
@@ -277,6 +305,8 @@ gibber_file_transfer_finalize (GObject *object)
   g_free (self->self_id);
   g_free (self->peer_id);
   g_free (self->filename);
+  g_free (self->description);
+  g_free (self->content_type);
 
   G_OBJECT_CLASS (gibber_file_transfer_parent_class)->finalize (object);
 }
diff --git a/lib/gibber/gibber-file-transfer.h b/lib/gibber/gibber-file-transfer.h
index 561040a..fe1bcce 100644
--- a/lib/gibber/gibber-file-transfer.h
+++ b/lib/gibber/gibber-file-transfer.h
@@ -77,6 +77,8 @@ struct _GibberFileTransfer
   gchar *peer_id;
 
   gchar *filename;
+  gchar *description;
+  gchar *content_type;
 
   GibberFileTransferDirection direction;
 };
diff --git a/lib/gibber/gibber-oob-file-transfer.c b/lib/gibber/gibber-oob-file-transfer.c
index 5dc2533..6dc4532 100644
--- a/lib/gibber/gibber-oob-file-transfer.c
+++ b/lib/gibber/gibber-oob-file-transfer.c
@@ -156,11 +156,14 @@ gibber_oob_file_transfer_new_from_stanza (GibberXmppStanza *stanza,
   GibberOobFileTransfer *self;
   GibberXmppNode *query;
   GibberXmppNode *url_node;
+  GibberXmppNode *desc_node;
   const gchar *self_id;
   const gchar *peer_id;
   const gchar *type;
   const gchar *id;
   const gchar *size;
+  const gchar *description = NULL;
+  const gchar *content_type;
   gchar *url;
   gchar *filename;
 
@@ -199,7 +202,19 @@ gibber_oob_file_transfer_new_from_stanza (GibberXmppStanza *stanza,
     }
   filename++; /* move after the last "/" */
   filename = unescape_filename (filename);
- 
+
+  desc_node = gibber_xmpp_node_get_child (query, "desc");
+  if (desc_node != NULL)
+    {
+      description = desc_node->content;
+    }
+
+  content_type = gibber_xmpp_node_get_attribute (url_node, "mimeType");
+  if (content_type == NULL)
+    {
+      content_type = "application/octet-stream";
+    }
+
   self = g_object_new (GIBBER_TYPE_OOB_FILE_TRANSFER,
       "id", id,
       "self-id", self_id,
@@ -207,6 +222,8 @@ gibber_oob_file_transfer_new_from_stanza (GibberXmppStanza *stanza,
       "filename", filename,
       "connection", connection,
       "direction", GIBBER_FILE_TRANSFER_DIRECTION_INCOMING,
+      "description", description,
+      "content-type", content_type,
       NULL);
 
   size = gibber_xmpp_node_get_attribute (url_node, "size");
@@ -367,6 +384,7 @@ create_transfer_offer (GibberOobFileTransfer *self,
   GibberXmppStanza *stanza;
   GibberXmppNode *query_node;
   GibberXmppNode *url_node;
+  GibberXmppNode *desc_node;
 
   gchar *filename_escaped;
   gchar *url;
@@ -410,9 +428,11 @@ create_transfer_offer (GibberOobFileTransfer *self,
 
   url_node = gibber_xmpp_node_add_child_with_content (query_node, "url", url);
   gibber_xmpp_node_set_attribute (url_node, "type", "file");
+  gibber_xmpp_node_set_attribute (url_node, "mimeType",
+      GIBBER_FILE_TRANSFER (self)->content_type);
 
-  /* FIXME: iChat uses <query mimeType="..."> to send the mime type */
-  /* FIXME: We should send a <desc> node containing the description */
+  desc_node = gibber_xmpp_node_add_child_with_content (query_node, "desc",
+      GIBBER_FILE_TRANSFER (self)->description);
 
   size = gibber_file_transfer_get_size (GIBBER_FILE_TRANSFER (self));
 
diff --git a/src/salut-file-transfer-channel.c b/src/salut-file-transfer-channel.c
index 57c6257..b0ecf2d 100644
--- a/src/salut-file-transfer-channel.c
+++ b/src/salut-file-transfer-channel.c
@@ -909,6 +909,8 @@ send_file_offer (SalutFileTransferChannel *self)
       "peer-id", self->priv->contact->name,
       "filename", self->priv->filename,
       "connection", self->priv->xmpp_connection,
+      "description", self->priv->description,
+      "content-type", self->priv->content_type,
       NULL);
   g_signal_connect (ft, "remote-accepted",
       G_CALLBACK (remote_accepted_cb), self);
@@ -969,9 +971,10 @@ salut_file_transfer_channel_received_file_offer (SalutFileTransferChannel *self,
 
   self->priv->filename = g_strdup (ft->filename);
   self->priv->size = gibber_file_transfer_get_size (ft);
+  self->priv->description = g_strdup (ft->description);
+  self->priv->content_type = g_strdup (ft->content_type);
 
   /* FIXME: missing properties:
-     - content_type
      - content_hash_type and content_hash
      - date
      - initial offset
diff --git a/tests/twisted/avahi/test-receive-file.py b/tests/twisted/avahi/test-receive-file.py
index 81b16d5..c28e4a8 100644
--- a/tests/twisted/avahi/test-receive-file.py
+++ b/tests/twisted/avahi/test-receive-file.py
@@ -111,6 +111,7 @@ def test(q, bus, conn):
     url_node = query.addElement('url', content=url)
     url_node['type'] = 'file'
     url_node['size'] = str(FILE_SIZE)
+    url_node['mimeType'] = FILE_CONTENT_TYPE
     query.addElement('desc', content=FILE_DESCRIPTION)
     outbound.send(iq)
 
@@ -132,16 +133,13 @@ def test(q, bus, conn):
 
     # org.freedesktop.Telepathy.Channel.Type.FileTransfer D-Bus properties
     assert props[ft_name_prefix + '.State'] == FT_STATE_LOCAL_PENDING
-    # The protocol doesn't allow us to send the content-type so use
-    # octet-stream as said in the spec.
-    assert props[ft_name_prefix + '.ContentType'] == 'application/octet-stream'
+    assert props[ft_name_prefix + '.ContentType'] == FILE_CONTENT_TYPE
     assert props[ft_name_prefix + '.Filename'] == FILE_NAME
     assert props[ft_name_prefix + '.Size'] == FILE_SIZE
     # FIXME: How should we deal with the hash properties?
     #assert props[ft_name_prefix + '.ContentHashType'] == FILE_HASH_TYPE
     #assert props[ft_name_prefix + '.ContentHash'] == FILE_HASH
-    # FIXME: Salut should parse the <desc> node and set the description
-    #assert props[ft_name_prefix + '.Description'] == FILE_DESCRIPTION
+    assert props[ft_name_prefix + '.Description'] == FILE_DESCRIPTION
     # FIXME: How should we deal with the Date property?
     #assert props[ft_name_prefix + '.Date'] == 1225278834
     assert props[ft_name_prefix + '.AvailableSocketTypes'] == \
diff --git a/tests/twisted/avahi/test-send-file.py b/tests/twisted/avahi/test-send-file.py
index 4880909..2492439 100644
--- a/tests/twisted/avahi/test-send-file.py
+++ b/tests/twisted/avahi/test-send-file.py
@@ -162,9 +162,12 @@ def test(q, bus, conn):
     url_node = xpath.queryForNodes("/iq/query/url",  iq)[0]
     assert url_node['type'] == 'file'
     assert url_node['size'] == str(FILE_SIZE)
+    assert url_node['mimeType'] == FILE_CONTENT_TYPE
     url = url_node.children[0]
     assert url.endswith(FILE_NAME)
-    # FIXME: Salut should send a <desc> node containing the description
+    desc_node = xpath.queryForNodes("/iq/query/desc",  iq)[0]
+    desc = desc_node.children[0]
+    assert desc == FILE_DESCRIPTION
 
     reply = domish.Element(('', 'iq'))
     reply['to'] = iq['from']
-- 
1.5.6.5




More information about the Telepathy-commits mailing list