1
|
1 /*****************************************************************************/
|
|
2 /* gftp-text.c - text port of gftp */
|
122
|
3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */
|
1
|
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 "gftp-text.h"
|
33
|
21 static const char cvsid[] = "$Id$";
|
1
|
22
|
|
23 static gftp_request * gftp_text_locreq = NULL;
|
|
24 static gftp_request * gftp_text_remreq = NULL;
|
|
25 static volatile int cancel = 0;
|
201
|
26 static int number_commands = 30;
|
1
|
27
|
|
28 struct _gftp_text_methods gftp_text_methods[] = {
|
|
29 {N_("about"), 2, gftp_text_about, NULL,
|
37
|
30 N_("Shows gFTP information"), NULL},
|
1
|
31 {N_("ascii"), 2, gftp_text_ascii, &gftp_text_remreq,
|
37
|
32 N_("Sets the current file transfer mode to Ascii (only for FTP)"), NULL},
|
1
|
33 {N_("binary"), 1, gftp_text_binary, &gftp_text_remreq,
|
37
|
34 N_("Sets the current file transfer mode to Binary (only for FTP)"), NULL},
|
1
|
35 {N_("cd"), 2, gftp_text_cd, &gftp_text_remreq,
|
37
|
36 N_("Changes the remote working directory"), NULL},
|
1
|
37 {N_("chdir"), 3, gftp_text_cd, &gftp_text_remreq,
|
37
|
38 N_("Changes the remote working directory"), NULL},
|
1
|
39 {N_("chmod"), 3, gftp_text_chmod, &gftp_text_remreq,
|
37
|
40 N_("Changes the permissions of a remote file"), NULL},
|
|
41 {N_("clear"), 3, gftp_text_clear, NULL,
|
|
42 N_("Available options: cache"), gftp_text_clear_show_subhelp},
|
|
43 {N_("close"), 3, gftp_text_close, &gftp_text_remreq,
|
|
44 N_("Disconnects from the remote site"), NULL},
|
1
|
45 {N_("delete"), 1, gftp_text_delete, &gftp_text_remreq,
|
37
|
46 N_("Removes a remote file"), NULL},
|
1
|
47 {N_("get"), 1, gftp_text_mget_file, NULL,
|
37
|
48 N_("Downloads remote file(s)"), NULL},
|
1
|
49 {N_("help"), 1, gftp_text_help, NULL,
|
37
|
50 N_("Shows this help screen"), NULL},
|
1
|
51 {N_("lcd"), 3, gftp_text_cd, &gftp_text_locreq,
|
37
|
52 N_("Changes the local working directory"), NULL},
|
1
|
53 {N_("lchdir"), 4, gftp_text_cd, &gftp_text_locreq,
|
37
|
54 N_("Changes the local working directory"), NULL},
|
1
|
55 {N_("lchmod"), 4, gftp_text_chmod, &gftp_text_locreq,
|
37
|
56 N_("Changes the permissions of a local file"), NULL},
|
1
|
57 {N_("ldelete"), 2, gftp_text_delete, &gftp_text_locreq,
|
37
|
58 N_("Removes a local file"), NULL},
|
1
|
59 {N_("lls"), 2, gftp_text_ls, &gftp_text_locreq,
|
37
|
60 N_("Shows the directory listing for the current local directory"), NULL},
|
1
|
61 {N_("lmkdir"), 2, gftp_text_mkdir, &gftp_text_locreq,
|
37
|
62 N_("Creates a local directory"), NULL},
|
1
|
63 {N_("lpwd"), 2, gftp_text_pwd, &gftp_text_locreq,
|
37
|
64 N_("Show current local directory"), NULL},
|
1
|
65 {N_("lrename"), 3, gftp_text_rename, &gftp_text_locreq,
|
37
|
66 N_("Rename a local file"), NULL},
|
1
|
67 {N_("lrmdir"), 3, gftp_text_rmdir, &gftp_text_locreq,
|
37
|
68 N_("Remove a local directory"), NULL},
|
1
|
69 {N_("ls"), 2, gftp_text_ls, &gftp_text_remreq,
|
37
|
70 N_("Shows the directory listing for the current remote directory"), NULL},
|
1
|
71 {N_("mget"), 2, gftp_text_mget_file, NULL,
|
37
|
72 N_("Downloads remote file(s)"), NULL},
|
1
|
73 {N_("mkdir"), 2, gftp_text_mkdir, &gftp_text_remreq,
|
37
|
74 N_("Creates a remote directory"), NULL},
|
1
|
75 {N_("mput"), 2, gftp_text_mput_file, NULL,
|
37
|
76 N_("Uploads local file(s)"), NULL},
|
1
|
77 {N_("open"), 1, gftp_text_open, &gftp_text_remreq,
|
37
|
78 N_("Opens a connection to a remote site"), NULL},
|
1
|
79 {N_("put"), 2, gftp_text_mput_file, NULL,
|
37
|
80 N_("Uploads local file(s)"), NULL},
|
1
|
81 {N_("pwd"), 2, gftp_text_pwd, &gftp_text_remreq,
|
37
|
82 N_("Show current remote directory"), NULL},
|
1
|
83 {N_("quit"), 1, gftp_text_quit, NULL,
|
37
|
84 N_("Exit from gFTP"), NULL},
|
1
|
85 {N_("rename"), 2, gftp_text_rename, &gftp_text_remreq,
|
37
|
86 N_("Rename a remote file"), NULL},
|
1
|
87 {N_("rmdir"), 2, gftp_text_rmdir, &gftp_text_remreq,
|
37
|
88 N_("Remove a remote directory"), NULL},
|
1
|
89 {N_("set"), 1, gftp_text_set, NULL,
|
37
|
90 N_("Show configuration file variables. You can also set variables by set var=val"), gftp_text_set_show_subhelp},
|
1
|
91 {NULL, 0, NULL, NULL, NULL}};
|
|
92
|
|
93 int
|
|
94 main (int argc, char **argv)
|
|
95 {
|
122
|
96 char *pos, *stpos, *startup_directory;
|
1
|
97 gftp_request * request;
|
|
98 size_t len, cmdlen;
|
|
99 int i;
|
230
|
100 #if HAVE_LIBREADLINE
|
1
|
101 char *tempstr, prompt[20];
|
|
102 #else
|
|
103 char tempstr[512];
|
|
104 #endif
|
|
105
|
290
|
106 gftp_locale_init ();
|
1
|
107
|
|
108 signal (SIGCHLD, sig_child);
|
|
109 signal (SIGPIPE, SIG_IGN);
|
|
110
|
124
|
111 gftp_read_config_file (SHARE_DIR);
|
|
112
|
|
113 if (gftp_parse_command_line (&argc, &argv) != 0)
|
|
114 exit (0);
|
1
|
115
|
|
116 /* SSH doesn't support reading the password with askpass via the command
|
|
117 line */
|
|
118
|
|
119 gftp_text_remreq = gftp_request_new ();
|
122
|
120 gftp_set_request_option (gftp_text_remreq, "ssh_use_askpass",
|
|
121 GINT_TO_POINTER(0));
|
143
|
122 gftp_set_request_option (gftp_text_remreq, "sshv2_use_sftp_subsys",
|
122
|
123 GINT_TO_POINTER(0));
|
1
|
124 gftp_text_remreq->logging_function = gftp_text_log;
|
|
125
|
|
126 gftp_text_locreq = gftp_request_new ();
|
122
|
127 gftp_set_request_option (gftp_text_locreq, "ssh_use_askpass",
|
|
128 GINT_TO_POINTER(0));
|
143
|
129 gftp_set_request_option (gftp_text_locreq, "sshv2_use_sftp_subsys",
|
122
|
130 GINT_TO_POINTER(0));
|
143
|
131
|
1
|
132 gftp_text_locreq->logging_function = gftp_text_log;
|
173
|
133 if (gftp_protocols[GFTP_LOCAL_NUM].init (gftp_text_locreq) == 0)
|
|
134 {
|
|
135 gftp_lookup_request_option (gftp_text_locreq, "startup_directory",
|
|
136 &startup_directory);
|
|
137 if (*startup_directory != '\0')
|
|
138 gftp_set_directory (gftp_text_locreq, startup_directory);
|
122
|
139
|
173
|
140 gftp_connect (gftp_text_locreq);
|
|
141 }
|
1
|
142
|
122
|
143 gftp_text_log (gftp_logging_misc, NULL, "%s, Copyright (C) 1998-2003 Brian Masney <", gftp_version);
|
1
|
144 gftp_text_log (gftp_logging_recv, NULL, "masneyb@gftp.org");
|
|
145 gftp_text_log (gftp_logging_misc, NULL, _(">.\nIf 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"));
|
|
146 gftp_text_log (gftp_logging_misc, NULL, "\n");
|
|
147 gftp_text_log (gftp_logging_misc, NULL, _("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"));
|
|
148 gftp_text_log (gftp_logging_misc, NULL, "\n");
|
|
149
|
|
150 if (argc == 3 && strcmp (argv[1], "-d") == 0)
|
|
151 {
|
|
152 if ((pos = strrchr (argv[2], '/')) != NULL)
|
|
153 *pos = '\0';
|
|
154 gftp_text_open (gftp_text_remreq, argv[2], NULL);
|
|
155
|
|
156 if (pos != NULL)
|
|
157 *pos = '/';
|
|
158
|
|
159 gftp_text_mget_file (gftp_text_remreq, pos + 1, NULL);
|
|
160 exit (0);
|
|
161 }
|
|
162 else if (argc == 2)
|
|
163 gftp_text_open (gftp_text_remreq, argv[1], NULL);
|
|
164
|
230
|
165 #if HAVE_LIBREADLINE
|
1
|
166 g_snprintf (prompt, sizeof (prompt), "%sftp%s> ", COLOR_BLUE, COLOR_DEFAULT);
|
|
167 while ((tempstr = readline (prompt)))
|
|
168 #else
|
|
169 printf ("%sftp%s> ", COLOR_BLUE, COLOR_DEFAULT);
|
|
170 while (fgets (tempstr, sizeof (tempstr), stdin) != NULL)
|
|
171 #endif
|
|
172 {
|
|
173 len = strlen (tempstr);
|
|
174 if (tempstr[len - 1] == '\n')
|
|
175 tempstr[--len] = '\0';
|
|
176 if (tempstr[len - 1] == '\r')
|
|
177 tempstr[--len] = '\0';
|
|
178
|
|
179 for (stpos = tempstr; *stpos == ' '; stpos++);
|
|
180
|
|
181 for (pos = tempstr + len - 1;
|
|
182 (*pos == ' ' || *pos == '\t') && pos > tempstr;
|
|
183 pos--)
|
|
184 *pos = '\0';
|
|
185
|
|
186 if (*stpos == '\0')
|
|
187 {
|
230
|
188 #if !HAVE_LIBREADLINE
|
1
|
189 printf ("%sftp%s> ", COLOR_BLUE, COLOR_DEFAULT);
|
|
190 #endif
|
|
191 continue;
|
|
192 }
|
|
193
|
230
|
194 #if HAVE_LIBREADLINE
|
1
|
195 add_history (tempstr);
|
|
196 #endif
|
|
197
|
|
198 if ((pos = strchr (stpos, ' ')) != NULL)
|
|
199 *pos = '\0';
|
|
200 cmdlen = strlen (stpos);
|
|
201
|
|
202 for (i=0; gftp_text_methods[i].command != NULL; i++)
|
|
203 {
|
|
204 if (strcmp (gftp_text_methods[i].command, stpos) == 0)
|
|
205 break;
|
|
206 else if (cmdlen >= gftp_text_methods[i].minlen &&
|
|
207 strncmp (gftp_text_methods[i].command, stpos, cmdlen) == 0)
|
|
208 break;
|
|
209 }
|
|
210
|
|
211 if (pos != NULL)
|
|
212 pos++;
|
|
213 else
|
|
214 pos = "";
|
|
215
|
|
216 if (gftp_text_methods[i].command != NULL)
|
|
217 {
|
|
218 if (gftp_text_methods[i].request != NULL)
|
|
219 request = *gftp_text_methods[i].request;
|
|
220 else
|
|
221 request = NULL;
|
|
222
|
|
223 if (gftp_text_methods[i].func (request, pos, NULL) == 0)
|
|
224 break;
|
|
225 }
|
|
226 else
|
|
227 gftp_text_log (gftp_logging_error, NULL,
|
|
228 _("Error: Command not recognized\n"));
|
|
229
|
230
|
230 #if HAVE_LIBREADLINE
|
1
|
231 free (tempstr);
|
|
232 #else
|
|
233 printf ("%sftp%s> ", COLOR_BLUE, COLOR_DEFAULT);
|
|
234 #endif
|
|
235 }
|
|
236
|
|
237 gftp_text_quit (NULL, NULL, NULL);
|
|
238
|
|
239 return (0);
|
|
240 }
|
|
241
|
|
242
|
|
243 void
|
186
|
244 gftp_text_log (gftp_logging_level level, gftp_request * request,
|
|
245 const char *string, ...)
|
1
|
246 {
|
186
|
247 char tempstr[512], *stpos, *endpos, *utf8_str = NULL, *outstr;
|
1
|
248 va_list argp;
|
|
249 int sw;
|
|
250
|
|
251 g_return_if_fail (string != NULL);
|
|
252
|
|
253 switch (level)
|
|
254 {
|
|
255 case gftp_logging_send:
|
|
256 printf ("%s", COLOR_GREEN);
|
|
257 break;
|
|
258 case gftp_logging_recv:
|
|
259 printf ("%s", COLOR_YELLOW);
|
|
260 break;
|
|
261 case gftp_logging_error:
|
|
262 printf ("%s", COLOR_RED);
|
|
263 break;
|
|
264 default:
|
|
265 printf ("%s", COLOR_DEFAULT);
|
|
266 break;
|
|
267 }
|
|
268
|
|
269 va_start (argp, string);
|
|
270 g_vsnprintf (tempstr, sizeof (tempstr), string, argp);
|
|
271 va_end (argp);
|
|
272
|
186
|
273 #if GLIB_MAJOR_VERSION > 1
|
|
274 if (!g_utf8_validate (tempstr, -1, NULL))
|
|
275 utf8_str = gftp_string_to_utf8 (request, tempstr);
|
|
276 #endif
|
|
277
|
|
278 if (utf8_str != NULL)
|
|
279 outstr = utf8_str;
|
|
280 else
|
|
281 outstr = tempstr;
|
|
282
|
122
|
283 if (gftp_logfd != NULL)
|
1
|
284 {
|
186
|
285 fwrite (outstr, 1, strlen (outstr), gftp_logfd);
|
122
|
286 if (ferror (gftp_logfd))
|
1
|
287 {
|
122
|
288 fclose (gftp_logfd);
|
|
289 gftp_logfd = NULL;
|
1
|
290 }
|
|
291 else
|
122
|
292 fflush (gftp_logfd);
|
1
|
293 }
|
|
294
|
|
295 sw = gftp_text_get_win_size ();
|
186
|
296 stpos = outstr;
|
|
297 endpos = outstr + 1;
|
1
|
298 do
|
|
299 {
|
|
300 if (strlen (stpos) <= sw)
|
|
301 {
|
|
302 printf ("%s", stpos);
|
|
303 break;
|
|
304 }
|
|
305 for (endpos = stpos + sw - 1; *endpos != ' ' && endpos > stpos; endpos--);
|
|
306 if (endpos != stpos)
|
|
307 {
|
|
308 *endpos = '\0';
|
|
309 }
|
|
310 printf ("%s\n", stpos);
|
|
311 stpos = endpos + 1;
|
|
312 }
|
|
313 while (stpos != endpos);
|
|
314
|
|
315 printf ("%s", COLOR_DEFAULT);
|
186
|
316
|
|
317 if (utf8_str != NULL)
|
|
318 g_free (utf8_str);
|
1
|
319 }
|
|
320
|
|
321
|
|
322 int
|
|
323 gftp_text_open (gftp_request * request, char *command, gpointer *data)
|
|
324 {
|
|
325 char tempstr[255], *pos;
|
|
326
|
|
327 if (GFTP_IS_CONNECTED (request))
|
|
328 {
|
|
329 gftp_disconnect (request);
|
|
330 }
|
|
331
|
|
332 if (*command == '\0')
|
|
333 {
|
186
|
334 gftp_text_log (gftp_logging_error, request,
|
1
|
335 _("usage: open [[ftp://][user:pass@]ftp-site[:port][/directory]]\n"));
|
|
336 return (1);
|
|
337 }
|
|
338
|
|
339 if (gftp_parse_url (request, command) < 0)
|
173
|
340 return (1);
|
1
|
341
|
169
|
342 if (request->need_userpass)
|
1
|
343 {
|
169
|
344 if (request->username == NULL || *request->username == '\0')
|
1
|
345 {
|
166
|
346 if ((pos = gftp_text_ask_question ("Username [anonymous]", 1, tempstr,
|
|
347 sizeof (tempstr))) != NULL)
|
1
|
348 {
|
166
|
349 gftp_set_username (request, pos);
|
169
|
350 gftp_set_password (request, NULL);
|
1
|
351 }
|
|
352 }
|
169
|
353
|
|
354 if (request->username != NULL &&
|
|
355 strcmp (request->username, "anonymous") != 0 &&
|
|
356 (request->password == NULL || *request->password == '\0'))
|
166
|
357 {
|
169
|
358 if ((pos = gftp_text_ask_question ("Password", 0, tempstr,
|
|
359 sizeof (tempstr))) == NULL)
|
|
360 return (1);
|
|
361 gftp_set_password (request, pos);
|
166
|
362 }
|
1
|
363 }
|
|
364
|
|
365 gftp_connect (request);
|
|
366 return (1);
|
|
367 }
|
|
368
|
|
369
|
|
370 int
|
|
371 gftp_text_close (gftp_request * request, char *command, gpointer *data)
|
|
372 {
|
|
373 gftp_disconnect (request);
|
|
374 return (1);
|
|
375 }
|
|
376
|
|
377
|
|
378 int
|
|
379 gftp_text_about (gftp_request * request, char *command, gpointer *data)
|
|
380 {
|
|
381 char *str;
|
|
382
|
186
|
383 gftp_text_log (gftp_logging_misc, request,
|
122
|
384 "%s. Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org>\n",
|
|
385 gftp_version);
|
1
|
386
|
|
387 str = _("Translated by");
|
|
388 if (strcmp (str, "Translated by") != 0)
|
186
|
389 gftp_text_log (gftp_logging_misc, request, "%s\n", str);
|
1
|
390 return (1);
|
|
391 }
|
|
392
|
|
393
|
|
394 int
|
|
395 gftp_text_quit (gftp_request * request, char *command, gpointer *data)
|
|
396 {
|
201
|
397 gftp_request_destroy (gftp_text_locreq, 1);
|
|
398 gftp_request_destroy (gftp_text_remreq, 1);
|
|
399 gftp_shutdown();
|
|
400
|
1
|
401 return (0);
|
|
402 }
|
|
403
|
|
404
|
|
405 int
|
|
406 gftp_text_pwd (gftp_request * request, char *command, gpointer *data)
|
|
407 {
|
|
408 if (!GFTP_IS_CONNECTED (request))
|
|
409 {
|
186
|
410 gftp_text_log (gftp_logging_error, request,
|
1
|
411 _("Error: Not connected to a remote site\n"));
|
|
412 return (1);
|
|
413 }
|
186
|
414 gftp_text_log (gftp_logging_misc, request, "%s\n", request->directory);
|
1
|
415 return (1);
|
|
416 }
|
|
417
|
|
418
|
|
419 int
|
|
420 gftp_text_cd (gftp_request * request, char *command, gpointer *data)
|
|
421 {
|
204
|
422 char *tempstr, *newdir = NULL;
|
1
|
423
|
|
424 if (!GFTP_IS_CONNECTED (request))
|
|
425 {
|
186
|
426 gftp_text_log (gftp_logging_error, request,
|
1
|
427 _("Error: Not connected to a remote site\n"));
|
|
428 return (1);
|
|
429 }
|
|
430 else if (*command == '\0')
|
|
431 {
|
186
|
432 gftp_text_log (gftp_logging_error, request,
|
|
433 _("usage: chdir <directory>\n"));
|
1
|
434 return (1);
|
|
435 }
|
204
|
436 else if (request->protonum == GFTP_LOCAL_NUM)
|
|
437 {
|
219
|
438 if (*command != '/' && request->directory != NULL)
|
204
|
439 {
|
|
440 tempstr = g_strconcat (request->directory, "/", command, NULL);
|
|
441 newdir = expand_path (tempstr);
|
|
442 g_free (tempstr);
|
|
443 }
|
|
444 else
|
|
445 newdir = expand_path (command);
|
|
446
|
|
447 if (newdir == NULL)
|
|
448 {
|
|
449 gftp_text_log (gftp_logging_error, request,
|
|
450 _("usage: chdir <directory>\n"));
|
|
451 return (1);
|
|
452 }
|
|
453 }
|
1
|
454
|
|
455 gftp_set_directory (request, newdir != NULL ? newdir : command);
|
|
456
|
|
457 if (newdir != NULL)
|
|
458 g_free (newdir);
|
|
459
|
|
460 return (1);
|
|
461 }
|
|
462
|
|
463
|
|
464 int
|
|
465 gftp_text_mkdir (gftp_request * request, char *command, gpointer *data)
|
|
466 {
|
|
467 if (!GFTP_IS_CONNECTED (request))
|
|
468 {
|
186
|
469 gftp_text_log (gftp_logging_error, request,
|
1
|
470 _("Error: Not connected to a remote site\n"));
|
|
471 return (1);
|
|
472 }
|
|
473
|
|
474 if (*command == '\0')
|
|
475 {
|
186
|
476 gftp_text_log (gftp_logging_error, request,
|
1
|
477 _("usage: mkdir <new directory>\n"));
|
|
478 }
|
|
479 else
|
|
480 {
|
|
481 gftp_make_directory (request, command);
|
|
482 }
|
|
483 return (1);
|
|
484 }
|
|
485
|
|
486
|
|
487 int
|
|
488 gftp_text_rmdir (gftp_request * request, char *command, gpointer *data)
|
|
489 {
|
|
490 if (!GFTP_IS_CONNECTED (request))
|
|
491 {
|
186
|
492 gftp_text_log (gftp_logging_error, request,
|
1
|
493 _("Error: Not connected to a remote site\n"));
|
|
494 return (1);
|
|
495 }
|
|
496
|
|
497 if (*command == '\0')
|
|
498 {
|
186
|
499 gftp_text_log (gftp_logging_error, request,
|
|
500 _("usage: rmdir <directory>\n"));
|
1
|
501 }
|
|
502 else
|
|
503 {
|
|
504 gftp_remove_directory (request, command);
|
|
505 }
|
|
506 return (1);
|
|
507 }
|
|
508
|
|
509
|
|
510 int
|
|
511 gftp_text_delete (gftp_request * request, char *command, gpointer *data)
|
|
512 {
|
|
513 if (!GFTP_IS_CONNECTED (request))
|
|
514 {
|
186
|
515 gftp_text_log (gftp_logging_error, request,
|
1
|
516 _("Error: Not connected to a remote site\n"));
|
|
517 return (1);
|
|
518 }
|
|
519
|
|
520 if (*command == '\0')
|
|
521 {
|
186
|
522 gftp_text_log (gftp_logging_error, request,
|
|
523 _("usage: delete <file>\n"));
|
1
|
524 }
|
|
525 else
|
|
526 {
|
179
|
527 if (gftp_remove_file (request, command) == 0)
|
182
|
528 gftp_delete_cache_entry (request, NULL, 0);
|
1
|
529 }
|
|
530 return (1);
|
|
531 }
|
|
532
|
|
533
|
|
534 int
|
|
535 gftp_text_rename (gftp_request * request, char *command, gpointer *data)
|
|
536 {
|
|
537 char *pos;
|
|
538
|
|
539 if (!GFTP_IS_CONNECTED (request))
|
|
540 {
|
186
|
541 gftp_text_log (gftp_logging_error, request,
|
1
|
542 _("Error: Not connected to a remote site\n"));
|
|
543 return (1);
|
|
544 }
|
|
545
|
|
546 if ((pos = strchr (command, ' ')) != NULL)
|
|
547 *pos++ = '\0';
|
|
548
|
|
549 if (*command == '\0' || pos == NULL || *pos == '\0')
|
|
550 {
|
186
|
551 gftp_text_log (gftp_logging_error, request,
|
1
|
552 _("usage: rename <old name> <new name>\n"));
|
|
553 }
|
|
554 else
|
|
555 {
|
|
556 gftp_rename_file (request, command, pos);
|
|
557 }
|
|
558 return (1);
|
|
559 }
|
|
560
|
|
561
|
|
562 int
|
|
563 gftp_text_chmod (gftp_request * request, char *command, gpointer *data)
|
|
564 {
|
|
565 char *pos;
|
|
566
|
|
567 if (!GFTP_IS_CONNECTED (request))
|
|
568 {
|
186
|
569 gftp_text_log (gftp_logging_error, request,
|
1
|
570 _("Error: Not connected to a remote site\n"));
|
|
571 return (1);
|
|
572 }
|
|
573
|
|
574 if ((pos = strchr (command, ' ')) != NULL)
|
|
575 *pos++ = '\0';
|
|
576
|
|
577 if (*command == '\0' || pos == NULL || *pos == '\0')
|
|
578 {
|
186
|
579 gftp_text_log (gftp_logging_error, request,
|
1
|
580 _("usage: chmod <mode> <file>\n"));
|
|
581 }
|
|
582 else
|
|
583 {
|
|
584 gftp_chmod (request, pos, strtol (command, NULL, 10));
|
|
585 }
|
|
586 return (1);
|
|
587 }
|
|
588
|
|
589
|
|
590 int
|
|
591 gftp_text_ls (gftp_request * request, char *command, gpointer *data)
|
|
592 {
|
37
|
593 GList * files, * templist, * delitem;
|
131
|
594 char *color, *filespec, *tempstr;
|
327
|
595 intptr_t sortcol, sortasds;
|
|
596 int got;
|
37
|
597 gftp_file * fle;
|
1
|
598 time_t curtime;
|
|
599
|
|
600 time (&curtime);
|
|
601 if (!GFTP_IS_CONNECTED (request))
|
|
602 {
|
186
|
603 gftp_text_log (gftp_logging_error, request,
|
1
|
604 _("Error: Not connected to a remote site\n"));
|
|
605 return (1);
|
|
606 }
|
|
607
|
|
608 filespec = *command != '\0' ? command : NULL;
|
|
609 if (gftp_list_files (request) != 0)
|
|
610 return (1);
|
|
611
|
37
|
612 files = NULL;
|
|
613 fle = g_malloc0 (sizeof (*fle));
|
274
|
614 while ((got = gftp_get_next_file (request, NULL, fle)) > 0 ||
|
|
615 got == GFTP_ERETRYABLE)
|
1
|
616 {
|
274
|
617 if (got < 0 || strcmp (fle->file, ".") == 0)
|
1
|
618 {
|
37
|
619 gftp_file_destroy (fle);
|
1
|
620 continue;
|
|
621 }
|
37
|
622 files = g_list_prepend (files, fle);
|
|
623 fle = g_malloc0 (sizeof (*fle));
|
|
624 }
|
|
625 g_free (fle);
|
1
|
626
|
58
|
627 if (files == NULL)
|
207
|
628 {
|
|
629 gftp_end_transfer (request);
|
|
630 return (1);
|
|
631 }
|
58
|
632
|
37
|
633 if (request == gftp_text_locreq)
|
|
634 {
|
122
|
635 gftp_lookup_request_option (request, "local_sortcol", &sortcol);
|
|
636 gftp_lookup_request_option (request, "local_sortasds", &sortasds);
|
37
|
637 }
|
|
638 else
|
|
639 {
|
122
|
640 gftp_lookup_request_option (request, "remote_sortcol", &sortcol);
|
|
641 gftp_lookup_request_option (request, "remote_sortasds", &sortasds);
|
37
|
642 }
|
|
643
|
|
644 files = gftp_sort_filelist (files, sortcol, sortasds);
|
|
645 delitem = NULL;
|
|
646 for (templist = files; templist != NULL; templist = templist->next)
|
|
647 {
|
|
648 if (delitem != NULL)
|
|
649 {
|
|
650 fle = delitem->data;
|
|
651 gftp_file_destroy (fle);
|
|
652 g_free (fle);
|
|
653 delitem = NULL;
|
|
654 }
|
|
655
|
|
656 fle = templist->data;
|
|
657
|
|
658 if (*fle->attribs == 'd')
|
1
|
659 color = COLOR_BLUE;
|
37
|
660 else if (*fle->attribs == 'l')
|
1
|
661 color = COLOR_WHITE;
|
37
|
662 else if (strchr (fle->attribs, 'x') != NULL)
|
1
|
663 color = COLOR_GREEN;
|
|
664 else
|
|
665 color = COLOR_DEFAULT;
|
|
666
|
131
|
667 tempstr = gftp_gen_ls_string (fle, color, COLOR_DEFAULT);
|
|
668 printf ("%s\n", tempstr);
|
|
669 g_free (tempstr);
|
|
670
|
37
|
671 delitem = templist;
|
1
|
672 }
|
207
|
673
|
1
|
674 gftp_end_transfer (request);
|
37
|
675
|
|
676 if (delitem != NULL)
|
|
677 {
|
|
678 fle = delitem->data;
|
|
679 gftp_file_destroy (fle);
|
|
680 g_free (fle);
|
|
681 delitem = NULL;
|
|
682 }
|
|
683
|
|
684 if (files != NULL)
|
|
685 g_list_free (files);
|
|
686
|
1
|
687 return (1);
|
|
688 }
|
|
689
|
|
690
|
|
691 int
|
|
692 gftp_text_binary (gftp_request * request, char *command, gpointer *data)
|
|
693 {
|
|
694 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
|
|
695 {
|
186
|
696 gftp_text_log (gftp_logging_error, request,
|
1
|
697 _("Error: Not connected to a remote site\n"));
|
|
698 return (1);
|
|
699 }
|
|
700
|
122
|
701 gftp_set_request_option (gftp_text_remreq, "ascii_transfers",
|
|
702 GINT_TO_POINTER(0));
|
|
703 gftp_set_request_option (gftp_text_locreq, "ascii_transfers",
|
|
704 GINT_TO_POINTER(0));
|
1
|
705 return (1);
|
|
706 }
|
|
707
|
|
708
|
|
709 int
|
|
710 gftp_text_ascii (gftp_request * request, char *command, gpointer *data)
|
|
711 {
|
|
712 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
|
|
713 {
|
186
|
714 gftp_text_log (gftp_logging_error, request,
|
1
|
715 _("Error: Not connected to a remote site\n"));
|
|
716 return (1);
|
|
717 }
|
|
718
|
122
|
719 gftp_set_request_option (gftp_text_remreq, "ascii_transfers",
|
|
720 GINT_TO_POINTER(1));
|
|
721 gftp_set_request_option (gftp_text_locreq, "ascii_transfers",
|
|
722 GINT_TO_POINTER(1));
|
1
|
723 return (1);
|
|
724 }
|
|
725
|
|
726
|
|
727 int
|
|
728 gftp_text_mget_file (gftp_request * request, char *command, gpointer *data)
|
|
729 {
|
|
730 gftp_transfer * transfer;
|
|
731 gftp_file * fle;
|
|
732
|
|
733 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
|
|
734 {
|
186
|
735 gftp_text_log (gftp_logging_error, request,
|
1
|
736 _("Error: Not connected to a remote site\n"));
|
|
737 return (1);
|
|
738 }
|
|
739
|
|
740 if (*command == '\0')
|
|
741 {
|
186
|
742 gftp_text_log (gftp_logging_error, request,
|
|
743 _("usage: mget <filespec>\n"));
|
1
|
744 return (1);
|
|
745 }
|
|
746
|
129
|
747 transfer = gftp_tdata_new ();
|
1
|
748 transfer->fromreq = gftp_text_remreq;
|
|
749 transfer->toreq = gftp_text_locreq;
|
|
750
|
|
751 /* FIXME - ask whether to resume/skip/overwrite */
|
|
752 if (gftp_list_files (transfer->fromreq) != 0)
|
|
753 {
|
|
754 transfer->fromreq = transfer->toreq = NULL;
|
|
755 free_tdata (transfer);
|
|
756 return (1);
|
|
757 }
|
|
758 fle = g_malloc0 (sizeof (*fle));
|
|
759 while (gftp_get_next_file (transfer->fromreq, command, fle) > 0)
|
|
760 {
|
|
761 if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0)
|
|
762 {
|
|
763 gftp_file_destroy (fle);
|
|
764 continue;
|
|
765 }
|
|
766 transfer->files = g_list_append (transfer->files, fle);
|
|
767 fle = g_malloc (sizeof (*fle));
|
|
768 }
|
|
769 g_free (fle);
|
|
770 gftp_end_transfer (transfer->fromreq);
|
|
771
|
|
772 if (transfer->files == NULL)
|
|
773 {
|
|
774 transfer->fromreq = transfer->toreq = NULL;
|
|
775 free_tdata (transfer);
|
|
776 return (1);
|
|
777 }
|
|
778
|
|
779 if (gftp_get_all_subdirs (transfer, NULL) != 0)
|
|
780 {
|
|
781 transfer->fromreq = transfer->toreq = NULL;
|
|
782 free_tdata (transfer);
|
|
783 return (1);
|
|
784 }
|
|
785
|
|
786 if (transfer->files == NULL)
|
|
787 {
|
|
788 transfer->fromreq = transfer->toreq = NULL;
|
|
789 free_tdata (transfer);
|
|
790 return (1);
|
|
791 }
|
|
792
|
|
793 gftp_text_transfer_files (transfer);
|
|
794 transfer->fromreq = transfer->toreq = NULL;
|
|
795 free_tdata (transfer);
|
|
796 return (1);
|
|
797 }
|
|
798
|
|
799
|
|
800 int
|
|
801 gftp_text_mput_file (gftp_request * request, char *command, gpointer *data)
|
|
802 {
|
|
803 gftp_transfer * transfer;
|
|
804 gftp_file * fle;
|
|
805
|
|
806 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
|
|
807 {
|
186
|
808 gftp_text_log (gftp_logging_error, request,
|
1
|
809 _("Error: Not connected to a remote site\n"));
|
|
810 return (1);
|
|
811 }
|
|
812
|
|
813 if (*command == '\0')
|
|
814 {
|
186
|
815 gftp_text_log (gftp_logging_error, request,
|
|
816 _("usage: mput <filespec>\n"));
|
1
|
817 return (1);
|
|
818 }
|
|
819
|
129
|
820 transfer = gftp_tdata_new ();
|
1
|
821 transfer->fromreq = gftp_text_locreq;
|
|
822 transfer->toreq = gftp_text_remreq;
|
|
823
|
|
824 if (gftp_list_files (transfer->fromreq) != 0)
|
|
825 {
|
|
826 transfer->fromreq = transfer->toreq = NULL;
|
|
827 free_tdata (transfer);
|
|
828 return (1);
|
|
829 }
|
|
830 fle = g_malloc (sizeof (*fle));
|
|
831 while (gftp_get_next_file (transfer->fromreq, command, fle) > 0)
|
|
832 {
|
|
833 if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0)
|
|
834 {
|
|
835 gftp_file_destroy (fle);
|
|
836 continue;
|
|
837 }
|
|
838 transfer->files = g_list_append (transfer->files, fle);
|
|
839 fle = g_malloc (sizeof (*fle));
|
|
840 }
|
|
841 g_free (fle);
|
|
842 gftp_end_transfer (transfer->fromreq);
|
|
843
|
|
844 if (transfer->files == NULL)
|
|
845 {
|
|
846 transfer->fromreq = transfer->toreq = NULL;
|
|
847 free_tdata (transfer);
|
|
848 return (1);
|
|
849 }
|
|
850
|
|
851 if (gftp_get_all_subdirs (transfer, NULL) != 0)
|
|
852 {
|
|
853 transfer->fromreq = transfer->toreq = NULL;
|
|
854 free_tdata (transfer);
|
|
855 return (1);
|
|
856 }
|
|
857
|
|
858 if (transfer->files == NULL)
|
|
859 {
|
|
860 transfer->fromreq = transfer->toreq = NULL;
|
|
861 free_tdata (transfer);
|
|
862 return (1);
|
|
863 }
|
|
864
|
|
865 gftp_text_transfer_files (transfer);
|
|
866 transfer->fromreq = transfer->toreq = NULL;
|
|
867 free_tdata (transfer);
|
|
868 return (1);
|
|
869 }
|
|
870
|
|
871
|
|
872 int
|
|
873 gftp_text_transfer_files (gftp_transfer * transfer)
|
|
874 {
|
327
|
875 int i, j, sw, tot;
|
|
876 intptr_t preserve_permissions;
|
122
|
877 char buf[8192], *progress = "|/-\\";
|
1
|
878 struct timeval updatetime;
|
|
879 long fromsize, total;
|
|
880 gftp_file * curfle;
|
|
881 ssize_t num_read;
|
182
|
882 mode_t mode;
|
|
883
|
|
884 gftp_lookup_request_option (transfer->fromreq, "preserve_permissions",
|
|
885 &preserve_permissions);
|
1
|
886
|
|
887 for (transfer->curfle = transfer->files;
|
|
888 transfer->curfle != NULL;
|
|
889 transfer->curfle = transfer->curfle->next)
|
|
890 {
|
|
891 curfle = transfer->curfle->data;
|
|
892 if (curfle->transfer_action == GFTP_TRANS_ACTION_SKIP)
|
|
893 continue;
|
|
894
|
|
895 if (curfle->isdir && transfer->toreq->mkdir != NULL)
|
|
896 {
|
|
897 transfer->toreq->mkdir (transfer->toreq, curfle->destfile);
|
|
898 continue;
|
|
899 }
|
|
900
|
|
901 transfer->curtrans = curfle->startsize;
|
58
|
902 fromsize = gftp_transfer_file (transfer->fromreq, curfle->file, -1,
|
1
|
903 curfle->startsize, transfer->toreq, curfle->destfile,
|
58
|
904 -1, curfle->startsize);
|
1
|
905 if (fromsize < 0)
|
|
906 return (1);
|
|
907
|
|
908 gettimeofday (&transfer->starttime, NULL);
|
|
909 memcpy (&transfer->lasttime, &transfer->starttime,
|
|
910 sizeof (transfer->lasttime));
|
|
911 memset (&updatetime, 0, sizeof (updatetime));
|
|
912
|
|
913 total = 0;
|
|
914 i = 0;
|
122
|
915 num_read = -1;
|
1
|
916 while (!cancel && (num_read = gftp_get_next_file_chunk (transfer->fromreq,
|
|
917 buf, sizeof (buf))) > 0)
|
|
918 {
|
|
919 printf ("\r%c ", progress[i++]);
|
|
920 fflush (stdout);
|
|
921 if (progress[i] == '\0')
|
|
922 i = 0;
|
|
923
|
|
924 total += num_read;
|
122
|
925 gftp_calc_kbs (transfer, num_read);
|
1
|
926 if (transfer->lasttime.tv_sec - updatetime.tv_sec >= 1 || total >= fromsize)
|
|
927 {
|
|
928 sw = gftp_text_get_win_size () - 20;
|
|
929 tot = (float) total / (float) fromsize * (float) sw;
|
|
930
|
|
931 if (tot > sw)
|
|
932 tot = sw;
|
|
933 printf ("[");
|
|
934 for (j=0; j<tot; j++)
|
|
935 printf ("=");
|
|
936 for (j=0; j<sw-tot; j++)
|
|
937 printf (" ");
|
|
938 printf ("] @ %.2fKB/s", transfer->kbs);
|
|
939 fflush (stdout);
|
|
940 memcpy (&updatetime, &transfer->lasttime, sizeof (updatetime));
|
|
941 }
|
|
942
|
122
|
943 if (gftp_put_next_file_chunk (transfer->toreq, buf, num_read) < 0)
|
1
|
944 {
|
|
945 num_read = -1;
|
|
946 break;
|
|
947 }
|
|
948 }
|
|
949 printf ("\n");
|
|
950
|
|
951 if (num_read < 0)
|
|
952 {
|
186
|
953 gftp_text_log (gftp_logging_misc, transfer->fromreq,
|
1
|
954 _("Could not download %s\n"), curfle->file);
|
|
955 gftp_disconnect (transfer->fromreq);
|
|
956 gftp_disconnect (transfer->toreq);
|
|
957 }
|
|
958 else
|
|
959 {
|
186
|
960 gftp_text_log (gftp_logging_misc, transfer->fromreq,
|
1
|
961 _("Successfully transferred %s\n"), curfle->file);
|
|
962 gftp_end_transfer (transfer->fromreq);
|
|
963 gftp_end_transfer (transfer->toreq);
|
|
964 }
|
|
965
|
182
|
966 if (!curfle->is_fd && preserve_permissions)
|
|
967 {
|
|
968 if (curfle->attribs)
|
|
969 {
|
|
970 mode = gftp_parse_attribs (curfle->attribs);
|
|
971 if (mode != 0)
|
|
972 gftp_chmod (transfer->toreq, curfle->destfile, mode);
|
|
973 }
|
|
974
|
|
975 if (curfle->datetime != 0)
|
|
976 gftp_set_file_time (transfer->toreq, curfle->destfile,
|
|
977 curfle->datetime);
|
|
978 }
|
1
|
979 }
|
|
980 return (1);
|
|
981 }
|
|
982
|
|
983
|
|
984 int
|
|
985 gftp_text_help (gftp_request * request, char *command, gpointer *data)
|
|
986 {
|
37
|
987 int i, j, ele, numrows, numcols = 6, handled;
|
|
988 char *pos;
|
1
|
989
|
|
990 if (command != NULL && *command != '\0')
|
|
991 {
|
37
|
992 for (pos = command; *pos != ' ' && *pos != '\0'; pos++);
|
|
993 if (*pos == ' ')
|
|
994 {
|
|
995 *pos++ = '\0';
|
|
996 if (*pos == '\0')
|
|
997 pos = NULL;
|
|
998 }
|
|
999 else
|
|
1000 pos = NULL;
|
|
1001
|
1
|
1002 for (i=0; gftp_text_methods[i].command != NULL; i++)
|
|
1003 {
|
|
1004 if (strcmp (gftp_text_methods[i].command, command) == 0)
|
|
1005 break;
|
|
1006 }
|
|
1007
|
|
1008 if (gftp_text_methods[i].cmd_description != NULL)
|
37
|
1009 {
|
|
1010 if (pos != NULL && gftp_text_methods[i].subhelp_func != NULL)
|
|
1011 handled = gftp_text_methods[i].subhelp_func (pos);
|
|
1012 else
|
|
1013 handled = 0;
|
|
1014
|
|
1015 if (!handled)
|
|
1016 printf ("%s\n", _(gftp_text_methods[i].cmd_description));
|
|
1017 }
|
1
|
1018 else
|
|
1019 *command = '\0';
|
|
1020 }
|
|
1021
|
|
1022 if (command == NULL || *command == '\0')
|
|
1023 {
|
|
1024 numrows = number_commands / numcols;
|
|
1025 if (number_commands % numcols != 0)
|
|
1026 numrows++;
|
|
1027
|
|
1028 printf (_("Supported commands:\n\n"));
|
|
1029 for (i=0; i<numrows; i++)
|
|
1030 {
|
|
1031 printf (" ");
|
|
1032 for (j=0; j<numcols; j++)
|
|
1033 {
|
|
1034 ele = i + j * numrows;
|
|
1035 if (ele >= number_commands)
|
|
1036 break;
|
|
1037 printf ("%-10s", gftp_text_methods[ele].command);
|
|
1038 }
|
|
1039 printf ("\n");
|
|
1040 }
|
|
1041
|
|
1042 printf ("\n");
|
|
1043 }
|
|
1044 return (1);
|
|
1045 }
|
|
1046
|
|
1047
|
|
1048 int
|
|
1049 gftp_text_set (gftp_request * request, char *command, gpointer *data)
|
|
1050 {
|
227
|
1051 gftp_config_vars * cv, newcv;
|
1
|
1052 char *pos, *backpos;
|
122
|
1053 GList * templist;
|
1
|
1054 int i;
|
|
1055
|
|
1056 if (command == NULL || *command == '\0')
|
|
1057 {
|
122
|
1058 for (templist = gftp_options_list;
|
|
1059 templist != NULL;
|
|
1060 templist = templist->next)
|
1
|
1061 {
|
122
|
1062 cv = templist->data;
|
37
|
1063
|
122
|
1064 for (i=0; cv[i].key != NULL; i++)
|
1
|
1065 {
|
122
|
1066 if (!(cv[i].ports_shown & GFTP_PORT_TEXT))
|
|
1067 continue;
|
|
1068
|
|
1069 if (*cv[i].key == '\0' ||
|
|
1070 gftp_option_types[cv[i].otype].write_function == NULL)
|
|
1071 continue;
|
|
1072
|
|
1073 printf ("%s = ", cv[i].key);
|
|
1074 gftp_option_types[cv[i].otype].write_function (&cv[i], stdout, 0);
|
|
1075 printf ("\n");
|
1
|
1076 }
|
|
1077 }
|
|
1078 }
|
|
1079 else
|
|
1080 {
|
|
1081 if ((pos = strchr (command, '=')) == NULL)
|
|
1082 {
|
186
|
1083 gftp_text_log (gftp_logging_error, request,
|
1
|
1084 _("usage: set [variable = value]\n"));
|
|
1085 return (1);
|
|
1086 }
|
|
1087 *pos = '\0';
|
|
1088
|
|
1089 for (backpos = pos - 1;
|
|
1090 (*backpos == ' ' || *backpos == '\t') && backpos > command;
|
|
1091 backpos--)
|
|
1092 *backpos = '\0';
|
|
1093 for (++pos; *pos == ' ' || *pos == '\t'; pos++);
|
|
1094
|
122
|
1095 if ((cv = g_hash_table_lookup (gftp_global_options_htable, command)) == NULL)
|
1
|
1096 {
|
186
|
1097 gftp_text_log (gftp_logging_error, request,
|
1
|
1098 _("Error: Variable %s is not a valid configuration variable.\n"), command);
|
|
1099 return (1);
|
|
1100 }
|
|
1101
|
122
|
1102 if (!(cv->ports_shown & GFTP_PORT_TEXT))
|
37
|
1103 {
|
186
|
1104 gftp_text_log (gftp_logging_error, request,
|
37
|
1105 _("Error: Variable %s is not available in the text port of gFTP\n"), command);
|
|
1106 return (1);
|
|
1107 }
|
|
1108
|
122
|
1109 if (gftp_option_types[cv->otype].read_function != NULL)
|
227
|
1110 {
|
|
1111 memcpy (&newcv, cv, sizeof (newcv));
|
|
1112 newcv.flags &= ~GFTP_CVARS_FLAGS_DYNMEM;
|
|
1113
|
|
1114 gftp_option_types[cv->otype].read_function (pos, &newcv, 1);
|
|
1115
|
|
1116 gftp_set_global_option (command, newcv.value);
|
|
1117
|
|
1118 if (newcv.flags & GFTP_CVARS_FLAGS_DYNMEM)
|
|
1119 g_free (newcv.value);
|
|
1120 }
|
1
|
1121 }
|
|
1122
|
|
1123 return (1);
|
|
1124 }
|
|
1125
|
|
1126
|
37
|
1127 int
|
|
1128 gftp_text_clear (gftp_request * request, char *command, gpointer *data)
|
|
1129 {
|
|
1130 if (strcasecmp (command, "cache") == 0)
|
|
1131 gftp_clear_cache_files ();
|
|
1132 else
|
186
|
1133 gftp_text_log (gftp_logging_error, request, _("Invalid argument\n"));
|
37
|
1134 return (1);
|
|
1135 }
|
|
1136
|
|
1137
|
1
|
1138 char *
|
|
1139 gftp_text_ask_question (const char *question, int echo, char *buf, size_t size)
|
|
1140 {
|
|
1141 struct termios term, oldterm;
|
|
1142 sigset_t sig, sigsave;
|
|
1143 char *pos, *termname;
|
201
|
1144 FILE *infd;
|
1
|
1145
|
|
1146 if (!echo)
|
|
1147 {
|
|
1148 sigemptyset (&sig);
|
|
1149 sigaddset (&sig, SIGINT);
|
|
1150 sigaddset (&sig, SIGTSTP);
|
|
1151 sigprocmask (SIG_BLOCK, &sig, &sigsave);
|
|
1152
|
|
1153 termname = ctermid (NULL);
|
|
1154 if ((infd = fopen (termname, "r+")) == NULL)
|
|
1155 {
|
|
1156
|
|
1157 gftp_text_log (gftp_logging_error, NULL,
|
186
|
1158 _("Cannot open controlling terminal %s\n"), termname);
|
1
|
1159 return (NULL);
|
|
1160 }
|
|
1161
|
|
1162 tcgetattr (0, &term);
|
|
1163 oldterm = term;
|
|
1164 term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
|
|
1165 tcsetattr (fileno (infd), TCSAFLUSH, &term);
|
|
1166 }
|
|
1167 else
|
201
|
1168 infd = stdin;
|
1
|
1169
|
201
|
1170 printf ("%s%s%s: ", COLOR_BLUE, question, COLOR_DEFAULT);
|
1
|
1171
|
|
1172 if (fgets (buf, size, infd) == NULL)
|
|
1173 return (NULL);
|
|
1174 buf[size - 1] = '\0';
|
|
1175
|
|
1176 if (!echo)
|
|
1177 {
|
201
|
1178 printf ("\n");
|
1
|
1179 tcsetattr (fileno (infd), TCSAFLUSH, &oldterm);
|
201
|
1180 fclose (infd);
|
1
|
1181 sigprocmask (SIG_SETMASK, &sigsave, NULL);
|
|
1182 }
|
|
1183
|
|
1184 for (pos = buf + strlen (buf) - 1; *pos == ' ' || *pos == '\r' ||
|
|
1185 *pos == '\n'; pos--);
|
|
1186 *(pos+1) = '\0';
|
|
1187
|
|
1188 for (pos = buf; *pos == ' '; pos++);
|
|
1189 if (*pos == '\0')
|
|
1190 return (NULL);
|
|
1191
|
|
1192 return (pos);
|
|
1193 }
|
|
1194
|
|
1195
|
|
1196 int
|
|
1197 gftp_text_get_win_size (void)
|
|
1198 {
|
|
1199 struct winsize size;
|
|
1200 int ret;
|
|
1201
|
|
1202 if (ioctl (0, TIOCGWINSZ, (char *) &size) < 0)
|
|
1203 ret = 80;
|
|
1204 else
|
|
1205 ret = size.ws_col;
|
|
1206 return (ret);
|
|
1207 }
|
|
1208
|
|
1209
|
|
1210 void
|
|
1211 sig_child (int signo)
|
|
1212 {
|
|
1213 }
|
|
1214
|
|
1215
|
37
|
1216 int
|
|
1217 gftp_text_set_show_subhelp (char *topic)
|
|
1218 {
|
122
|
1219 gftp_config_vars * cv;
|
37
|
1220
|
122
|
1221 if ((cv = g_hash_table_lookup (gftp_global_options_htable, topic)) != NULL)
|
37
|
1222 {
|
122
|
1223 printf ("%s\n", cv->comment);
|
|
1224 return (1);
|
37
|
1225 }
|
|
1226
|
|
1227 return (0);
|
|
1228 }
|
|
1229
|
|
1230
|
|
1231 int
|
|
1232 gftp_text_clear_show_subhelp (char *topic)
|
|
1233 {
|
|
1234 if (strcmp (topic, "cache") == 0)
|
|
1235 {
|
|
1236 printf (_("Clear the directory cache\n"));
|
|
1237 return (1);
|
|
1238 }
|
|
1239
|
|
1240 return (0);
|
|
1241 }
|
|
1242
|