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