Mercurial > pidgin
annotate src/ft.c @ 12210:5ae6ab7846a5
[gaim-migrate @ 14512]
IRC users might want to be able to return from away, maybe?
Capital T's are in short supply; so we need to conserve them.
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Thu, 24 Nov 2005 13:00:13 +0000 |
parents | de798f2f4bf1 |
children | 5e2a365af01b |
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(); |
9933 | 53 xfer->message = NULL; |
3609 | 54 |
5169 | 55 ui_ops = gaim_xfer_get_ui_ops(xfer); |
56 | |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
57 if (ui_ops != NULL && ui_ops->new_xfer != NULL) |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
58 ui_ops->new_xfer(xfer); |
5169 | 59 |
3609 | 60 return xfer; |
61 } | |
62 | |
7805 | 63 static void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
64 gaim_xfer_destroy(GaimXfer *xfer) |
3609 | 65 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
66 GaimXferUiOps *ui_ops; |
4247
3ea14f99c35c
[gaim-migrate @ 4497]
Christian Hammond <chipx86@chipx86.com>
parents:
4245
diff
changeset
|
67 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
68 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
69 |
9512 | 70 /* Close the file browser, if it's open */ |
71 gaim_request_close_with_handle(xfer); | |
72 | |
7805 | 73 if (gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_STARTED) |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
74 gaim_xfer_cancel_local(xfer); |
3609 | 75 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
76 ui_ops = gaim_xfer_get_ui_ops(xfer); |
3609 | 77 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
78 if (ui_ops != NULL && ui_ops->destroy != NULL) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
79 ui_ops->destroy(xfer); |
3609 | 80 |
9789 | 81 g_free(xfer->who); |
82 g_free(xfer->filename); | |
83 g_free(xfer->remote_ip); | |
84 g_free(xfer->local_filename); | |
3609 | 85 |
86 g_free(xfer); | |
87 } | |
88 | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
89 void |
7805 | 90 gaim_xfer_ref(GaimXfer *xfer) |
91 { | |
92 g_return_if_fail(xfer != NULL); | |
93 | |
94 xfer->ref++; | |
95 } | |
96 | |
97 void | |
98 gaim_xfer_unref(GaimXfer *xfer) | |
99 { | |
100 g_return_if_fail(xfer != NULL); | |
101 | |
102 xfer->ref--; | |
103 | |
104 if (xfer->ref == 0) | |
105 gaim_xfer_destroy(xfer); | |
106 } | |
107 | |
9788 | 108 static void |
109 gaim_xfer_set_status(GaimXfer *xfer, GaimXferStatusType status) | |
110 { | |
111 g_return_if_fail(xfer != NULL); | |
112 | |
11281
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
113 if(xfer->type == GAIM_XFER_SEND) { |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
114 switch(status) { |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
115 case GAIM_XFER_STATUS_ACCEPTED: |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
116 gaim_signal_emit(gaim_xfers_get_handle(), "file-send-accept", xfer); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
117 break; |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
118 case GAIM_XFER_STATUS_STARTED: |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
119 gaim_signal_emit(gaim_xfers_get_handle(), "file-send-start", xfer); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
120 break; |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
121 case GAIM_XFER_STATUS_DONE: |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
122 gaim_signal_emit(gaim_xfers_get_handle(), "file-send-complete", xfer); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
123 break; |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
124 case GAIM_XFER_STATUS_CANCEL_LOCAL: |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
125 case GAIM_XFER_STATUS_CANCEL_REMOTE: |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
126 gaim_signal_emit(gaim_xfers_get_handle(), "file-send-cancel", xfer); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
127 break; |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
128 default: |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
129 break; |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
130 } |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
131 } else if(xfer->type == GAIM_XFER_RECEIVE) { |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
132 switch(status) { |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
133 case GAIM_XFER_STATUS_ACCEPTED: |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
134 gaim_signal_emit(gaim_xfers_get_handle(), "file-recv-accept", xfer); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
135 break; |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
136 case GAIM_XFER_STATUS_STARTED: |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
137 gaim_signal_emit(gaim_xfers_get_handle(), "file-recv-start", xfer); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
138 break; |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
139 case GAIM_XFER_STATUS_DONE: |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
140 gaim_signal_emit(gaim_xfers_get_handle(), "file-recv-complete", xfer); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
141 break; |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
142 case GAIM_XFER_STATUS_CANCEL_LOCAL: |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
143 case GAIM_XFER_STATUS_CANCEL_REMOTE: |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
144 gaim_signal_emit(gaim_xfers_get_handle(), "file-recv-cancel", xfer); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
145 break; |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
146 default: |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
147 break; |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
148 } |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
149 } |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
150 |
9788 | 151 xfer->status = status; |
152 } | |
153 | |
11084 | 154 void gaim_xfer_conversation_write(GaimXfer *xfer, char *message, gboolean is_error) |
9932 | 155 { |
156 GaimConversation *conv = NULL; | |
157 GaimMessageFlags flags = GAIM_MESSAGE_SYSTEM; | |
10774 | 158 char *escaped; |
9932 | 159 |
160 g_return_if_fail(xfer != NULL); | |
161 g_return_if_fail(message != NULL); | |
162 | |
11338 | 163 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, xfer->who, |
10246 | 164 gaim_xfer_get_account(xfer)); |
9932 | 165 |
166 if (conv == NULL) | |
167 return; | |
168 | |
10774 | 169 escaped = g_markup_escape_text(message, -1); |
9932 | 170 |
171 if (is_error) | |
172 flags = GAIM_MESSAGE_ERROR; | |
173 | |
10774 | 174 gaim_conversation_write(conv, NULL, escaped, flags, time(NULL)); |
175 g_free(escaped); | |
9932 | 176 } |
177 | |
9796 | 178 static void gaim_xfer_show_file_error(GaimXfer *xfer, const char *filename) |
9785 | 179 { |
10919 | 180 int err = errno; |
181 gchar *msg = NULL, *utf8; | |
9796 | 182 GaimXferType xfer_type = gaim_xfer_get_type(xfer); |
10654 | 183 GaimAccount *account = gaim_xfer_get_account(xfer); |
9785 | 184 |
10919 | 185 utf8 = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); |
9796 | 186 switch(xfer_type) { |
187 case GAIM_XFER_SEND: | |
188 msg = g_strdup_printf(_("Error reading %s: \n%s.\n"), | |
10919 | 189 utf8, strerror(err)); |
9795 | 190 break; |
9796 | 191 case GAIM_XFER_RECEIVE: |
192 msg = g_strdup_printf(_("Error writing %s: \n%s.\n"), | |
10919 | 193 utf8, strerror(err)); |
9785 | 194 break; |
195 default: | |
9796 | 196 msg = g_strdup_printf(_("Error accessing %s: \n%s.\n"), |
10919 | 197 utf8, strerror(err)); |
9785 | 198 break; |
10919 | 199 } |
200 g_free(utf8); | |
9785 | 201 |
9932 | 202 gaim_xfer_conversation_write(xfer, msg, TRUE); |
10654 | 203 gaim_xfer_error(xfer_type, account, xfer->who, msg); |
9796 | 204 g_free(msg); |
9785 | 205 } |
206 | |
9511 | 207 static void |
208 gaim_xfer_choose_file_ok_cb(void *user_data, const char *filename) | |
209 { | |
210 GaimXfer *xfer; | |
211 struct stat st; | |
212 | |
213 xfer = (GaimXfer *)user_data; | |
214 | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10504
diff
changeset
|
215 if (g_stat(filename, &st) != 0) { |
9511 | 216 /* File not found. */ |
217 if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { | |
218 gaim_xfer_request_accepted(xfer, filename); | |
219 } | |
220 else { | |
9796 | 221 gaim_xfer_show_file_error(xfer, filename); |
9511 | 222 gaim_xfer_request_denied(xfer); |
223 } | |
224 } | |
225 else if ((gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) && | |
226 (st.st_size == 0)) { | |
227 | |
228 gaim_notify_error(NULL, NULL, | |
229 _("Cannot send a file of 0 bytes."), NULL); | |
230 | |
231 gaim_xfer_request_denied(xfer); | |
232 } | |
9785 | 233 else if ((gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) && |
234 S_ISDIR(st.st_mode)) { | |
235 /* | |
236 * XXX - Sending a directory should be valid for some protocols. | |
237 */ | |
238 gaim_notify_error(NULL, NULL, | |
239 _("Cannot send a directory."), NULL); | |
240 | |
241 gaim_xfer_request_denied(xfer); | |
242 } | |
243 else if ((gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) && | |
244 S_ISDIR(st.st_mode)) { | |
10919 | 245 char *msg, *utf8; |
246 utf8 = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); | |
247 msg = g_strdup_printf( | |
248 _("%s is not a regular file. Cowardly refusing to overwrite it.\n"), utf8); | |
249 g_free(utf8); | |
9785 | 250 gaim_notify_error(NULL, NULL, msg, NULL); |
251 g_free(msg); | |
252 gaim_xfer_request_denied(xfer); | |
253 } | |
9511 | 254 else { |
9785 | 255 gaim_xfer_request_accepted(xfer, filename); |
9511 | 256 } |
257 | |
258 gaim_xfer_unref(xfer); | |
259 } | |
260 | |
261 static void | |
262 gaim_xfer_choose_file_cancel_cb(void *user_data, const char *filename) | |
263 { | |
264 GaimXfer *xfer = (GaimXfer *)user_data; | |
265 | |
11159 | 266 gaim_xfer_set_status(xfer, GAIM_XFER_STATUS_CANCEL_LOCAL); |
9511 | 267 gaim_xfer_request_denied(xfer); |
268 } | |
269 | |
270 static int | |
271 gaim_xfer_choose_file(GaimXfer *xfer) | |
272 { | |
273 gaim_request_file(xfer, NULL, gaim_xfer_get_filename(xfer), | |
274 (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE), | |
275 G_CALLBACK(gaim_xfer_choose_file_ok_cb), | |
276 G_CALLBACK(gaim_xfer_choose_file_cancel_cb), xfer); | |
277 | |
278 return 0; | |
279 } | |
280 | |
281 static int | |
282 cancel_recv_cb(GaimXfer *xfer) | |
283 { | |
11159 | 284 gaim_xfer_set_status(xfer, GAIM_XFER_STATUS_CANCEL_LOCAL); |
9511 | 285 gaim_xfer_request_denied(xfer); |
286 gaim_xfer_unref(xfer); | |
287 | |
288 return 0; | |
289 } | |
290 | |
291 static void | |
292 gaim_xfer_ask_recv(GaimXfer *xfer) | |
293 { | |
10774 | 294 char *buf, *size_buf; |
9511 | 295 size_t size; |
296 | |
297 /* If we have already accepted the request, ask the destination file | |
298 name directly */ | |
299 if (gaim_xfer_get_status(xfer) != GAIM_XFER_STATUS_ACCEPTED) { | |
10654 | 300 GaimBuddy *buddy = gaim_find_buddy(xfer->account, xfer->who); |
301 | |
10470 | 302 if (gaim_xfer_get_filename(xfer) != NULL) |
303 { | |
304 size = gaim_xfer_get_size(xfer); | |
305 size_buf = gaim_str_size_to_units(size); | |
306 buf = g_strdup_printf(_("%s wants to send you %s (%s)"), | |
10654 | 307 buddy ? gaim_buddy_get_alias(buddy) : xfer->who, |
10774 | 308 gaim_xfer_get_filename(xfer), size_buf); |
10470 | 309 g_free(size_buf); |
310 } | |
311 else | |
312 { | |
10654 | 313 buf = g_strdup_printf(_("%s wants to send you a file"), |
314 buddy ? gaim_buddy_get_alias(buddy) : xfer->who); | |
10470 | 315 } |
9511 | 316 |
9933 | 317 if (xfer->message != NULL) |
318 serv_got_im(gaim_account_get_connection(xfer->account), | |
319 xfer->who, xfer->message, 0, time(NULL)); | |
320 | |
9976 | 321 gaim_request_accept_cancel(xfer, NULL, buf, NULL, |
322 GAIM_DEFAULT_ACTION_NONE, xfer, | |
323 G_CALLBACK(gaim_xfer_choose_file), | |
324 G_CALLBACK(cancel_recv_cb)); | |
9933 | 325 |
9511 | 326 g_free(buf); |
327 } else | |
328 gaim_xfer_choose_file(xfer); | |
329 } | |
330 | |
331 static int | |
332 ask_accept_ok(GaimXfer *xfer) | |
333 { | |
334 gaim_xfer_request_accepted(xfer, NULL); | |
335 | |
336 return 0; | |
337 } | |
338 | |
339 static int | |
340 ask_accept_cancel(GaimXfer *xfer) | |
341 { | |
342 gaim_xfer_request_denied(xfer); | |
343 gaim_xfer_unref(xfer); | |
344 | |
345 return 0; | |
346 } | |
347 | |
348 static void | |
349 gaim_xfer_ask_accept(GaimXfer *xfer) | |
350 { | |
351 char *buf, *buf2 = NULL; | |
10654 | 352 GaimBuddy *buddy = gaim_find_buddy(xfer->account, xfer->who); |
9511 | 353 |
354 buf = g_strdup_printf(_("Accept file transfer request from %s?"), | |
10654 | 355 buddy ? gaim_buddy_get_alias(buddy) : xfer->who); |
9511 | 356 if (gaim_xfer_get_remote_ip(xfer) && |
357 gaim_xfer_get_remote_port(xfer)) | |
358 buf2 = g_strdup_printf(_("A file is available for download from:\n" | |
359 "Remote host: %s\nRemote port: %d"), | |
360 gaim_xfer_get_remote_ip(xfer), | |
361 gaim_xfer_get_remote_port(xfer)); | |
9976 | 362 gaim_request_accept_cancel(xfer, NULL, buf, buf2, |
363 GAIM_DEFAULT_ACTION_NONE, xfer, | |
364 G_CALLBACK(ask_accept_ok), | |
365 G_CALLBACK(ask_accept_cancel)); | |
9511 | 366 g_free(buf); |
367 g_free(buf2); | |
368 } | |
369 | |
7805 | 370 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
371 gaim_xfer_request(GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
372 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
373 g_return_if_fail(xfer != NULL); |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
374 g_return_if_fail(xfer->ops.init != NULL); |
3609 | 375 |
9511 | 376 gaim_xfer_ref(xfer); |
4247
3ea14f99c35c
[gaim-migrate @ 4497]
Christian Hammond <chipx86@chipx86.com>
parents:
4245
diff
changeset
|
377 |
9511 | 378 if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { |
379 if (gaim_xfer_get_filename(xfer) || | |
11084 | 380 gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_ACCEPTED) { |
381 gchar* message = NULL; | |
382 message = g_strdup_printf(_("%s is offering to send file %s"), | |
383 xfer->who, gaim_xfer_get_filename(xfer)); | |
384 gaim_xfer_conversation_write(xfer, message, FALSE); | |
385 g_free(message); | |
9511 | 386 gaim_xfer_ask_recv(xfer); |
11084 | 387 } else { |
9511 | 388 gaim_xfer_ask_accept(xfer); |
11084 | 389 } |
9511 | 390 } else |
391 gaim_xfer_choose_file(xfer); | |
3609 | 392 } |
393 | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
394 void |
7805 | 395 gaim_xfer_request_accepted(GaimXfer *xfer, const char *filename) |
3609 | 396 { |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
397 GaimXferType type; |
9785 | 398 struct stat st; |
10919 | 399 char *msg, *utf8; |
10654 | 400 GaimAccount *account; |
401 GaimBuddy *buddy; | |
3609 | 402 |
8585 | 403 if (xfer == NULL) |
404 return; | |
405 | |
406 type = gaim_xfer_get_type(xfer); | |
10654 | 407 account = gaim_xfer_get_account(xfer); |
8585 | 408 |
409 if (!filename && type == GAIM_XFER_RECEIVE) { | |
410 xfer->status = GAIM_XFER_STATUS_ACCEPTED; | |
411 xfer->ops.init(xfer); | |
3609 | 412 return; |
4150 | 413 } |
3609 | 414 |
10654 | 415 buddy = gaim_find_buddy(account, xfer->who); |
416 | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
417 if (type == GAIM_XFER_SEND) { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
418 /* Check the filename. */ |
11934
525cf7ecd919
[gaim-migrate @ 14225]
Richard Laager <rlaager@wiktel.com>
parents:
11338
diff
changeset
|
419 #ifdef _WIN32 |
525cf7ecd919
[gaim-migrate @ 14225]
Richard Laager <rlaager@wiktel.com>
parents:
11338
diff
changeset
|
420 if (g_strrstr(filename, "../") || g_strrstr(filename, "..\\")) { |
525cf7ecd919
[gaim-migrate @ 14225]
Richard Laager <rlaager@wiktel.com>
parents:
11338
diff
changeset
|
421 #else |
525cf7ecd919
[gaim-migrate @ 14225]
Richard Laager <rlaager@wiktel.com>
parents:
11338
diff
changeset
|
422 if (g_strrstr(filename, "../")) { |
525cf7ecd919
[gaim-migrate @ 14225]
Richard Laager <rlaager@wiktel.com>
parents:
11338
diff
changeset
|
423 #endif |
10919 | 424 char *utf8 = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); |
3609 | 425 |
10919 | 426 msg = g_strdup_printf(_("%s is not a valid filename.\n"), utf8); |
10654 | 427 gaim_xfer_error(type, account, xfer->who, msg); |
10919 | 428 g_free(utf8); |
9932 | 429 g_free(msg); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
430 |
7805 | 431 gaim_xfer_unref(xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
432 return; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
433 } |
3609 | 434 |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10504
diff
changeset
|
435 if (g_stat(filename, &st) == -1) { |
11159 | 436 gaim_xfer_show_file_error(xfer, filename); |
7805 | 437 gaim_xfer_unref(xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
438 return; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
439 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
440 |
4605 | 441 gaim_xfer_set_local_filename(xfer, filename); |
9785 | 442 gaim_xfer_set_size(xfer, st.st_size); |
10134 | 443 |
10919 | 444 utf8 = g_filename_to_utf8(g_basename(filename), -1, NULL, NULL, NULL); |
445 gaim_xfer_set_filename(xfer, utf8); | |
446 | |
9932 | 447 msg = g_strdup_printf(_("Offering to send %s to %s"), |
10919 | 448 utf8, buddy ? gaim_buddy_get_alias(buddy) : xfer->who); |
449 g_free(utf8); | |
450 | |
9932 | 451 gaim_xfer_conversation_write(xfer, msg, FALSE); |
452 g_free(msg); | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
453 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
454 else { |
9785 | 455 xfer->status = GAIM_XFER_STATUS_ACCEPTED; |
4605 | 456 gaim_xfer_set_local_filename(xfer, filename); |
10654 | 457 |
458 msg = g_strdup_printf(_("Starting transfer of %s from %s"), | |
459 xfer->filename, buddy ? gaim_buddy_get_alias(buddy) : xfer->who); | |
460 gaim_xfer_conversation_write(xfer, msg, FALSE); | |
461 g_free(msg); | |
3609 | 462 } |
4150 | 463 |
10259 | 464 gaim_xfer_add(xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
465 xfer->ops.init(xfer); |
10259 | 466 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
467 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
468 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
469 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
470 gaim_xfer_request_denied(GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
471 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
472 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
473 |
7805 | 474 if (xfer->ops.request_denied != NULL) |
475 xfer->ops.request_denied(xfer); | |
5164 | 476 |
7805 | 477 gaim_xfer_unref(xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
478 } |
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 GaimXferType |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
481 gaim_xfer_get_type(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
482 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
483 g_return_val_if_fail(xfer != NULL, GAIM_XFER_UNKNOWN); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
484 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
485 return xfer->type; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
486 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
487 |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5495
diff
changeset
|
488 GaimAccount * |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
489 gaim_xfer_get_account(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
490 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
491 g_return_val_if_fail(xfer != NULL, NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
492 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
493 return xfer->account; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
494 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
495 |
7805 | 496 GaimXferStatusType |
497 gaim_xfer_get_status(const GaimXfer *xfer) | |
498 { | |
499 g_return_val_if_fail(xfer != NULL, GAIM_XFER_STATUS_UNKNOWN); | |
500 | |
501 return xfer->status; | |
502 } | |
503 | |
504 gboolean | |
7738 | 505 gaim_xfer_is_canceled(const GaimXfer *xfer) |
506 { | |
507 g_return_val_if_fail(xfer != NULL, TRUE); | |
508 | |
7805 | 509 if ((gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_CANCEL_LOCAL) || |
510 (gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_CANCEL_REMOTE)) | |
511 return TRUE; | |
512 else | |
513 return FALSE; | |
7738 | 514 } |
515 | |
4539
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
516 gboolean |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
517 gaim_xfer_is_completed(const GaimXfer *xfer) |
4539
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
518 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
519 g_return_val_if_fail(xfer != NULL, TRUE); |
4539
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
520 |
7805 | 521 return (gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_DONE); |
4539
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
522 } |
05476ef20d58
[gaim-migrate @ 4818]
Christian Hammond <chipx86@chipx86.com>
parents:
4538
diff
changeset
|
523 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
524 const char * |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
525 gaim_xfer_get_filename(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
526 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
527 g_return_val_if_fail(xfer != NULL, NULL); |
4514
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 return xfer->filename; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
530 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
531 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
532 const char * |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
533 gaim_xfer_get_local_filename(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
534 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
535 g_return_val_if_fail(xfer != NULL, NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
536 |
4605 | 537 return xfer->local_filename; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
538 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
539 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
540 size_t |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
541 gaim_xfer_get_bytes_sent(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
542 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
543 g_return_val_if_fail(xfer != NULL, 0); |
4514
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 return xfer->bytes_sent; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
546 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
547 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
548 size_t |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
549 gaim_xfer_get_bytes_remaining(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
550 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
551 g_return_val_if_fail(xfer != NULL, 0); |
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 return xfer->bytes_remaining; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
554 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
555 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
556 size_t |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
557 gaim_xfer_get_size(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
558 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
559 g_return_val_if_fail(xfer != NULL, 0); |
4514
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 return xfer->size; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
562 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
563 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
564 double |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
565 gaim_xfer_get_progress(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
566 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
567 g_return_val_if_fail(xfer != NULL, 0.0); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
568 |
4517
a2b2cce63fb8
[gaim-migrate @ 4795]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
569 if (gaim_xfer_get_size(xfer) == 0) |
a2b2cce63fb8
[gaim-migrate @ 4795]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
570 return 0.0; |
a2b2cce63fb8
[gaim-migrate @ 4795]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
571 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
572 return ((double)gaim_xfer_get_bytes_sent(xfer) / |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
573 (double)gaim_xfer_get_size(xfer)); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
574 } |
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 unsigned int |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
577 gaim_xfer_get_local_port(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
578 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
579 g_return_val_if_fail(xfer != NULL, -1); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
580 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
581 return xfer->local_port; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
582 } |
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 const char * |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
585 gaim_xfer_get_remote_ip(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
586 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
587 g_return_val_if_fail(xfer != NULL, NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
588 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
589 return xfer->remote_ip; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
590 } |
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 unsigned int |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
593 gaim_xfer_get_remote_port(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
594 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
595 g_return_val_if_fail(xfer != NULL, -1); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
596 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
597 return xfer->remote_port; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
598 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
599 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
600 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
601 gaim_xfer_set_completed(GaimXfer *xfer, gboolean completed) |
4538 | 602 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
603 GaimXferUiOps *ui_ops; |
4656 | 604 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
605 g_return_if_fail(xfer != NULL); |
4538 | 606 |
10654 | 607 if (completed == TRUE) { |
608 char *msg = NULL; | |
7805 | 609 gaim_xfer_set_status(xfer, GAIM_XFER_STATUS_DONE); |
4656 | 610 |
10654 | 611 if (gaim_xfer_get_filename(xfer) != NULL) |
612 msg = g_strdup_printf(_("Transfer of file %s complete"), | |
613 gaim_xfer_get_filename(xfer)); | |
614 else | |
615 msg = g_strdup_printf(_("File transfer complete")); | |
616 gaim_xfer_conversation_write(xfer, msg, FALSE); | |
617 g_free(msg); | |
618 } | |
619 | |
4656 | 620 ui_ops = gaim_xfer_get_ui_ops(xfer); |
621 | |
622 if (ui_ops != NULL && ui_ops->update_progress != NULL) | |
623 ui_ops->update_progress(xfer, gaim_xfer_get_progress(xfer)); | |
4538 | 624 } |
625 | |
626 void | |
9933 | 627 gaim_xfer_set_message(GaimXfer *xfer, const char *message) |
628 { | |
629 g_return_if_fail(xfer != NULL); | |
630 | |
631 g_free(xfer->message); | |
632 | |
633 if (message != NULL) | |
634 xfer->message = g_strdup(message); | |
635 else | |
636 xfer->message = NULL; | |
637 } | |
638 | |
639 void | |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
640 gaim_xfer_set_filename(GaimXfer *xfer, const char *filename) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
641 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
642 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
643 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
644 if (xfer->filename != NULL) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
645 g_free(xfer->filename); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
646 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
647 xfer->filename = (filename == NULL ? NULL : g_strdup(filename)); |
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 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
650 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
651 gaim_xfer_set_local_filename(GaimXfer *xfer, const char *filename) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
652 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
653 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
654 |
4605 | 655 if (xfer->local_filename != NULL) |
656 g_free(xfer->local_filename); | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
657 |
4605 | 658 xfer->local_filename = (filename == NULL ? NULL : g_strdup(filename)); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
659 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
660 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
661 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
662 gaim_xfer_set_size(GaimXfer *xfer, size_t size) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
663 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
664 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
665 |
4540
d83c5b925a05
[gaim-migrate @ 4819]
Christian Hammond <chipx86@chipx86.com>
parents:
4539
diff
changeset
|
666 if (xfer->size == 0) |
4538 | 667 xfer->bytes_remaining = size - xfer->bytes_sent; |
668 | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
669 xfer->size = size; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
670 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
671 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
672 GaimXferUiOps * |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
673 gaim_xfer_get_ui_ops(const GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
674 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
675 g_return_val_if_fail(xfer != NULL, NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
676 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
677 return xfer->ui_ops; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
678 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
679 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
680 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
681 gaim_xfer_set_init_fnc(GaimXfer *xfer, void (*fnc)(GaimXfer *)) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
682 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
683 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
684 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
685 xfer->ops.init = fnc; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
686 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
687 |
7805 | 688 void gaim_xfer_set_request_denied_fnc(GaimXfer *xfer, void (*fnc)(GaimXfer *)) |
689 { | |
690 g_return_if_fail(xfer != NULL); | |
691 | |
692 xfer->ops.request_denied = fnc; | |
693 } | |
4514
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 void |
12151
de798f2f4bf1
[gaim-migrate @ 14452]
Richard Laager <rlaager@wiktel.com>
parents:
11934
diff
changeset
|
696 gaim_xfer_set_read_fnc(GaimXfer *xfer, gssize (*fnc)(guchar **, GaimXfer *)) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
697 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
698 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
699 |
5495
5b678994929b
[gaim-migrate @ 5891]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5494
diff
changeset
|
700 xfer->ops.read = fnc; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
701 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
702 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
703 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
704 gaim_xfer_set_write_fnc(GaimXfer *xfer, |
12151
de798f2f4bf1
[gaim-migrate @ 14452]
Richard Laager <rlaager@wiktel.com>
parents:
11934
diff
changeset
|
705 gssize (*fnc)(const guchar *, size_t, GaimXfer *)) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
706 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
707 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
708 |
5495
5b678994929b
[gaim-migrate @ 5891]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5494
diff
changeset
|
709 xfer->ops.write = fnc; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
710 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
711 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
712 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
713 gaim_xfer_set_ack_fnc(GaimXfer *xfer, |
11159 | 714 void (*fnc)(GaimXfer *, const guchar *, size_t)) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
715 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
716 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
717 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
718 xfer->ops.ack = fnc; |
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 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
721 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
722 gaim_xfer_set_start_fnc(GaimXfer *xfer, void (*fnc)(GaimXfer *)) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
723 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
724 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
725 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
726 xfer->ops.start = fnc; |
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 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
730 gaim_xfer_set_end_fnc(GaimXfer *xfer, void (*fnc)(GaimXfer *)) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
731 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
732 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
733 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
734 xfer->ops.end = fnc; |
3609 | 735 } |
736 | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
737 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
738 gaim_xfer_set_cancel_send_fnc(GaimXfer *xfer, void (*fnc)(GaimXfer *)) |
3609 | 739 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
740 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
741 |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
742 xfer->ops.cancel_send = fnc; |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
743 } |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
744 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
745 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
746 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
|
747 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
748 g_return_if_fail(xfer != NULL); |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
749 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
750 xfer->ops.cancel_recv = fnc; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
751 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
752 |
12151
de798f2f4bf1
[gaim-migrate @ 14452]
Richard Laager <rlaager@wiktel.com>
parents:
11934
diff
changeset
|
753 gssize |
11159 | 754 gaim_xfer_read(GaimXfer *xfer, guchar **buffer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
755 { |
12151
de798f2f4bf1
[gaim-migrate @ 14452]
Richard Laager <rlaager@wiktel.com>
parents:
11934
diff
changeset
|
756 gssize s, r; |
3609 | 757 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
758 g_return_val_if_fail(xfer != NULL, 0); |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
759 g_return_val_if_fail(buffer != NULL, 0); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
760 |
4517
a2b2cce63fb8
[gaim-migrate @ 4795]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
761 if (gaim_xfer_get_size(xfer) == 0) |
a2b2cce63fb8
[gaim-migrate @ 4795]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
762 s = 4096; |
a2b2cce63fb8
[gaim-migrate @ 4795]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
763 else |
a2b2cce63fb8
[gaim-migrate @ 4795]
Christian Hammond <chipx86@chipx86.com>
parents:
4514
diff
changeset
|
764 s = MIN(gaim_xfer_get_bytes_remaining(xfer), 4096); |
3609 | 765 |
5495
5b678994929b
[gaim-migrate @ 5891]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5494
diff
changeset
|
766 if (xfer->ops.read != NULL) |
5b678994929b
[gaim-migrate @ 5891]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5494
diff
changeset
|
767 r = (xfer->ops.read)(buffer, xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
768 else { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
769 *buffer = g_malloc0(s); |
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 r = read(xfer->fd, *buffer, s); |
6482
16fcc379e484
[gaim-migrate @ 6996]
Christian Hammond <chipx86@chipx86.com>
parents:
6269
diff
changeset
|
772 if ((gaim_xfer_get_size(xfer) > 0) && |
4617 | 773 ((gaim_xfer_get_bytes_sent(xfer)+r) >= gaim_xfer_get_size(xfer))) |
4538 | 774 gaim_xfer_set_completed(xfer, TRUE); |
8316 | 775 else if(r <= 0) |
776 r = -1; | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
777 } |
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 return r; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
780 } |
3609 | 781 |
12151
de798f2f4bf1
[gaim-migrate @ 14452]
Richard Laager <rlaager@wiktel.com>
parents:
11934
diff
changeset
|
782 gssize |
11159 | 783 gaim_xfer_write(GaimXfer *xfer, const guchar *buffer, size_t size) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
784 { |
12151
de798f2f4bf1
[gaim-migrate @ 14452]
Richard Laager <rlaager@wiktel.com>
parents:
11934
diff
changeset
|
785 gssize r, s; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
786 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
787 g_return_val_if_fail(xfer != NULL, 0); |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
788 g_return_val_if_fail(buffer != NULL, 0); |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
789 g_return_val_if_fail(size != 0, 0); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
790 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
791 s = MIN(gaim_xfer_get_bytes_remaining(xfer), size); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
792 |
8231
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
793 if (xfer->ops.write != NULL) { |
5495
5b678994929b
[gaim-migrate @ 5891]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5494
diff
changeset
|
794 r = (xfer->ops.write)(buffer, s, xfer); |
8231
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
795 } else { |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
796 r = write(xfer->fd, buffer, s); |
8231
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
797 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
|
798 gaim_xfer_set_completed(xfer, TRUE); |
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
799 } |
3609 | 800 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
801 return r; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
802 } |
3609 | 803 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
804 static void |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
805 transfer_cb(gpointer data, gint source, GaimInputCondition condition) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
806 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
807 GaimXferUiOps *ui_ops; |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
808 GaimXfer *xfer = (GaimXfer *)data; |
11159 | 809 guchar *buffer = NULL; |
12151
de798f2f4bf1
[gaim-migrate @ 14452]
Richard Laager <rlaager@wiktel.com>
parents:
11934
diff
changeset
|
810 gssize r = 0; |
3609 | 811 |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
812 if (condition & GAIM_INPUT_READ) { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
813 r = gaim_xfer_read(xfer, &buffer); |
8316 | 814 if (r > 0) { |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
815 fwrite(buffer, 1, r, xfer->dest_fp); |
8316 | 816 } else if(r < 0) { |
817 gaim_xfer_cancel_remote(xfer); | |
818 return; | |
819 } | |
3609 | 820 } |
9798 | 821 |
822 if (condition & GAIM_INPUT_WRITE) { | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
823 size_t s = MIN(gaim_xfer_get_bytes_remaining(xfer), 4096); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
824 |
8351 | 825 /* this is so the prpl can keep the connection open |
826 if it needs to for some odd reason. */ | |
827 if (s == 0) { | |
9798 | 828 if (xfer->watcher) { |
8351 | 829 gaim_input_remove(xfer->watcher); |
830 xfer->watcher = 0; | |
831 } | |
832 return; | |
833 } | |
834 | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
835 buffer = g_malloc0(s); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
836 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
837 fread(buffer, 1, s, xfer->dest_fp); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
838 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
839 /* Write as much as we're allowed to. */ |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
840 r = gaim_xfer_write(xfer, buffer, s); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
841 |
8231
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
842 if (r == -1) { |
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
843 gaim_xfer_cancel_remote(xfer); |
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
844 g_free(buffer); |
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
845 return; |
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
8208
diff
changeset
|
846 } else if (r < s) { |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
847 /* We have to seek back in the file now. */ |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
848 fseek(xfer->dest_fp, r - s, SEEK_CUR); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
849 } |
3609 | 850 } |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
851 |
4540
d83c5b925a05
[gaim-migrate @ 4819]
Christian Hammond <chipx86@chipx86.com>
parents:
4539
diff
changeset
|
852 if (gaim_xfer_get_size(xfer) > 0) |
d83c5b925a05
[gaim-migrate @ 4819]
Christian Hammond <chipx86@chipx86.com>
parents:
4539
diff
changeset
|
853 xfer->bytes_remaining -= r; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
854 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
855 xfer->bytes_sent += r; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
856 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
857 if (xfer->ops.ack != NULL) |
4594 | 858 xfer->ops.ack(xfer, buffer, r); |
859 | |
860 g_free(buffer); | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
861 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
862 ui_ops = gaim_xfer_get_ui_ops(xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
863 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
864 if (ui_ops != NULL && ui_ops->update_progress != NULL) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
865 ui_ops->update_progress(xfer, gaim_xfer_get_progress(xfer)); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
866 |
4553
d03fcb3f4be2
[gaim-migrate @ 4833]
Christian Hammond <chipx86@chipx86.com>
parents:
4540
diff
changeset
|
867 if (gaim_xfer_is_completed(xfer)) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
868 gaim_xfer_end(xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
869 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
870 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
871 static void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
872 begin_transfer(GaimXfer *xfer, GaimInputCondition cond) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
873 { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
874 GaimXferType type = gaim_xfer_get_type(xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
875 |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10504
diff
changeset
|
876 xfer->dest_fp = g_fopen(gaim_xfer_get_local_filename(xfer), |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
877 type == GAIM_XFER_RECEIVE ? "wb" : "rb"); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
878 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
879 if (xfer->dest_fp == NULL) { |
9796 | 880 gaim_xfer_show_file_error(xfer, gaim_xfer_get_local_filename(xfer)); |
9785 | 881 gaim_xfer_cancel_local(xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
882 return; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
883 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
884 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
885 xfer->watcher = gaim_input_add(xfer->fd, cond, transfer_cb, xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
886 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
887 if (xfer->ops.start != NULL) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
888 xfer->ops.start(xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
889 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
890 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
891 static void |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
892 connect_cb(gpointer data, gint source, GaimInputCondition condition) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
893 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
894 GaimXfer *xfer = (GaimXfer *)data; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
895 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
896 xfer->fd = source; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
897 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
898 begin_transfer(xfer, condition); |
3609 | 899 } |
900 | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
901 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
902 gaim_xfer_start(GaimXfer *xfer, int fd, const char *ip, |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
903 unsigned int port) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
904 { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
905 GaimInputCondition cond; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
906 GaimXferType type; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
907 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
908 g_return_if_fail(xfer != NULL); |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
909 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
|
910 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
911 type = gaim_xfer_get_type(xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
912 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
913 xfer->bytes_remaining = gaim_xfer_get_size(xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
914 xfer->bytes_sent = 0; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
915 |
7805 | 916 gaim_xfer_set_status(xfer, GAIM_XFER_STATUS_STARTED); |
917 | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
918 if (type == GAIM_XFER_RECEIVE) { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
919 cond = GAIM_INPUT_READ; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
920 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
921 if (ip != NULL) { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
922 xfer->remote_ip = g_strdup(ip); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
923 xfer->remote_port = port; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
924 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
925 /* Establish a file descriptor. */ |
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
926 gaim_proxy_connect(xfer->account, xfer->remote_ip, |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
927 xfer->remote_port, connect_cb, xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
928 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
929 return; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
930 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
931 else { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
932 xfer->fd = fd; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
933 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
934 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
935 else { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
936 cond = GAIM_INPUT_WRITE; |
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 xfer->fd = fd; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
939 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
940 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
941 begin_transfer(xfer, cond); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
942 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
943 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
944 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
945 gaim_xfer_end(GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
946 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
947 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
948 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
949 /* See if we are actually trying to cancel this. */ |
7805 | 950 if (gaim_xfer_get_status(xfer) != GAIM_XFER_STATUS_DONE) { |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
951 gaim_xfer_cancel_local(xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
952 return; |
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 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
955 if (xfer->ops.end != NULL) |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
956 xfer->ops.end(xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
957 |
4521
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
958 if (xfer->watcher != 0) { |
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
959 gaim_input_remove(xfer->watcher); |
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
960 xfer->watcher = 0; |
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
961 } |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
962 |
4521
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
963 if (xfer->fd != 0) |
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
964 close(xfer->fd); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
965 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
966 if (xfer->dest_fp != NULL) { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
967 fclose(xfer->dest_fp); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
968 xfer->dest_fp = NULL; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
969 } |
7805 | 970 |
971 gaim_xfer_unref(xfer); | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
972 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
973 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
974 void |
8585 | 975 gaim_xfer_add(GaimXfer *xfer) |
976 { | |
977 GaimXferUiOps *ui_ops; | |
978 | |
979 g_return_if_fail(xfer != NULL); | |
980 | |
981 ui_ops = gaim_xfer_get_ui_ops(xfer); | |
982 | |
983 if (ui_ops != NULL && ui_ops->add_xfer != NULL) | |
984 ui_ops->add_xfer(xfer); | |
985 } | |
986 | |
987 void | |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
988 gaim_xfer_cancel_local(GaimXfer *xfer) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
989 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
990 GaimXferUiOps *ui_ops; |
10774 | 991 char *msg = NULL; |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
992 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
993 g_return_if_fail(xfer != NULL); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
994 |
7805 | 995 gaim_xfer_set_status(xfer, GAIM_XFER_STATUS_CANCEL_LOCAL); |
7738 | 996 |
10470 | 997 if (gaim_xfer_get_filename(xfer) != NULL) |
998 { | |
999 msg = g_strdup_printf(_("You canceled the transfer of %s"), | |
10774 | 1000 gaim_xfer_get_filename(xfer)); |
10470 | 1001 } |
1002 else | |
1003 { | |
1004 msg = g_strdup_printf(_("File transfer cancelled")); | |
1005 } | |
9932 | 1006 gaim_xfer_conversation_write(xfer, msg, FALSE); |
1007 g_free(msg); | |
1008 | |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1009 if (gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1010 { |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1011 if (xfer->ops.cancel_send != NULL) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1012 xfer->ops.cancel_send(xfer); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1013 } |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1014 else |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1015 { |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1016 if (xfer->ops.cancel_recv != NULL) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1017 xfer->ops.cancel_recv(xfer); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1018 } |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1019 |
4521
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
1020 if (xfer->watcher != 0) { |
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
1021 gaim_input_remove(xfer->watcher); |
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
1022 xfer->watcher = 0; |
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
1023 } |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1024 |
4521
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
1025 if (xfer->fd != 0) |
dda0fbba1c46
[gaim-migrate @ 4799]
Christian Hammond <chipx86@chipx86.com>
parents:
4518
diff
changeset
|
1026 close(xfer->fd); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1027 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1028 if (xfer->dest_fp != NULL) { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1029 fclose(xfer->dest_fp); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1030 xfer->dest_fp = NULL; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1031 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1032 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1033 ui_ops = gaim_xfer_get_ui_ops(xfer); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1034 |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1035 if (ui_ops != NULL && ui_ops->cancel_local != NULL) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1036 ui_ops->cancel_local(xfer); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1037 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1038 xfer->bytes_remaining = 0; |
7805 | 1039 |
1040 gaim_xfer_unref(xfer); | |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1041 } |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1042 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1043 void |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1044 gaim_xfer_cancel_remote(GaimXfer *xfer) |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1045 { |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1046 GaimXferUiOps *ui_ops; |
10774 | 1047 gchar *msg; |
10654 | 1048 GaimAccount *account; |
1049 GaimBuddy *buddy; | |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1050 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1051 g_return_if_fail(xfer != NULL); |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1052 |
9771 | 1053 gaim_request_close_with_handle(xfer); |
9932 | 1054 gaim_xfer_set_status(xfer, GAIM_XFER_STATUS_CANCEL_REMOTE); |
9771 | 1055 |
10654 | 1056 account = gaim_xfer_get_account(xfer); |
1057 buddy = gaim_find_buddy(account, xfer->who); | |
1058 | |
10470 | 1059 if (gaim_xfer_get_filename(xfer) != NULL) |
1060 { | |
1061 msg = g_strdup_printf(_("%s canceled the transfer of %s"), | |
10774 | 1062 buddy ? gaim_buddy_get_alias(buddy) : xfer->who, gaim_xfer_get_filename(xfer)); |
10470 | 1063 } |
1064 else | |
1065 { | |
10654 | 1066 msg = g_strdup_printf(_("%s canceled the file transfer"), |
1067 buddy ? gaim_buddy_get_alias(buddy) : xfer->who); | |
10470 | 1068 } |
9932 | 1069 gaim_xfer_conversation_write(xfer, msg, TRUE); |
10654 | 1070 gaim_xfer_error(gaim_xfer_get_type(xfer), account, xfer->who, msg); |
9771 | 1071 g_free(msg); |
1072 | |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1073 if (gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1074 { |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1075 if (xfer->ops.cancel_send != NULL) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1076 xfer->ops.cancel_send(xfer); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1077 } |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1078 else |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1079 { |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1080 if (xfer->ops.cancel_recv != NULL) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1081 xfer->ops.cancel_recv(xfer); |
7272
02f697df677b
[gaim-migrate @ 7849]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
1082 } |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1083 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1084 if (xfer->watcher != 0) { |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1085 gaim_input_remove(xfer->watcher); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1086 xfer->watcher = 0; |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1087 } |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1088 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1089 if (xfer->fd != 0) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1090 close(xfer->fd); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1091 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1092 if (xfer->dest_fp != NULL) { |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1093 fclose(xfer->dest_fp); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1094 xfer->dest_fp = NULL; |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1095 } |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1096 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1097 ui_ops = gaim_xfer_get_ui_ops(xfer); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1098 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1099 if (ui_ops != NULL && ui_ops->cancel_remote != NULL) |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4656
diff
changeset
|
1100 ui_ops->cancel_remote(xfer); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1101 |
4528
f8fec48f0fde
[gaim-migrate @ 4806]
Christian Hammond <chipx86@chipx86.com>
parents:
4521
diff
changeset
|
1102 xfer->bytes_remaining = 0; |
7805 | 1103 |
1104 gaim_xfer_unref(xfer); | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1105 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1106 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1107 void |
10654 | 1108 gaim_xfer_error(GaimXferType type, GaimAccount *account, const char *who, const char *msg) |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1109 { |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1110 char *title; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1111 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1112 g_return_if_fail(msg != NULL); |
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1113 g_return_if_fail(type != GAIM_XFER_UNKNOWN); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1114 |
10654 | 1115 if (account) { |
1116 GaimBuddy *buddy; | |
1117 buddy = gaim_find_buddy(account, who); | |
1118 if (buddy) | |
1119 who = gaim_buddy_get_alias(buddy); | |
1120 } | |
1121 | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1122 if (type == GAIM_XFER_SEND) |
11231
64e2c65ef650
[gaim-migrate @ 13371]
Richard Laager <rlaager@wiktel.com>
parents:
11159
diff
changeset
|
1123 title = g_strdup_printf(_("File transfer to %s failed."), who); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1124 else |
11231
64e2c65ef650
[gaim-migrate @ 13371]
Richard Laager <rlaager@wiktel.com>
parents:
11159
diff
changeset
|
1125 title = g_strdup_printf(_("File transfer from %s failed."), who); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1126 |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5169
diff
changeset
|
1127 gaim_notify_error(NULL, NULL, title, msg); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1128 |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1129 g_free(title); |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1130 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1131 |
8585 | 1132 void |
1133 gaim_xfer_update_progress(GaimXfer *xfer) | |
1134 { | |
1135 GaimXferUiOps *ui_ops; | |
1136 | |
1137 g_return_if_fail(xfer != NULL); | |
1138 | |
1139 ui_ops = gaim_xfer_get_ui_ops(xfer); | |
1140 if (ui_ops != NULL && ui_ops->update_progress != NULL) | |
1141 ui_ops->update_progress(xfer, gaim_xfer_get_progress(xfer)); | |
1142 } | |
1143 | |
1144 | |
6263
3565ee7a5dd3
[gaim-migrate @ 6760]
Christian Hammond <chipx86@chipx86.com>
parents:
6242
diff
changeset
|
1145 /************************************************************************** |
3565ee7a5dd3
[gaim-migrate @ 6760]
Christian Hammond <chipx86@chipx86.com>
parents:
6242
diff
changeset
|
1146 * File Transfer Subsystem API |
3565ee7a5dd3
[gaim-migrate @ 6760]
Christian Hammond <chipx86@chipx86.com>
parents:
6242
diff
changeset
|
1147 **************************************************************************/ |
11281
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1148 void * |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1149 gaim_xfers_get_handle(void) { |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1150 static int handle = 0; |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1151 |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1152 return &handle; |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1153 } |
6241
9ce44a7f9ae7
[gaim-migrate @ 6735]
Christian Hammond <chipx86@chipx86.com>
parents:
6240
diff
changeset
|
1154 |
9ce44a7f9ae7
[gaim-migrate @ 6735]
Christian Hammond <chipx86@chipx86.com>
parents:
6240
diff
changeset
|
1155 void |
11281
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1156 gaim_xfers_init(void) { |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1157 void *handle = gaim_xfers_get_handle(); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1158 |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1159 /* register signals */ |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1160 gaim_signal_register(handle, "file-recv-accept", |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1161 gaim_marshal_VOID__POINTER, |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1162 NULL, 1, |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1163 gaim_value_new(GAIM_TYPE_POINTER)); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1164 gaim_signal_register(handle, "file-send-accept", |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1165 gaim_marshal_VOID__POINTER, |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1166 NULL, 1, |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1167 gaim_value_new(GAIM_TYPE_POINTER)); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1168 gaim_signal_register(handle, "file-recv-start", |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1169 gaim_marshal_VOID__POINTER, |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1170 NULL, 1, |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1171 gaim_value_new(GAIM_TYPE_POINTER)); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1172 gaim_signal_register(handle, "file-send-start", |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1173 gaim_marshal_VOID__POINTER, |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1174 NULL, 1, |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1175 gaim_value_new(GAIM_TYPE_POINTER)); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1176 gaim_signal_register(handle, "file-send-cancel", |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1177 gaim_marshal_VOID__POINTER, |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1178 NULL, 1, |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1179 gaim_value_new(GAIM_TYPE_POINTER)); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1180 gaim_signal_register(handle, "file-recv-cancel", |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1181 gaim_marshal_VOID__POINTER, |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1182 NULL, 1, |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1183 gaim_value_new(GAIM_TYPE_POINTER)); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1184 gaim_signal_register(handle, "file-send-complete", |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1185 gaim_marshal_VOID__POINTER, |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1186 NULL, 1, |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1187 gaim_value_new(GAIM_TYPE_POINTER)); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1188 gaim_signal_register(handle, "file-recv-complete", |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1189 gaim_marshal_VOID__POINTER, |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1190 NULL, 1, |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1191 gaim_value_new(GAIM_TYPE_POINTER)); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1192 } |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1193 |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1194 void |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1195 gaim_xfers_uninit(void) { |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1196 gaim_signals_disconnect_by_handle(gaim_xfers_get_handle()); |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1197 } |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1198 |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1199 void |
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1200 gaim_xfers_set_ui_ops(GaimXferUiOps *ops) { |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1201 xfer_ui_ops = ops; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1202 } |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1203 |
6240
ac191233b816
[gaim-migrate @ 6734]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1204 GaimXferUiOps * |
11281
920a37a4c1be
[gaim-migrate @ 13478]
Gary Kramlich <grim@reaperworld.com>
parents:
11231
diff
changeset
|
1205 gaim_xfers_get_ui_ops(void) { |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1206 return xfer_ui_ops; |
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4249
diff
changeset
|
1207 } |