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