ft.h
Go to the documentation of this file.
1
7 /* purple
8 *
9 * Purple is the legal property of its developers, whose names are too numerous
10 * to list here. Please refer to the COPYRIGHT file distributed with this
11 * source distribution.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 */
27 #ifndef _PURPLE_FT_H_
28 #define _PURPLE_FT_H_
29
30 /**************************************************************************/
32 /**************************************************************************/
33 typedef struct _PurpleXfer PurpleXfer;
34
35 #include <glib.h>
36 #include <stdio.h>
37
38 #include "account.h"
39
43 typedef enum
44 {
45 PURPLE_XFER_UNKNOWN = 0,
46 PURPLE_XFER_SEND,
47 PURPLE_XFER_RECEIVE
49 } PurpleXferType;
50
54 typedef enum
55 {
56 PURPLE_XFER_STATUS_UNKNOWN = 0,
57 PURPLE_XFER_STATUS_NOT_STARTED,
58 PURPLE_XFER_STATUS_ACCEPTED,
59 PURPLE_XFER_STATUS_STARTED,
60 PURPLE_XFER_STATUS_DONE,
61 PURPLE_XFER_STATUS_CANCEL_LOCAL,
62 PURPLE_XFER_STATUS_CANCEL_REMOTE
63 } PurpleXferStatusType;
64
71 typedef struct
72 {
73 void (*new_xfer)(PurpleXfer *xfer);
74 void (*destroy)(PurpleXfer *xfer);
75 void (*add_xfer)(PurpleXfer *xfer);
76 void (*update_progress)(PurpleXfer *xfer, double percent);
77 void (*cancel_local)(PurpleXfer *xfer);
78 void (*cancel_remote)(PurpleXfer *xfer);
79
92 gssize (*ui_write)(PurpleXfer *xfer, const guchar *buffer, gssize size);
93
107 gssize (*ui_read)(PurpleXfer *xfer, guchar **buffer, gssize size);
108
121 void (*data_not_sent)(PurpleXfer *xfer, const guchar *buffer, gsize size);
122
128 void (*add_thumbnail)(PurpleXfer *xfer, const gchar *formats);
129 } PurpleXferUiOps;
130
134 struct _PurpleXfer
135 {
136 guint ref;
137 PurpleXferType type;
139 PurpleAccount *account;
141 char *who;
144 char *message;
145 char *filename;
146 char *local_filename;
147 size_t size;
149 FILE *dest_fp;
151 char *remote_ip;
152 int local_port;
153 int remote_port;
155 int fd;
156 int watcher;
158 size_t bytes_sent;
159 size_t bytes_remaining;
160 time_t start_time;
161 time_t end_time;
163 size_t current_buffer_size;
166 PurpleXferStatusType status;
172 struct
173 {
174 void (*init)(PurpleXfer *xfer);
175 void (*request_denied)(PurpleXfer *xfer);
176 void (*start)(PurpleXfer *xfer);
177 void (*end)(PurpleXfer *xfer);
178 void (*cancel_send)(PurpleXfer *xfer);
179 void (*cancel_recv)(PurpleXfer *xfer);
180 gssize (*read)(guchar **buffer, PurpleXfer *xfer);
181 gssize (*write)(const guchar *buffer, size_t size, PurpleXfer *xfer);
182 void (*ack)(PurpleXfer *xfer, const guchar *buffer, size_t size);
183 } ops;
184
185 PurpleXferUiOps *ui_ops;
186 void *ui_data;
188 void *data;
189 };
190
191 #ifdef __cplusplus
192 extern "C" {
193 #endif
194
195 /**************************************************************************/
197 /**************************************************************************/
213 PurpleXfer *purple_xfer_new(PurpleAccount *account,
214 PurpleXferType type, const char *who);
215
221 GList *purple_xfers_get_all(void);
222
229 void purple_xfer_ref(PurpleXfer *xfer);
230
240 void purple_xfer_unref(PurpleXfer *xfer);
241
251 void purple_xfer_request(PurpleXfer *xfer);
252
259 void purple_xfer_request_accepted(PurpleXfer *xfer, const char *filename);
260
266 void purple_xfer_request_denied(PurpleXfer *xfer);
267
275 PurpleXferType purple_xfer_get_type(const PurpleXfer *xfer);
276
284 PurpleAccount *purple_xfer_get_account(const PurpleXfer *xfer);
285
295 const char *purple_xfer_get_remote_user(const PurpleXfer *xfer);
296
304 PurpleXferStatusType purple_xfer_get_status(const PurpleXfer *xfer);
305
314 gboolean purple_xfer_is_canceled(const PurpleXfer *xfer);
315
323 gboolean purple_xfer_is_completed(const PurpleXfer *xfer);
324
332 const char *purple_xfer_get_filename(const PurpleXfer *xfer);
333
341 const char *purple_xfer_get_local_filename(const PurpleXfer *xfer);
342
350 size_t purple_xfer_get_bytes_sent(const PurpleXfer *xfer);
351
359 size_t purple_xfer_get_bytes_remaining(const PurpleXfer *xfer);
360
368 size_t purple_xfer_get_size(const PurpleXfer *xfer);
369
379 double purple_xfer_get_progress(const PurpleXfer *xfer);
380
388 unsigned int purple_xfer_get_local_port(const PurpleXfer *xfer);
389
397 const char *purple_xfer_get_remote_ip(const PurpleXfer *xfer);
398
406 unsigned int purple_xfer_get_remote_port(const PurpleXfer *xfer);
407
416 time_t purple_xfer_get_start_time(const PurpleXfer *xfer);
417
426 time_t purple_xfer_get_end_time(const PurpleXfer *xfer);
427
434 void purple_xfer_set_completed(PurpleXfer *xfer, gboolean completed);
435
442 void purple_xfer_set_message(PurpleXfer *xfer, const char *message);
443
450 void purple_xfer_set_filename(PurpleXfer *xfer, const char *filename);
451
458 void purple_xfer_set_local_filename(PurpleXfer *xfer, const char *filename);
459
466 void purple_xfer_set_size(PurpleXfer *xfer, size_t size);
467
481 void purple_xfer_set_bytes_sent(PurpleXfer *xfer, size_t bytes_sent);
482
490 PurpleXferUiOps *purple_xfer_get_ui_ops(const PurpleXfer *xfer);
491
498 void purple_xfer_set_read_fnc(PurpleXfer *xfer,
499 gssize (*fnc)(guchar **, PurpleXfer *));
500
507 void purple_xfer_set_write_fnc(PurpleXfer *xfer,
508 gssize (*fnc)(const guchar *, size_t, PurpleXfer *));
509
516 void purple_xfer_set_ack_fnc(PurpleXfer *xfer,
517 void (*fnc)(PurpleXfer *, const guchar *, size_t));
518
525 void purple_xfer_set_request_denied_fnc(PurpleXfer *xfer, void (*fnc)(PurpleXfer *));
526
537 void purple_xfer_set_init_fnc(PurpleXfer *xfer, void (*fnc)(PurpleXfer *));
538
545 void purple_xfer_set_start_fnc(PurpleXfer *xfer, void (*fnc)(PurpleXfer *));
546
553 void purple_xfer_set_end_fnc(PurpleXfer *xfer, void (*fnc)(PurpleXfer *));
554
561 void purple_xfer_set_cancel_send_fnc(PurpleXfer *xfer, void (*fnc)(PurpleXfer *));
562
569 void purple_xfer_set_cancel_recv_fnc(PurpleXfer *xfer, void (*fnc)(PurpleXfer *));
570
579 gssize purple_xfer_read(PurpleXfer *xfer, guchar **buffer);
580
590 gssize purple_xfer_write(PurpleXfer *xfer, const guchar *buffer, gsize size);
591
603 gboolean
604 purple_xfer_write_file(PurpleXfer *xfer, const guchar *buffer, gsize size);
605
618 gssize
619 purple_xfer_read_file(PurpleXfer *xfer, guchar *buffer, gsize size);
620
639 void purple_xfer_start(PurpleXfer *xfer, int fd, const char *ip,
640 unsigned int port);
641
647 void purple_xfer_end(PurpleXfer *xfer);
648
655 void purple_xfer_add(PurpleXfer *xfer);
656
662 void purple_xfer_cancel_local(PurpleXfer *xfer);
663
669 void purple_xfer_cancel_remote(PurpleXfer *xfer);
670
683 void purple_xfer_error(PurpleXferType type, PurpleAccount *account, const char *who, const char *msg);
684
690 void purple_xfer_update_progress(PurpleXfer *xfer);
691
701 void purple_xfer_conversation_write(PurpleXfer *xfer, char *message, gboolean is_error);
702
712 void purple_xfer_ui_ready(PurpleXfer *xfer);
713
723 void purple_xfer_prpl_ready(PurpleXfer *xfer);
724
734 gconstpointer purple_xfer_get_thumbnail(const PurpleXfer *xfer, gsize *len);
735
743 const gchar *purple_xfer_get_thumbnail_mimetype(const PurpleXfer *xfer);
744
745
755 void purple_xfer_set_thumbnail(PurpleXfer *xfer, gconstpointer thumbnail,
756 gsize size, const gchar *mimetype);
757
767 void purple_xfer_prepare_thumbnail(PurpleXfer *xfer, const gchar *formats);
768
769
772 /**************************************************************************/
774 /**************************************************************************/
782 void *purple_xfers_get_handle(void);
783
787 void purple_xfers_init(void);
788
792 void purple_xfers_uninit(void);
793
799 void purple_xfers_set_ui_ops(PurpleXferUiOps *ops);
800
806 PurpleXferUiOps *purple_xfers_get_ui_ops(void);
807
810 #ifdef __cplusplus
811 }
812 #endif
813
814 #endif /* _PURPLE_FT_H_ */
_PurpleXfer::remote_ip
char * remote_ip
The remote IP address.
Definition: ft.h:151
PurpleXferUiOps
File transfer UI operations.
Definition: ft.h:71
purple_xfer_get_ui_ops
PurpleXferUiOps * purple_xfer_get_ui_ops(const PurpleXfer *xfer)
Returns the UI operations structure for a file transfer.
PURPLE_XFER_UNKNOWN
Unknown file transfer type.
Definition: ft.h:45
_PurpleXfer::data
void * data
prpl-specific data.
Definition: ft.h:188
purple_xfer_set_init_fnc
void purple_xfer_set_init_fnc(PurpleXfer *xfer, void(*fnc)(PurpleXfer *))
Sets the transfer initialization function for the file transfer.
purple_xfer_get_progress
double purple_xfer_get_progress(const PurpleXfer *xfer)
Returns the current percentage of progress of the transfer.
purple_xfer_read_file
gssize purple_xfer_read_file(PurpleXfer *xfer, guchar *buffer, gsize size)
Writes chunk of file being sent.
purple_xfer_is_completed
gboolean purple_xfer_is_completed(const PurpleXfer *xfer)
Returns the completed state for a file transfer.
purple_xfer_ui_ready
void purple_xfer_ui_ready(PurpleXfer *xfer)
Allows the UI to signal it&#39;s ready to send/receive data (depending on the direction of the file trans...
PurpleXferType
PurpleXferType
Types of file transfers.
Definition: ft.h:43
_PurpleXfer::ui_ops
PurpleXferUiOps * ui_ops
UI-specific operations.
Definition: ft.h:185
purple_xfer_get_type
PurpleXferType purple_xfer_get_type(const PurpleXfer *xfer)
Returns the type of file transfer.
purple_xfer_update_progress
void purple_xfer_update_progress(PurpleXfer *xfer)
Updates file transfer progress.
purple_xfer_get_local_port
unsigned int purple_xfer_get_local_port(const PurpleXfer *xfer)
Returns the local port number in the file transfer.
_PurpleXfer::status
PurpleXferStatusType status
File Transfer&#39;s status.
Definition: ft.h:166
purple_xfer_set_bytes_sent
void purple_xfer_set_bytes_sent(PurpleXfer *xfer, size_t bytes_sent)
Sets the current working position in the active file transfer.
purple_xfer_add
void purple_xfer_add(PurpleXfer *xfer)
Adds a new file transfer to the list of file transfers.
purple_xfer_get_thumbnail
gconstpointer purple_xfer_get_thumbnail(const PurpleXfer *xfer, gsize *len)
Gets the thumbnail data for a transfer.
_PurpleXfer::who
char * who
The person on the other end of the transfer.
Definition: ft.h:141
PURPLE_XFER_STATUS_DONE
The xfer completed successfully.
Definition: ft.h:60
purple_xfer_error
void purple_xfer_error(PurpleXferType type, PurpleAccount *account, const char *who, const char *msg)
Displays a file transfer-related error message.
purple_xfer_get_status
PurpleXferStatusType purple_xfer_get_status(const PurpleXfer *xfer)
Returns the status of the xfer.
purple_xfer_get_bytes_sent
size_t purple_xfer_get_bytes_sent(const PurpleXfer *xfer)
Returns the number of bytes sent (or received) so far.
_PurpleXfer::current_buffer_size
size_t current_buffer_size
This gradually increases for fast network connections.
Definition: ft.h:163
_PurpleAccount
Structure representing an account.
Definition: account.h:169
purple_xfer_start
void purple_xfer_start(PurpleXfer *xfer, int fd, const char *ip, unsigned int port)
Starts a file transfer.
purple_xfer_request_denied
void purple_xfer_request_denied(PurpleXfer *xfer)
Called if the user rejects the file transfer request.
purple_xfer_set_cancel_recv_fnc
void purple_xfer_set_cancel_recv_fnc(PurpleXfer *xfer, void(*fnc)(PurpleXfer *))
Sets the cancel receive function for the file transfer.
purple_xfer_read
gssize purple_xfer_read(PurpleXfer *xfer, guchar **buffer)
Reads in data from a file transfer stream.
purple_xfer_ref
void purple_xfer_ref(PurpleXfer *xfer)
Increases the reference count on a PurpleXfer.
_PurpleXfer::account
PurpleAccount * account
The account.
Definition: ft.h:139
_PurpleXfer::dest_fp
FILE * dest_fp
The destination file pointer.
Definition: ft.h:149
_PurpleXfer::ops
struct _PurpleXfer::@2 ops
I/O operations, which should be set by the prpl using purple_xfer_set_init_fnc() and friends...
purple_xfer_get_remote_ip
const char * purple_xfer_get_remote_ip(const PurpleXfer *xfer)
Returns the remote IP address in the file transfer.
purple_xfer_set_thumbnail
void purple_xfer_set_thumbnail(PurpleXfer *xfer, gconstpointer thumbnail, gsize size, const gchar *mimetype)
Sets the thumbnail data for a transfer.
purple_xfers_get_all
GList * purple_xfers_get_all(void)
Returns all xfers.
purple_xfer_request_accepted
void purple_xfer_request_accepted(PurpleXfer *xfer, const char *filename)
Called if the user accepts the file transfer request.
PURPLE_XFER_STATUS_CANCEL_REMOTE
The xfer was cancelled by the other end, or we couldn&#39;t connect.
Definition: ft.h:62
_PurpleXfer::ref
guint ref
The reference count.
Definition: ft.h:136
purple_xfer_set_ack_fnc
void purple_xfer_set_ack_fnc(PurpleXfer *xfer, void(*fnc)(PurpleXfer *, const guchar *, size_t))
Sets the acknowledge function for the file transfer.
purple_xfer_get_start_time
time_t purple_xfer_get_start_time(const PurpleXfer *xfer)
Returns the time the transfer of a file started.
_PurpleXfer::filename
char * filename
The name sent over the network.
Definition: ft.h:145
PURPLE_XFER_STATUS_UNKNOWN
Unknown, the xfer may be null.
Definition: ft.h:56
_PurpleXfer::start_time
time_t start_time
When the transfer of data began.
Definition: ft.h:160
purple_xfer_set_completed
void purple_xfer_set_completed(PurpleXfer *xfer, gboolean completed)
Sets the completed state for the file transfer.
purple_xfers_get_handle
void * purple_xfers_get_handle(void)
Returns the handle to the file transfer subsystem.
purple_xfer_get_remote_port
unsigned int purple_xfer_get_remote_port(const PurpleXfer *xfer)
Returns the remote port number in the file transfer.
purple_xfer_get_end_time
time_t purple_xfer_get_end_time(const PurpleXfer *xfer)
Returns the time the transfer of a file ended.
PURPLE_XFER_STATUS_STARTED
purple_xfer_start has been called.
Definition: ft.h:59
purple_xfer_get_local_filename
const char * purple_xfer_get_local_filename(const PurpleXfer *xfer)
Returns the file&#39;s destination filename,.
purple_xfer_set_write_fnc
void purple_xfer_set_write_fnc(PurpleXfer *xfer, gssize(*fnc)(const guchar *, size_t, PurpleXfer *))
Sets the write function for the file transfer.
_PurpleXfer::ui_data
void * ui_data
UI-specific data.
Definition: ft.h:186
PurpleXferStatusType
PurpleXferStatusType
The different states of the xfer.
Definition: ft.h:54
purple_xfer_set_end_fnc
void purple_xfer_set_end_fnc(PurpleXfer *xfer, void(*fnc)(PurpleXfer *))
Sets the end transfer function for the file transfer.
purple_xfer_write
gssize purple_xfer_write(PurpleXfer *xfer, const guchar *buffer, gsize size)
Writes data to a file transfer stream.
PURPLE_XFER_STATUS_NOT_STARTED
It hasn&#39;t started yet.
Definition: ft.h:57
purple_xfer_set_message
void purple_xfer_set_message(PurpleXfer *xfer, const char *message)
Sets the filename for the file transfer.
purple_xfer_get_remote_user
const char * purple_xfer_get_remote_user(const PurpleXfer *xfer)
Returns the name of the remote user.
_PurpleXfer::bytes_remaining
size_t bytes_remaining
The number of bytes remaining.
Definition: ft.h:159
purple_xfers_init
void purple_xfers_init(void)
Initializes the file transfer subsystem.
purple_xfer_get_bytes_remaining
size_t purple_xfer_get_bytes_remaining(const PurpleXfer *xfer)
Returns the number of bytes remaining to send or receive.
_PurpleXfer::local_filename
char * local_filename
The name on the local hard drive.
Definition: ft.h:146
purple_xfer_get_size
size_t purple_xfer_get_size(const PurpleXfer *xfer)
Returns the size of the file being sent or received.
account.h
Account API.
purple_xfer_conversation_write
void purple_xfer_conversation_write(PurpleXfer *xfer, char *message, gboolean is_error)
Displays a file transfer-related message in the conversation window.
purple_xfer_new
PurpleXfer * purple_xfer_new(PurpleAccount *account, PurpleXferType type, const char *who)
Creates a new file transfer handle.
purple_xfer_get_filename
const char * purple_xfer_get_filename(const PurpleXfer *xfer)
Returns the name of the file being sent or received.
_PurpleXfer::type
PurpleXferType type
The type of transfer.
Definition: ft.h:137
purple_xfer_set_request_denied_fnc
void purple_xfer_set_request_denied_fnc(PurpleXfer *xfer, void(*fnc)(PurpleXfer *))
Sets the function to be called if the request is denied.
purple_xfer_is_canceled
gboolean purple_xfer_is_canceled(const PurpleXfer *xfer)
Returns true if the file transfer was cancelled.
_PurpleXfer::bytes_sent
size_t bytes_sent
The number of bytes sent.
Definition: ft.h:158
purple_xfer_unref
void purple_xfer_unref(PurpleXfer *xfer)
Decreases the reference count on a PurpleXfer.
purple_xfer_get_thumbnail_mimetype
const gchar * purple_xfer_get_thumbnail_mimetype(const PurpleXfer *xfer)
Gets the mimetype of the thumbnail preview for a transfer.
PURPLE_XFER_STATUS_CANCEL_LOCAL
The xfer was cancelled by us.
Definition: ft.h:61
purple_xfer_write_file
gboolean purple_xfer_write_file(PurpleXfer *xfer, const guchar *buffer, gsize size)
Writes chunk of received file.
purple_xfer_cancel_local
void purple_xfer_cancel_local(PurpleXfer *xfer)
Cancels a file transfer on the local end.
purple_xfer_prpl_ready
void purple_xfer_prpl_ready(PurpleXfer *xfer)
Allows the prpl to signal it&#39;s ready to send/receive data (depending on the direction of the file tra...
purple_xfer_request
void purple_xfer_request(PurpleXfer *xfer)
Requests confirmation for a file transfer from the user.
purple_xfers_get_ui_ops
PurpleXferUiOps * purple_xfers_get_ui_ops(void)
Returns the UI operations structure to be used in all purple file transfers.
_PurpleXfer::remote_port
int remote_port
The remote port.
Definition: ft.h:153
_PurpleXfer::local_port
int local_port
The local port.
Definition: ft.h:152
_PurpleXfer::end_time
time_t end_time
When the transfer of data ended.
Definition: ft.h:161
purple_xfer_cancel_remote
void purple_xfer_cancel_remote(PurpleXfer *xfer)
Cancels a file transfer from the remote end.
_PurpleXfer::watcher
int watcher
Watcher.
Definition: ft.h:156
purple_xfer_get_account
PurpleAccount * purple_xfer_get_account(const PurpleXfer *xfer)
Returns the account the file transfer is using.
purple_xfer_set_cancel_send_fnc
void purple_xfer_set_cancel_send_fnc(PurpleXfer *xfer, void(*fnc)(PurpleXfer *))
Sets the cancel send function for the file transfer.
purple_xfer_set_start_fnc
void purple_xfer_set_start_fnc(PurpleXfer *xfer, void(*fnc)(PurpleXfer *))
Sets the start transfer function for the file transfer.
purple_xfers_set_ui_ops
void purple_xfers_set_ui_ops(PurpleXferUiOps *ops)
Sets the UI operations structure to be used in all purple file transfers.
_PurpleXfer::fd
int fd
The socket file descriptor.
Definition: ft.h:155
PURPLE_XFER_STATUS_ACCEPTED
Receive accepted, but destination file not selected yet.
Definition: ft.h:58
_PurpleXfer::size
size_t size
The size of the file.
Definition: ft.h:147
purple_xfer_end
void purple_xfer_end(PurpleXfer *xfer)
Ends a file transfer.
PURPLE_XFER_RECEIVE
File receiving.
Definition: ft.h:47
purple_xfer_set_filename
void purple_xfer_set_filename(PurpleXfer *xfer, const char *filename)
Sets the filename for the file transfer.
purple_xfers_uninit
void purple_xfers_uninit(void)
Uninitializes the file transfer subsystem.
purple_xfer_set_size
void purple_xfer_set_size(PurpleXfer *xfer, size_t size)
Sets the size of the file in a file transfer.
PURPLE_XFER_SEND
File sending.
Definition: ft.h:46
purple_xfer_set_read_fnc
void purple_xfer_set_read_fnc(PurpleXfer *xfer, gssize(*fnc)(guchar **, PurpleXfer *))
Sets the read function for the file transfer.
purple_xfer_prepare_thumbnail
void purple_xfer_prepare_thumbnail(PurpleXfer *xfer, const gchar *formats)
Prepare a thumbnail for a transfer (if the UI supports it) will be no-op in case the UI doesn&#39;t imple...
_PurpleXfer
A core representation of a file transfer.
Definition: ft.h:134
_PurpleXfer::message
char * message
A message sent with the request.
Definition: ft.h:144
purple_xfer_set_local_filename
void purple_xfer_set_local_filename(PurpleXfer *xfer, const char *filename)
Sets the local filename for the file transfer.