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