aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimo.cecchi@collabora.co.uk>2009-05-24 18:55:30 +0800
committerCosimo Cecchi <cosimoc@gnome.org>2009-06-01 23:53:24 +0800
commitab0ce8a4bde442384f0e2ca6b0de973e75183607 (patch)
tree6ee7d387c645817f7783c343d41f5e6ec3b3bb72
parent67d4fbf275c98ed8478818cd8ee8d6e5d6c83844 (diff)
downloadgsoc2013-empathy-ab0ce8a4bde442384f0e2ca6b0de973e75183607.tar
gsoc2013-empathy-ab0ce8a4bde442384f0e2ca6b0de973e75183607.tar.gz
gsoc2013-empathy-ab0ce8a4bde442384f0e2ca6b0de973e75183607.tar.bz2
gsoc2013-empathy-ab0ce8a4bde442384f0e2ca6b0de973e75183607.tar.lz
gsoc2013-empathy-ab0ce8a4bde442384f0e2ca6b0de973e75183607.tar.xz
gsoc2013-empathy-ab0ce8a4bde442384f0e2ca6b0de973e75183607.tar.zst
gsoc2013-empathy-ab0ce8a4bde442384f0e2ca6b0de973e75183607.zip
Actually check if FT+hash is supported
Use the new API to find out if FT+hash is supported before setting the handler as ready. This gives the clients to use empathy_ft_handler_can_hash reliably before calling empahty_ft_handler_start_transfer to know to which signal they should connect.
-rw-r--r--libempathy/empathy-ft-handler.c114
1 files changed, 74 insertions, 40 deletions
diff --git a/libempathy/empathy-ft-handler.c b/libempathy/empathy-ft-handler.c
index 9315e6538..be40d5e01 100644
--- a/libempathy/empathy-ft-handler.c
+++ b/libempathy/empathy-ft-handler.c
@@ -1010,9 +1010,7 @@ ft_handler_read_async_cb (GObject *source,
hash_data->stream = G_INPUT_STREAM (stream);
hash_data->total_bytes = priv->total_bytes;
hash_data->handler = g_object_ref (handler);
- /* FIXME: should look at the CM capabilities before setting the
- * checksum type?
- */
+ /* FIXME: MD5 is the only ContentHashType supported right now */
hash_data->checksum = g_checksum_new (G_CHECKSUM_MD5);
/* org.freedesktop.Telepathy.Channel.Type.FileTransfer.ContentHashType */
@@ -1027,19 +1025,31 @@ ft_handler_read_async_cb (GObject *source,
}
static void
-find_channel_class_cb (GStrv channel_class,
+callbacks_data_free (gpointer user_data)
+{
+ CallbacksData *data = user_data;
+
+ if (data->handler != NULL)
+ g_object_unref (data->handler);
+
+ g_slice_free (CallbacksData, data);
+}
+
+static void
+find_ft_channel_class_cb (GStrv channel_class,
gpointer user_data)
{
- EmpathyFTHandler *handler = user_data;
- EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
+ CallbacksData *data = user_data;
+ EmpathyFTHandler *handler = data->handler;
gboolean allowed = TRUE;
GError *myerr = NULL;
+ /* this takes care of channel_class == NULL as well */
if (!tp_strv_contains ((const gchar * const *) channel_class,
TP_IFACE_CHANNEL ".TargetHandle"))
allowed = FALSE;
- DEBUG ("check if FT allowed: %s", allowed ? "True" : "False");
+ DEBUG ("check if FT is allowed: %s", allowed ? "True" : "False");
if (!allowed)
{
@@ -1047,47 +1057,67 @@ find_channel_class_cb (GStrv channel_class,
EMPATHY_FT_ERROR_NOT_SUPPORTED,
_("File transfer not supported by remote contact"));
- emit_error_signal (handler, myerr);
+ data->callback (NULL, myerr, data->user_data);
g_clear_error (&myerr);
-
- return;
}
-
- /* populate the request table with all the known properties */
- ft_handler_populate_outgoing_request (handler);
-
- if (priv->use_hash)
- /* start hashing the file */
- g_file_read_async (priv->gfile, G_PRIORITY_DEFAULT,
- priv->cancellable, ft_handler_read_async_cb, handler);
else
- /* push directly the handler to the dispatcher */
- ft_handler_push_to_dispatcher (handler);
+ {
+ data->callback (handler, NULL, data->user_data);
+ }
+
+ callbacks_data_free (data);
}
static void
-ft_handler_complete_request (EmpathyFTHandler *handler)
+find_hash_channel_class_cb (GStrv channel_class,
+ gpointer user_data)
{
- EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
- TpConnection *connection;
+ CallbacksData *data = user_data;
+ EmpathyFTHandler *handler = data->handler;
+ EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
+ gboolean allowed = TRUE;
- /* check if FT is allowed before firing up the I/O machinery */
- connection = empathy_contact_get_connection (priv->contact);
+ /* this takes care of channel_class == NULL as well */
+ if (!tp_strv_contains ((const gchar * const *) channel_class,
+ TP_IFACE_CHANNEL ".TargetHandle"))
+ allowed = FALSE;
+
+ DEBUG ("check if FT+hash is allowed: %s", allowed ? "True" : "False");
+
+ if (!allowed)
+ {
+ priv->use_hash = FALSE;
+
+ /* see if we support FT without hash instead */
+ empathy_dispatcher_find_requestable_channel_classes_async
+ (priv->dispatcher, empathy_contact_get_connection (priv->contact),
+ TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, TP_HANDLE_TYPE_CONTACT,
+ find_ft_channel_class_cb, data, NULL);
- empathy_dispatcher_find_channel_class_async (priv->dispatcher, connection,
- TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, TP_HANDLE_TYPE_CONTACT,
- find_channel_class_cb, handler);
+ return;
+ }
+ else
+ {
+ data->callback (handler, NULL, data->user_data);
+ callbacks_data_free (data);
+ }
}
static void
-callbacks_data_free (gpointer user_data)
+ft_handler_complete_request (EmpathyFTHandler *handler)
{
- CallbacksData *data = user_data;
+ EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
- if (data->handler != NULL)
- g_object_unref (data->handler);
+ /* populate the request table with all the known properties */
+ ft_handler_populate_outgoing_request (handler);
- g_slice_free (CallbacksData, data);
+ if (priv->use_hash)
+ /* start hashing the file */
+ g_file_read_async (priv->gfile, G_PRIORITY_DEFAULT,
+ priv->cancellable, ft_handler_read_async_cb, handler);
+ else
+ /* push directly the handler to the dispatcher */
+ ft_handler_push_to_dispatcher (handler);
}
static void
@@ -1118,11 +1148,7 @@ ft_handler_gfile_ready_cb (GObject *source,
g_object_unref (info);
out:
- if (error == NULL)
- {
- cb_data->callback (cb_data->handler, NULL, cb_data->user_data);
- }
- else
+ if (error != NULL)
{
if (!g_cancellable_is_cancelled (priv->cancellable))
g_cancellable_cancel (priv->cancellable);
@@ -1130,9 +1156,17 @@ out:
cb_data->callback (NULL, error, cb_data->user_data);
g_error_free (error);
g_object_unref (cb_data->handler);
- }
- callbacks_data_free (cb_data);
+ callbacks_data_free (cb_data);
+ }
+ else
+ {
+ /* see if FT/hashing are allowed */
+ empathy_dispatcher_find_requestable_channel_classes_async
+ (priv->dispatcher, empathy_contact_get_connection (priv->contact),
+ TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, TP_HANDLE_TYPE_CONTACT,
+ find_hash_channel_class_cb, cb_data, "ContentHashType", NULL);
+ }
}
static void