annotate src/ft.c @ 3622:2ef75915a13c

[gaim-migrate @ 3743] I haven't tested this thoroughly, but neither does Sean before he commits his code. committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Thu, 10 Oct 2002 06:54:08 +0000
parents e9f66d245253
children 9682c0e022c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3609
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1 /*
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
2 * gaim - file transfer functions
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
3 *
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
4 * Copyright (C) 2002, Wil Mahan <wtm2@duke.edu>
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 *
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 * 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
8 * the Free Software Foundation; either version 2 of the License, or
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 * (at your option) any later version.
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 *
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14 * GNU General Public License for more details.
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 *
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
22 #ifdef HAVE_CONFIG_H
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
23 #include <config.h>
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
24 #endif
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
25
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
26 #include <sys/stat.h>
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
27 #include <unistd.h>
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
28 #include <errno.h>
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
29 #include <string.h>
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
30
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
31 #define FT_BUFFER_SIZE (4096)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
32
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
33 #include <gtk/gtk.h>
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
34 #include "gaim.h"
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
35 #include "proxy.h"
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
36 #include "prpl.h"
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
37
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
38 /* Completely describes a file transfer. Opaque to callers. */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
39 struct file_transfer {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
40 enum { FILE_TRANSFER_TYPE_SEND, FILE_TRANSFER_TYPE_RECEIVE } type;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
41
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
42 enum {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
43 FILE_TRANSFER_STATE_ASK, /* waiting for confirmation */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
44 FILE_TRANSFER_STATE_CHOOSEFILE, /* waiting for file dialog */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
45 FILE_TRANSFER_STATE_TRANSFERRING, /* in actual transfer */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
46 FILE_TRANSFER_STATE_INTERRUPTED, /* other user canceled */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
47 FILE_TRANSFER_STATE_CANCELED, /* we canceled */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
48 FILE_TRANSFER_STATE_DONE, /* transfer complete */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
49 FILE_TRANSFER_STATE_CLEANUP /* freeing memory */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
50 } state;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
51
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
52 char *who;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
53
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
54 /* file selection dialog */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
55 GtkWidget *w;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
56 char **names;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
57 int *sizes;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
58 char *dir;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
59 char *initname;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
60 FILE *file;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
61
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
62 /* connection info */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
63 struct gaim_connection *gc;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
64 int fd;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
65 int watcher;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
66
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
67 /* state */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
68 int totfiles;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
69 int filesdone;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
70 int totsize;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
71 int bytessent;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
72 int bytesleft;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
73 };
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
74
3621
e9f66d245253 [gaim-migrate @ 3742]
Rob Flynn <gaim@robflynn.com>
parents: 3611
diff changeset
75
e9f66d245253 [gaim-migrate @ 3742]
Rob Flynn <gaim@robflynn.com>
parents: 3611
diff changeset
76
3609
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
77 static int ft_choose_file(gpointer a, struct file_transfer *xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
78 static void ft_cancel(gpointer w, struct file_transfer *xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
79 static void ft_delete(struct file_transfer *xfer);
3610
9313e146daf4 [gaim-migrate @ 3723]
Rob Flynn <gaim@robflynn.com>
parents: 3609
diff changeset
80 static void ft_callback(gpointer data, gint source, GaimInputCondition condition);
3609
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
81 static void ft_nextfile(struct file_transfer *xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
82 static int ft_mkdir(const char *name);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
83 static int ft_mkdir_help(char *dir);
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 static struct file_transfer *ft_new(int type, struct gaim_connection *gc,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
86 const char *who)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
87 {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
88 struct file_transfer *xfer = g_new0(struct file_transfer, 1);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
89 xfer->type = type;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
90 xfer->state = FILE_TRANSFER_STATE_ASK;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
91 xfer->gc = gc;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
92 xfer->who = g_strdup(who);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
93 xfer->filesdone = 0;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
94
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
95 return xfer;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
96 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
97
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
98 struct file_transfer *transfer_in_add(struct gaim_connection *gc,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
99 const char *who, const char *initname, int totsize,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
100 int totfiles, const char *msg)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
101 {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
102 struct file_transfer *xfer = ft_new(FILE_TRANSFER_TYPE_RECEIVE, gc,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
103 who);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
104 char *buf;
3621
e9f66d245253 [gaim-migrate @ 3742]
Rob Flynn <gaim@robflynn.com>
parents: 3611
diff changeset
105 char *sizebuf;
3609
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
106 static const char *sizestr[4] = { "bytes", "KB", "MB", "GB" };
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
107 float sizemag = (float)totsize;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
108 int szindex = 0;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
109
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
110 xfer->initname = g_strdup(initname);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
111 xfer->totsize = totsize;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
112 xfer->totfiles = totfiles;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
113 xfer->filesdone = 0;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
114
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
115 /* Ask the user whether he or she accepts the transfer. */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
116 while ((szindex < 4) && (sizemag > 1024)) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
117 sizemag /= 1024;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
118 szindex++;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
119 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
120
3621
e9f66d245253 [gaim-migrate @ 3742]
Rob Flynn <gaim@robflynn.com>
parents: 3611
diff changeset
121 if (totsize == -1)
e9f66d245253 [gaim-migrate @ 3742]
Rob Flynn <gaim@robflynn.com>
parents: 3611
diff changeset
122 sizebuf = g_strdup_printf(_("Unkown"));
3609
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
123 else
3621
e9f66d245253 [gaim-migrate @ 3742]
Rob Flynn <gaim@robflynn.com>
parents: 3611
diff changeset
124 sizebuf = g_strdup_printf("%.3g %s", sizemag, sizestr[szindex]);
e9f66d245253 [gaim-migrate @ 3742]
Rob Flynn <gaim@robflynn.com>
parents: 3611
diff changeset
125
e9f66d245253 [gaim-migrate @ 3742]
Rob Flynn <gaim@robflynn.com>
parents: 3611
diff changeset
126 if (xfer->totfiles == 1) {
e9f66d245253 [gaim-migrate @ 3742]
Rob Flynn <gaim@robflynn.com>
parents: 3611
diff changeset
127 buf = g_strdup_printf(_("%s requests that %s accept a file: %s (%s)"),
e9f66d245253 [gaim-migrate @ 3742]
Rob Flynn <gaim@robflynn.com>
parents: 3611
diff changeset
128 who, xfer->gc->username, initname, sizebuf);
e9f66d245253 [gaim-migrate @ 3742]
Rob Flynn <gaim@robflynn.com>
parents: 3611
diff changeset
129 } else {
e9f66d245253 [gaim-migrate @ 3742]
Rob Flynn <gaim@robflynn.com>
parents: 3611
diff changeset
130 buf = g_strdup_printf(_("%s requests that %s accept %d files: %s (%s)"),
3609
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
131 who, xfer->gc->username, xfer->totfiles,
3621
e9f66d245253 [gaim-migrate @ 3742]
Rob Flynn <gaim@robflynn.com>
parents: 3611
diff changeset
132 initname, sizebuf);
e9f66d245253 [gaim-migrate @ 3742]
Rob Flynn <gaim@robflynn.com>
parents: 3611
diff changeset
133 }
e9f66d245253 [gaim-migrate @ 3742]
Rob Flynn <gaim@robflynn.com>
parents: 3611
diff changeset
134
e9f66d245253 [gaim-migrate @ 3742]
Rob Flynn <gaim@robflynn.com>
parents: 3611
diff changeset
135 g_free(sizebuf);
3609
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
136
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
137 if (msg) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
138 char *newmsg = g_strconcat(buf, ": ", msg, NULL);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
139 g_free(buf);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
140 buf = newmsg;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
141 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
142
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
143 do_ask_dialog(buf, xfer, ft_choose_file, ft_cancel);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
144 g_free(buf);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
145
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
146 return xfer;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
147 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
148
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
149 struct file_transfer *transfer_out_add(struct gaim_connection *gc,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
150 const char *who)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
151 {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
152 struct file_transfer *xfer = ft_new(FILE_TRANSFER_TYPE_SEND, gc,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
153 who);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
154
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
155 ft_choose_file(NULL, xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
156
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
157 return xfer;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
158 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
159
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
160 /* We canceled the transfer, either by declining the initial
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
161 * confirmation dialog or canceling the file dialog.
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
162 */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
163 static void ft_cancel(gpointer w, struct file_transfer *xfer)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
164 {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
165 /* Make sure we weren't aborted while waiting for
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
166 * confirmation from the user.
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
167 */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
168 if (xfer->state == FILE_TRANSFER_STATE_INTERRUPTED) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
169 xfer->state = FILE_TRANSFER_STATE_CLEANUP;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
170 transfer_abort(xfer, NULL);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
171 return;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
172 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
173
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
174 xfer->state = FILE_TRANSFER_STATE_CANCELED;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
175 if (xfer->w) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
176 gtk_widget_destroy(xfer->w);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
177 xfer->w = NULL;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
178 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
179
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
180 if (xfer->gc->prpl->file_transfer_cancel)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
181 xfer->gc->prpl->file_transfer_cancel(xfer->gc, xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
182
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
183 ft_delete(xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
184 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
185
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
186 /* This is called when the other user aborts the transfer,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
187 * possibly in the middle of a transfer.
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
188 */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
189 int transfer_abort(struct file_transfer *xfer, const char *why)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
190 {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
191 if (xfer->state == FILE_TRANSFER_STATE_INTERRUPTED) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
192 /* If for some reason we have already been
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
193 * here and are waiting on some event before
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
194 * cleaning up, but we get another abort request,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
195 * we don't need to do anything else.
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
196 */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
197 return 1;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
198 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
199 else if (xfer->state == FILE_TRANSFER_STATE_ASK) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
200 /* Kludge: since there is no way to kill a
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
201 * do_ask_dialog() window, we just note the
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
202 * status here and clean up after the user
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
203 * makes a selection.
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
204 */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
205 xfer->state = FILE_TRANSFER_STATE_INTERRUPTED;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
206 return 1;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
207 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
208 else if (xfer->state == FILE_TRANSFER_STATE_TRANSFERRING) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
209 if (xfer->watcher) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
210 gaim_input_remove(xfer->watcher);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
211 xfer->watcher = 0;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
212 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
213 if (xfer->file) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
214 fclose(xfer->file);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
215 xfer->file = NULL;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
216 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
217 /* XXX theoretically, there is a race condition here,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
218 * because we could be inside ft_callback() when we
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
219 * free xfer below, with undefined results. Since
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
220 * we use non-blocking IO, this doesn't seem to be
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
221 * a problem, but it still makes me nervous--I don't
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
222 * know how to fix it other than using locks, though.
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
223 * -- wtm
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
224 */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
225 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
226 else if (xfer->state == FILE_TRANSFER_STATE_CHOOSEFILE) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
227 /* It's safe to clean up now. Just make sure we
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
228 * destroy the dialog window first.
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
229 */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
230 if (xfer->w) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
231 gtk_signal_disconnect_by_func(GTK_OBJECT(xfer->w),
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
232 GTK_SIGNAL_FUNC(ft_cancel), xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
233 gtk_widget_destroy(xfer->w);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
234 xfer->w = NULL;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
235 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
236 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
237
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
238 /* Let the user know that we were aborted, unless we already
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
239 * finished or the user aborted first.
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
240 */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
241 /* if ((xfer->state != FILE_TRANSFER_STATE_DONE) &&
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
242 (xfer->state != FILE_TRANSFER_STATE_CANCELED)) { */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
243 if (why) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
244 char *msg;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
245
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
246 if (xfer->type == FILE_TRANSFER_TYPE_SEND)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
247 msg = g_strdup_printf(_("File transfer to %s aborted."), xfer->who);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
248 else
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
249 msg = g_strdup_printf(_("File transfer from %s aborted."), xfer->who);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
250 do_error_dialog(msg, why, GAIM_ERROR);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
251 g_free(msg);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
252 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
253
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
254 ft_delete(xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
255
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
256 return 0;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
257 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
258
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
259
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
260 static void ft_delete(struct file_transfer *xfer)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
261 {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
262 if (xfer->names)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
263 g_strfreev(xfer->names);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
264 if (xfer->initname)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
265 g_free(xfer->initname);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
266 if (xfer->who)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
267 g_free(xfer->who);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
268 if (xfer->sizes)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
269 g_free(xfer->sizes);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
270 g_free(xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
271 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
272
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
273 static void ft_choose_ok(gpointer a, struct file_transfer *xfer) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
274 gboolean exists, is_dir;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
275 struct stat st;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
276 const char *err = NULL;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
277
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
278 xfer->names = gtk_file_selection_get_selections(GTK_FILE_SELECTION(xfer->w));
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
279 exists = !stat(*xfer->names, &st);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
280 is_dir = (exists) ? S_ISDIR(st.st_mode) : 0;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
281
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
282 if (exists) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
283 if (xfer->type == FILE_TRANSFER_TYPE_RECEIVE)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
284 /* XXX overwrite/append/cancel prompt */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
285 err = _("That file already exists; please choose another name.");
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
286 else { /* (xfer->type == FILE_TRANSFER_TYPE_SEND) */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
287 char **cur;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
288 /* First find the total number of files,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
289 * so we know how much space to allocate.
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
290 */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
291 xfer->totfiles = 0;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
292 for (cur = xfer->names; *cur; cur++) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
293 xfer->totfiles++;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
294 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
295
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
296 /* Now get sizes for each file. */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
297 xfer->totsize = st.st_size;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
298 xfer->sizes = g_malloc(xfer->totfiles
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
299 * sizeof(*xfer->sizes));
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
300 xfer->sizes[0] = st.st_size;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
301 for (cur = xfer->names + 1; *cur; cur++) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
302 exists = !stat(*cur, &st);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
303 if (!exists) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
304 err = _("File not found.");
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
305 break;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
306 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
307 xfer->sizes[cur - xfer->names] =
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
308 st.st_size;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
309 xfer->totsize += st.st_size;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
310 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
311 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
312 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
313 else { /* doesn't exist */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
314 if (xfer->type == FILE_TRANSFER_TYPE_SEND)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
315 err = _("File not found.");
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
316 else if (xfer->totfiles > 1) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
317 if (!xfer->names[0] || xfer->names[1]) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
318 err = _("You may only choose one new directory.");
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
319 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
320 else {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
321 if (ft_mkdir(*xfer->names))
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
322 err = _("Unable to create directory.");
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
323 else
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
324 xfer->dir = g_strconcat(xfer->names[0],
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
325 "/", NULL);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
326 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
327 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
328 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
329
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
330 if (err)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
331 do_error_dialog(err, NULL, GAIM_ERROR);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
332 else {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
333 /* File name looks valid */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
334 gtk_widget_destroy(xfer->w);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
335 xfer->w = NULL;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
336
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
337 if (xfer->type == FILE_TRANSFER_TYPE_SEND) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
338 char *desc;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
339 if (xfer->totfiles == 1)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
340 desc = *xfer->names;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
341 else
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
342 /* XXX what else? */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
343 desc = "*";
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
344 /* desc = g_path_get_basename(g_path_get_dirname(*xfer->names)); */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
345 xfer->gc->prpl->file_transfer_out(xfer->gc, xfer,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
346 desc, xfer->totfiles,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
347 xfer->totsize);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
348 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
349 else
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
350 xfer->gc->prpl->file_transfer_in(xfer->gc, xfer,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
351 0); /* XXX */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
352 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
353 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
354
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
355 /* Called on outgoing transfers to get information about the
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
356 * current file.
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
357 */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
358 int transfer_get_file_info(struct file_transfer *xfer, int *size,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
359 char **name)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
360 {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
361 *size = xfer->sizes[xfer->filesdone];
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
362 *name = xfer->names[xfer->filesdone];
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
363 return 0;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
364 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
365
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
366 static int ft_choose_file(gpointer a, struct file_transfer *xfer)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
367 {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
368 char *curdir = g_get_current_dir(); /* should be freed */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
369 char *initstr;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
370
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
371 /* If the connection is interrupted while we are waiting
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
372 * for do_ask_dialog(), then we can't clean up until we
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
373 * get here, after the user makes a selection.
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
374 */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
375 if (xfer->state == FILE_TRANSFER_STATE_INTERRUPTED) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
376 xfer->state = FILE_TRANSFER_STATE_CLEANUP;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
377 transfer_abort(xfer, NULL);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
378 return 1;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
379 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
380
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
381 xfer->state = FILE_TRANSFER_STATE_CHOOSEFILE;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
382 if (xfer->type == FILE_TRANSFER_TYPE_RECEIVE)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
383 xfer->w = gtk_file_selection_new(_("Gaim - Save As..."));
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
384 else /* (xfer->type == FILE_TRANSFER_TYPE_SEND) */ {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
385 xfer->w = gtk_file_selection_new(_("Gaim - Open..."));
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
386 gtk_file_selection_set_select_multiple(GTK_FILE_SELECTION(xfer->w),
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
387 1);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
388 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
389
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
390 if (xfer->initname) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
391 initstr = g_strdup_printf("%s/%s", curdir, xfer->initname);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
392 } else
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
393 initstr = g_strconcat(curdir, "/", NULL);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
394 g_free(curdir);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
395
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
396 gtk_file_selection_set_filename(GTK_FILE_SELECTION(xfer->w),
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
397 initstr);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
398 g_free(initstr);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
399
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
400 gtk_signal_connect(GTK_OBJECT(xfer->w), "delete_event",
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
401 GTK_SIGNAL_FUNC(ft_cancel), xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
402 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(xfer->w)->cancel_button),
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
403 "clicked", GTK_SIGNAL_FUNC(ft_cancel), xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
404 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(xfer->w)->ok_button),
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
405 "clicked", GTK_SIGNAL_FUNC(ft_choose_ok), xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
406 gtk_widget_show(xfer->w);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
407
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
408 return 0;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
409 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
410
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
411 static int ft_open_file(struct file_transfer *xfer, const char *filename,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
412 int offset)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
413 {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
414 char *err = NULL;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
415
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
416 if (xfer->type == FILE_TRANSFER_TYPE_RECEIVE) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
417 xfer->file = fopen(filename,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
418 (offset > 0) ? "a" : "w");
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
419
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
420 if (!xfer->file)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
421 err = g_strdup_printf(_("Could not open %s for writing: %s"),
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
422 filename, g_strerror(errno));
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
423
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
424 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
425 else /* (xfer->type == FILE_TRANSFER_TYPE_SEND) */ {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
426 xfer->file = fopen(filename, "r");
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
427 if (!xfer->file)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
428 err = g_strdup_printf(_("Could not open %s for reading: %s"),
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
429 filename, g_strerror(errno));
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
430 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
431
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
432 if (err) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
433 do_error_dialog(err, NULL, GAIM_ERROR);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
434 g_free(err);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
435 return -1;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
436 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
437
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
438 fseek(xfer->file, offset, SEEK_SET);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
439
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
440 return 0;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
441 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
442
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
443 /* Takes a full file name, and creates any directories above it
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
444 * that don't exist already.
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
445 */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
446 static int ft_mkdir(const char *name) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
447 int ret = 0;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
448 struct stat st;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
449 mode_t m = umask(0077);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
450 char *dir;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
451
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
452 dir = g_path_get_dirname(name);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
453 if (stat(dir, &st))
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
454 ret = ft_mkdir_help(dir);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
455
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
456 g_free(dir);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
457 umask(m);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
458 return ret;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
459 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
460
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
461 /* Two functions, one recursive, just to make a directory. Yuck. */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
462 static int ft_mkdir_help(char *dir) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
463 int ret;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
464
3611
a99f6f97a3f9 [gaim-migrate @ 3724]
Rob Flynn <gaim@robflynn.com>
parents: 3610
diff changeset
465 ret = mkdir(dir, 0775);
3609
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
466 if (ret) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
467 char *index = strrchr(dir, G_DIR_SEPARATOR);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
468 if (!index)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
469 return -1;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
470 *index = '\0';
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
471 ret = ft_mkdir_help(dir);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
472 *index = G_DIR_SEPARATOR;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
473 if (!ret)
3611
a99f6f97a3f9 [gaim-migrate @ 3724]
Rob Flynn <gaim@robflynn.com>
parents: 3610
diff changeset
474 ret = mkdir(dir, 0775);
3609
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
475 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
476
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
477 return ret;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
478 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
479
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
480 int transfer_in_do(struct file_transfer *xfer, int fd,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
481 const char *filename, int size)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
482 {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
483 char *fullname;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
484
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
485 xfer->state = FILE_TRANSFER_STATE_TRANSFERRING;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
486 xfer->fd = fd;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
487 xfer->bytesleft = size;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
488
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
489 /* XXX implement resuming incoming transfers */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
490 #if 0
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
491 if (xfer->sizes)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
492 xfer->bytesleft -= xfer->sizes[0];
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
493 #endif
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
494
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
495 /* Security check */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
496 if (g_strrstr(filename, "..")) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
497 xfer->state = FILE_TRANSFER_STATE_CLEANUP;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
498 transfer_abort(xfer, _("Invalid incoming filename component"));
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
499 return -1;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
500 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
501
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
502 if (xfer->totfiles > 1)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
503 fullname = g_strconcat(xfer->dir, filename, NULL);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
504 else
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
505 /* Careful: filename is the name on the *other*
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
506 * end; don't use it here. */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
507 fullname = g_strdup(xfer->names[xfer->filesdone]);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
508
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
509
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
510 if (ft_mkdir(fullname)) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
511 xfer->state = FILE_TRANSFER_STATE_CLEANUP;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
512 transfer_abort(xfer, _("Invalid incoming filename"));
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
513 return -1;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
514 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
515
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
516 if (!ft_open_file(xfer, fullname, 0)) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
517 /* Special case: if we are receiving an empty file,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
518 * we would never enter the callback. Just avoid the
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
519 * callback altogether.
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
520 */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
521 if (xfer->bytesleft == 0)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
522 ft_nextfile(xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
523 else
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
524 xfer->watcher = gaim_input_add(fd,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
525 GAIM_INPUT_READ,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
526 ft_callback, xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
527 } else {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
528 /* Error opening file */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
529 xfer->state = FILE_TRANSFER_STATE_CLEANUP;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
530 transfer_abort(xfer, NULL);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
531 g_free(fullname);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
532 return -1;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
533 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
534
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
535 g_free(fullname);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
536 return 0;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
537 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
538
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
539 int transfer_out_do(struct file_transfer *xfer, int fd, int offset) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
540 xfer->state = FILE_TRANSFER_STATE_TRANSFERRING;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
541 xfer->fd = fd;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
542 xfer->bytesleft = xfer->sizes[xfer->filesdone] - offset;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
543
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
544 if (!ft_open_file(xfer, xfer->names[xfer->filesdone], offset)) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
545 /* Special case: see transfer_in_do().
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
546 */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
547 if (xfer->bytesleft == 0)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
548 ft_nextfile(xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
549 else
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
550 xfer->watcher = gaim_input_add(fd,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
551 GAIM_INPUT_WRITE, ft_callback,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
552 xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
553 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
554 else {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
555 /* Error opening file */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
556 xfer->state = FILE_TRANSFER_STATE_CLEANUP;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
557 transfer_abort(xfer, NULL);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
558 return -1;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
559 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
560
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
561 return 0;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
562 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
563
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
564 static void ft_callback(gpointer data, gint source,
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
565 GaimInputCondition condition)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
566 {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
567 struct file_transfer *xfer = (struct file_transfer *)data;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
568 int rt, i;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
569 char buf[FT_BUFFER_SIZE];
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
570
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
571 if (condition & GAIM_INPUT_READ) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
572 rt = read(xfer->fd, buf, MIN(xfer->bytesleft, FT_BUFFER_SIZE));
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
573 /* XXX What if the transfer is interrupted while we
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
574 * are inside read()? How can this be handled safely?
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
575 * -- wtm
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
576 */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
577 if (rt > 0) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
578 xfer->bytesleft -= rt;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
579 for (i = 0; i < rt; i++) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
580 fprintf(xfer->file, "%c", buf[i]);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
581 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
582 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
583
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
584 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
585 else /* (condition & GAIM_INPUT_WRITE) */ {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
586 int remain = MIN(xfer->bytesleft, FT_BUFFER_SIZE);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
587
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
588 for (i = 0; i < remain; i++)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
589 fscanf(xfer->file, "%c", &buf[i]);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
590
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
591 rt = write(xfer->fd, buf, remain);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
592 if (rt > 0)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
593 xfer->bytesleft -= rt;
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
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
596 if (rt < 0)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
597 return;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
598
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
599 xfer->bytessent += rt;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
600
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
601 if (xfer->gc->prpl->file_transfer_data_chunk)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
602 xfer->gc->prpl->file_transfer_data_chunk(xfer->gc, xfer, buf, rt);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
603
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
604 if (rt > 0 && xfer->bytesleft == 0) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
605 /* We are done with this file! */
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
606 gaim_input_remove(xfer->watcher);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
607 xfer->watcher = 0;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
608 fclose(xfer->file);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
609 xfer->file = 0;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
610 ft_nextfile(xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
611 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
612 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
613
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
614 static void ft_nextfile(struct file_transfer *xfer)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
615 {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
616 debug_printf("file transfer %d of %d done\n",
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
617 xfer->filesdone + 1, xfer->totfiles);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
618
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
619 if (++xfer->filesdone == xfer->totfiles) {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
620 char *msg;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
621 char *msg2;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
622
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
623 xfer->gc->prpl->file_transfer_done(xfer->gc, xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
624
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
625 if (xfer->type == FILE_TRANSFER_TYPE_RECEIVE)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
626 msg = g_strdup_printf(_("File transfer from %s to %s completed successfully."),
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
627 xfer->who, xfer->gc->username);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
628 else
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
629 msg = g_strdup_printf(_("File transfer from %s to %s completed successfully."),
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
630 xfer->gc->username, xfer->who);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
631 xfer->state = FILE_TRANSFER_STATE_DONE;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
632
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
633 if (xfer->totfiles > 1)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
634 msg2 = g_strdup_printf(_("%d files transferred."),
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
635 xfer->totfiles);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
636 else
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
637 msg2 = NULL;
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
638
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
639 do_error_dialog(msg, msg2, GAIM_INFO);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
640 g_free(msg);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
641 if (msg2)
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
642 g_free(msg2);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
643
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
644 ft_delete(xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
645 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
646 else {
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
647 xfer->gc->prpl->file_transfer_nextfile(xfer->gc, xfer);
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
648 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
649 }
4faf84dfdda2 [gaim-migrate @ 3722]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
650