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