2 * empathy-ft-handler.c - Source for EmpathyFTHandler
3 * Copyright (C) 2009 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Author: Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
22 /* empathy-ft-handler.c */
27 #include <glib/gi18n.h>
28 #include <telepathy-glib/account-channel-request.h>
29 #include <telepathy-glib/util.h>
30 #include <telepathy-glib/dbus.h>
31 #include <telepathy-glib/interfaces.h>
33 #include "empathy-ft-handler.h"
34 #include "empathy-time.h"
35 #include "empathy-utils.h"
37 #define DEBUG_FLAG EMPATHY_DEBUG_FT
38 #include "empathy-debug.h"
41 * SECTION:empathy-ft-handler
42 * @title: EmpathyFTHandler
43 * @short_description: an object representing a File Transfer
44 * @include: libempathy/empathy-ft-handler
46 * #EmpathyFTHandler is the object which represents a File Transfer with all
48 * The creation of an #EmpathyFTHandler is done with
49 * empathy_ft_handler_new_outgoing() or empathy_ft_handler_new_incoming(),
50 * even though clients should not need to call them directly, as
51 * #EmpathyFTFactory does it for them. Remember that for the file transfer
52 * to work with an incoming handler,
53 * empathy_ft_handler_incoming_set_destination() should be called after
54 * empathy_ft_handler_new_incoming(). #EmpathyFTFactory does this
56 * It's important to note that, as the creation of the handlers is async, once
57 * an handler is created, it already has all the interesting properties set,
58 * like filename, total bytes, content type and so on, making it useful
59 * to be displayed in an UI.
60 * The transfer API works like a state machine; it has three signals,
61 * ::transfer-started, ::transfer-progress, ::transfer-done, which will be
62 * emitted in the relevant phases.
63 * In addition, if the handler is created with checksumming enabled,
64 * other three signals (::hashing-started, ::hashing-progress, ::hashing-done)
65 * will be emitted before or after the transfer, depending on the direction
66 * (respectively outgoing and incoming) of the handler.
67 * At any time between the call to empathy_ft_handler_start_transfer() and
68 * the last signal, a ::transfer-error can be emitted, indicating that an
69 * error has happened in the operation. The message of the error is localized
73 G_DEFINE_TYPE (EmpathyFTHandler, empathy_ft_handler, G_TYPE_OBJECT)
75 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyFTHandler)
77 #define BUFFER_SIZE 4096
86 PROP_MODIFICATION_TIME,
88 PROP_TRANSFERRED_BYTES,
104 GInputStream *stream;
105 GError *error /* comment to make the style checker happy */;
110 EmpathyFTHandler *handler;
114 EmpathyFTHandlerReadyCallback callback;
116 EmpathyFTHandler *handler;
121 gboolean dispose_run;
124 TpFileTransferChannel *channel;
125 GCancellable *cancellable;
128 /* request for the new transfer */
131 /* transfer properties */
132 EmpathyContact *contact;
137 guint64 transferred_bytes;
140 TpFileHashType content_hash_type;
142 gint64 user_action_time;
146 guint remaining_time;
147 gint64 last_update_time;
149 gboolean is_completed;
150 } EmpathyFTHandlerPriv;
152 static guint signals[LAST_SIGNAL] = { 0 };
154 static gboolean do_hash_job_incoming (GIOSchedulerJob *job,
155 GCancellable *cancellable, gpointer user_data);
157 /* GObject implementations */
159 do_get_property (GObject *object,
164 EmpathyFTHandlerPriv *priv = GET_PRIV (object);
169 g_value_set_object (value, priv->contact);
171 case PROP_CONTENT_TYPE:
172 g_value_set_string (value, priv->content_type);
174 case PROP_DESCRIPTION:
175 g_value_set_string (value, priv->description);
178 g_value_set_string (value, priv->filename);
180 case PROP_MODIFICATION_TIME:
181 g_value_set_uint64 (value, priv->mtime);
183 case PROP_TOTAL_BYTES:
184 g_value_set_uint64 (value, priv->total_bytes);
186 case PROP_TRANSFERRED_BYTES:
187 g_value_set_uint64 (value, priv->transferred_bytes);
190 g_value_set_object (value, priv->gfile);
193 g_value_set_object (value, priv->channel);
195 case PROP_USER_ACTION_TIME:
196 g_value_set_int64 (value, priv->user_action_time);
199 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
204 do_set_property (GObject *object,
209 EmpathyFTHandlerPriv *priv = GET_PRIV (object);
214 priv->contact = g_value_dup_object (value);
216 case PROP_CONTENT_TYPE:
217 priv->content_type = g_value_dup_string (value);
219 case PROP_DESCRIPTION:
220 priv->description = g_value_dup_string (value);
223 priv->filename = g_value_dup_string (value);
225 case PROP_MODIFICATION_TIME:
226 priv->mtime = g_value_get_uint64 (value);
228 case PROP_TOTAL_BYTES:
229 priv->total_bytes = g_value_get_uint64 (value);
231 case PROP_TRANSFERRED_BYTES:
232 priv->transferred_bytes = g_value_get_uint64 (value);
235 priv->gfile = g_value_dup_object (value);
238 priv->channel = g_value_dup_object (value);
240 case PROP_USER_ACTION_TIME:
241 priv->user_action_time = g_value_get_int64 (value);
244 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
249 do_dispose (GObject *object)
251 EmpathyFTHandlerPriv *priv = GET_PRIV (object);
253 if (priv->dispose_run)
256 priv->dispose_run = TRUE;
258 if (priv->contact != NULL) {
259 g_object_unref (priv->contact);
260 priv->contact = NULL;
263 if (priv->gfile != NULL) {
264 g_object_unref (priv->gfile);
268 if (priv->channel != NULL) {
269 tp_channel_close_async (TP_CHANNEL (priv->channel), NULL, NULL);
270 g_object_unref (priv->channel);
271 priv->channel = NULL;
274 if (priv->cancellable != NULL) {
275 g_object_unref (priv->cancellable);
276 priv->cancellable = NULL;
279 if (priv->request != NULL)
281 g_hash_table_unref (priv->request);
282 priv->request = NULL;
285 G_OBJECT_CLASS (empathy_ft_handler_parent_class)->dispose (object);
289 do_finalize (GObject *object)
291 EmpathyFTHandlerPriv *priv = GET_PRIV (object);
293 DEBUG ("%p", object);
295 g_free (priv->content_type);
296 priv->content_type = NULL;
298 g_free (priv->filename);
299 priv->filename = NULL;
301 g_free (priv->description);
302 priv->description = NULL;
304 g_free (priv->content_hash);
305 priv->content_hash = NULL;
307 G_OBJECT_CLASS (empathy_ft_handler_parent_class)->finalize (object);
311 empathy_ft_handler_class_init (EmpathyFTHandlerClass *klass)
313 GObjectClass *object_class = G_OBJECT_CLASS (klass);
314 GParamSpec *param_spec;
316 g_type_class_add_private (klass, sizeof (EmpathyFTHandlerPriv));
318 object_class->get_property = do_get_property;
319 object_class->set_property = do_set_property;
320 object_class->dispose = do_dispose;
321 object_class->finalize = do_finalize;
326 * EmpathyFTHandler:contact:
328 * The remote #EmpathyContact for the transfer
330 param_spec = g_param_spec_object ("contact",
331 "contact", "The remote contact",
332 EMPATHY_TYPE_CONTACT,
333 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
334 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
337 * EmpathyFTHandler:content-type:
339 * The content type of the file being transferred
341 param_spec = g_param_spec_string ("content-type",
342 "content-type", "The content type of the file", NULL,
343 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
344 g_object_class_install_property (object_class,
345 PROP_CONTENT_TYPE, param_spec);
348 * EmpathyFTHandler:description:
350 * The description of the file being transferred
352 param_spec = g_param_spec_string ("description",
353 "description", "The description of the file", NULL,
354 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
355 g_object_class_install_property (object_class,
356 PROP_DESCRIPTION, param_spec);
359 * EmpathyFTHandler:filename:
361 * The name of the file being transferred
363 param_spec = g_param_spec_string ("filename",
364 "filename", "The name of the file", NULL,
365 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
366 g_object_class_install_property (object_class,
367 PROP_FILENAME, param_spec);
370 * EmpathyFTHandler:modification-time:
372 * The modification time of the file being transferred
374 param_spec = g_param_spec_uint64 ("modification-time",
375 "modification-time", "The mtime of the file", 0,
376 G_MAXUINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
377 g_object_class_install_property (object_class,
378 PROP_MODIFICATION_TIME, param_spec);
381 * EmpathyFTHandler:total-bytes:
383 * The size (in bytes) of the file being transferred
385 param_spec = g_param_spec_uint64 ("total-bytes",
386 "total-bytes", "The size of the file", 0,
387 G_MAXUINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
388 g_object_class_install_property (object_class,
389 PROP_TOTAL_BYTES, param_spec);
392 * EmpathyFTHandler:transferred-bytes:
394 * The number of the bytes already transferred
396 param_spec = g_param_spec_uint64 ("transferred-bytes",
397 "transferred-bytes", "The number of bytes already transferred", 0,
398 G_MAXUINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
399 g_object_class_install_property (object_class,
400 PROP_TRANSFERRED_BYTES, param_spec);
403 * EmpathyFTHandler:gfile:
405 * The #GFile object where the transfer actually happens
407 param_spec = g_param_spec_object ("gfile",
408 "gfile", "The GFile we're handling",
410 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
411 g_object_class_install_property (object_class, PROP_G_FILE, param_spec);
414 * EmpathyFTHandler:channel:
416 * The underlying #TpFileTransferChannel managing the transfer
418 param_spec = g_param_spec_object ("channel",
419 "channel", "The file transfer channel",
420 TP_TYPE_FILE_TRANSFER_CHANNEL,
421 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
422 g_object_class_install_property (object_class, PROP_CHANNEL, param_spec);
424 param_spec = g_param_spec_int64 ("user-action-time", "user action time",
427 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
428 g_object_class_install_property (object_class, PROP_USER_ACTION_TIME,
434 * EmpathyFTHandler::transfer-started
435 * @handler: the object which has received the signal
436 * @channel: the #TpFileTransferChannel for which the transfer has started
438 * This signal is emitted when the actual transfer starts.
440 signals[TRANSFER_STARTED] =
441 g_signal_new ("transfer-started", G_TYPE_FROM_CLASS (klass),
442 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
443 g_cclosure_marshal_generic,
445 1, TP_TYPE_FILE_TRANSFER_CHANNEL);
448 * EmpathyFTHandler::transfer-done
449 * @handler: the object which has received the signal
450 * @channel: the #TpFileTransferChannel for which the transfer has started
452 * This signal will be emitted when the actual transfer is completed
455 signals[TRANSFER_DONE] =
456 g_signal_new ("transfer-done", G_TYPE_FROM_CLASS (klass),
457 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
458 g_cclosure_marshal_generic,
460 1, TP_TYPE_FILE_TRANSFER_CHANNEL);
463 * EmpathyFTHandler::transfer-error
464 * @handler: the object which has received the signal
467 * This signal can be emitted anytime between the call to
468 * empathy_ft_handler_start_transfer() and the last expected signal
469 * (::transfer-done or ::hashing-done), and it's guaranteed to be the last
470 * signal coming from the handler, meaning that no other operation will
471 * take place after this signal.
473 signals[TRANSFER_ERROR] =
474 g_signal_new ("transfer-error", G_TYPE_FROM_CLASS (klass),
475 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
476 g_cclosure_marshal_generic,
481 * EmpathyFTHandler::transfer-progress
482 * @handler: the object which has received the signal
483 * @current_bytes: the bytes currently transferred
484 * @total_bytes: the total bytes of the handler
485 * @remaining_time: the number of seconds remaining for the transfer
487 * @speed: the current speed of the transfer (in KB/s)
489 * This signal is emitted to notify clients of the progress of the
492 signals[TRANSFER_PROGRESS] =
493 g_signal_new ("transfer-progress", G_TYPE_FROM_CLASS (klass),
494 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
495 g_cclosure_marshal_generic,
497 4, G_TYPE_UINT64, G_TYPE_UINT64, G_TYPE_UINT, G_TYPE_DOUBLE);
500 * EmpathyFTHandler::hashing-started
501 * @handler: the object which has received the signal
503 * This signal is emitted when the hashing operation of the handler
504 * is started. Note that this might happen or not, depending on the CM
505 * and remote contact capabilities. Clients shoud use
506 * empathy_ft_handler_get_use_hash() before calling
507 * empathy_ft_handler_start_transfer() to know whether they should connect
510 signals[HASHING_STARTED] =
511 g_signal_new ("hashing-started", G_TYPE_FROM_CLASS (klass),
512 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
513 g_cclosure_marshal_generic,
517 * EmpathyFTHandler::hashing-progress
518 * @handler: the object which has received the signal
519 * @current_bytes: the bytes currently hashed
520 * @total_bytes: the total bytes of the handler
522 * This signal is emitted to notify clients of the progress of the
525 signals[HASHING_PROGRESS] =
526 g_signal_new ("hashing-progress", G_TYPE_FROM_CLASS (klass),
527 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
528 g_cclosure_marshal_generic,
530 2, G_TYPE_UINT64, G_TYPE_UINT64);
533 * EmpathyFTHandler::hashing-done
534 * @handler: the object which has received the signal
536 * This signal is emitted when the hashing operation of the handler
539 signals[HASHING_DONE] =
540 g_signal_new ("hashing-done", G_TYPE_FROM_CLASS (klass),
541 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
542 g_cclosure_marshal_generic,
547 empathy_ft_handler_init (EmpathyFTHandler *self)
549 EmpathyFTHandlerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
550 EMPATHY_TYPE_FT_HANDLER, EmpathyFTHandlerPriv);
553 priv->cancellable = g_cancellable_new ();
556 /* private functions */
559 hash_data_free (HashingData *data)
561 g_free (data->buffer);
563 if (data->stream != NULL)
564 g_object_unref (data->stream);
566 if (data->checksum != NULL)
567 g_checksum_free (data->checksum);
569 if (data->error != NULL)
570 g_error_free (data->error);
572 if (data->handler != NULL)
573 g_object_unref (data->handler);
575 g_slice_free (HashingData, data);
579 tp_file_hash_to_g_checksum (TpFileHashType type)
581 GChecksumType retval;
585 case TP_FILE_HASH_TYPE_MD5:
586 retval = G_CHECKSUM_MD5;
588 case TP_FILE_HASH_TYPE_SHA1:
589 retval = G_CHECKSUM_SHA1;
591 case TP_FILE_HASH_TYPE_SHA256:
592 retval = G_CHECKSUM_SHA256;
594 case TP_FILE_HASH_TYPE_NONE:
596 g_assert_not_reached ();
604 check_hash_incoming (EmpathyFTHandler *handler)
606 HashingData *hash_data;
607 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
609 if (!EMP_STR_EMPTY (priv->content_hash))
611 hash_data = g_slice_new0 (HashingData);
612 hash_data->total_bytes = priv->total_bytes;
613 hash_data->handler = g_object_ref (handler);
614 hash_data->checksum = g_checksum_new
615 (tp_file_hash_to_g_checksum (priv->content_hash_type));
617 g_signal_emit (handler, signals[HASHING_STARTED], 0);
619 g_io_scheduler_push_job (do_hash_job_incoming, hash_data, NULL,
620 G_PRIORITY_DEFAULT, priv->cancellable);
625 emit_error_signal (EmpathyFTHandler *handler,
628 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
630 DEBUG ("Error in transfer: %s\n", error->message);
632 if (!g_cancellable_is_cancelled (priv->cancellable))
633 g_cancellable_cancel (priv->cancellable);
635 g_signal_emit (handler, signals[TRANSFER_ERROR], 0, error);
639 update_remaining_time_and_speed (EmpathyFTHandler *handler,
640 guint64 transferred_bytes)
642 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
643 gint64 elapsed_time, current_time;
644 guint64 transferred, last_transferred_bytes;
648 last_transferred_bytes = priv->transferred_bytes;
649 priv->transferred_bytes = transferred_bytes;
651 current_time = empathy_time_get_current ();
652 elapsed_time = current_time - priv->last_update_time;
654 if (elapsed_time >= 1)
656 transferred = transferred_bytes - last_transferred_bytes;
657 speed = (gdouble) transferred / (gdouble) elapsed_time;
658 remaining_time = (priv->total_bytes - priv->transferred_bytes) / speed;
660 priv->remaining_time = remaining_time;
661 priv->last_update_time = current_time;
666 ft_transfer_transferred_bytes_cb (TpFileTransferChannel *channel,
668 EmpathyFTHandler *handler)
670 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
673 if (empathy_ft_handler_is_cancelled (handler))
676 bytes = tp_file_transfer_channel_get_transferred_bytes (channel);
678 if (priv->transferred_bytes == 0)
680 priv->last_update_time = empathy_time_get_current ();
681 g_signal_emit (handler, signals[TRANSFER_STARTED], 0, channel);
684 if (priv->transferred_bytes != bytes)
686 update_remaining_time_and_speed (handler, bytes);
688 g_signal_emit (handler, signals[TRANSFER_PROGRESS], 0,
689 bytes, priv->total_bytes, priv->remaining_time,
695 ft_transfer_provide_cb (GObject *source,
696 GAsyncResult *result,
699 TpFileTransferChannel *channel = TP_FILE_TRANSFER_CHANNEL (source);
700 EmpathyFTHandler *handler = user_data;
701 GError *error = NULL;
703 if (!tp_file_transfer_channel_provide_file_finish (channel, result, &error))
705 emit_error_signal (handler, error);
706 g_clear_error (&error);
711 ft_transfer_accept_cb (GObject *source,
712 GAsyncResult *result,
715 TpFileTransferChannel *channel = TP_FILE_TRANSFER_CHANNEL (source);
716 EmpathyFTHandler *handler = user_data;
717 GError *error = NULL;
719 if (!tp_file_transfer_channel_accept_file_finish (channel, result, &error))
721 emit_error_signal (handler, error);
722 g_clear_error (&error);
727 error_from_state_change_reason (TpFileTransferStateChangeReason reason)
730 GError *retval = NULL;
736 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE:
737 string = _("No reason was specified");
739 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REQUESTED:
740 string = _("The change in state was requested");
742 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_STOPPED:
743 string = _("You canceled the file transfer");
745 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_STOPPED:
746 string = _("The other participant canceled the file transfer");
748 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_ERROR:
749 string = _("Error while trying to transfer the file");
751 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_ERROR:
752 string = _("The other participant is unable to transfer the file");
755 string = _("Unknown reason");
759 retval = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
760 EMPATHY_FT_ERROR_TP_ERROR, string);
766 ft_transfer_state_cb (TpFileTransferChannel *channel,
768 EmpathyFTHandler *handler)
770 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
771 TpFileTransferStateChangeReason reason;
772 TpFileTransferState state = tp_file_transfer_channel_get_state (
775 if (state == TP_FILE_TRANSFER_STATE_COMPLETED)
777 priv->is_completed = TRUE;
778 g_signal_emit (handler, signals[TRANSFER_DONE], 0, channel);
780 tp_channel_close_async (TP_CHANNEL (channel), NULL, NULL);
782 if (empathy_ft_handler_is_incoming (handler) && priv->use_hash)
784 check_hash_incoming (handler);
787 else if (state == TP_FILE_TRANSFER_STATE_CANCELLED)
789 GError *error = error_from_state_change_reason (reason);
790 emit_error_signal (handler, error);
791 g_clear_error (&error);
796 ft_handler_create_channel_cb (GObject *source,
797 GAsyncResult *result,
800 EmpathyFTHandler *handler = user_data;
801 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
802 GError *error = NULL;
805 DEBUG ("Dispatcher create channel CB");
807 channel = tp_account_channel_request_create_and_handle_channel_finish (
808 TP_ACCOUNT_CHANNEL_REQUEST (source), result, NULL, &error);
811 DEBUG ("Failed to request FT channel: %s", error->message);
813 g_cancellable_set_error_if_cancelled (priv->cancellable, &error);
817 emit_error_signal (handler, error);
819 g_clear_object (&channel);
820 g_error_free (error);
824 priv->channel = TP_FILE_TRANSFER_CHANNEL (channel);
826 tp_g_signal_connect_object (priv->channel, "notify::state",
827 G_CALLBACK (ft_transfer_state_cb), handler, 0);
828 tp_g_signal_connect_object (priv->channel, "notify::transferred-bytes",
829 G_CALLBACK (ft_transfer_transferred_bytes_cb), handler, 0);
831 tp_file_transfer_channel_provide_file_async (priv->channel, priv->gfile,
832 ft_transfer_provide_cb, handler);
836 ft_handler_push_to_dispatcher (EmpathyFTHandler *handler)
839 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
840 TpAccountChannelRequest *req;
842 DEBUG ("Pushing request to the dispatcher");
844 account = empathy_contact_get_account (priv->contact);
846 req = tp_account_channel_request_new (account, priv->request,
847 priv->user_action_time);
849 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
850 ft_handler_create_channel_cb, handler);
852 g_object_unref (req);
856 ft_handler_populate_outgoing_request (EmpathyFTHandler *handler)
858 guint contact_handle;
859 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
862 contact_handle = empathy_contact_get_handle (priv->contact);
863 uri = g_file_get_uri (priv->gfile);
865 priv->request = tp_asv_new (
866 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
867 TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER,
868 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
869 TP_HANDLE_TYPE_CONTACT,
870 TP_PROP_CHANNEL_TARGET_HANDLE, G_TYPE_UINT,
872 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_TYPE, G_TYPE_STRING,
874 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_FILENAME, G_TYPE_STRING,
876 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_SIZE, G_TYPE_UINT64,
878 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_DATE, G_TYPE_UINT64,
880 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_URI, G_TYPE_STRING, uri,
887 hash_job_done (gpointer user_data)
889 HashingData *hash_data = user_data;
890 EmpathyFTHandler *handler = hash_data->handler;
891 EmpathyFTHandlerPriv *priv;
892 GError *error = NULL;
894 DEBUG ("Closing stream after hashing.");
896 priv = GET_PRIV (handler);
898 if (hash_data->error != NULL)
900 error = hash_data->error;
901 hash_data->error = NULL;
905 DEBUG ("Got file hash %s", g_checksum_get_string (hash_data->checksum));
907 if (empathy_ft_handler_is_incoming (handler))
909 if (g_strcmp0 (g_checksum_get_string (hash_data->checksum),
912 DEBUG ("Hash mismatch when checking incoming handler: "
913 "received %s, calculated %s", priv->content_hash,
914 g_checksum_get_string (hash_data->checksum));
916 error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
917 EMPATHY_FT_ERROR_HASH_MISMATCH,
918 _("File transfer completed, but the file was corrupted"));
923 DEBUG ("Hash verification matched, received %s, calculated %s",
925 g_checksum_get_string (hash_data->checksum));
930 /* set the checksum in the request...
931 * org.freedesktop.Telepathy.Channel.Type.FileTransfer.ContentHash
933 tp_asv_set_string (priv->request,
934 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH,
935 g_checksum_get_string (hash_data->checksum));
942 emit_error_signal (handler, error);
943 g_clear_error (&error);
947 g_signal_emit (handler, signals[HASHING_DONE], 0);
949 if (!empathy_ft_handler_is_incoming (handler))
950 /* the request is complete now, push it to the dispatcher */
951 ft_handler_push_to_dispatcher (handler);
954 hash_data_free (hash_data);
960 emit_hashing_progress (gpointer user_data)
962 HashingData *hash_data = user_data;
964 g_signal_emit (hash_data->handler, signals[HASHING_PROGRESS], 0,
965 (guint64) hash_data->total_read, (guint64) hash_data->total_bytes);
971 do_hash_job (GIOSchedulerJob *job,
972 GCancellable *cancellable,
975 HashingData *hash_data = user_data;
977 GError *error = NULL;
980 if (hash_data->buffer == NULL)
981 hash_data->buffer = g_malloc0 (BUFFER_SIZE);
983 bytes_read = g_input_stream_read (hash_data->stream, hash_data->buffer,
984 BUFFER_SIZE, cancellable, &error);
988 hash_data->total_read += bytes_read;
990 /* we now have the chunk */
993 g_checksum_update (hash_data->checksum, hash_data->buffer, bytes_read);
994 g_io_scheduler_job_send_to_mainloop_async (job, emit_hashing_progress,
997 g_free (hash_data->buffer);
998 hash_data->buffer = NULL;
1004 g_input_stream_close (hash_data->stream, cancellable, &error);
1009 hash_data->error = error;
1011 g_io_scheduler_job_send_to_mainloop_async (job, hash_job_done,
1018 do_hash_job_incoming (GIOSchedulerJob *job,
1019 GCancellable *cancellable,
1022 HashingData *hash_data = user_data;
1023 EmpathyFTHandler *handler = hash_data->handler;
1024 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
1025 GError *error = NULL;
1027 DEBUG ("checking integrity for incoming handler");
1029 /* need to get the stream first */
1031 G_INPUT_STREAM (g_file_read (priv->gfile, cancellable, &error));
1035 hash_data->error = error;
1036 g_io_scheduler_job_send_to_mainloop_async (job, hash_job_done,
1041 return do_hash_job (job, cancellable, user_data);
1045 ft_handler_read_async_cb (GObject *source,
1049 GFileInputStream *stream;
1050 GError *error = NULL;
1051 HashingData *hash_data;
1052 EmpathyFTHandler *handler = user_data;
1053 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
1055 DEBUG ("GFile read async CB.");
1057 stream = g_file_read_finish (priv->gfile, res, &error);
1060 emit_error_signal (handler, error);
1061 g_clear_error (&error);
1066 hash_data = g_slice_new0 (HashingData);
1067 hash_data->stream = G_INPUT_STREAM (stream);
1068 hash_data->total_bytes = priv->total_bytes;
1069 hash_data->handler = g_object_ref (handler);
1070 /* FIXME: MD5 is the only ContentHashType supported right now */
1071 hash_data->checksum = g_checksum_new (G_CHECKSUM_MD5);
1073 tp_asv_set_uint32 (priv->request,
1074 TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH_TYPE,
1075 TP_FILE_HASH_TYPE_MD5);
1077 g_signal_emit (handler, signals[HASHING_STARTED], 0);
1079 g_io_scheduler_push_job (do_hash_job, hash_data, NULL,
1080 G_PRIORITY_DEFAULT, priv->cancellable);
1084 callbacks_data_free (gpointer user_data)
1086 CallbacksData *data = user_data;
1088 if (data->handler != NULL)
1089 g_object_unref (data->handler);
1091 g_slice_free (CallbacksData, data);
1095 set_content_hash_type_from_classes (EmpathyFTHandler *handler,
1098 GArray *possible_values;
1101 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
1102 gboolean support_ft = FALSE;
1105 possible_values = g_array_new (TRUE, TRUE, sizeof (guint));
1107 for (i = 0; i < classes->len; i++)
1111 const gchar *chan_type;
1113 tp_value_array_unpack (g_ptr_array_index (classes, i), 2,
1116 chan_type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE);
1118 if (tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER))
1121 if (tp_asv_get_uint32 (fixed, TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, NULL) !=
1122 TP_HANDLE_TYPE_CONTACT)
1127 value = tp_asv_get_uint32
1128 (fixed, TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH_TYPE,
1132 g_array_append_val (possible_values, value);
1137 g_array_unref (possible_values);
1141 if (possible_values->len == 0)
1143 /* there are no channel classes with hash support, disable it. */
1144 priv->use_hash = FALSE;
1145 priv->content_hash_type = TP_FILE_HASH_TYPE_NONE;
1150 priv->use_hash = TRUE;
1152 if (possible_values->len == 1)
1154 priv->content_hash_type = g_array_index (possible_values, guint, 0);
1158 /* order the array and pick the first non zero, so that MD5
1159 * is the preferred value.
1161 g_array_sort (possible_values, empathy_uint_compare);
1163 if (g_array_index (possible_values, guint, 0) == 0)
1164 priv->content_hash_type = g_array_index (possible_values, guint, 1);
1166 priv->content_hash_type = g_array_index (possible_values, guint, 0);
1170 g_array_unref (possible_values);
1172 DEBUG ("Hash enabled %s; setting content hash type as %u",
1173 priv->use_hash ? "True" : "False", priv->content_hash_type);
1179 check_hashing (CallbacksData *data)
1181 EmpathyFTHandler *handler = data->handler;
1182 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
1183 GError *myerr = NULL;
1184 TpCapabilities *caps;
1188 conn = empathy_contact_get_connection (priv->contact);
1190 caps = tp_connection_get_capabilities (conn);
1193 data->callback (handler, NULL, data->user_data);
1197 classes = tp_capabilities_get_channel_classes (caps);
1199 /* set whether we support hash and the type of it */
1200 if (!set_content_hash_type_from_classes (handler, classes))
1202 g_set_error_literal (&myerr, EMPATHY_FT_ERROR_QUARK,
1203 EMPATHY_FT_ERROR_NOT_SUPPORTED,
1204 _("File transfer not supported by remote contact"));
1206 if (!g_cancellable_is_cancelled (priv->cancellable))
1207 g_cancellable_cancel (priv->cancellable);
1209 data->callback (handler, myerr, data->user_data);
1210 g_clear_error (&myerr);
1214 /* get back to the caller now */
1215 data->callback (handler, NULL, data->user_data);
1219 callbacks_data_free (data);
1223 ft_handler_complete_request (EmpathyFTHandler *handler)
1225 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
1227 /* populate the request table with all the known properties */
1228 ft_handler_populate_outgoing_request (handler);
1231 /* start hashing the file */
1232 g_file_read_async (priv->gfile, G_PRIORITY_DEFAULT,
1233 priv->cancellable, ft_handler_read_async_cb, handler);
1235 /* push directly the handler to the dispatcher */
1236 ft_handler_push_to_dispatcher (handler);
1240 ft_handler_gfile_ready_cb (GObject *source,
1242 CallbacksData *cb_data)
1245 GError *error = NULL;
1247 EmpathyFTHandlerPriv *priv = GET_PRIV (cb_data->handler);
1249 DEBUG ("Got GFileInfo.");
1251 info = g_file_query_info_finish (priv->gfile, res, &error);
1256 if (g_file_info_get_file_type (info) != G_FILE_TYPE_REGULAR)
1258 error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
1259 EMPATHY_FT_ERROR_INVALID_SOURCE_FILE,
1260 _("The selected file is not a regular file"));
1264 priv->total_bytes = g_file_info_get_size (info);
1265 if (priv->total_bytes == 0)
1267 error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
1268 EMPATHY_FT_ERROR_EMPTY_SOURCE_FILE,
1269 _("The selected file is empty"));
1273 priv->content_type = g_strdup (g_file_info_get_content_type (info));
1274 priv->filename = g_strdup (g_file_info_get_display_name (info));
1275 g_file_info_get_modification_time (info, &mtime);
1276 priv->mtime = mtime.tv_sec;
1277 priv->transferred_bytes = 0;
1278 priv->description = NULL;
1280 g_object_unref (info);
1285 if (!g_cancellable_is_cancelled (priv->cancellable))
1286 g_cancellable_cancel (priv->cancellable);
1288 cb_data->callback (cb_data->handler, error, cb_data->user_data);
1289 g_error_free (error);
1291 callbacks_data_free (cb_data);
1295 /* see if FT/hashing are allowed */
1296 check_hashing (cb_data);
1301 channel_get_all_properties_cb (TpProxy *proxy,
1302 GHashTable *properties,
1303 const GError *error,
1305 GObject *weak_object)
1307 CallbacksData *cb_data = user_data;
1308 EmpathyFTHandler *handler = EMPATHY_FT_HANDLER (weak_object);
1309 EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
1314 if (!g_cancellable_is_cancelled (priv->cancellable))
1315 g_cancellable_cancel (priv->cancellable);
1317 cb_data->callback (handler, (GError *) error, cb_data->user_data);
1319 callbacks_data_free (cb_data);
1323 priv->content_hash = g_value_dup_string (
1324 g_hash_table_lookup (properties, "ContentHash"));
1326 priv->content_hash_type = g_value_get_uint (
1327 g_hash_table_lookup (properties, "ContentHashType"));
1329 contact = tp_channel_get_target_contact (TP_CHANNEL (proxy));
1330 priv->contact = empathy_contact_dup_from_tp_contact (contact);
1332 cb_data->callback (handler, NULL, cb_data->user_data);
1335 /* public methods */
1338 * empathy_ft_handler_new_outgoing:
1339 * @contact: the #EmpathyContact to send @source to
1340 * @source: the #GFile to send
1341 * @callback: callback to be called when the handler has been created
1342 * @user_data: user data to be passed to @callback
1344 * Triggers the creation of a new #EmpathyFTHandler for an outgoing transfer.
1347 empathy_ft_handler_new_outgoing (EmpathyContact *contact,
1350 EmpathyFTHandlerReadyCallback callback,
1353 EmpathyFTHandler *handler;
1354 CallbacksData *data;
1355 EmpathyFTHandlerPriv *priv;
1357 DEBUG ("New handler outgoing");
1359 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1360 g_return_if_fail (G_IS_FILE (source));
1362 handler = g_object_new (EMPATHY_TYPE_FT_HANDLER,
1365 "user-action-time", action_time,
1368 priv = GET_PRIV (handler);
1370 data = g_slice_new0 (CallbacksData);
1371 data->callback = callback;
1372 data->user_data = user_data;
1373 data->handler = g_object_ref (handler);
1375 /* start collecting info about the file */
1376 g_file_query_info_async (priv->gfile,
1377 G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
1378 G_FILE_ATTRIBUTE_STANDARD_SIZE ","
1379 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
1380 G_FILE_ATTRIBUTE_STANDARD_TYPE ","
1381 G_FILE_ATTRIBUTE_TIME_MODIFIED,
1382 G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT,
1383 NULL, (GAsyncReadyCallback) ft_handler_gfile_ready_cb, data);
1387 * empathy_ft_handler_new_incoming:
1388 * @channel: the #TpFileTransferChannel proxy to the incoming channel
1389 * @callback: callback to be called when the handler has been created
1390 * @user_data: user data to be passed to @callback
1392 * Triggers the creation of a new #EmpathyFTHandler for an incoming transfer.
1393 * Note that for the handler to be useful, you will have to set a destination
1394 * file with empathy_ft_handler_incoming_set_destination() after the handler
1398 empathy_ft_handler_new_incoming (TpFileTransferChannel *channel,
1399 EmpathyFTHandlerReadyCallback callback,
1402 EmpathyFTHandler *handler;
1403 CallbacksData *data;
1404 EmpathyFTHandlerPriv *priv;
1406 g_return_if_fail (TP_IS_FILE_TRANSFER_CHANNEL (channel));
1408 handler = g_object_new (EMPATHY_TYPE_FT_HANDLER,
1409 "channel", channel, NULL);
1411 priv = GET_PRIV (handler);
1413 data = g_slice_new0 (CallbacksData);
1414 data->callback = callback;
1415 data->user_data = user_data;
1416 data->handler = g_object_ref (handler);
1418 priv->total_bytes = tp_file_transfer_channel_get_size (channel);
1420 priv->transferred_bytes = tp_file_transfer_channel_get_transferred_bytes (
1423 priv->filename = g_strdup (tp_file_transfer_channel_get_filename (channel));
1425 priv->content_type = g_strdup (tp_file_transfer_channel_get_mime_type (
1428 priv->description = g_strdup (tp_file_transfer_channel_get_description (
1431 tp_cli_dbus_properties_call_get_all (channel,
1432 -1, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER,
1433 channel_get_all_properties_cb, data, NULL, G_OBJECT (handler));
1437 * empathy_ft_handler_start_transfer:
1438 * @handler: an #EmpathyFTHandler
1440 * Starts the transfer machinery. After this call, the transfer and hashing
1441 * signals will be emitted by the handler.
1444 empathy_ft_handler_start_transfer (EmpathyFTHandler *handler)
1446 EmpathyFTHandlerPriv *priv;
1448 g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
1450 priv = GET_PRIV (handler);
1452 if (priv->channel == NULL)
1454 ft_handler_complete_request (handler);
1458 /* TODO: add support for resume. */
1459 tp_file_transfer_channel_accept_file_async (priv->channel,
1460 priv->gfile, 0, ft_transfer_accept_cb, handler);
1462 tp_g_signal_connect_object (priv->channel, "notify::state",
1463 G_CALLBACK (ft_transfer_state_cb), handler, 0);
1464 tp_g_signal_connect_object (priv->channel, "notify::transferred-bytes",
1465 G_CALLBACK (ft_transfer_transferred_bytes_cb), handler, 0);
1470 * empathy_ft_handler_cancel_transfer:
1471 * @handler: an #EmpathyFTHandler
1473 * Cancels an ongoing handler operation. Note that this doesn't destroy
1474 * the object, which will keep all the properties, altough it won't be able
1475 * to do any more I/O.
1478 empathy_ft_handler_cancel_transfer (EmpathyFTHandler *handler)
1480 EmpathyFTHandlerPriv *priv;
1482 g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
1484 priv = GET_PRIV (handler);
1486 /* if we don't have a channel, we are hashing, so
1487 * we can just cancel the GCancellable to stop it.
1489 if (priv->channel == NULL)
1490 g_cancellable_cancel (priv->cancellable);
1492 tp_channel_close_async (TP_CHANNEL (priv->channel), NULL, NULL);
1496 * empathy_ft_handler_incoming_set_destination:
1497 * @handler: an #EmpathyFTHandler
1498 * @destination: the #GFile where the transfer should be saved
1500 * Sets the destination of the incoming handler to be @destination.
1501 * Note that calling this method is mandatory before starting the transfer
1502 * for incoming handlers.
1505 empathy_ft_handler_incoming_set_destination (EmpathyFTHandler *handler,
1508 EmpathyFTHandlerPriv *priv;
1510 g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
1511 g_return_if_fail (G_IS_FILE (destination));
1513 priv = GET_PRIV (handler);
1515 g_object_set (handler, "gfile", destination, NULL);
1517 /* check if hash is supported. if it isn't, set use_hash to FALSE
1518 * anyway, so that clients won't be expecting us to checksum.
1520 if (EMP_STR_EMPTY (priv->content_hash) ||
1521 priv->content_hash_type == TP_FILE_HASH_TYPE_NONE)
1522 priv->use_hash = FALSE;
1524 priv->use_hash = TRUE;
1528 * empathy_ft_handler_get_filename:
1529 * @handler: an #EmpathyFTHandler
1531 * Returns the name of the file being transferred.
1533 * Return value: the name of the file being transferred
1536 empathy_ft_handler_get_filename (EmpathyFTHandler *handler)
1538 EmpathyFTHandlerPriv *priv;
1540 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), NULL);
1542 priv = GET_PRIV (handler);
1544 return priv->filename;
1548 * empathy_ft_handler_get_content_type:
1549 * @handler: an #EmpathyFTHandler
1551 * Returns the content type of the file being transferred.
1553 * Return value: the content type of the file being transferred
1556 empathy_ft_handler_get_content_type (EmpathyFTHandler *handler)
1558 EmpathyFTHandlerPriv *priv;
1560 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), NULL);
1562 priv = GET_PRIV (handler);
1564 return priv->content_type;
1568 * empathy_ft_handler_get_contact:
1569 * @handler: an #EmpathyFTHandler
1571 * Returns the remote #EmpathyContact at the other side of the transfer.
1573 * Return value: the remote #EmpathyContact for @handler
1576 empathy_ft_handler_get_contact (EmpathyFTHandler *handler)
1578 EmpathyFTHandlerPriv *priv;
1580 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), NULL);
1582 priv = GET_PRIV (handler);
1584 return priv->contact;
1588 * empathy_ft_handler_get_gfile:
1589 * @handler: an #EmpathyFTHandler
1591 * Returns the #GFile where the transfer is being read/saved.
1593 * Return value: the #GFile where the transfer is being read/saved
1596 empathy_ft_handler_get_gfile (EmpathyFTHandler *handler)
1598 EmpathyFTHandlerPriv *priv;
1600 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), NULL);
1602 priv = GET_PRIV (handler);
1608 * empathy_ft_handler_get_use_hash:
1609 * @handler: an #EmpathyFTHandler
1611 * Returns whether @handler has checksumming enabled. This can depend on
1612 * the CM and the remote contact capabilities.
1614 * Return value: %TRUE if the handler has checksumming enabled,
1618 empathy_ft_handler_get_use_hash (EmpathyFTHandler *handler)
1620 EmpathyFTHandlerPriv *priv;
1622 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), FALSE);
1624 priv = GET_PRIV (handler);
1626 return priv->use_hash;
1630 * empathy_ft_handler_is_incoming:
1631 * @handler: an #EmpathyFTHandler
1633 * Returns whether @handler is incoming or outgoing.
1635 * Return value: %TRUE if the handler is incoming, %FALSE otherwise.
1638 empathy_ft_handler_is_incoming (EmpathyFTHandler *handler)
1640 EmpathyFTHandlerPriv *priv;
1642 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), FALSE);
1644 priv = GET_PRIV (handler);
1646 if (priv->channel == NULL)
1649 return !tp_channel_get_requested ((TpChannel *) priv->channel);
1653 * empathy_ft_handler_get_transferred_bytes:
1654 * @handler: an #EmpathyFTHandler
1656 * Returns the number of bytes already transferred by the handler.
1658 * Return value: the number of bytes already transferred by the handler.
1661 empathy_ft_handler_get_transferred_bytes (EmpathyFTHandler *handler)
1663 EmpathyFTHandlerPriv *priv;
1665 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), 0);
1667 priv = GET_PRIV (handler);
1669 return priv->transferred_bytes;
1673 * empathy_ft_handler_get_total_bytes:
1674 * @handler: an #EmpathyFTHandler
1676 * Returns the total size of the file being transferred by the handler.
1678 * Return value: a number of bytes indicating the total size of the file being
1679 * transferred by the handler.
1682 empathy_ft_handler_get_total_bytes (EmpathyFTHandler *handler)
1684 EmpathyFTHandlerPriv *priv;
1686 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), 0);
1688 priv = GET_PRIV (handler);
1690 return priv->total_bytes;
1694 * empathy_ft_handler_is_completed:
1695 * @handler: an #EmpathyFTHandler
1697 * Returns whether the transfer for @handler has been completed succesfully.
1699 * Return value: %TRUE if the handler has been transferred correctly, %FALSE
1703 empathy_ft_handler_is_completed (EmpathyFTHandler *handler)
1705 EmpathyFTHandlerPriv *priv;
1707 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), FALSE);
1709 priv = GET_PRIV (handler);
1711 return priv->is_completed;
1715 * empathy_ft_handler_is_cancelled:
1716 * @handler: an #EmpathyFTHandler
1718 * Returns whether the transfer for @handler has been cancelled or has stopped
1721 * Return value: %TRUE if the transfer for @handler has been cancelled
1722 * or has stopped due to an error, %FALSE otherwise.
1725 empathy_ft_handler_is_cancelled (EmpathyFTHandler *handler)
1727 EmpathyFTHandlerPriv *priv;
1729 g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), FALSE);
1731 priv = GET_PRIV (handler);
1733 return g_cancellable_is_cancelled (priv->cancellable);