Mercurial > pidgin
annotate src/ft.h @ 4569:7f2de19d052d
[gaim-migrate @ 4850]
Bug fix. Gaim would crash if using the IM convo window slider bars after plugin removal.
committer: Tailor Script <tailor@pidgin.im>
| author | Herman Bloggs <hermanator12002@yahoo.com> |
|---|---|
| date | Tue, 11 Feb 2003 00:58:28 +0000 |
| parents | 05476ef20d58 |
| children | a2c95c0d7333 |
| rev | line source |
|---|---|
| 4514 | 1 /** |
| 2 * @file ft.h The file transfer interface | |
| 3 * | |
| 4 * gaim | |
| 5 * | |
| 6 * Copyright (C) 2002-2003, Christian Hammond <chipx86@gnupdate.org> | |
| 7 * | |
| 8 * This program is free software; you can redistribute it and/or modify | |
| 9 * it under the terms of the GNU General Public License as published by | |
| 10 * the Free Software Foundation; either version 2 of the License, or | |
| 11 * (at your option) any later version. | |
| 12 * | |
| 13 * This program is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 * GNU General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU General Public License | |
| 19 * along with this program; if not, write to the Free Software | |
| 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 * | |
| 22 */ | |
| 23 #ifndef _GAIM_FT_H_ | |
| 24 #define _GAIM_FT_H_ | |
| 25 | |
| 26 /**************************************************************************/ | |
| 27 /** Data Structures */ | |
| 28 /**************************************************************************/ | |
| 29 struct gaim_xfer *xfer; | |
| 30 | |
| 31 /** | |
| 32 * Types of file transfers. | |
| 33 */ | |
| 34 typedef enum | |
| 35 { | |
| 36 GAIM_XFER_UNKNOWN = 0, /**< Unknown file transfer type. */ | |
| 37 GAIM_XFER_SEND, /**< File sending. */ | |
| 38 GAIM_XFER_RECEIVE /**< File receiving. */ | |
| 39 | |
| 40 } GaimXferType; | |
| 41 | |
| 42 /** | |
| 43 * File transfer UI operations. | |
| 44 * | |
| 45 * Any UI representing a file transfer must assign a filled-out | |
| 46 * gaim_xfer_ui_ops structure to the gaim_xfer. | |
| 47 */ | |
| 48 struct gaim_xfer_ui_ops | |
| 49 { | |
| 50 void (*destroy)(struct gaim_xfer *xfer); | |
| 51 void (*request_file)(struct gaim_xfer *xfer); | |
| 52 void (*ask_cancel)(struct gaim_xfer *xfer); | |
| 53 void (*add_xfer)(struct gaim_xfer *xfer); | |
| 54 void (*update_progress)(struct gaim_xfer *xfer, double percent); | |
| 55 void (*cancel)(struct gaim_xfer *xfer); | |
| 56 }; | |
| 57 | |
| 58 /** | |
| 59 * A core representation of a file transfer. | |
| 60 */ | |
| 61 struct gaim_xfer | |
| 62 { | |
| 63 GaimXferType type; /**< The type of transfer. */ | |
| 64 | |
| 65 struct gaim_account *account; /**< The account. */ | |
| 66 | |
| 67 char *who; /**< The person on the other end of the | |
| 68 transfer. */ | |
| 69 | |
| 70 char *filename; /**< The name of the file. */ | |
| 71 char *dest_filename; /**< The destination filename. */ | |
| 72 size_t size; /**< The size of the file. */ | |
| 73 | |
| 74 FILE *dest_fp; /**< The destination file pointer. */ | |
| 75 | |
| 76 char *local_ip; /**< The local IP address. */ | |
| 77 char *remote_ip; /**< The remote IP address. */ | |
| 78 int local_port; /**< The local port. */ | |
| 79 int remote_port; /**< The remote port. */ | |
| 80 | |
| 81 int fd; /**< The socket file descriptor. */ | |
| 82 int watcher; /**< Watcher. */ | |
| 83 | |
| 84 size_t bytes_sent; /**< The number of bytes sent. */ | |
| 85 size_t bytes_remaining; /**< The number of bytes remaining. */ | |
| 86 | |
| 4538 | 87 gboolean completed; /**< File Transfer is completed. */ |
| 88 | |
| 4514 | 89 /* I/O operations. */ |
| 90 struct | |
| 91 { | |
| 92 void (*init)(struct gaim_xfer *xfer); | |
| 93 void (*start)(struct gaim_xfer *xfer); | |
| 94 void (*end)(struct gaim_xfer *xfer); | |
| 95 void (*cancel)(struct gaim_xfer *xfer); | |
|
4518
a6be92358df3
[gaim-migrate @ 4796]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
96 size_t (*read)(char **buffer, struct gaim_xfer *xfer); |
| 4514 | 97 size_t (*write)(const char *buffer, size_t size, |
|
4518
a6be92358df3
[gaim-migrate @ 4796]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
98 struct gaim_xfer *xfer); |
| 4514 | 99 void (*ack)(struct gaim_xfer *xfer); |
| 100 | |
| 101 } ops; | |
| 102 | |
| 103 struct gaim_xfer_ui_ops *ui_ops; /**< UI-specific operations. */ | |
| 104 void *ui_data; /**< UI-specific data. */ | |
| 105 | |
| 106 void *data; /**< prpl-specific data. */ | |
| 107 }; | |
| 108 | |
| 109 /**************************************************************************/ | |
| 110 /** @name File Transfer API */ | |
| 111 /**************************************************************************/ | |
| 112 /*@{*/ | |
| 113 | |
| 114 /** | |
| 115 * Creates a new file transfer handle. | |
| 116 * | |
| 117 * @param account The account sending or receiving the file. | |
| 118 * @param type The type of file transfer. | |
| 119 * @param who The name of the remote user. | |
| 120 * | |
| 121 * @return A file transfer handle. | |
| 122 */ | |
| 123 struct gaim_xfer *gaim_xfer_new(struct gaim_account *account, | |
| 124 GaimXferType type, const char *who); | |
| 125 | |
| 126 /** | |
| 127 * Destroys a file transfer handle. | |
| 128 * | |
| 129 * @param xfer The file transfer to destroy. | |
| 130 */ | |
| 131 void gaim_xfer_destroy(struct gaim_xfer *xfer); | |
| 132 | |
| 133 /** | |
| 134 * Requests confirmation for a file transfer from the user. | |
| 135 * | |
| 136 * @param xfer The file transfer to request confirmation on. | |
| 137 */ | |
| 138 void gaim_xfer_request(struct gaim_xfer *xfer); | |
| 139 | |
| 140 /** | |
| 141 * Called if the user accepts the file transfer request. | |
| 142 * | |
| 143 * @param xfer The file transfer. | |
| 144 * @param filename The filename. | |
| 145 */ | |
| 146 void gaim_xfer_request_accepted(struct gaim_xfer *xfer, char *filename); | |
| 147 | |
| 148 /** | |
| 149 * Called if the user rejects the file transfer request. | |
| 150 * | |
| 151 * @param xfer The file transfer. | |
| 152 */ | |
| 153 void gaim_xfer_request_denied(struct gaim_xfer *xfer); | |
| 154 | |
| 155 /** | |
| 156 * Returns the type of file transfer. | |
| 157 * | |
| 158 * @param xfer The file transfer. | |
| 159 * | |
| 160 * @return The type of the file transfer. | |
| 161 */ | |
| 162 GaimXferType gaim_xfer_get_type(const struct gaim_xfer *xfer); | |
| 163 | |
| 164 /** | |
| 165 * Returns the account the file transfer is using. | |
| 166 * | |
| 167 * @param xfer The file transfer. | |
| 168 * | |
| 169 * @return The account. | |
| 170 */ | |
| 171 struct gaim_account *gaim_xfer_get_account(const struct gaim_xfer *xfer); | |
| 172 | |
| 173 /** | |
|
4539
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
174 * Returns the completed state for a file transfer. |
|
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
175 * |
|
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
176 * @param xfer The file transfer. |
|
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
177 * |
|
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
178 * @return The completed state. |
|
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
179 */ |
|
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
180 gboolean gaim_xfer_is_completed(const struct gaim_xfer *xfer); |
|
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
181 |
|
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
182 /** |
| 4514 | 183 * Returns the name of the file being sent or received. |
| 184 * | |
| 185 * @param xfer The file transfer. | |
| 186 * | |
| 187 * @return The filename. | |
| 188 */ | |
| 189 const char *gaim_xfer_get_filename(const struct gaim_xfer *xfer); | |
| 190 | |
| 191 /** | |
| 192 * Returns the file's destination filename, | |
| 193 * | |
| 194 * @param xfer The file transfer. | |
| 195 * | |
| 196 * @return The destination filename. | |
| 197 */ | |
| 198 const char *gaim_xfer_get_dest_filename(const struct gaim_xfer *xfer); | |
| 199 | |
| 200 /** | |
| 201 * Returns the number of bytes sent so far. | |
| 202 * | |
| 203 * @param xfer The file transfer. | |
| 204 * | |
| 205 * @return The number of bytes sent. | |
| 206 */ | |
| 207 size_t gaim_xfer_get_bytes_sent(const struct gaim_xfer *xfer); | |
| 208 | |
| 209 /** | |
| 210 * Returns the number of bytes received so far. | |
| 211 * | |
| 212 * @param xfer The file transfer. | |
| 213 * | |
| 214 * @return The number of bytes received. | |
| 215 */ | |
| 216 size_t gaim_xfer_get_bytes_remaining(const struct gaim_xfer *xfer); | |
| 217 | |
| 218 /** | |
| 219 * Returns the size of the file being sent or received. | |
| 220 * | |
| 221 * @param xfer The file transfer. | |
| 222 * | |
| 223 * @return The total size of the file. | |
| 224 */ | |
| 225 size_t gaim_xfer_get_size(const struct gaim_xfer *xfer); | |
| 226 | |
| 227 /** | |
| 228 * Returns the current percentage of progress of the transfer. | |
| 229 * | |
| 230 * This is a number between 0 (0%) and 1 (100%). | |
| 231 * | |
| 232 * @param xfer The file transfer. | |
| 233 * | |
| 234 * @return The percentage complete. | |
| 235 */ | |
| 236 double gaim_xfer_get_progress(const struct gaim_xfer *xfer); | |
| 237 | |
| 238 /** | |
| 239 * Returns the local IP address in the file transfer. | |
| 240 * | |
| 241 * @param xfer The file transfer. | |
| 242 * | |
| 243 * @return The IP address on this end. | |
| 244 */ | |
| 245 const char *gaim_xfer_get_local_ip(const struct gaim_xfer *xfer); | |
| 246 | |
| 247 /** | |
| 248 * Returns the local port number in the file transfer. | |
| 249 * | |
| 250 * @param xfer The file transfer. | |
| 251 * | |
| 252 * @return The port number on this end. | |
| 253 */ | |
| 254 unsigned int gaim_xfer_get_local_port(const struct gaim_xfer *xfer); | |
| 255 | |
| 256 /** | |
| 257 * Returns the remote IP address in the file transfer. | |
| 258 * | |
| 259 * @param xfer The file transfer. | |
| 260 * | |
| 261 * @return The IP address on the other end. | |
| 262 */ | |
| 263 const char *gaim_xfer_get_remote_ip(const struct gaim_xfer *xfer); | |
| 264 | |
| 265 /** | |
| 266 * Returns the remote port number in the file transfer. | |
| 267 * | |
| 268 * @param xfer The file transfer. | |
| 269 * | |
| 270 * @return The port number on the other end. | |
| 271 */ | |
| 272 unsigned int gaim_xfer_get_remote_port(const struct gaim_xfer *xfer); | |
| 273 | |
| 274 /** | |
| 4538 | 275 * Sets the completed state for the file transfer. |
| 276 * | |
| 277 * @param xfer The file transfer. | |
| 278 * @param completed The completed state. | |
| 279 */ | |
| 280 void gaim_xfer_set_completed(struct gaim_xfer *xfer, gboolean completed); | |
| 281 | |
| 282 /** | |
| 4514 | 283 * Sets the filename for the file transfer. |
| 284 * | |
| 285 * @param xfer The file transfer. | |
| 286 * @param filename The filename. | |
| 287 */ | |
| 288 void gaim_xfer_set_filename(struct gaim_xfer *xfer, const char *filename); | |
| 289 | |
| 290 /** | |
| 291 * Sets the destination filename for the file transfer. | |
| 292 * | |
| 293 * @param xfer The file transfer. | |
| 294 * @param filename The filename | |
| 295 */ | |
| 296 void gaim_xfer_set_dest_filename(struct gaim_xfer *xfer, const char *filename); | |
| 297 | |
| 298 /** | |
| 299 * Sets the size of the file in a file transfer. | |
| 300 * | |
| 301 * @param xfer The file transfer. | |
| 302 * @param size The size of the file. | |
| 303 */ | |
| 304 void gaim_xfer_set_size(struct gaim_xfer *xfer, size_t size); | |
| 305 | |
| 306 /** | |
| 307 * Returns the UI operations structure for a file transfer. | |
| 308 * | |
| 309 * @param xfer The file transfer. | |
| 310 * | |
| 311 * @return The UI operations structure. | |
| 312 */ | |
| 313 struct gaim_xfer_ui_ops *gaim_xfer_get_ui_ops(const struct gaim_xfer *xfer); | |
| 314 | |
| 315 /** | |
| 316 * Sets the read function for the file transfer. | |
| 317 * | |
| 318 * @param xfer The file transfer. | |
| 319 * @param fnc The read function. | |
| 320 */ | |
| 321 void gaim_xfer_set_read_fnc(struct gaim_xfer *xfer, | |
|
4518
a6be92358df3
[gaim-migrate @ 4796]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
322 size_t (*fnc)(char **, struct gaim_xfer *)); |
| 4514 | 323 |
| 324 /** | |
| 325 * Sets the write function for the file transfer. | |
| 326 * | |
| 327 * @param xfer The file transfer. | |
| 328 * @param fnc The write function. | |
| 329 */ | |
| 330 void gaim_xfer_set_write_fnc(struct gaim_xfer *xfer, | |
|
4518
a6be92358df3
[gaim-migrate @ 4796]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
331 size_t (*fnc)(const char *, size_t, struct gaim_xfer *)); |
| 4514 | 332 |
| 333 /** | |
| 334 * Sets the acknowledge function for the file transfer. | |
| 335 * | |
| 336 * @param xfer The file transfer. | |
| 337 * @param fnc The acknowledge function. | |
| 338 */ | |
| 339 void gaim_xfer_set_ack_fnc(struct gaim_xfer *xfer, | |
| 340 void (*fnc)(struct gaim_xfer *)); | |
| 341 | |
| 342 /** | |
| 343 * Sets the transfer initialization function for the file transfer. | |
| 344 * | |
| 345 * This function is required, and must call gaim_xfer_start() with | |
| 346 * the necessary parameters. This will be called if the file transfer | |
| 347 * is accepted by the user. | |
| 348 * | |
| 349 * @param xfer The file transfer. | |
| 350 * @param fnc The transfer initialization function. | |
| 351 */ | |
| 352 void gaim_xfer_set_init_fnc(struct gaim_xfer *xfer, | |
| 353 void (*fnc)(struct gaim_xfer *)); | |
| 354 | |
| 355 /** | |
| 356 * Sets the start transfer function for the file transfer. | |
| 357 * | |
| 358 * @param xfer The file transfer. | |
| 359 * @param fnc The start transfer function. | |
| 360 */ | |
| 361 void gaim_xfer_set_start_fnc(struct gaim_xfer *xfer, | |
| 362 void (*fnc)(struct gaim_xfer *)); | |
| 363 | |
| 364 /** | |
| 365 * Sets the end transfer function for the file transfer. | |
| 366 * | |
| 367 * @param xfer The file transfer. | |
| 368 * @param fnc The end transfer function. | |
| 369 */ | |
| 370 void gaim_xfer_set_end_fnc(struct gaim_xfer *xfer, | |
| 371 void (*fnc)(struct gaim_xfer *)); | |
| 372 | |
| 373 /** | |
| 374 * Sets the cancel transfer function for the file transfer. | |
| 375 * | |
| 376 * @param xfer The file transfer. | |
| 377 * @param fnc The cancel transfer function. | |
| 378 */ | |
| 379 void gaim_xfer_set_cancel_fnc(struct gaim_xfer *xfer, | |
| 380 void (*fnc)(struct gaim_xfer *)); | |
| 381 | |
| 382 /** | |
| 383 * Reads in data from a file transfer stream. | |
| 384 * | |
| 385 * @param xfer The file transfer. | |
| 386 * @param buffer The buffer that will be created to contain the data. | |
| 387 * | |
| 388 * @return The number of bytes read. | |
| 389 */ | |
| 390 size_t gaim_xfer_read(struct gaim_xfer *xfer, char **buffer); | |
| 391 | |
| 392 /** | |
| 393 * Writes data to a file transfer stream. | |
| 394 * | |
| 395 * @param xfer The file transfer. | |
| 396 * @param buffer The buffer to read the data from. | |
| 397 * @param size The number of bytes to write. | |
| 398 * | |
| 399 * @return The number of bytes written. | |
| 400 */ | |
| 401 size_t gaim_xfer_write(struct gaim_xfer *xfer, const char *buffer, | |
| 402 size_t size); | |
| 403 | |
| 404 /** | |
| 405 * Starts a file transfer. | |
| 406 * | |
| 407 * Either @a fd must be specified <i>or</i> @a ip and @a port on a | |
| 408 * file receive transfer. On send, @a fd must be specified, and | |
| 409 * @a ip and @a port are ignored. | |
| 410 * | |
| 411 * @param xfer The file transfer. | |
| 412 * @param fd The file descriptor for the socket. | |
| 413 * @param ip The IP address to connect to. | |
| 414 * @param port The port to connect to. | |
| 415 */ | |
| 416 void gaim_xfer_start(struct gaim_xfer *xfer, int fd, const char *ip, | |
| 417 unsigned int port); | |
| 418 | |
| 419 /** | |
| 420 * Ends a file transfer. | |
| 421 * | |
| 422 * @param xfer The file transfer. | |
| 423 */ | |
| 424 void gaim_xfer_end(struct gaim_xfer *xfer); | |
| 425 | |
| 426 /** | |
| 427 * Cancels a file transfer. | |
| 428 * | |
| 429 * @param xfer The file transfer. | |
| 430 */ | |
| 431 void gaim_xfer_cancel(struct gaim_xfer *xfer); | |
| 432 | |
| 433 /** | |
| 434 * Displays a file transfer-related error message. | |
| 435 * | |
| 436 * This is a wrapper around do_error_dialog(), which automatically | |
| 437 * specifies a title ("File transfer to <i>user</i> aborted" or | |
| 438 * "File Transfer from <i>user</i> aborted"). | |
| 439 * | |
| 440 * @param type The type of file transfer. | |
| 441 * @param who The user on the other end of the transfer. | |
| 442 * @param msg The message to display. | |
| 443 */ | |
| 444 void gaim_xfer_error(GaimXferType type, const char *who, const char *msg); | |
| 445 | |
| 446 /*@}*/ | |
| 447 | |
| 448 /**************************************************************************/ | |
| 449 /** @name UI Registration Functions */ | |
| 450 /**************************************************************************/ | |
| 451 /*@{*/ | |
| 452 | |
| 453 /** | |
| 454 * Sets the UI operations structure to be used in all gaim file transfers. | |
| 455 * | |
| 456 * @param fnc The function. | |
| 457 */ | |
| 458 void gaim_set_xfer_ui_ops(struct gaim_xfer_ui_ops *ops); | |
| 459 | |
| 460 /** | |
| 461 * Returns the UI operations structure to be used in all gaim file transfers. | |
| 462 * | |
| 463 * @return The UI operations structure. | |
| 464 */ | |
| 465 struct gaim_xfer_ui_ops *gaim_get_xfer_ui_ops(void); | |
| 466 | |
| 467 /*@}*/ | |
| 468 | |
| 469 #endif /* _GAIM_FT_H_ */ |
