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