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
|
355
|
91 if (ret && cdata->run_function != gftpui_common_run_ls)
|
341
|
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
|
355
|
500 static int
|
341
|
501 gftpui_common_cmd_ls (void *uidata, gftp_request * request, char *command)
|
|
502 {
|
355
|
503 char *startcolor, *endcolor, *tempstr;
|
|
504 gftpui_callback_data * cdata;
|
|
505 GList * templist;
|
341
|
506 gftp_file * fle;
|
|
507
|
|
508 if (!GFTP_IS_CONNECTED (request))
|
|
509 {
|
|
510 request->logging_function (gftp_logging_error, request,
|
|
511 _("Error: Not connected to a remote site\n"));
|
|
512 return (1);
|
|
513 }
|
|
514
|
355
|
515 cdata = g_malloc0 (sizeof (*cdata));
|
|
516 cdata->request = request;
|
|
517 cdata->uidata = uidata;
|
|
518 cdata->source_string = *command != '\0' ? command : NULL;
|
|
519 cdata->run_function = gftpui_common_run_ls;
|
341
|
520
|
355
|
521 gftpui_common_run_callback_function (cdata);
|
341
|
522
|
355
|
523 templist = cdata->files;
|
|
524 while (templist != NULL)
|
341
|
525 {
|
|
526 fle = templist->data;
|
|
527
|
|
528 gftpui_lookup_file_colors (fle, &startcolor, &endcolor);
|
|
529 tempstr = gftp_gen_ls_string (fle, startcolor, endcolor);
|
354
|
530 request->logging_function (gftp_logging_misc_nolog, request, "%s\n",
|
|
531 tempstr);
|
341
|
532 g_free (tempstr);
|
|
533
|
355
|
534 templist = templist->next;
|
|
535 gftp_file_destroy (fle);
|
|
536 g_free (fle);
|
341
|
537 }
|
|
538
|
|
539
|
355
|
540 if (cdata->files != NULL)
|
|
541 g_list_free (cdata->files);
|
|
542 g_free (cdata);
|
341
|
543
|
|
544 return (1);
|
|
545 }
|
|
546
|
|
547
|
|
548 static int
|
|
549 gftpui_common_cmd_set (void *uidata, gftp_request * request, char *command)
|
|
550 {
|
|
551 gftp_config_vars * cv, newcv;
|
|
552 gftp_logging_func logfunc;
|
|
553 char *pos, *backpos;
|
|
554 GList * templist;
|
|
555 int i;
|
|
556
|
|
557 logfunc = _gftpui_common_log (request);
|
|
558
|
|
559 if (command == NULL || *command == '\0')
|
|
560 {
|
|
561 for (templist = gftp_options_list;
|
|
562 templist != NULL;
|
|
563 templist = templist->next)
|
|
564 {
|
|
565 cv = templist->data;
|
|
566
|
|
567 for (i=0; cv[i].key != NULL; i++)
|
|
568 {
|
|
569 if (!(cv[i].ports_shown & GFTP_PORT_TEXT))
|
|
570 continue;
|
|
571
|
|
572 if (*cv[i].key == '\0' ||
|
|
573 gftp_option_types[cv[i].otype].write_function == NULL)
|
|
574 continue;
|
|
575
|
|
576 printf ("%s = ", cv[i].key);
|
|
577 gftp_option_types[cv[i].otype].write_function (&cv[i], stdout, 0);
|
|
578 printf ("\n");
|
|
579 }
|
|
580 }
|
|
581 }
|
|
582 else
|
|
583 {
|
|
584 if ((pos = strchr (command, '=')) == NULL)
|
|
585 {
|
|
586 logfunc (gftp_logging_error, request,
|
|
587 _("usage: set [variable = value]\n"));
|
|
588 return (1);
|
|
589 }
|
|
590 *pos = '\0';
|
|
591
|
|
592 for (backpos = pos - 1;
|
|
593 (*backpos == ' ' || *backpos == '\t') && backpos > command;
|
|
594 backpos--)
|
|
595 *backpos = '\0';
|
|
596 for (++pos; *pos == ' ' || *pos == '\t'; pos++);
|
|
597
|
|
598 if ((cv = g_hash_table_lookup (gftp_global_options_htable, command)) == NULL)
|
|
599 {
|
|
600 logfunc (gftp_logging_error, request,
|
|
601 _("Error: Variable %s is not a valid configuration variable.\n"), command);
|
|
602 return (1);
|
|
603 }
|
|
604
|
|
605 if (!(cv->ports_shown & GFTP_PORT_TEXT))
|
|
606 {
|
|
607 logfunc (gftp_logging_error, request,
|
|
608 _("Error: Variable %s is not available in the text port of gFTP\n"), command);
|
|
609 return (1);
|
|
610 }
|
|
611
|
|
612 if (gftp_option_types[cv->otype].read_function != NULL)
|
|
613 {
|
|
614 memcpy (&newcv, cv, sizeof (newcv));
|
|
615 newcv.flags &= ~GFTP_CVARS_FLAGS_DYNMEM;
|
|
616
|
|
617 gftp_option_types[cv->otype].read_function (pos, &newcv, 1);
|
|
618
|
|
619 gftp_set_global_option (command, newcv.value);
|
|
620
|
|
621 if (newcv.flags & GFTP_CVARS_FLAGS_DYNMEM)
|
|
622 g_free (newcv.value);
|
|
623 }
|
|
624 }
|
|
625
|
|
626 return (1);
|
|
627 }
|
|
628
|
|
629
|
|
630 static int
|
|
631 gftpui_common_cmd_help (void *uidata, gftp_request * request, char *command)
|
|
632 {
|
|
633 int i, j, ele, numrows, numcols = 6, handled, number_commands;
|
|
634 char *pos;
|
|
635
|
|
636 for (number_commands=0;
|
|
637 gftpui_common_commands[number_commands].command != NULL;
|
|
638 number_commands++);
|
|
639
|
|
640 if (command != NULL && *command != '\0')
|
|
641 {
|
|
642 for (pos = command; *pos != ' ' && *pos != '\0'; pos++);
|
|
643 if (*pos == ' ')
|
|
644 {
|
|
645 *pos++ = '\0';
|
|
646 if (*pos == '\0')
|
|
647 pos = NULL;
|
|
648 }
|
|
649 else
|
|
650 pos = NULL;
|
|
651
|
|
652 for (i=0; gftpui_common_commands[i].command != NULL; i++)
|
|
653 {
|
|
654 if (strcmp (gftpui_common_commands[i].command, command) == 0)
|
|
655 break;
|
|
656 }
|
|
657
|
|
658 if (gftpui_common_commands[i].cmd_description != NULL)
|
|
659 {
|
|
660 if (pos != NULL && gftpui_common_commands[i].subhelp_func != NULL)
|
|
661 handled = gftpui_common_commands[i].subhelp_func (pos);
|
|
662 else
|
|
663 handled = 0;
|
|
664
|
|
665 if (!handled)
|
|
666 printf ("%s\n", _(gftpui_common_commands[i].cmd_description));
|
|
667 }
|
|
668 else
|
|
669 *command = '\0';
|
|
670 }
|
|
671
|
|
672 if (command == NULL || *command == '\0')
|
|
673 {
|
|
674 numrows = number_commands / numcols;
|
|
675 if (number_commands % numcols != 0)
|
|
676 numrows++;
|
|
677
|
|
678 printf (_("Supported commands:\n\n"));
|
|
679 for (i=0; i<numrows; i++)
|
|
680 {
|
|
681 printf (" ");
|
|
682 for (j=0; j<numcols; j++)
|
|
683 {
|
|
684 ele = i + j * numrows;
|
|
685 if (ele >= number_commands)
|
|
686 break;
|
|
687 printf ("%-10s", gftpui_common_commands[ele].command);
|
|
688 }
|
|
689 printf ("\n");
|
|
690 }
|
|
691
|
|
692 printf ("\n");
|
|
693 }
|
|
694 return (1);
|
|
695 }
|
|
696
|
|
697
|
|
698 gftpui_common_methods gftpui_common_commands[] = {
|
|
699 {N_("about"), 2, gftpui_common_cmd_about, gftpui_common_request_none,
|
|
700 N_("Shows gFTP information"), NULL},
|
|
701 {N_("ascii"), 2, gftpui_common_cmd_ascii, gftpui_common_request_remote,
|
|
702 N_("Sets the current file transfer mode to Ascii (only for FTP)"), NULL},
|
|
703 {N_("binary"), 1, gftpui_common_cmd_binary, gftpui_common_request_remote,
|
|
704 N_("Sets the current file transfer mode to Binary (only for FTP)"), NULL},
|
|
705 {N_("cd"), 2, gftpui_common_cmd_chdir, gftpui_common_request_remote,
|
|
706 N_("Changes the remote working directory"), NULL},
|
|
707 {N_("chdir"), 3, gftpui_common_cmd_chdir, gftpui_common_request_remote,
|
|
708 N_("Changes the remote working directory"), NULL},
|
|
709 {N_("chmod"), 3, gftpui_common_cmd_chmod, gftpui_common_request_remote,
|
|
710 N_("Changes the permissions of a remote file"), NULL},
|
|
711 {N_("clear"), 3, gftpui_common_cmd_clear, gftpui_common_request_none,
|
|
712 N_("Available options: cache"), gftpui_common_clear_show_subhelp},
|
|
713 {N_("close"), 3, gftpui_common_cmd_close, gftpui_common_request_remote,
|
|
714 N_("Disconnects from the remote site"), NULL},
|
350
|
715 {N_("delete"), 1, gftpui_common_cmd_delete, gftpui_common_request_remote,
|
341
|
716 N_("Removes a remote file"), NULL},
|
|
717 /* FIXME
|
|
718 {N_("get"), 1, gftp_text_mget_file, gftpui_common_request_none,
|
|
719 N_("Downloads remote file(s)"), NULL},
|
|
720 */
|
|
721 {N_("help"), 1, gftpui_common_cmd_help, gftpui_common_request_none,
|
|
722 N_("Shows this help screen"), NULL},
|
|
723 {N_("lcd"), 3, gftpui_common_cmd_chdir, gftpui_common_request_local,
|
|
724 N_("Changes the local working directory"), NULL},
|
|
725 {N_("lchdir"), 4, gftpui_common_cmd_chdir, gftpui_common_request_local,
|
|
726 N_("Changes the local working directory"), NULL},
|
|
727 {N_("lchmod"), 4, gftpui_common_cmd_chmod, gftpui_common_request_local,
|
|
728 N_("Changes the permissions of a local file"), NULL},
|
|
729 {N_("ldelete"), 2, gftpui_common_cmd_delete, gftpui_common_request_local,
|
|
730 N_("Removes a local file"), NULL},
|
|
731 {N_("lls"), 2, gftpui_common_cmd_ls, gftpui_common_request_local,
|
|
732 N_("Shows the directory listing for the current local directory"), NULL},
|
|
733 {N_("lmkdir"), 2, gftpui_common_cmd_mkdir, gftpui_common_request_local,
|
|
734 N_("Creates a local directory"), NULL},
|
|
735 {N_("lpwd"), 2, gftpui_common_cmd_pwd, gftpui_common_request_local,
|
|
736 N_("Show current local directory"), NULL},
|
|
737 {N_("lrename"), 3, gftpui_common_cmd_rename, gftpui_common_request_local,
|
|
738 N_("Rename a local file"), NULL},
|
|
739 {N_("lrmdir"), 3, gftpui_common_cmd_rmdir, gftpui_common_request_local,
|
|
740 N_("Remove a local directory"), NULL},
|
|
741 {N_("ls"), 2, gftpui_common_cmd_ls, gftpui_common_request_remote,
|
|
742 N_("Shows the directory listing for the current remote directory"), NULL},
|
|
743 /* FIXME
|
|
744 {N_("mget"), 2, gftp_text_mget_file, gftpui_common_request_none,
|
|
745 N_("Downloads remote file(s)"), NULL},
|
|
746 */
|
|
747 {N_("mkdir"), 2, gftpui_common_cmd_mkdir, gftpui_common_request_remote,
|
|
748 N_("Creates a remote directory"), NULL},
|
|
749 /* FIXME
|
|
750 {N_("mput"), 2, gftp_text_mput_file, gftpui_common_request_none,
|
|
751 N_("Uploads local file(s)"), NULL},
|
|
752 {N_("open"), 1, gftp_text_open, gftpui_common_request_remote,
|
|
753 N_("Opens a connection to a remote site"), NULL},
|
|
754 {N_("put"), 2, gftp_text_mput_file, gftpui_common_request_none,
|
|
755 N_("Uploads local file(s)"), NULL},
|
|
756 */
|
|
757 {N_("pwd"), 2, gftpui_common_cmd_pwd, gftpui_common_request_remote,
|
|
758 N_("Show current remote directory"), NULL},
|
|
759 {N_("quit"), 1, gftpui_common_cmd_quit, gftpui_common_request_none,
|
|
760 N_("Exit from gFTP"), NULL},
|
|
761 {N_("rename"), 2, gftpui_common_cmd_rename, gftpui_common_request_remote,
|
|
762 N_("Rename a remote file"), NULL},
|
|
763 {N_("rmdir"), 2, gftpui_common_cmd_rmdir, gftpui_common_request_remote,
|
|
764 N_("Remove a remote directory"), NULL},
|
|
765 {N_("set"), 1, gftpui_common_cmd_set, gftpui_common_request_none,
|
|
766 N_("Show configuration file variables. You can also set variables by set var=val"), gftpui_common_set_show_subhelp},
|
350
|
767 {N_("site"), 2, gftpui_common_cmd_site, gftpui_common_request_remote,
|
|
768 N_("Run a site specific command"), NULL},
|
341
|
769 {NULL, 0, NULL, gftpui_common_request_none,
|
|
770 NULL, NULL}};
|
|
771
|
|
772
|
|
773 int
|
|
774 gftpui_common_init (void *locui, gftp_request * locreq,
|
|
775 void *remui, gftp_request * remreq)
|
|
776 {
|
|
777 gftpui_common_local_uidata = locui;
|
|
778 gftpui_common_local_request = locreq;
|
|
779
|
|
780 gftpui_common_remote_uidata = remui;
|
|
781 gftpui_common_remote_request = remreq;
|
|
782
|
|
783 return (0);
|
|
784 }
|
|
785
|
|
786
|
|
787 int
|
|
788 gftpui_common_process_command (const char *command)
|
|
789 {
|
|
790 const char *stpos;
|
|
791 char *pos, *newstr;
|
|
792 gftp_request * request;
|
|
793 size_t cmdlen;
|
|
794 void *uidata;
|
|
795 int ret, i;
|
|
796 size_t len;
|
|
797
|
|
798 for (stpos = command; *stpos == ' ' || *stpos == '\t'; stpos++);
|
|
799
|
|
800 newstr = g_strdup (stpos);
|
|
801 len = strlen (newstr);
|
|
802
|
|
803 if (len > 0 && newstr[len - 1] == '\n')
|
|
804 newstr[--len] = '\0';
|
|
805 if (len > 0 && newstr[len - 1] == '\r')
|
|
806 newstr[--len] = '\0';
|
|
807
|
|
808 for (pos = newstr + len - 1;
|
|
809 (*pos == ' ' || *pos == '\t') && pos > newstr;
|
|
810 pos--)
|
|
811 *pos = '\0';
|
|
812
|
|
813 if (*stpos == '\0')
|
|
814 {
|
|
815 g_free (newstr);
|
|
816 return (1);
|
|
817 }
|
|
818
|
|
819 if ((pos = strchr (newstr, ' ')) != NULL)
|
|
820 *pos = '\0';
|
|
821
|
|
822 cmdlen = strlen (newstr);
|
|
823 for (i=0; gftpui_common_commands[i].command != NULL; i++)
|
|
824 {
|
|
825 if (strcmp (gftpui_common_commands[i].command, newstr) == 0)
|
|
826 break;
|
|
827 else if (cmdlen >= gftpui_common_commands[i].minlen &&
|
|
828 strncmp (gftpui_common_commands[i].command, newstr, cmdlen) == 0)
|
|
829 break;
|
|
830 }
|
|
831
|
|
832 if (pos != NULL)
|
|
833 pos++;
|
|
834 else
|
|
835 pos = "";
|
|
836
|
|
837 if (gftpui_common_commands[i].command != NULL)
|
|
838 {
|
|
839 if (gftpui_common_commands[i].reqtype == gftpui_common_request_local)
|
|
840 {
|
|
841 request = gftpui_common_local_request;
|
|
842 uidata = gftpui_common_local_uidata;
|
|
843 }
|
|
844 else if (gftpui_common_commands[i].reqtype == gftpui_common_request_remote)
|
|
845 {
|
|
846 request = gftpui_common_remote_request;
|
|
847 uidata = gftpui_common_remote_uidata;
|
|
848 }
|
|
849 else
|
|
850 {
|
|
851 request = NULL;
|
|
852 uidata = NULL;
|
|
853 }
|
|
854
|
|
855 ret = gftpui_common_commands[i].func (uidata, request, pos);
|
|
856 }
|
|
857 else
|
|
858 {
|
|
859 gftpui_common_local_request->logging_function (gftp_logging_error,
|
|
860 gftpui_common_local_request,
|
|
861 _("Error: Command not recognized\n"));
|
|
862 ret = 1;
|
|
863 }
|
|
864
|
|
865 g_free (newstr);
|
|
866 return (ret);
|
|
867 }
|
|
868
|