]> git.0d.be Git - empathy.git/blob - libempathy/empathy-tp-file.c
Don't set the status to cancelled when closing
[empathy.git] / libempathy / empathy-tp-file.c
1 /*
2  * Copyright (C) 2007-2009 Collabora Ltd.
3  * Copyright (C) 2007 Marco Barisione <marco@barisione.org>
4  *
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.
9  *
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.
14  *
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
18  *
19  * Authors: Marco Barisione <marco@barisione.org>
20  *          Jonny Lamb <jonny.lamb@collabora.co.uk>
21  *          Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
22  */
23
24 #include <config.h>
25
26 #include <string.h>
27 #include <unistd.h>
28 #include <errno.h>
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #include <sys/un.h>
32
33 #include <glib/gi18n-lib.h>
34
35 #include <gio/gio.h>
36 #include <gio/gunixinputstream.h>
37 #include <gio/gunixoutputstream.h>
38
39 #include <telepathy-glib/proxy-subclass.h>
40 #include <telepathy-glib/util.h>
41
42 #include "empathy-tp-file.h"
43 #include "empathy-marshal.h"
44 #include "empathy-time.h"
45 #include "empathy-utils.h"
46
47 #define DEBUG_FLAG EMPATHY_DEBUG_FT
48 #include "empathy-debug.h"
49
50 /**
51  * SECTION:empathy-tp-file
52  * @title: EmpathyTpFile
53  * @short_description: Object which represents a Telepathy file channel
54  * @include: libempathy/empathy-tp-file.h
55  *
56  * #EmpathyTpFile is an object which represents a Telepathy file channel.
57  */
58
59 /**
60  * EmpathyTpFile:
61  * @parent: parent object
62  *
63  * Object which represents a Telepathy file channel.
64  */
65
66 /**
67  * EMPATHY_TP_FILE_UNKNOWN_SIZE:
68  *
69  * Value used for the "size" or "estimated-size" properties when the size of
70  * the transferred file is unknown.
71  */
72
73 /* EmpathyTpFile object */
74
75 typedef struct {
76   TpChannel *channel;
77   gboolean ready;
78
79   GInputStream *in_stream;
80   GOutputStream *out_stream;
81
82   /* org.freedesktop.Telepathy.Channel.Type.FileTransfer D-Bus properties */
83   TpFileTransferState state;
84   TpFileTransferStateChangeReason state_change_reason;
85
86   /* transfer properties */
87   gboolean incoming;
88   time_t start_time;
89   GArray *unix_socket_path;
90   guint64 offset;
91
92   /* GCancellable we're passed when offering/accepting the transfer */
93   GCancellable *cancellable;
94
95   /* callbacks for the operation */
96   EmpathyTpFileProgressCallback progress_callback;
97   gpointer progress_user_data;
98   EmpathyTpFileOperationCallback op_callback;
99   gpointer op_user_data;
100
101   gboolean dispose_run;
102 } EmpathyTpFilePriv;
103
104 enum {
105   PROP_0,
106   PROP_CHANNEL,
107   PROP_INCOMING
108 };
109
110 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpFile)
111
112 G_DEFINE_TYPE (EmpathyTpFile, empathy_tp_file, G_TYPE_OBJECT);
113
114 /* private functions */
115
116 static void
117 tp_file_get_state_cb (TpProxy *proxy,
118                       const GValue *value,
119                       const GError *error,
120                       gpointer user_data,
121                       GObject *weak_object)
122 {
123   EmpathyTpFilePriv *priv = GET_PRIV (weak_object);
124
125   if (error)
126     {
127       /* set a default value for the state */
128       priv->state = TP_FILE_TRANSFER_STATE_NONE;
129       return;
130     }
131
132   priv->state = g_value_get_uint (value);
133 }
134
135 static void
136 tp_file_invalidated_cb (TpProxy       *proxy,
137                         guint          domain,
138                         gint           code,
139                         gchar         *message,
140                         EmpathyTpFile *tp_file)
141 {
142   EmpathyTpFilePriv *priv = GET_PRIV (tp_file);
143
144   DEBUG ("Channel invalidated: %s", message);
145
146   if (priv->state != TP_FILE_TRANSFER_STATE_COMPLETED &&
147       priv->state != TP_FILE_TRANSFER_STATE_CANCELLED)
148     {
149       /* The channel is not in a finished state, an error occured */
150       priv->state = TP_FILE_TRANSFER_STATE_CANCELLED;
151       priv->state_change_reason =
152           TP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_ERROR;
153     }
154 }
155
156 static void
157 ft_operation_close_clean (EmpathyTpFile *tp_file)
158 {
159   EmpathyTpFilePriv *priv = GET_PRIV (tp_file);
160
161   DEBUG ("Splice close clean");
162
163   if (priv->op_callback)
164     priv->op_callback (tp_file, NULL, priv->op_user_data);
165 }
166
167 static void
168 ft_operation_close_with_error (EmpathyTpFile *tp_file,
169                                GError *error)
170 {
171   EmpathyTpFilePriv *priv = GET_PRIV (tp_file);
172
173   DEBUG ("Splice close with error %s", error->message);
174
175   if (priv->op_callback)
176     priv->op_callback (tp_file, error, priv->op_user_data);
177 }
178
179 static void
180 splice_stream_ready_cb (GObject *source,
181                         GAsyncResult *res,
182                         gpointer user_data)
183 {
184   EmpathyTpFile *tp_file;
185   GError *error = NULL;
186
187   tp_file = user_data;
188
189   DEBUG ("Splice stream ready cb");
190
191   g_output_stream_splice_finish (G_OUTPUT_STREAM (source), res, &error);
192
193   if (error != NULL)
194     {
195       ft_operation_close_with_error (tp_file, error);
196       g_clear_error (&error);
197       return;
198     }
199 }
200
201 static void
202 tp_file_start_transfer (EmpathyTpFile *tp_file)
203 {
204   gint fd;
205   struct sockaddr_un addr;
206   GError *error = NULL;
207   EmpathyTpFilePriv *priv = GET_PRIV (tp_file);
208
209   fd = socket (PF_UNIX, SOCK_STREAM, 0);
210   if (fd < 0)
211     {
212       int code = errno;
213
214       error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
215           EMPATHY_FT_ERROR_SOCKET, g_strerror (code));
216
217       DEBUG ("Failed to create socket, closing channel");
218
219       ft_operation_close_with_error (tp_file, error);
220       g_clear_error (&error);
221
222       return;
223     }
224
225   memset (&addr, 0, sizeof (addr));
226   addr.sun_family = AF_UNIX;
227   strncpy (addr.sun_path, priv->unix_socket_path->data,
228       priv->unix_socket_path->len);
229
230   if (connect (fd, (struct sockaddr*) &addr, sizeof (addr)) < 0)
231     {
232       int code = errno;
233
234       error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
235           EMPATHY_FT_ERROR_SOCKET, g_strerror (code));
236
237       DEBUG ("Failed to connect socket, closing channel");
238
239       ft_operation_close_with_error (tp_file, error);
240       close (fd);
241       g_clear_error (&error);
242
243       return;
244     }
245
246   DEBUG ("Start the transfer");
247
248   priv->start_time = empathy_time_get_current ();
249
250   /* notify we're starting a transfer */
251   if (priv->progress_callback)
252     priv->progress_callback (tp_file, 0, priv->progress_user_data);
253
254   if (priv->incoming)
255     {
256       GInputStream *socket_stream;
257
258       socket_stream = g_unix_input_stream_new (fd, TRUE);
259
260       g_output_stream_splice_async (priv->out_stream, socket_stream,
261           G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
262           G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
263           G_PRIORITY_DEFAULT, priv->cancellable,
264           splice_stream_ready_cb, tp_file);
265
266       g_object_unref (socket_stream);
267     }
268   else
269     {
270       GOutputStream *socket_stream;
271
272       socket_stream = g_unix_output_stream_new (fd, TRUE);
273
274       g_output_stream_splice_async (socket_stream, priv->in_stream,
275           G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
276           G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
277           G_PRIORITY_DEFAULT, priv->cancellable,
278           splice_stream_ready_cb, tp_file);
279
280       g_object_unref (socket_stream);
281     }
282 }
283
284 static void
285 tp_file_state_changed_cb (TpChannel *proxy,
286                           guint state,
287                           guint reason,
288                           gpointer user_data,
289                           GObject *weak_object)
290 {
291   EmpathyTpFilePriv *priv = GET_PRIV (weak_object);
292
293   if (state == priv->state)
294     return;
295
296   DEBUG ("File transfer state changed:\n"
297       "old state = %u, state = %u, reason = %u\n"
298       "\tincoming = %s, in_stream = %s, out_stream = %s",
299       priv->state, state, reason,
300       priv->incoming ? "yes" : "no",
301       priv->in_stream ? "present" : "not present",
302       priv->out_stream ? "present" : "not present");
303
304   priv->state = state;
305   priv->state_change_reason = reason;
306
307   /* If the channel is open AND we have the socket path, we can start the
308    * transfer. The socket path could be NULL if we are not doing the actual
309    * data transfer but are just an observer for the channel.
310    */
311   if (state == TP_FILE_TRANSFER_STATE_OPEN &&
312       priv->unix_socket_path != NULL)
313     tp_file_start_transfer (EMPATHY_TP_FILE (weak_object));
314
315   if (state == TP_FILE_TRANSFER_STATE_COMPLETED)
316     ft_operation_close_clean (EMPATHY_TP_FILE (weak_object));
317 }
318
319 static void
320 tp_file_transferred_bytes_changed_cb (TpChannel *proxy,
321                                       guint64 count,
322                                       gpointer user_data,
323                                       GObject *weak_object)
324 {
325   EmpathyTpFilePriv *priv = GET_PRIV (weak_object);
326
327   /* don't notify for 0 bytes count */
328   if (count == 0)
329     return;
330
331   /* notify clients */
332   if (priv->progress_callback)
333     priv->progress_callback (EMPATHY_TP_FILE (weak_object),
334         count, priv->progress_user_data);
335 }
336
337 static void
338 ft_operation_provide_or_accept_file_cb (TpChannel *proxy,
339                                         const GValue *address,
340                                         const GError *error,
341                                         gpointer user_data,
342                                         GObject *weak_object)
343 {
344   EmpathyTpFile *tp_file = EMPATHY_TP_FILE (weak_object);
345   GError *myerr = NULL;
346   EmpathyTpFilePriv *priv = GET_PRIV (tp_file);
347
348   g_cancellable_set_error_if_cancelled (priv->cancellable, &myerr);
349
350   if (error)
351     {
352       if (myerr)
353         {
354           /* if we were both cancelled and failed when calling the method,
355           * report the method error.
356           */
357           g_clear_error (&myerr);
358           myerr = g_error_copy (error);
359         }
360     }
361
362   if (myerr)
363     {
364       DEBUG ("Error: %s", error->message);
365       ft_operation_close_with_error (tp_file, myerr);
366       g_clear_error (&myerr);
367       return;
368     }
369
370   if (G_VALUE_TYPE (address) == DBUS_TYPE_G_UCHAR_ARRAY)
371     {
372       priv->unix_socket_path = g_value_dup_boxed (address);
373     }
374   else if (G_VALUE_TYPE (address) == G_TYPE_STRING)
375     {
376       /* Old bugged version of telepathy-salut used to store the address
377        * as a 's' instead of an 'ay' */
378       const gchar *path;
379
380       path = g_value_get_string (address);
381       priv->unix_socket_path = g_array_sized_new (TRUE, FALSE, sizeof (gchar),
382                                                   strlen (path));
383       g_array_insert_vals (priv->unix_socket_path, 0, path, strlen (path));
384     }
385
386   DEBUG ("Got unix socket path: %s", priv->unix_socket_path->data);
387
388   /* if the channel is already open, start the transfer now, otherwise,
389    * wait for the state change signal.
390    */
391   if (priv->state == TP_FILE_TRANSFER_STATE_OPEN)
392     tp_file_start_transfer (tp_file);
393 }
394
395 static void
396 file_read_async_cb (GObject *source,
397                     GAsyncResult *res,
398                     gpointer user_data)
399 {
400   GValue nothing = { 0 };
401   EmpathyTpFile *tp_file = user_data;
402   EmpathyTpFilePriv *priv;
403   GFileInputStream *in_stream;
404   GError *error = NULL;
405
406   priv = GET_PRIV (tp_file);
407
408   in_stream = g_file_read_finish (G_FILE (source), res, &error);
409
410   if (error != NULL)
411     {
412       ft_operation_close_with_error (tp_file, error);
413       g_clear_error (&error);
414       return;
415     }
416
417   priv->in_stream = G_INPUT_STREAM (in_stream);
418
419   g_value_init (&nothing, G_TYPE_STRING);
420   g_value_set_static_string (&nothing, "");
421
422   tp_cli_channel_type_file_transfer_call_provide_file (
423       priv->channel, -1,
424       TP_SOCKET_ADDRESS_TYPE_UNIX, TP_SOCKET_ACCESS_CONTROL_LOCALHOST,
425       &nothing, ft_operation_provide_or_accept_file_cb, NULL, NULL, G_OBJECT (tp_file));
426 }
427
428 static void
429 file_replace_async_cb (GObject *source,
430                        GAsyncResult *res,
431                        gpointer user_data)
432 {
433   GValue nothing = { 0 };
434   EmpathyTpFile *tp_file = user_data;
435   EmpathyTpFilePriv *priv;
436   GError *error = NULL;
437   GFileOutputStream *out_stream;
438
439   priv = GET_PRIV (tp_file);
440
441   out_stream = g_file_replace_finish (G_FILE (source), res, &error);
442
443   if (error != NULL)
444     {
445       ft_operation_close_with_error (tp_file, error);
446       g_clear_error (&error);
447
448       return;
449     }
450
451   priv->out_stream = G_OUTPUT_STREAM (out_stream);
452
453   g_value_init (&nothing, G_TYPE_STRING);
454   g_value_set_static_string (&nothing, "");
455
456   tp_cli_channel_type_file_transfer_call_accept_file (priv->channel,
457       -1, TP_SOCKET_ADDRESS_TYPE_UNIX, TP_SOCKET_ACCESS_CONTROL_LOCALHOST,
458       &nothing, priv->offset,
459       ft_operation_provide_or_accept_file_cb, NULL, NULL, G_OBJECT (tp_file));
460 }
461
462 static void
463 close_channel_internal (EmpathyTpFile *tp_file,
464                         gboolean cancel)
465 {
466   EmpathyTpFilePriv *priv;
467
468   g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file));
469   
470   priv = GET_PRIV (tp_file);
471
472   DEBUG ("Closing channel..");
473   tp_cli_channel_call_close (priv->channel, -1,
474     NULL, NULL, NULL, NULL);
475
476   if (priv->cancellable != NULL &&
477       !g_cancellable_is_cancelled (priv->cancellable) && cancel)
478     g_cancellable_cancel (priv->cancellable);
479 }
480
481 /* GObject methods */
482
483 static void
484 empathy_tp_file_init (EmpathyTpFile *tp_file)
485 {
486   EmpathyTpFilePriv *priv;
487
488   priv = G_TYPE_INSTANCE_GET_PRIVATE ((tp_file),
489       EMPATHY_TYPE_TP_FILE, EmpathyTpFilePriv);
490
491   tp_file->priv = priv;
492 }
493
494 static void
495 do_dispose (GObject *object)
496 {
497   EmpathyTpFilePriv *priv = GET_PRIV (object);
498
499   if (priv->dispose_run)
500     return;
501
502   priv->dispose_run = TRUE;
503
504   if (priv->channel)
505     {
506       g_signal_handlers_disconnect_by_func (priv->channel,
507           tp_file_invalidated_cb, object);
508       g_object_unref (priv->channel);
509       priv->channel = NULL;
510     }
511
512   if (priv->in_stream)
513     g_object_unref (priv->in_stream);
514
515   if (priv->out_stream)
516     g_object_unref (priv->out_stream);
517
518   if (priv->cancellable)
519     g_object_unref (priv->cancellable);
520
521   G_OBJECT_CLASS (empathy_tp_file_parent_class)->dispose (object);
522 }
523
524 static void
525 do_finalize (GObject *object)
526 {
527   EmpathyTpFilePriv *priv = GET_PRIV (object);
528
529   DEBUG ("%p", object);
530
531   g_array_free (priv->unix_socket_path, TRUE);
532
533   G_OBJECT_CLASS (empathy_tp_file_parent_class)->finalize (object);
534 }
535
536 static void
537 do_get_property (GObject *object,
538                  guint param_id,
539                  GValue *value,
540                  GParamSpec *pspec)
541 {
542   EmpathyTpFilePriv *priv = GET_PRIV (object);
543
544   switch (param_id)
545     {
546       case PROP_CHANNEL:
547         g_value_set_object (value, priv->channel);
548         break;
549       case PROP_INCOMING:
550         g_value_set_boolean (value, priv->incoming);
551         break;
552       default:
553         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
554         break;
555     };
556 }
557
558 static void
559 do_set_property (GObject *object,
560                  guint param_id,
561                  const GValue *value,
562                  GParamSpec *pspec)
563 {
564   EmpathyTpFilePriv *priv = GET_PRIV (object);
565   switch (param_id)
566     {
567       case PROP_CHANNEL:
568         priv->channel = g_object_ref (g_value_get_object (value));
569         break;
570       case PROP_INCOMING:
571         priv->incoming = g_value_get_boolean (value);
572         break;
573       default:
574         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
575         break;
576     };
577 }
578
579 static GObject *
580 do_constructor (GType type,
581                 guint n_props,
582                 GObjectConstructParam *props)
583 {
584   GObject *file_obj;
585   EmpathyTpFile *tp_file;
586   EmpathyTpFilePriv *priv;
587
588   file_obj = G_OBJECT_CLASS (empathy_tp_file_parent_class)->constructor (type,
589       n_props, props);
590   
591   tp_file = EMPATHY_TP_FILE (file_obj);
592   priv = GET_PRIV (tp_file);
593
594   g_signal_connect (priv->channel, "invalidated",
595     G_CALLBACK (tp_file_invalidated_cb), tp_file);
596
597   tp_cli_channel_type_file_transfer_connect_to_file_transfer_state_changed (
598       priv->channel, tp_file_state_changed_cb, NULL, NULL,
599       G_OBJECT (tp_file), NULL);
600
601   tp_cli_channel_type_file_transfer_connect_to_transferred_bytes_changed (
602       priv->channel, tp_file_transferred_bytes_changed_cb,
603       NULL, NULL, G_OBJECT (tp_file), NULL);
604
605   tp_cli_dbus_properties_call_get (priv->channel,
606       -1, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "State", tp_file_get_state_cb,
607       NULL, NULL, file_obj);
608
609   priv->state_change_reason =
610       TP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE;
611
612   return file_obj;
613 }
614
615 static void
616 empathy_tp_file_class_init (EmpathyTpFileClass *klass)
617 {
618   GObjectClass *object_class = G_OBJECT_CLASS (klass);
619
620   object_class->finalize = do_finalize;
621   object_class->dispose = do_dispose;
622   object_class->constructor = do_constructor;
623   object_class->get_property = do_get_property;
624   object_class->set_property = do_set_property;
625
626   /* Construct-only properties */
627   g_object_class_install_property (object_class,
628       PROP_CHANNEL,
629       g_param_spec_object ("channel",
630           "telepathy channel",
631           "The file transfer channel",
632           TP_TYPE_CHANNEL,
633           G_PARAM_READWRITE |
634           G_PARAM_CONSTRUCT_ONLY));
635
636   g_object_class_install_property (object_class,
637       PROP_INCOMING,
638       g_param_spec_boolean ("incoming",
639           "direction of transfer",
640           "The direction of the file being transferred",
641           FALSE,
642           G_PARAM_READWRITE |
643           G_PARAM_CONSTRUCT_ONLY));
644
645   g_type_class_add_private (object_class, sizeof (EmpathyTpFilePriv));
646 }
647
648 /* public methods */
649
650 /**
651  * empathy_tp_file_new:
652  * @channel: a #TpChannel
653  *
654  * Creates a new #EmpathyTpFile wrapping @channel, or return a new ref to an
655  * existing #EmpathyTpFile for that channel. The returned #EmpathyTpFile
656  * should be unrefed with g_object_unref() when finished with.
657  *
658  * Return value: a new #EmpathyTpFile
659  */
660 EmpathyTpFile *
661 empathy_tp_file_new (TpChannel *channel, gboolean incoming)
662 {
663   EmpathyTpFile *tp_file;
664
665   g_return_val_if_fail (TP_IS_CHANNEL (channel), NULL);
666
667   tp_file = g_object_new (EMPATHY_TYPE_TP_FILE,
668       "channel", channel, "incoming", incoming,
669       NULL);
670
671   return tp_file;
672 }
673
674 void
675 empathy_tp_file_accept (EmpathyTpFile *tp_file,
676                         guint64 offset,
677                         GFile *gfile,
678                         GCancellable *cancellable,
679                         EmpathyTpFileProgressCallback progress_callback,
680                         gpointer progress_user_data,
681                         EmpathyTpFileOperationCallback op_callback,
682                         gpointer op_user_data)
683 {
684   EmpathyTpFilePriv *priv = GET_PRIV (tp_file);
685
686   g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file));
687   g_return_if_fail (G_IS_FILE (gfile));
688   g_return_if_fail (G_IS_CANCELLABLE (cancellable));
689
690   priv->cancellable = g_object_ref (cancellable);
691   priv->progress_callback = progress_callback;
692   priv->progress_user_data = progress_user_data;
693   priv->op_callback = op_callback;
694   priv->op_user_data = op_user_data;
695   priv->offset = offset;
696
697   g_file_replace_async (gfile, NULL, FALSE, G_FILE_CREATE_NONE,
698       G_PRIORITY_DEFAULT, cancellable, file_replace_async_cb, tp_file);
699 }
700
701 void
702 empathy_tp_file_offer (EmpathyTpFile *tp_file,
703                        GFile *gfile,
704                        GCancellable *cancellable,
705                        EmpathyTpFileProgressCallback progress_callback,
706                        gpointer progress_user_data,
707                        EmpathyTpFileOperationCallback op_callback,
708                        gpointer op_user_data)
709 {
710   EmpathyTpFilePriv *priv = GET_PRIV (tp_file);
711
712   g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file));
713   g_return_if_fail (G_IS_FILE (gfile));
714   g_return_if_fail (G_IS_CANCELLABLE (cancellable));
715
716   priv->cancellable = g_object_ref (cancellable);
717   priv->progress_callback = progress_callback;
718   priv->progress_user_data = progress_user_data;
719   priv->op_callback = op_callback;
720   priv->op_user_data = op_user_data;
721
722   g_file_read_async (gfile, G_PRIORITY_DEFAULT, cancellable,
723       file_read_async_cb, tp_file);
724 }
725
726 /**
727  * empathy_tp_file_is_incoming:
728  * @tp_file: an #EmpathyTpFile
729  *
730  * Returns whether @tp_file is incoming.
731  *
732  * Return value: %TRUE if the @tp_file is incoming, otherwise %FALSE
733  */
734 gboolean
735 empathy_tp_file_is_incoming (EmpathyTpFile *tp_file)
736 {
737   EmpathyTpFilePriv *priv;
738
739   g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), FALSE);
740   
741   priv = GET_PRIV (tp_file);
742
743   return priv->incoming;
744 }
745
746 void
747 empathy_tp_file_cancel (EmpathyTpFile *tp_file)
748 {
749   close_channel_internal (tp_file, TRUE);
750 }
751
752 /**
753  * empathy_tp_file_is_ready:
754  * @tp_file: an #EmpathyTpFile
755  *
756  * Returns whether the file channel @tp_file is ready for use.
757  *
758  * @tp_file is classed as ready if its state is no longer
759  * %TP_FILE_TRANSFER_STATE_NONE, or if details about the remote
760  * contact have been fully received.
761  *
762  * Return value: %TRUE if @tp_file is ready for use
763  */
764 gboolean
765 empathy_tp_file_is_ready (EmpathyTpFile *tp_file)
766 {
767   close_channel_internal (tp_file, FALSE);
768 }