341
|
1 /*****************************************************************************/
|
|
2 /* gftpui.c - UI related functions for gFTP */
|
|
3 /* Copyright (C) 1998-2003 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., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
|
|
18 /*****************************************************************************/
|
|
19
|
|
20 #include "gftpui.h"
|
|
21 static const char cvsid[] = "$Id$";
|
|
22
|
|
23 sigjmp_buf gftpui_common_jmp_environment;
|
|
24 volatile int gftpui_common_use_jmp_environment = 0;
|
|
25
|
|
26 static void *gftpui_common_local_uidata, *gftpui_common_remote_uidata;
|
367
|
27 static gftp_request * gftpui_common_local_request,
|
|
28 * gftpui_common_remote_request;
|
|
29 GStaticMutex gftpui_common_transfer_mutex = G_STATIC_MUTEX_INIT;
|
341
|
30
|
|
31
|
|
32 static gftp_logging_func
|
|
33 _gftpui_common_log (gftp_request * request)
|
|
34 {
|
|
35 if (request == NULL)
|
|
36 return (gftpui_common_local_request->logging_function);
|
|
37 else
|
|
38 return (request->logging_function);
|
|
39 }
|
|
40
|
|
41
|
|
42 static void *
|
|
43 _gftpui_common_thread_callback (void * data)
|
|
44 {
|
367
|
45 intptr_t network_timeout, sleep_time;
|
341
|
46 gftpui_callback_data * cdata;
|
|
47 int success, sj;
|
|
48
|
|
49 cdata = data;
|
|
50 gftp_lookup_request_option (cdata->request, "network_timeout",
|
|
51 &network_timeout);
|
367
|
52 gftp_lookup_request_option (cdata->request, "sleep_time",
|
|
53 &sleep_time);
|
341
|
54
|
|
55 sj = sigsetjmp (gftpui_common_jmp_environment, 1);
|
|
56 gftpui_common_use_jmp_environment = 1;
|
|
57
|
367
|
58 success = GFTP_ERETRYABLE;
|
341
|
59 if (sj == 0)
|
|
60 {
|
367
|
61 while (1)
|
|
62 {
|
|
63 if (network_timeout > 0)
|
|
64 alarm (network_timeout);
|
|
65 success = cdata->run_function (cdata);
|
|
66 alarm (0);
|
341
|
67
|
367
|
68 if (success == GFTP_EFATAL || success == 0 || cdata->retries == 0)
|
|
69 break;
|
341
|
70
|
367
|
71 cdata->request->logging_function (gftp_logging_misc, cdata->request,
|
|
72 _("Waiting %d seconds until trying to connect again\n"),
|
|
73 sleep_time);
|
|
74 alarm (sleep_time);
|
|
75 pause ();
|
|
76 cdata->retries--;
|
|
77 }
|
341
|
78 }
|
|
79 else
|
|
80 {
|
|
81 gftp_disconnect (cdata->request);
|
|
82 cdata->request->logging_function (gftp_logging_error, cdata->request,
|
|
83 _("Operation canceled\n"));
|
|
84 }
|
|
85
|
|
86 gftpui_common_use_jmp_environment = 0;
|
|
87 cdata->request->stopable = 0;
|
|
88
|
|
89 return (GINT_TO_POINTER (success));
|
|
90 }
|
|
91
|
|
92
|
|
93 int
|
|
94 gftpui_common_run_callback_function (gftpui_callback_data * cdata)
|
|
95 {
|
|
96 int ret;
|
|
97
|
|
98 if (gftpui_check_reconnect (cdata) < 0)
|
|
99 return (0);
|
|
100
|
|
101 if (gftp_protocols[cdata->request->protonum].use_threads)
|
|
102 ret = GPOINTER_TO_INT (gftpui_generic_thread (_gftpui_common_thread_callback, cdata));
|
|
103 else
|
|
104 ret = GPOINTER_TO_INT (cdata->run_function (cdata));
|
|
105
|
367
|
106 if (ret == 0 && cdata->run_function != gftpui_common_run_ls)
|
341
|
107 gftpui_refresh (cdata->uidata);
|
|
108
|
367
|
109 return (ret == 0);
|
341
|
110 }
|
|
111
|
|
112
|
|
113 RETSIGTYPE
|
|
114 gftpui_common_signal_handler (int signo)
|
|
115 {
|
|
116 signal (signo, gftpui_common_signal_handler);
|
|
117
|
|
118 if (gftpui_common_use_jmp_environment)
|
|
119 siglongjmp (gftpui_common_jmp_environment, signo == SIGINT ? 1 : 2);
|
|
120 else if (signo == SIGINT)
|
|
121 exit (1);
|
|
122 }
|
|
123
|
|
124
|
|
125 void
|
|
126 gftpui_common_about (gftp_logging_func logging_function, gpointer logdata)
|
|
127 {
|
|
128 char *str;
|
|
129
|
|
130 logging_function (gftp_logging_misc, logdata, "%s, Copyright (C) 1998-2003 Brian Masney <", gftp_version);
|
|
131 logging_function (gftp_logging_recv, logdata, "masneyb@gftp.org");
|
|
132 logging_function (gftp_logging_misc, logdata, _(">. If you have any questions, comments, or suggestions about this program, please feel free to email them to me. You can always find out the latest news about gFTP from my website at http://www.gftp.org/\n"));
|
|
133 logging_function (gftp_logging_misc, logdata, _("gFTP comes with ABSOLUTELY NO WARRANTY; for details, see the COPYING file. This is free software, and you are welcome to redistribute it under certain conditions; for details, see the COPYING file\n"));
|
|
134
|
|
135 str = _("Translated by");
|
|
136 if (strcmp (str, "Translated by") != 0)
|
|
137 logging_function (gftp_logging_misc, logdata, "%s\n", str);
|
|
138 }
|
|
139
|
|
140
|
|
141 static int
|
|
142 gftpui_common_cmd_about (void *uidata, gftp_request * request, char *command)
|
|
143 {
|
|
144 gftpui_common_about (_gftpui_common_log (request),
|
|
145 gftpui_common_local_request);
|
|
146 return (1);
|
|
147 }
|
|
148
|
|
149
|
|
150 static int
|
|
151 gftpui_common_cmd_ascii (void *uidata, gftp_request * request, char *command)
|
|
152 {
|
350
|
153 gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(1));
|
341
|
154 return (1);
|
|
155 }
|
|
156
|
|
157
|
|
158 static int
|
|
159 gftpui_common_cmd_binary (void *uidata, gftp_request * request, char *command)
|
|
160 {
|
350
|
161 gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(0));
|
341
|
162 return (1);
|
|
163 }
|
|
164
|
|
165
|
|
166 static int
|
|
167 gftpui_common_cmd_chmod (void *uidata, gftp_request * request, char *command)
|
|
168 {
|
350
|
169 gftpui_callback_data * cdata;
|
341
|
170 char *pos;
|
|
171
|
|
172 if (!GFTP_IS_CONNECTED (request))
|
|
173 {
|
|
174 request->logging_function (gftp_logging_error, request,
|
|
175 _("Error: Not connected to a remote site\n"));
|
|
176
|
|
177 return (1);
|
|
178 }
|
|
179
|
|
180 if ((pos = strchr (command, ' ')) != NULL)
|
|
181 *pos++ = '\0';
|
|
182
|
|
183 if (*command == '\0' || pos == NULL || *pos == '\0')
|
|
184 {
|
|
185 request->logging_function (gftp_logging_error, request,
|
|
186 _("usage: chmod <mode> <file>\n"));
|
|
187 }
|
|
188 else
|
|
189 {
|
350
|
190 cdata = g_malloc0 (sizeof (*cdata));
|
|
191 cdata->request = request;
|
|
192 cdata->uidata = uidata;
|
|
193 cdata->input_string = command;
|
|
194 cdata->source_string = pos;
|
|
195 cdata->run_function = gftpui_common_run_chmod;
|
|
196
|
|
197 gftpui_common_run_callback_function (cdata);
|
|
198
|
|
199 g_free (cdata);
|
341
|
200 }
|
|
201
|
|
202 return (1);
|
|
203 }
|
|
204
|
|
205
|
|
206 static int
|
|
207 gftpui_common_cmd_rename (void *uidata, gftp_request * request, char *command)
|
|
208 {
|
350
|
209 gftpui_callback_data * cdata;
|
341
|
210 char *pos;
|
|
211
|
|
212 if (!GFTP_IS_CONNECTED (request))
|
|
213 {
|
|
214 request->logging_function (gftp_logging_error, request,
|
|
215 _("Error: Not connected to a remote site\n"));
|
|
216 return (1);
|
|
217 }
|
|
218
|
|
219 if ((pos = strchr (command, ' ')) != NULL)
|
|
220 *pos++ = '\0';
|
|
221
|
|
222 if (*command == '\0' || pos == NULL || *pos == '\0')
|
|
223 {
|
|
224 request->logging_function (gftp_logging_error, request,
|
|
225 _("usage: rename <old name> <new name>\n"));
|
|
226 }
|
|
227 else
|
|
228 {
|
350
|
229 cdata = g_malloc0 (sizeof (*cdata));
|
|
230 cdata->request = request;
|
|
231 cdata->uidata = uidata;
|
|
232 cdata->source_string = command;
|
|
233 cdata->input_string = pos;
|
|
234 cdata->run_function = gftpui_common_run_rename;
|
|
235
|
|
236 gftpui_common_run_callback_function (cdata);
|
|
237
|
|
238 g_free (cdata);
|
341
|
239 }
|
|
240
|
|
241 return (1);
|
|
242 }
|
|
243
|
|
244
|
|
245 static int
|
|
246 gftpui_common_cmd_delete (void *uidata, gftp_request * request, char *command)
|
|
247 {
|
350
|
248 gftpui_callback_data * cdata;
|
|
249
|
341
|
250 if (!GFTP_IS_CONNECTED (request))
|
|
251 {
|
|
252 request->logging_function (gftp_logging_error, request,
|
|
253 _("Error: Not connected to a remote site\n"));
|
|
254 return (1);
|
|
255 }
|
|
256 else if (*command == '\0')
|
|
257 {
|
|
258 request->logging_function (gftp_logging_error, request,
|
|
259 _("usage: delete <file>\n"));
|
|
260 }
|
|
261 else
|
|
262 {
|
350
|
263 cdata = g_malloc0 (sizeof (*cdata));
|
|
264 cdata->request = request;
|
|
265 cdata->uidata = uidata;
|
|
266 cdata->input_string = command;
|
|
267 cdata->run_function = gftpui_common_run_delete;
|
|
268
|
|
269 gftpui_common_run_callback_function (cdata);
|
|
270
|
|
271 g_free (cdata);
|
341
|
272 }
|
|
273
|
|
274 return (1);
|
|
275 }
|
|
276
|
|
277
|
|
278 static int
|
|
279 gftpui_common_cmd_rmdir (void *uidata, gftp_request * request, char *command)
|
|
280 {
|
350
|
281 gftpui_callback_data * cdata;
|
|
282
|
341
|
283 if (!GFTP_IS_CONNECTED (request))
|
|
284 {
|
|
285 request->logging_function (gftp_logging_error, request,
|
|
286 _("Error: Not connected to a remote site\n"));
|
|
287 return (1);
|
|
288 }
|
|
289 else if (*command == '\0')
|
|
290 {
|
|
291 request->logging_function (gftp_logging_error, request,
|
|
292 _("usage: rmdir <directory>\n"));
|
|
293 }
|
|
294 else
|
|
295 {
|
350
|
296 cdata = g_malloc0 (sizeof (*cdata));
|
|
297 cdata->request = request;
|
|
298 cdata->uidata = uidata;
|
|
299 cdata->input_string = command;
|
|
300 cdata->run_function = gftpui_common_run_rmdir;
|
|
301
|
|
302 gftpui_common_run_callback_function (cdata);
|
|
303
|
|
304 g_free (cdata);
|
|
305 }
|
|
306
|
|
307 return (1);
|
|
308 }
|
|
309
|
|
310
|
|
311 static int
|
|
312 gftpui_common_cmd_site (void *uidata, gftp_request * request, char *command)
|
|
313 {
|
|
314 gftpui_callback_data * cdata;
|
|
315
|
|
316 if (!GFTP_IS_CONNECTED (request))
|
|
317 {
|
|
318 request->logging_function (gftp_logging_error, request,
|
|
319 _("Error: Not connected to a remote site\n"));
|
|
320 return (1);
|
|
321 }
|
|
322 else if (*command == '\0')
|
|
323 {
|
|
324 request->logging_function (gftp_logging_error, request,
|
|
325 _("usage: site <site command>\n"));
|
|
326 }
|
|
327 else
|
|
328 {
|
|
329 cdata = g_malloc0 (sizeof (*cdata));
|
|
330 cdata->request = request;
|
|
331 cdata->uidata = uidata;
|
|
332 cdata->input_string = command;
|
|
333 cdata->run_function = gftpui_common_run_site;
|
|
334
|
|
335 gftpui_common_run_callback_function (cdata);
|
|
336
|
|
337 g_free (cdata);
|
341
|
338 }
|
|
339
|
|
340 return (1);
|
|
341 }
|
|
342
|
|
343
|
|
344 static int
|
|
345 gftpui_common_cmd_mkdir (void *uidata, gftp_request * request, char *command)
|
|
346 {
|
|
347 gftpui_callback_data * cdata;
|
|
348
|
|
349 if (!GFTP_IS_CONNECTED (request))
|
|
350 {
|
|
351 request->logging_function (gftp_logging_error, request,
|
|
352 _("Error: Not connected to a remote site\n"));
|
|
353 return (1);
|
|
354 }
|
|
355 else if (*command == '\0')
|
|
356 {
|
|
357 request->logging_function (gftp_logging_error, request,
|
|
358 _("usage: mkdir <new directory>\n"));
|
|
359 }
|
|
360 else
|
|
361 {
|
|
362 cdata = g_malloc0 (sizeof (*cdata));
|
|
363 cdata->request = request;
|
|
364 cdata->uidata = uidata;
|
|
365 cdata->input_string = command;
|
|
366 cdata->run_function = gftpui_common_run_mkdir;
|
|
367
|
|
368 gftpui_common_run_callback_function (cdata);
|
|
369
|
|
370 g_free (cdata);
|
|
371 }
|
|
372
|
|
373 return (1);
|
|
374 }
|
|
375
|
|
376
|
|
377 static int
|
|
378 gftpui_common_cmd_chdir (void *uidata, gftp_request * request, char *command)
|
|
379 {
|
350
|
380 gftpui_callback_data * cdata;
|
341
|
381 char *tempstr, *newdir = NULL;
|
|
382
|
|
383 if (!GFTP_IS_CONNECTED (request))
|
|
384 {
|
|
385 request->logging_function (gftp_logging_error, request,
|
|
386 _("Error: Not connected to a remote site\n"));
|
|
387 return (1);
|
|
388 }
|
|
389 else if (*command == '\0')
|
|
390 {
|
|
391 request->logging_function (gftp_logging_error, request,
|
|
392 _("usage: chdir <directory>\n"));
|
|
393 return (1);
|
|
394 }
|
|
395 else if (request->protonum == GFTP_LOCAL_NUM)
|
|
396 {
|
|
397 if (*command != '/' && request->directory != NULL)
|
|
398 {
|
350
|
399 tempstr = gftp_build_path (request->directory, command, NULL);
|
341
|
400 newdir = expand_path (tempstr);
|
|
401 g_free (tempstr);
|
|
402 }
|
|
403 else
|
|
404 newdir = expand_path (command);
|
|
405
|
|
406 if (newdir == NULL)
|
|
407 {
|
|
408 request->logging_function (gftp_logging_error, request,
|
|
409 _("usage: chdir <directory>\n"));
|
|
410 return (1);
|
|
411 }
|
|
412 }
|
|
413
|
350
|
414 cdata = g_malloc0 (sizeof (*cdata));
|
|
415 cdata->request = request;
|
|
416 cdata->uidata = uidata;
|
|
417 cdata->input_string = newdir != NULL ? newdir : command;
|
|
418 cdata->run_function = gftpui_common_run_chdir;
|
|
419
|
|
420 gftpui_common_run_callback_function (cdata);
|
|
421
|
|
422 g_free (cdata);
|
341
|
423
|
|
424 if (newdir != NULL)
|
|
425 g_free (newdir);
|
|
426
|
|
427 return (1);
|
|
428 }
|
|
429
|
|
430
|
|
431 static int
|
|
432 gftpui_common_cmd_close (void *uidata, gftp_request * request, char *command)
|
|
433 {
|
|
434 gftp_disconnect (request);
|
|
435 return (1);
|
|
436 }
|
|
437
|
|
438
|
|
439 static int
|
|
440 gftpui_common_cmd_pwd (void *uidata, gftp_request * request, char *command)
|
|
441 {
|
|
442 if (!GFTP_IS_CONNECTED (request))
|
|
443 {
|
|
444 request->logging_function (gftp_logging_error, request,
|
|
445 _("Error: Not connected to a remote site\n"));
|
|
446 return (1);
|
|
447 }
|
|
448
|
|
449 request->logging_function (gftp_logging_misc, request,
|
|
450 "%s\n", request->directory);
|
|
451
|
|
452 return (1);
|
|
453 }
|
|
454
|
|
455
|
|
456 static int
|
|
457 gftpui_common_cmd_quit (void *uidata, gftp_request * request, char *command)
|
|
458 {
|
|
459 gftp_shutdown();
|
|
460
|
|
461 return (0);
|
|
462 }
|
|
463
|
|
464
|
|
465 static int
|
|
466 gftpui_common_cmd_clear (void *uidata, gftp_request * request, char *command)
|
|
467 {
|
|
468 gftp_logging_func logfunc;
|
|
469
|
|
470 if (strcasecmp (command, "cache") == 0)
|
|
471 gftp_clear_cache_files ();
|
|
472 else
|
|
473 {
|
|
474 logfunc = _gftpui_common_log (request);
|
|
475 logfunc (gftp_logging_error, request, _("Invalid argument\n"));
|
|
476 }
|
|
477
|
|
478 return (1);
|
|
479 }
|
|
480
|
|
481
|
|
482 static int
|
|
483 gftpui_common_clear_show_subhelp (char *topic)
|
|
484 {
|
|
485 gftp_logging_func logfunc;
|
|
486
|
|
487 logfunc = gftpui_common_local_request->logging_function;
|
|
488 if (strcmp (topic, "cache") == 0)
|
|
489 {
|
|
490 logfunc (gftp_logging_misc, NULL, _("Clear the directory cache\n"));
|
|
491 return (1);
|
|
492 }
|
|
493
|
|
494 return (0);
|
|
495 }
|
|
496
|
|
497
|
|
498 static int
|
|
499 gftpui_common_set_show_subhelp (char *topic)
|
|
500 {
|
|
501 gftp_logging_func logfunc;
|
|
502 gftp_config_vars * cv;
|
|
503
|
|
504 logfunc = gftpui_common_local_request->logging_function;
|
|
505 if ((cv = g_hash_table_lookup (gftp_global_options_htable, topic)) != NULL)
|
|
506 {
|
|
507 logfunc (gftp_logging_misc, NULL, "%s\n", cv->comment);
|
|
508 return (1);
|
|
509 }
|
|
510
|
|
511 return (0);
|
|
512 }
|
|
513
|
|
514
|
355
|
515 static int
|
341
|
516 gftpui_common_cmd_ls (void *uidata, gftp_request * request, char *command)
|
|
517 {
|
355
|
518 char *startcolor, *endcolor, *tempstr;
|
|
519 gftpui_callback_data * cdata;
|
|
520 GList * templist;
|
341
|
521 gftp_file * fle;
|
|
522
|
|
523 if (!GFTP_IS_CONNECTED (request))
|
|
524 {
|
|
525 request->logging_function (gftp_logging_error, request,
|
|
526 _("Error: Not connected to a remote site\n"));
|
|
527 return (1);
|
|
528 }
|
|
529
|
355
|
530 cdata = g_malloc0 (sizeof (*cdata));
|
|
531 cdata->request = request;
|
|
532 cdata->uidata = uidata;
|
|
533 cdata->source_string = *command != '\0' ? command : NULL;
|
|
534 cdata->run_function = gftpui_common_run_ls;
|
341
|
535
|
355
|
536 gftpui_common_run_callback_function (cdata);
|
341
|
537
|
355
|
538 templist = cdata->files;
|
|
539 while (templist != NULL)
|
341
|
540 {
|
|
541 fle = templist->data;
|
|
542
|
|
543 gftpui_lookup_file_colors (fle, &startcolor, &endcolor);
|
|
544 tempstr = gftp_gen_ls_string (fle, startcolor, endcolor);
|
354
|
545 request->logging_function (gftp_logging_misc_nolog, request, "%s\n",
|
|
546 tempstr);
|
341
|
547 g_free (tempstr);
|
|
548
|
355
|
549 templist = templist->next;
|
|
550 gftp_file_destroy (fle);
|
|
551 g_free (fle);
|
341
|
552 }
|
|
553
|
|
554
|
355
|
555 if (cdata->files != NULL)
|
|
556 g_list_free (cdata->files);
|
|
557 g_free (cdata);
|
341
|
558
|
|
559 return (1);
|
|
560 }
|
|
561
|
|
562
|
367
|
563 int
|
356
|
564 gftpui_common_cmd_open (void *uidata, gftp_request * request, char *command)
|
|
565 {
|
367
|
566 gftpui_callback_data * cdata;
|
|
567 intptr_t retries;
|
356
|
568 char *tempstr;
|
|
569
|
|
570 if (GFTP_IS_CONNECTED (request))
|
|
571 {
|
|
572 gftp_disconnect (request); /* FIXME */
|
|
573 }
|
|
574
|
367
|
575 if (command != NULL)
|
356
|
576 {
|
367
|
577 if (*command == '\0')
|
|
578 {
|
|
579 request->logging_function (gftp_logging_error, request,
|
|
580 _("usage: open " GFTP_URL_USAGE "\n"));
|
|
581 return (1);
|
|
582 }
|
|
583
|
|
584 if (gftp_parse_url (request, command) < 0)
|
|
585 return (1);
|
356
|
586 }
|
|
587
|
|
588 if (request->need_userpass)
|
|
589 {
|
|
590 if (request->username == NULL || *request->username == '\0')
|
|
591 {
|
|
592 if ((tempstr = gftpui_prompt_username (uidata, request)) != NULL)
|
|
593 {
|
|
594 gftp_set_username (request, tempstr);
|
|
595 gftp_set_password (request, NULL);
|
|
596 g_free (tempstr);
|
|
597 }
|
|
598 }
|
|
599
|
|
600 if (request->username != NULL &&
|
|
601 strcmp (request->username, "anonymous") != 0 &&
|
|
602 (request->password == NULL || *request->password == '\0'))
|
|
603 {
|
|
604 if ((tempstr = gftpui_prompt_password (uidata, request)) != NULL)
|
|
605 {
|
|
606 gftp_set_password (request, tempstr);
|
|
607 g_free (tempstr);
|
|
608 }
|
|
609 }
|
|
610 }
|
|
611
|
367
|
612 gftp_lookup_request_option (request, "retries", &retries);
|
|
613
|
|
614 cdata = g_malloc0 (sizeof (*cdata));
|
|
615 cdata->request = request;
|
|
616 cdata->uidata = uidata;
|
|
617 cdata->run_function = gftpui_common_run_connect;
|
|
618 cdata->retries = retries;
|
|
619
|
|
620 gftpui_common_run_callback_function (cdata);
|
|
621
|
|
622 g_free (cdata);
|
356
|
623
|
|
624 return (1);
|
|
625 }
|
|
626
|
|
627
|
|
628 static int
|
341
|
629 gftpui_common_cmd_set (void *uidata, gftp_request * request, char *command)
|
|
630 {
|
|
631 gftp_config_vars * cv, newcv;
|
|
632 gftp_logging_func logfunc;
|
|
633 char *pos, *backpos;
|
|
634 GList * templist;
|
|
635 int i;
|
|
636
|
|
637 logfunc = _gftpui_common_log (request);
|
|
638
|
|
639 if (command == NULL || *command == '\0')
|
|
640 {
|
|
641 for (templist = gftp_options_list;
|
|
642 templist != NULL;
|
|
643 templist = templist->next)
|
|
644 {
|
|
645 cv = templist->data;
|
|
646
|
|
647 for (i=0; cv[i].key != NULL; i++)
|
|
648 {
|
|
649 if (!(cv[i].ports_shown & GFTP_PORT_TEXT))
|
|
650 continue;
|
|
651
|
|
652 if (*cv[i].key == '\0' ||
|
|
653 gftp_option_types[cv[i].otype].write_function == NULL)
|
|
654 continue;
|
|
655
|
|
656 printf ("%s = ", cv[i].key);
|
|
657 gftp_option_types[cv[i].otype].write_function (&cv[i], stdout, 0);
|
|
658 printf ("\n");
|
|
659 }
|
|
660 }
|
|
661 }
|
|
662 else
|
|
663 {
|
|
664 if ((pos = strchr (command, '=')) == NULL)
|
|
665 {
|
|
666 logfunc (gftp_logging_error, request,
|
|
667 _("usage: set [variable = value]\n"));
|
|
668 return (1);
|
|
669 }
|
|
670 *pos = '\0';
|
|
671
|
|
672 for (backpos = pos - 1;
|
|
673 (*backpos == ' ' || *backpos == '\t') && backpos > command;
|
|
674 backpos--)
|
|
675 *backpos = '\0';
|
|
676 for (++pos; *pos == ' ' || *pos == '\t'; pos++);
|
|
677
|
|
678 if ((cv = g_hash_table_lookup (gftp_global_options_htable, command)) == NULL)
|
|
679 {
|
|
680 logfunc (gftp_logging_error, request,
|
|
681 _("Error: Variable %s is not a valid configuration variable.\n"), command);
|
|
682 return (1);
|
|
683 }
|
|
684
|
|
685 if (!(cv->ports_shown & GFTP_PORT_TEXT))
|
|
686 {
|
|
687 logfunc (gftp_logging_error, request,
|
|
688 _("Error: Variable %s is not available in the text port of gFTP\n"), command);
|
|
689 return (1);
|
|
690 }
|
|
691
|
|
692 if (gftp_option_types[cv->otype].read_function != NULL)
|
|
693 {
|
|
694 memcpy (&newcv, cv, sizeof (newcv));
|
|
695 newcv.flags &= ~GFTP_CVARS_FLAGS_DYNMEM;
|
|
696
|
|
697 gftp_option_types[cv->otype].read_function (pos, &newcv, 1);
|
|
698
|
|
699 gftp_set_global_option (command, newcv.value);
|
|
700
|
|
701 if (newcv.flags & GFTP_CVARS_FLAGS_DYNMEM)
|
|
702 g_free (newcv.value);
|
|
703 }
|
|
704 }
|
|
705
|
|
706 return (1);
|
|
707 }
|
|
708
|
|
709
|
|
710 static int
|
|
711 gftpui_common_cmd_help (void *uidata, gftp_request * request, char *command)
|
|
712 {
|
|
713 int i, j, ele, numrows, numcols = 6, handled, number_commands;
|
|
714 char *pos;
|
|
715
|
|
716 for (number_commands=0;
|
|
717 gftpui_common_commands[number_commands].command != NULL;
|
|
718 number_commands++);
|
|
719
|
|
720 if (command != NULL && *command != '\0')
|
|
721 {
|
|
722 for (pos = command; *pos != ' ' && *pos != '\0'; pos++);
|
|
723 if (*pos == ' ')
|
|
724 {
|
|
725 *pos++ = '\0';
|
|
726 if (*pos == '\0')
|
|
727 pos = NULL;
|
|
728 }
|
|
729 else
|
|
730 pos = NULL;
|
|
731
|
|
732 for (i=0; gftpui_common_commands[i].command != NULL; i++)
|
|
733 {
|
|
734 if (strcmp (gftpui_common_commands[i].command, command) == 0)
|
|
735 break;
|
|
736 }
|
|
737
|
|
738 if (gftpui_common_commands[i].cmd_description != NULL)
|
|
739 {
|
|
740 if (pos != NULL && gftpui_common_commands[i].subhelp_func != NULL)
|
|
741 handled = gftpui_common_commands[i].subhelp_func (pos);
|
|
742 else
|
|
743 handled = 0;
|
|
744
|
|
745 if (!handled)
|
|
746 printf ("%s\n", _(gftpui_common_commands[i].cmd_description));
|
|
747 }
|
|
748 else
|
|
749 *command = '\0';
|
|
750 }
|
|
751
|
|
752 if (command == NULL || *command == '\0')
|
|
753 {
|
|
754 numrows = number_commands / numcols;
|
|
755 if (number_commands % numcols != 0)
|
|
756 numrows++;
|
|
757
|
|
758 printf (_("Supported commands:\n\n"));
|
|
759 for (i=0; i<numrows; i++)
|
|
760 {
|
|
761 printf (" ");
|
|
762 for (j=0; j<numcols; j++)
|
|
763 {
|
|
764 ele = i + j * numrows;
|
|
765 if (ele >= number_commands)
|
|
766 break;
|
|
767 printf ("%-10s", gftpui_common_commands[ele].command);
|
|
768 }
|
|
769 printf ("\n");
|
|
770 }
|
|
771
|
|
772 printf ("\n");
|
|
773 }
|
|
774 return (1);
|
|
775 }
|
|
776
|
|
777
|
|
778 gftpui_common_methods gftpui_common_commands[] = {
|
|
779 {N_("about"), 2, gftpui_common_cmd_about, gftpui_common_request_none,
|
|
780 N_("Shows gFTP information"), NULL},
|
|
781 {N_("ascii"), 2, gftpui_common_cmd_ascii, gftpui_common_request_remote,
|
|
782 N_("Sets the current file transfer mode to Ascii (only for FTP)"), NULL},
|
|
783 {N_("binary"), 1, gftpui_common_cmd_binary, gftpui_common_request_remote,
|
|
784 N_("Sets the current file transfer mode to Binary (only for FTP)"), NULL},
|
|
785 {N_("cd"), 2, gftpui_common_cmd_chdir, gftpui_common_request_remote,
|
|
786 N_("Changes the remote working directory"), NULL},
|
|
787 {N_("chdir"), 3, gftpui_common_cmd_chdir, gftpui_common_request_remote,
|
|
788 N_("Changes the remote working directory"), NULL},
|
|
789 {N_("chmod"), 3, gftpui_common_cmd_chmod, gftpui_common_request_remote,
|
|
790 N_("Changes the permissions of a remote file"), NULL},
|
|
791 {N_("clear"), 3, gftpui_common_cmd_clear, gftpui_common_request_none,
|
|
792 N_("Available options: cache"), gftpui_common_clear_show_subhelp},
|
|
793 {N_("close"), 3, gftpui_common_cmd_close, gftpui_common_request_remote,
|
|
794 N_("Disconnects from the remote site"), NULL},
|
350
|
795 {N_("delete"), 1, gftpui_common_cmd_delete, gftpui_common_request_remote,
|
341
|
796 N_("Removes a remote file"), NULL},
|
|
797 /* FIXME
|
|
798 {N_("get"), 1, gftp_text_mget_file, gftpui_common_request_none,
|
|
799 N_("Downloads remote file(s)"), NULL},
|
|
800 */
|
|
801 {N_("help"), 1, gftpui_common_cmd_help, gftpui_common_request_none,
|
|
802 N_("Shows this help screen"), NULL},
|
|
803 {N_("lcd"), 3, gftpui_common_cmd_chdir, gftpui_common_request_local,
|
|
804 N_("Changes the local working directory"), NULL},
|
|
805 {N_("lchdir"), 4, gftpui_common_cmd_chdir, gftpui_common_request_local,
|
|
806 N_("Changes the local working directory"), NULL},
|
|
807 {N_("lchmod"), 4, gftpui_common_cmd_chmod, gftpui_common_request_local,
|
|
808 N_("Changes the permissions of a local file"), NULL},
|
|
809 {N_("ldelete"), 2, gftpui_common_cmd_delete, gftpui_common_request_local,
|
|
810 N_("Removes a local file"), NULL},
|
|
811 {N_("lls"), 2, gftpui_common_cmd_ls, gftpui_common_request_local,
|
|
812 N_("Shows the directory listing for the current local directory"), NULL},
|
|
813 {N_("lmkdir"), 2, gftpui_common_cmd_mkdir, gftpui_common_request_local,
|
|
814 N_("Creates a local directory"), NULL},
|
|
815 {N_("lpwd"), 2, gftpui_common_cmd_pwd, gftpui_common_request_local,
|
|
816 N_("Show current local directory"), NULL},
|
|
817 {N_("lrename"), 3, gftpui_common_cmd_rename, gftpui_common_request_local,
|
|
818 N_("Rename a local file"), NULL},
|
|
819 {N_("lrmdir"), 3, gftpui_common_cmd_rmdir, gftpui_common_request_local,
|
|
820 N_("Remove a local directory"), NULL},
|
|
821 {N_("ls"), 2, gftpui_common_cmd_ls, gftpui_common_request_remote,
|
|
822 N_("Shows the directory listing for the current remote directory"), NULL},
|
|
823 /* FIXME
|
|
824 {N_("mget"), 2, gftp_text_mget_file, gftpui_common_request_none,
|
|
825 N_("Downloads remote file(s)"), NULL},
|
|
826 */
|
|
827 {N_("mkdir"), 2, gftpui_common_cmd_mkdir, gftpui_common_request_remote,
|
|
828 N_("Creates a remote directory"), NULL},
|
|
829 /* FIXME
|
|
830 {N_("mput"), 2, gftp_text_mput_file, gftpui_common_request_none,
|
|
831 N_("Uploads local file(s)"), NULL},
|
356
|
832 */
|
|
833 {N_("open"), 1, gftpui_common_cmd_open, gftpui_common_request_remote,
|
341
|
834 N_("Opens a connection to a remote site"), NULL},
|
356
|
835 /* FIXME
|
341
|
836 {N_("put"), 2, gftp_text_mput_file, gftpui_common_request_none,
|
|
837 N_("Uploads local file(s)"), NULL},
|
|
838 */
|
|
839 {N_("pwd"), 2, gftpui_common_cmd_pwd, gftpui_common_request_remote,
|
|
840 N_("Show current remote directory"), NULL},
|
|
841 {N_("quit"), 1, gftpui_common_cmd_quit, gftpui_common_request_none,
|
|
842 N_("Exit from gFTP"), NULL},
|
|
843 {N_("rename"), 2, gftpui_common_cmd_rename, gftpui_common_request_remote,
|
|
844 N_("Rename a remote file"), NULL},
|
|
845 {N_("rmdir"), 2, gftpui_common_cmd_rmdir, gftpui_common_request_remote,
|
|
846 N_("Remove a remote directory"), NULL},
|
|
847 {N_("set"), 1, gftpui_common_cmd_set, gftpui_common_request_none,
|
|
848 N_("Show configuration file variables. You can also set variables by set var=val"), gftpui_common_set_show_subhelp},
|
350
|
849 {N_("site"), 2, gftpui_common_cmd_site, gftpui_common_request_remote,
|
|
850 N_("Run a site specific command"), NULL},
|
341
|
851 {NULL, 0, NULL, gftpui_common_request_none,
|
|
852 NULL, NULL}};
|
|
853
|
|
854
|
|
855 int
|
|
856 gftpui_common_init (void *locui, gftp_request * locreq,
|
|
857 void *remui, gftp_request * remreq)
|
|
858 {
|
|
859 gftpui_common_local_uidata = locui;
|
|
860 gftpui_common_local_request = locreq;
|
|
861
|
|
862 gftpui_common_remote_uidata = remui;
|
|
863 gftpui_common_remote_request = remreq;
|
|
864
|
|
865 return (0);
|
|
866 }
|
|
867
|
|
868
|
|
869 int
|
|
870 gftpui_common_process_command (const char *command)
|
|
871 {
|
|
872 const char *stpos;
|
|
873 char *pos, *newstr;
|
|
874 gftp_request * request;
|
|
875 size_t cmdlen;
|
|
876 void *uidata;
|
|
877 int ret, i;
|
|
878 size_t len;
|
|
879
|
|
880 for (stpos = command; *stpos == ' ' || *stpos == '\t'; stpos++);
|
|
881
|
|
882 newstr = g_strdup (stpos);
|
|
883 len = strlen (newstr);
|
|
884
|
|
885 if (len > 0 && newstr[len - 1] == '\n')
|
|
886 newstr[--len] = '\0';
|
|
887 if (len > 0 && newstr[len - 1] == '\r')
|
|
888 newstr[--len] = '\0';
|
|
889
|
|
890 for (pos = newstr + len - 1;
|
|
891 (*pos == ' ' || *pos == '\t') && pos > newstr;
|
|
892 pos--)
|
|
893 *pos = '\0';
|
|
894
|
|
895 if (*stpos == '\0')
|
|
896 {
|
|
897 g_free (newstr);
|
|
898 return (1);
|
|
899 }
|
|
900
|
|
901 if ((pos = strchr (newstr, ' ')) != NULL)
|
|
902 *pos = '\0';
|
|
903
|
|
904 cmdlen = strlen (newstr);
|
|
905 for (i=0; gftpui_common_commands[i].command != NULL; i++)
|
|
906 {
|
|
907 if (strcmp (gftpui_common_commands[i].command, newstr) == 0)
|
|
908 break;
|
|
909 else if (cmdlen >= gftpui_common_commands[i].minlen &&
|
|
910 strncmp (gftpui_common_commands[i].command, newstr, cmdlen) == 0)
|
|
911 break;
|
|
912 }
|
|
913
|
|
914 if (pos != NULL)
|
|
915 pos++;
|
|
916 else
|
|
917 pos = "";
|
|
918
|
|
919 if (gftpui_common_commands[i].command != NULL)
|
|
920 {
|
|
921 if (gftpui_common_commands[i].reqtype == gftpui_common_request_local)
|
|
922 {
|
|
923 request = gftpui_common_local_request;
|
|
924 uidata = gftpui_common_local_uidata;
|
|
925 }
|
|
926 else if (gftpui_common_commands[i].reqtype == gftpui_common_request_remote)
|
|
927 {
|
|
928 request = gftpui_common_remote_request;
|
|
929 uidata = gftpui_common_remote_uidata;
|
|
930 }
|
|
931 else
|
|
932 {
|
|
933 request = NULL;
|
|
934 uidata = NULL;
|
|
935 }
|
|
936
|
|
937 ret = gftpui_common_commands[i].func (uidata, request, pos);
|
|
938 }
|
|
939 else
|
|
940 {
|
|
941 gftpui_common_local_request->logging_function (gftp_logging_error,
|
|
942 gftpui_common_local_request,
|
|
943 _("Error: Command not recognized\n"));
|
|
944 ret = 1;
|
|
945 }
|
|
946
|
|
947 g_free (newstr);
|
|
948 return (ret);
|
|
949 }
|
|
950
|
367
|
951
|
|
952 gftp_transfer *
|
|
953 gftpui_common_add_file_transfer (gftp_request * fromreq, gftp_request * toreq,
|
|
954 void *fromuidata, void *touidata,
|
|
955 GList * files)
|
|
956 {
|
|
957 intptr_t append_transfers, one_transfer;
|
|
958 GList * templist, *curfle;
|
|
959 gftp_transfer * tdata;
|
|
960 gftp_file * tempfle;
|
|
961 int show_dialog;
|
|
962 char *pos;
|
|
963
|
|
964 for (templist = files; templist != NULL; templist = templist->next)
|
|
965 {
|
|
966 tempfle = templist->data;
|
|
967 if (tempfle->startsize > 0)
|
|
968 break;
|
|
969 }
|
|
970 show_dialog = templist != NULL;
|
|
971
|
|
972 gftp_lookup_request_option (fromreq, "append_transfers",
|
|
973 &append_transfers);
|
|
974 gftp_lookup_request_option (fromreq, "one_transfer",
|
|
975 &one_transfer);
|
|
976
|
|
977 tdata = NULL;
|
|
978 if (append_transfers && one_transfer && !show_dialog)
|
|
979 {
|
|
980 if (g_thread_supported ())
|
|
981 g_static_mutex_lock (&gftpui_common_transfer_mutex);
|
|
982
|
|
983 for (templist = gftp_file_transfers;
|
|
984 templist != NULL;
|
|
985 templist = templist->next)
|
|
986 {
|
|
987 tdata = templist->data;
|
|
988
|
|
989 if (g_thread_supported ())
|
|
990 g_static_mutex_lock (&tdata->structmutex);
|
|
991
|
|
992 if (!compare_request (tdata->fromreq, fromreq, 0) ||
|
|
993 !compare_request (tdata->toreq, toreq, 0) ||
|
|
994 tdata->curfle == NULL)
|
|
995 {
|
|
996 if (g_thread_supported ())
|
|
997 g_static_mutex_unlock (&tdata->structmutex);
|
|
998
|
|
999 continue;
|
|
1000 }
|
|
1001
|
|
1002 tdata->files = g_list_concat (tdata->files, files);
|
|
1003
|
|
1004 for (curfle = files; curfle != NULL; curfle = curfle->next)
|
|
1005 {
|
|
1006 tempfle = curfle->data;
|
|
1007
|
|
1008 if (tempfle->isdir)
|
|
1009 tdata->numdirs++;
|
|
1010 else
|
|
1011 tdata->numfiles++;
|
|
1012
|
|
1013 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP)
|
|
1014 tdata->total_bytes += tempfle->size;
|
|
1015
|
|
1016 if ((pos = strrchr (tempfle->file, '/')) == NULL)
|
|
1017 pos = tempfle->file;
|
|
1018 else
|
|
1019 pos++;
|
|
1020
|
|
1021 gftpui_add_file_to_transfer (tdata, curfle, pos);
|
|
1022 }
|
|
1023
|
|
1024 if (g_thread_supported ())
|
|
1025 g_static_mutex_unlock (&tdata->structmutex);
|
|
1026
|
|
1027 break;
|
|
1028 }
|
|
1029
|
|
1030 if (g_thread_supported ())
|
|
1031 g_static_mutex_unlock (&gftpui_common_transfer_mutex);
|
|
1032 }
|
|
1033 else
|
|
1034 templist = NULL;
|
|
1035
|
|
1036 if (templist == NULL)
|
|
1037 {
|
|
1038 tdata = gftp_tdata_new ();
|
|
1039 tdata->fromreq = copy_request (fromreq, 0);
|
|
1040 tdata->toreq = copy_request (toreq, 0);
|
|
1041
|
|
1042 tdata->fromwdata = fromuidata;
|
|
1043 tdata->towdata = touidata;
|
|
1044
|
|
1045 if (!show_dialog)
|
|
1046 tdata->show = tdata->ready = 1;
|
|
1047
|
|
1048 tdata->files = files;
|
|
1049 for (curfle = files; curfle != NULL; curfle = curfle->next)
|
|
1050 {
|
|
1051 tempfle = curfle->data;
|
|
1052 if (tempfle->isdir)
|
|
1053 tdata->numdirs++;
|
|
1054 else
|
|
1055 tdata->numfiles++;
|
|
1056
|
|
1057 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP)
|
|
1058 tdata->total_bytes += tempfle->size;
|
|
1059 }
|
|
1060
|
|
1061 if (g_thread_supported ())
|
|
1062 g_static_mutex_lock (&gftpui_common_transfer_mutex);
|
|
1063
|
|
1064 gftp_file_transfers = g_list_append (gftp_file_transfers, tdata);
|
|
1065
|
|
1066 if (g_thread_supported ())
|
|
1067 g_static_mutex_unlock (&gftpui_common_transfer_mutex);
|
|
1068
|
|
1069 if (show_dialog)
|
|
1070 gftpui_ask_transfer (tdata);
|
|
1071 }
|
|
1072
|
|
1073 return (tdata);
|
|
1074 }
|
|
1075
|
|
1076
|
|
1077 static void
|
|
1078 _gftpui_common_setup_fds (gftp_transfer * tdata, gftp_file * curfle,
|
|
1079 int *fromfd, int *tofd)
|
|
1080 {
|
|
1081 *tofd = -1;
|
|
1082 *fromfd = -1;
|
|
1083
|
|
1084 if (curfle->is_fd)
|
|
1085 {
|
|
1086 if (tdata->toreq->protonum == GFTP_LOCAL_NUM)
|
|
1087 *tofd = curfle->fd;
|
|
1088 else if (tdata->fromreq->protonum == GFTP_LOCAL_NUM)
|
|
1089 *fromfd = curfle->fd;
|
|
1090 }
|
|
1091 }
|
|
1092
|
|
1093
|
|
1094 static void
|
|
1095 _gftpui_common_done_with_fds (gftp_transfer * tdata, gftp_file * curfle)
|
|
1096 {
|
|
1097 if (curfle->is_fd)
|
|
1098 {
|
|
1099 if (tdata->toreq->protonum == GFTP_LOCAL_NUM)
|
|
1100 tdata->toreq->datafd = -1;
|
|
1101 else
|
|
1102 tdata->fromreq->datafd = -1;
|
|
1103 }
|
|
1104 }
|
|
1105
|
|
1106
|
|
1107 int
|
|
1108 gftpui_common_transfer_files (gftp_transfer * tdata)
|
|
1109 {
|
|
1110 int i, mode, tofd, fromfd;
|
|
1111 intptr_t preserve_permissions;
|
|
1112 char buf[8192];
|
|
1113 off_t fromsize, total;
|
|
1114 gftp_file * curfle;
|
|
1115 ssize_t num_read, ret;
|
|
1116
|
|
1117 tdata->curfle = tdata->files;
|
|
1118 gettimeofday (&tdata->starttime, NULL);
|
|
1119 memcpy (&tdata->lasttime, &tdata->starttime,
|
|
1120 sizeof (tdata->lasttime));
|
|
1121
|
|
1122 gftp_lookup_request_option (tdata->fromreq, "preserve_permissions",
|
|
1123 &preserve_permissions);
|
|
1124
|
|
1125 while (tdata->curfle != NULL)
|
|
1126 {
|
|
1127 num_read = -1;
|
|
1128
|
|
1129 if (g_thread_supported ())
|
|
1130 g_static_mutex_lock (&tdata->structmutex);
|
|
1131
|
|
1132 curfle = tdata->curfle->data;
|
|
1133 tdata->current_file_number++;
|
|
1134
|
|
1135 if (g_thread_supported ())
|
|
1136 g_static_mutex_unlock (&tdata->structmutex);
|
|
1137
|
|
1138 if (curfle->transfer_action == GFTP_TRANS_ACTION_SKIP)
|
|
1139 {
|
|
1140 if (g_thread_supported ())
|
|
1141 g_static_mutex_lock (&tdata->structmutex);
|
|
1142
|
|
1143 tdata->next_file = 1;
|
|
1144 tdata->curfle = tdata->curfle->next;
|
|
1145
|
|
1146 if (g_thread_supported ())
|
|
1147 g_static_mutex_unlock (&tdata->structmutex);
|
|
1148 continue;
|
|
1149 }
|
|
1150
|
|
1151 fromsize = -1;
|
|
1152 if (gftp_connect (tdata->fromreq) == 0 &&
|
|
1153 gftp_connect (tdata->toreq) == 0)
|
|
1154 {
|
|
1155 if (curfle->isdir)
|
|
1156 {
|
|
1157 if (tdata->toreq->mkdir != NULL)
|
|
1158 {
|
|
1159 tdata->toreq->mkdir (tdata->toreq, curfle->destfile);
|
|
1160 if (!GFTP_IS_CONNECTED (tdata->toreq))
|
|
1161 break;
|
|
1162 }
|
|
1163
|
|
1164 if (g_thread_supported ())
|
|
1165 g_static_mutex_lock (&tdata->structmutex);
|
|
1166
|
|
1167 tdata->next_file = 1;
|
|
1168 tdata->curfle = tdata->curfle->next;
|
|
1169
|
|
1170 if (g_thread_supported ())
|
|
1171 g_static_mutex_unlock (&tdata->structmutex);
|
|
1172 continue;
|
|
1173 }
|
|
1174
|
|
1175 _gftpui_common_setup_fds (tdata, curfle, &fromfd, &tofd);
|
|
1176
|
|
1177 if (curfle->size == 0)
|
|
1178 {
|
|
1179 curfle->size = gftp_get_file_size (tdata->fromreq, curfle->file);
|
|
1180 tdata->total_bytes += curfle->size;
|
|
1181 }
|
|
1182
|
|
1183 if (GFTP_IS_CONNECTED (tdata->fromreq) &&
|
|
1184 GFTP_IS_CONNECTED (tdata->toreq))
|
|
1185 {
|
|
1186 fromsize = gftp_transfer_file (tdata->fromreq, curfle->file,
|
|
1187 fromfd,
|
|
1188 curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ?
|
|
1189 curfle->startsize : 0,
|
|
1190 tdata->toreq, curfle->destfile, tofd,
|
|
1191 curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ?
|
|
1192 curfle->startsize : 0);
|
|
1193 }
|
|
1194 }
|
|
1195
|
|
1196 if (!GFTP_IS_CONNECTED (tdata->fromreq) ||
|
|
1197 !GFTP_IS_CONNECTED (tdata->toreq))
|
|
1198 {
|
|
1199 tdata->fromreq->logging_function (gftp_logging_misc,
|
|
1200 tdata->fromreq,
|
|
1201 _("Error: Remote site disconnected after trying to tdata file\n"));
|
|
1202 }
|
|
1203 else if (fromsize < 0)
|
|
1204 {
|
|
1205 if (g_thread_supported ())
|
|
1206 g_static_mutex_lock (&tdata->structmutex);
|
|
1207
|
|
1208 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP;
|
|
1209 tdata->next_file = 1;
|
|
1210 tdata->curfle = tdata->curfle->next;
|
|
1211
|
|
1212 if (g_thread_supported ())
|
|
1213 g_static_mutex_unlock (&tdata->structmutex);
|
|
1214 continue;
|
|
1215 }
|
|
1216 else
|
|
1217 {
|
|
1218 if (g_thread_supported ())
|
|
1219 g_static_mutex_lock (&tdata->structmutex);
|
|
1220
|
|
1221 tdata->curtrans = 0;
|
|
1222 tdata->curresumed = curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? curfle->startsize : 0;
|
|
1223 tdata->resumed_bytes += tdata->curresumed;
|
|
1224
|
|
1225 if (g_thread_supported ())
|
|
1226 g_static_mutex_unlock (&tdata->structmutex);
|
|
1227
|
|
1228 total = 0;
|
|
1229 i = 0;
|
|
1230 while (!tdata->cancel &&
|
|
1231 (num_read = gftp_get_next_file_chunk (tdata->fromreq,
|
|
1232 buf, sizeof (buf))) > 0)
|
|
1233 {
|
|
1234 total += num_read;
|
|
1235 gftp_calc_kbs (tdata, num_read);
|
|
1236
|
|
1237 if ((ret = gftp_put_next_file_chunk (tdata->toreq, buf,
|
|
1238 num_read)) < 0)
|
|
1239 {
|
|
1240 num_read = (int) ret;
|
|
1241 break;
|
|
1242 }
|
|
1243 }
|
|
1244 }
|
|
1245
|
|
1246 if (tdata->cancel)
|
|
1247 {
|
|
1248 if (gftp_abort_transfer (tdata->fromreq) != 0)
|
|
1249 gftp_disconnect (tdata->fromreq);
|
|
1250
|
|
1251 if (gftp_abort_transfer (tdata->toreq) != 0)
|
|
1252 gftp_disconnect (tdata->toreq);
|
|
1253 }
|
|
1254 else if (num_read < 0)
|
|
1255 {
|
|
1256 tdata->fromreq->logging_function (gftp_logging_misc,
|
|
1257 tdata->fromreq,
|
|
1258 _("Could not download %s from %s\n"),
|
|
1259 curfle->file,
|
|
1260 tdata->fromreq->hostname);
|
|
1261
|
|
1262 if (gftp_get_transfer_status (tdata, num_read) == GFTP_ERETRYABLE)
|
|
1263 continue;
|
|
1264
|
|
1265 break;
|
|
1266 }
|
|
1267 else
|
|
1268 {
|
|
1269 _gftpui_common_done_with_fds (tdata, curfle);
|
|
1270 if (gftp_end_transfer (tdata->fromreq) != 0)
|
|
1271 {
|
|
1272 if (gftp_get_transfer_status (tdata, -1) == GFTP_ERETRYABLE)
|
|
1273 continue;
|
|
1274
|
|
1275 break;
|
|
1276 }
|
|
1277 gftp_end_transfer (tdata->toreq);
|
|
1278
|
|
1279 tdata->fromreq->logging_function (gftp_logging_misc,
|
|
1280 tdata->fromreq,
|
|
1281 _("Successfully tdatared %s at %.2f KB/s\n"),
|
|
1282 curfle->file, tdata->kbs);
|
|
1283 }
|
|
1284
|
|
1285 if (!curfle->is_fd && preserve_permissions)
|
|
1286 {
|
|
1287 if (curfle->attribs)
|
|
1288 {
|
|
1289 mode = gftp_parse_attribs (curfle->attribs);
|
|
1290 if (mode != 0)
|
|
1291 gftp_chmod (tdata->toreq, curfle->destfile, mode);
|
|
1292 }
|
|
1293
|
|
1294 if (curfle->datetime != 0)
|
|
1295 gftp_set_file_time (tdata->toreq, curfle->destfile,
|
|
1296 curfle->datetime);
|
|
1297 }
|
|
1298
|
|
1299 if (g_thread_supported ())
|
|
1300 g_static_mutex_lock (&tdata->structmutex);
|
|
1301
|
|
1302 tdata->curtrans = 0;
|
|
1303 tdata->next_file = 1;
|
|
1304 curfle->transfer_done = 1;
|
|
1305 tdata->curfle = tdata->curfle->next;
|
|
1306
|
|
1307 if (g_thread_supported ())
|
|
1308 g_static_mutex_unlock (&tdata->structmutex);
|
|
1309
|
|
1310 if (tdata->cancel && !tdata->skip_file)
|
|
1311 break;
|
|
1312 tdata->cancel = 0;
|
|
1313 tdata->fromreq->cancel = 0;
|
|
1314 tdata->toreq->cancel = 0;
|
|
1315 }
|
|
1316 tdata->done = 1;
|
|
1317
|
|
1318 return (1); /* FIXME */
|
|
1319 }
|
|
1320
|