Sun, 02 Mar 2003 19:21:36 +0000
[gaim-migrate @ 4942]
remove deprecated gtk calls, gtk2-ify log viewer, gtk2-ify jabber vcard
dialog, and probably a cleanup or two I forgot about.
| 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 | ||
|
4605
67526771e679
[gaim-migrate @ 4892]
Mark Doliner <markdoliner@pidgin.im>
parents:
4595
diff
changeset
|
70 | char *filename; /**< The name sent over the network. */ |
|
67526771e679
[gaim-migrate @ 4892]
Mark Doliner <markdoliner@pidgin.im>
parents:
4595
diff
changeset
|
71 | char *local_filename; /**< The name on the local hard drive. */ |
| 4514 | 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); |
|
4594
a96954344300
[gaim-migrate @ 4879]
Mark Doliner <markdoliner@pidgin.im>
parents:
4539
diff
changeset
|
99 | void (*ack)(struct gaim_xfer *xfer, const char *buffer, |
|
a96954344300
[gaim-migrate @ 4879]
Mark Doliner <markdoliner@pidgin.im>
parents:
4539
diff
changeset
|
100 | size_t size); |
| 4514 | 101 | |
| 102 | } ops; | |
| 103 | ||
| 104 | struct gaim_xfer_ui_ops *ui_ops; /**< UI-specific operations. */ | |
| 105 | void *ui_data; /**< UI-specific data. */ | |
| 106 | ||
| 107 | void *data; /**< prpl-specific data. */ | |
| 108 | }; | |
| 109 | ||
| 110 | /**************************************************************************/ | |
| 111 | /** @name File Transfer API */ | |
| 112 | /**************************************************************************/ | |
| 113 | /*@{*/ | |
| 114 | ||
| 115 | /** | |
| 116 | * Creates a new file transfer handle. | |
| 117 | * | |
| 118 | * @param account The account sending or receiving the file. | |
| 119 | * @param type The type of file transfer. | |
| 120 | * @param who The name of the remote user. | |
| 121 | * | |
| 122 | * @return A file transfer handle. | |
| 123 | */ | |
| 124 | struct gaim_xfer *gaim_xfer_new(struct gaim_account *account, | |
| 125 | GaimXferType type, const char *who); | |
| 126 | ||
| 127 | /** | |
| 128 | * Destroys a file transfer handle. | |
| 129 | * | |
| 130 | * @param xfer The file transfer to destroy. | |
| 131 | */ | |
| 132 | void gaim_xfer_destroy(struct gaim_xfer *xfer); | |
| 133 | ||
| 134 | /** | |
| 135 | * Requests confirmation for a file transfer from the user. | |
| 136 | * | |
| 137 | * @param xfer The file transfer to request confirmation on. | |
| 138 | */ | |
| 139 | void gaim_xfer_request(struct gaim_xfer *xfer); | |
| 140 | ||
| 141 | /** | |
| 142 | * Called if the user accepts the file transfer request. | |
| 143 | * | |
| 144 | * @param xfer The file transfer. | |
| 145 | * @param filename The filename. | |
| 146 | */ | |
| 147 | void gaim_xfer_request_accepted(struct gaim_xfer *xfer, char *filename); | |
| 148 | ||
| 149 | /** | |
| 150 | * Called if the user rejects the file transfer request. | |
| 151 | * | |
| 152 | * @param xfer The file transfer. | |
| 153 | */ | |
| 154 | void gaim_xfer_request_denied(struct gaim_xfer *xfer); | |
| 155 | ||
| 156 | /** | |
| 157 | * Returns the type of file transfer. | |
| 158 | * | |
| 159 | * @param xfer The file transfer. | |
| 160 | * | |
| 161 | * @return The type of the file transfer. | |
| 162 | */ | |
| 163 | GaimXferType gaim_xfer_get_type(const struct gaim_xfer *xfer); | |
| 164 | ||
| 165 | /** | |
| 166 | * Returns the account the file transfer is using. | |
| 167 | * | |
| 168 | * @param xfer The file transfer. | |
| 169 | * | |
| 170 | * @return The account. | |
| 171 | */ | |
| 172 | struct gaim_account *gaim_xfer_get_account(const struct gaim_xfer *xfer); | |
| 173 | ||
| 174 | /** | |
|
4539
44671e1ce14e
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
175 | * Returns the completed state for a file transfer. |
|
44671e1ce14e
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
176 | * |
|
44671e1ce14e
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
177 | * @param xfer The file transfer. |
|
44671e1ce14e
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
178 | * |
|
44671e1ce14e
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
179 | * @return The completed state. |
|
44671e1ce14e
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
180 | */ |
|
44671e1ce14e
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
181 | gboolean gaim_xfer_is_completed(const struct gaim_xfer *xfer); |
|
44671e1ce14e
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
182 | |
|
44671e1ce14e
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
183 | /** |
| 4514 | 184 | * Returns the name of the file being sent or received. |
| 185 | * | |
| 186 | * @param xfer The file transfer. | |
| 187 | * | |
| 188 | * @return The filename. | |
| 189 | */ | |
| 190 | const char *gaim_xfer_get_filename(const struct gaim_xfer *xfer); | |
| 191 | ||
| 192 | /** | |
| 193 | * Returns the file's destination filename, | |
| 194 | * | |
| 195 | * @param xfer The file transfer. | |
| 196 | * | |
| 197 | * @return The destination filename. | |
| 198 | */ | |
|
4605
67526771e679
[gaim-migrate @ 4892]
Mark Doliner <markdoliner@pidgin.im>
parents:
4595
diff
changeset
|
199 | const char *gaim_xfer_get_local_filename(const struct gaim_xfer *xfer); |
| 4514 | 200 | |
| 201 | /** | |
| 202 | * Returns the number of bytes sent so far. | |
| 203 | * | |
| 204 | * @param xfer The file transfer. | |
| 205 | * | |
| 206 | * @return The number of bytes sent. | |
| 207 | */ | |
| 208 | size_t gaim_xfer_get_bytes_sent(const struct gaim_xfer *xfer); | |
| 209 | ||
| 210 | /** | |
| 211 | * Returns the number of bytes received so far. | |
| 212 | * | |
| 213 | * @param xfer The file transfer. | |
| 214 | * | |
| 215 | * @return The number of bytes received. | |
| 216 | */ | |
| 217 | size_t gaim_xfer_get_bytes_remaining(const struct gaim_xfer *xfer); | |
| 218 | ||
| 219 | /** | |
| 220 | * Returns the size of the file being sent or received. | |
| 221 | * | |
| 222 | * @param xfer The file transfer. | |
| 223 | * | |
| 224 | * @return The total size of the file. | |
| 225 | */ | |
| 226 | size_t gaim_xfer_get_size(const struct gaim_xfer *xfer); | |
| 227 | ||
| 228 | /** | |
| 229 | * Returns the current percentage of progress of the transfer. | |
| 230 | * | |
| 231 | * This is a number between 0 (0%) and 1 (100%). | |
| 232 | * | |
| 233 | * @param xfer The file transfer. | |
| 234 | * | |
| 235 | * @return The percentage complete. | |
| 236 | */ | |
| 237 | double gaim_xfer_get_progress(const struct gaim_xfer *xfer); | |
| 238 | ||
| 239 | /** | |
| 240 | * Returns the local IP address in the file transfer. | |
| 241 | * | |
| 242 | * @param xfer The file transfer. | |
| 243 | * | |
| 244 | * @return The IP address on this end. | |
| 245 | */ | |
| 246 | const char *gaim_xfer_get_local_ip(const struct gaim_xfer *xfer); | |
| 247 | ||
| 248 | /** | |
| 249 | * Returns the local port number in the file transfer. | |
| 250 | * | |
| 251 | * @param xfer The file transfer. | |
| 252 | * | |
| 253 | * @return The port number on this end. | |
| 254 | */ | |
| 255 | unsigned int gaim_xfer_get_local_port(const struct gaim_xfer *xfer); | |
| 256 | ||
| 257 | /** | |
| 258 | * Returns the remote IP address in the file transfer. | |
| 259 | * | |
| 260 | * @param xfer The file transfer. | |
| 261 | * | |
| 262 | * @return The IP address on the other end. | |
| 263 | */ | |
| 264 | const char *gaim_xfer_get_remote_ip(const struct gaim_xfer *xfer); | |
| 265 | ||
| 266 | /** | |
| 267 | * Returns the remote port number in the file transfer. | |
| 268 | * | |
| 269 | * @param xfer The file transfer. | |
| 270 | * | |
| 271 | * @return The port number on the other end. | |
| 272 | */ | |
| 273 | unsigned int gaim_xfer_get_remote_port(const struct gaim_xfer *xfer); | |
| 274 | ||
| 275 | /** | |
| 4538 | 276 | * Sets the completed state for the file transfer. |
| 277 | * | |
| 278 | * @param xfer The file transfer. | |
| 279 | * @param completed The completed state. | |
| 280 | */ | |
| 281 | void gaim_xfer_set_completed(struct gaim_xfer *xfer, gboolean completed); | |
| 282 | ||
| 283 | /** | |
| 4514 | 284 | * Sets the filename for the file transfer. |
| 285 | * | |
| 286 | * @param xfer The file transfer. | |
| 287 | * @param filename The filename. | |
| 288 | */ | |
| 289 | void gaim_xfer_set_filename(struct gaim_xfer *xfer, const char *filename); | |
| 290 | ||
| 291 | /** | |
|
4605
67526771e679
[gaim-migrate @ 4892]
Mark Doliner <markdoliner@pidgin.im>
parents:
4595
diff
changeset
|
292 | * Sets the local filename for the file transfer. |
| 4514 | 293 | * |
| 294 | * @param xfer The file transfer. | |
| 295 | * @param filename The filename | |
| 296 | */ | |
|
4605
67526771e679
[gaim-migrate @ 4892]
Mark Doliner <markdoliner@pidgin.im>
parents:
4595
diff
changeset
|
297 | void gaim_xfer_set_local_filename(struct gaim_xfer *xfer, const char *filename); |
| 4514 | 298 | |
| 299 | /** | |
| 300 | * Sets the size of the file in a file transfer. | |
| 301 | * | |
| 302 | * @param xfer The file transfer. | |
| 303 | * @param size The size of the file. | |
| 304 | */ | |
| 305 | void gaim_xfer_set_size(struct gaim_xfer *xfer, size_t size); | |
| 306 | ||
| 307 | /** | |
| 308 | * Returns the UI operations structure for a file transfer. | |
| 309 | * | |
| 310 | * @param xfer The file transfer. | |
| 311 | * | |
| 312 | * @return The UI operations structure. | |
| 313 | */ | |
| 314 | struct gaim_xfer_ui_ops *gaim_xfer_get_ui_ops(const struct gaim_xfer *xfer); | |
| 315 | ||
| 316 | /** | |
| 317 | * Sets the read function for the file transfer. | |
| 318 | * | |
| 319 | * @param xfer The file transfer. | |
| 320 | * @param fnc The read function. | |
| 321 | */ | |
| 322 | void gaim_xfer_set_read_fnc(struct gaim_xfer *xfer, | |
|
4518
7ef89224fd04
[gaim-migrate @ 4796]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
323 | size_t (*fnc)(char **, struct gaim_xfer *)); |
| 4514 | 324 | |
| 325 | /** | |
| 326 | * Sets the write function for the file transfer. | |
| 327 | * | |
| 328 | * @param xfer The file transfer. | |
| 329 | * @param fnc The write function. | |
| 330 | */ | |
| 331 | void gaim_xfer_set_write_fnc(struct gaim_xfer *xfer, | |
|
4518
7ef89224fd04
[gaim-migrate @ 4796]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
332 | size_t (*fnc)(const char *, size_t, struct gaim_xfer *)); |
| 4514 | 333 | |
| 334 | /** | |
| 335 | * Sets the acknowledge function for the file transfer. | |
| 336 | * | |
| 337 | * @param xfer The file transfer. | |
| 338 | * @param fnc The acknowledge function. | |
| 339 | */ | |
| 340 | void gaim_xfer_set_ack_fnc(struct gaim_xfer *xfer, | |
|
4595
398fc487bf7b
[gaim-migrate @ 4880]
Mark Doliner <markdoliner@pidgin.im>
parents:
4594
diff
changeset
|
341 | void (*fnc)(struct gaim_xfer *, const char *, size_t)); |
| 4514 | 342 | |
| 343 | /** | |
| 344 | * Sets the transfer initialization function for the file transfer. | |
| 345 | * | |
| 346 | * This function is required, and must call gaim_xfer_start() with | |
| 347 | * the necessary parameters. This will be called if the file transfer | |
| 348 | * is accepted by the user. | |
| 349 | * | |
| 350 | * @param xfer The file transfer. | |
| 351 | * @param fnc The transfer initialization function. | |
| 352 | */ | |
| 353 | void gaim_xfer_set_init_fnc(struct gaim_xfer *xfer, | |
| 354 | void (*fnc)(struct gaim_xfer *)); | |
| 355 | ||
| 356 | /** | |
| 357 | * Sets the start transfer function for the file transfer. | |
| 358 | * | |
| 359 | * @param xfer The file transfer. | |
| 360 | * @param fnc The start transfer function. | |
| 361 | */ | |
| 362 | void gaim_xfer_set_start_fnc(struct gaim_xfer *xfer, | |
| 363 | void (*fnc)(struct gaim_xfer *)); | |
| 364 | ||
| 365 | /** | |
| 366 | * Sets the end transfer function for the file transfer. | |
| 367 | * | |
| 368 | * @param xfer The file transfer. | |
| 369 | * @param fnc The end transfer function. | |
| 370 | */ | |
| 371 | void gaim_xfer_set_end_fnc(struct gaim_xfer *xfer, | |
| 372 | void (*fnc)(struct gaim_xfer *)); | |
| 373 | ||
| 374 | /** | |
| 375 | * Sets the cancel transfer function for the file transfer. | |
| 376 | * | |
| 377 | * @param xfer The file transfer. | |
| 378 | * @param fnc The cancel transfer function. | |
| 379 | */ | |
| 380 | void gaim_xfer_set_cancel_fnc(struct gaim_xfer *xfer, | |
| 381 | void (*fnc)(struct gaim_xfer *)); | |
| 382 | ||
| 383 | /** | |
| 384 | * Reads in data from a file transfer stream. | |
| 385 | * | |
| 386 | * @param xfer The file transfer. | |
| 387 | * @param buffer The buffer that will be created to contain the data. | |
| 388 | * | |
| 389 | * @return The number of bytes read. | |
| 390 | */ | |
| 391 | size_t gaim_xfer_read(struct gaim_xfer *xfer, char **buffer); | |
| 392 | ||
| 393 | /** | |
| 394 | * Writes data to a file transfer stream. | |
| 395 | * | |
| 396 | * @param xfer The file transfer. | |
| 397 | * @param buffer The buffer to read the data from. | |
| 398 | * @param size The number of bytes to write. | |
| 399 | * | |
| 400 | * @return The number of bytes written. | |
| 401 | */ | |
| 402 | size_t gaim_xfer_write(struct gaim_xfer *xfer, const char *buffer, | |
| 403 | size_t size); | |
| 404 | ||
| 405 | /** | |
| 406 | * Starts a file transfer. | |
| 407 | * | |
| 408 | * Either @a fd must be specified <i>or</i> @a ip and @a port on a | |
| 409 | * file receive transfer. On send, @a fd must be specified, and | |
| 410 | * @a ip and @a port are ignored. | |
| 411 | * | |
| 412 | * @param xfer The file transfer. | |
| 413 | * @param fd The file descriptor for the socket. | |
| 414 | * @param ip The IP address to connect to. | |
| 415 | * @param port The port to connect to. | |
| 416 | */ | |
| 417 | void gaim_xfer_start(struct gaim_xfer *xfer, int fd, const char *ip, | |
| 418 | unsigned int port); | |
| 419 | ||
| 420 | /** | |
| 421 | * Ends a file transfer. | |
| 422 | * | |
| 423 | * @param xfer The file transfer. | |
| 424 | */ | |
| 425 | void gaim_xfer_end(struct gaim_xfer *xfer); | |
| 426 | ||
| 427 | /** | |
| 428 | * Cancels a file transfer. | |
| 429 | * | |
| 430 | * @param xfer The file transfer. | |
| 431 | */ | |
| 432 | void gaim_xfer_cancel(struct gaim_xfer *xfer); | |
| 433 | ||
| 434 | /** | |
| 435 | * Displays a file transfer-related error message. | |
| 436 | * | |
| 437 | * This is a wrapper around do_error_dialog(), which automatically | |
| 438 | * specifies a title ("File transfer to <i>user</i> aborted" or | |
| 439 | * "File Transfer from <i>user</i> aborted"). | |
| 440 | * | |
| 441 | * @param type The type of file transfer. | |
| 442 | * @param who The user on the other end of the transfer. | |
| 443 | * @param msg The message to display. | |
| 444 | */ | |
| 445 | void gaim_xfer_error(GaimXferType type, const char *who, const char *msg); | |
| 446 | ||
| 447 | /*@}*/ | |
| 448 | ||
| 449 | /**************************************************************************/ | |
| 450 | /** @name UI Registration Functions */ | |
| 451 | /**************************************************************************/ | |
| 452 | /*@{*/ | |
| 453 | ||
| 454 | /** | |
| 455 | * Sets the UI operations structure to be used in all gaim file transfers. | |
| 456 | * | |
| 457 | * @param fnc The function. | |
| 458 | */ | |
| 459 | void gaim_set_xfer_ui_ops(struct gaim_xfer_ui_ops *ops); | |
| 460 | ||
| 461 | /** | |
| 462 | * Returns the UI operations structure to be used in all gaim file transfers. | |
| 463 | * | |
| 464 | * @return The UI operations structure. | |
| 465 | */ | |
| 466 | struct gaim_xfer_ui_ops *gaim_get_xfer_ui_ops(void); | |
| 467 | ||
| 468 | /*@}*/ | |
| 469 | ||
| 470 | #endif /* _GAIM_FT_H_ */ |