Mercurial > pidgin
annotate src/ft.h @ 4703:e4dda06a3143
[gaim-migrate @ 5014]
Changed a bunch of the window titles from "Gaim - What this window is" to
"What this window is". It's better like this.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Tue, 11 Mar 2003 08:17:22 +0000 |
parents | 3145c5c45877 |
children | 4691c5936c01 |
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 /**************************************************************************/ | |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
29 struct gaim_xfer; |
4514 | 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); | |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
55 void (*cancel_local)(struct gaim_xfer *xfer); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
56 void (*cancel_remote)(struct gaim_xfer *xfer); |
4514 | 57 }; |
58 | |
59 /** | |
60 * A core representation of a file transfer. | |
61 */ | |
62 struct gaim_xfer | |
63 { | |
64 GaimXferType type; /**< The type of transfer. */ | |
65 | |
66 struct gaim_account *account; /**< The account. */ | |
67 | |
68 char *who; /**< The person on the other end of the | |
69 transfer. */ | |
70 | |
4605 | 71 char *filename; /**< The name sent over the network. */ |
72 char *local_filename; /**< The name on the local hard drive. */ | |
4514 | 73 size_t size; /**< The size of the file. */ |
74 | |
75 FILE *dest_fp; /**< The destination file pointer. */ | |
76 | |
77 char *local_ip; /**< The local IP address. */ | |
78 char *remote_ip; /**< The remote IP address. */ | |
79 int local_port; /**< The local port. */ | |
80 int remote_port; /**< The remote port. */ | |
81 | |
82 int fd; /**< The socket file descriptor. */ | |
83 int watcher; /**< Watcher. */ | |
84 | |
85 size_t bytes_sent; /**< The number of bytes sent. */ | |
86 size_t bytes_remaining; /**< The number of bytes remaining. */ | |
87 | |
4538 | 88 gboolean completed; /**< File Transfer is completed. */ |
89 | |
4514 | 90 /* I/O operations. */ |
91 struct | |
92 { | |
93 void (*init)(struct gaim_xfer *xfer); | |
94 void (*start)(struct gaim_xfer *xfer); | |
95 void (*end)(struct gaim_xfer *xfer); | |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
96 void (*cancel_send)(struct gaim_xfer *xfer); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
97 void (*cancel_recv)(struct gaim_xfer *xfer); |
4518
a6be92358df3
[gaim-migrate @ 4796]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
98 size_t (*read)(char **buffer, struct gaim_xfer *xfer); |
4514 | 99 size_t (*write)(const char *buffer, size_t size, |
4518
a6be92358df3
[gaim-migrate @ 4796]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
100 struct gaim_xfer *xfer); |
4594 | 101 void (*ack)(struct gaim_xfer *xfer, const char *buffer, |
102 size_t size); | |
4514 | 103 |
104 } ops; | |
105 | |
106 struct gaim_xfer_ui_ops *ui_ops; /**< UI-specific operations. */ | |
107 void *ui_data; /**< UI-specific data. */ | |
108 | |
109 void *data; /**< prpl-specific data. */ | |
110 }; | |
111 | |
112 /**************************************************************************/ | |
113 /** @name File Transfer API */ | |
114 /**************************************************************************/ | |
115 /*@{*/ | |
116 | |
117 /** | |
118 * Creates a new file transfer handle. | |
119 * | |
120 * @param account The account sending or receiving the file. | |
121 * @param type The type of file transfer. | |
122 * @param who The name of the remote user. | |
123 * | |
124 * @return A file transfer handle. | |
125 */ | |
126 struct gaim_xfer *gaim_xfer_new(struct gaim_account *account, | |
127 GaimXferType type, const char *who); | |
128 | |
129 /** | |
130 * Destroys a file transfer handle. | |
131 * | |
132 * @param xfer The file transfer to destroy. | |
133 */ | |
134 void gaim_xfer_destroy(struct gaim_xfer *xfer); | |
135 | |
136 /** | |
137 * Requests confirmation for a file transfer from the user. | |
138 * | |
139 * @param xfer The file transfer to request confirmation on. | |
140 */ | |
141 void gaim_xfer_request(struct gaim_xfer *xfer); | |
142 | |
143 /** | |
144 * Called if the user accepts the file transfer request. | |
145 * | |
146 * @param xfer The file transfer. | |
147 * @param filename The filename. | |
148 */ | |
149 void gaim_xfer_request_accepted(struct gaim_xfer *xfer, char *filename); | |
150 | |
151 /** | |
152 * Called if the user rejects the file transfer request. | |
153 * | |
154 * @param xfer The file transfer. | |
155 */ | |
156 void gaim_xfer_request_denied(struct gaim_xfer *xfer); | |
157 | |
158 /** | |
159 * Returns the type of file transfer. | |
160 * | |
161 * @param xfer The file transfer. | |
162 * | |
163 * @return The type of the file transfer. | |
164 */ | |
165 GaimXferType gaim_xfer_get_type(const struct gaim_xfer *xfer); | |
166 | |
167 /** | |
168 * Returns the account the file transfer is using. | |
169 * | |
170 * @param xfer The file transfer. | |
171 * | |
172 * @return The account. | |
173 */ | |
174 struct gaim_account *gaim_xfer_get_account(const struct gaim_xfer *xfer); | |
175 | |
176 /** | |
4539
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
177 * Returns the completed state for a file transfer. |
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
178 * |
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
179 * @param xfer The file transfer. |
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
180 * |
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
181 * @return The completed state. |
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
182 */ |
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
183 gboolean gaim_xfer_is_completed(const struct gaim_xfer *xfer); |
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
184 |
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
185 /** |
4514 | 186 * Returns the name of the file being sent or received. |
187 * | |
188 * @param xfer The file transfer. | |
189 * | |
190 * @return The filename. | |
191 */ | |
192 const char *gaim_xfer_get_filename(const struct gaim_xfer *xfer); | |
193 | |
194 /** | |
195 * Returns the file's destination filename, | |
196 * | |
197 * @param xfer The file transfer. | |
198 * | |
199 * @return The destination filename. | |
200 */ | |
4605 | 201 const char *gaim_xfer_get_local_filename(const struct gaim_xfer *xfer); |
4514 | 202 |
203 /** | |
204 * Returns the number of bytes sent so far. | |
205 * | |
206 * @param xfer The file transfer. | |
207 * | |
208 * @return The number of bytes sent. | |
209 */ | |
210 size_t gaim_xfer_get_bytes_sent(const struct gaim_xfer *xfer); | |
211 | |
212 /** | |
213 * Returns the number of bytes received so far. | |
214 * | |
215 * @param xfer The file transfer. | |
216 * | |
217 * @return The number of bytes received. | |
218 */ | |
219 size_t gaim_xfer_get_bytes_remaining(const struct gaim_xfer *xfer); | |
220 | |
221 /** | |
222 * Returns the size of the file being sent or received. | |
223 * | |
224 * @param xfer The file transfer. | |
225 * | |
226 * @return The total size of the file. | |
227 */ | |
228 size_t gaim_xfer_get_size(const struct gaim_xfer *xfer); | |
229 | |
230 /** | |
231 * Returns the current percentage of progress of the transfer. | |
232 * | |
233 * This is a number between 0 (0%) and 1 (100%). | |
234 * | |
235 * @param xfer The file transfer. | |
236 * | |
237 * @return The percentage complete. | |
238 */ | |
239 double gaim_xfer_get_progress(const struct gaim_xfer *xfer); | |
240 | |
241 /** | |
242 * Returns the local IP address in the file transfer. | |
243 * | |
244 * @param xfer The file transfer. | |
245 * | |
246 * @return The IP address on this end. | |
247 */ | |
248 const char *gaim_xfer_get_local_ip(const struct gaim_xfer *xfer); | |
249 | |
250 /** | |
251 * Returns the local port number in the file transfer. | |
252 * | |
253 * @param xfer The file transfer. | |
254 * | |
255 * @return The port number on this end. | |
256 */ | |
257 unsigned int gaim_xfer_get_local_port(const struct gaim_xfer *xfer); | |
258 | |
259 /** | |
260 * Returns the remote IP address in the file transfer. | |
261 * | |
262 * @param xfer The file transfer. | |
263 * | |
264 * @return The IP address on the other end. | |
265 */ | |
266 const char *gaim_xfer_get_remote_ip(const struct gaim_xfer *xfer); | |
267 | |
268 /** | |
269 * Returns the remote port number in the file transfer. | |
270 * | |
271 * @param xfer The file transfer. | |
272 * | |
273 * @return The port number on the other end. | |
274 */ | |
275 unsigned int gaim_xfer_get_remote_port(const struct gaim_xfer *xfer); | |
276 | |
277 /** | |
4538 | 278 * Sets the completed state for the file transfer. |
279 * | |
280 * @param xfer The file transfer. | |
281 * @param completed The completed state. | |
282 */ | |
283 void gaim_xfer_set_completed(struct gaim_xfer *xfer, gboolean completed); | |
284 | |
285 /** | |
4514 | 286 * Sets the filename for the file transfer. |
287 * | |
288 * @param xfer The file transfer. | |
289 * @param filename The filename. | |
290 */ | |
291 void gaim_xfer_set_filename(struct gaim_xfer *xfer, const char *filename); | |
292 | |
293 /** | |
4605 | 294 * Sets the local filename for the file transfer. |
4514 | 295 * |
296 * @param xfer The file transfer. | |
297 * @param filename The filename | |
298 */ | |
4605 | 299 void gaim_xfer_set_local_filename(struct gaim_xfer *xfer, const char *filename); |
4514 | 300 |
301 /** | |
302 * Sets the size of the file in a file transfer. | |
303 * | |
304 * @param xfer The file transfer. | |
305 * @param size The size of the file. | |
306 */ | |
307 void gaim_xfer_set_size(struct gaim_xfer *xfer, size_t size); | |
308 | |
309 /** | |
310 * Returns the UI operations structure for a file transfer. | |
311 * | |
312 * @param xfer The file transfer. | |
313 * | |
314 * @return The UI operations structure. | |
315 */ | |
316 struct gaim_xfer_ui_ops *gaim_xfer_get_ui_ops(const struct gaim_xfer *xfer); | |
317 | |
318 /** | |
319 * Sets the read function for the file transfer. | |
320 * | |
321 * @param xfer The file transfer. | |
322 * @param fnc The read function. | |
323 */ | |
324 void gaim_xfer_set_read_fnc(struct gaim_xfer *xfer, | |
4518
a6be92358df3
[gaim-migrate @ 4796]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
325 size_t (*fnc)(char **, struct gaim_xfer *)); |
4514 | 326 |
327 /** | |
328 * Sets the write function for the file transfer. | |
329 * | |
330 * @param xfer The file transfer. | |
331 * @param fnc The write function. | |
332 */ | |
333 void gaim_xfer_set_write_fnc(struct gaim_xfer *xfer, | |
4518
a6be92358df3
[gaim-migrate @ 4796]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
334 size_t (*fnc)(const char *, size_t, struct gaim_xfer *)); |
4514 | 335 |
336 /** | |
337 * Sets the acknowledge function for the file transfer. | |
338 * | |
339 * @param xfer The file transfer. | |
340 * @param fnc The acknowledge function. | |
341 */ | |
342 void gaim_xfer_set_ack_fnc(struct gaim_xfer *xfer, | |
4595 | 343 void (*fnc)(struct gaim_xfer *, const char *, size_t)); |
4514 | 344 |
345 /** | |
346 * Sets the transfer initialization function for the file transfer. | |
347 * | |
348 * This function is required, and must call gaim_xfer_start() with | |
349 * the necessary parameters. This will be called if the file transfer | |
350 * is accepted by the user. | |
351 * | |
352 * @param xfer The file transfer. | |
353 * @param fnc The transfer initialization function. | |
354 */ | |
355 void gaim_xfer_set_init_fnc(struct gaim_xfer *xfer, | |
356 void (*fnc)(struct gaim_xfer *)); | |
357 | |
358 /** | |
359 * Sets the start transfer function for the file transfer. | |
360 * | |
361 * @param xfer The file transfer. | |
362 * @param fnc The start transfer function. | |
363 */ | |
364 void gaim_xfer_set_start_fnc(struct gaim_xfer *xfer, | |
365 void (*fnc)(struct gaim_xfer *)); | |
366 | |
367 /** | |
368 * Sets the end transfer function for the file transfer. | |
369 * | |
370 * @param xfer The file transfer. | |
371 * @param fnc The end transfer function. | |
372 */ | |
373 void gaim_xfer_set_end_fnc(struct gaim_xfer *xfer, | |
374 void (*fnc)(struct gaim_xfer *)); | |
375 | |
376 /** | |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
377 * Sets the cancel send function for the file transfer. |
4514 | 378 * |
379 * @param xfer The file transfer. | |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
380 * @param fnc The cancel send function. |
4514 | 381 */ |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
382 void gaim_xfer_set_cancel_send_fnc(struct gaim_xfer *xfer, |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
383 void (*fnc)(struct gaim_xfer *)); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
384 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
385 /** |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
386 * Sets the cancel receive function for the file transfer. |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
387 * |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
388 * @param xfer The file transfer. |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
389 * @param fnc The cancel receive function. |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
390 */ |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
391 void gaim_xfer_set_cancel_recv_fnc(struct gaim_xfer *xfer, |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
392 void (*fnc)(struct gaim_xfer *)); |
4514 | 393 |
394 /** | |
395 * Reads in data from a file transfer stream. | |
396 * | |
397 * @param xfer The file transfer. | |
398 * @param buffer The buffer that will be created to contain the data. | |
399 * | |
400 * @return The number of bytes read. | |
401 */ | |
402 size_t gaim_xfer_read(struct gaim_xfer *xfer, char **buffer); | |
403 | |
404 /** | |
405 * Writes data to a file transfer stream. | |
406 * | |
407 * @param xfer The file transfer. | |
408 * @param buffer The buffer to read the data from. | |
409 * @param size The number of bytes to write. | |
410 * | |
411 * @return The number of bytes written. | |
412 */ | |
413 size_t gaim_xfer_write(struct gaim_xfer *xfer, const char *buffer, | |
414 size_t size); | |
415 | |
416 /** | |
417 * Starts a file transfer. | |
418 * | |
419 * Either @a fd must be specified <i>or</i> @a ip and @a port on a | |
420 * file receive transfer. On send, @a fd must be specified, and | |
421 * @a ip and @a port are ignored. | |
422 * | |
423 * @param xfer The file transfer. | |
424 * @param fd The file descriptor for the socket. | |
425 * @param ip The IP address to connect to. | |
426 * @param port The port to connect to. | |
427 */ | |
428 void gaim_xfer_start(struct gaim_xfer *xfer, int fd, const char *ip, | |
429 unsigned int port); | |
430 | |
431 /** | |
432 * Ends a file transfer. | |
433 * | |
434 * @param xfer The file transfer. | |
435 */ | |
436 void gaim_xfer_end(struct gaim_xfer *xfer); | |
437 | |
438 /** | |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
439 * Cancels a file transfer on the local end. |
4514 | 440 * |
441 * @param xfer The file transfer. | |
442 */ | |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
443 void gaim_xfer_cancel_local(struct gaim_xfer *xfer); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
444 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
445 /** |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
446 * Cancels a file transfer from the remote end. |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
447 * |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
448 * @param xfer The file transfer. |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
449 */ |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4605
diff
changeset
|
450 void gaim_xfer_cancel_remote(struct gaim_xfer *xfer); |
4514 | 451 |
452 /** | |
453 * Displays a file transfer-related error message. | |
454 * | |
455 * This is a wrapper around do_error_dialog(), which automatically | |
456 * specifies a title ("File transfer to <i>user</i> aborted" or | |
457 * "File Transfer from <i>user</i> aborted"). | |
458 * | |
459 * @param type The type of file transfer. | |
460 * @param who The user on the other end of the transfer. | |
461 * @param msg The message to display. | |
462 */ | |
463 void gaim_xfer_error(GaimXferType type, const char *who, const char *msg); | |
464 | |
465 /*@}*/ | |
466 | |
467 /**************************************************************************/ | |
468 /** @name UI Registration Functions */ | |
469 /**************************************************************************/ | |
470 /*@{*/ | |
471 | |
472 /** | |
473 * Sets the UI operations structure to be used in all gaim file transfers. | |
474 * | |
475 * @param fnc The function. | |
476 */ | |
477 void gaim_set_xfer_ui_ops(struct gaim_xfer_ui_ops *ops); | |
478 | |
479 /** | |
480 * Returns the UI operations structure to be used in all gaim file transfers. | |
481 * | |
482 * @return The UI operations structure. | |
483 */ | |
484 struct gaim_xfer_ui_ops *gaim_get_xfer_ui_ops(void); | |
485 | |
486 /*@}*/ | |
487 | |
488 #endif /* _GAIM_FT_H_ */ |