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;
|
|
27 static gftp_request * gftpui_common_local_request, * gftpui_common_remote_request;
|
|
28
|
|
29
|
|
30 static gftp_logging_func
|
|
31 _gftpui_common_log (gftp_request * request)
|
|
32 {
|
|
33 if (request == NULL)
|
|
34 return (gftpui_common_local_request->logging_function);
|
|
35 else
|
|
36 return (request->logging_function);
|
|
37 }
|
|
38
|
|
39
|
|
40 static void *
|
|
41 _gftpui_common_thread_callback (void * data)
|
|
42 {
|
|
43 gftpui_callback_data * cdata;
|
|
44 intptr_t network_timeout;
|
|
45 int success, sj;
|
|
46
|
|
47 cdata = data;
|
|
48 gftp_lookup_request_option (cdata->request, "network_timeout",
|
|
49 &network_timeout);
|
|
50
|
|
51 sj = sigsetjmp (gftpui_common_jmp_environment, 1);
|
|
52 gftpui_common_use_jmp_environment = 1;
|
|
53
|
|
54 success = 0;
|
|
55 if (sj == 0)
|
|
56 {
|
|
57 if (network_timeout > 0)
|
|
58 alarm (network_timeout);
|
|
59
|
|
60 success = cdata->run_function (cdata);
|
|
61
|
|
62 alarm (0);
|
|
63 }
|
|
64 else
|
|
65 {
|
|
66 gftp_disconnect (cdata->request);
|
|
67 cdata->request->logging_function (gftp_logging_error, cdata->request,
|
|
68 _("Operation canceled\n"));
|
|
69 }
|
|
70
|
|
71 gftpui_common_use_jmp_environment = 0;
|
|
72 cdata->request->stopable = 0;
|
|
73
|
|
74 return (GINT_TO_POINTER (success));
|
|
75 }
|
|
76
|
|
77
|
|
78 int
|
|
79 gftpui_common_run_callback_function (gftpui_callback_data * cdata)
|
|
80 {
|
|
81 int ret;
|
|
82
|
|
83 if (gftpui_check_reconnect (cdata) < 0)
|
|
84 return (0);
|
|
85
|
|
86 if (gftp_protocols[cdata->request->protonum].use_threads)
|
|
87 ret = GPOINTER_TO_INT (gftpui_generic_thread (_gftpui_common_thread_callback, cdata));
|
|
88 else
|
|
89 ret = GPOINTER_TO_INT (cdata->run_function (cdata));
|
|
90
|
|
91 if (ret)
|
|
92 gftpui_refresh (cdata->uidata);
|
|
93
|
|
94 return (ret);
|
|
95 }
|
|
96
|
|
97
|
|
98 RETSIGTYPE
|
|
99 gftpui_common_signal_handler (int signo)
|
|
100 {
|
|
101 signal (signo, gftpui_common_signal_handler);
|
|
102
|
|
103 if (gftpui_common_use_jmp_environment)
|
|
104 siglongjmp (gftpui_common_jmp_environment, signo == SIGINT ? 1 : 2);
|
|
105 else if (signo == SIGINT)
|
|
106 exit (1);
|
|
107 }
|
|
108
|
|
109
|
|
110 void
|
|
111 gftpui_common_about (gftp_logging_func logging_function, gpointer logdata)
|
|
112 {
|
|
113 char *str;
|
|
114
|
|
115 logging_function (gftp_logging_misc, logdata, "%s, Copyright (C) 1998-2003 Brian Masney <", gftp_version);
|
|
116 logging_function (gftp_logging_recv, logdata, "masneyb@gftp.org");
|
|
117 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"));
|
|
118 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"));
|
|
119
|
|
120 str = _("Translated by");
|
|
121 if (strcmp (str, "Translated by") != 0)
|
|
122 logging_function (gftp_logging_misc, logdata, "%s\n", str);
|
|
123 }
|
|
124
|
|
125
|
|
126 static int
|
|
127 gftpui_common_cmd_about (void *uidata, gftp_request * request, char *command)
|
|
128 {
|
|
129 gftpui_common_about (_gftpui_common_log (request),
|
|
130 gftpui_common_local_request);
|
|
131 return (1);
|
|
132 }
|
|
133
|
|
134
|
|
135 static int
|
|
136 gftpui_common_cmd_ascii (void *uidata, gftp_request * request, char *command)
|
|
137 {
|
350
|
138 gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(1));
|
341
|
139 return (1);
|
|
140 }
|
|
141
|
|
142
|
|
143 static int
|
|
144 gftpui_common_cmd_binary (void *uidata, gftp_request * request, char *command)
|
|
145 {
|
350
|
146 gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(0));
|
341
|
147 return (1);
|
|
148 }
|
|
149
|
|
150
|
|
151 static int
|
|
152 gftpui_common_cmd_chmod (void *uidata, gftp_request * request, char *command)
|
|
153 {
|
350
|
154 gftpui_callback_data * cdata;
|
341
|
155 char *pos;
|
|
156
|
|
157 if (!GFTP_IS_CONNECTED (request))
|
|
158 {
|
|
159 request->logging_function (gftp_logging_error, request,
|
|
160 _("Error: Not connected to a remote site\n"));
|
|
161
|
|
162 return (1);
|
|
163 }
|
|
164
|
|
165 if ((pos = strchr (command, ' ')) != NULL)
|
|
166 *pos++ = '\0';
|
|
167
|
|
168 if (*command == '\0' || pos == NULL || *pos == '\0')
|
|
169 {
|
|
170 request->logging_function (gftp_logging_error, request,
|
|
171 _("usage: chmod <mode> <file>\n"));
|
|
172 }
|
|
173 else
|
|
174 {
|
350
|
175 cdata = g_malloc0 (sizeof (*cdata));
|
|
176 cdata->request = request;
|
|
177 cdata->uidata = uidata;
|
|
178 cdata->input_string = command;
|
|
179 cdata->source_string = pos;
|
|
180 cdata->run_function = gftpui_common_run_chmod;
|
|
181
|
|
182 gftpui_common_run_callback_function (cdata);
|
|
183
|
|
184 g_free (cdata);
|
341
|
185 }
|
|
186
|
|
187 return (1);
|
|
188 }
|
|
189
|
|
190
|
|
191 static int
|
|
192 gftpui_common_cmd_rename (void *uidata, gftp_request * request, char *command)
|
|
193 {
|
350
|
194 gftpui_callback_data * cdata;
|
341
|
195 char *pos;
|
|
196
|
|
197 if (!GFTP_IS_CONNECTED (request))
|
|
198 {
|
|
199 request->logging_function (gftp_logging_error, request,
|
|
200 _("Error: Not connected to a remote site\n"));
|
|
201 return (1);
|
|
202 }
|
|
203
|
|
204 if ((pos = strchr (command, ' ')) != NULL)
|
|
205 *pos++ = '\0';
|
|
206
|
|
207 if (*command == '\0' || pos == NULL || *pos == '\0')
|
|
208 {
|
|
209 request->logging_function (gftp_logging_error, request,
|
|
210 _("usage: rename <old name> <new name>\n"));
|
|
211 }
|
|
212 else
|
|
213 {
|
350
|
214 cdata = g_malloc0 (sizeof (*cdata));
|
|
215 cdata->request = request;
|
|
216 cdata->uidata = uidata;
|
|
217 cdata->source_string = command;
|
|
218 cdata->input_string = pos;
|
|
219 cdata->run_function = gftpui_common_run_rename;
|
|
220
|
|
221 gftpui_common_run_callback_function (cdata);
|
|
222
|
|
223 g_free (cdata);
|
341
|
224 }
|
|
225
|
|
226 return (1);
|
|
227 }
|
|
228
|
|
229
|
|
230 static int
|
|
231 gftpui_common_cmd_delete (void *uidata, gftp_request * request, char *command)
|
|
232 {
|
350
|
233 gftpui_callback_data * cdata;
|
|
234
|
341
|
235 if (!GFTP_IS_CONNECTED (request))
|
|
236 {
|
|
237 request->logging_function (gftp_logging_error, request,
|
|
238 _("Error: Not connected to a remote site\n"));
|
|
239 return (1);
|
|
240 }
|
|
241 else if (*command == '\0')
|
|
242 {
|
|
243 request->logging_function (gftp_logging_error, request,
|
|
244 _("usage: delete <file>\n"));
|
|
245 }
|
|
246 else
|
|
247 {
|
350
|
248 cdata = g_malloc0 (sizeof (*cdata));
|
|
249 cdata->request = request;
|
|
250 cdata->uidata = uidata;
|
|
251 cdata->input_string = command;
|
|
252 cdata->run_function = gftpui_common_run_delete;
|
|
253
|
|
254 gftpui_common_run_callback_function (cdata);
|
|
255
|
|
256 g_free (cdata);
|
341
|
257 }
|
|
258
|
|
259 return (1);
|
|
260 }
|
|
261
|
|
262
|
|
263 static int
|
|
264 gftpui_common_cmd_rmdir (void *uidata, gftp_request * request, char *command)
|
|
265 {
|
350
|
266 gftpui_callback_data * cdata;
|
|
267
|
341
|
268 if (!GFTP_IS_CONNECTED (request))
|
|
269 {
|
|
270 request->logging_function (gftp_logging_error, request,
|
|
271 _("Error: Not connected to a remote site\n"));
|
|
272 return (1);
|
|
273 }
|
|
274 else if (*command == '\0')
|
|
275 {
|
|
276 request->logging_function (gftp_logging_error, request,
|
|
277 _("usage: rmdir <directory>\n"));
|
|
278 }
|
|
279 else
|
|
280 {
|
350
|
281 cdata = g_malloc0 (sizeof (*cdata));
|
|
282 cdata->request = request;
|
|
283 cdata->uidata = uidata;
|
|
284 cdata->input_string = command;
|
|
285 cdata->run_function = gftpui_common_run_rmdir;
|
|
286
|
|
287 gftpui_common_run_callback_function (cdata);
|
|
288
|
|
289 g_free (cdata);
|
|
290 }
|
|
291
|
|
292 return (1);
|
|
293 }
|
|
294
|
|
295
|
|
296 static int
|
|
297 gftpui_common_cmd_site (void *uidata, gftp_request * request, char *command)
|
|
298 {
|
|
299 gftpui_callback_data * cdata;
|
|
300
|
|
301 if (!GFTP_IS_CONNECTED (request))
|
|
302 {
|
|
303 request->logging_function (gftp_logging_error, request,
|
|
304 _("Error: Not connected to a remote site\n"));
|
|
305 return (1);
|
|
306 }
|
|
307 else if (*command == '\0')
|
|
308 {
|
|
309 request->logging_function (gftp_logging_error, request,
|
|
310 _("usage: site <site command>\n"));
|
|
311 }
|
|
312 else
|
|
313 {
|
|
314 cdata = g_malloc0 (sizeof (*cdata));
|
|
315 cdata->request = request;
|
|
316 cdata->uidata = uidata;
|
|
317 cdata->input_string = command;
|
|
318 cdata->run_function = gftpui_common_run_site;
|
|
319
|
|
320 gftpui_common_run_callback_function (cdata);
|
|
321
|
|
322 g_free (cdata);
|
341
|
323 }
|
|
324
|
|
325 return (1);
|
|
326 }
|
|
327
|
|
328
|
|
329 static int
|
|
330 gftpui_common_cmd_mkdir (void *uidata, gftp_request * request, char *command)
|
|
331 {
|
|
332 gftpui_callback_data * cdata;
|
|
333
|
|
334 if (!GFTP_IS_CONNECTED (request))
|
|
335 {
|
|
336 request->logging_function (gftp_logging_error, request,
|
|
337 _("Error: Not connected to a remote site\n"));
|
|
338 return (1);
|
|
339 }
|
|
340 else if (*command == '\0')
|
|
341 {
|
|
342 request->logging_function (gftp_logging_error, request,
|
|
343 _("usage: mkdir <new directory>\n"));
|
|
344 }
|
|
345 else
|
|
346 {
|
|
347 cdata = g_malloc0 (sizeof (*cdata));
|
|
348 cdata->request = request;
|
|
349 cdata->uidata = uidata;
|
|
350 cdata->input_string = command;
|
|
351 cdata->run_function = gftpui_common_run_mkdir;
|
|
352
|
|
353 gftpui_common_run_callback_function (cdata);
|
|
354
|
|
355 g_free (cdata);
|
|
356 }
|
|
357
|
|
358 return (1);
|
|
359 }
|
|
360
|
|
361
|
|
362 static int
|
|
363 gftpui_common_cmd_chdir (void *uidata, gftp_request * request, char *command)
|
|
364 {
|
350
|
365 gftpui_callback_data * cdata;
|
341
|
366 char *tempstr, *newdir = NULL;
|
|
367
|
|
368 if (!GFTP_IS_CONNECTED (request))
|
|
369 {
|
|
370 request->logging_function (gftp_logging_error, request,
|
|
371 _("Error: Not connected to a remote site\n"));
|
|
372 return (1);
|
|
373 }
|
|
374 else if (*command == '\0')
|
|
375 {
|
|
376 request->logging_function (gftp_logging_error, request,
|
|
377 _("usage: chdir <directory>\n"));
|
|
378 return (1);
|
|
379 }
|
|
380 else if (request->protonum == GFTP_LOCAL_NUM)
|
|
381 {
|
|
382 if (*command != '/' && request->directory != NULL)
|
|
383 {
|
350
|
384 tempstr = gftp_build_path (request->directory, command, NULL);
|
341
|
385 newdir = expand_path (tempstr);
|
|
386 g_free (tempstr);
|
|
387 }
|
|
388 else
|
|
389 newdir = expand_path (command);
|
|
390
|
|
391 if (newdir == NULL)
|
|
392 {
|
|
393 request->logging_function (gftp_logging_error, request,
|
|
394 _("usage: chdir <directory>\n"));
|
|
395 return (1);
|
|
396 }
|
|
397 }
|
|
398
|
350
|
399 cdata = g_malloc0 (sizeof (*cdata));
|
|
400 cdata->request = request;
|
|
401 cdata->uidata = uidata;
|
|
402 cdata->input_string = newdir != NULL ? newdir : command;
|
|
403 cdata->run_function = gftpui_common_run_chdir;
|
|
404
|
|
405 gftpui_common_run_callback_function (cdata);
|
|
406
|
|
407 g_free (cdata);
|
341
|
408
|
|
409 if (newdir != NULL)
|
|
410 g_free (newdir);
|
|
411
|
|
412 return (1);
|
|
413 }
|
|
414
|
|
415
|
|
416 static int
|
|
417 gftpui_common_cmd_close (void *uidata, gftp_request * request, char *command)
|
|
418 {
|
|
419 gftp_disconnect (request);
|
|
420 return (1);
|
|
421 }
|
|
422
|
|
423
|
|
424 static int
|
|
425 gftpui_common_cmd_pwd (void *uidata, gftp_request * request, char *command)
|
|
426 {
|
|
427 if (!GFTP_IS_CONNECTED (request))
|
|
428 {
|
|
429 request->logging_function (gftp_logging_error, request,
|
|
430 _("Error: Not connected to a remote site\n"));
|
|
431 return (1);
|
|
432 }
|
|
433
|
|
434 request->logging_function (gftp_logging_misc, request,
|
|
435 "%s\n", request->directory);
|
|
436
|
|
437 return (1);
|
|
438 }
|
|
439
|
|
440
|
|
441 static int
|
|
442 gftpui_common_cmd_quit (void *uidata, gftp_request * request, char *command)
|
|
443 {
|
|
444 gftp_shutdown();
|
|
445
|
|
446 return (0);
|
|
447 }
|
|
448
|
|
449
|
|
450 static int
|
|
451 gftpui_common_cmd_clear (void *uidata, gftp_request * request, char *command)
|
|
452 {
|
|
453 gftp_logging_func logfunc;
|
|
454
|
|
455 if (strcasecmp (command, "cache") == 0)
|
|
456 gftp_clear_cache_files ();
|
|
457 else
|
|
458 {
|
|
459 logfunc = _gftpui_common_log (request);
|
|
460 logfunc (gftp_logging_error, request, _("Invalid argument\n"));
|
|
461 }
|
|
462
|
|
463 return (1);
|
|
464 }
|
|
465
|
|
466
|
|
467 static int
|
|
468 gftpui_common_clear_show_subhelp (char *topic)
|
|
469 {
|
|
470 gftp_logging_func logfunc;
|
|
471
|
|
472 logfunc = gftpui_common_local_request->logging_function;
|
|
473 if (strcmp (topic, "cache") == 0)
|
|
474 {
|
|
475 logfunc (gftp_logging_misc, NULL, _("Clear the directory cache\n"));
|
|
476 return (1);
|
|
477 }
|
|
478
|
|
479 return (0);
|
|
480 }
|
|
481
|
|
482
|
|
483 static int
|
|
484 gftpui_common_set_show_subhelp (char *topic)
|
|
485 {
|
|
486 gftp_logging_func logfunc;
|
|
487 gftp_config_vars * cv;
|
|
488
|
|
489 logfunc = gftpui_common_local_request->logging_function;
|
|
490 if ((cv = g_hash_table_lookup (gftp_global_options_htable, topic)) != NULL)
|
|
491 {
|
|
492 logfunc (gftp_logging_misc, NULL, "%s\n", cv->comment);
|
|
493 return (1);
|
|
494 }
|
|
495
|
|
496 return (0);
|
|
497 }
|
|
498
|
|
499
|
|
500 int
|
|
501 gftpui_common_cmd_ls (void *uidata, gftp_request * request, char *command)
|
|
502 {
|
|
503 char *startcolor, *endcolor, *filespec, *tempstr;
|
|
504 GList * files, * templist, * delitem;
|
|
505 intptr_t sortcol, sortasds;
|
|
506 gftp_file * fle;
|
|
507 time_t curtime;
|
|
508 int got;
|
|
509
|
|
510 time (&curtime);
|
|
511 if (!GFTP_IS_CONNECTED (request))
|
|
512 {
|
|
513 request->logging_function (gftp_logging_error, request,
|
|
514 _("Error: Not connected to a remote site\n"));
|
|
515 return (1);
|
|
516 }
|
|
517
|
|
518 filespec = *command != '\0' ? command : NULL;
|
|
519 if (gftp_list_files (request) != 0)
|
|
520 return (1);
|
|
521
|
|
522 files = NULL;
|
|
523 fle = g_malloc0 (sizeof (*fle));
|
|
524 while ((got = gftp_get_next_file (request, NULL, fle)) > 0 ||
|
|
525 got == GFTP_ERETRYABLE)
|
|
526 {
|
350
|
527 if (got < 0 || strcmp (fle->file, ".") == 0 ||
|
|
528 !gftp_match_filespec (fle->file, filespec))
|
341
|
529 {
|
|
530 gftp_file_destroy (fle);
|
|
531 continue;
|
|
532 }
|
|
533 files = g_list_prepend (files, fle);
|
|
534 fle = g_malloc0 (sizeof (*fle));
|
|
535 }
|
|
536 g_free (fle);
|
|
537
|
|
538 if (files == NULL)
|
|
539 {
|
|
540 gftp_end_transfer (request);
|
|
541 return (1);
|
|
542 }
|
|
543
|
|
544 if (request == gftpui_common_local_request)
|
|
545 {
|
|
546 gftp_lookup_request_option (request, "local_sortcol", &sortcol);
|
|
547 gftp_lookup_request_option (request, "local_sortasds", &sortasds);
|
|
548 }
|
|
549 else
|
|
550 {
|
|
551 gftp_lookup_request_option (request, "remote_sortcol", &sortcol);
|
|
552 gftp_lookup_request_option (request, "remote_sortasds", &sortasds);
|
|
553 }
|
|
554
|
|
555 files = gftp_sort_filelist (files, sortcol, sortasds);
|
|
556 delitem = NULL;
|
|
557 for (templist = files; templist != NULL; templist = templist->next)
|
|
558 {
|
|
559 if (delitem != NULL)
|
|
560 {
|
|
561 fle = delitem->data;
|
|
562 gftp_file_destroy (fle);
|
|
563 g_free (fle);
|
|
564 delitem = NULL;
|
|
565 }
|
|
566
|
|
567 fle = templist->data;
|
|
568
|
|
569 gftpui_lookup_file_colors (fle, &startcolor, &endcolor);
|
|
570 tempstr = gftp_gen_ls_string (fle, startcolor, endcolor);
|
|
571
|
354
|
572 request->logging_function (gftp_logging_misc_nolog, request, "%s\n",
|
|
573 tempstr);
|
341
|
574
|
|
575 g_free (tempstr);
|
|
576
|
|
577 delitem = templist;
|
|
578 }
|
|
579
|
|
580 gftp_end_transfer (request);
|
|
581
|
|
582 if (delitem != NULL)
|
|
583 {
|
|
584 fle = delitem->data;
|
|
585 gftp_file_destroy (fle);
|
|
586 g_free (fle);
|
|
587 delitem = NULL;
|
|
588 }
|
|
589
|
|
590 if (files != NULL)
|
|
591 g_list_free (files);
|
|
592
|
|
593 return (1);
|
|
594 }
|
|
595
|
|
596
|
|
597 static int
|
|
598 gftpui_common_cmd_set (void *uidata, gftp_request * request, char *command)
|
|
599 {
|
|
600 gftp_config_vars * cv, newcv;
|
|
601 gftp_logging_func logfunc;
|
|
602 char *pos, *backpos;
|
|
603 GList * templist;
|
|
604 int i;
|
|
605
|
|
606 logfunc = _gftpui_common_log (request);
|
|
607
|
|
608 if (command == NULL || *command == '\0')
|
|
609 {
|
|
610 for (templist = gftp_options_list;
|
|
611 templist != NULL;
|
|
612 templist = templist->next)
|
|
613 {
|
|
614 cv = templist->data;
|
|
615
|
|
616 for (i=0; cv[i].key != NULL; i++)
|
|
617 {
|
|
618 if (!(cv[i].ports_shown & GFTP_PORT_TEXT))
|
|
619 continue;
|
|
620
|
|
621 if (*cv[i].key == '\0' ||
|
|
622 gftp_option_types[cv[i].otype].write_function == NULL)
|
|
623 continue;
|
|
624
|
|
625 printf ("%s = ", cv[i].key);
|
|
626 gftp_option_types[cv[i].otype].write_function (&cv[i], stdout, 0);
|
|
627 printf ("\n");
|
|
628 }
|
|
629 }
|
|
630 }
|
|
631 else
|
|
632 {
|
|
633 if ((pos = strchr (command, '=')) == NULL)
|
|
634 {
|
|
635 logfunc (gftp_logging_error, request,
|
|
636 _("usage: set [variable = value]\n"));
|
|
637 return (1);
|
|
638 }
|
|
639 *pos = '\0';
|
|
640
|
|
641 for (backpos = pos - 1;
|
|
642 (*backpos == ' ' || *backpos == '\t') && backpos > command;
|
|
643 backpos--)
|
|
644 *backpos = '\0';
|
|
645 for (++pos; *pos == ' ' || *pos == '\t'; pos++);
|
|
646
|
|
647 if ((cv = g_hash_table_lookup (gftp_global_options_htable, command)) == NULL)
|
|
648 {
|
|
649 logfunc (gftp_logging_error, request,
|
|
650 _("Error: Variable %s is not a valid configuration variable.\n"), command);
|
|
651 return (1);
|
|
652 }
|
|
653
|
|
654 if (!(cv->ports_shown & GFTP_PORT_TEXT))
|
|
655 {
|
|
656 logfunc (gftp_logging_error, request,
|
|
657 _("Error: Variable %s is not available in the text port of gFTP\n"), command);
|
|
658 return (1);
|
|
659 }
|
|
660
|
|
661 if (gftp_option_types[cv->otype].read_function != NULL)
|
|
662 {
|
|
663 memcpy (&newcv, cv, sizeof (newcv));
|
|
664 newcv.flags &= ~GFTP_CVARS_FLAGS_DYNMEM;
|
|
665
|
|
666 gftp_option_types[cv->otype].read_function (pos, &newcv, 1);
|
|
667
|
|
668 gftp_set_global_option (command, newcv.value);
|
|
669
|
|
670 if (newcv.flags & GFTP_CVARS_FLAGS_DYNMEM)
|
|
671 g_free (newcv.value);
|
|
672 }
|
|
673 }
|
|
674
|
|
675 return (1);
|
|
676 }
|
|
677
|
|
678
|
|
679 static int
|
|
680 gftpui_common_cmd_help (void *uidata, gftp_request * request, char *command)
|
|
681 {
|
|
682 int i, j, ele, numrows, numcols = 6, handled, number_commands;
|
|
683 char *pos;
|
|
684
|
|
685 for (number_commands=0;
|
|
686 gftpui_common_commands[number_commands].command != NULL;
|
|
687 number_commands++);
|
|
688
|
|
689 if (command != NULL && *command != '\0')
|
|
690 {
|
|
691 for (pos = command; *pos != ' ' && *pos != '\0'; pos++);
|
|
692 if (*pos == ' ')
|
|
693 {
|
|
694 *pos++ = '\0';
|
|
695 if (*pos == '\0')
|
|
696 pos = NULL;
|
|
697 }
|
|
698 else
|
|
699 pos = NULL;
|
|
700
|
|
701 for (i=0; gftpui_common_commands[i].command != NULL; i++)
|
|
702 {
|
|
703 if (strcmp (gftpui_common_commands[i].command, command) == 0)
|
|
704 break;
|
|
705 }
|
|
706
|
|
707 if (gftpui_common_commands[i].cmd_description != NULL)
|
|
708 {
|
|
709 if (pos != NULL && gftpui_common_commands[i].subhelp_func != NULL)
|
|
710 handled = gftpui_common_commands[i].subhelp_func (pos);
|
|
711 else
|
|
712 handled = 0;
|
|
713
|
|
714 if (!handled)
|
|
715 printf ("%s\n", _(gftpui_common_commands[i].cmd_description));
|
|
716 }
|
|
717 else
|
|
718 *command = '\0';
|
|
719 }
|
|
720
|
|
721 if (command == NULL || *command == '\0')
|
|
722 {
|
|
723 numrows = number_commands / numcols;
|
|
724 if (number_commands % numcols != 0)
|
|
725 numrows++;
|
|
726
|
|
727 printf (_("Supported commands:\n\n"));
|
|
728 for (i=0; i<numrows; i++)
|
|
729 {
|
|
730 printf (" ");
|
|
731 for (j=0; j<numcols; j++)
|
|
732 {
|
|
733 ele = i + j * numrows;
|
|
734 if (ele >= number_commands)
|
|
735 break;
|
|
736 printf ("%-10s", gftpui_common_commands[ele].command);
|
|
737 }
|
|
738 printf ("\n");
|
|
739 }
|
|
740
|
|
741 printf ("\n");
|
|
742 }
|
|
743 return (1);
|
|
744 }
|
|
745
|
|
746
|
|
747 gftpui_common_methods gftpui_common_commands[] = {
|
|
748 {N_("about"), 2, gftpui_common_cmd_about, gftpui_common_request_none,
|
|
749 N_("Shows gFTP information"), NULL},
|
|
750 {N_("ascii"), 2, gftpui_common_cmd_ascii, gftpui_common_request_remote,
|
|
751 N_("Sets the current file transfer mode to Ascii (only for FTP)"), NULL},
|
|
752 {N_("binary"), 1, gftpui_common_cmd_binary, gftpui_common_request_remote,
|
|
753 N_("Sets the current file transfer mode to Binary (only for FTP)"), NULL},
|
|
754 {N_("cd"), 2, gftpui_common_cmd_chdir, gftpui_common_request_remote,
|
|
755 N_("Changes the remote working directory"), NULL},
|
|
756 {N_("chdir"), 3, gftpui_common_cmd_chdir, gftpui_common_request_remote,
|
|
757 N_("Changes the remote working directory"), NULL},
|
|
758 {N_("chmod"), 3, gftpui_common_cmd_chmod, gftpui_common_request_remote,
|
|
759 N_("Changes the permissions of a remote file"), NULL},
|
|
760 {N_("clear"), 3, gftpui_common_cmd_clear, gftpui_common_request_none,
|
|
761 N_("Available options: cache"), gftpui_common_clear_show_subhelp},
|
|
762 {N_("close"), 3, gftpui_common_cmd_close, gftpui_common_request_remote,
|
|
763 N_("Disconnects from the remote site"), NULL},
|
350
|
764 {N_("delete"), 1, gftpui_common_cmd_delete, gftpui_common_request_remote,
|
341
|
765 N_("Removes a remote file"), NULL},
|
|
766 /* FIXME
|
|
767 {N_("get"), 1, gftp_text_mget_file, gftpui_common_request_none,
|
|
768 N_("Downloads remote file(s)"), NULL},
|
|
769 */
|
|
770 {N_("help"), 1, gftpui_common_cmd_help, gftpui_common_request_none,
|
|
771 N_("Shows this help screen"), NULL},
|
|
772 {N_("lcd"), 3, gftpui_common_cmd_chdir, gftpui_common_request_local,
|
|
773 N_("Changes the local working directory"), NULL},
|
|
774 {N_("lchdir"), 4, gftpui_common_cmd_chdir, gftpui_common_request_local,
|
|
775 N_("Changes the local working directory"), NULL},
|
|
776 {N_("lchmod"), 4, gftpui_common_cmd_chmod, gftpui_common_request_local,
|
|
777 N_("Changes the permissions of a local file"), NULL},
|
|
778 {N_("ldelete"), 2, gftpui_common_cmd_delete, gftpui_common_request_local,
|
|
779 N_("Removes a local file"), NULL},
|
|
780 {N_("lls"), 2, gftpui_common_cmd_ls, gftpui_common_request_local,
|
|
781 N_("Shows the directory listing for the current local directory"), NULL},
|
|
782 {N_("lmkdir"), 2, gftpui_common_cmd_mkdir, gftpui_common_request_local,
|
|
783 N_("Creates a local directory"), NULL},
|
|
784 {N_("lpwd"), 2, gftpui_common_cmd_pwd, gftpui_common_request_local,
|
|
785 N_("Show current local directory"), NULL},
|
|
786 {N_("lrename"), 3, gftpui_common_cmd_rename, gftpui_common_request_local,
|
|
787 N_("Rename a local file"), NULL},
|
|
788 {N_("lrmdir"), 3, gftpui_common_cmd_rmdir, gftpui_common_request_local,
|
|
789 N_("Remove a local directory"), NULL},
|
|
790 {N_("ls"), 2, gftpui_common_cmd_ls, gftpui_common_request_remote,
|
|
791 N_("Shows the directory listing for the current remote directory"), NULL},
|
|
792 /* FIXME
|
|
793 {N_("mget"), 2, gftp_text_mget_file, gftpui_common_request_none,
|
|
794 N_("Downloads remote file(s)"), NULL},
|
|
795 */
|
|
796 {N_("mkdir"), 2, gftpui_common_cmd_mkdir, gftpui_common_request_remote,
|
|
797 N_("Creates a remote directory"), NULL},
|
|
798 /* FIXME
|
|
799 {N_("mput"), 2, gftp_text_mput_file, gftpui_common_request_none,
|
|
800 N_("Uploads local file(s)"), NULL},
|
|
801 {N_("open"), 1, gftp_text_open, gftpui_common_request_remote,
|
|
802 N_("Opens a connection to a remote site"), NULL},
|
|
803 {N_("put"), 2, gftp_text_mput_file, gftpui_common_request_none,
|
|
804 N_("Uploads local file(s)"), NULL},
|
|
805 */
|
|
806 {N_("pwd"), 2, gftpui_common_cmd_pwd, gftpui_common_request_remote,
|
|
807 N_("Show current remote directory"), NULL},
|
|
808 {N_("quit"), 1, gftpui_common_cmd_quit, gftpui_common_request_none,
|
|
809 N_("Exit from gFTP"), NULL},
|
|
810 {N_("rename"), 2, gftpui_common_cmd_rename, gftpui_common_request_remote,
|
|
811 N_("Rename a remote file"), NULL},
|
|
812 {N_("rmdir"), 2, gftpui_common_cmd_rmdir, gftpui_common_request_remote,
|
|
813 N_("Remove a remote directory"), NULL},
|
|
814 {N_("set"), 1, gftpui_common_cmd_set, gftpui_common_request_none,
|
|
815 N_("Show configuration file variables. You can also set variables by set var=val"), gftpui_common_set_show_subhelp},
|
350
|
816 {N_("site"), 2, gftpui_common_cmd_site, gftpui_common_request_remote,
|
|
817 N_("Run a site specific command"), NULL},
|
341
|
818 {NULL, 0, NULL, gftpui_common_request_none,
|
|
819 NULL, NULL}};
|
|
820
|
|
821
|
|
822 int
|
|
823 gftpui_common_init (void *locui, gftp_request * locreq,
|
|
824 void *remui, gftp_request * remreq)
|
|
825 {
|
|
826 gftpui_common_local_uidata = locui;
|
|
827 gftpui_common_local_request = locreq;
|
|
828
|
|
829 gftpui_common_remote_uidata = remui;
|
|
830 gftpui_common_remote_request = remreq;
|
|
831
|
|
832 return (0);
|
|
833 }
|
|
834
|
|
835
|
|
836 int
|
|
837 gftpui_common_process_command (const char *command)
|
|
838 {
|
|
839 const char *stpos;
|
|
840 char *pos, *newstr;
|
|
841 gftp_request * request;
|
|
842 size_t cmdlen;
|
|
843 void *uidata;
|
|
844 int ret, i;
|
|
845 size_t len;
|
|
846
|
|
847 for (stpos = command; *stpos == ' ' || *stpos == '\t'; stpos++);
|
|
848
|
|
849 newstr = g_strdup (stpos);
|
|
850 len = strlen (newstr);
|
|
851
|
|
852 if (len > 0 && newstr[len - 1] == '\n')
|
|
853 newstr[--len] = '\0';
|
|
854 if (len > 0 && newstr[len - 1] == '\r')
|
|
855 newstr[--len] = '\0';
|
|
856
|
|
857 for (pos = newstr + len - 1;
|
|
858 (*pos == ' ' || *pos == '\t') && pos > newstr;
|
|
859 pos--)
|
|
860 *pos = '\0';
|
|
861
|
|
862 if (*stpos == '\0')
|
|
863 {
|
|
864 g_free (newstr);
|
|
865 return (1);
|
|
866 }
|
|
867
|
|
868 if ((pos = strchr (newstr, ' ')) != NULL)
|
|
869 *pos = '\0';
|
|
870
|
|
871 cmdlen = strlen (newstr);
|
|
872 for (i=0; gftpui_common_commands[i].command != NULL; i++)
|
|
873 {
|
|
874 if (strcmp (gftpui_common_commands[i].command, newstr) == 0)
|
|
875 break;
|
|
876 else if (cmdlen >= gftpui_common_commands[i].minlen &&
|
|
877 strncmp (gftpui_common_commands[i].command, newstr, cmdlen) == 0)
|
|
878 break;
|
|
879 }
|
|
880
|
|
881 if (pos != NULL)
|
|
882 pos++;
|
|
883 else
|
|
884 pos = "";
|
|
885
|
|
886 if (gftpui_common_commands[i].command != NULL)
|
|
887 {
|
|
888 if (gftpui_common_commands[i].reqtype == gftpui_common_request_local)
|
|
889 {
|
|
890 request = gftpui_common_local_request;
|
|
891 uidata = gftpui_common_local_uidata;
|
|
892 }
|
|
893 else if (gftpui_common_commands[i].reqtype == gftpui_common_request_remote)
|
|
894 {
|
|
895 request = gftpui_common_remote_request;
|
|
896 uidata = gftpui_common_remote_uidata;
|
|
897 }
|
|
898 else
|
|
899 {
|
|
900 request = NULL;
|
|
901 uidata = NULL;
|
|
902 }
|
|
903
|
|
904 ret = gftpui_common_commands[i].func (uidata, request, pos);
|
|
905 }
|
|
906 else
|
|
907 {
|
|
908 gftpui_common_local_request->logging_function (gftp_logging_error,
|
|
909 gftpui_common_local_request,
|
|
910 _("Error: Command not recognized\n"));
|
|
911 ret = 1;
|
|
912 }
|
|
913
|
|
914 g_free (newstr);
|
|
915 return (ret);
|
|
916 }
|
|
917
|