Frameworks/libpurple.framework/Versions/0.6.2/Headers/ft.h
author Zachary West <zacw@adium.im>
Fri Aug 21 13:25:11 2009 -0700 (2009-08-21)
changeset 2592 e8d15275025e
parent 1739 Frameworks/libpurple.framework/Versions/0.6.0/Headers/ft.h@8b0daad9656c
permissions -rw-r--r--
im.pidgin.adium.1-4 at 267c6165e02e34318a1823960bd04c0639952f73
Evan@653
     1
/**
Evan@653
     2
 * @file ft.h File Transfer API
Evan@653
     3
 * @ingroup core
Evan@653
     4
 * @see @ref xfer-signals
Evan@653
     5
 */
Evan@653
     6
Evan@653
     7
/* purple
Evan@653
     8
 *
Evan@653
     9
 * Purple is the legal property of its developers, whose names are too numerous
Evan@653
    10
 * to list here.  Please refer to the COPYRIGHT file distributed with this
Evan@653
    11
 * source distribution.
Evan@653
    12
 *
Evan@653
    13
 * This program is free software; you can redistribute it and/or modify
Evan@653
    14
 * it under the terms of the GNU General Public License as published by
Evan@653
    15
 * the Free Software Foundation; either version 2 of the License, or
Evan@653
    16
 * (at your option) any later version.
Evan@653
    17
 *
Evan@653
    18
 * This program is distributed in the hope that it will be useful,
Evan@653
    19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Evan@653
    20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Evan@653
    21
 * GNU General Public License for more details.
Evan@653
    22
 *
Evan@653
    23
 * You should have received a copy of the GNU General Public License
Evan@653
    24
 * along with this program; if not, write to the Free Software
Evan@653
    25
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
Evan@653
    26
 */
Evan@653
    27
#ifndef _PURPLE_FT_H_
Evan@653
    28
#define _PURPLE_FT_H_
Evan@653
    29
Evan@653
    30
/**************************************************************************/
Evan@653
    31
/** Data Structures                                                       */
Evan@653
    32
/**************************************************************************/
Evan@653
    33
typedef struct _PurpleXfer PurpleXfer;
Evan@653
    34
Evan@653
    35
#include <glib.h>
Evan@653
    36
#include <stdio.h>
Evan@653
    37
Evan@653
    38
#include "account.h"
Evan@653
    39
Evan@653
    40
/**
Evan@653
    41
 * Types of file transfers.
Evan@653
    42
 */
Evan@653
    43
typedef enum
Evan@653
    44
{
Evan@653
    45
	PURPLE_XFER_UNKNOWN = 0,  /**< Unknown file transfer type. */
Evan@653
    46
	PURPLE_XFER_SEND,         /**< File sending.               */
Evan@653
    47
	PURPLE_XFER_RECEIVE       /**< File receiving.             */
Evan@653
    48
Evan@653
    49
} PurpleXferType;
Evan@653
    50
Evan@653
    51
/**
Evan@653
    52
 * The different states of the xfer.
Evan@653
    53
 */
Evan@653
    54
typedef enum
Evan@653
    55
{
Evan@653
    56
	PURPLE_XFER_STATUS_UNKNOWN = 0,   /**< Unknown, the xfer may be null. */
Evan@653
    57
	PURPLE_XFER_STATUS_NOT_STARTED,   /**< It hasn't started yet. */
Evan@653
    58
	PURPLE_XFER_STATUS_ACCEPTED,      /**< Receive accepted, but destination file not selected yet */
Evan@653
    59
	PURPLE_XFER_STATUS_STARTED,       /**< purple_xfer_start has been called. */
Evan@653
    60
	PURPLE_XFER_STATUS_DONE,          /**< The xfer completed successfully. */
Evan@653
    61
	PURPLE_XFER_STATUS_CANCEL_LOCAL,  /**< The xfer was canceled by us. */
Evan@653
    62
	PURPLE_XFER_STATUS_CANCEL_REMOTE  /**< The xfer was canceled by the other end, or we couldn't connect. */
Evan@653
    63
} PurpleXferStatusType;
Evan@653
    64
Evan@653
    65
/**
Evan@653
    66
 * File transfer UI operations.
Evan@653
    67
 *
Evan@653
    68
 * Any UI representing a file transfer must assign a filled-out
Evan@653
    69
 * PurpleXferUiOps structure to the purple_xfer.
Evan@653
    70
 */
Evan@653
    71
typedef struct
Evan@653
    72
{
Evan@653
    73
	void (*new_xfer)(PurpleXfer *xfer);
Evan@653
    74
	void (*destroy)(PurpleXfer *xfer);
Evan@653
    75
	void (*add_xfer)(PurpleXfer *xfer);
Evan@653
    76
	void (*update_progress)(PurpleXfer *xfer, double percent);
Evan@653
    77
	void (*cancel_local)(PurpleXfer *xfer);
Evan@653
    78
	void (*cancel_remote)(PurpleXfer *xfer);
Evan@653
    79
zacw@2592
    80
	/**
zacw@2592
    81
	 * UI op to write data received from the prpl. The UI must deal with the
zacw@2592
    82
	 * entire buffer and return size, or it is treated as an error.
zacw@2592
    83
	 *
zacw@2592
    84
	 * @param xfer    The file transfer structure
zacw@2592
    85
	 * @param buffer  The buffer to write
zacw@2592
    86
	 * @param size    The size of the buffer
zacw@2592
    87
	 *
zacw@2592
    88
	 * @return size if the write was successful, or a value between 0 and
zacw@2592
    89
	 *         size on error.
zacw@2592
    90
	 * @since 2.6.0
zacw@2592
    91
	 */
zacw@2592
    92
	gssize (*ui_write)(PurpleXfer *xfer, const guchar *buffer, gssize size);
zacw@2592
    93
zacw@2592
    94
	/**
zacw@2592
    95
	 * UI op to read data to send to the prpl for a file transfer.
zacw@2592
    96
	 *
zacw@2592
    97
	 * @param xfer    The file transfer structure
zacw@2592
    98
	 * @param buffer  A pointer to a buffer. The UI must allocate this buffer.
zacw@2592
    99
	 *                libpurple will free the data.
zacw@2592
   100
	 * @param size    The maximum amount of data to put in the buffer.
zacw@2592
   101
	 *
zacw@2592
   102
	 * @returns The amount of data in the buffer, 0 if nothing is available,
zacw@2592
   103
	 *          and a negative value if an error occurred and the transfer
zacw@2592
   104
	 *          should be cancelled (libpurple will cancel).
zacw@2592
   105
	 * @since 2.6.0
zacw@2592
   106
	 */
zacw@2592
   107
	gssize (*ui_read)(PurpleXfer *xfer, guchar **buffer, gssize size);
zacw@2592
   108
zacw@2592
   109
	/**
zacw@2592
   110
	 * Op to notify the UI that not all the data read in was written. The UI
zacw@2592
   111
	 * should re-enqueue this data and return it the next time read is called.
zacw@2592
   112
	 *
zacw@2592
   113
	 * This MUST be implemented if read and write are implemented.
zacw@2592
   114
	 *
zacw@2592
   115
	 * @param xfer    The file transfer structure
zacw@2592
   116
	 * @param buffer  A pointer to the beginning of the unwritten data.
zacw@2592
   117
	 * @param size    The amount of unwritten data.
zacw@2592
   118
	 *
zacw@2592
   119
	 * @since 2.6.0
zacw@2592
   120
	 */
zacw@2592
   121
	void (*data_not_sent)(PurpleXfer *xfer, const guchar *buffer, gsize size);
zacw@2592
   122
Evan@653
   123
	void (*_purple_reserved1)(void);
Evan@653
   124
} PurpleXferUiOps;
Evan@653
   125
Evan@653
   126
/**
Evan@653
   127
 * A core representation of a file transfer.
Evan@653
   128
 */
Evan@653
   129
struct _PurpleXfer
Evan@653
   130
{
Evan@653
   131
	guint ref;                    /**< The reference count.                */
Evan@653
   132
	PurpleXferType type;            /**< The type of transfer.               */
Evan@653
   133
Evan@653
   134
	PurpleAccount *account;         /**< The account.                        */
Evan@653
   135
Evan@653
   136
	char *who;                    /**< The person on the other end of the
Evan@653
   137
	                                   transfer.                           */
Evan@653
   138
Evan@653
   139
	char *message;                /**< A message sent with the request     */
Evan@653
   140
	char *filename;               /**< The name sent over the network.     */
Evan@653
   141
	char *local_filename;         /**< The name on the local hard drive.   */
Evan@653
   142
	size_t size;                  /**< The size of the file.               */
Evan@653
   143
Evan@653
   144
	FILE *dest_fp;                /**< The destination file pointer.       */
Evan@653
   145
Evan@653
   146
	char *remote_ip;              /**< The remote IP address.              */
Evan@653
   147
	int local_port;               /**< The local port.                     */
Evan@653
   148
	int remote_port;              /**< The remote port.                    */
Evan@653
   149
Evan@653
   150
	int fd;                       /**< The socket file descriptor.         */
Evan@653
   151
	int watcher;                  /**< Watcher.                            */
Evan@653
   152
Evan@653
   153
	size_t bytes_sent;            /**< The number of bytes sent.           */
Evan@653
   154
	size_t bytes_remaining;       /**< The number of bytes remaining.      */
Evan@653
   155
	time_t start_time;            /**< When the transfer of data began.    */
Evan@653
   156
	time_t end_time;              /**< When the transfer of data ended.    */
Evan@653
   157
Evan@653
   158
	size_t current_buffer_size;   /**< This gradually increases for fast
Evan@653
   159
	                                   network connections. */
Evan@653
   160
Evan@653
   161
	PurpleXferStatusType status;    /**< File Transfer's status.             */
Evan@653
   162
Evan@653
   163
	/* I/O operations. */
Evan@653
   164
	struct
Evan@653
   165
	{
Evan@653
   166
		void (*init)(PurpleXfer *xfer);
Evan@653
   167
		void (*request_denied)(PurpleXfer *xfer);
Evan@653
   168
		void (*start)(PurpleXfer *xfer);
Evan@653
   169
		void (*end)(PurpleXfer *xfer);
Evan@653
   170
		void (*cancel_send)(PurpleXfer *xfer);
Evan@653
   171
		void (*cancel_recv)(PurpleXfer *xfer);
Evan@653
   172
		gssize (*read)(guchar **buffer, PurpleXfer *xfer);
Evan@653
   173
		gssize (*write)(const guchar *buffer, size_t size, PurpleXfer *xfer);
Evan@653
   174
		void (*ack)(PurpleXfer *xfer, const guchar *buffer, size_t size);
Evan@653
   175
	} ops;
Evan@653
   176
Evan@653
   177
	PurpleXferUiOps *ui_ops;            /**< UI-specific operations. */
Evan@653
   178
	void *ui_data;                    /**< UI-specific data.       */
Evan@653
   179
Evan@653
   180
	void *data;                       /**< prpl-specific data.     */
Evan@653
   181
};
Evan@653
   182
Evan@653
   183
#ifdef __cplusplus
Evan@653
   184
extern "C" {
Evan@653
   185
#endif
Evan@653
   186
Evan@653
   187
/**************************************************************************/
Evan@653
   188
/** @name File Transfer API                                               */
Evan@653
   189
/**************************************************************************/
Evan@653
   190
/*@{*/
Evan@653
   191
Evan@653
   192
/**
Evan@653
   193
 * Creates a new file transfer handle.
Evan@653
   194
 * This is called by prpls.
Evan@653
   195
 * The handle starts with a ref count of 1, and this reference
Evan@653
   196
 * is owned by the core. The prpl normally does not need to
Evan@653
   197
 * purple_xfer_ref or unref.
Evan@653
   198
 *
Evan@653
   199
 * @param account The account sending or receiving the file.
Evan@653
   200
 * @param type    The type of file transfer.
Evan@653
   201
 * @param who     The name of the remote user.
Evan@653
   202
 *
Evan@653
   203
 * @return A file transfer handle.
Evan@653
   204
 */
Evan@653
   205
PurpleXfer *purple_xfer_new(PurpleAccount *account,
Evan@653
   206
								PurpleXferType type, const char *who);
Evan@653
   207
Evan@653
   208
/**
Evan@653
   209
 * Returns all xfers
Evan@653
   210
 *
Evan@653
   211
 * @return all current xfers with refs
Evan@653
   212
 */
Evan@653
   213
GList *purple_xfers_get_all(void);
Evan@653
   214
Evan@653
   215
/**
Evan@653
   216
 * Increases the reference count on a PurpleXfer.
Evan@653
   217
 * Please call purple_xfer_unref later.
Evan@653
   218
 *
Evan@653
   219
 * @param xfer A file transfer handle.
Evan@653
   220
 */
Evan@653
   221
void purple_xfer_ref(PurpleXfer *xfer);
Evan@653
   222
Evan@653
   223
/**
Evan@653
   224
 * Decreases the reference count on a PurpleXfer.
Evan@653
   225
 * If the reference reaches 0, purple_xfer_destroy (an internal function)
Evan@653
   226
 * will destroy the xfer. It calls the ui destroy cb first.
Evan@653
   227
 * Since the core keeps a ref on the xfer, only an erroneous call to
Evan@653
   228
 * this function will destroy the xfer while still in use.
Evan@653
   229
 *
Evan@653
   230
 * @param xfer A file transfer handle.
Evan@653
   231
 */
Evan@653
   232
void purple_xfer_unref(PurpleXfer *xfer);
Evan@653
   233
Evan@653
   234
/**
Evan@653
   235
 * Requests confirmation for a file transfer from the user. If receiving
Evan@653
   236
 * a file which is known at this point, this requests user to accept and
Evan@653
   237
 * save the file. If the filename is unknown (not set) this only requests user
Evan@653
   238
 * to accept the file transfer. In this case protocol must call this function
Evan@653
   239
 * again once the filename is available.
Evan@653
   240
 *
Evan@653
   241
 * @param xfer The file transfer to request confirmation on.
Evan@653
   242
 */
Evan@653
   243
void purple_xfer_request(PurpleXfer *xfer);
Evan@653
   244
Evan@653
   245
/**
Evan@653
   246
 * Called if the user accepts the file transfer request.
Evan@653
   247
 *
Evan@653
   248
 * @param xfer     The file transfer.
Evan@653
   249
 * @param filename The filename.
Evan@653
   250
 */
Evan@653
   251
void purple_xfer_request_accepted(PurpleXfer *xfer, const char *filename);
Evan@653
   252
Evan@653
   253
/**
Evan@653
   254
 * Called if the user rejects the file transfer request.
Evan@653
   255
 *
Evan@653
   256
 * @param xfer The file transfer.
Evan@653
   257
 */
Evan@653
   258
void purple_xfer_request_denied(PurpleXfer *xfer);
Evan@653
   259
Evan@653
   260
/**
Evan@653
   261
 * Returns the type of file transfer.
Evan@653
   262
 *
Evan@653
   263
 * @param xfer The file transfer.
Evan@653
   264
 *
Evan@653
   265
 * @return The type of the file transfer.
Evan@653
   266
 */
Evan@653
   267
PurpleXferType purple_xfer_get_type(const PurpleXfer *xfer);
Evan@653
   268
Evan@653
   269
/**
Evan@653
   270
 * Returns the account the file transfer is using.
Evan@653
   271
 *
Evan@653
   272
 * @param xfer The file transfer.
Evan@653
   273
 *
Evan@653
   274
 * @return The account.
Evan@653
   275
 */
Evan@653
   276
PurpleAccount *purple_xfer_get_account(const PurpleXfer *xfer);
Evan@653
   277
Evan@653
   278
/**
Evan@653
   279
 * Returns the name of the remote user.
Evan@653
   280
 *
Evan@653
   281
 * @param xfer The file transfer.
Evan@653
   282
 *
Evan@653
   283
 * @return The name of the remote user.
Evan@653
   284
 *
Evan@653
   285
 * @since 2.1.0
Evan@653
   286
 */
Evan@653
   287
const char *purple_xfer_get_remote_user(const PurpleXfer *xfer);
Evan@653
   288
Evan@653
   289
/**
Evan@653
   290
 * Returns the status of the xfer.
Evan@653
   291
 *
Evan@653
   292
 * @param xfer The file transfer.
Evan@653
   293
 *
Evan@653
   294
 * @return The status.
Evan@653
   295
 */
Evan@653
   296
PurpleXferStatusType purple_xfer_get_status(const PurpleXfer *xfer);
Evan@653
   297
Evan@653
   298
/**
Evan@653
   299
 * Returns true if the file transfer was canceled.
Evan@653
   300
 *
Evan@653
   301
 * @param xfer The file transfer.
Evan@653
   302
 *
Evan@653
   303
 * @return Whether or not the transfer was canceled.
Evan@653
   304
 */
Evan@653
   305
gboolean purple_xfer_is_canceled(const PurpleXfer *xfer);
Evan@653
   306
Evan@653
   307
/**
Evan@653
   308
 * Returns the completed state for a file transfer.
Evan@653
   309
 *
Evan@653
   310
 * @param xfer The file transfer.
Evan@653
   311
 *
Evan@653
   312
 * @return The completed state.
Evan@653
   313
 */
Evan@653
   314
gboolean purple_xfer_is_completed(const PurpleXfer *xfer);
Evan@653
   315
Evan@653
   316
/**
Evan@653
   317
 * Returns the name of the file being sent or received.
Evan@653
   318
 *
Evan@653
   319
 * @param xfer The file transfer.
Evan@653
   320
 *
Evan@653
   321
 * @return The filename.
Evan@653
   322
 */
Evan@653
   323
const char *purple_xfer_get_filename(const PurpleXfer *xfer);
Evan@653
   324
Evan@653
   325
/**
Evan@653
   326
 * Returns the file's destination filename,
Evan@653
   327
 *
Evan@653
   328
 * @param xfer The file transfer.
Evan@653
   329
 *
Evan@653
   330
 * @return The destination filename.
Evan@653
   331
 */
Evan@653
   332
const char *purple_xfer_get_local_filename(const PurpleXfer *xfer);
Evan@653
   333
Evan@653
   334
/**
Evan@653
   335
 * Returns the number of bytes sent (or received) so far.
Evan@653
   336
 *
Evan@653
   337
 * @param xfer The file transfer.
Evan@653
   338
 *
Evan@653
   339
 * @return The number of bytes sent.
Evan@653
   340
 */
Evan@653
   341
size_t purple_xfer_get_bytes_sent(const PurpleXfer *xfer);
Evan@653
   342
Evan@653
   343
/**
Evan@653
   344
 * Returns the number of bytes remaining to send or receive.
Evan@653
   345
 *
Evan@653
   346
 * @param xfer The file transfer.
Evan@653
   347
 *
Evan@653
   348
 * @return The number of bytes remaining.
Evan@653
   349
 */
Evan@653
   350
size_t purple_xfer_get_bytes_remaining(const PurpleXfer *xfer);
Evan@653
   351
Evan@653
   352
/**
Evan@653
   353
 * Returns the size of the file being sent or received.
Evan@653
   354
 *
Evan@653
   355
 * @param xfer The file transfer.
Evan@653
   356
 *
Evan@653
   357
 * @return The total size of the file.
Evan@653
   358
 */
Evan@653
   359
size_t purple_xfer_get_size(const PurpleXfer *xfer);
Evan@653
   360
Evan@653
   361
/**
Evan@653
   362
 * Returns the current percentage of progress of the transfer.
Evan@653
   363
 *
Evan@653
   364
 * This is a number between 0 (0%) and 1 (100%).
Evan@653
   365
 *
Evan@653
   366
 * @param xfer The file transfer.
Evan@653
   367
 *
Evan@653
   368
 * @return The percentage complete.
Evan@653
   369
 */
Evan@653
   370
double purple_xfer_get_progress(const PurpleXfer *xfer);
Evan@653
   371
Evan@653
   372
/**
Evan@653
   373
 * Returns the local port number in the file transfer.
Evan@653
   374
 *
Evan@653
   375
 * @param xfer The file transfer.
Evan@653
   376
 *
Evan@653
   377
 * @return The port number on this end.
Evan@653
   378
 */
Evan@653
   379
unsigned int purple_xfer_get_local_port(const PurpleXfer *xfer);
Evan@653
   380
Evan@653
   381
/**
Evan@653
   382
 * Returns the remote IP address in the file transfer.
Evan@653
   383
 *
Evan@653
   384
 * @param xfer The file transfer.
Evan@653
   385
 *
Evan@653
   386
 * @return The IP address on the other end.
Evan@653
   387
 */
Evan@653
   388
const char *purple_xfer_get_remote_ip(const PurpleXfer *xfer);
Evan@653
   389
Evan@653
   390
/**
Evan@653
   391
 * Returns the remote port number in the file transfer.
Evan@653
   392
 *
Evan@653
   393
 * @param xfer The file transfer.
Evan@653
   394
 *
Evan@653
   395
 * @return The port number on the other end.
Evan@653
   396
 */
Evan@653
   397
unsigned int purple_xfer_get_remote_port(const PurpleXfer *xfer);
Evan@653
   398
Evan@653
   399
/**
Evan@653
   400
 * Returns the time the transfer of a file started.
Evan@653
   401
 *
Evan@653
   402
 * @param xfer  The file transfer.
Evan@653
   403
 *
Evan@653
   404
 * @return The time when the transfer started.
Evan@653
   405
 * @since 2.4.0
Evan@653
   406
 */
Evan@653
   407
time_t purple_xfer_get_start_time(const PurpleXfer *xfer);
Evan@653
   408
Evan@653
   409
/**
Evan@653
   410
 * Returns the time the transfer of a file ended.
Evan@653
   411
 *
Evan@653
   412
 * @param xfer  The file transfer.
Evan@653
   413
 *
Evan@653
   414
 * @return The time when the transfer ended.
Evan@653
   415
 * @since 2.4.0
Evan@653
   416
 */
Evan@653
   417
time_t purple_xfer_get_end_time(const PurpleXfer *xfer);
Evan@653
   418
Evan@653
   419
/**
Evan@653
   420
 * Sets the completed state for the file transfer.
Evan@653
   421
 *
Evan@653
   422
 * @param xfer      The file transfer.
Evan@653
   423
 * @param completed The completed state.
Evan@653
   424
 */
Evan@653
   425
void purple_xfer_set_completed(PurpleXfer *xfer, gboolean completed);
Evan@653
   426
Evan@653
   427
/**
Evan@653
   428
 * Sets the filename for the file transfer.
Evan@653
   429
 *
Evan@653
   430
 * @param xfer     The file transfer.
Evan@653
   431
 * @param message The message.
Evan@653
   432
 */
Evan@653
   433
void purple_xfer_set_message(PurpleXfer *xfer, const char *message);
Evan@653
   434
Evan@653
   435
/**
Evan@653
   436
 * Sets the filename for the file transfer.
Evan@653
   437
 *
Evan@653
   438
 * @param xfer     The file transfer.
Evan@653
   439
 * @param filename The filename.
Evan@653
   440
 */
Evan@653
   441
void purple_xfer_set_filename(PurpleXfer *xfer, const char *filename);
Evan@653
   442
Evan@653
   443
/**
Evan@653
   444
 * Sets the local filename for the file transfer.
Evan@653
   445
 *
Evan@653
   446
 * @param xfer     The file transfer.
Evan@653
   447
 * @param filename The filename
Evan@653
   448
 */
Evan@653
   449
void purple_xfer_set_local_filename(PurpleXfer *xfer, const char *filename);
Evan@653
   450
Evan@653
   451
/**
Evan@653
   452
 * Sets the size of the file in a file transfer.
Evan@653
   453
 *
Evan@653
   454
 * @param xfer The file transfer.
Evan@653
   455
 * @param size The size of the file.
Evan@653
   456
 */
Evan@653
   457
void purple_xfer_set_size(PurpleXfer *xfer, size_t size);
Evan@653
   458
Evan@653
   459
/**
Evan@653
   460
 * Sets the current working position in the active file transfer.  This
Evan@653
   461
 * can be used to jump backward in the file if the protocol detects
Evan@653
   462
 * that some bit of data needs to be resent or has been sent twice.
Evan@653
   463
 *
Evan@653
   464
 * It's used for pausing and resuming an oscar file transfer.
Evan@653
   465
 *
Evan@653
   466
 * @param xfer       The file transfer.
Evan@653
   467
 * @param bytes_sent The new current position in the file.  If we're
Evan@653
   468
 *                   sending a file then this is the byte that we will
Evan@653
   469
 *                   send.  If we're receiving a file, this is the
Evan@653
   470
 *                   next byte that we expect to receive.
Evan@653
   471
 */
Evan@653
   472
void purple_xfer_set_bytes_sent(PurpleXfer *xfer, size_t bytes_sent);
Evan@653
   473
Evan@653
   474
/**
Evan@653
   475
 * Returns the UI operations structure for a file transfer.
Evan@653
   476
 *
Evan@653
   477
 * @param xfer The file transfer.
Evan@653
   478
 *
Evan@653
   479
 * @return The UI operations structure.
Evan@653
   480
 */
Evan@653
   481
PurpleXferUiOps *purple_xfer_get_ui_ops(const PurpleXfer *xfer);
Evan@653
   482
Evan@653
   483
/**
Evan@653
   484
 * Sets the read function for the file transfer.
Evan@653
   485
 *
Evan@653
   486
 * @param xfer The file transfer.
Evan@653
   487
 * @param fnc  The read function.
Evan@653
   488
 */
Evan@653
   489
void purple_xfer_set_read_fnc(PurpleXfer *xfer,
Evan@653
   490
		gssize (*fnc)(guchar **, PurpleXfer *));
Evan@653
   491
Evan@653
   492
/**
Evan@653
   493
 * Sets the write function for the file transfer.
Evan@653
   494
 *
Evan@653
   495
 * @param xfer The file transfer.
Evan@653
   496
 * @param fnc  The write function.
Evan@653
   497
 */
Evan@653
   498
void purple_xfer_set_write_fnc(PurpleXfer *xfer,
Evan@653
   499
		gssize (*fnc)(const guchar *, size_t, PurpleXfer *));
Evan@653
   500
Evan@653
   501
/**
Evan@653
   502
 * Sets the acknowledge function for the file transfer.
Evan@653
   503
 *
Evan@653
   504
 * @param xfer The file transfer.
Evan@653
   505
 * @param fnc  The acknowledge function.
Evan@653
   506
 */
Evan@653
   507
void purple_xfer_set_ack_fnc(PurpleXfer *xfer,
Evan@653
   508
		void (*fnc)(PurpleXfer *, const guchar *, size_t));
Evan@653
   509
Evan@653
   510
/**
Evan@653
   511
 * Sets the function to be called if the request is denied.
Evan@653
   512
 *
Evan@653
   513
 * @param xfer The file transfer.
Evan@653
   514
 * @param fnc The request denied prpl callback.
Evan@653
   515
 */
Evan@653
   516
void purple_xfer_set_request_denied_fnc(PurpleXfer *xfer, void (*fnc)(PurpleXfer *));
Evan@653
   517
Evan@653
   518
/**
Evan@653
   519
 * Sets the transfer initialization function for the file transfer.
Evan@653
   520
 *
Evan@653
   521
 * This function is required, and must call purple_xfer_start() with
Evan@653
   522
 * the necessary parameters. This will be called if the file transfer
Evan@653
   523
 * is accepted by the user.
Evan@653
   524
 *
Evan@653
   525
 * @param xfer The file transfer.
Evan@653
   526
 * @param fnc  The transfer initialization function.
Evan@653
   527
 */
Evan@653
   528
void purple_xfer_set_init_fnc(PurpleXfer *xfer, void (*fnc)(PurpleXfer *));
Evan@653
   529
Evan@653
   530
/**
Evan@653
   531
 * Sets the start transfer function for the file transfer.
Evan@653
   532
 *
Evan@653
   533
 * @param xfer The file transfer.
Evan@653
   534
 * @param fnc  The start transfer function.
Evan@653
   535
 */
Evan@653
   536
void purple_xfer_set_start_fnc(PurpleXfer *xfer, void (*fnc)(PurpleXfer *));
Evan@653
   537
Evan@653
   538
/**
Evan@653
   539
 * Sets the end transfer function for the file transfer.
Evan@653
   540
 *
Evan@653
   541
 * @param xfer The file transfer.
Evan@653
   542
 * @param fnc  The end transfer function.
Evan@653
   543
 */
Evan@653
   544
void purple_xfer_set_end_fnc(PurpleXfer *xfer, void (*fnc)(PurpleXfer *));
Evan@653
   545
Evan@653
   546
/**
Evan@653
   547
 * Sets the cancel send function for the file transfer.
Evan@653
   548
 *
Evan@653
   549
 * @param xfer The file transfer.
Evan@653
   550
 * @param fnc  The cancel send function.
Evan@653
   551
 */
Evan@653
   552
void purple_xfer_set_cancel_send_fnc(PurpleXfer *xfer, void (*fnc)(PurpleXfer *));
Evan@653
   553
Evan@653
   554
/**
Evan@653
   555
 * Sets the cancel receive function for the file transfer.
Evan@653
   556
 *
Evan@653
   557
 * @param xfer The file transfer.
Evan@653
   558
 * @param fnc  The cancel receive function.
Evan@653
   559
 */
Evan@653
   560
void purple_xfer_set_cancel_recv_fnc(PurpleXfer *xfer, void (*fnc)(PurpleXfer *));
Evan@653
   561
Evan@653
   562
/**
Evan@653
   563
 * Reads in data from a file transfer stream.
Evan@653
   564
 *
Evan@653
   565
 * @param xfer   The file transfer.
Evan@653
   566
 * @param buffer The buffer that will be created to contain the data.
Evan@653
   567
 *
Evan@653
   568
 * @return The number of bytes read, or -1.
Evan@653
   569
 */
Evan@653
   570
gssize purple_xfer_read(PurpleXfer *xfer, guchar **buffer);
Evan@653
   571
Evan@653
   572
/**
Evan@653
   573
 * Writes data to a file transfer stream.
Evan@653
   574
 *
Evan@653
   575
 * @param xfer   The file transfer.
Evan@653
   576
 * @param buffer The buffer to read the data from.
Evan@653
   577
 * @param size   The number of bytes to write.
Evan@653
   578
 *
Evan@653
   579
 * @return The number of bytes written, or -1.
Evan@653
   580
 */
Evan@653
   581
gssize purple_xfer_write(PurpleXfer *xfer, const guchar *buffer, gsize size);
Evan@653
   582
Evan@653
   583
/**
Evan@653
   584
 * Starts a file transfer.
Evan@653
   585
 *
Evan@653
   586
 * Either @a fd must be specified <i>or</i> @a ip and @a port on a
Evan@653
   587
 * file receive transfer. On send, @a fd must be specified, and
Evan@653
   588
 * @a ip and @a port are ignored.
Evan@653
   589
 *
zacw@2592
   590
 * Prior to libpurple 2.6.0, passing '0' to @a fd was special-cased to
zacw@2592
   591
 * allow the protocol plugin to facilitate the file transfer itself. As of
zacw@2592
   592
 * 2.6.0, this is supported (for backward compatibility), but will be
zacw@2592
   593
 * removed in libpurple 3.0.0. If a prpl detects that the running libpurple
zacw@2592
   594
 * is running 2.6.0 or higher, it should use the invalid fd '-1'.
zacw@2592
   595
 *
Evan@653
   596
 * @param xfer The file transfer.
Evan@653
   597
 * @param fd   The file descriptor for the socket.
Evan@653
   598
 * @param ip   The IP address to connect to.
Evan@653
   599
 * @param port The port to connect to.
Evan@653
   600
 */
Evan@653
   601
void purple_xfer_start(PurpleXfer *xfer, int fd, const char *ip,
Evan@653
   602
					 unsigned int port);
Evan@653
   603
Evan@653
   604
/**
Evan@653
   605
 * Ends a file transfer.
Evan@653
   606
 *
Evan@653
   607
 * @param xfer The file transfer.
Evan@653
   608
 */
Evan@653
   609
void purple_xfer_end(PurpleXfer *xfer);
Evan@653
   610
Evan@653
   611
/**
Evan@653
   612
 * Adds a new file transfer to the list of file transfers. Call this only
Evan@653
   613
 * if you are not using purple_xfer_start.
Evan@653
   614
 *
Evan@653
   615
 * @param xfer The file transfer.
Evan@653
   616
 */
Evan@653
   617
void purple_xfer_add(PurpleXfer *xfer);
Evan@653
   618
Evan@653
   619
/**
Evan@653
   620
 * Cancels a file transfer on the local end.
Evan@653
   621
 *
Evan@653
   622
 * @param xfer The file transfer.
Evan@653
   623
 */
Evan@653
   624
void purple_xfer_cancel_local(PurpleXfer *xfer);
Evan@653
   625
Evan@653
   626
/**
Evan@653
   627
 * Cancels a file transfer from the remote end.
Evan@653
   628
 *
Evan@653
   629
 * @param xfer The file transfer.
Evan@653
   630
 */
Evan@653
   631
void purple_xfer_cancel_remote(PurpleXfer *xfer);
Evan@653
   632
Evan@653
   633
/**
Evan@653
   634
 * Displays a file transfer-related error message.
Evan@653
   635
 *
Evan@653
   636
 * This is a wrapper around purple_notify_error(), which automatically
Evan@653
   637
 * specifies a title ("File transfer to <i>user</i> failed" or
Evan@653
   638
 * "File Transfer from <i>user</i> failed").
Evan@653
   639
 *
Evan@653
   640
 * @param type    The type of file transfer.
Evan@653
   641
 * @param account The account sending or receiving the file.
Evan@653
   642
 * @param who     The user on the other end of the transfer.
Evan@653
   643
 * @param msg     The message to display.
Evan@653
   644
 */
Evan@653
   645
void purple_xfer_error(PurpleXferType type, PurpleAccount *account, const char *who, const char *msg);
Evan@653
   646
Evan@653
   647
/**
Evan@653
   648
 * Updates file transfer progress.
Evan@653
   649
 *
Evan@653
   650
 * @param xfer      The file transfer.
Evan@653
   651
 */
Evan@653
   652
void purple_xfer_update_progress(PurpleXfer *xfer);
Evan@653
   653
Evan@653
   654
/**
Evan@653
   655
 * Displays a file transfer-related message in the conversation window
Evan@653
   656
 *
Evan@653
   657
 * This is a wrapper around purple_conversation_write
Evan@653
   658
 *
Evan@653
   659
 * @param xfer The file transfer to which this message relates.
Evan@653
   660
 * @param message The message to display.
Evan@653
   661
 * @param is_error Is this an error message?.
Evan@653
   662
 */
Evan@653
   663
void purple_xfer_conversation_write(PurpleXfer *xfer, char *message, gboolean is_error);
Evan@653
   664
zacw@2592
   665
/**
zacw@2592
   666
 * Allows the UI to signal it's ready to send/receive data (depending on
zacw@2592
   667
 * the direction of the file transfer. Used when the UI is providing
zacw@2592
   668
 * read/write/data_not_sent UI ops.
zacw@2592
   669
 *
zacw@2592
   670
 * @param xfer The file transfer which is ready.
zacw@2592
   671
 *
zacw@2592
   672
 * @since 2.6.0
zacw@2592
   673
 */
zacw@2592
   674
void purple_xfer_ui_ready(PurpleXfer *xfer);
zacw@2592
   675
zacw@2592
   676
/**
zacw@2592
   677
 * Allows the prpl to signal it's readh to send/receive data (depending on
zacw@2592
   678
 * the direction of the file transfer. Used when the prpl provides read/write
zacw@2592
   679
 * ops and cannot/does not provide a raw fd to the core.
zacw@2592
   680
 *
zacw@2592
   681
 * @param xfer The file transfer which is ready.
zacw@2592
   682
 *
zacw@2592
   683
 * @since 2.6.0
zacw@2592
   684
 */
zacw@2592
   685
void purple_xfer_prpl_ready(PurpleXfer *xfer);
zacw@2592
   686
Evan@653
   687
/*@}*/
Evan@653
   688
Evan@653
   689
/**************************************************************************/
Evan@653
   690
/** @name UI Registration Functions                                       */
Evan@653
   691
/**************************************************************************/
Evan@653
   692
/*@{*/
Evan@653
   693
Evan@653
   694
/**
Evan@653
   695
 * Returns the handle to the file transfer subsystem
Evan@653
   696
 *
Evan@653
   697
 * @return The handle
Evan@653
   698
 */
Evan@653
   699
void *purple_xfers_get_handle(void);
Evan@653
   700
Evan@653
   701
/**
Evan@653
   702
 * Initializes the file transfer subsystem
Evan@653
   703
 */
Evan@653
   704
void purple_xfers_init(void);
Evan@653
   705
Evan@653
   706
/**
Evan@653
   707
 * Uninitializes the file transfer subsystem
Evan@653
   708
 */
Evan@653
   709
void purple_xfers_uninit(void);
Evan@653
   710
Evan@653
   711
/**
Evan@653
   712
 * Sets the UI operations structure to be used in all purple file transfers.
Evan@653
   713
 *
Evan@653
   714
 * @param ops The UI operations structure.
Evan@653
   715
 */
Evan@653
   716
void purple_xfers_set_ui_ops(PurpleXferUiOps *ops);
Evan@653
   717
Evan@653
   718
/**
Evan@653
   719
 * Returns the UI operations structure to be used in all purple file transfers.
Evan@653
   720
 *
Evan@653
   721
 * @return The UI operations structure.
Evan@653
   722
 */
Evan@653
   723
PurpleXferUiOps *purple_xfers_get_ui_ops(void);
Evan@653
   724
Evan@653
   725
/*@}*/
Evan@653
   726
Evan@653
   727
#ifdef __cplusplus
Evan@653
   728
}
Evan@653
   729
#endif
Evan@653
   730
Evan@653
   731
#endif /* _PURPLE_FT_H_ */