annotate src/ft.c @ 9798:255596f41014

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