Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/ftp new features:



details:   https://anonhg.NetBSD.org/src/rev/9296d82dd1ec
branches:  trunk
changeset: 477604:9296d82dd1ec
user:      lukem <lukem%NetBSD.org@localhost>
date:      Sun Oct 24 12:31:36 1999 +0000

description:
new features:
- add `usage'; displays the usage of a command.
  implemented by calling the c_handler() with argc = 0, argv = "funcname".
- add `passive auto'; does the same as $FTPMODE=auto.
- add `set [option value]'; display all options, or set an option to a value.
- add `unset option'; unset an option.
- add getoptionvalue() to retrieve an option's value, and replace a few
  global variables with calls to this.
- implement cleanuppeer(), which resets various bits of state back to
  `disconnected'. call in disconnect() and lostpeer().
- support completing on `options'.
- improve recovery after a SIGINT may have closed the connection.
  XXX: there's still a couple to fix

other stuff:
- various consistency fixes in the man page.
- ensure that the command usage strings in the code and man page match reality.
- mput/mget: check that the connection still exists before each xfer.
- minor cosmetic changes in confirm().
- set code correctly in sizecmd() and modtime()
- don't need \n in err() strings.
- change lostpeer to take an argument (rather than casting (sig_t)lostpeer
  in signal handlers)
- knf and whitespace police.

diffstat:

 usr.bin/ftp/cmds.c      |  409 +++++++++++++++++++++++++++++++++++------------
 usr.bin/ftp/cmdtab.c    |   29 ++-
 usr.bin/ftp/complete.c  |   55 +++++-
 usr.bin/ftp/domacro.c   |    9 +-
 usr.bin/ftp/extern.h    |   11 +-
 usr.bin/ftp/fetch.c     |   47 ++--
 usr.bin/ftp/ftp.1       |  371 +++++++++++++++++++++++++++---------------
 usr.bin/ftp/ftp.c       |  110 +++++++-----
 usr.bin/ftp/ftp_var.h   |   24 +-
 usr.bin/ftp/main.c      |  190 +++++++++++++---------
 usr.bin/ftp/ruserpass.c |    8 +-
 usr.bin/ftp/util.c      |  129 ++++++++++----
 12 files changed, 931 insertions(+), 461 deletions(-)

diffs (truncated from 3109 to 300 lines):

diff -r 18f9874fd7b2 -r 9296d82dd1ec usr.bin/ftp/cmds.c
--- a/usr.bin/ftp/cmds.c        Sun Oct 24 08:43:59 1999 +0000
+++ b/usr.bin/ftp/cmds.c        Sun Oct 24 12:31:36 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmds.c,v 1.75 1999/10/13 02:47:54 lukem Exp $  */
+/*     $NetBSD: cmds.c,v 1.76 1999/10/24 12:31:36 lukem Exp $  */
 
 /*-
  * Copyright (c) 1996-1999 The NetBSD Foundation, Inc.
@@ -107,7 +107,7 @@
 #if 0
 static char sccsid[] = "@(#)cmds.c     8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: cmds.c,v 1.75 1999/10/13 02:47:54 lukem Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.76 1999/10/24 12:31:36 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -182,13 +182,13 @@
                                break;
                        case 'q':
                                mflag = 0;
-                               fprintf(ttyout, "%s aborted\n", mname);
+                               fprintf(ttyout, "%s aborted.\n", mname);
                                /* FALLTHROUGH */
                        case 'n':
                                return (0);
                        case '?':
                                fprintf(ttyout,
-                                   " confirmation options:\n"
+                                   "  confirmation options:\n"
                                    "\ta  answer `yes' for the duration of %s\n"
                                    "\tn  answer `no' for this file\n"
                                    "\tp  turn off `prompt' mode\n"
@@ -214,7 +214,7 @@
        struct types *p;
        int comret;
 
-       if (argc > 2) {
+       if ((argc == 0 && argv != NULL) || argc > 2) {
                char *sep;
 
                fprintf(ttyout, "usage: %s [", argv[0]);
@@ -300,6 +300,11 @@
        char *argv[];
 {
 
+       if (argc == 0 && argv != NULL) {
+               fprintf(ttyout, "usage: %s\n", argv[0]);
+               code = -1;
+               return;
+       }
        stype[1] = "binary";
        settype(2, stype);
 }
@@ -314,6 +319,11 @@
        char *argv[];
 {
 
+       if (argc == 0 && argv != NULL) {
+               fprintf(ttyout, "usage: %s\n", argv[0]);
+               code = -1;
+               return;
+       }
        stype[1] = "ascii";
        settype(2, stype);
 }
@@ -328,6 +338,11 @@
        char *argv[];
 {
 
+       if (argc == 0 && argv != NULL) {
+               fprintf(ttyout, "usage: %s\n", argv[0]);
+               code = -1;
+               return;
+       }
        stype[1] = "tenex";
        settype(2, stype);
 }
@@ -342,6 +357,11 @@
        char *argv[];
 {
 
+       if ((argc == 0 && argv != NULL) || argc != 2) {
+               fprintf(ttyout, "usage: %s mode-name\n", argv[0]);
+               code = -1;
+               return;
+       }
        fprintf(ttyout, "We only support %s mode, sorry.\n", modename);
        code = -1;
 }
@@ -356,6 +376,11 @@
        char *argv[];
 {
 
+       if ((argc == 0 && argv != NULL) || argc != 2) {
+               fprintf(ttyout, "usage: %s format\n", argv[0]);
+               code = -1;
+               return;
+       }
        fprintf(ttyout, "We only support %s format, sorry.\n", formname);
        code = -1;
 }
@@ -370,6 +395,11 @@
        char *argv[];
 {
 
+       if ((argc == 0 && argv != NULL) || argc != 2) {
+               fprintf(ttyout, "usage: %s struct-mode\n", argv[0]);
+               code = -1;
+               return;
+       }
        fprintf(ttyout, "We only support %s structure, sorry.\n", structname);
        code = -1;
 }
@@ -391,11 +421,12 @@
                argv[2] = argv[1];
                loc++;
        }
-       if (argc < 2 && !another(&argc, &argv, "local-file"))
+       if ((argc == 0 && argv != NULL) ||
+           (argc == 1 && !another(&argc, &argv, "local-file")))
                goto usage;
        if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) {
 usage:
-               fprintf(ttyout, "usage: %s local-file [ remote-file ]\n",
+               fprintf(ttyout, "usage: %s local-file [remote-file]\n",
                    argv[0]);
                code = -1;
                return;
@@ -430,7 +461,8 @@
        int ointer;
        char *tp;
 
-       if (argc < 2 && !another(&argc, &argv, "local-files")) {
+       if ((argc == 0 && argv != NULL) ||
+           (argc == 1 && !another(&argc, &argv, "local-files"))) {
                fprintf(ttyout, "usage: %s local-files\n", argv[0]);
                code = -1;
                return;
@@ -444,7 +476,7 @@
                char *cp;
 
                while ((cp = remglob(argv, 0, NULL)) != NULL) {
-                       if (*cp == '\0') {
+                       if (*cp == '\0' || !connected) {
                                mflag = 0;
                                continue;
                        }
@@ -470,7 +502,7 @@
                }
                goto cleanupmput;
        }
-       for (i = 1; i < argc; i++) {
+       for (i = 1; i < argc && connected; i++) {
                char **cpp;
                glob_t gl;
                int flags;
@@ -500,7 +532,8 @@
                        globfree(&gl);
                        continue;
                }
-               for (cpp = gl.gl_pathv; cpp && *cpp != NULL; cpp++) {
+               for (cpp = gl.gl_pathv; cpp && *cpp != NULL && connected;
+                   cpp++) {
                        if (mflag && confirm(argv[0], *cpp)) {
                                tp = (ntflag) ? dotrans(*cpp) : *cpp;
                                tp = (mapflag) ? domap(tp) : tp;
@@ -560,11 +593,12 @@
                argv[2] = argv[1];
                loc++;
        }
-       if (argc < 2 && !another(&argc, &argv, "remote-file"))
+       if ((argc == 0 && argv != NULL) ||
+           (argc == 1 && !another(&argc, &argv, "remote-file")))
                goto usage;
        if ((argc < 3 && !another(&argc, &argv, "local-file")) || argc > 3) {
 usage:
-               fprintf(ttyout, "usage: %s remote-file [ local-file ]\n",
+               fprintf(ttyout, "usage: %s remote-file [local-file]\n",
                    argv[0]);
                code = -1;
                return (0);
@@ -660,7 +694,8 @@
        int ch, ointer;
        char *cp, *tp, *tp2, tmpbuf[MAXPATHLEN];
 
-       if (argc < 2 && !another(&argc, &argv, "remote-files")) {
+       if ((argc == 0 && argv != NULL) ||
+           (argc == 1 && !another(&argc, &argv, "remote-files"))) {
                fprintf(ttyout, "usage: %s remote-files\n", argv[0]);
                code = -1;
                return;
@@ -671,7 +706,7 @@
        if (sigsetjmp(jabort, 1))
                mabort();
        while ((cp = remglob(argv, proxy, NULL)) != NULL) {
-               if (*cp == '\0') {
+               if (*cp == '\0' || !connected) {
                        mflag = 0;
                        continue;
                }
@@ -724,6 +759,11 @@
 {
        int i;
 
+       if (argc == 0 && argv != NULL) {
+               fprintf(ttyout, "usage: %s\n", argv[0]);
+               code = -1;
+               return;
+       }
        if (connected)
                fprintf(ttyout, "Connected %sto %s.\n",
                    connected == -1 ? "and logged in" : "", hostname);
@@ -742,7 +782,8 @@
        }
        fprintf(ttyout, "Gate ftp: %s, server %s, port %s.\n", onoff(gatemode),
            *gateserver ? gateserver : "(none)", gateport);
-       fprintf(ttyout, "Passive mode: %s.\n", onoff(passivemode));
+       fprintf(ttyout, "Passive mode: %s; fallback to active mode: %s.\n",
+           onoff(passivemode), onoff(activefallback));
        fprintf(ttyout, "Mode: %s; Type: %s; Form: %s; Structure: %s.\n",
            modename, typename, formname, structname);
        fprintf(ttyout, "Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s.\n",
@@ -805,7 +846,7 @@
        int  *var;
        const char *mesg;
 {
-       if (argc < 2) {
+       if (argc == 1) {
                *var = !*var;
        } else if (argc == 2 && strcasecmp(argv[1], "on") == 0) {
                *var = 1;
@@ -844,6 +885,11 @@
 {
 
 #ifdef NO_EDITCOMPLETE
+       if (argc == 0 && argv != NULL) {
+               fprintf(ttyout, "usage: %s\n", argv[0]);
+               code = -1;
+               return;
+       }
        if (verbose)
                fputs("Editing support not compiled in; ignoring command.\n",
                    ttyout);
@@ -973,9 +1019,9 @@
 {
        static char gsbuf[MAXHOSTNAMELEN];
 
-       if (argc > 3) {
+       if ((argc == 0 && argv != NULL) || argc > 3) {
                fprintf(ttyout,
-                   "usage: %s [ on | off | gateserver [ port ] ]\n", argv[0]);
+                   "usage: %s [ on | off | gateserver [port] ]\n", argv[0]);
                code = -1;
                return;
        } else if (argc < 2) {
@@ -1040,7 +1086,7 @@
        int argc;
        char *argv[];
 {
-       if (argc > 2) {
+       if ((argc == 0 && argv != NULL) || argc > 2) {
                fprintf(ttyout, "usage: %s [ on | off | debuglevel ]\n",
                    argv[0]);
                code = -1;
@@ -1082,8 +1128,8 @@
 {
        int r;
 
-       if ((argc < 2 && !another(&argc, &argv, "remote-directory")) ||
-           argc > 2) {
+       if ((argc == 1 && !another(&argc, &argv, "remote-directory")) ||
+           (argc == 0 && argv != NULL) || argc > 2) {
                fprintf(ttyout, "usage: %s remote-directory\n", argv[0]);
                code = -1;
                return;
@@ -1110,28 +1156,25 @@
        char buf[MAXPATHLEN];
        char *locdir;
 
-       if (argc < 2) {
+       code = -1;
+       if (argc == 1) {
                argc++;
                argv[1] = home;
        }
        if (argc != 2) {
-               fprintf(ttyout, "usage: %s local-directory\n", argv[0]);
-               code = -1;
-               return;
-       }
-       if ((locdir = globulize(argv[1])) == NULL) {
-               code = -1;
+               fprintf(ttyout, "usage: %s [local-directory]\n", argv[0]);
                return;
        }
-       if (chdir(locdir) < 0) {
+       if ((locdir = globulize(argv[1])) == NULL)
+               return;



Home | Main Index | Thread Index | Old Index