Mercurial > pidgin.yaz
annotate src/ft.c @ 9812:d56f24cc4dad
[gaim-migrate @ 10683]
See the changelog. This is a modified patch #1005629.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 22 Aug 2004 03:06:33 +0000 |
parents | ccf5a52730b9 |
children | 3fa121db91d0 |
rev | line source |
---|---|
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1 /** |
7820 | 2 * @file ft.c File Transfer API |
3609 | 3 * |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
4 * gaim |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
5 * |
8046 | 6 * Gaim is the legal property of its developers, whose names are too numerous |
7 * to list here. Please refer to the COPYRIGHT file distributed with this | |
8 * source distribution. | |
4538 | 9 * |
3609 | 10 * This program is free software; you can redistribute it and/or modify |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 * | |
24 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
25 #include "internal.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
26 #include "ft.h" |
8231
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
27 #include "network.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
28 #include "notify.h" |
6241
9ce44a7f9ae7
[gaim-migrate @ 6735]
Christian Hammond <chipx86@chipx86.com>
parents:
6240
diff
changeset
|
29 #include "prefs.h" |
3609 | 30 #include "proxy.h" |
9511 | 31 #include "request.h" |
32 #include "util.h" | |
5494
d557a53e35c5
[gaim-migrate @ 5890]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5436
diff
changeset
|
33 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
34 static GaimXferUiOps *xfer_ui_ops = NULL; |
3609 | 35 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
36 GaimXfer * |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
37 gaim_xfer_new(GaimAccount *account, GaimXferType type, const char *who) |
3609 | 38 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
39 GaimXfer *xfer; |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
40 GaimXferUiOps *ui_ops; |
3609 | 41 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
42 g_return_val_if_fail(type != GAIM_XFER_UNKNOWN, NULL); |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
43 g_return_val_if_fail(account != NULL, NULL); |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
44 g_return_val_if_fail(who != NULL, NULL); |
3609 | 45 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
46 xfer = g_new0(GaimXfer, 1); |
3609 | 47 |
7805 | 48 xfer->ref = 1; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
49 xfer->type = type; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
50 xfer->account = account; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
51 xfer->who = g_strdup(who); |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6482
diff
changeset
|
52 xfer->ui_ops = gaim_xfers_get_ui_ops(); |
3609 | 53 |
5169 | 54 ui_ops = gaim_xfer_get_ui_ops(xfer); |
55 | |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
56 if (ui_ops != NULL && ui_ops->new_xfer != NULL) |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
57 ui_ops->new_xfer(xfer); |
5169 | 58 |
3609 | 59 return xfer; |
60 } | |
61 | |
7805 | 62 static void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
63 gaim_xfer_destroy(GaimXfer *xfer) |
3609 | 64 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
65 GaimXferUiOps *ui_ops; |
4247
3ea14f99c35c
[gaim-migrate @ 4497]
Christian Hammond <chipx86@chipx86.com>
parents:
4245
diff
changeset
|
66 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
67 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
68 |
9512 | 69 /* Close the file browser, if it's open */ |
70 gaim_request_close_with_handle(xfer); | |
71 | |
7805 | 72 if (gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_STARTED) |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
73 gaim_xfer_cancel_local(xfer); |
3609 | 74 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
75 ui_ops = gaim_xfer_get_ui_ops(xfer); |
3609 | 76 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
77 if (ui_ops != NULL && ui_ops->destroy != NULL) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
78 ui_ops->destroy(xfer); |
3609 | 79 |
9789 | 80 g_free(xfer->who); |
81 g_free(xfer->filename); | |
82 g_free(xfer->remote_ip); | |
83 g_free(xfer->local_filename); | |
3609 | 84 |
85 g_free(xfer); | |
86 } | |
87 | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
88 void |
7805 | 89 gaim_xfer_ref(GaimXfer *xfer) |
90 { | |
91 g_return_if_fail(xfer != NULL); | |
92 | |
93 xfer->ref++; | |
94 } | |
95 | |
96 void | |
97 gaim_xfer_unref(GaimXfer *xfer) | |
98 { | |
99 g_return_if_fail(xfer != NULL); | |
100 | |
101 xfer->ref--; | |
102 | |
103 if (xfer->ref == 0) | |
104 gaim_xfer_destroy(xfer); | |
105 } | |
106 | |
9788 | 107 static void |
108 gaim_xfer_set_status(GaimXfer *xfer, GaimXferStatusType status) | |
109 { | |
110 g_return_if_fail(xfer != NULL); | |
111 | |
112 xfer->status = status; | |
113 } | |
114 | |
9796 | 115 static void gaim_xfer_show_file_error(GaimXfer *xfer, const char *filename) |
9785 | 116 { |
9789 | 117 gchar *msg = NULL; |
9796 | 118 GaimXferType xfer_type = gaim_xfer_get_type(xfer); |
9785 | 119 |
9796 | 120 switch(xfer_type) { |
121 case GAIM_XFER_SEND: | |
122 msg = g_strdup_printf(_("Error reading %s: \n%s.\n"), | |
123 filename, strerror(errno)); | |
9795 | 124 break; |
9796 | 125 case GAIM_XFER_RECEIVE: |
126 msg = g_strdup_printf(_("Error writing %s: \n%s.\n"), | |
127 filename, strerror(errno)); | |
9785 | 128 break; |
129 default: | |
9796 | 130 msg = g_strdup_printf(_("Error accessing %s: \n%s.\n"), |
131 filename, strerror(errno)); | |
9785 | 132 break; |
9796 | 133 } |
9785 | 134 |
9796 | 135 gaim_xfer_error(xfer_type, xfer->who, msg); |
136 g_free(msg); | |
9785 | 137 } |
138 | |
9511 | 139 static void |
140 gaim_xfer_choose_file_ok_cb(void *user_data, const char *filename) | |
141 { | |
142 GaimXfer *xfer; | |
143 struct stat st; | |
144 | |
145 xfer = (GaimXfer *)user_data; | |
146 | |
147 if (stat(filename, &st) != 0) { | |
148 /* File not found. */ | |
149 if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { | |
150 gaim_xfer_request_accepted(xfer, filename); | |
151 } | |
152 else { | |
9796 | 153 gaim_xfer_show_file_error(xfer, filename); |
9511 | 154 gaim_xfer_request_denied(xfer); |
155 } | |
156 } | |
157 else if ((gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) && | |
158 (st.st_size == 0)) { | |
159 | |
160 gaim_notify_error(NULL, NULL, | |
161 _("Cannot send a file of 0 bytes."), NULL); | |
162 | |
163 gaim_xfer_request_denied(xfer); | |
164 } | |
9785 | 165 else if ((gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) && |
166 S_ISDIR(st.st_mode)) { | |
167 /* | |
168 * XXX - Sending a directory should be valid for some protocols. | |
169 */ | |
170 gaim_notify_error(NULL, NULL, | |
171 _("Cannot send a directory."), NULL); | |
172 | |
173 gaim_xfer_request_denied(xfer); | |
174 } | |
175 else if ((gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) && | |
176 S_ISDIR(st.st_mode)) { | |
177 char *msg = g_strdup_printf( | |
178 _("%s is not a regular file. Cowardly refusing to overwrite it.\n"), filename); | |
179 gaim_notify_error(NULL, NULL, msg, NULL); | |
180 g_free(msg); | |
181 gaim_xfer_request_denied(xfer); | |
182 } | |
9511 | 183 else { |
9785 | 184 gaim_xfer_request_accepted(xfer, filename); |
9511 | 185 } |
186 | |
187 gaim_xfer_unref(xfer); | |
188 } | |
189 | |
190 static void | |
191 gaim_xfer_choose_file_cancel_cb(void *user_data, const char *filename) | |
192 { | |
193 GaimXfer *xfer = (GaimXfer *)user_data; | |
194 | |
9788 | 195 gaim_xfer_set_status(xfer, GAIM_XFER_STATUS_CANCEL_LOCAL); |
9511 | 196 gaim_xfer_request_denied(xfer); |
197 } | |
198 | |
199 static int | |
200 gaim_xfer_choose_file(GaimXfer *xfer) | |
201 { | |
202 gaim_request_file(xfer, NULL, gaim_xfer_get_filename(xfer), | |
203 (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE), | |
204 G_CALLBACK(gaim_xfer_choose_file_ok_cb), | |
205 G_CALLBACK(gaim_xfer_choose_file_cancel_cb), xfer); | |
206 | |
207 return 0; | |
208 } | |
209 | |
210 static int | |
211 cancel_recv_cb(GaimXfer *xfer) | |
212 { | |
9788 | 213 gaim_xfer_set_status(xfer, GAIM_XFER_STATUS_CANCEL_LOCAL); |
9511 | 214 gaim_xfer_request_denied(xfer); |
215 gaim_xfer_unref(xfer); | |
216 | |
217 return 0; | |
218 } | |
219 | |
220 static void | |
221 gaim_xfer_ask_recv(GaimXfer *xfer) | |
222 { | |
223 char *buf, *size_buf; | |
224 size_t size; | |
225 | |
226 /* If we have already accepted the request, ask the destination file | |
227 name directly */ | |
228 if (gaim_xfer_get_status(xfer) != GAIM_XFER_STATUS_ACCEPTED) { | |
229 size = gaim_xfer_get_size(xfer); | |
230 size_buf = gaim_str_size_to_units(size); | |
231 | |
232 buf = g_strdup_printf(_("%s wants to send you %s (%s)"), | |
233 xfer->who, gaim_xfer_get_filename(xfer), | |
234 size_buf); | |
235 g_free(size_buf); | |
236 | |
9512 | 237 gaim_request_accept_cancel(xfer, NULL, buf, NULL, 0, xfer, |
9511 | 238 G_CALLBACK(gaim_xfer_choose_file), |
239 G_CALLBACK(cancel_recv_cb)); | |
240 g_free(buf); | |
241 } else | |
242 gaim_xfer_choose_file(xfer); | |
243 } | |
244 | |
245 static int | |
246 ask_accept_ok(GaimXfer *xfer) | |
247 { | |
248 gaim_xfer_request_accepted(xfer, NULL); | |
249 | |
250 return 0; | |
251 } | |
252 | |
253 static int | |
254 ask_accept_cancel(GaimXfer *xfer) | |
255 { | |
256 gaim_xfer_request_denied(xfer); | |
257 gaim_xfer_unref(xfer); | |
258 | |
259 return 0; | |
260 } | |
261 | |
262 static void | |
263 gaim_xfer_ask_accept(GaimXfer *xfer) | |
264 { | |
265 char *buf, *buf2 = NULL; | |
266 | |
267 buf = g_strdup_printf(_("Accept file transfer request from %s?"), | |
268 xfer->who); | |
269 if (gaim_xfer_get_remote_ip(xfer) && | |
270 gaim_xfer_get_remote_port(xfer)) | |
271 buf2 = g_strdup_printf(_("A file is available for download from:\n" | |
272 "Remote host: %s\nRemote port: %d"), | |
273 gaim_xfer_get_remote_ip(xfer), | |
274 gaim_xfer_get_remote_port(xfer)); | |
9512 | 275 gaim_request_accept_cancel(xfer, NULL, buf, buf2, 0, xfer, |
9511 | 276 G_CALLBACK(ask_accept_ok), |
277 G_CALLBACK(ask_accept_cancel)); | |
278 g_free(buf); | |
279 g_free(buf2); | |
280 } | |
281 | |
7805 | 282 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
283 gaim_xfer_request(GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
284 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
285 g_return_if_fail(xfer != NULL); |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
286 g_return_if_fail(xfer->ops.init != NULL); |
3609 | 287 |
9511 | 288 gaim_xfer_ref(xfer); |
4247
3ea14f99c35c
[gaim-migrate @ 4497]
Christian Hammond <chipx86@chipx86.com>
parents:
4245
diff
changeset
|
289 |
9511 | 290 if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { |
291 if (gaim_xfer_get_filename(xfer) || | |
292 gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_ACCEPTED) | |
293 gaim_xfer_ask_recv(xfer); | |
294 else | |
295 gaim_xfer_ask_accept(xfer); | |
296 } else | |
297 gaim_xfer_choose_file(xfer); | |
3609 | 298 } |
299 | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
300 void |
7805 | 301 gaim_xfer_request_accepted(GaimXfer *xfer, const char *filename) |
3609 | 302 { |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
303 GaimXferType type; |
9785 | 304 struct stat st; |
3609 | 305 |
8585 | 306 if (xfer == NULL) |
307 return; | |
308 | |
309 type = gaim_xfer_get_type(xfer); | |
310 | |
311 if (!filename && type == GAIM_XFER_RECEIVE) { | |
312 xfer->status = GAIM_XFER_STATUS_ACCEPTED; | |
313 xfer->ops.init(xfer); | |
3609 | 314 return; |
4150 | 315 } |
3609 | 316 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
317 if (type == GAIM_XFER_SEND) { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
318 /* Check the filename. */ |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
319 if (g_strrstr(filename, "..")) { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
320 char *msg; |
3609 | 321 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
322 msg = g_strdup_printf(_("%s is not a valid filename.\n"), |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
323 filename); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
324 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
325 gaim_xfer_error(type, xfer->who, msg); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
326 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
327 g_free(msg); |
7805 | 328 gaim_xfer_unref(xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
329 return; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
330 } |
3609 | 331 |
9785 | 332 if (stat(filename, &st) == -1) { |
9796 | 333 gaim_xfer_show_file_error(xfer, filename); |
7805 | 334 gaim_xfer_unref(xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
335 return; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
336 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
337 |
4605 | 338 gaim_xfer_set_local_filename(xfer, filename); |
9785 | 339 gaim_xfer_set_size(xfer, st.st_size); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
340 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
341 else { |
9785 | 342 xfer->status = GAIM_XFER_STATUS_ACCEPTED; |
4605 | 343 gaim_xfer_set_local_filename(xfer, filename); |
3609 | 344 } |
4150 | 345 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
346 xfer->ops.init(xfer); |
9772 | 347 gaim_xfer_add(xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
348 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
349 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
350 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
351 gaim_xfer_request_denied(GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
352 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
353 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
354 |
7805 | 355 if (xfer->ops.request_denied != NULL) |
356 xfer->ops.request_denied(xfer); | |
5164 | 357 |
7805 | 358 gaim_xfer_unref(xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
359 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
360 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
361 GaimXferType |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
362 gaim_xfer_get_type(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
363 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
364 g_return_val_if_fail(xfer != NULL, GAIM_XFER_UNKNOWN); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
365 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
366 return xfer->type; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
367 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
368 |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5495
diff
changeset
|
369 GaimAccount * |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
370 gaim_xfer_get_account(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
371 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
372 g_return_val_if_fail(xfer != NULL, NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
373 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
374 return xfer->account; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
375 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
376 |
7805 | 377 GaimXferStatusType |
378 gaim_xfer_get_status(const GaimXfer *xfer) | |
379 { | |
380 g_return_val_if_fail(xfer != NULL, GAIM_XFER_STATUS_UNKNOWN); | |
381 | |
382 return xfer->status; | |
383 } | |
384 | |
385 gboolean | |
7738 | 386 gaim_xfer_is_canceled(const GaimXfer *xfer) |
387 { | |
388 g_return_val_if_fail(xfer != NULL, TRUE); | |
389 | |
7805 | 390 if ((gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_CANCEL_LOCAL) || |
391 (gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_CANCEL_REMOTE)) | |
392 return TRUE; | |
393 else | |
394 return FALSE; | |
7738 | 395 } |
396 | |
4539
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
397 gboolean |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
398 gaim_xfer_is_completed(const GaimXfer *xfer) |
4539
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
399 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
400 g_return_val_if_fail(xfer != NULL, TRUE); |
4539
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
401 |
7805 | 402 return (gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_DONE); |
4539
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
403 } |
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
404 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
405 const char * |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
406 gaim_xfer_get_filename(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
407 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
408 g_return_val_if_fail(xfer != NULL, NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
409 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
410 return xfer->filename; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
411 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
412 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
413 const char * |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
414 gaim_xfer_get_local_filename(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
415 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
416 g_return_val_if_fail(xfer != NULL, NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
417 |
4605 | 418 return xfer->local_filename; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
419 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
420 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
421 size_t |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
422 gaim_xfer_get_bytes_sent(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
423 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
424 g_return_val_if_fail(xfer != NULL, 0); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
425 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
426 return xfer->bytes_sent; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
427 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
428 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
429 size_t |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
430 gaim_xfer_get_bytes_remaining(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
431 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
432 g_return_val_if_fail(xfer != NULL, 0); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
433 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
434 return xfer->bytes_remaining; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
435 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
436 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
437 size_t |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
438 gaim_xfer_get_size(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
439 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
440 g_return_val_if_fail(xfer != NULL, 0); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
441 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
442 return xfer->size; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
443 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
444 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
445 double |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
446 gaim_xfer_get_progress(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
447 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
448 g_return_val_if_fail(xfer != NULL, 0.0); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
449 |
4517
a2b2cce63fb8
[gaim-migrate @ 4795]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
450 if (gaim_xfer_get_size(xfer) == 0) |
a2b2cce63fb8
[gaim-migrate @ 4795]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
451 return 0.0; |
a2b2cce63fb8
[gaim-migrate @ 4795]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
452 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
453 return ((double)gaim_xfer_get_bytes_sent(xfer) / |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
454 (double)gaim_xfer_get_size(xfer)); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
455 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
456 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
457 unsigned int |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
458 gaim_xfer_get_local_port(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
459 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
460 g_return_val_if_fail(xfer != NULL, -1); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
461 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
462 return xfer->local_port; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
463 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
464 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
465 const char * |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
466 gaim_xfer_get_remote_ip(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
467 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
468 g_return_val_if_fail(xfer != NULL, NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
469 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
470 return xfer->remote_ip; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
471 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
472 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
473 unsigned int |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
474 gaim_xfer_get_remote_port(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
475 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
476 g_return_val_if_fail(xfer != NULL, -1); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
477 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
478 return xfer->remote_port; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
479 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
480 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
481 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
482 gaim_xfer_set_completed(GaimXfer *xfer, gboolean completed) |
4538 | 483 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
484 GaimXferUiOps *ui_ops; |
4656 | 485 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
486 g_return_if_fail(xfer != NULL); |
4538 | 487 |
7805 | 488 if (completed == TRUE) |
489 gaim_xfer_set_status(xfer, GAIM_XFER_STATUS_DONE); | |
4656 | 490 |
491 ui_ops = gaim_xfer_get_ui_ops(xfer); | |
492 | |
493 if (ui_ops != NULL && ui_ops->update_progress != NULL) | |
494 ui_ops->update_progress(xfer, gaim_xfer_get_progress(xfer)); | |
4538 | 495 } |
496 | |
497 void | |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
498 gaim_xfer_set_filename(GaimXfer *xfer, const char *filename) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
499 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
500 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
501 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
502 if (xfer->filename != NULL) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
503 g_free(xfer->filename); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
504 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
505 xfer->filename = (filename == NULL ? NULL : g_strdup(filename)); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
506 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
507 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
508 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
509 gaim_xfer_set_local_filename(GaimXfer *xfer, const char *filename) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
510 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
511 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
512 |
4605 | 513 if (xfer->local_filename != NULL) |
514 g_free(xfer->local_filename); | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
515 |
4605 | 516 xfer->local_filename = (filename == NULL ? NULL : g_strdup(filename)); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
517 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
518 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
519 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
520 gaim_xfer_set_size(GaimXfer *xfer, size_t size) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
521 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
522 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
523 |
4540
d83c5b925a05
[gaim-migrate @ 4819]
Christian Hammond <chipx86@chipx86.com>
parents:
4539
diff
changeset
|
524 if (xfer->size == 0) |
4538 | 525 xfer->bytes_remaining = size - xfer->bytes_sent; |
526 | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
527 xfer->size = size; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
528 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
529 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
530 GaimXferUiOps * |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
531 gaim_xfer_get_ui_ops(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
532 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
533 g_return_val_if_fail(xfer != NULL, NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
534 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
535 return xfer->ui_ops; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
536 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
537 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
538 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
539 gaim_xfer_set_init_fnc(GaimXfer *xfer, void (*fnc)(GaimXfer *)) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
540 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
541 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
542 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
543 xfer->ops.init = fnc; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
544 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
545 |
7805 | 546 void gaim_xfer_set_request_denied_fnc(GaimXfer *xfer, void (*fnc)(GaimXfer *)) |
547 { | |
548 g_return_if_fail(xfer != NULL); | |
549 | |
550 xfer->ops.request_denied = fnc; | |
551 } | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
552 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
553 void |
8231
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
554 gaim_xfer_set_read_fnc(GaimXfer *xfer, ssize_t (*fnc)(char **, GaimXfer *)) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
555 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
556 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
557 |
5495
5b678994929b
[gaim-migrate @ 5891]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5494
diff
changeset
|
558 xfer->ops.read = fnc; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
559 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
560 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
561 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
562 gaim_xfer_set_write_fnc(GaimXfer *xfer, |
8231
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
563 ssize_t (*fnc)(const char *, size_t, GaimXfer *)) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
564 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
565 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
566 |
5495
5b678994929b
[gaim-migrate @ 5891]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5494
diff
changeset
|
567 xfer->ops.write = fnc; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
568 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
569 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
570 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
571 gaim_xfer_set_ack_fnc(GaimXfer *xfer, |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
572 void (*fnc)(GaimXfer *, const char *, size_t)) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
573 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
574 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
575 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
576 xfer->ops.ack = fnc; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
577 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
578 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
579 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
580 gaim_xfer_set_start_fnc(GaimXfer *xfer, void (*fnc)(GaimXfer *)) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
581 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
582 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
583 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
584 xfer->ops.start = fnc; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
585 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
586 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
587 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
588 gaim_xfer_set_end_fnc(GaimXfer *xfer, void (*fnc)(GaimXfer *)) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
589 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
590 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
591 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
592 xfer->ops.end = fnc; |
3609 | 593 } |
594 | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
595 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
596 gaim_xfer_set_cancel_send_fnc(GaimXfer *xfer, void (*fnc)(GaimXfer *)) |
3609 | 597 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
598 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
599 |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
600 xfer->ops.cancel_send = fnc; |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
601 } |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
602 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
603 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
604 gaim_xfer_set_cancel_recv_fnc(GaimXfer *xfer, void (*fnc)(GaimXfer *)) |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
605 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
606 g_return_if_fail(xfer != NULL); |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
607 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
608 xfer->ops.cancel_recv = fnc; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
609 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
610 |
8231
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
611 ssize_t |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
612 gaim_xfer_read(GaimXfer *xfer, char **buffer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
613 { |
8231
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
614 ssize_t s, r; |
3609 | 615 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
616 g_return_val_if_fail(xfer != NULL, 0); |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
617 g_return_val_if_fail(buffer != NULL, 0); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
618 |
4517
a2b2cce63fb8
[gaim-migrate @ 4795]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
619 if (gaim_xfer_get_size(xfer) == 0) |
a2b2cce63fb8
[gaim-migrate @ 4795]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
620 s = 4096; |
a2b2cce63fb8
[gaim-migrate @ 4795]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
621 else |
a2b2cce63fb8
[gaim-migrate @ 4795]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
622 s = MIN(gaim_xfer_get_bytes_remaining(xfer), 4096); |
3609 | 623 |
5495
5b678994929b
[gaim-migrate @ 5891]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5494
diff
changeset
|
624 if (xfer->ops.read != NULL) |
5b678994929b
[gaim-migrate @ 5891]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5494
diff
changeset
|
625 r = (xfer->ops.read)(buffer, xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
626 else { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
627 *buffer = g_malloc0(s); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
628 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
629 r = read(xfer->fd, *buffer, s); |
6482
16fcc379e484
[gaim-migrate @ 6996]
Christian Hammond <chipx86@chipx86.com>
parents:
6269
diff
changeset
|
630 if ((gaim_xfer_get_size(xfer) > 0) && |
4617 | 631 ((gaim_xfer_get_bytes_sent(xfer)+r) >= gaim_xfer_get_size(xfer))) |
4538 | 632 gaim_xfer_set_completed(xfer, TRUE); |
8316 | 633 else if(r <= 0) |
634 r = -1; | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
635 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
636 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
637 return r; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
638 } |
3609 | 639 |
8231
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
640 ssize_t |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
641 gaim_xfer_write(GaimXfer *xfer, const char *buffer, size_t size) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
642 { |
8231
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
643 ssize_t r, s; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
644 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
645 g_return_val_if_fail(xfer != NULL, 0); |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
646 g_return_val_if_fail(buffer != NULL, 0); |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
647 g_return_val_if_fail(size != 0, 0); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
648 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
649 s = MIN(gaim_xfer_get_bytes_remaining(xfer), size); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
650 |
8231
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
651 if (xfer->ops.write != NULL) { |
5495
5b678994929b
[gaim-migrate @ 5891]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5494
diff
changeset
|
652 r = (xfer->ops.write)(buffer, s, xfer); |
8231
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
653 } else { |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
654 r = write(xfer->fd, buffer, s); |
8231
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
655 if ((gaim_xfer_get_bytes_sent(xfer)+r) >= gaim_xfer_get_size(xfer)) |
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
656 gaim_xfer_set_completed(xfer, TRUE); |
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
657 } |
3609 | 658 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
659 return r; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
660 } |
3609 | 661 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
662 static void |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
663 transfer_cb(gpointer data, gint source, GaimInputCondition condition) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
664 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
665 GaimXferUiOps *ui_ops; |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
666 GaimXfer *xfer = (GaimXfer *)data; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
667 char *buffer = NULL; |
9798 | 668 ssize_t r = 0; |
3609 | 669 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
670 if (condition & GAIM_INPUT_READ) { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
671 r = gaim_xfer_read(xfer, &buffer); |
8316 | 672 if (r > 0) { |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
673 fwrite(buffer, 1, r, xfer->dest_fp); |
8316 | 674 } else if(r < 0) { |
675 gaim_xfer_cancel_remote(xfer); | |
676 return; | |
677 } | |
3609 | 678 } |
9798 | 679 |
680 if (condition & GAIM_INPUT_WRITE) { | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
681 size_t s = MIN(gaim_xfer_get_bytes_remaining(xfer), 4096); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
682 |
8351 | 683 /* this is so the prpl can keep the connection open |
684 if it needs to for some odd reason. */ | |
685 if (s == 0) { | |
9798 | 686 if (xfer->watcher) { |
8351 | 687 gaim_input_remove(xfer->watcher); |
688 xfer->watcher = 0; | |
689 } | |
690 return; | |
691 } | |
692 | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
693 buffer = g_malloc0(s); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
694 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
695 fread(buffer, 1, s, xfer->dest_fp); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
696 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
697 /* Write as much as we're allowed to. */ |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
698 r = gaim_xfer_write(xfer, buffer, s); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
699 |
8231
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
700 if (r == -1) { |
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
701 gaim_xfer_cancel_remote(xfer); |
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
702 g_free(buffer); |
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
703 return; |
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
704 } else if (r < s) { |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
705 /* We have to seek back in the file now. */ |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
706 fseek(xfer->dest_fp, r - s, SEEK_CUR); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
707 } |
3609 | 708 } |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
709 |
4540
d83c5b925a05
[gaim-migrate @ 4819]
Christian Hammond <chipx86@chipx86.com>
parents:
4539
diff
changeset
|
710 if (gaim_xfer_get_size(xfer) > 0) |
d83c5b925a05
[gaim-migrate @ 4819]
Christian Hammond <chipx86@chipx86.com>
parents:
4539
diff
changeset
|
711 xfer->bytes_remaining -= r; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
712 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
713 xfer->bytes_sent += r; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
714 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
715 if (xfer->ops.ack != NULL) |
4594 | 716 xfer->ops.ack(xfer, buffer, r); |
717 | |
718 g_free(buffer); | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
719 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
720 ui_ops = gaim_xfer_get_ui_ops(xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
721 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
722 if (ui_ops != NULL && ui_ops->update_progress != NULL) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
723 ui_ops->update_progress(xfer, gaim_xfer_get_progress(xfer)); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
724 |
4553
d03fcb3f4be2
[gaim-migrate @ 4833]
Christian Hammond <chipx86@chipx86.com>
parents:
4540
diff
changeset
|
725 if (gaim_xfer_is_completed(xfer)) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
726 gaim_xfer_end(xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
727 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
728 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
729 static void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
730 begin_transfer(GaimXfer *xfer, GaimInputCondition cond) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
731 { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
732 GaimXferType type = gaim_xfer_get_type(xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
733 |
4605 | 734 xfer->dest_fp = fopen(gaim_xfer_get_local_filename(xfer), |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
735 type == GAIM_XFER_RECEIVE ? "wb" : "rb"); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
736 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
737 if (xfer->dest_fp == NULL) { |
9796 | 738 gaim_xfer_show_file_error(xfer, gaim_xfer_get_local_filename(xfer)); |
9785 | 739 gaim_xfer_cancel_local(xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
740 return; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
741 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
742 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
743 xfer->watcher = gaim_input_add(xfer->fd, cond, transfer_cb, xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
744 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
745 if (xfer->ops.start != NULL) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
746 xfer->ops.start(xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
747 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
748 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
749 static void |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
750 connect_cb(gpointer data, gint source, GaimInputCondition condition) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
751 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
752 GaimXfer *xfer = (GaimXfer *)data; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
753 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
754 xfer->fd = source; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
755 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
756 begin_transfer(xfer, condition); |
3609 | 757 } |
758 | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
759 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
760 gaim_xfer_start(GaimXfer *xfer, int fd, const char *ip, |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
761 unsigned int port) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
762 { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
763 GaimInputCondition cond; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
764 GaimXferType type; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
765 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
766 g_return_if_fail(xfer != NULL); |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
767 g_return_if_fail(gaim_xfer_get_type(xfer) != GAIM_XFER_UNKNOWN); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
768 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
769 type = gaim_xfer_get_type(xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
770 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
771 xfer->bytes_remaining = gaim_xfer_get_size(xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
772 xfer->bytes_sent = 0; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
773 |
7805 | 774 gaim_xfer_set_status(xfer, GAIM_XFER_STATUS_STARTED); |
775 | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
776 if (type == GAIM_XFER_RECEIVE) { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
777 cond = GAIM_INPUT_READ; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
778 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
779 if (ip != NULL) { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
780 xfer->remote_ip = g_strdup(ip); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
781 xfer->remote_port = port; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
782 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
783 /* Establish a file descriptor. */ |
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
784 gaim_proxy_connect(xfer->account, xfer->remote_ip, |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
785 xfer->remote_port, connect_cb, xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
786 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
787 return; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
788 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
789 else { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
790 xfer->fd = fd; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
791 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
792 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
793 else { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
794 cond = GAIM_INPUT_WRITE; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
795 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
796 xfer->fd = fd; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
797 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
798 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
799 begin_transfer(xfer, cond); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
800 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
801 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
802 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
803 gaim_xfer_end(GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
804 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
805 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
806 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
807 /* See if we are actually trying to cancel this. */ |
7805 | 808 if (gaim_xfer_get_status(xfer) != GAIM_XFER_STATUS_DONE) { |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
809 gaim_xfer_cancel_local(xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
810 return; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
811 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
812 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
813 if (xfer->ops.end != NULL) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
814 xfer->ops.end(xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
815 |
4521
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
816 if (xfer->watcher != 0) { |
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
817 gaim_input_remove(xfer->watcher); |
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
818 xfer->watcher = 0; |
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
819 } |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
820 |
4521
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
821 if (xfer->fd != 0) |
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
822 close(xfer->fd); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
823 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
824 if (xfer->dest_fp != NULL) { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
825 fclose(xfer->dest_fp); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
826 xfer->dest_fp = NULL; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
827 } |
7805 | 828 |
829 gaim_xfer_unref(xfer); | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
830 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
831 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
832 void |
8585 | 833 gaim_xfer_add(GaimXfer *xfer) |
834 { | |
835 GaimXferUiOps *ui_ops; | |
836 | |
837 g_return_if_fail(xfer != NULL); | |
838 | |
839 ui_ops = gaim_xfer_get_ui_ops(xfer); | |
840 | |
841 if (ui_ops != NULL && ui_ops->add_xfer != NULL) | |
842 ui_ops->add_xfer(xfer); | |
843 } | |
844 | |
845 void | |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
846 gaim_xfer_cancel_local(GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
847 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
848 GaimXferUiOps *ui_ops; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
849 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
850 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
851 |
7805 | 852 gaim_xfer_set_status(xfer, GAIM_XFER_STATUS_CANCEL_LOCAL); |
7738 | 853 |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
854 if (gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
855 { |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
856 if (xfer->ops.cancel_send != NULL) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
857 xfer->ops.cancel_send(xfer); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
858 } |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
859 else |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
860 { |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
861 if (xfer->ops.cancel_recv != NULL) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
862 xfer->ops.cancel_recv(xfer); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
863 } |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
864 |
4521
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
865 if (xfer->watcher != 0) { |
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
866 gaim_input_remove(xfer->watcher); |
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
867 xfer->watcher = 0; |
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
868 } |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
869 |
4521
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
870 if (xfer->fd != 0) |
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
871 close(xfer->fd); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
872 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
873 if (xfer->dest_fp != NULL) { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
874 fclose(xfer->dest_fp); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
875 xfer->dest_fp = NULL; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
876 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
877 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
878 ui_ops = gaim_xfer_get_ui_ops(xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
879 |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
880 if (ui_ops != NULL && ui_ops->cancel_local != NULL) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
881 ui_ops->cancel_local(xfer); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
882 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
883 xfer->bytes_remaining = 0; |
7805 | 884 |
885 gaim_xfer_unref(xfer); | |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
886 } |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
887 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
888 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
889 gaim_xfer_cancel_remote(GaimXfer *xfer) |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
890 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
891 GaimXferUiOps *ui_ops; |
9771 | 892 gchar *msg; |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
893 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
894 g_return_if_fail(xfer != NULL); |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
895 |
9771 | 896 gaim_request_close_with_handle(xfer); |
897 | |
898 msg = g_strdup_printf(_("%s canceled the transfer of %s"), | |
9788 | 899 xfer->who, gaim_xfer_get_filename(xfer)); |
9771 | 900 gaim_xfer_error(gaim_xfer_get_type(xfer), xfer->who, msg); |
901 g_free(msg); | |
902 | |
7805 | 903 gaim_xfer_set_status(xfer, GAIM_XFER_STATUS_CANCEL_REMOTE); |
7738 | 904 |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
905 if (gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
906 { |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
907 if (xfer->ops.cancel_send != NULL) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
908 xfer->ops.cancel_send(xfer); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
909 } |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
910 else |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
911 { |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
912 if (xfer->ops.cancel_recv != NULL) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
913 xfer->ops.cancel_recv(xfer); |
7272
02f697df677b
[gaim-migrate @ 7849]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
914 } |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
915 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
916 if (xfer->watcher != 0) { |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
917 gaim_input_remove(xfer->watcher); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
918 xfer->watcher = 0; |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
919 } |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
920 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
921 if (xfer->fd != 0) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
922 close(xfer->fd); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
923 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
924 if (xfer->dest_fp != NULL) { |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
925 fclose(xfer->dest_fp); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
926 xfer->dest_fp = NULL; |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
927 } |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
928 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
929 ui_ops = gaim_xfer_get_ui_ops(xfer); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
930 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
931 if (ui_ops != NULL && ui_ops->cancel_remote != NULL) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
932 ui_ops->cancel_remote(xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
933 |
4528
f8fec48f0fde
[gaim-migrate @ 4806]
Christian Hammond <chipx86@chipx86.com>
parents:
4521
diff
changeset
|
934 xfer->bytes_remaining = 0; |
7805 | 935 |
936 gaim_xfer_unref(xfer); | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
937 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
938 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
939 void |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
940 gaim_xfer_error(GaimXferType type, const char *who, const char *msg) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
941 { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
942 char *title; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
943 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
944 g_return_if_fail(msg != NULL); |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
945 g_return_if_fail(type != GAIM_XFER_UNKNOWN); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
946 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
947 if (type == GAIM_XFER_SEND) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
948 title = g_strdup_printf(_("File transfer to %s aborted.\n"), who); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
949 else |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
950 title = g_strdup_printf(_("File transfer from %s aborted.\n"), who); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
951 |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5169
diff
changeset
|
952 gaim_notify_error(NULL, NULL, title, msg); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
953 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
954 g_free(title); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
955 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
956 |
8585 | 957 void |
958 gaim_xfer_update_progress(GaimXfer *xfer) | |
959 { | |
960 GaimXferUiOps *ui_ops; | |
961 | |
962 g_return_if_fail(xfer != NULL); | |
963 | |
964 ui_ops = gaim_xfer_get_ui_ops(xfer); | |
965 if (ui_ops != NULL && ui_ops->update_progress != NULL) | |
966 ui_ops->update_progress(xfer, gaim_xfer_get_progress(xfer)); | |
967 } | |
968 | |
969 | |
6263
3565ee7a5dd3
[gaim-migrate @ 6760]
Christian Hammond <chipx86@chipx86.com>
parents:
6242
diff
changeset
|
970 /************************************************************************** |
3565ee7a5dd3
[gaim-migrate @ 6760]
Christian Hammond <chipx86@chipx86.com>
parents:
6242
diff
changeset
|
971 * File Transfer Subsystem API |
3565ee7a5dd3
[gaim-migrate @ 6760]
Christian Hammond <chipx86@chipx86.com>
parents:
6242
diff
changeset
|
972 **************************************************************************/ |
6241
9ce44a7f9ae7
[gaim-migrate @ 6735]
Christian Hammond <chipx86@chipx86.com>
parents:
6240
diff
changeset
|
973 |
9ce44a7f9ae7
[gaim-migrate @ 6735]
Christian Hammond <chipx86@chipx86.com>
parents:
6240
diff
changeset
|
974 void |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6482
diff
changeset
|
975 gaim_xfers_set_ui_ops(GaimXferUiOps *ops) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
976 { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
977 xfer_ui_ops = ops; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
978 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
979 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
980 GaimXferUiOps * |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6482
diff
changeset
|
981 gaim_xfers_get_ui_ops(void) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
982 { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
983 return xfer_ui_ops; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
984 } |