Mercurial > gftp.yaz
annotate src/gtk/transfer.c @ 40:66c064fd05bc
2002-10-17 Brian Masney <masneyb@gftp.org>
* lib/protocols.c - add gftp_abort_transfer function. Also, in
gftp_transfer_file, when we do a gftp_put_file, if that fails,
try to abort the transfer.
* lib/rfc959.c - add rfc959_abort_transfer function
* lib/rfc2068.c, lib/local.c - point abort_transfer pointer to
rfc2068_end_transfer and local_end_transfer respectively
* lib/ssh.c, lib/sshv2.c - add FIXME to implement abort function
* src/gtk/transfer.c - when we stop a transfer, try to abort it
first. If that fails, disconnect from the site completely
author | masneyb |
---|---|
date | Fri, 18 Oct 2002 02:53:52 +0000 |
parents | 5a178bd04ca5 |
children | 4bcfaf6307b5 |
rev | line source |
---|---|
1 | 1 /*****************************************************************************/ |
2 /* transfer.c - functions to handle transfering files */ | |
3 /* Copyright (C) 1998-2002 Brian Masney <masneyb@gftp.org> */ | |
4 /* */ | |
5 /* This program is free software; you can redistribute it and/or modify */ | |
6 /* it under the terms of the GNU General Public License as published by */ | |
7 /* the Free Software Foundation; either version 2 of the License, or */ | |
8 /* (at your option) any later version. */ | |
9 /* */ | |
10 /* This program is distributed in the hope that it will be useful, */ | |
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ | |
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ | |
13 /* GNU General Public License for more details. */ | |
14 /* */ | |
15 /* You should have received a copy of the GNU General Public License */ | |
16 /* along with this program; if not, write to the Free Software */ | |
17 /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
18 /*****************************************************************************/ | |
19 | |
20 #include <gftp-gtk.h> | |
33 | 21 static const char cvsid[] = "$Id$"; |
1 | 22 |
23 static void *getdir_thread ( void *data ); | |
24 static void *connect_thread ( void *data ); | |
25 static void on_next_transfer ( gftp_transfer * tdata ); | |
26 static void show_transfer ( gftp_transfer * tdata ); | |
27 static void transfer_done ( GList * node ); | |
28 static void create_transfer ( gftp_transfer * tdata ); | |
29 static void update_file_status ( gftp_transfer * tdata ); | |
30 static void trans_selectall ( GtkWidget * widget, | |
31 gpointer data ); | |
32 static void trans_unselectall ( GtkWidget * widget, | |
33 gpointer data ); | |
34 static void overwrite ( GtkWidget * widget, | |
35 gpointer data ); | |
36 static void resume ( GtkWidget * widget, | |
37 gpointer data ); | |
38 static void skip ( GtkWidget * widget, | |
39 gpointer data ); | |
40 static void ok ( GtkWidget * widget, | |
41 gpointer data ); | |
42 static void cancel ( GtkWidget * widget, | |
43 gpointer data ); | |
44 static void gftp_gtk_calc_kbs ( gftp_transfer * tdata, | |
45 ssize_t num_read ); | |
46 static void check_done_process ( void ); | |
19 | 47 static void do_upload ( gftp_viewedit_data * ve_proc, |
48 gftp_dialog_data * ddata ); | |
49 static void dont_upload ( gftp_viewedit_data * ve_proc, | |
50 gftp_dialog_data * ddata ); | |
51 static void free_edit_data ( gftp_viewedit_data *ve_proc ); | |
1 | 52 static int get_status ( gftp_transfer * tdata, |
53 ssize_t num_read ); | |
54 static void wakeup_main_thread ( gpointer data, | |
55 gint source, | |
56 GdkInputCondition condition ); | |
57 static gint setup_wakeup_main_thread ( gftp_request * request ); | |
58 static void teardown_wakeup_main_thread ( gftp_request * request, | |
59 gint handler ); | |
60 static mode_t parse_attribs ( char *attribs ); | |
61 static void remove_file ( char *filename ); | |
62 static RETSIGTYPE sig_connquit ( int signo ); | |
63 | |
64 static sigjmp_buf connenvir; | |
65 static GtkWidget * dialog; | |
66 | |
67 int | |
68 ftp_list_files (gftp_window_data * wdata, int usecache) | |
69 { | |
70 guint handler; | |
71 void *success; | |
72 | |
73 gtk_label_set (GTK_LABEL (wdata->hoststxt), _("Receiving file names...")); | |
33 | 74 if (gftp_is_started) |
75 fix_display (); | |
76 | |
1 | 77 wdata->show_selected = 0; |
78 if (wdata->files == NULL) | |
79 { | |
80 if (check_reconnect (wdata) < 0) | |
81 return (0); | |
82 | |
83 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
84 wdata->request->stopable = 1; | |
85 if (wdata->request->use_threads) | |
86 { | |
87 gtk_widget_set_sensitive (stop_btn, 1); | |
88 | |
89 handler = setup_wakeup_main_thread (wdata->request); | |
90 pthread_create (&wdata->tid, NULL, getdir_thread, wdata->request); | |
91 while (wdata->request->stopable) | |
31 | 92 { |
33 | 93 GDK_THREADS_LEAVE (); |
31 | 94 g_main_iteration (TRUE); |
95 } | |
1 | 96 teardown_wakeup_main_thread (wdata->request, handler); |
97 | |
98 pthread_join (wdata->tid, &success); | |
99 gtk_widget_set_sensitive (stop_btn, 0); | |
100 } | |
101 else | |
102 success = getdir_thread (wdata->request); | |
103 wdata->files = success; | |
104 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
105 memset (&wdata->tid, 0, sizeof (wdata->tid)); | |
106 } | |
107 | |
108 if (wdata->files == NULL || !GFTP_IS_CONNECTED (wdata->request)) | |
109 { | |
110 disconnect (wdata); | |
111 return (0); | |
112 } | |
113 | |
114 wdata->sorted = 0; | |
37 | 115 sortrows (GTK_CLIST (wdata->listbox), *wdata->sortcol, (gpointer) wdata); |
1 | 116 if (IS_NONE_SELECTED (wdata)) |
117 gtk_clist_select_row (GTK_CLIST (wdata->listbox), 0, 0); | |
118 return (1); | |
119 } | |
120 | |
121 | |
122 static void * | |
123 getdir_thread (void * data) | |
124 { | |
125 int sj, havedotdot, got; | |
126 gftp_request * request; | |
127 gftp_file * fle; | |
128 GList * files; | |
129 | |
130 request = data; | |
131 request->user_data = (void *) 0x1; | |
132 | |
133 if (request->use_threads) | |
134 { | |
135 sj = sigsetjmp (connenvir, 1); | |
136 signal (SIGINT, sig_connquit); | |
137 signal (SIGALRM, sig_connquit); | |
138 } | |
139 else | |
140 sj = 0; | |
141 | |
142 files = NULL; | |
143 if (sj == 0 || sj == 2) | |
144 { | |
145 if (gftp_list_files (request) != 0 || !GFTP_IS_CONNECTED (request)) | |
146 { | |
147 if (request->use_threads) | |
148 { | |
149 signal (SIGINT, SIG_DFL); | |
150 signal (SIGALRM, SIG_IGN); | |
151 } | |
152 request->user_data = NULL; | |
153 request->stopable = 0; | |
154 if (request->wakeup_main_thread[1] > 0) | |
155 write (request->wakeup_main_thread[1], " ", 1); | |
156 return (NULL); | |
157 } | |
158 | |
159 request->gotbytes = 0; | |
160 havedotdot = 0; | |
161 fle = g_malloc0 (sizeof (*fle)); | |
162 while ((got = gftp_get_next_file (request, NULL, fle)) > 0) | |
163 { | |
164 request->gotbytes += got; | |
165 if (strcmp (fle->file, ".") == 0) | |
166 { | |
167 gftp_file_destroy (fle); | |
168 continue; | |
169 } | |
170 else if (strcmp (fle->file, "..") == 0) | |
171 havedotdot = 1; | |
172 | |
173 files = g_list_append (files, fle); | |
174 fle = g_malloc0 (sizeof (*fle)); | |
175 } | |
176 g_free (fle); | |
177 | |
178 if (!GFTP_IS_CONNECTED (request)) | |
179 { | |
180 if (request->use_threads) | |
181 { | |
182 signal (SIGINT, SIG_DFL); | |
183 signal (SIGALRM, SIG_IGN); | |
184 } | |
185 request->user_data = NULL; | |
186 request->stopable = 0; | |
187 if (request->wakeup_main_thread[1] > 0) | |
188 write (request->wakeup_main_thread[1], " ", 1); | |
189 return (NULL); | |
190 } | |
191 | |
192 gftp_end_transfer (request); | |
193 request->gotbytes = -1; | |
194 | |
195 if (!havedotdot) | |
196 { | |
197 fle = g_malloc0 (sizeof (*fle)); | |
198 fle->file = g_malloc (3); | |
199 strcpy (fle->file, ".."); | |
200 fle->user = g_malloc0 (1); | |
201 fle->group = g_malloc0 (1); | |
202 fle->attribs = g_malloc0 (1); | |
203 *fle->attribs = '\0'; | |
204 fle->isdir = 1; | |
205 files = g_list_prepend (files, fle); | |
206 } | |
207 } | |
208 | |
209 request->user_data = NULL; | |
210 if (request->use_threads) | |
211 { | |
212 signal (SIGINT, SIG_DFL); | |
213 signal (SIGALRM, SIG_IGN); | |
214 } | |
215 request->stopable = 0; | |
216 if (request->wakeup_main_thread[1] > 0) | |
217 write (request->wakeup_main_thread[1], " ", 1); | |
218 return (files); | |
219 } | |
220 | |
221 | |
19 | 222 static void |
223 try_connect_again (gftp_request * request, gftp_dialog_data * ddata) | |
224 { | |
225 gftp_set_password (request, gtk_entry_get_text (GTK_ENTRY (ddata->edit))); | |
226 request->stopable = 0; | |
227 } | |
228 | |
229 | |
230 static void | |
231 dont_connect_again (gftp_request * request, gftp_dialog_data * ddata) | |
232 { | |
233 request->stopable = 0; | |
234 } | |
235 | |
236 | |
1 | 237 int |
238 ftp_connect (gftp_window_data * wdata, gftp_request * request, int getdir) | |
239 { | |
240 int success; | |
241 guint handler; | |
242 void *ret; | |
243 | |
244 ret = 0; | |
245 if (wdata->request == request) | |
246 { | |
247 gtk_label_set (GTK_LABEL (wdata->hoststxt), _("Connecting...")); | |
248 } | |
249 | |
7 | 250 if (request->need_userpass && request->username != NULL && |
251 *request->username != '\0' && | |
252 (request->password == NULL || *request->password == '\0')) | |
1 | 253 { |
254 if (wdata && wdata->request == request) | |
255 { | |
256 request->stopable = 1; | |
257 MakeEditDialog (_("Enter Password"), | |
258 _("Please enter your password for this site"), NULL, | |
19 | 259 0, NULL, gftp_dialog_button_connect, |
260 try_connect_again, request, | |
261 dont_connect_again, request); | |
31 | 262 |
1 | 263 while (request->stopable) |
31 | 264 { |
33 | 265 GDK_THREADS_LEAVE (); |
31 | 266 g_main_iteration (TRUE); |
267 } | |
1 | 268 |
269 if (GFTP_GET_PASSWORD (request) == NULL || | |
270 *GFTP_GET_PASSWORD (request) == '\0') | |
271 return (0); | |
272 } | |
273 else | |
274 gftp_set_password (request, ""); | |
275 } | |
276 | |
277 if (wdata && wdata->request == request && request->use_threads) | |
278 { | |
279 request->stopable = 1; | |
280 if (wdata) | |
281 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
282 gtk_widget_set_sensitive (stop_btn, 1); | |
283 pthread_create (&wdata->tid, NULL, connect_thread, request); | |
284 | |
285 handler = setup_wakeup_main_thread (wdata->request); | |
286 while (request->stopable) | |
31 | 287 { |
33 | 288 GDK_THREADS_LEAVE (); |
31 | 289 g_main_iteration (TRUE); |
290 } | |
1 | 291 pthread_join (wdata->tid, &ret); |
292 teardown_wakeup_main_thread (wdata->request, handler); | |
293 | |
294 gtk_widget_set_sensitive (stop_btn, 0); | |
295 if (wdata) | |
296 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
297 } | |
298 else | |
299 ret = connect_thread (request); | |
300 success = (int) ret; | |
301 memset (&wdata->tid, 0, sizeof (wdata->tid)); | |
302 | |
303 if (!GFTP_IS_CONNECTED (wdata->request)) | |
304 disconnect (wdata); | |
305 else if (success) | |
306 { | |
307 ftp_list_files (wdata, 1); | |
308 if (!GFTP_IS_CONNECTED (wdata->request)) | |
309 disconnect (wdata); | |
310 } | |
311 | |
312 return (success); | |
313 } | |
314 | |
315 | |
316 static void * | |
317 connect_thread (void *data) | |
318 { | |
319 static int conn_num; | |
320 gftp_request * request; | |
321 int ret, sj; | |
322 | |
323 request = data; | |
324 request->user_data = (void *) 0x1; | |
325 | |
326 conn_num = 0; | |
327 if (request->use_threads) | |
328 { | |
329 sj = sigsetjmp (connenvir, 1); | |
330 signal (SIGINT, sig_connquit); | |
331 signal (SIGALRM, sig_connquit); | |
332 } | |
333 else | |
334 sj = 0; | |
335 | |
336 ret = 0; | |
337 if (sj != 0) | |
338 { | |
339 ret = 0; | |
340 gftp_disconnect (request); | |
341 } | |
342 | |
343 while (sj != 1 && (request->retries == 0 || conn_num < request->retries)) | |
344 { | |
345 conn_num++; | |
346 if (request->network_timeout > 0) | |
347 alarm (request->network_timeout); | |
348 ret = gftp_connect (request) == 0; | |
349 alarm (0); | |
350 | |
351 if (ret) | |
352 break; | |
353 else if (request->retries == 0 || conn_num < request->retries) | |
354 { | |
355 request->logging_function (gftp_logging_misc, request->user_data, | |
356 _("Waiting %d seconds until trying to connect again\n"), | |
357 request->sleep_time); | |
358 alarm (request->sleep_time); | |
359 pause (); | |
360 } | |
361 } | |
362 | |
363 if (request->use_threads) | |
364 { | |
365 signal (SIGINT, SIG_DFL); | |
366 signal (SIGALRM, SIG_IGN); | |
367 } | |
368 | |
369 request->user_data = NULL; | |
370 request->stopable = 0; | |
371 if (request->wakeup_main_thread[1] > 0) | |
372 write (request->wakeup_main_thread[1], " ", 1); | |
373 return ((void *) ret); | |
374 } | |
375 | |
376 | |
377 void | |
378 get_files (gpointer data) | |
379 { | |
380 transfer_window_files (&window2, &window1); | |
381 } | |
382 | |
383 | |
384 void | |
385 put_files (gpointer data) | |
386 { | |
387 transfer_window_files (&window1, &window2); | |
388 } | |
389 | |
390 | |
391 void | |
392 transfer_window_files (gftp_window_data * fromwdata, gftp_window_data * towdata) | |
393 { | |
394 gftp_file * tempfle, * newfle; | |
395 GList * templist, * filelist; | |
396 gftp_transfer * transfer; | |
397 guint timeout_num; | |
398 void *ret; | |
399 int num; | |
400 | |
401 if (!check_status (_("Transfer Files"), fromwdata, 1, 0, 1, | |
402 towdata->request->put_file != NULL && fromwdata->request->get_file != NULL)) | |
403 return; | |
404 | |
405 if (!GFTP_IS_CONNECTED (fromwdata->request) || | |
406 !GFTP_IS_CONNECTED (towdata->request)) | |
407 { | |
408 ftp_log (gftp_logging_misc, NULL, | |
409 _("Retrieve Files: Not connected to a remote site\n")); | |
410 return; | |
411 } | |
412 | |
413 if (check_reconnect (fromwdata) < 0 || check_reconnect (towdata) < 0) | |
414 return; | |
415 | |
416 transfer = g_malloc0 (sizeof (*transfer)); | |
417 transfer->fromreq = copy_request (fromwdata->request); | |
418 transfer->toreq = copy_request (towdata->request); | |
419 transfer->transfer_direction = fromwdata == &window2 ? | |
420 GFTP_DIRECTION_DOWNLOAD : GFTP_DIRECTION_UPLOAD; | |
421 transfer->fromwdata = fromwdata; | |
422 transfer->towdata = towdata; | |
423 | |
424 num = 0; | |
425 templist = GTK_CLIST (fromwdata->listbox)->selection; | |
426 filelist = fromwdata->files; | |
427 while (templist != NULL) | |
428 { | |
429 templist = get_next_selection (templist, &filelist, &num); | |
430 tempfle = filelist->data; | |
431 if (strcmp (tempfle->file, "..") != 0) | |
432 { | |
433 newfle = copy_fdata (tempfle); | |
434 transfer->files = g_list_append (transfer->files, newfle); | |
435 } | |
436 } | |
437 | |
438 if (transfer->files != NULL) | |
439 { | |
440 swap_socks (transfer->fromreq, fromwdata->request); | |
441 swap_socks (transfer->toreq, towdata->request); | |
442 | |
443 if (transfer->fromreq->use_threads || | |
444 (transfer->toreq && transfer->toreq->use_threads)) | |
445 { | |
446 transfer->fromreq->stopable = 1; | |
447 pthread_create (&fromwdata->tid, NULL, do_getdir_thread, transfer); | |
448 | |
449 timeout_num = gtk_timeout_add (100, progress_timeout, transfer); | |
450 | |
451 while (transfer->fromreq->stopable) | |
31 | 452 { |
33 | 453 GDK_THREADS_LEAVE (); |
31 | 454 g_main_iteration (TRUE); |
455 } | |
1 | 456 |
457 gtk_timeout_remove (timeout_num); | |
458 transfer->numfiles = transfer->numdirs = -1; | |
459 update_directory_download_progress (transfer); | |
460 | |
461 pthread_join (fromwdata->tid, &ret); | |
462 } | |
463 else | |
464 ret = do_getdir_thread (transfer); | |
465 | |
466 if (!GFTP_IS_CONNECTED (transfer->fromreq)) | |
467 { | |
468 disconnect (fromwdata); | |
469 return; | |
470 } | |
471 | |
472 if (!GFTP_IS_CONNECTED (transfer->toreq)) | |
473 { | |
474 disconnect (towdata); | |
475 return; | |
476 } | |
477 | |
478 swap_socks (fromwdata->request, transfer->fromreq); | |
479 swap_socks (towdata->request, transfer->toreq); | |
480 } | |
481 | |
482 if (transfer->files != NULL) | |
483 { | |
484 add_file_transfer (transfer->fromreq, transfer->toreq, | |
485 transfer->fromwdata, transfer->towdata, | |
486 transfer->files, 0); | |
487 g_free (transfer); | |
488 } | |
489 else | |
490 { | |
491 if (transfer->statmutex) | |
492 pthread_mutex_destroy (transfer->statmutex); | |
493 if (transfer->structmutex) | |
494 pthread_mutex_destroy (transfer->structmutex); | |
495 free_tdata (transfer); | |
496 } | |
497 } | |
498 | |
499 void * | |
500 do_getdir_thread (void * data) | |
501 { | |
502 gftp_transfer * transfer; | |
503 int success, sj; | |
504 | |
505 transfer = data; | |
506 transfer->fromreq->user_data = (void *) 0x01; | |
507 if (transfer->toreq) | |
508 transfer->toreq->user_data = (void *) 0x01; | |
509 | |
510 if (transfer->fromreq->use_threads || | |
511 (transfer->toreq && transfer->toreq->use_threads)) | |
512 { | |
513 sj = sigsetjmp (connenvir, 1); | |
514 signal (SIGINT, sig_connquit); | |
515 signal (SIGALRM, sig_connquit); | |
516 } | |
517 else | |
518 sj = 0; | |
519 | |
520 success = 0; | |
521 if (sj == 0) | |
522 success = gftp_get_all_subdirs (transfer, NULL) == 0; | |
523 else | |
524 { | |
525 gftp_disconnect (transfer->fromreq); | |
526 if (transfer->toreq) | |
527 gftp_disconnect (transfer->toreq); | |
528 transfer->fromreq->logging_function (gftp_logging_error, | |
529 transfer->fromreq->user_data, | |
530 _("Operation canceled\n")); | |
531 } | |
532 | |
533 if (transfer->fromreq->use_threads || | |
534 (transfer->toreq && transfer->toreq->use_threads)) | |
535 { | |
536 signal (SIGINT, SIG_DFL); | |
537 signal (SIGALRM, SIG_IGN); | |
538 } | |
539 | |
540 transfer->fromreq->user_data = NULL; | |
541 if (transfer->toreq) | |
542 transfer->toreq->user_data = NULL; | |
543 transfer->fromreq->stopable = 0; | |
544 return ((void *) success); | |
545 } | |
546 | |
547 | |
548 | |
549 void * | |
550 gftp_gtk_transfer_files (void *data) | |
551 { | |
552 gftp_transfer * transfer; | |
553 char *tempstr, buf[8192]; | |
554 FILE * tofd, * fromfd; | |
555 off_t fromsize, total; | |
556 gftp_file * curfle; | |
557 ssize_t num_read; | |
558 int i, mode; | |
559 | |
560 pthread_detach (pthread_self ()); | |
561 transfer = data; | |
562 transfer->fromreq->user_data = (void *) 0x1; | |
563 transfer->toreq->user_data = (void *) 0x1; | |
564 transfer->curfle = transfer->files; | |
565 gettimeofday (&transfer->starttime, NULL); | |
566 memcpy (&transfer->lasttime, &transfer->starttime, | |
567 sizeof (transfer->lasttime)); | |
568 while (transfer->curfle != NULL) | |
569 { | |
570 pthread_mutex_lock (transfer->structmutex); | |
571 curfle = transfer->curfle->data; | |
572 transfer->current_file_number++; | |
573 pthread_mutex_unlock (transfer->structmutex); | |
574 | |
575 if (curfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
576 { | |
577 pthread_mutex_lock (transfer->structmutex); | |
578 transfer->next_file = 1; | |
579 transfer->curfle = transfer->curfle->next; | |
580 pthread_mutex_unlock (transfer->structmutex); | |
581 continue; | |
582 } | |
583 | |
584 fromsize = -1; | |
585 if (gftp_connect (transfer->fromreq) == 0 && | |
586 gftp_connect (transfer->toreq) == 0) | |
587 { | |
588 if (curfle->isdir) | |
589 { | |
590 if (transfer->toreq->mkdir != NULL) | |
591 { | |
592 transfer->toreq->mkdir (transfer->toreq, curfle->destfile); | |
593 if (!GFTP_IS_CONNECTED (transfer->toreq)) | |
594 break; | |
595 } | |
596 | |
597 pthread_mutex_lock (transfer->structmutex); | |
598 transfer->next_file = 1; | |
599 transfer->curfle = transfer->curfle->next; | |
600 pthread_mutex_unlock (transfer->structmutex); | |
601 continue; | |
602 } | |
603 | |
604 if (transfer->fromreq->maxkbs > 0) | |
605 { | |
606 transfer->fromreq->logging_function (gftp_logging_misc, | |
607 transfer->fromreq->user_data, | |
608 _("File transfer will be throttled to %.2f KB/s\n"), | |
609 transfer->fromreq->maxkbs); | |
610 } | |
611 | |
612 if (curfle->is_fd) | |
613 { | |
614 if (transfer->transfer_direction == GFTP_DIRECTION_DOWNLOAD) | |
615 { | |
616 tofd = curfle->fd; | |
617 fromfd = NULL; | |
618 } | |
619 else | |
620 { | |
621 tofd = NULL; | |
622 fromfd = curfle->fd; | |
623 } | |
624 } | |
625 else | |
626 { | |
627 tofd = NULL; | |
628 fromfd = NULL; | |
629 } | |
630 | |
631 if (curfle->size == 0) | |
632 { | |
633 curfle->size = gftp_get_file_size (transfer->fromreq, curfle->file); | |
634 transfer->total_bytes += curfle->size; | |
635 } | |
636 | |
637 if (GFTP_IS_CONNECTED (transfer->fromreq) && | |
638 GFTP_IS_CONNECTED (transfer->toreq)) | |
639 { | |
640 fromsize = gftp_transfer_file (transfer->fromreq, curfle->file, | |
641 fromfd, | |
642 curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? | |
643 curfle->startsize : 0, | |
644 transfer->toreq, curfle->destfile, tofd, | |
645 curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? | |
646 curfle->startsize : 0); | |
647 } | |
648 } | |
649 | |
650 if (!GFTP_IS_CONNECTED (transfer->fromreq) || | |
651 !GFTP_IS_CONNECTED (transfer->toreq)) | |
652 { | |
653 transfer->fromreq->logging_function (gftp_logging_misc, | |
654 transfer->fromreq->user_data, | |
655 _("Error: Remote site disconnected after trying to transfer file\n")); | |
656 num_read = -1; | |
657 } | |
658 else if (fromsize < 0) | |
659 { | |
660 if (curfle->is_fd) | |
661 { | |
662 if (transfer->transfer_direction == GFTP_DIRECTION_DOWNLOAD) | |
663 transfer->toreq->datafd = NULL; | |
664 else | |
665 transfer->fromreq->datafd = NULL; | |
666 } | |
667 | |
668 pthread_mutex_lock (transfer->structmutex); | |
669 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
670 transfer->next_file = 1; | |
671 transfer->curfle = transfer->curfle->next; | |
672 pthread_mutex_unlock (transfer->structmutex); | |
673 continue; | |
674 } | |
675 else | |
676 { | |
677 pthread_mutex_lock (transfer->structmutex); | |
678 transfer->curtrans = 0; | |
679 transfer->curresumed = curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? curfle->startsize : 0; | |
680 transfer->resumed_bytes += transfer->curresumed; | |
681 pthread_mutex_unlock (transfer->structmutex); | |
682 | |
683 total = 0; | |
684 i = 0; | |
685 while (!transfer->cancel && | |
686 (num_read = gftp_get_next_file_chunk (transfer->fromreq, | |
687 buf, sizeof (buf))) > 0) | |
688 { | |
689 total += num_read; | |
690 gftp_gtk_calc_kbs (transfer, num_read); | |
691 | |
692 if (GFTP_GET_DATA_TYPE (transfer->fromreq) == GFTP_TYPE_ASCII) | |
693 tempstr = gftp_convert_ascii (buf, &num_read, 1); | |
694 else | |
695 tempstr = buf; | |
696 | |
697 if (gftp_put_next_file_chunk (transfer->toreq, tempstr, | |
698 num_read) < 0) | |
699 { | |
700 num_read = -1; | |
701 break; | |
702 } | |
703 | |
704 /* We don't have to free tempstr for a download because new | |
705 memory is not allocated for it in that case */ | |
706 if (GFTP_GET_DATA_TYPE (transfer->fromreq) == GFTP_TYPE_ASCII && | |
707 transfer->transfer_direction == GFTP_DIRECTION_UPLOAD) | |
708 g_free (tempstr); | |
709 } | |
710 } | |
711 | |
40 | 712 if (transfer->cancel) |
713 { | |
714 if (gftp_abort_transfer (transfer->fromreq) != 0) | |
715 gftp_disconnect (transfer->fromreq); | |
716 | |
717 if (gftp_abort_transfer (transfer->toreq) != 0) | |
718 gftp_disconnect (transfer->toreq); | |
719 } | |
720 else if (num_read < 0) | |
1 | 721 { |
722 transfer->fromreq->logging_function (gftp_logging_misc, | |
723 transfer->fromreq->user_data, | |
724 _("Could not download %s from %s\n"), | |
725 curfle->file, | |
726 transfer->fromreq->hostname); | |
727 | |
728 if (get_status (transfer, num_read) == 1) | |
40 | 729 continue; |
730 | |
1 | 731 break; |
732 } | |
733 else | |
734 { | |
40 | 735 /* FIXME - this needs cleaned up. NOTE: view/edit file will be |
736 broken if the file has to be resumed */ | |
1 | 737 if (curfle->is_fd) |
738 { | |
739 if (transfer->transfer_direction == GFTP_DIRECTION_DOWNLOAD) | |
740 transfer->toreq->datafd = NULL; | |
741 else | |
742 transfer->fromreq->datafd = NULL; | |
743 } | |
744 | |
745 if (gftp_end_transfer (transfer->fromreq) != 0) | |
746 { | |
747 if (get_status (transfer, -1) == 1) | |
40 | 748 continue; |
749 | |
1 | 750 break; |
751 } | |
752 gftp_end_transfer (transfer->toreq); | |
753 | |
754 transfer->fromreq->logging_function (gftp_logging_misc, | |
755 transfer->fromreq->user_data, | |
756 _("Successfully transferred %s at %.2f KB/s\n"), | |
757 curfle->file, transfer->kbs); | |
758 } | |
759 | |
760 if (!curfle->is_fd) | |
761 { | |
762 if (curfle->attribs) | |
763 { | |
764 mode = parse_attribs (curfle->attribs); | |
765 if (mode != 0) | |
766 gftp_chmod (transfer->toreq, curfle->destfile, | |
767 parse_attribs (curfle->attribs)); | |
768 } | |
769 | |
770 if (curfle->datetime != 0) | |
771 gftp_set_file_time (transfer->toreq, curfle->destfile, | |
772 curfle->datetime); | |
773 } | |
774 | |
775 pthread_mutex_lock (transfer->structmutex); | |
776 transfer->next_file = 1; | |
777 curfle->transfer_done = 1; | |
778 transfer->curfle = transfer->curfle->next; | |
779 pthread_mutex_unlock (transfer->structmutex); | |
780 | |
781 if (transfer->cancel && !transfer->skip_file) | |
782 break; | |
783 transfer->cancel = 0; | |
784 } | |
785 transfer->done = 1; | |
786 transfer->fromreq->user_data = NULL; | |
787 transfer->toreq->user_data = NULL; | |
788 return (NULL); | |
789 } | |
790 | |
791 | |
792 void | |
793 add_file_transfer (gftp_request * fromreq, gftp_request * toreq, | |
794 gftp_window_data * fromwdata, gftp_window_data * towdata, | |
795 GList * files, int copy_req) | |
796 { | |
797 gftp_curtrans_data * transdata; | |
798 GList * templist, *curfle; | |
799 gftp_transfer * tdata; | |
800 gftp_file * tempfle; | |
801 char *pos, *text[2]; | |
802 int dialog; | |
803 | |
804 for (templist = files; templist != NULL; templist = templist->next) | |
805 { | |
806 tempfle = templist->data; | |
807 if (tempfle->startsize > 0) | |
808 break; | |
809 } | |
810 dialog = templist != NULL; | |
811 | |
812 if (append_file_transfers) | |
813 { | |
814 pthread_mutex_lock (&transfer_mutex); | |
815 for (templist = file_transfers; templist != NULL; templist = templist->next) | |
816 { | |
817 tdata = templist->data; | |
818 pthread_mutex_lock (tdata->structmutex); | |
819 if (compare_request (tdata->fromreq, fromreq, 0) && | |
820 compare_request (tdata->toreq, toreq, 0) && | |
821 tdata->curfle != NULL) | |
822 { | |
823 if (!copy_req) | |
824 { | |
825 gftp_request_destroy (fromreq); | |
826 gftp_request_destroy (toreq); | |
827 } | |
828 fromreq = NULL; | |
829 toreq = NULL; | |
830 | |
831 for (curfle = tdata->curfle; | |
832 curfle != NULL && curfle->next != NULL; | |
833 curfle = curfle->next); | |
834 if (curfle == NULL) | |
835 { | |
836 curfle = files; | |
837 files->prev = NULL; | |
838 } | |
839 else | |
840 { | |
841 curfle->next = files; | |
842 files->prev = curfle; | |
843 } | |
844 | |
845 for (curfle = files; curfle != NULL; curfle = curfle->next) | |
846 { | |
847 tempfle = curfle->data; | |
848 if (tempfle->isdir) | |
849 tdata->numdirs++; | |
850 else | |
851 tdata->numfiles++; | |
852 if ((pos = strrchr (tempfle->file, '/')) == NULL) | |
853 pos = tempfle->file; | |
854 else | |
855 pos++; | |
856 | |
857 text[0] = pos; | |
858 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
859 text[1] = _("Skipped"); | |
860 else | |
861 { | |
862 tdata->total_bytes += tempfle->size; | |
863 text[1] = _("Waiting..."); | |
864 } | |
865 | |
866 tempfle->node = gtk_ctree_insert_node (GTK_CTREE (dlwdw), | |
867 tdata->node, NULL, text, 5, | |
868 NULL, NULL, NULL, NULL, | |
869 FALSE, FALSE); | |
870 transdata = g_malloc (sizeof (*transdata)); | |
871 transdata->transfer = tdata; | |
872 transdata->curfle = curfle; | |
873 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tempfle->node, | |
874 transdata); | |
875 } | |
876 pthread_mutex_unlock (tdata->structmutex); | |
877 break; | |
878 } | |
879 pthread_mutex_unlock (tdata->structmutex); | |
880 } | |
881 pthread_mutex_unlock (&transfer_mutex); | |
882 } | |
883 else | |
884 templist = NULL; | |
885 | |
886 if (templist == NULL) | |
887 { | |
888 tdata = g_malloc0 (sizeof (*tdata)); | |
889 if (copy_req) | |
890 { | |
891 tdata->fromreq = copy_request (fromreq); | |
892 tdata->toreq = copy_request (toreq); | |
893 } | |
894 else | |
895 { | |
896 tdata->fromreq = fromreq; | |
897 tdata->toreq = toreq; | |
898 } | |
899 tdata->transfer_direction = fromwdata && fromwdata == &window1 ? | |
900 GFTP_DIRECTION_UPLOAD : GFTP_DIRECTION_DOWNLOAD; | |
901 tdata->fromwdata = fromwdata; | |
902 tdata->towdata = towdata; | |
903 if (!dialog) | |
904 tdata->show = tdata->ready = 1; | |
905 tdata->files = files; | |
906 for (curfle = files; curfle != NULL; curfle = curfle->next) | |
907 { | |
908 tempfle = curfle->data; | |
909 if (tempfle->isdir) | |
910 tdata->numdirs++; | |
911 else | |
912 tdata->numfiles++; | |
913 } | |
914 tdata->structmutex = g_malloc (sizeof (pthread_mutex_t)); | |
915 pthread_mutex_init (tdata->structmutex, NULL); | |
916 tdata->statmutex = g_malloc (sizeof (pthread_mutex_t)); | |
917 pthread_mutex_init (tdata->statmutex, NULL); | |
918 pthread_mutex_lock (&transfer_mutex); | |
919 file_transfers = g_list_append (file_transfers, tdata); | |
920 pthread_mutex_unlock (&transfer_mutex); | |
921 if (dialog) | |
922 gftp_gtk_ask_transfer (tdata); | |
923 } | |
924 } | |
925 | |
926 | |
927 gint | |
928 update_downloads (gpointer data) | |
929 { | |
930 char tempstr[50], temp1str[127]; | |
931 GList * templist, * next; | |
932 gftp_transfer * tdata; | |
933 | |
934 if (file_transfer_logs != NULL) | |
935 display_cached_logs (); | |
936 | |
937 if (window2.request->gotbytes != 0) | |
938 { | |
939 if (window2.request->gotbytes == -1) | |
940 { | |
941 update_window_info (); | |
942 window2.request->gotbytes = 0; | |
943 } | |
944 else | |
945 { | |
946 insert_commas (window2.request->gotbytes, tempstr, sizeof (tempstr)); | |
947 g_snprintf (temp1str, sizeof (temp1str), | |
948 _("Retrieving file names...%s bytes"), tempstr); | |
949 gtk_label_set (GTK_LABEL (window2.hoststxt), temp1str); | |
950 } | |
951 } | |
952 | |
953 if (viewedit_process_done) | |
954 check_done_process (); | |
955 | |
956 for (templist = file_transfers; templist != NULL;) | |
957 { | |
958 tdata = templist->data; | |
959 if (tdata->ready) | |
960 { | |
961 pthread_mutex_lock (tdata->structmutex); | |
962 | |
963 if (tdata->next_file) | |
964 on_next_transfer (tdata); | |
965 else if (tdata->show) | |
966 show_transfer (tdata); | |
967 else if (tdata->done) | |
968 { | |
969 next = templist->next; | |
970 transfer_done (templist); | |
971 templist = next; | |
972 continue; | |
973 } | |
974 | |
975 if (tdata->curfle != NULL) | |
976 { | |
977 if (!tdata->started && start_file_transfers && | |
978 (transfer_in_progress == 0 || !do_one_transfer_at_a_time)) | |
979 create_transfer (tdata); | |
980 | |
981 if (tdata->started) | |
982 update_file_status (tdata); | |
983 } | |
984 pthread_mutex_unlock (tdata->structmutex); | |
985 } | |
986 templist = templist->next; | |
987 } | |
988 | |
989 gtk_timeout_add (500, update_downloads, NULL); | |
990 return (0); | |
991 } | |
992 | |
993 | |
994 static void | |
995 on_next_transfer (gftp_transfer * tdata) | |
996 { | |
997 gftp_file * tempfle; | |
998 int fd; | |
999 | |
1000 tdata->next_file = 0; | |
1001 for (; tdata->updfle != tdata->curfle; tdata->updfle = tdata->updfle->next) | |
1002 { | |
1003 tempfle = tdata->updfle->data; | |
1004 | |
1005 if (tempfle->is_fd) | |
1006 fd = fileno (tempfle->fd); | |
1007 else | |
1008 fd = 0; | |
1009 | |
1010 if (tempfle->done_view) | |
1011 { | |
1012 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
1013 view_file (tempfle->destfile, fd, 1, tempfle->done_rm, 1, 0, | |
1014 tempfle->file, NULL); | |
1015 | |
1016 if (tempfle->is_fd) | |
1017 { | |
1018 fclose (tempfle->fd); | |
1019 tempfle->fd = NULL; | |
1020 } | |
1021 } | |
1022 else if (tempfle->done_edit) | |
1023 { | |
1024 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
1025 view_file (tempfle->destfile, fd, 0, tempfle->done_rm, 1, 0, | |
1026 tempfle->file, NULL); | |
1027 | |
1028 if (tempfle->is_fd) | |
1029 { | |
1030 fclose (tempfle->fd); | |
1031 tempfle->fd = NULL; | |
1032 } | |
1033 } | |
1034 else if (tempfle->done_rm) | |
1035 tdata->fromreq->rmfile (tdata->fromreq, tempfle->file); | |
1036 | |
1037 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
1038 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->node, 1, | |
1039 _("Skipped")); | |
1040 else | |
1041 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->node, 1, | |
1042 _("Finished")); | |
1043 } | |
1044 | |
1045 if (refresh_files && tdata->curfle && tdata->curfle->next && | |
1046 compare_request (tdata->toreq, | |
1047 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
1048 refresh (tdata->towdata); | |
1049 } | |
1050 | |
1051 | |
1052 static void | |
19 | 1053 get_trans_password (gftp_request * request, gftp_dialog_data * ddata) |
1054 { | |
1055 gftp_set_password (request, gtk_entry_get_text (GTK_ENTRY (ddata->edit))); | |
1056 request->stopable = 0; | |
1057 } | |
1058 | |
1059 | |
1060 static void | |
1061 cancel_get_trans_password (gftp_transfer * tdata, gftp_dialog_data * ddata) | |
1062 { | |
1063 if (tdata->fromreq->stopable == 0) | |
1064 return; | |
1065 | |
1066 pthread_mutex_lock (tdata->structmutex); | |
1067 if (tdata->started) | |
1068 tdata->cancel = 1; | |
1069 else | |
1070 tdata->done = 1; | |
1071 | |
1072 tdata->fromreq->stopable = 0; | |
1073 tdata->toreq->stopable = 0; | |
40 | 1074 pthread_mutex_unlock (tdata->structmutex); |
1075 | |
19 | 1076 ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer of %s\n"), |
1077 ((gftp_file *) tdata->curfle->data)->file); | |
1078 } | |
1079 | |
1080 | |
1081 static void | |
1 | 1082 show_transfer (gftp_transfer * tdata) |
1083 { | |
1084 GdkPixmap * closedir_pixmap, * opendir_pixmap; | |
1085 GdkBitmap * closedir_bitmap, * opendir_bitmap; | |
1086 gftp_curtrans_data * transdata; | |
1087 gftp_file * tempfle; | |
1088 char *pos, *text[2]; | |
1089 GList * templist; | |
1090 | |
1091 gftp_get_pixmap (dlwdw, "open_dir.xpm", &opendir_pixmap, &opendir_bitmap); | |
1092 gftp_get_pixmap (dlwdw, "dir.xpm", &closedir_pixmap, &closedir_bitmap); | |
1093 | |
1094 text[0] = GFTP_GET_HOSTNAME (tdata->fromreq); | |
1095 text[1] = _("Waiting..."); | |
1096 tdata->node = gtk_ctree_insert_node (GTK_CTREE (dlwdw), NULL, NULL, text, 5, | |
1097 closedir_pixmap, closedir_bitmap, | |
1098 opendir_pixmap, opendir_bitmap, | |
1099 FALSE, | |
1100 tdata->numdirs + tdata->numfiles < 50); | |
1101 transdata = g_malloc (sizeof (*transdata)); | |
1102 transdata->transfer = tdata; | |
1103 transdata->curfle = NULL; | |
1104 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tdata->node, transdata); | |
1105 tdata->show = 0; | |
1106 tdata->curfle = tdata->updfle = tdata->files; | |
1107 | |
1108 tdata->total_bytes = 0; | |
1109 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
1110 { | |
1111 tempfle = templist->data; | |
1112 if ((pos = strrchr (tempfle->file, '/')) == NULL) | |
1113 pos = tempfle->file; | |
1114 else | |
1115 pos++; | |
1116 text[0] = pos; | |
1117 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
1118 text[1] = _("Skipped"); | |
1119 else | |
1120 { | |
1121 tdata->total_bytes += tempfle->size; | |
1122 text[1] = _("Waiting..."); | |
1123 } | |
1124 | |
1125 tempfle->node = gtk_ctree_insert_node (GTK_CTREE (dlwdw), tdata->node, | |
1126 NULL, text, 5, NULL, NULL, NULL, | |
1127 NULL, FALSE, FALSE); | |
1128 transdata = g_malloc (sizeof (*transdata)); | |
1129 transdata->transfer = tdata; | |
1130 transdata->curfle = templist; | |
1131 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tempfle->node, transdata); | |
1132 } | |
1133 | |
1134 if (!tdata->toreq->stopable && tdata->toreq->need_userpass && | |
1135 (tdata->toreq->password == NULL || *tdata->toreq->password == '\0')) | |
1136 { | |
1137 tdata->toreq->stopable = 1; | |
1138 MakeEditDialog (_("Enter Password"), | |
1139 _("Please enter your password for this site"), NULL, 0, | |
19 | 1140 NULL, gftp_dialog_button_connect, |
1141 get_trans_password, tdata->toreq, | |
1142 cancel_get_trans_password, tdata); | |
1 | 1143 } |
1144 | |
1145 if (!tdata->fromreq->stopable && tdata->fromreq->need_userpass && | |
1146 (tdata->fromreq->password == NULL || *tdata->fromreq->password == '\0')) | |
1147 { | |
1148 tdata->fromreq->stopable = 1; | |
1149 MakeEditDialog (_("Enter Password"), | |
1150 _("Please enter your password for this site"), NULL, 0, | |
19 | 1151 NULL, gftp_dialog_button_connect, |
1152 get_trans_password, tdata->fromreq, | |
1153 cancel_get_trans_password, tdata); | |
1 | 1154 } |
1155 } | |
1156 | |
1157 | |
1158 static void | |
1159 transfer_done (GList * node) | |
1160 { | |
1161 gftp_curtrans_data * transdata; | |
1162 gftp_request * fromreq; | |
1163 gftp_transfer * tdata; | |
1164 gftp_file * tempfle; | |
1165 GList * templist; | |
1166 | |
1167 tdata = node->data; | |
1168 if (tdata->started) | |
1169 { | |
1170 fromreq = ((gftp_window_data *) tdata->fromwdata)->request; | |
1171 if (!tdata->fromreq->stopable && tdata->fromwdata && | |
1172 ((fromreq->sockfd == NULL && fromreq->cached) || | |
1173 fromreq->always_connected) && tdata->fromreq->sockfd != NULL && | |
1174 compare_request (tdata->fromreq, fromreq, 0)) | |
1175 { | |
1176 swap_socks (((gftp_window_data *) tdata->towdata)->request, | |
1177 tdata->toreq); | |
1178 swap_socks (((gftp_window_data *) tdata->fromwdata)->request, | |
1179 tdata->fromreq); | |
1180 } | |
1181 else | |
1182 { | |
1183 gftp_disconnect (tdata->fromreq); | |
1184 gftp_disconnect (tdata->toreq); | |
1185 } | |
1186 | |
1187 if (tdata->towdata != NULL && compare_request (tdata->toreq, | |
1188 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
1189 refresh (tdata->towdata); | |
1190 | |
1191 transfer_in_progress--; | |
1192 } | |
1193 | |
2
a171df6764a7
* Fixed crash if you was already transfering a file, and you started another
masneyb
parents:
1
diff
changeset
|
1194 if (!tdata->show && tdata->started) |
1 | 1195 { |
1196 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), tdata->node); | |
1197 if (transdata != NULL) | |
1198 g_free (transdata); | |
1199 | |
1200 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
1201 { | |
1202 tempfle = templist->data; | |
1203 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), tempfle->node); | |
1204 if (transdata != NULL) | |
1205 g_free (transdata); | |
1206 } | |
1207 | |
1208 gtk_ctree_remove_node (GTK_CTREE (dlwdw), tdata->node); | |
1209 } | |
1210 pthread_mutex_lock (&transfer_mutex); | |
1211 file_transfers = g_list_remove_link (file_transfers, node); | |
1212 pthread_mutex_unlock (&transfer_mutex); | |
1213 pthread_mutex_destroy (tdata->structmutex); | |
1214 pthread_mutex_destroy (tdata->statmutex); | |
1215 free_tdata (tdata); | |
1216 } | |
1217 | |
1218 | |
1219 static void | |
1220 create_transfer (gftp_transfer * tdata) | |
1221 { | |
1222 pthread_t tid; | |
1223 | |
1224 if (!tdata->fromreq->stopable) | |
1225 { | |
1226 if (tdata->fromwdata && | |
1227 ((gftp_window_data *) tdata->fromwdata)->request->sockfd != NULL && | |
1228 !((gftp_window_data *) tdata->fromwdata)->request->stopable && | |
1229 compare_request (tdata->fromreq, ((gftp_window_data *) tdata->fromwdata)->request, 0)) | |
1230 { | |
1231 swap_socks (tdata->toreq, | |
1232 ((gftp_window_data *) tdata->towdata)->request); | |
1233 swap_socks (tdata->fromreq, | |
1234 ((gftp_window_data *) tdata->fromwdata)->request); | |
1235 update_window_info (); | |
1236 } | |
1237 transfer_in_progress++; | |
1238 tdata->started = 1; | |
1239 tdata->stalled = 1; | |
1240 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->node, 1, | |
1241 _("Connecting...")); | |
1242 pthread_create (&tid, NULL, gftp_gtk_transfer_files, tdata); | |
1243 } | |
1244 } | |
1245 | |
1246 | |
1247 static void | |
1248 update_file_status (gftp_transfer * tdata) | |
1249 { | |
1250 char totstr[100], dlstr[100], gotstr[50], ofstr[50]; | |
1251 int hours, mins, secs, pcent, st; | |
1252 double remaining; | |
1253 gftp_file * tempfle; | |
1254 struct timeval tv; | |
1255 | |
1256 pthread_mutex_lock (tdata->statmutex); | |
1257 tempfle = tdata->curfle->data; | |
1258 | |
1259 gettimeofday (&tv, NULL); | |
1260 if ((remaining = (double) (tv.tv_sec - tdata->starttime.tv_sec) + ((double) (tv.tv_usec - tdata->starttime.tv_usec) / 1000000.0)) == 0) | |
1261 remaining = 1.0; | |
1262 | |
1263 remaining = ((double) (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes)) / 1024.0 / tdata->kbs; | |
1264 hours = (off_t) remaining / 3600; | |
1265 remaining -= hours * 3600; | |
1266 mins = (off_t) remaining / 60; | |
1267 remaining -= mins * 60; | |
1268 secs = (off_t) remaining; | |
1269 | |
1270 if (hours < 0 || mins < 0 || secs < 0) | |
1271 { | |
1272 pthread_mutex_unlock (tdata->statmutex); | |
1273 return; | |
1274 } | |
1275 | |
1276 pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0); | |
1277 if (pcent < 0 || pcent > 100) | |
1278 pcent = 0; | |
1279 | |
1280 g_snprintf (totstr, sizeof (totstr), | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
1281 _("%d%% complete, %02d:%02d:%02d est. time remaining. (File %ld of %ld)"), |
1 | 1282 pcent, hours, mins, secs, tdata->current_file_number, |
1283 tdata->numdirs + tdata->numfiles); | |
1284 | |
1285 *dlstr = '\0'; | |
1286 if (!tdata->stalled) | |
1287 { | |
1288 insert_commas (tdata->curtrans + tdata->curresumed, gotstr, sizeof (gotstr)); | |
1289 insert_commas (tempfle->size, ofstr, sizeof (ofstr)); | |
1290 st = 1; | |
1291 if (tv.tv_sec - tdata->lasttime.tv_sec <= 5) | |
1292 { | |
1293 if (tdata->curfle->next != NULL) | |
1294 { | |
1295 remaining = ((double) (tempfle->size - tdata->curtrans - tdata->curresumed)) / 1024.0 / tdata->kbs; | |
1296 hours = (off_t) remaining / 3600; | |
1297 remaining -= hours * 3600; | |
1298 mins = (off_t) remaining / 60; | |
1299 remaining -= mins * 60; | |
1300 secs = (off_t) remaining; | |
1301 } | |
1302 | |
1303 if (!(hours < 0 || mins < 0 || secs < 0)) | |
1304 { | |
1305 g_snprintf (dlstr, sizeof (dlstr), | |
1306 _("Recv %s of %s at %.2fKB/s, %02d:%02d:%02d est. time remaining"), gotstr, ofstr, tdata->kbs, hours, mins, secs); | |
1307 st = 0; | |
1308 } | |
1309 } | |
1310 | |
1311 if (st) | |
1312 { | |
1313 tdata->stalled = 1; | |
1314 g_snprintf (dlstr, sizeof (dlstr), | |
1315 _("Recv %s of %s, transfer stalled, unknown time remaining"), | |
1316 gotstr, ofstr); | |
1317 } | |
1318 } | |
1319 | |
1320 pthread_mutex_unlock (tdata->statmutex); | |
1321 | |
1322 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->node, 1, totstr); | |
1323 | |
1324 if (*dlstr != '\0') | |
1325 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->node, 1, dlstr); | |
1326 } | |
1327 | |
1328 | |
1329 void | |
1330 start_transfer (gpointer data) | |
1331 { | |
1332 gftp_curtrans_data * transdata; | |
1333 GtkCTreeNode * node; | |
1334 | |
1335 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1336 { | |
1337 ftp_log (gftp_logging_misc, NULL, | |
1338 _("There are no file transfers selected\n")); | |
1339 return; | |
1340 } | |
1341 node = GTK_CLIST (dlwdw)->selection->data; | |
1342 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1343 | |
1344 pthread_mutex_lock (transdata->transfer->structmutex); | |
1345 if (!transdata->transfer->started) | |
1346 create_transfer (transdata->transfer); | |
1347 pthread_mutex_unlock (transdata->transfer->structmutex); | |
1348 } | |
1349 | |
1350 | |
1351 void | |
1352 stop_transfer (gpointer data) | |
1353 { | |
1354 gftp_curtrans_data * transdata; | |
1355 GtkCTreeNode * node; | |
1356 | |
1357 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1358 { | |
1359 ftp_log (gftp_logging_misc, NULL, | |
1360 _("There are no file transfers selected\n")); | |
1361 return; | |
1362 } | |
1363 node = GTK_CLIST (dlwdw)->selection->data; | |
1364 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1365 | |
1366 pthread_mutex_lock (transdata->transfer->structmutex); | |
1367 if (transdata->transfer->started) | |
1368 { | |
1369 transdata->transfer->cancel = 1; | |
1370 transdata->transfer->skip_file = 0; | |
1371 } | |
1372 else | |
1373 transdata->transfer->done = 1; | |
40 | 1374 pthread_mutex_unlock (transdata->transfer->structmutex); |
1375 | |
1 | 1376 ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer on host %s\n"), |
1377 transdata->transfer->fromreq->hostname); | |
1378 } | |
1379 | |
1380 | |
1381 void | |
1382 skip_transfer (gpointer data) | |
1383 { | |
1384 gftp_curtrans_data * transdata; | |
1385 GtkCTreeNode * node; | |
1386 gftp_file * curfle; | |
40 | 1387 char *file; |
1 | 1388 |
1389 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1390 { | |
1391 ftp_log (gftp_logging_misc, NULL, | |
1392 _("There are no file transfers selected\n")); | |
1393 return; | |
1394 } | |
1395 node = GTK_CLIST (dlwdw)->selection->data; | |
1396 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1397 | |
1398 pthread_mutex_lock (transdata->transfer->structmutex); | |
1399 if (transdata->transfer->curfle != NULL) | |
1400 { | |
1401 curfle = transdata->transfer->curfle->data; | |
1402 if (transdata->transfer->started) | |
1403 { | |
1404 transdata->transfer->cancel = 1; | |
1405 transdata->transfer->skip_file = 1; | |
1406 } | |
1407 | |
1408 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
40 | 1409 file = curfle->file; |
1 | 1410 } |
40 | 1411 else |
1412 file = NULL; | |
1 | 1413 pthread_mutex_unlock (transdata->transfer->structmutex); |
40 | 1414 |
1415 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), | |
1416 file, transdata->transfer->fromreq->hostname); | |
1 | 1417 } |
1418 | |
1419 | |
1420 void | |
1421 remove_file_transfer (gpointer data) | |
1422 { | |
1423 gftp_curtrans_data * transdata; | |
1424 GtkCTreeNode * node; | |
1425 gftp_file * curfle; | |
1426 | |
1427 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1428 { | |
1429 ftp_log (gftp_logging_misc, NULL, | |
1430 _("There are no file transfers selected\n")); | |
1431 return; | |
1432 } | |
1433 | |
1434 node = GTK_CLIST (dlwdw)->selection->data; | |
1435 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1436 | |
1437 | |
1438 if (transdata->curfle == NULL || transdata->curfle->data == NULL) | |
1439 return; | |
1440 | |
1441 curfle = transdata->curfle->data; | |
1442 | |
1443 if (curfle->transfer_action & GFTP_TRANS_ACTION_SKIP) | |
1444 return; | |
1445 | |
1446 pthread_mutex_lock (transdata->transfer->structmutex); | |
1447 | |
1448 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
1449 | |
1450 if (transdata->transfer->started && | |
1451 transdata->curfle == transdata->transfer->curfle) | |
1452 { | |
1453 transdata->transfer->cancel = 1; | |
1454 transdata->transfer->skip_file = 1; | |
1455 } | |
1456 else if (transdata->curfle != transdata->transfer->curfle && | |
1457 !curfle->transfer_done) | |
1458 { | |
1459 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), curfle->node, 1, | |
1460 _("Skipped")); | |
1461 transdata->transfer->total_bytes -= curfle->size; | |
1462 } | |
1463 | |
40 | 1464 pthread_mutex_unlock (transdata->transfer->structmutex); |
1465 | |
1 | 1466 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), |
1467 curfle->file, transdata->transfer->fromreq->hostname); | |
1468 } | |
1469 | |
1470 | |
1471 void | |
1472 move_transfer_up (gpointer data) | |
1473 { | |
1474 GList * firstentry, * secentry, * lastentry; | |
1475 gftp_curtrans_data * transdata; | |
1476 GtkCTreeNode * node; | |
1477 | |
1478 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1479 { | |
1480 ftp_log (gftp_logging_misc, NULL, | |
1481 _("There are no file transfers selected\n")); | |
1482 return; | |
1483 } | |
1484 node = GTK_CLIST (dlwdw)->selection->data; | |
1485 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1486 | |
1487 if (transdata->curfle == NULL) | |
1488 return; | |
1489 | |
1490 pthread_mutex_lock (transdata->transfer->structmutex); | |
1491 if (transdata->curfle->prev != NULL && (!transdata->transfer->started || | |
1492 (transdata->transfer->curfle != transdata->curfle && | |
1493 transdata->transfer->curfle != transdata->curfle->prev))) | |
1494 { | |
1495 if (transdata->curfle->prev->prev == NULL) | |
1496 { | |
1497 firstentry = transdata->curfle->prev; | |
1498 lastentry = transdata->curfle->next; | |
1499 transdata->transfer->files = transdata->curfle; | |
1500 transdata->curfle->next = firstentry; | |
1501 transdata->transfer->files->prev = NULL; | |
1502 firstentry->prev = transdata->curfle; | |
1503 firstentry->next = lastentry; | |
1504 if (lastentry != NULL) | |
1505 lastentry->prev = firstentry; | |
1506 } | |
1507 else | |
1508 { | |
1509 firstentry = transdata->curfle->prev->prev; | |
1510 secentry = transdata->curfle->prev; | |
1511 lastentry = transdata->curfle->next; | |
1512 firstentry->next = transdata->curfle; | |
1513 transdata->curfle->prev = firstentry; | |
1514 transdata->curfle->next = secentry; | |
1515 secentry->prev = transdata->curfle; | |
1516 secentry->next = lastentry; | |
1517 if (lastentry != NULL) | |
1518 lastentry->prev = secentry; | |
1519 } | |
1520 | |
1521 gtk_ctree_move (GTK_CTREE (dlwdw), | |
1522 ((gftp_file *) transdata->curfle->data)->node, | |
1523 transdata->transfer->node, | |
1524 transdata->curfle->next != NULL ? | |
1525 ((gftp_file *) transdata->curfle->next->data)->node : | |
1526 NULL); | |
1527 } | |
1528 pthread_mutex_unlock (transdata->transfer->structmutex); | |
1529 } | |
1530 | |
1531 void | |
1532 move_transfer_down (gpointer data) | |
1533 { | |
1534 GList * firstentry, * secentry, * lastentry; | |
1535 gftp_curtrans_data * transdata; | |
1536 GtkCTreeNode * node; | |
1537 | |
1538 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1539 { | |
1540 ftp_log (gftp_logging_misc, NULL, | |
1541 _("There are no file transfers selected\n")); | |
1542 return; | |
1543 } | |
1544 node = GTK_CLIST (dlwdw)->selection->data; | |
1545 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1546 | |
1547 if (transdata->curfle == NULL) | |
1548 return; | |
1549 | |
1550 pthread_mutex_lock (transdata->transfer->structmutex); | |
1551 if (transdata->curfle->next != NULL && (!transdata->transfer->started || | |
1552 (transdata->transfer->curfle != transdata->curfle && | |
1553 transdata->transfer->curfle != transdata->curfle->next))) | |
1554 { | |
1555 if (transdata->curfle->prev == NULL) | |
1556 { | |
1557 firstentry = transdata->curfle->next; | |
1558 lastentry = transdata->curfle->next->next; | |
1559 transdata->transfer->files = firstentry; | |
1560 transdata->transfer->files->prev = NULL; | |
1561 transdata->transfer->files->next = transdata->curfle; | |
1562 transdata->curfle->prev = transdata->transfer->files; | |
1563 transdata->curfle->next = lastentry; | |
1564 if (lastentry != NULL) | |
1565 lastentry->prev = transdata->curfle; | |
1566 } | |
1567 else | |
1568 { | |
1569 firstentry = transdata->curfle->prev; | |
1570 secentry = transdata->curfle->next; | |
1571 lastentry = transdata->curfle->next->next; | |
1572 firstentry->next = secentry; | |
1573 secentry->prev = firstentry; | |
1574 secentry->next = transdata->curfle; | |
1575 transdata->curfle->prev = secentry; | |
1576 transdata->curfle->next = lastentry; | |
1577 if (lastentry != NULL) | |
1578 lastentry->prev = transdata->curfle; | |
1579 } | |
1580 | |
1581 gtk_ctree_move (GTK_CTREE (dlwdw), | |
1582 ((gftp_file *) transdata->curfle->data)->node, | |
1583 transdata->transfer->node, | |
1584 transdata->curfle->next != NULL ? | |
1585 ((gftp_file *) transdata->curfle->next->data)->node : | |
1586 NULL); | |
1587 } | |
1588 pthread_mutex_unlock (transdata->transfer->structmutex); | |
1589 } | |
1590 | |
1591 | |
1592 void | |
1593 gftp_gtk_ask_transfer (gftp_transfer * tdata) | |
1594 { | |
1595 char *dltitles[4], *add_data[4] = { NULL, NULL, NULL, NULL }, | |
1596 tempstr[50], temp1str[50]; | |
1597 GtkWidget * tempwid, * scroll, * hbox; | |
1598 gftp_file * tempfle; | |
1599 GList * templist; | |
1600 size_t len; | |
1601 char *pos; | |
1602 int i; | |
1603 | |
1604 dltitles[0] = _("Filename"); | |
1605 dltitles[1] = _("Local Size"); | |
1606 dltitles[2] = _("Remote Size"); | |
1607 dltitles[3] = _("Action"); | |
19 | 1608 dialog = gtk_dialog_new (); /* FIXME - gtk+ 2.0 stock icons */ |
1 | 1609 gtk_grab_add (dialog); |
1610 gtk_window_set_title (GTK_WINDOW (dialog), | |
1611 tdata->transfer_direction == GFTP_DIRECTION_DOWNLOAD ? | |
1612 _("Download Files") : _("Upload Files")); | |
1613 gtk_window_set_wmclass (GTK_WINDOW(dialog), "transfer", "gFTP"); | |
1614 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 10); | |
1615 gtk_container_border_width (GTK_CONTAINER | |
1616 (GTK_DIALOG (dialog)->action_area), 5); | |
1617 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 5); | |
1618 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 35); | |
1619 gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE); | |
1620 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); | |
1621 gtk_signal_connect_object (GTK_OBJECT (dialog), "delete_event", | |
1622 GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
1623 GTK_OBJECT (dialog)); | |
1624 | |
1625 tempwid = gtk_label_new (_("The following file(s) exist on both the local and remote computer\nPlease select what you would like to do")); | |
1626 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), tempwid, FALSE, | |
1627 FALSE, 0); | |
1628 gtk_widget_show (tempwid); | |
1629 | |
1630 scroll = gtk_scrolled_window_new (NULL, NULL); | |
1631 gtk_widget_set_size_request (scroll, 450, 200); | |
1632 | |
1633 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), | |
1634 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
1635 tdata->clist = gtk_clist_new_with_titles (4, dltitles); | |
1636 gtk_container_add (GTK_CONTAINER (scroll), tdata->clist); | |
1637 | |
1638 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2 | |
1639 gtk_clist_set_selection_mode (GTK_CLIST (tdata->clist), | |
1640 GTK_SELECTION_EXTENDED); | |
1641 #else | |
1642 gtk_clist_set_selection_mode (GTK_CLIST (tdata->clist), | |
1643 GTK_SELECTION_MULTIPLE); | |
1644 #endif | |
1645 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 0, 100); | |
1646 gtk_clist_set_column_justification (GTK_CLIST (tdata->clist), 1, | |
1647 GTK_JUSTIFY_RIGHT); | |
1648 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 1, 85); | |
1649 gtk_clist_set_column_justification (GTK_CLIST (tdata->clist), 2, | |
1650 GTK_JUSTIFY_RIGHT); | |
1651 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 2, 85); | |
1652 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 3, 85); | |
1653 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), scroll, TRUE, TRUE, | |
1654 0); | |
1655 gtk_widget_show (tdata->clist); | |
1656 gtk_widget_show (scroll); | |
1657 | |
1658 for (templist = tdata->files; templist != NULL; | |
1659 templist = templist->next) | |
1660 { | |
1661 tempfle = templist->data; | |
1662 if (tempfle->startsize == 0 || tempfle->isdir) | |
1663 { | |
1664 tempfle->shown = 0; | |
1665 continue; | |
1666 } | |
1667 tempfle->shown = 1; | |
1668 | |
1669 pos = tempfle->destfile; | |
1670 len = strlen (GFTP_GET_DIRECTORY (tdata->toreq)); | |
1671 if (strncmp (pos, GFTP_GET_DIRECTORY (tdata->toreq), len) == 0) | |
1672 pos = tempfle->destfile + len + 1; | |
1673 add_data[0] = pos; | |
1674 | |
1675 if (overwrite_by_default) | |
1676 add_data[3] = _("Overwrite"); | |
1677 else | |
1678 { | |
1679 if (tempfle->startsize >= tempfle->size) | |
1680 { | |
1681 add_data[3] = _("Skip"); | |
1682 tempfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
1683 } | |
1684 else | |
1685 { | |
1686 add_data[3] = _("Resume"); | |
1687 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME; | |
1688 } | |
1689 } | |
1690 | |
1691 if (tdata->transfer_direction == GFTP_DIRECTION_DOWNLOAD) | |
1692 { | |
1693 add_data[2] = insert_commas (tempfle->size, tempstr, | |
1694 sizeof (tempstr)); | |
1695 add_data[1] = insert_commas (tempfle->startsize, temp1str, | |
1696 sizeof (temp1str)); | |
1697 } | |
1698 else | |
1699 { | |
1700 add_data[1] = insert_commas (tempfle->size, tempstr, | |
1701 sizeof (tempstr)); | |
1702 add_data[2] = insert_commas (tempfle->startsize, temp1str, | |
1703 sizeof (temp1str)); | |
1704 } | |
1705 i = gtk_clist_append (GTK_CLIST (tdata->clist), add_data); | |
1706 gtk_clist_set_row_data (GTK_CLIST (tdata->clist), i, tempfle); | |
1707 } | |
1708 | |
1709 gtk_clist_select_all (GTK_CLIST (tdata->clist)); | |
1710 | |
1711 hbox = gtk_hbox_new (TRUE, 20); | |
1712 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, TRUE, TRUE, 0); | |
1713 gtk_widget_show (hbox); | |
1714 | |
1715 tempwid = gtk_button_new_with_label (_("Overwrite")); | |
1716 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
1717 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
1718 GTK_SIGNAL_FUNC (overwrite), (gpointer) tdata); | |
1719 gtk_widget_show (tempwid); | |
1720 | |
1721 tempwid = gtk_button_new_with_label (_("Resume")); | |
1722 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
1723 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
1724 GTK_SIGNAL_FUNC (resume), (gpointer) tdata); | |
1725 gtk_widget_show (tempwid); | |
1726 | |
1727 tempwid = gtk_button_new_with_label (_("Skip File")); | |
1728 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
1729 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", GTK_SIGNAL_FUNC (skip), | |
1730 (gpointer) tdata); | |
1731 gtk_widget_show (tempwid); | |
1732 | |
1733 hbox = gtk_hbox_new (TRUE, 20); | |
1734 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, TRUE, TRUE, 0); | |
1735 gtk_widget_show (hbox); | |
1736 | |
1737 tempwid = gtk_button_new_with_label (_("Select All")); | |
1738 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
1739 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
1740 GTK_SIGNAL_FUNC (trans_selectall), (gpointer) tdata); | |
1741 gtk_widget_show (tempwid); | |
1742 | |
1743 tempwid = gtk_button_new_with_label (_("Deselect All")); | |
1744 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
1745 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
1746 GTK_SIGNAL_FUNC (trans_unselectall), (gpointer) tdata); | |
1747 gtk_widget_show (tempwid); | |
1748 | |
1749 tempwid = gtk_button_new_with_label (_("OK")); | |
1750 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); | |
1751 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, | |
1752 TRUE, TRUE, 0); | |
1753 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", GTK_SIGNAL_FUNC (ok), | |
1754 (gpointer) tdata); | |
1755 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked", | |
1756 GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
1757 GTK_OBJECT (dialog)); | |
1758 gtk_widget_grab_default (tempwid); | |
1759 gtk_widget_show (tempwid); | |
1760 | |
1761 tempwid = gtk_button_new_with_label (_(" Cancel ")); | |
1762 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); | |
1763 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, | |
1764 TRUE, TRUE, 0); | |
1765 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
1766 GTK_SIGNAL_FUNC (cancel), (gpointer) tdata); | |
1767 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked", | |
1768 GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
1769 GTK_OBJECT (dialog)); | |
1770 gtk_widget_show (tempwid); | |
1771 | |
1772 gtk_widget_show (dialog); | |
1773 dialog = NULL; | |
1774 } | |
1775 | |
1776 | |
1777 static void | |
1778 trans_selectall (GtkWidget * widget, gpointer data) | |
1779 { | |
1780 gftp_transfer * tdata; | |
1781 tdata = data; | |
1782 | |
1783 gtk_clist_select_all (GTK_CLIST (tdata->clist)); | |
1784 } | |
1785 | |
1786 | |
1787 static void | |
1788 trans_unselectall (GtkWidget * widget, gpointer data) | |
1789 { | |
1790 gftp_transfer * tdata; | |
1791 tdata = data; | |
1792 | |
1793 gtk_clist_unselect_all (GTK_CLIST (tdata->clist)); | |
1794 } | |
1795 | |
1796 | |
1797 static void | |
1798 overwrite (GtkWidget * widget, gpointer data) | |
1799 { | |
1800 GList * templist, * filelist; | |
1801 gftp_transfer * tdata; | |
1802 gftp_file * tempfle; | |
1803 int curpos; | |
1804 | |
1805 tdata = data; | |
1806 curpos = 0; | |
1807 filelist = tdata->files; | |
1808 templist = GTK_CLIST (tdata->clist)->selection; | |
1809 while (templist != NULL) | |
1810 { | |
1811 templist = get_next_selection (templist, &filelist, &curpos); | |
1812 tempfle = filelist->data; | |
1813 tempfle->transfer_action = GFTP_TRANS_ACTION_OVERWRITE; | |
1814 gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Overwrite")); | |
1815 } | |
1816 } | |
1817 | |
1818 | |
1819 static void | |
1820 resume (GtkWidget * widget, gpointer data) | |
1821 { | |
1822 GList * templist, * filelist; | |
1823 gftp_transfer * tdata; | |
1824 gftp_file * tempfle; | |
1825 int curpos; | |
1826 | |
1827 tdata = data; | |
1828 curpos = 0; | |
1829 filelist = tdata->files; | |
1830 templist = GTK_CLIST (tdata->clist)->selection; | |
1831 while (templist != NULL) | |
1832 { | |
1833 templist = get_next_selection (templist, &filelist, &curpos); | |
1834 tempfle = filelist->data; | |
1835 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME; | |
1836 gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Resume")); | |
1837 } | |
1838 } | |
1839 | |
1840 | |
1841 static void | |
1842 skip (GtkWidget * widget, gpointer data) | |
1843 { | |
1844 GList * templist, * filelist; | |
1845 gftp_transfer * tdata; | |
1846 gftp_file * tempfle; | |
1847 int curpos; | |
1848 | |
1849 tdata = data; | |
1850 curpos = 0; | |
1851 filelist = tdata->files; | |
1852 templist = GTK_CLIST (tdata->clist)->selection; | |
1853 while (templist != NULL) | |
1854 { | |
1855 templist = get_next_selection (templist, &filelist, &curpos); | |
1856 tempfle = filelist->data; | |
1857 tempfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
1858 gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Skip")); | |
1859 } | |
1860 } | |
1861 | |
1862 | |
1863 static void | |
1864 ok (GtkWidget * widget, gpointer data) | |
1865 { | |
1866 gftp_transfer * tdata; | |
1867 gftp_file * tempfle; | |
1868 GList * templist; | |
1869 | |
1870 tdata = data; | |
1871 pthread_mutex_lock ((pthread_mutex_t *) tdata->structmutex); | |
1872 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
1873 { | |
1874 tempfle = templist->data; | |
1875 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
1876 break; | |
1877 } | |
1878 | |
1879 if (templist == NULL) | |
1880 { | |
1881 tdata->show = 0; | |
1882 tdata->ready = tdata->done = 1; | |
1883 } | |
1884 else | |
1885 tdata->show = tdata->ready = 1; | |
1886 pthread_mutex_unlock ((pthread_mutex_t *) tdata->structmutex); | |
1887 } | |
1888 | |
1889 | |
1890 static void | |
1891 cancel (GtkWidget * widget, gpointer data) | |
1892 { | |
1893 gftp_transfer * tdata; | |
1894 | |
1895 tdata = data; | |
1896 pthread_mutex_lock ((pthread_mutex_t *) tdata->structmutex); | |
1897 tdata->show = 0; | |
1898 tdata->done = tdata->ready = 1; | |
1899 pthread_mutex_unlock ((pthread_mutex_t *) tdata->structmutex); | |
1900 } | |
1901 | |
1902 | |
1903 static void | |
1904 gftp_gtk_calc_kbs (gftp_transfer * tdata, ssize_t num_read) | |
1905 { | |
1906 unsigned long waitusecs; | |
1907 double difftime, curkbs; | |
1908 gftp_file * tempfle; | |
1909 struct timeval tv; | |
1910 unsigned long toadd; | |
1911 | |
1912 gettimeofday (&tv, NULL); | |
1913 pthread_mutex_lock (tdata->statmutex); | |
1914 | |
1915 tempfle = tdata->curfle->data; | |
1916 tdata->trans_bytes += num_read; | |
1917 tdata->curtrans += num_read; | |
1918 tdata->stalled = 0; | |
1919 | |
1920 difftime = (tv.tv_sec - tdata->starttime.tv_sec) + ((double) (tv.tv_usec - tdata->starttime.tv_usec) / 1000000.0); | |
19 | 1921 if (difftime <= 0) |
1 | 1922 tdata->kbs = (double) tdata->trans_bytes / 1024.0; |
1923 else | |
1924 tdata->kbs = (double) tdata->trans_bytes / 1024.0 / difftime; | |
1925 | |
1926 difftime = (tv.tv_sec - tdata->lasttime.tv_sec) + ((double) (tv.tv_usec - tdata->lasttime.tv_usec) / 1000000.0); | |
1927 | |
1928 if (difftime <= 0) | |
1929 curkbs = (double) (num_read / 1024.0); | |
1930 else | |
1931 curkbs = (double) (num_read / 1024.0 / difftime); | |
1932 | |
1933 if (tdata->fromreq->maxkbs > 0 && | |
1934 curkbs > tdata->fromreq->maxkbs) | |
1935 { | |
1936 waitusecs = (double) num_read / 1024.0 / tdata->fromreq->maxkbs * 1000000.0 - difftime; | |
1937 | |
1938 if (waitusecs > 0) | |
1939 { | |
1940 pthread_mutex_unlock (tdata->statmutex); | |
1941 difftime += ((double) waitusecs / 1000000.0); | |
1942 usleep (waitusecs); | |
1943 pthread_mutex_lock (tdata->statmutex); | |
1944 } | |
1945 } | |
1946 | |
1947 /* I don't call gettimeofday (&tdata->lasttime) here because this will use | |
1948 less system resources. This will be close enough for what we need */ | |
1949 difftime += tdata->lasttime.tv_usec / 1000000.0; | |
1950 toadd = (long) difftime; | |
1951 difftime -= toadd; | |
1952 tdata->lasttime.tv_sec += toadd; | |
1953 tdata->lasttime.tv_usec = difftime * 1000000.0; | |
1954 | |
1955 pthread_mutex_unlock (tdata->statmutex); | |
1956 } | |
1957 | |
1958 | |
1959 static void | |
1960 check_done_process (void) | |
1961 { | |
1962 gftp_viewedit_data * ve_proc; | |
1963 GList * curdata, *deldata; | |
1964 struct stat st; | |
1965 int ret; | |
1966 char *str; | |
1967 pid_t pid; | |
1968 | |
1969 viewedit_process_done = 0; | |
1970 while ((pid = waitpid (-1, &ret, WNOHANG)) > 0) | |
1971 { | |
1972 curdata = viewedit_processes; | |
1973 while (curdata != NULL) | |
1974 { | |
1975 ve_proc = curdata->data; | |
1976 deldata = curdata; | |
1977 curdata = curdata->next; | |
1978 if (ve_proc->pid == pid) | |
1979 { | |
1980 viewedit_processes = g_list_remove_link (viewedit_processes, | |
1981 deldata); | |
1982 if (ret != 0) | |
1983 ftp_log (gftp_logging_error, NULL, | |
1984 _("Error: Child %d returned %d\n"), pid, ret); | |
1985 else | |
1986 ftp_log (gftp_logging_misc, NULL, | |
1987 _("Child %d returned successfully\n"), pid); | |
1988 | |
1989 if (!ve_proc->view && !ve_proc->dontupload) | |
1990 { | |
1991 /* We was editing the file. Upload it */ | |
1992 if (stat (ve_proc->filename, &st) == -1) | |
1993 ftp_log (gftp_logging_error, NULL, | |
1994 _("Error: Cannot get information about file %s: %s\n"), | |
1995 ve_proc->filename, g_strerror (errno)); | |
1996 else if (st.st_mtime == ve_proc->st.st_mtime) | |
1997 { | |
1998 ftp_log (gftp_logging_misc, NULL, | |
1999 _("File %s was not changed\n"), | |
2000 ve_proc->filename); | |
2001 remove_file (ve_proc->filename); | |
2002 } | |
2003 else | |
2004 { | |
2005 memcpy (&ve_proc->st, &st, sizeof (ve_proc->st)); | |
2006 str = g_strdup_printf ( | |
19 | 2007 _("File %s has changed.\nWould you like to upload it?"), |
1 | 2008 ve_proc->remote_filename); |
2009 | |
19 | 2010 MakeYesNoDialog (_("Edit File"), str, |
2011 do_upload, ve_proc, | |
2012 dont_upload, ve_proc); | |
1 | 2013 g_free (str); |
2014 continue; | |
2015 } | |
2016 } | |
2017 | |
19 | 2018 free_edit_data (ve_proc); |
1 | 2019 continue; |
2020 } | |
2021 } | |
2022 } | |
2023 } | |
2024 | |
2025 | |
2026 static void | |
19 | 2027 do_upload (gftp_viewedit_data * ve_proc, gftp_dialog_data * ddata) |
1 | 2028 { |
2029 gftp_file * tempfle; | |
2030 GList * newfile; | |
2031 | |
2032 tempfle = g_malloc0 (sizeof (*tempfle)); | |
2033 tempfle->destfile = ve_proc->remote_filename; | |
2034 ve_proc->remote_filename = NULL; | |
2035 tempfle->file = ve_proc->filename; | |
2036 ve_proc->filename = NULL; | |
2037 tempfle->done_rm = 1; | |
2038 newfile = g_list_append (NULL, tempfle); | |
2039 add_file_transfer (ve_proc->fromwdata->request, ve_proc->towdata->request, | |
2040 ve_proc->fromwdata, ve_proc->towdata, newfile, 1); | |
19 | 2041 free_edit_data (ve_proc); |
1 | 2042 } |
2043 | |
2044 | |
2045 static void | |
19 | 2046 dont_upload (gftp_viewedit_data * ve_proc, gftp_dialog_data * ddata) |
1 | 2047 { |
2048 remove_file (ve_proc->filename); | |
19 | 2049 free_edit_data (ve_proc); |
1 | 2050 } |
2051 | |
2052 | |
2053 static void | |
19 | 2054 free_edit_data (gftp_viewedit_data * ve_proc) |
1 | 2055 { |
2056 int i; | |
2057 | |
2058 if (ve_proc->filename) | |
2059 g_free (ve_proc->filename); | |
2060 if (ve_proc->remote_filename) | |
2061 g_free (ve_proc->remote_filename); | |
2062 for (i = 0; ve_proc->argv[i] != NULL; i++) | |
2063 g_free (ve_proc->argv[i]); | |
2064 g_free (ve_proc->argv); | |
2065 g_free (ve_proc); | |
2066 } | |
2067 | |
2068 | |
2069 static int | |
2070 get_status (gftp_transfer * tdata, ssize_t num_read) | |
2071 { | |
2072 gftp_file * tempfle; | |
2073 struct timeval tv; | |
2074 | |
2075 pthread_mutex_lock (tdata->structmutex); | |
2076 if (tdata->curfle == NULL) | |
2077 { | |
2078 pthread_mutex_unlock (tdata->structmutex); | |
2079 return (-1); | |
2080 } | |
2081 tempfle = tdata->curfle->data; | |
2082 pthread_mutex_unlock (tdata->structmutex); | |
2083 | |
2084 gftp_disconnect (tdata->fromreq); | |
2085 gftp_disconnect (tdata->toreq); | |
2086 if (num_read < 0 || tdata->skip_file) | |
2087 { | |
2088 if (tdata->fromreq->retries != 0 && tdata->current_file_retries >= tdata->fromreq->retries) | |
2089 { | |
2090 tdata->fromreq->logging_function (gftp_logging_error, | |
2091 tdata->fromreq->user_data, | |
2092 _("Error: Remote site %s disconnected. Max retries reached...giving up\n"), | |
36 | 2093 tdata->fromreq->hostname != NULL ? |
2094 tdata->fromreq->hostname : tdata->toreq->hostname); | |
1 | 2095 return (-1); |
2096 } | |
2097 else | |
2098 { | |
2099 tdata->fromreq->logging_function (gftp_logging_error, | |
2100 tdata->fromreq->user_data, | |
2101 _("Error: Remote site %s disconnected. Will reconnect in %d seconds\n"), | |
36 | 2102 tdata->fromreq->hostname != NULL ? |
2103 tdata->fromreq->hostname : tdata->toreq->hostname, | |
2104 tdata->fromreq->sleep_time); | |
1 | 2105 } |
2106 | |
2107 while (tdata->fromreq->retries == 0 || | |
2108 tdata->current_file_retries <= tdata->fromreq->retries) | |
2109 { | |
2110 if (!tdata->skip_file) | |
2111 { | |
2112 tv.tv_sec = tdata->fromreq->sleep_time; | |
2113 tv.tv_usec = 0; | |
2114 select (0, NULL, NULL, NULL, &tv); | |
2115 } | |
2116 | |
2117 if (gftp_connect (tdata->fromreq) == 0 && | |
2118 gftp_connect (tdata->toreq) == 0) | |
2119 { | |
2120 pthread_mutex_lock (tdata->structmutex); | |
2121 tdata->resumed_bytes = tdata->resumed_bytes + tdata->trans_bytes - tdata->curresumed - tdata->curtrans; | |
2122 tdata->trans_bytes = 0; | |
2123 if (tdata->skip_file) | |
2124 { | |
2125 tdata->total_bytes -= tempfle->size; | |
2126 tdata->curtrans = 0; | |
2127 | |
2128 tdata->curfle = tdata->curfle->next; | |
2129 tdata->next_file = 1; | |
2130 tdata->skip_file = 0; | |
2131 tdata->cancel = 0; | |
2132 } | |
2133 else | |
2134 { | |
2135 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME; | |
2136 tempfle->startsize = tdata->curtrans + tdata->curresumed; | |
2137 /* We decrement this here because it will be incremented in | |
2138 the loop again */ | |
2139 tdata->curresumed = 0; | |
2140 tdata->current_file_number--; /* Decrement this because it | |
2141 will be incremented when we | |
2142 continue in the loop */ | |
2143 } | |
2144 gettimeofday (&tdata->starttime, NULL); | |
2145 pthread_mutex_unlock (tdata->structmutex); | |
2146 return (1); | |
2147 } | |
2148 else | |
2149 tdata->current_file_retries++; | |
2150 } | |
2151 } | |
2152 else if (tdata->cancel) | |
2153 return (-1); | |
2154 | |
2155 return (0); | |
2156 } | |
2157 | |
2158 | |
2159 static void | |
2160 wakeup_main_thread (gpointer data, gint source, GdkInputCondition condition) | |
2161 { | |
2162 gftp_request * request; | |
2163 char c; | |
2164 | |
2165 request = data; | |
2166 if (request->wakeup_main_thread[0] > 0) | |
2167 read (request->wakeup_main_thread[0], &c, 1); | |
2168 } | |
2169 | |
2170 | |
2171 static gint | |
2172 setup_wakeup_main_thread (gftp_request * request) | |
2173 { | |
2174 gint handler; | |
2175 | |
2176 if (socketpair (AF_UNIX, SOCK_STREAM, 0, request->wakeup_main_thread) == 0) | |
2177 { | |
2178 handler = gdk_input_add (request->wakeup_main_thread[0], | |
2179 GDK_INPUT_READ, wakeup_main_thread, request); | |
2180 } | |
2181 else | |
2182 { | |
2183 request->wakeup_main_thread[0] = 0; | |
2184 request->wakeup_main_thread[1] = 0; | |
2185 handler = 0; | |
2186 } | |
2187 return (handler); | |
2188 } | |
2189 | |
2190 | |
2191 static void | |
2192 teardown_wakeup_main_thread (gftp_request * request, gint handler) | |
2193 { | |
2194 if (request->wakeup_main_thread[0] > 0 && request->wakeup_main_thread[1] > 0) | |
2195 { | |
2196 gdk_input_remove (handler); | |
2197 close (request->wakeup_main_thread[0]); | |
2198 close (request->wakeup_main_thread[1]); | |
2199 request->wakeup_main_thread[0] = 0; | |
2200 request->wakeup_main_thread[1] = 0; | |
2201 } | |
2202 } | |
2203 | |
2204 | |
2205 static mode_t | |
2206 parse_attribs (char *attribs) | |
2207 { | |
2208 mode_t mode; | |
2209 int cur; | |
2210 | |
2211 cur = 0; | |
2212 if (attribs[1] == 'r') | |
2213 cur += 4; | |
2214 if (attribs[2] == 'w') | |
2215 cur += 2; | |
2216 if (attribs[3] == 'x' || | |
2217 attribs[3] == 's') | |
2218 cur += 1; | |
2219 mode = cur; | |
2220 | |
2221 cur = 0; | |
2222 if (attribs[4] == 'r') | |
2223 cur += 4; | |
2224 if (attribs[5] == 'w') | |
2225 cur += 2; | |
2226 if (attribs[6] == 'x' || | |
2227 attribs[6] == 's') | |
2228 cur += 1; | |
2229 mode = (mode * 10) + cur; | |
2230 | |
2231 cur = 0; | |
2232 if (attribs[7] == 'r') | |
2233 cur += 4; | |
2234 if (attribs[8] == 'w') | |
2235 cur += 2; | |
2236 if (attribs[9] == 'x' || | |
2237 attribs[9] == 's') | |
2238 cur += 1; | |
2239 mode = (mode * 10) + cur; | |
2240 | |
2241 return (mode); | |
2242 } | |
2243 | |
2244 | |
2245 static void | |
2246 remove_file (char *filename) | |
2247 { | |
2248 if (unlink (filename) == 0) | |
2249 ftp_log (gftp_logging_misc, NULL, _("Successfully removed %s\n"), | |
2250 filename); | |
2251 else | |
2252 ftp_log (gftp_logging_error, NULL, | |
2253 _("Error: Could not remove file %s: %s\n"), filename, | |
2254 g_strerror (errno)); | |
2255 } | |
2256 | |
2257 | |
2258 static RETSIGTYPE | |
2259 sig_connquit (int signo) | |
2260 { | |
2261 signal (signo, sig_connquit); | |
2262 siglongjmp (connenvir, signo == SIGINT ? 1 : 2); | |
2263 } | |
2264 |