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