Mercurial > gftp.yaz
annotate src/gtk/transfer.c @ 84:7ef60ce2bdb2
2002-12-29 Brian Masney <masneyb@gftp.org>
* lib/ssh.c lib/config_file.c lib/Makefile.am lib/gftp.h lib/options.h - removed old legacy SSH protocol and option to enable this protocol
* lib/gftp.h - added GFTP_ERETRYABLE and GFTP_EFATAL error codes
* lib/bookmark.c lib/local.c lib/protocols.c lib/rfc959.c lib/rfc2068.c
lib/sshv2.c - return new error codes instead of -1 or -2
* lib/misc.c (gftp_*_sort_function_ds) - changed return values
* src/gtk/transfer.c (connect_thread) - if return value of
gftp_connect() is GFTP_EFATAL, don't attempt to retry the connection
author | masneyb |
---|---|
date | Sun, 29 Dec 2002 15:16:27 +0000 |
parents | fe308e435ed5 |
children | 759c7d019a89 |
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; | |
608 | |
609 pthread_mutex_lock (tdata->structmutex); | |
610 if (tdata->curfle == NULL) | |
611 { | |
612 pthread_mutex_unlock (tdata->structmutex); | |
613 return (-1); | |
614 } | |
615 tempfle = tdata->curfle->data; | |
616 pthread_mutex_unlock (tdata->structmutex); | |
617 | |
618 gftp_disconnect (tdata->fromreq); | |
619 gftp_disconnect (tdata->toreq); | |
620 if (num_read < 0 || tdata->skip_file) | |
621 { | |
622 if (tdata->fromreq->retries != 0 && tdata->current_file_retries >= tdata->fromreq->retries) | |
623 { | |
624 tdata->fromreq->logging_function (gftp_logging_error, | |
625 tdata->fromreq->user_data, | |
626 _("Error: Remote site %s disconnected. Max retries reached...giving up\n"), | |
627 tdata->fromreq->hostname != NULL ? | |
628 tdata->fromreq->hostname : tdata->toreq->hostname); | |
629 return (-1); | |
630 } | |
631 else | |
632 { | |
633 tdata->fromreq->logging_function (gftp_logging_error, | |
634 tdata->fromreq->user_data, | |
635 _("Error: Remote site %s disconnected. Will reconnect in %d seconds\n"), | |
636 tdata->fromreq->hostname != NULL ? | |
637 tdata->fromreq->hostname : tdata->toreq->hostname, | |
638 tdata->fromreq->sleep_time); | |
639 } | |
640 | |
641 while (tdata->fromreq->retries == 0 || | |
642 tdata->current_file_retries <= tdata->fromreq->retries) | |
643 { | |
644 if (!tdata->skip_file) | |
645 { | |
646 tv.tv_sec = tdata->fromreq->sleep_time; | |
647 tv.tv_usec = 0; | |
648 select (0, NULL, NULL, NULL, &tv); | |
649 } | |
650 | |
651 if (gftp_connect (tdata->fromreq) == 0 && | |
652 gftp_connect (tdata->toreq) == 0) | |
653 { | |
654 pthread_mutex_lock (tdata->structmutex); | |
655 tdata->resumed_bytes = tdata->resumed_bytes + tdata->trans_bytes - tdata->curresumed - tdata->curtrans; | |
656 tdata->trans_bytes = 0; | |
657 if (tdata->skip_file) | |
658 { | |
659 tdata->total_bytes -= tempfle->size; | |
660 tdata->curtrans = 0; | |
661 | |
662 tdata->curfle = tdata->curfle->next; | |
663 tdata->next_file = 1; | |
664 tdata->skip_file = 0; | |
665 tdata->cancel = 0; | |
666 tdata->fromreq->cancel = 0; | |
667 tdata->toreq->cancel = 0; | |
668 } | |
669 else | |
670 { | |
671 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME; | |
672 tempfle->startsize = tdata->curtrans + tdata->curresumed; | |
673 /* We decrement this here because it will be incremented in | |
674 the loop again */ | |
675 tdata->curresumed = 0; | |
676 tdata->current_file_number--; /* Decrement this because it | |
677 will be incremented when we | |
678 continue in the loop */ | |
679 } | |
680 gettimeofday (&tdata->starttime, NULL); | |
681 pthread_mutex_unlock (tdata->structmutex); | |
682 return (1); | |
683 } | |
684 else | |
685 tdata->current_file_retries++; | |
686 } | |
687 } | |
688 else if (tdata->cancel) | |
689 return (-1); | |
690 | |
691 return (0); | |
692 } | |
693 | |
694 | |
695 static mode_t | |
696 parse_attribs (char *attribs) | |
697 { | |
698 mode_t mode; | |
699 int cur; | |
700 | |
701 cur = 0; | |
702 if (attribs[1] == 'r') | |
703 cur += 4; | |
704 if (attribs[2] == 'w') | |
705 cur += 2; | |
706 if (attribs[3] == 'x' || | |
707 attribs[3] == 's') | |
708 cur += 1; | |
709 mode = cur; | |
710 | |
711 cur = 0; | |
712 if (attribs[4] == 'r') | |
713 cur += 4; | |
714 if (attribs[5] == 'w') | |
715 cur += 2; | |
716 if (attribs[6] == 'x' || | |
717 attribs[6] == 's') | |
718 cur += 1; | |
719 mode = (mode * 10) + cur; | |
720 | |
721 cur = 0; | |
722 if (attribs[7] == 'r') | |
723 cur += 4; | |
724 if (attribs[8] == 'w') | |
725 cur += 2; | |
726 if (attribs[9] == 'x' || | |
727 attribs[9] == 's') | |
728 cur += 1; | |
729 mode = (mode * 10) + cur; | |
730 | |
731 return (mode); | |
732 } | |
733 | |
1 | 734 |
735 void * | |
736 gftp_gtk_transfer_files (void *data) | |
737 { | |
76 | 738 int i, mode, dl_type, tofd, fromfd, old_from_datatype; |
1 | 739 gftp_transfer * transfer; |
740 char *tempstr, buf[8192]; | |
741 off_t fromsize, total; | |
742 gftp_file * curfle; | |
743 ssize_t num_read; | |
744 | |
745 pthread_detach (pthread_self ()); | |
746 transfer = data; | |
747 transfer->curfle = transfer->files; | |
748 gettimeofday (&transfer->starttime, NULL); | |
749 memcpy (&transfer->lasttime, &transfer->starttime, | |
750 sizeof (transfer->lasttime)); | |
76 | 751 |
752 dl_type = transfer->fromreq->data_type; | |
753 old_from_datatype = transfer->fromreq->data_type; | |
754 | |
1 | 755 while (transfer->curfle != NULL) |
756 { | |
757 pthread_mutex_lock (transfer->structmutex); | |
758 curfle = transfer->curfle->data; | |
76 | 759 transfer->current_file_number++; |
1 | 760 pthread_mutex_unlock (transfer->structmutex); |
761 | |
762 if (curfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
763 { | |
764 pthread_mutex_lock (transfer->structmutex); | |
765 transfer->next_file = 1; | |
766 transfer->curfle = transfer->curfle->next; | |
767 pthread_mutex_unlock (transfer->structmutex); | |
768 continue; | |
769 } | |
770 | |
771 fromsize = -1; | |
772 if (gftp_connect (transfer->fromreq) == 0 && | |
773 gftp_connect (transfer->toreq) == 0) | |
774 { | |
775 if (curfle->isdir) | |
776 { | |
777 if (transfer->toreq->mkdir != NULL) | |
778 { | |
779 transfer->toreq->mkdir (transfer->toreq, curfle->destfile); | |
780 if (!GFTP_IS_CONNECTED (transfer->toreq)) | |
781 break; | |
782 } | |
783 | |
784 pthread_mutex_lock (transfer->structmutex); | |
785 transfer->next_file = 1; | |
786 transfer->curfle = transfer->curfle->next; | |
787 pthread_mutex_unlock (transfer->structmutex); | |
788 continue; | |
789 } | |
790 | |
791 if (transfer->fromreq->maxkbs > 0) | |
792 { | |
793 transfer->fromreq->logging_function (gftp_logging_misc, | |
794 transfer->fromreq->user_data, | |
795 _("File transfer will be throttled to %.2f KB/s\n"), | |
796 transfer->fromreq->maxkbs); | |
797 } | |
798 | |
799 if (curfle->is_fd) | |
800 { | |
801 if (transfer->transfer_direction == GFTP_DIRECTION_DOWNLOAD) | |
802 { | |
803 tofd = curfle->fd; | |
58 | 804 fromfd = -1; |
1 | 805 } |
806 else | |
807 { | |
58 | 808 tofd = -1; |
1 | 809 fromfd = curfle->fd; |
810 } | |
811 } | |
812 else | |
813 { | |
58 | 814 tofd = -1; |
815 fromfd = -1; | |
1 | 816 } |
817 | |
818 if (curfle->size == 0) | |
819 { | |
820 curfle->size = gftp_get_file_size (transfer->fromreq, curfle->file); | |
821 transfer->total_bytes += curfle->size; | |
822 } | |
823 | |
824 if (GFTP_IS_CONNECTED (transfer->fromreq) && | |
825 GFTP_IS_CONNECTED (transfer->toreq)) | |
826 { | |
76 | 827 if (!curfle->ascii && old_from_datatype == GFTP_TYPE_BINARY) |
828 dl_type = GFTP_TYPE_BINARY; | |
829 else | |
830 dl_type = GFTP_GET_DATA_TYPE (transfer->fromreq) == GFTP_TYPE_ASCII || curfle->ascii ? GFTP_TYPE_ASCII : GFTP_TYPE_BINARY; | |
831 | |
832 if (dl_type != transfer->fromreq->data_type) | |
74 | 833 { |
76 | 834 if (gftp_set_data_type (transfer->fromreq, dl_type) != 0) |
835 gftp_disconnect (transfer->fromreq); | |
836 } | |
74 | 837 |
76 | 838 if (dl_type != transfer->toreq->data_type) |
839 { | |
840 if (gftp_set_data_type (transfer->toreq, dl_type) != 0) | |
841 gftp_disconnect (transfer->toreq); | |
842 } | |
843 } | |
74 | 844 |
76 | 845 if (GFTP_IS_CONNECTED (transfer->fromreq) && |
846 GFTP_IS_CONNECTED (transfer->toreq)) | |
847 { | |
1 | 848 fromsize = gftp_transfer_file (transfer->fromreq, curfle->file, |
849 fromfd, | |
850 curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? | |
851 curfle->startsize : 0, | |
852 transfer->toreq, curfle->destfile, tofd, | |
853 curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? | |
854 curfle->startsize : 0); | |
855 } | |
856 } | |
857 | |
858 if (!GFTP_IS_CONNECTED (transfer->fromreq) || | |
859 !GFTP_IS_CONNECTED (transfer->toreq)) | |
860 { | |
861 transfer->fromreq->logging_function (gftp_logging_misc, | |
862 transfer->fromreq->user_data, | |
863 _("Error: Remote site disconnected after trying to transfer file\n")); | |
864 num_read = -1; | |
865 } | |
866 else if (fromsize < 0) | |
867 { | |
868 if (curfle->is_fd) | |
869 { | |
870 if (transfer->transfer_direction == GFTP_DIRECTION_DOWNLOAD) | |
58 | 871 transfer->toreq->datafd = -1; |
1 | 872 else |
58 | 873 transfer->fromreq->datafd = -1; |
1 | 874 } |
875 | |
876 pthread_mutex_lock (transfer->structmutex); | |
877 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
878 transfer->next_file = 1; | |
879 transfer->curfle = transfer->curfle->next; | |
880 pthread_mutex_unlock (transfer->structmutex); | |
881 continue; | |
882 } | |
883 else | |
884 { | |
885 pthread_mutex_lock (transfer->structmutex); | |
886 transfer->curtrans = 0; | |
887 transfer->curresumed = curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? curfle->startsize : 0; | |
888 transfer->resumed_bytes += transfer->curresumed; | |
889 pthread_mutex_unlock (transfer->structmutex); | |
890 | |
891 total = 0; | |
892 i = 0; | |
893 while (!transfer->cancel && | |
894 (num_read = gftp_get_next_file_chunk (transfer->fromreq, | |
895 buf, sizeof (buf))) > 0) | |
896 { | |
897 total += num_read; | |
898 gftp_gtk_calc_kbs (transfer, num_read); | |
899 | |
76 | 900 if (dl_type == GFTP_TYPE_ASCII) |
1 | 901 tempstr = gftp_convert_ascii (buf, &num_read, 1); |
902 else | |
903 tempstr = buf; | |
904 | |
905 if (gftp_put_next_file_chunk (transfer->toreq, tempstr, | |
906 num_read) < 0) | |
907 { | |
908 num_read = -1; | |
909 break; | |
910 } | |
911 | |
912 /* We don't have to free tempstr for a download because new | |
913 memory is not allocated for it in that case */ | |
76 | 914 if (dl_type == GFTP_TYPE_ASCII && |
1 | 915 transfer->transfer_direction == GFTP_DIRECTION_UPLOAD) |
916 g_free (tempstr); | |
917 } | |
918 } | |
919 | |
40 | 920 if (transfer->cancel) |
921 { | |
922 if (gftp_abort_transfer (transfer->fromreq) != 0) | |
923 gftp_disconnect (transfer->fromreq); | |
924 | |
925 if (gftp_abort_transfer (transfer->toreq) != 0) | |
926 gftp_disconnect (transfer->toreq); | |
927 } | |
928 else if (num_read < 0) | |
1 | 929 { |
930 transfer->fromreq->logging_function (gftp_logging_misc, | |
931 transfer->fromreq->user_data, | |
932 _("Could not download %s from %s\n"), | |
933 curfle->file, | |
934 transfer->fromreq->hostname); | |
935 | |
936 if (get_status (transfer, num_read) == 1) | |
40 | 937 continue; |
938 | |
1 | 939 break; |
940 } | |
941 else | |
942 { | |
40 | 943 /* FIXME - this needs cleaned up. NOTE: view/edit file will be |
944 broken if the file has to be resumed */ | |
1 | 945 if (curfle->is_fd) |
946 { | |
947 if (transfer->transfer_direction == GFTP_DIRECTION_DOWNLOAD) | |
58 | 948 transfer->toreq->datafd = -1; |
1 | 949 else |
58 | 950 transfer->fromreq->datafd = -1; |
1 | 951 } |
952 | |
953 if (gftp_end_transfer (transfer->fromreq) != 0) | |
954 { | |
955 if (get_status (transfer, -1) == 1) | |
40 | 956 continue; |
957 | |
1 | 958 break; |
959 } | |
960 gftp_end_transfer (transfer->toreq); | |
961 | |
962 transfer->fromreq->logging_function (gftp_logging_misc, | |
963 transfer->fromreq->user_data, | |
964 _("Successfully transferred %s at %.2f KB/s\n"), | |
965 curfle->file, transfer->kbs); | |
966 } | |
967 | |
968 if (!curfle->is_fd) | |
969 { | |
970 if (curfle->attribs) | |
971 { | |
972 mode = parse_attribs (curfle->attribs); | |
973 if (mode != 0) | |
974 gftp_chmod (transfer->toreq, curfle->destfile, | |
975 parse_attribs (curfle->attribs)); | |
976 } | |
977 | |
978 if (curfle->datetime != 0) | |
979 gftp_set_file_time (transfer->toreq, curfle->destfile, | |
980 curfle->datetime); | |
981 } | |
982 | |
983 pthread_mutex_lock (transfer->structmutex); | |
984 transfer->next_file = 1; | |
985 curfle->transfer_done = 1; | |
986 transfer->curfle = transfer->curfle->next; | |
987 pthread_mutex_unlock (transfer->structmutex); | |
988 | |
989 if (transfer->cancel && !transfer->skip_file) | |
990 break; | |
991 transfer->cancel = 0; | |
42 | 992 transfer->fromreq->cancel = 0; |
993 transfer->toreq->cancel = 0; | |
1 | 994 } |
995 transfer->done = 1; | |
996 return (NULL); | |
997 } | |
998 | |
999 | |
1000 void | |
1001 add_file_transfer (gftp_request * fromreq, gftp_request * toreq, | |
1002 gftp_window_data * fromwdata, gftp_window_data * towdata, | |
1003 GList * files, int copy_req) | |
1004 { | |
1005 gftp_curtrans_data * transdata; | |
1006 GList * templist, *curfle; | |
1007 gftp_transfer * tdata; | |
1008 gftp_file * tempfle; | |
1009 char *pos, *text[2]; | |
1010 int dialog; | |
1011 | |
1012 for (templist = files; templist != NULL; templist = templist->next) | |
1013 { | |
1014 tempfle = templist->data; | |
1015 if (tempfle->startsize > 0) | |
1016 break; | |
1017 } | |
1018 dialog = templist != NULL; | |
1019 | |
1020 if (append_file_transfers) | |
1021 { | |
1022 pthread_mutex_lock (&transfer_mutex); | |
1023 for (templist = file_transfers; templist != NULL; templist = templist->next) | |
1024 { | |
1025 tdata = templist->data; | |
1026 pthread_mutex_lock (tdata->structmutex); | |
1027 if (compare_request (tdata->fromreq, fromreq, 0) && | |
1028 compare_request (tdata->toreq, toreq, 0) && | |
1029 tdata->curfle != NULL) | |
1030 { | |
1031 if (!copy_req) | |
1032 { | |
67 | 1033 gftp_request_destroy (fromreq, 1); |
1034 gftp_request_destroy (toreq, 1); | |
1 | 1035 } |
1036 fromreq = NULL; | |
1037 toreq = NULL; | |
1038 | |
1039 for (curfle = tdata->curfle; | |
1040 curfle != NULL && curfle->next != NULL; | |
1041 curfle = curfle->next); | |
1042 if (curfle == NULL) | |
1043 { | |
1044 curfle = files; | |
1045 files->prev = NULL; | |
1046 } | |
1047 else | |
1048 { | |
1049 curfle->next = files; | |
1050 files->prev = curfle; | |
1051 } | |
1052 | |
1053 for (curfle = files; curfle != NULL; curfle = curfle->next) | |
1054 { | |
1055 tempfle = curfle->data; | |
1056 if (tempfle->isdir) | |
1057 tdata->numdirs++; | |
1058 else | |
1059 tdata->numfiles++; | |
1060 if ((pos = strrchr (tempfle->file, '/')) == NULL) | |
1061 pos = tempfle->file; | |
1062 else | |
1063 pos++; | |
1064 | |
1065 text[0] = pos; | |
1066 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
1067 text[1] = _("Skipped"); | |
1068 else | |
1069 { | |
1070 tdata->total_bytes += tempfle->size; | |
1071 text[1] = _("Waiting..."); | |
1072 } | |
1073 | |
1074 tempfle->node = gtk_ctree_insert_node (GTK_CTREE (dlwdw), | |
1075 tdata->node, NULL, text, 5, | |
1076 NULL, NULL, NULL, NULL, | |
1077 FALSE, FALSE); | |
1078 transdata = g_malloc (sizeof (*transdata)); | |
1079 transdata->transfer = tdata; | |
1080 transdata->curfle = curfle; | |
1081 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tempfle->node, | |
1082 transdata); | |
1083 } | |
1084 pthread_mutex_unlock (tdata->structmutex); | |
1085 break; | |
1086 } | |
1087 pthread_mutex_unlock (tdata->structmutex); | |
1088 } | |
1089 pthread_mutex_unlock (&transfer_mutex); | |
1090 } | |
1091 else | |
1092 templist = NULL; | |
1093 | |
1094 if (templist == NULL) | |
1095 { | |
1096 tdata = g_malloc0 (sizeof (*tdata)); | |
1097 if (copy_req) | |
1098 { | |
1099 tdata->fromreq = copy_request (fromreq); | |
1100 tdata->toreq = copy_request (toreq); | |
1101 } | |
1102 else | |
1103 { | |
1104 tdata->fromreq = fromreq; | |
1105 tdata->toreq = toreq; | |
1106 } | |
1107 tdata->transfer_direction = fromwdata && fromwdata == &window1 ? | |
1108 GFTP_DIRECTION_UPLOAD : GFTP_DIRECTION_DOWNLOAD; | |
1109 tdata->fromwdata = fromwdata; | |
1110 tdata->towdata = towdata; | |
1111 if (!dialog) | |
1112 tdata->show = tdata->ready = 1; | |
1113 tdata->files = files; | |
1114 for (curfle = files; curfle != NULL; curfle = curfle->next) | |
1115 { | |
1116 tempfle = curfle->data; | |
1117 if (tempfle->isdir) | |
1118 tdata->numdirs++; | |
1119 else | |
1120 tdata->numfiles++; | |
1121 } | |
1122 tdata->structmutex = g_malloc (sizeof (pthread_mutex_t)); | |
1123 pthread_mutex_init (tdata->structmutex, NULL); | |
1124 tdata->statmutex = g_malloc (sizeof (pthread_mutex_t)); | |
1125 pthread_mutex_init (tdata->statmutex, NULL); | |
1126 pthread_mutex_lock (&transfer_mutex); | |
1127 file_transfers = g_list_append (file_transfers, tdata); | |
1128 pthread_mutex_unlock (&transfer_mutex); | |
1129 if (dialog) | |
1130 gftp_gtk_ask_transfer (tdata); | |
1131 } | |
1132 } | |
1133 | |
1134 | |
48 | 1135 static void |
1136 remove_file (char *filename) | |
1137 { | |
1138 if (unlink (filename) == 0) | |
1139 ftp_log (gftp_logging_misc, NULL, _("Successfully removed %s\n"), | |
1140 filename); | |
1141 else | |
1142 ftp_log (gftp_logging_error, NULL, | |
1143 _("Error: Could not remove file %s: %s\n"), filename, | |
1144 g_strerror (errno)); | |
1145 } | |
1146 | |
1147 | |
1148 static void | |
1149 free_edit_data (gftp_viewedit_data * ve_proc) | |
1150 { | |
1151 int i; | |
1152 | |
1153 if (ve_proc->filename) | |
1154 g_free (ve_proc->filename); | |
1155 if (ve_proc->remote_filename) | |
1156 g_free (ve_proc->remote_filename); | |
1157 for (i = 0; ve_proc->argv[i] != NULL; i++) | |
1158 g_free (ve_proc->argv[i]); | |
1159 g_free (ve_proc->argv); | |
1160 g_free (ve_proc); | |
1161 } | |
1162 | |
1163 | |
1164 static void | |
1165 dont_upload (gftp_viewedit_data * ve_proc, gftp_dialog_data * ddata) | |
1 | 1166 { |
48 | 1167 remove_file (ve_proc->filename); |
1168 free_edit_data (ve_proc); | |
1169 } | |
1170 | |
1171 | |
1172 static void | |
1173 do_upload (gftp_viewedit_data * ve_proc, gftp_dialog_data * ddata) | |
1174 { | |
1175 gftp_file * tempfle; | |
1176 GList * newfile; | |
1 | 1177 |
48 | 1178 tempfle = g_malloc0 (sizeof (*tempfle)); |
1179 tempfle->destfile = ve_proc->remote_filename; | |
1180 ve_proc->remote_filename = NULL; | |
1181 tempfle->file = ve_proc->filename; | |
1182 ve_proc->filename = NULL; | |
1183 tempfle->done_rm = 1; | |
1184 newfile = g_list_append (NULL, tempfle); | |
1185 add_file_transfer (ve_proc->fromwdata->request, ve_proc->towdata->request, | |
1186 ve_proc->fromwdata, ve_proc->towdata, newfile, 1); | |
1187 free_edit_data (ve_proc); | |
1188 } | |
1189 | |
1 | 1190 |
48 | 1191 static void |
1192 check_done_process (void) | |
1193 { | |
1194 gftp_viewedit_data * ve_proc; | |
1195 GList * curdata, *deldata; | |
1196 struct stat st; | |
1197 int ret; | |
1198 char *str; | |
1199 pid_t pid; | |
1200 | |
1201 viewedit_process_done = 0; | |
1202 while ((pid = waitpid (-1, &ret, WNOHANG)) > 0) | |
1 | 1203 { |
48 | 1204 curdata = viewedit_processes; |
1205 while (curdata != NULL) | |
1206 { | |
1207 ve_proc = curdata->data; | |
1208 deldata = curdata; | |
1209 curdata = curdata->next; | |
1210 if (ve_proc->pid == pid) | |
1211 { | |
1212 viewedit_processes = g_list_remove_link (viewedit_processes, | |
1213 deldata); | |
1214 if (ret != 0) | |
1215 ftp_log (gftp_logging_error, NULL, | |
1216 _("Error: Child %d returned %d\n"), pid, ret); | |
1217 else | |
1218 ftp_log (gftp_logging_misc, NULL, | |
1219 _("Child %d returned successfully\n"), pid); | |
1220 | |
1221 if (!ve_proc->view && !ve_proc->dontupload) | |
1222 { | |
1223 /* We was editing the file. Upload it */ | |
1224 if (stat (ve_proc->filename, &st) == -1) | |
1225 ftp_log (gftp_logging_error, NULL, | |
1226 _("Error: Cannot get information about file %s: %s\n"), | |
1227 ve_proc->filename, g_strerror (errno)); | |
1228 else if (st.st_mtime == ve_proc->st.st_mtime) | |
1229 { | |
1230 ftp_log (gftp_logging_misc, NULL, | |
1231 _("File %s was not changed\n"), | |
1232 ve_proc->filename); | |
1233 remove_file (ve_proc->filename); | |
1234 } | |
1235 else | |
1236 { | |
1237 memcpy (&ve_proc->st, &st, sizeof (ve_proc->st)); | |
1238 str = g_strdup_printf ( | |
1239 _("File %s has changed.\nWould you like to upload it?"), | |
1240 ve_proc->remote_filename); | |
1241 | |
1242 MakeYesNoDialog (_("Edit File"), str, | |
1243 do_upload, ve_proc, | |
1244 dont_upload, ve_proc); | |
1245 g_free (str); | |
1246 continue; | |
1247 } | |
1248 } | |
1249 | |
1250 free_edit_data (ve_proc); | |
1251 continue; | |
1252 } | |
1 | 1253 } |
1254 } | |
1255 } | |
1256 | |
1257 | |
1258 static void | |
1259 on_next_transfer (gftp_transfer * tdata) | |
1260 { | |
1261 gftp_file * tempfle; | |
1262 int fd; | |
1263 | |
1264 tdata->next_file = 0; | |
1265 for (; tdata->updfle != tdata->curfle; tdata->updfle = tdata->updfle->next) | |
1266 { | |
1267 tempfle = tdata->updfle->data; | |
1268 | |
1269 if (tempfle->is_fd) | |
58 | 1270 fd = tempfle->fd; |
1 | 1271 else |
1272 fd = 0; | |
1273 | |
1274 if (tempfle->done_view) | |
1275 { | |
1276 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
1277 view_file (tempfle->destfile, fd, 1, tempfle->done_rm, 1, 0, | |
1278 tempfle->file, NULL); | |
1279 | |
1280 if (tempfle->is_fd) | |
1281 { | |
58 | 1282 close (tempfle->fd); |
1283 tempfle->fd = -1; | |
1 | 1284 } |
1285 } | |
1286 else if (tempfle->done_edit) | |
1287 { | |
1288 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
1289 view_file (tempfle->destfile, fd, 0, tempfle->done_rm, 1, 0, | |
1290 tempfle->file, NULL); | |
1291 | |
1292 if (tempfle->is_fd) | |
1293 { | |
58 | 1294 close (tempfle->fd); |
1295 tempfle->fd = -1; | |
1 | 1296 } |
1297 } | |
1298 else if (tempfle->done_rm) | |
1299 tdata->fromreq->rmfile (tdata->fromreq, tempfle->file); | |
1300 | |
1301 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
1302 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->node, 1, | |
1303 _("Skipped")); | |
1304 else | |
1305 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->node, 1, | |
1306 _("Finished")); | |
1307 } | |
1308 | |
1309 if (refresh_files && tdata->curfle && tdata->curfle->next && | |
1310 compare_request (tdata->toreq, | |
1311 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
1312 refresh (tdata->towdata); | |
1313 } | |
1314 | |
1315 | |
1316 static void | |
19 | 1317 get_trans_password (gftp_request * request, gftp_dialog_data * ddata) |
1318 { | |
1319 gftp_set_password (request, gtk_entry_get_text (GTK_ENTRY (ddata->edit))); | |
1320 request->stopable = 0; | |
1321 } | |
1322 | |
1323 | |
1324 static void | |
1325 cancel_get_trans_password (gftp_transfer * tdata, gftp_dialog_data * ddata) | |
1326 { | |
1327 if (tdata->fromreq->stopable == 0) | |
1328 return; | |
1329 | |
1330 pthread_mutex_lock (tdata->structmutex); | |
1331 if (tdata->started) | |
42 | 1332 { |
1333 tdata->cancel = 1; | |
1334 tdata->fromreq->cancel = 1; | |
1335 tdata->toreq->cancel = 1; | |
1336 } | |
19 | 1337 else |
1338 tdata->done = 1; | |
1339 | |
1340 tdata->fromreq->stopable = 0; | |
1341 tdata->toreq->stopable = 0; | |
40 | 1342 pthread_mutex_unlock (tdata->structmutex); |
1343 | |
19 | 1344 ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer of %s\n"), |
1345 ((gftp_file *) tdata->curfle->data)->file); | |
1346 } | |
1347 | |
1348 | |
1349 static void | |
1 | 1350 show_transfer (gftp_transfer * tdata) |
1351 { | |
1352 GdkPixmap * closedir_pixmap, * opendir_pixmap; | |
1353 GdkBitmap * closedir_bitmap, * opendir_bitmap; | |
1354 gftp_curtrans_data * transdata; | |
1355 gftp_file * tempfle; | |
1356 char *pos, *text[2]; | |
1357 GList * templist; | |
1358 | |
1359 gftp_get_pixmap (dlwdw, "open_dir.xpm", &opendir_pixmap, &opendir_bitmap); | |
1360 gftp_get_pixmap (dlwdw, "dir.xpm", &closedir_pixmap, &closedir_bitmap); | |
1361 | |
1362 text[0] = GFTP_GET_HOSTNAME (tdata->fromreq); | |
1363 text[1] = _("Waiting..."); | |
1364 tdata->node = gtk_ctree_insert_node (GTK_CTREE (dlwdw), NULL, NULL, text, 5, | |
1365 closedir_pixmap, closedir_bitmap, | |
1366 opendir_pixmap, opendir_bitmap, | |
1367 FALSE, | |
1368 tdata->numdirs + tdata->numfiles < 50); | |
1369 transdata = g_malloc (sizeof (*transdata)); | |
1370 transdata->transfer = tdata; | |
1371 transdata->curfle = NULL; | |
1372 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tdata->node, transdata); | |
1373 tdata->show = 0; | |
1374 tdata->curfle = tdata->updfle = tdata->files; | |
1375 | |
1376 tdata->total_bytes = 0; | |
1377 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
1378 { | |
1379 tempfle = templist->data; | |
1380 if ((pos = strrchr (tempfle->file, '/')) == NULL) | |
1381 pos = tempfle->file; | |
1382 else | |
1383 pos++; | |
1384 text[0] = pos; | |
1385 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
1386 text[1] = _("Skipped"); | |
1387 else | |
1388 { | |
1389 tdata->total_bytes += tempfle->size; | |
1390 text[1] = _("Waiting..."); | |
1391 } | |
1392 | |
1393 tempfle->node = gtk_ctree_insert_node (GTK_CTREE (dlwdw), tdata->node, | |
1394 NULL, text, 5, NULL, NULL, NULL, | |
1395 NULL, FALSE, FALSE); | |
1396 transdata = g_malloc (sizeof (*transdata)); | |
1397 transdata->transfer = tdata; | |
1398 transdata->curfle = templist; | |
1399 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tempfle->node, transdata); | |
1400 } | |
1401 | |
1402 if (!tdata->toreq->stopable && tdata->toreq->need_userpass && | |
1403 (tdata->toreq->password == NULL || *tdata->toreq->password == '\0')) | |
1404 { | |
1405 tdata->toreq->stopable = 1; | |
1406 MakeEditDialog (_("Enter Password"), | |
1407 _("Please enter your password for this site"), NULL, 0, | |
19 | 1408 NULL, gftp_dialog_button_connect, |
1409 get_trans_password, tdata->toreq, | |
1410 cancel_get_trans_password, tdata); | |
1 | 1411 } |
1412 | |
1413 if (!tdata->fromreq->stopable && tdata->fromreq->need_userpass && | |
1414 (tdata->fromreq->password == NULL || *tdata->fromreq->password == '\0')) | |
1415 { | |
1416 tdata->fromreq->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->fromreq, | |
1421 cancel_get_trans_password, tdata); | |
1 | 1422 } |
1423 } | |
1424 | |
1425 | |
1426 static void | |
1427 transfer_done (GList * node) | |
1428 { | |
1429 gftp_curtrans_data * transdata; | |
1430 gftp_request * fromreq; | |
1431 gftp_transfer * tdata; | |
1432 gftp_file * tempfle; | |
1433 GList * templist; | |
1434 | |
1435 tdata = node->data; | |
1436 if (tdata->started) | |
1437 { | |
56 | 1438 fromreq = tdata->fromwdata != NULL ? ((gftp_window_data *) tdata->fromwdata)->request : NULL; |
1 | 1439 if (!tdata->fromreq->stopable && tdata->fromwdata && |
67 | 1440 ((fromreq->sockfd < 0 && fromreq->cached) || fromreq->always_connected) && |
66 | 1441 (tdata->fromreq->sockfd > 0 || tdata->fromreq->always_connected) && |
1 | 1442 compare_request (tdata->fromreq, fromreq, 0)) |
1443 { | |
63 | 1444 gftp_swap_socks (((gftp_window_data *) tdata->towdata)->request, |
1445 tdata->toreq); | |
1446 gftp_swap_socks (((gftp_window_data *) tdata->fromwdata)->request, | |
1447 tdata->fromreq); | |
1 | 1448 } |
1449 else | |
1450 { | |
1451 gftp_disconnect (tdata->fromreq); | |
1452 gftp_disconnect (tdata->toreq); | |
1453 } | |
1454 | |
1455 if (tdata->towdata != NULL && compare_request (tdata->toreq, | |
1456 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
1457 refresh (tdata->towdata); | |
1458 | |
1459 transfer_in_progress--; | |
1460 } | |
1461 | |
2
a171df6764a7
* Fixed crash if you was already transfering a file, and you started another
masneyb
parents:
1
diff
changeset
|
1462 if (!tdata->show && tdata->started) |
1 | 1463 { |
1464 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), tdata->node); | |
1465 if (transdata != NULL) | |
1466 g_free (transdata); | |
1467 | |
1468 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
1469 { | |
1470 tempfle = templist->data; | |
1471 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), tempfle->node); | |
1472 if (transdata != NULL) | |
1473 g_free (transdata); | |
1474 } | |
1475 | |
1476 gtk_ctree_remove_node (GTK_CTREE (dlwdw), tdata->node); | |
1477 } | |
1478 pthread_mutex_lock (&transfer_mutex); | |
1479 file_transfers = g_list_remove_link (file_transfers, node); | |
1480 pthread_mutex_unlock (&transfer_mutex); | |
1481 pthread_mutex_destroy (tdata->structmutex); | |
1482 pthread_mutex_destroy (tdata->statmutex); | |
1483 free_tdata (tdata); | |
1484 } | |
1485 | |
1486 | |
1487 static void | |
1488 create_transfer (gftp_transfer * tdata) | |
1489 { | |
1490 pthread_t tid; | |
1491 | |
1492 if (!tdata->fromreq->stopable) | |
1493 { | |
1494 if (tdata->fromwdata && | |
66 | 1495 (((gftp_window_data *) tdata->fromwdata)->request->sockfd > 0 || |
1496 ((gftp_window_data *) tdata->fromwdata)->request->always_connected) && | |
1 | 1497 !((gftp_window_data *) tdata->fromwdata)->request->stopable && |
1498 compare_request (tdata->fromreq, ((gftp_window_data *) tdata->fromwdata)->request, 0)) | |
1499 { | |
63 | 1500 gftp_swap_socks (tdata->toreq, |
1501 ((gftp_window_data *) tdata->towdata)->request); | |
1502 gftp_swap_socks (tdata->fromreq, | |
1503 ((gftp_window_data *) tdata->fromwdata)->request); | |
1 | 1504 update_window_info (); |
1505 } | |
1506 transfer_in_progress++; | |
1507 tdata->started = 1; | |
1508 tdata->stalled = 1; | |
1509 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->node, 1, | |
1510 _("Connecting...")); | |
1511 pthread_create (&tid, NULL, gftp_gtk_transfer_files, tdata); | |
1512 } | |
1513 } | |
1514 | |
1515 | |
1516 static void | |
1517 update_file_status (gftp_transfer * tdata) | |
1518 { | |
1519 char totstr[100], dlstr[100], gotstr[50], ofstr[50]; | |
1520 int hours, mins, secs, pcent, st; | |
1521 double remaining; | |
1522 gftp_file * tempfle; | |
1523 struct timeval tv; | |
1524 | |
1525 pthread_mutex_lock (tdata->statmutex); | |
1526 tempfle = tdata->curfle->data; | |
1527 | |
1528 gettimeofday (&tv, NULL); | |
1529 if ((remaining = (double) (tv.tv_sec - tdata->starttime.tv_sec) + ((double) (tv.tv_usec - tdata->starttime.tv_usec) / 1000000.0)) == 0) | |
1530 remaining = 1.0; | |
1531 | |
1532 remaining = ((double) (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes)) / 1024.0 / tdata->kbs; | |
1533 hours = (off_t) remaining / 3600; | |
1534 remaining -= hours * 3600; | |
1535 mins = (off_t) remaining / 60; | |
1536 remaining -= mins * 60; | |
1537 secs = (off_t) remaining; | |
1538 | |
1539 if (hours < 0 || mins < 0 || secs < 0) | |
1540 { | |
1541 pthread_mutex_unlock (tdata->statmutex); | |
1542 return; | |
1543 } | |
1544 | |
1545 pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0); | |
1546 if (pcent < 0 || pcent > 100) | |
1547 pcent = 0; | |
1548 | |
1549 g_snprintf (totstr, sizeof (totstr), | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
1550 _("%d%% complete, %02d:%02d:%02d est. time remaining. (File %ld of %ld)"), |
1 | 1551 pcent, hours, mins, secs, tdata->current_file_number, |
1552 tdata->numdirs + tdata->numfiles); | |
1553 | |
1554 *dlstr = '\0'; | |
1555 if (!tdata->stalled) | |
1556 { | |
1557 insert_commas (tdata->curtrans + tdata->curresumed, gotstr, sizeof (gotstr)); | |
1558 insert_commas (tempfle->size, ofstr, sizeof (ofstr)); | |
1559 st = 1; | |
1560 if (tv.tv_sec - tdata->lasttime.tv_sec <= 5) | |
1561 { | |
1562 if (tdata->curfle->next != NULL) | |
1563 { | |
1564 remaining = ((double) (tempfle->size - tdata->curtrans - tdata->curresumed)) / 1024.0 / tdata->kbs; | |
1565 hours = (off_t) remaining / 3600; | |
1566 remaining -= hours * 3600; | |
1567 mins = (off_t) remaining / 60; | |
1568 remaining -= mins * 60; | |
1569 secs = (off_t) remaining; | |
1570 } | |
1571 | |
1572 if (!(hours < 0 || mins < 0 || secs < 0)) | |
1573 { | |
1574 g_snprintf (dlstr, sizeof (dlstr), | |
1575 _("Recv %s of %s at %.2fKB/s, %02d:%02d:%02d est. time remaining"), gotstr, ofstr, tdata->kbs, hours, mins, secs); | |
1576 st = 0; | |
1577 } | |
1578 } | |
1579 | |
1580 if (st) | |
1581 { | |
1582 tdata->stalled = 1; | |
1583 g_snprintf (dlstr, sizeof (dlstr), | |
1584 _("Recv %s of %s, transfer stalled, unknown time remaining"), | |
1585 gotstr, ofstr); | |
1586 } | |
1587 } | |
1588 | |
1589 pthread_mutex_unlock (tdata->statmutex); | |
1590 | |
1591 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->node, 1, totstr); | |
1592 | |
1593 if (*dlstr != '\0') | |
1594 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->node, 1, dlstr); | |
1595 } | |
1596 | |
56 | 1597 static void |
1598 update_window_transfer_bytes (gftp_window_data * wdata) | |
1599 { | |
1600 char *tempstr, *temp1str; | |
1601 | |
1602 if (wdata->request->gotbytes == -1) | |
1603 { | |
1604 update_window_info (); | |
1605 wdata->request->gotbytes = 0; | |
1606 } | |
1607 else | |
1608 { | |
1609 tempstr = insert_commas (wdata->request->gotbytes, NULL, 0); | |
1610 temp1str = g_strdup_printf (_("Retrieving file names...%s bytes"), | |
1611 tempstr); | |
1612 gtk_label_set (GTK_LABEL (wdata->hoststxt), temp1str); | |
1613 g_free (tempstr); | |
1614 g_free (temp1str); | |
1615 } | |
1616 } | |
1617 | |
1 | 1618 |
48 | 1619 gint |
1620 update_downloads (gpointer data) | |
1621 { | |
1622 GList * templist, * next; | |
1623 gftp_transfer * tdata; | |
1624 | |
1625 if (file_transfer_logs != NULL) | |
1626 display_cached_logs (); | |
1627 | |
56 | 1628 if (window1.request->gotbytes != 0) |
1629 update_window_transfer_bytes (&window1); | |
48 | 1630 if (window2.request->gotbytes != 0) |
56 | 1631 update_window_transfer_bytes (&window2); |
48 | 1632 |
1633 if (viewedit_process_done) | |
1634 check_done_process (); | |
1635 | |
1636 for (templist = file_transfers; templist != NULL;) | |
1637 { | |
1638 tdata = templist->data; | |
1639 if (tdata->ready) | |
1640 { | |
1641 pthread_mutex_lock (tdata->structmutex); | |
1642 | |
1643 if (tdata->next_file) | |
1644 on_next_transfer (tdata); | |
1645 else if (tdata->show) | |
1646 show_transfer (tdata); | |
1647 else if (tdata->done) | |
1648 { | |
1649 next = templist->next; | |
59 | 1650 pthread_mutex_unlock (tdata->structmutex); |
48 | 1651 transfer_done (templist); |
1652 templist = next; | |
1653 continue; | |
1654 } | |
1655 | |
1656 if (tdata->curfle != NULL) | |
1657 { | |
1658 if (!tdata->started && start_file_transfers && | |
1659 (transfer_in_progress == 0 || !do_one_transfer_at_a_time)) | |
1660 create_transfer (tdata); | |
1661 | |
1662 if (tdata->started) | |
1663 update_file_status (tdata); | |
1664 } | |
1665 pthread_mutex_unlock (tdata->structmutex); | |
1666 } | |
1667 templist = templist->next; | |
1668 } | |
1669 | |
1670 gtk_timeout_add (500, update_downloads, NULL); | |
1671 return (0); | |
1672 } | |
1673 | |
1674 | |
1 | 1675 void |
1676 start_transfer (gpointer data) | |
1677 { | |
1678 gftp_curtrans_data * transdata; | |
1679 GtkCTreeNode * node; | |
1680 | |
1681 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1682 { | |
1683 ftp_log (gftp_logging_misc, NULL, | |
1684 _("There are no file transfers selected\n")); | |
1685 return; | |
1686 } | |
1687 node = GTK_CLIST (dlwdw)->selection->data; | |
1688 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1689 | |
1690 pthread_mutex_lock (transdata->transfer->structmutex); | |
1691 if (!transdata->transfer->started) | |
1692 create_transfer (transdata->transfer); | |
1693 pthread_mutex_unlock (transdata->transfer->structmutex); | |
1694 } | |
1695 | |
1696 | |
1697 void | |
1698 stop_transfer (gpointer data) | |
1699 { | |
1700 gftp_curtrans_data * transdata; | |
1701 GtkCTreeNode * node; | |
1702 | |
1703 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1704 { | |
1705 ftp_log (gftp_logging_misc, NULL, | |
1706 _("There are no file transfers selected\n")); | |
1707 return; | |
1708 } | |
1709 node = GTK_CLIST (dlwdw)->selection->data; | |
1710 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1711 | |
1712 pthread_mutex_lock (transdata->transfer->structmutex); | |
1713 if (transdata->transfer->started) | |
1714 { | |
1715 transdata->transfer->cancel = 1; | |
42 | 1716 transdata->transfer->fromreq->cancel = 1; |
1717 transdata->transfer->toreq->cancel = 1; | |
1 | 1718 transdata->transfer->skip_file = 0; |
1719 } | |
1720 else | |
1721 transdata->transfer->done = 1; | |
40 | 1722 pthread_mutex_unlock (transdata->transfer->structmutex); |
1723 | |
1 | 1724 ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer on host %s\n"), |
1725 transdata->transfer->fromreq->hostname); | |
1726 } | |
1727 | |
1728 | |
1729 void | |
1730 skip_transfer (gpointer data) | |
1731 { | |
1732 gftp_curtrans_data * transdata; | |
1733 GtkCTreeNode * node; | |
1734 gftp_file * curfle; | |
40 | 1735 char *file; |
1 | 1736 |
1737 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1738 { | |
1739 ftp_log (gftp_logging_misc, NULL, | |
1740 _("There are no file transfers selected\n")); | |
1741 return; | |
1742 } | |
1743 node = GTK_CLIST (dlwdw)->selection->data; | |
1744 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1745 | |
1746 pthread_mutex_lock (transdata->transfer->structmutex); | |
1747 if (transdata->transfer->curfle != NULL) | |
1748 { | |
1749 curfle = transdata->transfer->curfle->data; | |
1750 if (transdata->transfer->started) | |
1751 { | |
1752 transdata->transfer->cancel = 1; | |
42 | 1753 transdata->transfer->fromreq->cancel = 1; |
1754 transdata->transfer->toreq->cancel = 1; | |
1 | 1755 transdata->transfer->skip_file = 1; |
1756 } | |
1757 | |
1758 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
40 | 1759 file = curfle->file; |
1 | 1760 } |
40 | 1761 else |
1762 file = NULL; | |
1 | 1763 pthread_mutex_unlock (transdata->transfer->structmutex); |
40 | 1764 |
1765 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), | |
1766 file, transdata->transfer->fromreq->hostname); | |
1 | 1767 } |
1768 | |
1769 | |
1770 void | |
1771 remove_file_transfer (gpointer data) | |
1772 { | |
1773 gftp_curtrans_data * transdata; | |
1774 GtkCTreeNode * node; | |
1775 gftp_file * curfle; | |
1776 | |
1777 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1778 { | |
1779 ftp_log (gftp_logging_misc, NULL, | |
1780 _("There are no file transfers selected\n")); | |
1781 return; | |
1782 } | |
1783 | |
1784 node = GTK_CLIST (dlwdw)->selection->data; | |
1785 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1786 | |
1787 | |
1788 if (transdata->curfle == NULL || transdata->curfle->data == NULL) | |
1789 return; | |
1790 | |
1791 curfle = transdata->curfle->data; | |
1792 | |
1793 if (curfle->transfer_action & GFTP_TRANS_ACTION_SKIP) | |
1794 return; | |
1795 | |
1796 pthread_mutex_lock (transdata->transfer->structmutex); | |
1797 | |
1798 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
1799 | |
1800 if (transdata->transfer->started && | |
1801 transdata->curfle == transdata->transfer->curfle) | |
1802 { | |
1803 transdata->transfer->cancel = 1; | |
42 | 1804 transdata->transfer->fromreq->cancel = 1; |
1805 transdata->transfer->toreq->cancel = 1; | |
1 | 1806 transdata->transfer->skip_file = 1; |
1807 } | |
1808 else if (transdata->curfle != transdata->transfer->curfle && | |
1809 !curfle->transfer_done) | |
1810 { | |
1811 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), curfle->node, 1, | |
1812 _("Skipped")); | |
1813 transdata->transfer->total_bytes -= curfle->size; | |
1814 } | |
1815 | |
40 | 1816 pthread_mutex_unlock (transdata->transfer->structmutex); |
1817 | |
1 | 1818 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), |
1819 curfle->file, transdata->transfer->fromreq->hostname); | |
1820 } | |
1821 | |
1822 | |
1823 void | |
1824 move_transfer_up (gpointer data) | |
1825 { | |
1826 GList * firstentry, * secentry, * lastentry; | |
1827 gftp_curtrans_data * transdata; | |
1828 GtkCTreeNode * node; | |
1829 | |
1830 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1831 { | |
1832 ftp_log (gftp_logging_misc, NULL, | |
1833 _("There are no file transfers selected\n")); | |
1834 return; | |
1835 } | |
1836 node = GTK_CLIST (dlwdw)->selection->data; | |
1837 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1838 | |
1839 if (transdata->curfle == NULL) | |
1840 return; | |
1841 | |
1842 pthread_mutex_lock (transdata->transfer->structmutex); | |
1843 if (transdata->curfle->prev != NULL && (!transdata->transfer->started || | |
1844 (transdata->transfer->curfle != transdata->curfle && | |
1845 transdata->transfer->curfle != transdata->curfle->prev))) | |
1846 { | |
1847 if (transdata->curfle->prev->prev == NULL) | |
1848 { | |
1849 firstentry = transdata->curfle->prev; | |
1850 lastentry = transdata->curfle->next; | |
1851 transdata->transfer->files = transdata->curfle; | |
1852 transdata->curfle->next = firstentry; | |
1853 transdata->transfer->files->prev = NULL; | |
1854 firstentry->prev = transdata->curfle; | |
1855 firstentry->next = lastentry; | |
1856 if (lastentry != NULL) | |
1857 lastentry->prev = firstentry; | |
1858 } | |
1859 else | |
1860 { | |
1861 firstentry = transdata->curfle->prev->prev; | |
1862 secentry = transdata->curfle->prev; | |
1863 lastentry = transdata->curfle->next; | |
1864 firstentry->next = transdata->curfle; | |
1865 transdata->curfle->prev = firstentry; | |
1866 transdata->curfle->next = secentry; | |
1867 secentry->prev = transdata->curfle; | |
1868 secentry->next = lastentry; | |
1869 if (lastentry != NULL) | |
1870 lastentry->prev = secentry; | |
1871 } | |
1872 | |
1873 gtk_ctree_move (GTK_CTREE (dlwdw), | |
1874 ((gftp_file *) transdata->curfle->data)->node, | |
1875 transdata->transfer->node, | |
1876 transdata->curfle->next != NULL ? | |
1877 ((gftp_file *) transdata->curfle->next->data)->node : | |
1878 NULL); | |
1879 } | |
1880 pthread_mutex_unlock (transdata->transfer->structmutex); | |
1881 } | |
1882 | |
1883 void | |
1884 move_transfer_down (gpointer data) | |
1885 { | |
1886 GList * firstentry, * secentry, * lastentry; | |
1887 gftp_curtrans_data * transdata; | |
1888 GtkCTreeNode * node; | |
1889 | |
1890 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1891 { | |
1892 ftp_log (gftp_logging_misc, NULL, | |
1893 _("There are no file transfers selected\n")); | |
1894 return; | |
1895 } | |
1896 node = GTK_CLIST (dlwdw)->selection->data; | |
1897 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1898 | |
1899 if (transdata->curfle == NULL) | |
1900 return; | |
1901 | |
1902 pthread_mutex_lock (transdata->transfer->structmutex); | |
1903 if (transdata->curfle->next != NULL && (!transdata->transfer->started || | |
1904 (transdata->transfer->curfle != transdata->curfle && | |
1905 transdata->transfer->curfle != transdata->curfle->next))) | |
1906 { | |
1907 if (transdata->curfle->prev == NULL) | |
1908 { | |
1909 firstentry = transdata->curfle->next; | |
1910 lastentry = transdata->curfle->next->next; | |
1911 transdata->transfer->files = firstentry; | |
1912 transdata->transfer->files->prev = NULL; | |
1913 transdata->transfer->files->next = transdata->curfle; | |
1914 transdata->curfle->prev = transdata->transfer->files; | |
1915 transdata->curfle->next = lastentry; | |
1916 if (lastentry != NULL) | |
1917 lastentry->prev = transdata->curfle; | |
1918 } | |
1919 else | |
1920 { | |
1921 firstentry = transdata->curfle->prev; | |
1922 secentry = transdata->curfle->next; | |
1923 lastentry = transdata->curfle->next->next; | |
1924 firstentry->next = secentry; | |
1925 secentry->prev = firstentry; | |
1926 secentry->next = transdata->curfle; | |
1927 transdata->curfle->prev = secentry; | |
1928 transdata->curfle->next = lastentry; | |
1929 if (lastentry != NULL) | |
1930 lastentry->prev = transdata->curfle; | |
1931 } | |
1932 | |
1933 gtk_ctree_move (GTK_CTREE (dlwdw), | |
1934 ((gftp_file *) transdata->curfle->data)->node, | |
1935 transdata->transfer->node, | |
1936 transdata->curfle->next != NULL ? | |
1937 ((gftp_file *) transdata->curfle->next->data)->node : | |
1938 NULL); | |
1939 } | |
1940 pthread_mutex_unlock (transdata->transfer->structmutex); | |
1941 } | |
1942 | |
1943 | |
48 | 1944 static void |
1945 trans_selectall (GtkWidget * widget, gpointer data) | |
1946 { | |
1947 gftp_transfer * tdata; | |
1948 tdata = data; | |
1949 | |
1950 gtk_clist_select_all (GTK_CLIST (tdata->clist)); | |
1951 } | |
1952 | |
1953 | |
1954 static void | |
1955 trans_unselectall (GtkWidget * widget, gpointer data) | |
1956 { | |
1957 gftp_transfer * tdata; | |
1958 tdata = data; | |
1959 | |
1960 gtk_clist_unselect_all (GTK_CLIST (tdata->clist)); | |
1961 } | |
1962 | |
1963 | |
1964 static void | |
1965 overwrite (GtkWidget * widget, gpointer data) | |
1966 { | |
1967 GList * templist, * filelist; | |
1968 gftp_transfer * tdata; | |
1969 gftp_file * tempfle; | |
1970 int curpos; | |
1971 | |
1972 tdata = data; | |
1973 curpos = 0; | |
1974 filelist = tdata->files; | |
1975 templist = GTK_CLIST (tdata->clist)->selection; | |
1976 while (templist != NULL) | |
1977 { | |
1978 templist = get_next_selection (templist, &filelist, &curpos); | |
1979 tempfle = filelist->data; | |
1980 tempfle->transfer_action = GFTP_TRANS_ACTION_OVERWRITE; | |
1981 gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Overwrite")); | |
1982 } | |
1983 } | |
1984 | |
1985 | |
1986 static void | |
1987 resume (GtkWidget * widget, gpointer data) | |
1988 { | |
1989 GList * templist, * filelist; | |
1990 gftp_transfer * tdata; | |
1991 gftp_file * tempfle; | |
1992 int curpos; | |
1993 | |
1994 tdata = data; | |
1995 curpos = 0; | |
1996 filelist = tdata->files; | |
1997 templist = GTK_CLIST (tdata->clist)->selection; | |
1998 while (templist != NULL) | |
1999 { | |
2000 templist = get_next_selection (templist, &filelist, &curpos); | |
2001 tempfle = filelist->data; | |
2002 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME; | |
2003 gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Resume")); | |
2004 } | |
2005 } | |
2006 | |
2007 | |
2008 static void | |
2009 skip (GtkWidget * widget, gpointer data) | |
2010 { | |
2011 GList * templist, * filelist; | |
2012 gftp_transfer * tdata; | |
2013 gftp_file * tempfle; | |
2014 int curpos; | |
2015 | |
2016 tdata = data; | |
2017 curpos = 0; | |
2018 filelist = tdata->files; | |
2019 templist = GTK_CLIST (tdata->clist)->selection; | |
2020 while (templist != NULL) | |
2021 { | |
2022 templist = get_next_selection (templist, &filelist, &curpos); | |
2023 tempfle = filelist->data; | |
2024 tempfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
2025 gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Skip")); | |
2026 } | |
2027 } | |
2028 | |
2029 | |
2030 static void | |
2031 ok (GtkWidget * widget, gpointer data) | |
2032 { | |
2033 gftp_transfer * tdata; | |
2034 gftp_file * tempfle; | |
2035 GList * templist; | |
2036 | |
2037 tdata = data; | |
2038 pthread_mutex_lock ((pthread_mutex_t *) tdata->structmutex); | |
2039 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
2040 { | |
2041 tempfle = templist->data; | |
2042 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
2043 break; | |
2044 } | |
2045 | |
2046 if (templist == NULL) | |
2047 { | |
2048 tdata->show = 0; | |
2049 tdata->ready = tdata->done = 1; | |
2050 } | |
2051 else | |
2052 tdata->show = tdata->ready = 1; | |
2053 pthread_mutex_unlock ((pthread_mutex_t *) tdata->structmutex); | |
2054 } | |
2055 | |
2056 | |
2057 static void | |
2058 cancel (GtkWidget * widget, gpointer data) | |
2059 { | |
2060 gftp_transfer * tdata; | |
2061 | |
2062 tdata = data; | |
2063 pthread_mutex_lock ((pthread_mutex_t *) tdata->structmutex); | |
2064 tdata->show = 0; | |
2065 tdata->done = tdata->ready = 1; | |
2066 pthread_mutex_unlock ((pthread_mutex_t *) tdata->structmutex); | |
2067 } | |
2068 | |
2069 | |
49 | 2070 #if GTK_MAJOR_VERSION > 1 |
2071 static void | |
2072 transfer_action (GtkWidget * widget, gint response, gpointer user_data) | |
2073 { | |
2074 switch (response) | |
2075 { | |
2076 case GTK_RESPONSE_OK: | |
2077 ok (widget, user_data); | |
2078 gtk_widget_destroy (widget); | |
2079 break; | |
2080 case GTK_RESPONSE_CANCEL: | |
2081 cancel (widget, user_data); | |
2082 /* no break */ | |
2083 default: | |
2084 gtk_widget_destroy (widget); | |
2085 } | |
2086 } | |
2087 #endif | |
2088 | |
2089 | |
1 | 2090 void |
2091 gftp_gtk_ask_transfer (gftp_transfer * tdata) | |
2092 { | |
2093 char *dltitles[4], *add_data[4] = { NULL, NULL, NULL, NULL }, | |
49 | 2094 tempstr[50], temp1str[50], *pos, *title; |
1 | 2095 GtkWidget * tempwid, * scroll, * hbox; |
2096 gftp_file * tempfle; | |
2097 GList * templist; | |
2098 size_t len; | |
2099 int i; | |
2100 | |
2101 dltitles[0] = _("Filename"); | |
2102 dltitles[1] = _("Local Size"); | |
2103 dltitles[2] = _("Remote Size"); | |
2104 dltitles[3] = _("Action"); | |
49 | 2105 title = tdata->transfer_direction == GFTP_DIRECTION_DOWNLOAD ? |
2106 _("Download Files") : _("Upload Files"); | |
2107 | |
2108 #if GTK_MAJOR_VERSION == 1 | |
2109 dialog = gtk_dialog_new (); | |
1 | 2110 gtk_grab_add (dialog); |
49 | 2111 gtk_window_set_title (GTK_WINDOW (dialog), title); |
2112 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 5); | |
1 | 2113 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 35); |
2114 gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE); | |
49 | 2115 |
1 | 2116 gtk_signal_connect_object (GTK_OBJECT (dialog), "delete_event", |
2117 GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
2118 GTK_OBJECT (dialog)); | |
49 | 2119 #else |
2120 dialog = gtk_dialog_new_with_buttons (title, NULL, 0, | |
2121 GTK_STOCK_OK, | |
2122 GTK_RESPONSE_OK, | |
2123 GTK_STOCK_CANCEL, | |
2124 GTK_RESPONSE_CANCEL, | |
2125 NULL); | |
2126 #endif | |
2127 gtk_window_set_wmclass (GTK_WINDOW(dialog), "transfer", "gFTP"); | |
2128 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); | |
2129 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 10); | |
2130 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 5); | |
1 | 2131 |
2132 tempwid = gtk_label_new (_("The following file(s) exist on both the local and remote computer\nPlease select what you would like to do")); | |
2133 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), tempwid, FALSE, | |
2134 FALSE, 0); | |
2135 gtk_widget_show (tempwid); | |
2136 | |
2137 scroll = gtk_scrolled_window_new (NULL, NULL); | |
2138 gtk_widget_set_size_request (scroll, 450, 200); | |
2139 | |
2140 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), | |
2141 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
2142 tdata->clist = gtk_clist_new_with_titles (4, dltitles); | |
2143 gtk_container_add (GTK_CONTAINER (scroll), tdata->clist); | |
2144 | |
45 | 2145 #if GTK_MAJOR_VERSION == 1 |
1 | 2146 gtk_clist_set_selection_mode (GTK_CLIST (tdata->clist), |
2147 GTK_SELECTION_EXTENDED); | |
2148 #else | |
2149 gtk_clist_set_selection_mode (GTK_CLIST (tdata->clist), | |
2150 GTK_SELECTION_MULTIPLE); | |
2151 #endif | |
2152 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 0, 100); | |
2153 gtk_clist_set_column_justification (GTK_CLIST (tdata->clist), 1, | |
2154 GTK_JUSTIFY_RIGHT); | |
2155 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 1, 85); | |
2156 gtk_clist_set_column_justification (GTK_CLIST (tdata->clist), 2, | |
2157 GTK_JUSTIFY_RIGHT); | |
2158 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 2, 85); | |
2159 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 3, 85); | |
2160 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), scroll, TRUE, TRUE, | |
2161 0); | |
2162 gtk_widget_show (tdata->clist); | |
2163 gtk_widget_show (scroll); | |
2164 | |
2165 for (templist = tdata->files; templist != NULL; | |
2166 templist = templist->next) | |
2167 { | |
2168 tempfle = templist->data; | |
2169 if (tempfle->startsize == 0 || tempfle->isdir) | |
2170 { | |
2171 tempfle->shown = 0; | |
2172 continue; | |
2173 } | |
2174 tempfle->shown = 1; | |
2175 | |
2176 pos = tempfle->destfile; | |
2177 len = strlen (GFTP_GET_DIRECTORY (tdata->toreq)); | |
2178 if (strncmp (pos, GFTP_GET_DIRECTORY (tdata->toreq), len) == 0) | |
2179 pos = tempfle->destfile + len + 1; | |
2180 add_data[0] = pos; | |
2181 | |
2182 if (overwrite_by_default) | |
2183 add_data[3] = _("Overwrite"); | |
2184 else | |
2185 { | |
2186 if (tempfle->startsize >= tempfle->size) | |
2187 { | |
2188 add_data[3] = _("Skip"); | |
2189 tempfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
2190 } | |
2191 else | |
2192 { | |
2193 add_data[3] = _("Resume"); | |
2194 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME; | |
2195 } | |
2196 } | |
2197 | |
2198 if (tdata->transfer_direction == GFTP_DIRECTION_DOWNLOAD) | |
2199 { | |
2200 add_data[2] = insert_commas (tempfle->size, tempstr, | |
2201 sizeof (tempstr)); | |
2202 add_data[1] = insert_commas (tempfle->startsize, temp1str, | |
2203 sizeof (temp1str)); | |
2204 } | |
2205 else | |
2206 { | |
2207 add_data[1] = insert_commas (tempfle->size, tempstr, | |
2208 sizeof (tempstr)); | |
2209 add_data[2] = insert_commas (tempfle->startsize, temp1str, | |
2210 sizeof (temp1str)); | |
2211 } | |
2212 i = gtk_clist_append (GTK_CLIST (tdata->clist), add_data); | |
2213 gtk_clist_set_row_data (GTK_CLIST (tdata->clist), i, tempfle); | |
2214 } | |
2215 | |
2216 gtk_clist_select_all (GTK_CLIST (tdata->clist)); | |
2217 | |
2218 hbox = gtk_hbox_new (TRUE, 20); | |
2219 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, TRUE, TRUE, 0); | |
2220 gtk_widget_show (hbox); | |
2221 | |
2222 tempwid = gtk_button_new_with_label (_("Overwrite")); | |
2223 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
2224 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
2225 GTK_SIGNAL_FUNC (overwrite), (gpointer) tdata); | |
2226 gtk_widget_show (tempwid); | |
2227 | |
2228 tempwid = gtk_button_new_with_label (_("Resume")); | |
2229 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
2230 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
2231 GTK_SIGNAL_FUNC (resume), (gpointer) tdata); | |
2232 gtk_widget_show (tempwid); | |
2233 | |
2234 tempwid = gtk_button_new_with_label (_("Skip File")); | |
2235 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
2236 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", GTK_SIGNAL_FUNC (skip), | |
2237 (gpointer) tdata); | |
2238 gtk_widget_show (tempwid); | |
2239 | |
2240 hbox = gtk_hbox_new (TRUE, 20); | |
2241 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, TRUE, TRUE, 0); | |
2242 gtk_widget_show (hbox); | |
2243 | |
2244 tempwid = gtk_button_new_with_label (_("Select All")); | |
2245 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
2246 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
2247 GTK_SIGNAL_FUNC (trans_selectall), (gpointer) tdata); | |
2248 gtk_widget_show (tempwid); | |
2249 | |
2250 tempwid = gtk_button_new_with_label (_("Deselect All")); | |
2251 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
2252 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
2253 GTK_SIGNAL_FUNC (trans_unselectall), (gpointer) tdata); | |
2254 gtk_widget_show (tempwid); | |
2255 | |
49 | 2256 #if GTK_MAJOR_VERSION == 1 |
1 | 2257 tempwid = gtk_button_new_with_label (_("OK")); |
2258 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); | |
2259 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, | |
2260 TRUE, TRUE, 0); | |
2261 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", GTK_SIGNAL_FUNC (ok), | |
2262 (gpointer) tdata); | |
2263 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked", | |
2264 GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
2265 GTK_OBJECT (dialog)); | |
2266 gtk_widget_grab_default (tempwid); | |
2267 gtk_widget_show (tempwid); | |
2268 | |
2269 tempwid = gtk_button_new_with_label (_(" Cancel ")); | |
2270 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); | |
2271 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, | |
2272 TRUE, TRUE, 0); | |
2273 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
2274 GTK_SIGNAL_FUNC (cancel), (gpointer) tdata); | |
2275 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked", | |
2276 GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
2277 GTK_OBJECT (dialog)); | |
2278 gtk_widget_show (tempwid); | |
49 | 2279 #else |
2280 g_signal_connect (GTK_OBJECT (dialog), "response", | |
2281 G_CALLBACK (transfer_action), (gpointer) tdata); | |
2282 #endif | |
1 | 2283 |
2284 gtk_widget_show (dialog); | |
2285 dialog = NULL; | |
2286 } | |
2287 |