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
|
|
572 request->logging_function (gftp_logging_misc, request, "%s\n", tempstr);
|
|
573
|
|
574 g_free (tempstr);
|
|
575
|
|
576 delitem = templist;
|
|
577 }
|
|
578
|
|
579 gftp_end_transfer (request);
|
|
580
|
|
581 if (delitem != NULL)
|
|
582 {
|
|
583 fle = delitem->data;
|
|
584 gftp_file_destroy (fle);
|
|
585 g_free (fle);
|
|
586 delitem = NULL;
|
|
587 }
|
|
588
|
|
589 if (files != NULL)
|
|
590 g_list_free (files);
|
|
591
|
|
592 return (1);
|
|
593 }
|
|
594
|
|
595
|
|
596 static int
|
|
597 gftpui_common_cmd_set (void *uidata, gftp_request * request, char *command)
|
|
598 {
|
|
599 gftp_config_vars * cv, newcv;
|
|
600 gftp_logging_func logfunc;
|
|
601 char *pos, *backpos;
|
|
602 GList * templist;
|
|
603 int i;
|
|
604
|
|
605 logfunc = _gftpui_common_log (request);
|
|
606
|
|
607 if (command == NULL || *command == '\0')
|
|
608 {
|
|
609 for (templist = gftp_options_list;
|
|
610 templist != NULL;
|
|
611 templist = templist->next)
|
|
612 {
|
|
613 cv = templist->data;
|
|
614
|
|
615 for (i=0; cv[i].key != NULL; i++)
|
|
616 {
|
|
617 if (!(cv[i].ports_shown & GFTP_PORT_TEXT))
|
|
618 continue;
|
|
619
|
|
620 if (*cv[i].key == '\0' ||
|
|
621 gftp_option_types[cv[i].otype].write_function == NULL)
|
|
622 continue;
|
|
623
|
|
624 printf ("%s = ", cv[i].key);
|
|
625 gftp_option_types[cv[i].otype].write_function (&cv[i], stdout, 0);
|
|
626 printf ("\n");
|
|
627 }
|
|
628 }
|
|
629 }
|
|
630 else
|
|
631 {
|
|
632 if ((pos = strchr (command, '=')) == NULL)
|
|
633 {
|
|
634 logfunc (gftp_logging_error, request,
|
|
635 _("usage: set [variable = value]\n"));
|
|
636 return (1);
|
|
637 }
|
|
638 *pos = '\0';
|
|
639
|
|
640 for (backpos = pos - 1;
|
|
641 (*backpos == ' ' || *backpos == '\t') && backpos > command;
|
|
642 backpos--)
|
|
643 *backpos = '\0';
|
|
644 for (++pos; *pos == ' ' || *pos == '\t'; pos++);
|
|
645
|
|
646 if ((cv = g_hash_table_lookup (gftp_global_options_htable, command)) == NULL)
|
|
647 {
|
|
648 logfunc (gftp_logging_error, request,
|
|
649 _("Error: Variable %s is not a valid configuration variable.\n"), command);
|
|
650 return (1);
|
|
651 }
|
|
652
|
|
653 if (!(cv->ports_shown & GFTP_PORT_TEXT))
|
|
654 {
|
|
655 logfunc (gftp_logging_error, request,
|
|
656 _("Error: Variable %s is not available in the text port of gFTP\n"), command);
|
|
657 return (1);
|
|
658 }
|
|
659
|
|
660 if (gftp_option_types[cv->otype].read_function != NULL)
|
|
661 {
|
|
662 memcpy (&newcv, cv, sizeof (newcv));
|
|
663 newcv.flags &= ~GFTP_CVARS_FLAGS_DYNMEM;
|
|
664
|
|
665 gftp_option_types[cv->otype].read_function (pos, &newcv, 1);
|
|
666
|
|
667 gftp_set_global_option (command, newcv.value);
|
|
668
|
|
669 if (newcv.flags & GFTP_CVARS_FLAGS_DYNMEM)
|
|
670 g_free (newcv.value);
|
|
671 }
|
|
672 }
|
|
673
|
|
674 return (1);
|
|
675 }
|
|
676
|
|
677
|
|
678 static int
|
|
679 gftpui_common_cmd_help (void *uidata, gftp_request * request, char *command)
|
|
680 {
|
|
681 int i, j, ele, numrows, numcols = 6, handled, number_commands;
|
|
682 char *pos;
|
|
683
|
|
684 for (number_commands=0;
|
|
685 gftpui_common_commands[number_commands].command != NULL;
|
|
686 number_commands++);
|
|
687
|
|
688 if (command != NULL && *command != '\0')
|
|
689 {
|
|
690 for (pos = command; *pos != ' ' && *pos != '\0'; pos++);
|
|
691 if (*pos == ' ')
|
|
692 {
|
|
693 *pos++ = '\0';
|
|
694 if (*pos == '\0')
|
|
695 pos = NULL;
|
|
696 }
|
|
697 else
|
|
698 pos = NULL;
|
|
699
|
|
700 for (i=0; gftpui_common_commands[i].command != NULL; i++)
|
|
701 {
|
|
702 if (strcmp (gftpui_common_commands[i].command, command) == 0)
|
|
703 break;
|
|
704 }
|
|
705
|
|
706 if (gftpui_common_commands[i].cmd_description != NULL)
|
|
707 {
|
|
708 if (pos != NULL && gftpui_common_commands[i].subhelp_func != NULL)
|
|
709 handled = gftpui_common_commands[i].subhelp_func (pos);
|
|
710 else
|
|
711 handled = 0;
|
|
712
|
|
713 if (!handled)
|
|
714 printf ("%s\n", _(gftpui_common_commands[i].cmd_description));
|
|
715 }
|
|
716 else
|
|
717 *command = '\0';
|
|
718 }
|
|
719
|
|
720 if (command == NULL || *command == '\0')
|
|
721 {
|
|
722 numrows = number_commands / numcols;
|
|
723 if (number_commands % numcols != 0)
|
|
724 numrows++;
|
|
725
|
|
726 printf (_("Supported commands:\n\n"));
|
|
727 for (i=0; i<numrows; i++)
|
|
728 {
|
|
729 printf (" ");
|
|
730 for (j=0; j<numcols; j++)
|
|
731 {
|
|
732 ele = i + j * numrows;
|
|
733 if (ele >= number_commands)
|
|
734 break;
|
|
735 printf ("%-10s", gftpui_common_commands[ele].command);
|
|
736 }
|
|
737 printf ("\n");
|
|
738 }
|
|
739
|
|
740 printf ("\n");
|
|
741 }
|
|
742 return (1);
|
|
743 }
|
|
744
|
|
745
|
|
746 gftpui_common_methods gftpui_common_commands[] = {
|
|
747 {N_("about"), 2, gftpui_common_cmd_about, gftpui_common_request_none,
|
|
748 N_("Shows gFTP information"), NULL},
|
|
749 {N_("ascii"), 2, gftpui_common_cmd_ascii, gftpui_common_request_remote,
|
|
750 N_("Sets the current file transfer mode to Ascii (only for FTP)"), NULL},
|
|
751 {N_("binary"), 1, gftpui_common_cmd_binary, gftpui_common_request_remote,
|
|
752 N_("Sets the current file transfer mode to Binary (only for FTP)"), NULL},
|
|
753 {N_("cd"), 2, gftpui_common_cmd_chdir, gftpui_common_request_remote,
|
|
754 N_("Changes the remote working directory"), NULL},
|
|
755 {N_("chdir"), 3, gftpui_common_cmd_chdir, gftpui_common_request_remote,
|
|
756 N_("Changes the remote working directory"), NULL},
|
|
757 {N_("chmod"), 3, gftpui_common_cmd_chmod, gftpui_common_request_remote,
|
|
758 N_("Changes the permissions of a remote file"), NULL},
|
|
759 {N_("clear"), 3, gftpui_common_cmd_clear, gftpui_common_request_none,
|
|
760 N_("Available options: cache"), gftpui_common_clear_show_subhelp},
|
|
761 {N_("close"), 3, gftpui_common_cmd_close, gftpui_common_request_remote,
|
|
762 N_("Disconnects from the remote site"), NULL},
|
350
|
763 {N_("delete"), 1, gftpui_common_cmd_delete, gftpui_common_request_remote,
|
341
|
764 N_("Removes a remote file"), NULL},
|
|
765 /* FIXME
|
|
766 {N_("get"), 1, gftp_text_mget_file, gftpui_common_request_none,
|
|
767 N_("Downloads remote file(s)"), NULL},
|
|
768 */
|
|
769 {N_("help"), 1, gftpui_common_cmd_help, gftpui_common_request_none,
|
|
770 N_("Shows this help screen"), NULL},
|
|
771 {N_("lcd"), 3, gftpui_common_cmd_chdir, gftpui_common_request_local,
|
|
772 N_("Changes the local working directory"), NULL},
|
|
773 {N_("lchdir"), 4, gftpui_common_cmd_chdir, gftpui_common_request_local,
|
|
774 N_("Changes the local working directory"), NULL},
|
|
775 {N_("lchmod"), 4, gftpui_common_cmd_chmod, gftpui_common_request_local,
|
|
776 N_("Changes the permissions of a local file"), NULL},
|
|
777 {N_("ldelete"), 2, gftpui_common_cmd_delete, gftpui_common_request_local,
|
|
778 N_("Removes a local file"), NULL},
|
|
779 {N_("lls"), 2, gftpui_common_cmd_ls, gftpui_common_request_local,
|
|
780 N_("Shows the directory listing for the current local directory"), NULL},
|
|
781 {N_("lmkdir"), 2, gftpui_common_cmd_mkdir, gftpui_common_request_local,
|
|
782 N_("Creates a local directory"), NULL},
|
|
783 {N_("lpwd"), 2, gftpui_common_cmd_pwd, gftpui_common_request_local,
|
|
784 N_("Show current local directory"), NULL},
|
|
785 {N_("lrename"), 3, gftpui_common_cmd_rename, gftpui_common_request_local,
|
|
786 N_("Rename a local file"), NULL},
|
|
787 {N_("lrmdir"), 3, gftpui_common_cmd_rmdir, gftpui_common_request_local,
|
|
788 N_("Remove a local directory"), NULL},
|
|
789 {N_("ls"), 2, gftpui_common_cmd_ls, gftpui_common_request_remote,
|
|
790 N_("Shows the directory listing for the current remote directory"), NULL},
|
|
791 /* FIXME
|
|
792 {N_("mget"), 2, gftp_text_mget_file, gftpui_common_request_none,
|
|
793 N_("Downloads remote file(s)"), NULL},
|
|
794 */
|
|
795 {N_("mkdir"), 2, gftpui_common_cmd_mkdir, gftpui_common_request_remote,
|
|
796 N_("Creates a remote directory"), NULL},
|
|
797 /* FIXME
|
|
798 {N_("mput"), 2, gftp_text_mput_file, gftpui_common_request_none,
|
|
799 N_("Uploads local file(s)"), NULL},
|
|
800 {N_("open"), 1, gftp_text_open, gftpui_common_request_remote,
|
|
801 N_("Opens a connection to a remote site"), NULL},
|
|
802 {N_("put"), 2, gftp_text_mput_file, gftpui_common_request_none,
|
|
803 N_("Uploads local file(s)"), NULL},
|
|
804 */
|
|
805 {N_("pwd"), 2, gftpui_common_cmd_pwd, gftpui_common_request_remote,
|
|
806 N_("Show current remote directory"), NULL},
|
|
807 {N_("quit"), 1, gftpui_common_cmd_quit, gftpui_common_request_none,
|
|
808 N_("Exit from gFTP"), NULL},
|
|
809 {N_("rename"), 2, gftpui_common_cmd_rename, gftpui_common_request_remote,
|
|
810 N_("Rename a remote file"), NULL},
|
|
811 {N_("rmdir"), 2, gftpui_common_cmd_rmdir, gftpui_common_request_remote,
|
|
812 N_("Remove a remote directory"), NULL},
|
|
813 {N_("set"), 1, gftpui_common_cmd_set, gftpui_common_request_none,
|
|
814 N_("Show configuration file variables. You can also set variables by set var=val"), gftpui_common_set_show_subhelp},
|
350
|
815 {N_("site"), 2, gftpui_common_cmd_site, gftpui_common_request_remote,
|
|
816 N_("Run a site specific command"), NULL},
|
341
|
817 {NULL, 0, NULL, gftpui_common_request_none,
|
|
818 NULL, NULL}};
|
|
819
|
|
820
|
|
821 int
|
|
822 gftpui_common_init (void *locui, gftp_request * locreq,
|
|
823 void *remui, gftp_request * remreq)
|
|
824 {
|
|
825 gftpui_common_local_uidata = locui;
|
|
826 gftpui_common_local_request = locreq;
|
|
827
|
|
828 gftpui_common_remote_uidata = remui;
|
|
829 gftpui_common_remote_request = remreq;
|
|
830
|
|
831 return (0);
|
|
832 }
|
|
833
|
|
834
|
|
835 int
|
|
836 gftpui_common_process_command (const char *command)
|
|
837 {
|
|
838 const char *stpos;
|
|
839 char *pos, *newstr;
|
|
840 gftp_request * request;
|
|
841 size_t cmdlen;
|
|
842 void *uidata;
|
|
843 int ret, i;
|
|
844 size_t len;
|
|
845
|
|
846 for (stpos = command; *stpos == ' ' || *stpos == '\t'; stpos++);
|
|
847
|
|
848 newstr = g_strdup (stpos);
|
|
849 len = strlen (newstr);
|
|
850
|
|
851 if (len > 0 && newstr[len - 1] == '\n')
|
|
852 newstr[--len] = '\0';
|
|
853 if (len > 0 && newstr[len - 1] == '\r')
|
|
854 newstr[--len] = '\0';
|
|
855
|
|
856 for (pos = newstr + len - 1;
|
|
857 (*pos == ' ' || *pos == '\t') && pos > newstr;
|
|
858 pos--)
|
|
859 *pos = '\0';
|
|
860
|
|
861 if (*stpos == '\0')
|
|
862 {
|
|
863 g_free (newstr);
|
|
864 return (1);
|
|
865 }
|
|
866
|
|
867 if ((pos = strchr (newstr, ' ')) != NULL)
|
|
868 *pos = '\0';
|
|
869
|
|
870 cmdlen = strlen (newstr);
|
|
871 for (i=0; gftpui_common_commands[i].command != NULL; i++)
|
|
872 {
|
|
873 if (strcmp (gftpui_common_commands[i].command, newstr) == 0)
|
|
874 break;
|
|
875 else if (cmdlen >= gftpui_common_commands[i].minlen &&
|
|
876 strncmp (gftpui_common_commands[i].command, newstr, cmdlen) == 0)
|
|
877 break;
|
|
878 }
|
|
879
|
|
880 if (pos != NULL)
|
|
881 pos++;
|
|
882 else
|
|
883 pos = "";
|
|
884
|
|
885 if (gftpui_common_commands[i].command != NULL)
|
|
886 {
|
|
887 if (gftpui_common_commands[i].reqtype == gftpui_common_request_local)
|
|
888 {
|
|
889 request = gftpui_common_local_request;
|
|
890 uidata = gftpui_common_local_uidata;
|
|
891 }
|
|
892 else if (gftpui_common_commands[i].reqtype == gftpui_common_request_remote)
|
|
893 {
|
|
894 request = gftpui_common_remote_request;
|
|
895 uidata = gftpui_common_remote_uidata;
|
|
896 }
|
|
897 else
|
|
898 {
|
|
899 request = NULL;
|
|
900 uidata = NULL;
|
|
901 }
|
|
902
|
|
903 ret = gftpui_common_commands[i].func (uidata, request, pos);
|
|
904 }
|
|
905 else
|
|
906 {
|
|
907 gftpui_common_local_request->logging_function (gftp_logging_error,
|
|
908 gftpui_common_local_request,
|
|
909 _("Error: Command not recognized\n"));
|
|
910 ret = 1;
|
|
911 }
|
|
912
|
|
913 g_free (newstr);
|
|
914 return (ret);
|
|
915 }
|
|
916
|