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