Thu, 06 Feb 2003 04:32:54 +0000
[gaim-migrate @ 4817]
Jabber can receive files again.
I'm sure everyone was losing as much sleep over this as I was.
| 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
7ef89224fd04
[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
7ef89224fd04
[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 | /** | |
| 174 | * Returns the name of the file being sent or received. | |
| 175 | * | |
| 176 | * @param xfer The file transfer. | |
| 177 | * | |
| 178 | * @return The filename. | |
| 179 | */ | |
| 180 | const char *gaim_xfer_get_filename(const struct gaim_xfer *xfer); | |
| 181 | ||
| 182 | /** | |
| 183 | * Returns the file's destination filename, | |
| 184 | * | |
| 185 | * @param xfer The file transfer. | |
| 186 | * | |
| 187 | * @return The destination filename. | |
| 188 | */ | |
| 189 | const char *gaim_xfer_get_dest_filename(const struct gaim_xfer *xfer); | |
| 190 | ||
| 191 | /** | |
| 192 | * Returns the number of bytes sent so far. | |
| 193 | * | |
| 194 | * @param xfer The file transfer. | |
| 195 | * | |
| 196 | * @return The number of bytes sent. | |
| 197 | */ | |
| 198 | size_t gaim_xfer_get_bytes_sent(const struct gaim_xfer *xfer); | |
| 199 | ||
| 200 | /** | |
| 201 | * Returns the number of bytes received so far. | |
| 202 | * | |
| 203 | * @param xfer The file transfer. | |
| 204 | * | |
| 205 | * @return The number of bytes received. | |
| 206 | */ | |
| 207 | size_t gaim_xfer_get_bytes_remaining(const struct gaim_xfer *xfer); | |
| 208 | ||
| 209 | /** | |
| 210 | * Returns the size of the file being sent or received. | |
| 211 | * | |
| 212 | * @param xfer The file transfer. | |
| 213 | * | |
| 214 | * @return The total size of the file. | |
| 215 | */ | |
| 216 | size_t gaim_xfer_get_size(const struct gaim_xfer *xfer); | |
| 217 | ||
| 218 | /** | |
| 219 | * Returns the current percentage of progress of the transfer. | |
| 220 | * | |
| 221 | * This is a number between 0 (0%) and 1 (100%). | |
| 222 | * | |
| 223 | * @param xfer The file transfer. | |
| 224 | * | |
| 225 | * @return The percentage complete. | |
| 226 | */ | |
| 227 | double gaim_xfer_get_progress(const struct gaim_xfer *xfer); | |
| 228 | ||
| 229 | /** | |
| 230 | * Returns the local IP address in the file transfer. | |
| 231 | * | |
| 232 | * @param xfer The file transfer. | |
| 233 | * | |
| 234 | * @return The IP address on this end. | |
| 235 | */ | |
| 236 | const char *gaim_xfer_get_local_ip(const struct gaim_xfer *xfer); | |
| 237 | ||
| 238 | /** | |
| 239 | * Returns the local port number in the file transfer. | |
| 240 | * | |
| 241 | * @param xfer The file transfer. | |
| 242 | * | |
| 243 | * @return The port number on this end. | |
| 244 | */ | |
| 245 | unsigned int gaim_xfer_get_local_port(const struct gaim_xfer *xfer); | |
| 246 | ||
| 247 | /** | |
| 248 | * Returns the remote IP address in the file transfer. | |
| 249 | * | |
| 250 | * @param xfer The file transfer. | |
| 251 | * | |
| 252 | * @return The IP address on the other end. | |
| 253 | */ | |
| 254 | const char *gaim_xfer_get_remote_ip(const struct gaim_xfer *xfer); | |
| 255 | ||
| 256 | /** | |
| 257 | * Returns the remote port number in the file transfer. | |
| 258 | * | |
| 259 | * @param xfer The file transfer. | |
| 260 | * | |
| 261 | * @return The port number on the other end. | |
| 262 | */ | |
| 263 | unsigned int gaim_xfer_get_remote_port(const struct gaim_xfer *xfer); | |
| 264 | ||
| 265 | /** | |
| 4538 | 266 | * Sets the completed state for the file transfer. |
| 267 | * | |
| 268 | * @param xfer The file transfer. | |
| 269 | * @param completed The completed state. | |
| 270 | */ | |
| 271 | void gaim_xfer_set_completed(struct gaim_xfer *xfer, gboolean completed); | |
| 272 | ||
| 273 | /** | |
| 4514 | 274 | * Sets the filename for the file transfer. |
| 275 | * | |
| 276 | * @param xfer The file transfer. | |
| 277 | * @param filename The filename. | |
| 278 | */ | |
| 279 | void gaim_xfer_set_filename(struct gaim_xfer *xfer, const char *filename); | |
| 280 | ||
| 281 | /** | |
| 282 | * Sets the destination filename for the file transfer. | |
| 283 | * | |
| 284 | * @param xfer The file transfer. | |
| 285 | * @param filename The filename | |
| 286 | */ | |
| 287 | void gaim_xfer_set_dest_filename(struct gaim_xfer *xfer, const char *filename); | |
| 288 | ||
| 289 | /** | |
| 290 | * Sets the size of the file in a file transfer. | |
| 291 | * | |
| 292 | * @param xfer The file transfer. | |
| 293 | * @param size The size of the file. | |
| 294 | */ | |
| 295 | void gaim_xfer_set_size(struct gaim_xfer *xfer, size_t size); | |
| 296 | ||
| 297 | /** | |
| 298 | * Returns the UI operations structure for a file transfer. | |
| 299 | * | |
| 300 | * @param xfer The file transfer. | |
| 301 | * | |
| 302 | * @return The UI operations structure. | |
| 303 | */ | |
| 304 | struct gaim_xfer_ui_ops *gaim_xfer_get_ui_ops(const struct gaim_xfer *xfer); | |
| 305 | ||
| 306 | /** | |
| 307 | * Sets the read function for the file transfer. | |
| 308 | * | |
| 309 | * @param xfer The file transfer. | |
| 310 | * @param fnc The read function. | |
| 311 | */ | |
| 312 | void gaim_xfer_set_read_fnc(struct gaim_xfer *xfer, | |
|
4518
7ef89224fd04
[gaim-migrate @ 4796]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
313 | size_t (*fnc)(char **, struct gaim_xfer *)); |
| 4514 | 314 | |
| 315 | /** | |
| 316 | * Sets the write function for the file transfer. | |
| 317 | * | |
| 318 | * @param xfer The file transfer. | |
| 319 | * @param fnc The write function. | |
| 320 | */ | |
| 321 | void gaim_xfer_set_write_fnc(struct gaim_xfer *xfer, | |
|
4518
7ef89224fd04
[gaim-migrate @ 4796]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
322 | size_t (*fnc)(const char *, size_t, struct gaim_xfer *)); |
| 4514 | 323 | |
| 324 | /** | |
| 325 | * Sets the acknowledge function for the file transfer. | |
| 326 | * | |
| 327 | * @param xfer The file transfer. | |
| 328 | * @param fnc The acknowledge function. | |
| 329 | */ | |
| 330 | void gaim_xfer_set_ack_fnc(struct gaim_xfer *xfer, | |
| 331 | void (*fnc)(struct gaim_xfer *)); | |
| 332 | ||
| 333 | /** | |
| 334 | * Sets the transfer initialization function for the file transfer. | |
| 335 | * | |
| 336 | * This function is required, and must call gaim_xfer_start() with | |
| 337 | * the necessary parameters. This will be called if the file transfer | |
| 338 | * is accepted by the user. | |
| 339 | * | |
| 340 | * @param xfer The file transfer. | |
| 341 | * @param fnc The transfer initialization function. | |
| 342 | */ | |
| 343 | void gaim_xfer_set_init_fnc(struct gaim_xfer *xfer, | |
| 344 | void (*fnc)(struct gaim_xfer *)); | |
| 345 | ||
| 346 | /** | |
| 347 | * Sets the start transfer function for the file transfer. | |
| 348 | * | |
| 349 | * @param xfer The file transfer. | |
| 350 | * @param fnc The start transfer function. | |
| 351 | */ | |
| 352 | void gaim_xfer_set_start_fnc(struct gaim_xfer *xfer, | |
| 353 | void (*fnc)(struct gaim_xfer *)); | |
| 354 | ||
| 355 | /** | |
| 356 | * Sets the end transfer function for the file transfer. | |
| 357 | * | |
| 358 | * @param xfer The file transfer. | |
| 359 | * @param fnc The end transfer function. | |
| 360 | */ | |
| 361 | void gaim_xfer_set_end_fnc(struct gaim_xfer *xfer, | |
| 362 | void (*fnc)(struct gaim_xfer *)); | |
| 363 | ||
| 364 | /** | |
| 365 | * Sets the cancel transfer function for the file transfer. | |
| 366 | * | |
| 367 | * @param xfer The file transfer. | |
| 368 | * @param fnc The cancel transfer function. | |
| 369 | */ | |
| 370 | void gaim_xfer_set_cancel_fnc(struct gaim_xfer *xfer, | |
| 371 | void (*fnc)(struct gaim_xfer *)); | |
| 372 | ||
| 373 | /** | |
| 374 | * Reads in data from a file transfer stream. | |
| 375 | * | |
| 376 | * @param xfer The file transfer. | |
| 377 | * @param buffer The buffer that will be created to contain the data. | |
| 378 | * | |
| 379 | * @return The number of bytes read. | |
| 380 | */ | |
| 381 | size_t gaim_xfer_read(struct gaim_xfer *xfer, char **buffer); | |
| 382 | ||
| 383 | /** | |
| 384 | * Writes data to a file transfer stream. | |
| 385 | * | |
| 386 | * @param xfer The file transfer. | |
| 387 | * @param buffer The buffer to read the data from. | |
| 388 | * @param size The number of bytes to write. | |
| 389 | * | |
| 390 | * @return The number of bytes written. | |
| 391 | */ | |
| 392 | size_t gaim_xfer_write(struct gaim_xfer *xfer, const char *buffer, | |
| 393 | size_t size); | |
| 394 | ||
| 395 | /** | |
| 396 | * Starts a file transfer. | |
| 397 | * | |
| 398 | * Either @a fd must be specified <i>or</i> @a ip and @a port on a | |
| 399 | * file receive transfer. On send, @a fd must be specified, and | |
| 400 | * @a ip and @a port are ignored. | |
| 401 | * | |
| 402 | * @param xfer The file transfer. | |
| 403 | * @param fd The file descriptor for the socket. | |
| 404 | * @param ip The IP address to connect to. | |
| 405 | * @param port The port to connect to. | |
| 406 | */ | |
| 407 | void gaim_xfer_start(struct gaim_xfer *xfer, int fd, const char *ip, | |
| 408 | unsigned int port); | |
| 409 | ||
| 410 | /** | |
| 411 | * Ends a file transfer. | |
| 412 | * | |
| 413 | * @param xfer The file transfer. | |
| 414 | */ | |
| 415 | void gaim_xfer_end(struct gaim_xfer *xfer); | |
| 416 | ||
| 417 | /** | |
| 418 | * Cancels a file transfer. | |
| 419 | * | |
| 420 | * @param xfer The file transfer. | |
| 421 | */ | |
| 422 | void gaim_xfer_cancel(struct gaim_xfer *xfer); | |
| 423 | ||
| 424 | /** | |
| 425 | * Displays a file transfer-related error message. | |
| 426 | * | |
| 427 | * This is a wrapper around do_error_dialog(), which automatically | |
| 428 | * specifies a title ("File transfer to <i>user</i> aborted" or | |
| 429 | * "File Transfer from <i>user</i> aborted"). | |
| 430 | * | |
| 431 | * @param type The type of file transfer. | |
| 432 | * @param who The user on the other end of the transfer. | |
| 433 | * @param msg The message to display. | |
| 434 | */ | |
| 435 | void gaim_xfer_error(GaimXferType type, const char *who, const char *msg); | |
| 436 | ||
| 437 | /*@}*/ | |
| 438 | ||
| 439 | /**************************************************************************/ | |
| 440 | /** @name UI Registration Functions */ | |
| 441 | /**************************************************************************/ | |
| 442 | /*@{*/ | |
| 443 | ||
| 444 | /** | |
| 445 | * Sets the UI operations structure to be used in all gaim file transfers. | |
| 446 | * | |
| 447 | * @param fnc The function. | |
| 448 | */ | |
| 449 | void gaim_set_xfer_ui_ops(struct gaim_xfer_ui_ops *ops); | |
| 450 | ||
| 451 | /** | |
| 452 | * Returns the UI operations structure to be used in all gaim file transfers. | |
| 453 | * | |
| 454 | * @return The UI operations structure. | |
| 455 | */ | |
| 456 | struct gaim_xfer_ui_ops *gaim_get_xfer_ui_ops(void); | |
| 457 | ||
| 458 | /*@}*/ | |
| 459 | ||
| 460 | #endif /* _GAIM_FT_H_ */ |