Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/ftp [fear this; more ftp hacking from lukem :-]



details:   https://anonhg.NetBSD.org/src/rev/5fc26b79b1b6
branches:  trunk
changeset: 474141:5fc26b79b1b6
user:      lukem <lukem%NetBSD.org@localhost>
date:      Tue Jun 29 10:43:16 1999 +0000

description:
[fear this; more ftp hacking from lukem :-]

features:
---------
* transfer rate throttling with the new `rate' command. syntax:
        rate direction [max [incr]]
  where direction is `all', `get' or `put'.
  if max is not supplied, the current settings are displayed.
  if max is supplied, then transfers in the given direction will
  be throttled to this value.
  if incr is supplied, the increment for the `on-the-fly' scaling
  will be set to that, otherwise `1024' is used.
  currently implemented for binary get, binary put, and url fetches.
  not yet supported for ascii get or put, or local file copies.
* on-the-fly scaling of the throttle based on signals:
    - SIGUSR1 raises the throttle rate by the increment for that direction
    - SIGUSR2 lowers the throttle rate by the increment for that direction
* -T dir,max[,incr] option to set rate from the command line
* `k', `m', `g' suffix support for bytecounts in the `hash', `rate',
  `rcvbuf' and `sndbuf' commands)

bug fixes and code mods:
------------------------
* fix up ftp_login() so that ruserpass() is always called, even for
  command-line url fetches.
* implement strsuftoi(), which parses a given number into a int with
  suffix support. replaces getsockbufsize()
* implement parserate(), which does the argv parsing for -T and rate
* save and restore errno in signal handlers (may not be necessary, but
  it doesn't hurt)

notes:
------
the rate command has had reasonable testing, but I'd like feedback
if it doesn't do the right thing, especially from people on slower
(i.e, modem) links.
I haven't tested the rate throttle against a http server which does
`transfer-encoding: chunked' because I couldn't find a server to
test against.

diffstat:

 usr.bin/ftp/cmds.c    |  111 +++++++++++++++++++++++++++++++++++++++++++-----
 usr.bin/ftp/cmdtab.c  |    7 ++-
 usr.bin/ftp/extern.h  |    7 ++-
 usr.bin/ftp/fetch.c   |   53 ++++++++++++++++++----
 usr.bin/ftp/ftp.1     |  115 +++++++++++++++++++++++++++++++++++++++++++++++--
 usr.bin/ftp/ftp.c     |  108 +++++++++++++++++++++++++++++++++++-----------
 usr.bin/ftp/ftp_var.h |    9 +++-
 usr.bin/ftp/main.c    |   48 ++++++++++++++++---
 usr.bin/ftp/util.c    |   81 ++++++++++++++++++++++++++--------
 9 files changed, 451 insertions(+), 88 deletions(-)

diffs (truncated from 984 to 300 lines):

diff -r 70ec4badb2b4 -r 5fc26b79b1b6 usr.bin/ftp/cmds.c
--- a/usr.bin/ftp/cmds.c        Tue Jun 29 07:44:21 1999 +0000
+++ b/usr.bin/ftp/cmds.c        Tue Jun 29 10:43:16 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmds.c,v 1.51 1999/06/20 22:07:28 cgd Exp $    */
+/*     $NetBSD: cmds.c,v 1.52 1999/06/29 10:43:16 lukem Exp $  */
 
 /*-
  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
 #if 0
 static char sccsid[] = "@(#)cmds.c     8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: cmds.c,v 1.51 1999/06/20 22:07:28 cgd Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.52 1999/06/29 10:43:16 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -727,6 +727,12 @@
        fprintf(ttyout,
            "Hash mark printing: %s; Mark count: %d; Progress bar: %s.\n",
            onoff(hash), mark, onoff(progress));
+       fprintf(ttyout,
+           "Get transfer rate throttle: %s; maximum: %d; increment %d.\n",
+           onoff(rate_get), rate_get, rate_get_incr);
+       fprintf(ttyout,
+           "Put transfer rate throttle: %s; maximum: %d; increment %d.\n",
+           onoff(rate_put), rate_put, rate_put_incr);
        fprintf(ttyout, "Use of PORT cmds: %s.\n", onoff(sendport));
 #ifndef NO_EDITCOMPLETE
        fprintf(ttyout, "Command line editing: %s.\n", onoff(editing));
@@ -829,10 +835,9 @@
                hash = 0;
        else {
                int nmark;
-               char *ep;
 
-               nmark = strtol(argv[1], &ep, 10);
-               if (nmark < 1 || *ep != '\0') {
+               nmark = strsuftoi(argv[1]);
+               if (nmark < 1) {
                        fprintf(ttyout, "mark: bad bytecount value `%s'.\n",
                            argv[1]);
                        code = -1;
@@ -1007,17 +1012,16 @@
                else if (strcasecmp(argv[1], "off") == 0)
                        debug = 0;
                else {
-                       char *ep;
-                       long val;
+                       int val;
 
-                       val = strtol(argv[1], &ep, 10);
-                       if (val < 0 || val > INT_MAX || *ep != '\0') {
+                       val = strsuftoi(argv[1]);
+                       if (val < 0) {
                                fprintf(ttyout, "%s: bad debugging value.\n",
                                    argv[1]);
                                code = -1;
                                return;
                        }
-                       debug = (int)val;
+                       debug = val;
                }
        } else
                debug = !debug;
@@ -2039,6 +2043,89 @@
        code = togglevar(argc, argv, &runique, "Receive unique");
 }
 
+int
+parserate(argc, argv, cmdlineopt)
+       int argc;
+       char *argv[];
+       int cmdlineopt;
+{
+       int dir, max, incr, showonly;
+       sig_t oldusr1, oldusr2;
+
+       if (argc > 4 || (argc < (cmdlineopt ? 3 : 2))) {
+usage:
+               if (cmdlineopt)
+                       fprintf(ttyout,
+                           "usage: %s (all|get|put),maximum[,increment]]\n",
+                           argv[0]);
+               else
+                       fprintf(ttyout,
+                           "usage: %s (all|get|put) [maximum [increment]]\n",
+                           argv[0]);
+               return -1;
+       }
+       dir = max = incr = showonly = 0;
+#define RATE_GET       1
+#define RATE_PUT       2
+#define RATE_ALL       (RATE_GET | RATE_PUT)
+
+       if (strcasecmp(argv[1], "all") == 0)
+               dir = RATE_ALL;
+       else if (strcasecmp(argv[1], "get") == 0)
+               dir = RATE_GET;
+       else if (strcasecmp(argv[1], "put") == 0)
+               dir = RATE_PUT;
+       else
+               goto usage;
+
+       if (argc >= 3) {
+               if ((max = strsuftoi(argv[2])) < 0)
+                       goto usage;
+       } else
+               showonly = 1;
+
+       if (argc == 4) {
+               if ((incr = strsuftoi(argv[3])) <= 0)
+                       goto usage;
+       } else
+               incr = DEFAULTINCR;
+
+       oldusr1 = signal(SIGUSR1, SIG_IGN);
+       oldusr2 = signal(SIGUSR2, SIG_IGN);
+       if (dir & RATE_GET) {
+               if (!showonly) {
+                       rate_get = max;
+                       rate_get_incr = incr;
+               }
+               if (!cmdlineopt || verbose)
+                       fprintf(ttyout,
+                   "Get xfer rate throttle: %s; maximum: %d; increment %d.\n",
+                           onoff(rate_get), rate_get, rate_get_incr);
+       }
+       if (dir & RATE_PUT) {
+               if (!showonly) {
+                       rate_put = max;
+                       rate_put_incr = incr;
+               }
+               if (!cmdlineopt || verbose)
+                       fprintf(ttyout,
+                   "Put xfer rate throttle: %s; maximum: %d; increment %d.\n",
+                           onoff(rate_put), rate_put, rate_put_incr);
+       }
+       (void)signal(SIGUSR1, oldusr1);
+       (void)signal(SIGUSR2, oldusr2);
+       return 0;
+}
+
+void
+setrate(argc, argv)
+       int argc;
+       char *argv[];
+{
+
+       code = parserate(argc, argv, 0);
+}
+
 /* change directory to parent directory */
 void
 cdup(argc, argv)
@@ -2311,7 +2398,7 @@
                return;
        }
 
-       if ((size = getsockbufsize(argv[1])) == -1) {
+       if ((size = strsuftoi(argv[1])) == -1) {
                printf("invalid socket buffer size: %s\n", argv[1]);
                code = -1;
                return;
@@ -2340,7 +2427,7 @@
                return;
        }
 
-       if ((size = getsockbufsize(argv[1])) == -1) {
+       if ((size = strsuftoi(argv[1])) == -1) {
                printf("invalid socket buffer size: %s\n", argv[1]);
                code = -1;
                return;
diff -r 70ec4badb2b4 -r 5fc26b79b1b6 usr.bin/ftp/cmdtab.c
--- a/usr.bin/ftp/cmdtab.c      Tue Jun 29 07:44:21 1999 +0000
+++ b/usr.bin/ftp/cmdtab.c      Tue Jun 29 10:43:16 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmdtab.c,v 1.22 1999/06/24 14:54:28 christos Exp $     */
+/*     $NetBSD: cmdtab.c,v 1.23 1999/06/29 10:43:17 lukem Exp $        */
 
 /*
  * Copyright (c) 1985, 1989, 1993, 1994
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)cmdtab.c   8.4 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: cmdtab.c,v 1.22 1999/06/24 14:54:28 christos Exp $");
+__RCSID("$NetBSD: cmdtab.c,v 1.23 1999/06/29 10:43:17 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -102,6 +102,7 @@
 char   pwdhelp[] =     "print working directory on remote machine";
 char   quithelp[] =    "terminate ftp session and exit";
 char   quotehelp[] =   "send arbitrary ftp command";
+char   ratehelp[] =    "set transfer rate limit";
 char   rcvbufhelp[] =  "set socket receive buffer size";
 char   receivehelp[] = "receive file";
 char   regethelp[] =   "get file restarting at end of local file";
@@ -200,6 +201,7 @@
        { "pwd",        pwdhelp,        0, 1, 1, CMPL0          pwd },
        { "quit",       quithelp,       0, 0, 0, CMPL0          quit },
        { "quote",      quotehelp,      1, 1, 1, CMPL0          quote },
+       { "rate",       ratehelp,       0, 0, 0, CMPL0          setrate },
        { "rcvbuf",     rcvbufhelp,     0, 0, 0, CMPL0          rcvbuf },
        { "recv",       receivehelp,    1, 1, 1, CMPL(rl)       get },
        { "reget",      regethelp,      1, 1, 1, CMPL(rl)       reget },
@@ -220,6 +222,7 @@
        { "sunique",    suniquehelp,    0, 0, 1, CMPL0          setsunique },
        { "system",     systemhelp,     0, 1, 1, CMPL0          syst },
        { "tenex",      tenexhelp,      0, 1, 1, CMPL0          settenex },
+       { "throttle",   ratehelp,       0, 0, 0, CMPL0          setrate },
        { "trace",      tracehelp,      0, 0, 0, CMPL0          settrace },
        { "type",       typehelp,       0, 1, 1, CMPL0          settype },
        { "umask",      umaskhelp,      0, 1, 1, CMPL0          do_umask },
diff -r 70ec4badb2b4 -r 5fc26b79b1b6 usr.bin/ftp/extern.h
--- a/usr.bin/ftp/extern.h      Tue Jun 29 07:44:21 1999 +0000
+++ b/usr.bin/ftp/extern.h      Tue Jun 29 10:43:16 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.30 1999/06/24 14:46:59 christos Exp $     */
+/*     $NetBSD: extern.h,v 1.31 1999/06/29 10:43:17 lukem Exp $        */
 
 /*-
  * Copyright (c) 1994 The Regents of the University of California.
@@ -52,6 +52,7 @@
 void   changetype __P((int, int));
 void   cmdabort __P((int));
 void   cmdscanner __P((int));
+void   crankrate __P((int));
 int    command __P((const char *, ...));
 #ifndef NO_EDITCOMPLETE
 unsigned char complete __P((EditLine *, int));
@@ -74,7 +75,6 @@
 struct cmd *getcmd __P((const char *));
 int    getit __P((int, char **, int, const char *));
 int    getreply __P((int));
-int    getsockbufsize __P((const char *));
 int    globulize __P((char **));
 char   *gunique __P((const char *));
 void   help __P((int, char **));
@@ -100,6 +100,7 @@
 char   *onoff __P((int));
 void   newer __P((int, char **));
 void   page __P((int, char **));
+int    parserate __P((int, char **, int));
 void    progressmeter __P((int));
 char   *prompt __P((void));
 void   proxabort __P((int));
@@ -150,6 +151,7 @@
 void   setpreserve __P((int, char **));
 void   setprogress __P((int, char **));
 void   setprompt __P((int, char **));
+void   setrate __P((int, char **));
 void   setrunique __P((int, char **));
 void   setstruct __P((int, char **));
 void   setsunique __P((int, char **));
@@ -165,6 +167,7 @@
 char   *slurpstring __P((void));
 void   sndbuf __P((int, char **));
 void   status __P((int, char **));
+int    strsuftoi __P((const char *));
 void   syst __P((int, char **));
 int    togglevar __P((int, char **, int *, const char *));
 void   usage __P((void));
diff -r 70ec4badb2b4 -r 5fc26b79b1b6 usr.bin/ftp/fetch.c
--- a/usr.bin/ftp/fetch.c       Tue Jun 29 07:44:21 1999 +0000
+++ b/usr.bin/ftp/fetch.c       Tue Jun 29 10:43:16 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fetch.c,v 1.58 1999/06/27 01:17:19 lukem Exp $ */
+/*     $NetBSD: fetch.c,v 1.59 1999/06/29 10:43:17 lukem Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.58 1999/06/27 01:17:19 lukem Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.59 1999/06/29 10:43:17 lukem Exp $");
 #endif /* not lint */
 
 /*
@@ -947,17 +947,37 @@
                                goto cleanup_fetch_url;
                        }
                        if (debug)
-                               fprintf(ttyout, "got chunksize of %qd\n",
+                               fprintf(ttyout,
+#ifndef NO_QUAD
+                                   "got chunksize of %qd\n",
                                    (long long)chunksize);
+#else
+                                   "got chunksize of %ld\n",
+                                   (long)chunksize);
+#endif
                        if (chunksize == 0)
                                break;
                }
-               while ((len = fread(buf, sizeof(char),



Home | Main Index | Thread Index | Old Index