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