Mercurial > pidgin
annotate src/rvous.c @ 214:2e0c2450280b
[gaim-migrate @ 224]
Whoops.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 03 May 2000 21:38:49 +0000 |
parents | 89c9334d3484 |
children | f7e17fb767eb |
rev | line source |
---|---|
198 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
22 #include <string.h> | |
23 #include <stdio.h> | |
24 #include <stdlib.h> | |
25 #include <time.h> | |
26 #include <sys/types.h> | |
27 #include <sys/stat.h> | |
28 #include <fcntl.h> | |
29 #include <sys/socket.h> | |
30 #include <netdb.h> | |
31 #include <netinet/in.h> | |
32 #include <unistd.h> | |
33 #include <netinet/in.h> | |
34 #include <arpa/inet.h> | |
212
89c9334d3484
[gaim-migrate @ 222]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
211
diff
changeset
|
35 #include <pthread.h> |
198 | 36 |
37 #include <gtk/gtk.h> | |
38 #include "gaim.h" | |
39 | |
40 static void do_send_file(GtkWidget *, struct file_transfer *); | |
41 static void do_get_file (GtkWidget *, struct file_transfer *); | |
42 | |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
43 static void toggle(GtkWidget *w, int *m) |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
44 { |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
45 *m = !(*m); |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
46 } |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
47 |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
48 static void free_ft(struct file_transfer *ft) |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
49 { |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
50 if (ft->window) { gtk_widget_destroy(ft->window); ft->window = NULL; } |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
51 if (ft->filename) g_free(ft->filename); |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
52 if (ft->user) g_free(ft->user); |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
53 if (ft->message) g_free(ft->message); |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
54 if (ft->ip) g_free(ft->ip); |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
55 if (ft->cookie) g_free(ft->cookie); |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
56 g_free(ft); |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
57 } |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
58 |
198 | 59 static void warn_callback(GtkWidget *widget, struct file_transfer *ft) |
60 { | |
61 show_warn_dialog(ft->user); | |
62 } | |
63 | |
64 static void info_callback(GtkWidget *widget, struct file_transfer *ft) | |
65 { | |
66 serv_get_info(ft->user); | |
67 } | |
68 | |
69 static void cancel_callback(GtkWidget *widget, struct file_transfer *ft) | |
70 { | |
71 char *send = g_malloc(256); | |
72 | |
73 if (ft->accepted) { | |
74 g_free(send); | |
75 return; | |
76 } | |
77 | |
78 g_snprintf(send, 255, "toc_rvous_cancel %s %s %s", normalize(ft->user), | |
79 ft->cookie, ft->UID); | |
80 sflap_send(send, strlen(send), TYPE_DATA); | |
81 g_free(send); | |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
82 free_ft(ft); |
198 | 83 } |
84 | |
85 static void accept_callback(GtkWidget *widget, struct file_transfer *ft) | |
86 { | |
87 char *buf = g_malloc(BUF_LEN); | |
88 char *fname = g_malloc(BUF_LEN); | |
89 char *c; | |
90 | |
91 if (!strcmp(ft->UID, FILE_SEND_UID)) { | |
92 c = ft->filename + strlen(ft->filename); | |
93 | |
94 while (c != ft->filename) { | |
95 if (*c == '/' || *c == '\\') { | |
96 strcpy(fname, c+1); | |
97 break; | |
98 } | |
99 c--; | |
100 } | |
101 | |
102 if (c == ft->filename) | |
103 strcpy(fname, ft->filename); | |
104 } | |
105 | |
106 gtk_widget_destroy(ft->window); | |
107 ft->window = NULL; | |
108 | |
109 ft->window = gtk_file_selection_new("Gaim - Save As..."); | |
110 | |
111 gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(ft->window)); | |
112 | |
113 if (!strcmp(ft->UID, FILE_SEND_UID)) | |
114 g_snprintf(buf, BUF_LEN - 1, "%s/%s", getenv("HOME"), fname); | |
115 else | |
116 g_snprintf(buf, BUF_LEN - 1, "%s/", getenv("HOME")); | |
117 gtk_file_selection_set_filename(GTK_FILE_SELECTION(ft->window), buf); | |
118 | |
119 gtk_signal_connect(GTK_OBJECT(ft->window), "destroy", | |
120 GTK_SIGNAL_FUNC(cancel_callback), ft); | |
121 | |
122 if (!strcmp(ft->UID, FILE_SEND_UID)) { | |
123 gtk_signal_connect(GTK_OBJECT( | |
124 GTK_FILE_SELECTION(ft->window)->ok_button), | |
125 "clicked", GTK_SIGNAL_FUNC(do_get_file), ft); | |
126 } else { | |
127 gtk_signal_connect(GTK_OBJECT( | |
128 GTK_FILE_SELECTION(ft->window)->ok_button), | |
129 "clicked", GTK_SIGNAL_FUNC(do_send_file), ft); | |
130 } | |
131 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(ft->window)->cancel_button), | |
132 "clicked", GTK_SIGNAL_FUNC(cancel_callback), ft); | |
133 | |
134 gtk_widget_show(ft->window); | |
135 | |
136 g_free(buf); | |
137 g_free(fname); | |
138 } | |
139 | |
140 static void do_get_file(GtkWidget *w, struct file_transfer *ft) | |
141 { | |
142 char *send = g_malloc(256); | |
143 char *file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(ft->window)); | |
144 char *buf; | |
145 char *header; | |
146 short hdrlen; | |
147 int read_rv; | |
148 char bmagic[7]; | |
149 struct sockaddr_in sin; | |
150 guint32 rcv; | |
151 char *c; | |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
152 int cont = 1; |
212
89c9334d3484
[gaim-migrate @ 222]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
211
diff
changeset
|
153 GtkWidget *fw = NULL, *fbar = NULL, *label = NULL; |
89c9334d3484
[gaim-migrate @ 222]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
211
diff
changeset
|
154 GtkWidget *button = NULL, *pct = NULL; |
211
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
210
diff
changeset
|
155 |
198 | 156 if (!(ft->f = fopen(file,"w"))) { |
157 buf = g_malloc(BUF_LONG); | |
158 g_snprintf(buf, BUF_LONG / 2, "Error writing file %s", file); | |
159 do_error_dialog(buf, "Error"); | |
160 g_free(buf); | |
161 ft->accepted = 0; | |
162 accept_callback(NULL, ft); | |
163 return; | |
164 } | |
165 | |
166 ft->accepted = 1; | |
167 | |
168 gtk_widget_destroy(ft->window); | |
169 ft->window = NULL; | |
170 g_snprintf(send, 255, "toc_rvous_accept %s %s %s", normalize(ft->user), | |
171 ft->cookie, ft->UID); | |
172 sflap_send(send, strlen(send), TYPE_DATA); | |
173 g_free(send); | |
174 | |
175 | |
176 | |
177 sin.sin_addr.s_addr = inet_addr(ft->ip); | |
178 sin.sin_family = AF_INET; | |
179 sin.sin_port = htons(ft->port); | |
180 | |
181 ft->fd = socket(AF_INET, SOCK_STREAM, 0); | |
182 | |
214
2e0c2450280b
[gaim-migrate @ 224]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
212
diff
changeset
|
183 if (ft->fd <= -1 || connect(ft->fd, (struct sockaddr *)&sin, sizeof(sin))) { |
198 | 184 return; |
185 } | |
186 | |
187 rcv = 0; | |
188 header = g_malloc(6); | |
189 while (rcv != 6) { | |
190 read_rv = read(ft->fd, header + rcv, 6 - rcv); | |
191 if(read_rv < 0) { | |
192 close(ft->fd); | |
193 g_free(header); | |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
194 free_ft(ft); |
198 | 195 return; |
196 } | |
197 rcv += read_rv; | |
198 while(gtk_events_pending()) | |
199 gtk_main_iteration(); | |
200 } | |
201 | |
202 strncpy(bmagic, header, 6); | |
203 bmagic[6] = 0; | |
204 | |
205 hdrlen = 0; | |
206 hdrlen |= (header[4] << 8) & 0xff00; | |
207 hdrlen |= (header[5] << 0) & 0x00ff; | |
208 hdrlen -= 6; | |
209 | |
210 sprintf(debug_buff, "header length %d\n", hdrlen); | |
211 debug_print(debug_buff); | |
212 | |
213 g_free(header); | |
214 header = g_malloc(hdrlen); | |
215 | |
216 rcv = 0; | |
217 | |
218 while (rcv != hdrlen) { | |
219 read_rv = read(ft->fd, header + rcv, hdrlen - rcv); | |
220 if(read_rv < 0) { | |
221 close(ft->fd); | |
222 g_free(header); | |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
223 free_ft(ft); |
198 | 224 return; |
225 } | |
226 rcv += read_rv; | |
227 while(gtk_events_pending()) | |
228 gtk_main_iteration(); | |
229 } | |
230 | |
231 c = header; | |
232 | |
233 header[0] = 2; header[1] = 2; | |
234 | |
235 buf = frombase64(ft->cookie); | |
236 memcpy(header + 2, buf, 8); | |
237 g_free(buf); | |
238 memset(header + 62, 0, 32); strcpy(header + 62, "Gaim"); | |
239 memset(header + 10, 0, 4); | |
240 header[18] = 1; header[19] = 0; | |
241 header[20] = 1; header[21] = 0; | |
242 | |
243 sprintf(debug_buff, "sending confirmation\n"); | |
244 debug_print(debug_buff); | |
245 write(ft->fd, bmagic, 6); | |
246 write(ft->fd, header, hdrlen); | |
247 | |
248 buf = g_malloc(1024); | |
249 rcv = 0; | |
250 | |
251 fw = gtk_dialog_new(); | |
252 buf = g_malloc(2048); | |
212
89c9334d3484
[gaim-migrate @ 222]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
211
diff
changeset
|
253 snprintf(buf, 2048, "Receiving %s from %s", ft->filename, ft->user); |
198 | 254 label = gtk_label_new(buf); |
255 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(fw)->vbox), label, 0, 0, 5); | |
256 gtk_widget_show(label); | |
257 fbar = gtk_progress_bar_new(); | |
258 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(fw)->action_area), fbar, 0, 0, 5); | |
259 gtk_widget_show(fbar); | |
212
89c9334d3484
[gaim-migrate @ 222]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
211
diff
changeset
|
260 pct = gtk_label_new("0 %"); |
89c9334d3484
[gaim-migrate @ 222]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
211
diff
changeset
|
261 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(fw)->action_area), pct, 0, 0, 5); |
89c9334d3484
[gaim-migrate @ 222]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
211
diff
changeset
|
262 gtk_widget_show(pct); |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
263 button = gtk_button_new_with_label("Cancel"); |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
264 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(fw)->action_area), button, 0, 0, 5); |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
265 gtk_widget_show(button); |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
266 gtk_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc)toggle, &cont); |
212
89c9334d3484
[gaim-migrate @ 222]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
211
diff
changeset
|
267 gtk_window_set_title(GTK_WINDOW(fw), "Gaim - File Transfer"); |
198 | 268 gtk_widget_realize(fw); |
269 aol_icon(fw->window); | |
270 gtk_widget_show(fw); | |
271 | |
272 sprintf(debug_buff, "Receiving %s from %s (%d bytes)\n", ft->filename, | |
273 ft->user, ft->size); | |
274 debug_print(debug_buff); | |
275 | |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
276 while (rcv != ft->size && cont) { |
198 | 277 int i; |
278 int remain = ft->size - rcv > 1024 ? 1024 : ft->size - rcv; | |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
279 read_rv = recv(ft->fd, buf, remain, O_NONBLOCK); |
198 | 280 if(read_rv < 0) { |
281 fclose(ft->f); | |
282 close(ft->fd); | |
283 g_free(buf); | |
284 g_free(header); | |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
285 free_ft(ft); |
198 | 286 return; |
287 } | |
288 rcv += read_rv; | |
289 for (i = 0; i < read_rv; i++) | |
290 fprintf(ft->f, "%c", buf[i]); | |
212
89c9334d3484
[gaim-migrate @ 222]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
211
diff
changeset
|
291 snprintf(buf, 2048, "Receiving %s from %s", |
89c9334d3484
[gaim-migrate @ 222]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
211
diff
changeset
|
292 header + 186, ft->user); |
198 | 293 gtk_label_set_text(GTK_LABEL(label), buf); |
294 gtk_progress_bar_update(GTK_PROGRESS_BAR(fbar), | |
295 (float)(rcv)/(float)(ft->size)); | |
212
89c9334d3484
[gaim-migrate @ 222]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
211
diff
changeset
|
296 sprintf(buf, "%d / %d K (%2.0f %%)", rcv/1024, ft->size/1024, |
89c9334d3484
[gaim-migrate @ 222]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
211
diff
changeset
|
297 100*((float)rcv)/((float)ft->size)); |
89c9334d3484
[gaim-migrate @ 222]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
211
diff
changeset
|
298 gtk_label_set_text(GTK_LABEL(pct), buf); |
198 | 299 while(gtk_events_pending()) |
300 gtk_main_iteration(); | |
301 } | |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
302 fclose(ft->f); |
201
d9a5f7b1d500
[gaim-migrate @ 211]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
303 gtk_widget_destroy(fw); |
d9a5f7b1d500
[gaim-migrate @ 211]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
304 fw = NULL; |
198 | 305 |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
306 if (!cont) { |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
307 char *tmp = frombase64(ft->cookie); |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
308 sprintf(buf, "toc_rvous_cancel %s %s %s", ft->user, tmp, ft->UID); |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
309 sflap_send(buf, strlen(buf), TYPE_DATA); |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
310 close(ft->fd); |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
311 free_ft(ft); |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
312 return; |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
313 } |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
314 |
198 | 315 memset(header + 18, 0, 4); |
316 header[94] = 0; | |
317 header[1] = 0x04; | |
318 memcpy(header+58, header+34, 4); | |
319 memcpy(header+54, header+22, 4); | |
320 write(ft->fd, bmagic, 6); | |
321 write(ft->fd, header, hdrlen); | |
322 close(ft->fd); | |
323 | |
324 g_free(buf); | |
325 g_free(header); | |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
326 free_ft(ft); |
198 | 327 } |
328 | |
329 static void do_send_file(GtkWidget *w, struct file_transfer *ft) { | |
330 char *send = g_malloc(256); | |
331 char *file = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(ft->window))); | |
332 char *buf; | |
333 int read_rv; | |
334 struct file_header *fhdr = g_new0(struct file_header, 1); | |
335 struct sockaddr_in sin; | |
336 guint32 rcv; | |
203
4fa63e83406b
[gaim-migrate @ 213]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
202
diff
changeset
|
337 char *c; |
198 | 338 struct stat st; |
204
579e59e66381
[gaim-migrate @ 214]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
203
diff
changeset
|
339 struct tm *fortime; |
198 | 340 |
341 stat(file, &st); | |
342 if (!(ft->f = fopen(file, "r"))) { | |
343 buf = g_malloc(BUF_LONG); | |
344 g_snprintf(buf, BUF_LONG / 2, "Error reading file %s", file); | |
345 do_error_dialog(buf, "Error"); | |
346 g_free(buf); | |
347 ft->accepted = 0; | |
348 accept_callback(NULL, ft); | |
349 return; | |
350 } | |
351 | |
352 ft->accepted = 1; | |
353 | |
354 gtk_widget_destroy(ft->window); | |
355 ft->window = NULL; | |
356 g_snprintf(send, 255, "toc_rvous_accept %s %s %s", normalize(ft->user), | |
357 ft->cookie, ft->UID); | |
358 sflap_send(send, strlen(send), TYPE_DATA); | |
359 g_free(send); | |
360 | |
361 | |
362 | |
363 sin.sin_addr.s_addr = inet_addr(ft->ip); | |
364 sin.sin_family = AF_INET; | |
365 sin.sin_port = htons(ft->port); | |
366 | |
367 ft->fd = socket(AF_INET, SOCK_STREAM, 0); | |
368 | |
214
2e0c2450280b
[gaim-migrate @ 224]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
212
diff
changeset
|
369 if (ft->fd <= -1 || connect(ft->fd, (struct sockaddr *)&sin, sizeof(sin))) { |
198 | 370 return; |
371 } | |
372 | |
373 /* here's where we differ from do_get_file */ | |
374 /* 1. build/send header | |
375 * 2. receive header | |
201
d9a5f7b1d500
[gaim-migrate @ 211]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
376 * 3. send listing file |
d9a5f7b1d500
[gaim-migrate @ 211]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
377 * 4. receive header |
d9a5f7b1d500
[gaim-migrate @ 211]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
378 * |
d9a5f7b1d500
[gaim-migrate @ 211]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
379 * then we need to wait to actually send the file. |
198 | 380 */ |
381 | |
382 /* 1. build/send header */ | |
203
4fa63e83406b
[gaim-migrate @ 213]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
202
diff
changeset
|
383 c = file + strlen(file); |
4fa63e83406b
[gaim-migrate @ 213]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
202
diff
changeset
|
384 while (*(c - 1) != '/') c--; |
198 | 385 buf = frombase64(ft->cookie); |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
386 sprintf(debug_buff, "Building header to send %s (cookie: %s)\n", file, buf); |
198 | 387 debug_print(debug_buff); |
211
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
210
diff
changeset
|
388 fhdr->magic[0] = 'O'; fhdr->magic[1] = 'F'; |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
210
diff
changeset
|
389 fhdr->magic[2] = 'T'; fhdr->magic[3] = '2'; |
210
ec0686b3b03f
[gaim-migrate @ 220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
205
diff
changeset
|
390 fhdr->hdrlen = 256; |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
391 fhdr->hdrtype = 0x1108; |
202
bcc54ee34531
[gaim-migrate @ 212]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
201
diff
changeset
|
392 snprintf(fhdr->bcookie, 8, "%s", buf); |
198 | 393 g_free(buf); |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
394 fhdr->encrypt = 0; |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
395 fhdr->compress = 0; |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
396 fhdr->totfiles = 1; |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
397 fhdr->filesleft = 1; |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
398 fhdr->totparts = 1; |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
399 fhdr->partsleft = 1; |
211
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
210
diff
changeset
|
400 fhdr->totsize = (long)st.st_size; /* combined size of all files */ |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
210
diff
changeset
|
401 /* size = strlen("mm/dd/yyyy hh:mm sizesize 'name'\r\n") */ |
203
4fa63e83406b
[gaim-migrate @ 213]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
202
diff
changeset
|
402 fhdr->size = 30 + strlen(c); /* size of listing.txt */ |
4fa63e83406b
[gaim-migrate @ 213]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
202
diff
changeset
|
403 fhdr->modtime = time(NULL); /* time since UNIX epoch */ |
211
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
210
diff
changeset
|
404 fhdr->checksum = 0x89f70000; /* ? this is the only thing i have wrong */ |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
405 fhdr->rfrcsum = 0; |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
406 fhdr->rfsize = 0; |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
407 fhdr->cretime = 0; |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
408 fhdr->rfcsum = 0; |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
409 fhdr->nrecvd = 0; |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
410 fhdr->recvcsum = 0; |
211
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
210
diff
changeset
|
411 snprintf(fhdr->idstring, 32, "OFT_Windows ICBMFT V1.1 32"); |
205
5531861bf3f5
[gaim-migrate @ 215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
204
diff
changeset
|
412 fhdr->flags = 0x02; /* don't ask me why */ |
202
bcc54ee34531
[gaim-migrate @ 212]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
201
diff
changeset
|
413 fhdr->lnameoffset = 0x1A; /* ? still no clue */ |
bcc54ee34531
[gaim-migrate @ 212]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
201
diff
changeset
|
414 fhdr->lsizeoffset = 0x10; /* whatever */ |
205
5531861bf3f5
[gaim-migrate @ 215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
204
diff
changeset
|
415 memset(fhdr->dummy, 0, 69); |
5531861bf3f5
[gaim-migrate @ 215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
204
diff
changeset
|
416 memset(fhdr->macfileinfo, 0, 16); |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
417 fhdr->nencode = 0; |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
418 fhdr->nlanguage = 0; |
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
198
diff
changeset
|
419 snprintf(fhdr->name, 64, "listing.txt"); |
210
ec0686b3b03f
[gaim-migrate @ 220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
205
diff
changeset
|
420 read_rv = write(ft->fd, fhdr, 256); |
198 | 421 if (read_rv <= -1) { |
210
ec0686b3b03f
[gaim-migrate @ 220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
205
diff
changeset
|
422 sprintf(debug_buff, "Couldn't write opening header\n"); |
198 | 423 debug_print(debug_buff); |
424 close(ft->fd); | |
425 return; | |
426 } | |
427 | |
428 /* 2. receive header */ | |
429 sprintf(debug_buff, "Receiving header\n"); | |
430 debug_print(debug_buff); | |
210
ec0686b3b03f
[gaim-migrate @ 220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
205
diff
changeset
|
431 read_rv = read(ft->fd, fhdr, 256); |
198 | 432 if (read_rv <= -1) { |
433 sprintf(debug_buff, "Couldn't read header\n"); | |
434 debug_print(debug_buff); | |
435 close(ft->fd); | |
436 return; | |
437 } | |
438 | |
201
d9a5f7b1d500
[gaim-migrate @ 211]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
439 /* 3. send listing file */ |
203
4fa63e83406b
[gaim-migrate @ 213]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
202
diff
changeset
|
440 /* mm/dd/yyyy hh:mm sizesize name.ext\r\n */ |
4fa63e83406b
[gaim-migrate @ 213]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
202
diff
changeset
|
441 /* creation date ^ */ |
198 | 442 sprintf(debug_buff, "Sending file\n"); |
443 debug_print(debug_buff); | |
444 rcv = 0; | |
204
579e59e66381
[gaim-migrate @ 214]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
203
diff
changeset
|
445 buf = g_malloc(ft->size + 1); |
579e59e66381
[gaim-migrate @ 214]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
203
diff
changeset
|
446 fortime = localtime(&st.st_ctime); |
579e59e66381
[gaim-migrate @ 214]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
203
diff
changeset
|
447 snprintf(buf, ft->size + 1, "%2d/%2d/%4d %2d:%2d %8ld %s\r\n", |
579e59e66381
[gaim-migrate @ 214]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
203
diff
changeset
|
448 fortime->tm_mon + 1, fortime->tm_mday, fortime->tm_year + 1900, |
579e59e66381
[gaim-migrate @ 214]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
203
diff
changeset
|
449 fortime->tm_hour + 1, fortime->tm_min + 1, |
579e59e66381
[gaim-migrate @ 214]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
203
diff
changeset
|
450 st.st_size, c); |
579e59e66381
[gaim-migrate @ 214]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
203
diff
changeset
|
451 sprintf(debug_buff, "Sending listing.txt to %s\n", ft->user); |
198 | 452 debug_print(debug_buff); |
453 | |
204
579e59e66381
[gaim-migrate @ 214]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
203
diff
changeset
|
454 while (rcv != ft->size) { |
198 | 455 int remain = st.st_size - rcv > 1024 ? 1024 : st.st_size - rcv; |
204
579e59e66381
[gaim-migrate @ 214]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
203
diff
changeset
|
456 read_rv = write(ft->fd, buf + rcv, remain); |
198 | 457 if (read_rv <= -1) { |
458 sprintf(debug_buff, "Could not send file, wrote %d\n", rcv); | |
459 debug_print(debug_buff); | |
460 close(ft->fd); | |
461 return; | |
462 } | |
463 rcv += read_rv; | |
464 while(gtk_events_pending()) | |
465 gtk_main_iteration(); | |
466 } | |
467 | |
201
d9a5f7b1d500
[gaim-migrate @ 211]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
468 /* 4. receive header */ |
198 | 469 sprintf(debug_buff, "Receiving closing header\n"); |
470 debug_print(debug_buff); | |
210
ec0686b3b03f
[gaim-migrate @ 220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
205
diff
changeset
|
471 read_rv = read(ft->fd, fhdr, 256); |
198 | 472 if (read_rv <= -1) { |
473 sprintf(debug_buff, "Couldn't read closing header\n"); | |
474 debug_print(debug_buff); | |
475 close(ft->fd); | |
476 return; | |
477 } | |
478 | |
479 fclose(ft->f); | |
480 close(ft->fd); | |
481 g_free(fhdr); | |
482 } | |
483 | |
484 void accept_file_dialog(struct file_transfer *ft) | |
485 { | |
486 GtkWidget *accept, *info, *warn, *cancel; | |
487 GtkWidget *label; | |
488 GtkWidget *vbox, *bbox; | |
489 char buf[1024]; | |
490 | |
491 | |
492 ft->window = gtk_window_new(GTK_WINDOW_DIALOG); | |
493 | |
494 accept = gtk_button_new_with_label("Accept"); | |
495 info = gtk_button_new_with_label("Info"); | |
496 warn = gtk_button_new_with_label("Warn"); | |
497 cancel = gtk_button_new_with_label("Cancel"); | |
498 | |
499 bbox = gtk_hbox_new(TRUE, 10); | |
500 vbox = gtk_vbox_new(FALSE, 5); | |
501 | |
502 gtk_widget_show(accept); | |
503 gtk_widget_show(info); | |
504 gtk_widget_show(warn); | |
505 gtk_widget_show(cancel); | |
506 | |
507 gtk_box_pack_start(GTK_BOX(bbox), accept, TRUE, TRUE, 10); | |
508 gtk_box_pack_start(GTK_BOX(bbox), info, TRUE, TRUE, 10); | |
509 gtk_box_pack_start(GTK_BOX(bbox), warn, TRUE, TRUE, 10); | |
510 gtk_box_pack_start(GTK_BOX(bbox), cancel, TRUE, TRUE, 10); | |
511 | |
512 if (!strcmp(ft->UID, FILE_SEND_UID)) { | |
513 g_snprintf(buf, sizeof(buf), "%s requests you to accept the file: %s (%d bytes)", | |
514 ft->user, ft->filename, ft->size); | |
515 } else { | |
516 g_snprintf(buf, sizeof(buf), "%s requests you to send them a file", | |
517 ft->user); | |
518 } | |
211
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
210
diff
changeset
|
519 if (ft->message) |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
210
diff
changeset
|
520 strncat(buf, ft->message, sizeof(buf) - strlen(buf)); |
198 | 521 label = gtk_label_new(buf); |
522 gtk_widget_show(label); | |
523 gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 5); | |
524 gtk_box_pack_start(GTK_BOX(vbox), bbox, TRUE, TRUE, 5); | |
525 | |
526 gtk_window_set_title(GTK_WINDOW(ft->window), "Gaim - File Transfer?"); | |
527 gtk_window_set_focus(GTK_WINDOW(ft->window), accept); | |
528 gtk_container_add(GTK_CONTAINER(ft->window), vbox); | |
529 gtk_container_border_width(GTK_CONTAINER(ft->window), 10); | |
530 gtk_widget_show(vbox); | |
531 gtk_widget_show(bbox); | |
532 gtk_widget_realize(ft->window); | |
533 aol_icon(ft->window->window); | |
534 | |
535 gtk_widget_show(ft->window); | |
536 | |
537 | |
538 gtk_signal_connect(GTK_OBJECT(accept), "clicked", | |
539 GTK_SIGNAL_FUNC(accept_callback), ft); | |
540 gtk_signal_connect(GTK_OBJECT(cancel), "clicked", | |
541 GTK_SIGNAL_FUNC(cancel_callback), ft); | |
542 gtk_signal_connect(GTK_OBJECT(warn), "clicked", | |
543 GTK_SIGNAL_FUNC(warn_callback), ft); | |
544 gtk_signal_connect(GTK_OBJECT(info), "clicked", | |
545 GTK_SIGNAL_FUNC(info_callback), ft); | |
546 | |
547 | |
548 if (ft->message) { | |
549 /* we'll do this later | |
550 while(gtk_events_pending()) | |
551 gtk_main_iteration(); | |
552 html_print(text, ft->message); | |
553 */ | |
554 } | |
555 } |