bug-inetutils
[Top][All Lists]
Advanced

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

Re: [bug-inetutils] ftp open without args


From: Debarshi 'Rishi' Ray
Subject: Re: [bug-inetutils] ftp open without args
Date: Sun, 12 Aug 2007 02:02:20 +0530

> By the way, we previously discussed making "open" without any args
> attempt to reopen the host from the command line (or previous open).  Is
> this still pending?

Not any more.

Here (attached as ftp-open.diff and inline) is a patch to fix this
issue. However you need to apply the ftp-cmd.diff (read below) before
applying this one.

diff -urNp inetutils/ftp/cmds.c inetutils-build/ftp/cmds.c
--- inetutils/ftp/cmds.c        2007-08-12 07:18:01.000000000 +0530
+++ inetutils-build/ftp/cmds.c  2007-08-12 07:08:02.000000000 +0530
@@ -214,7 +214,7 @@ setpeer (argc, argv)
      int argc;
      char *argv[];
 {
-  char *host;
+  char *host = NULL;
   int port;

   if (connected && command ("NOOP") != COMPLETE)
@@ -225,16 +225,28 @@ setpeer (argc, argv)
       code = -1;
       return;
     }
+
   if (argc < 2)
-    another (&argc, &argv, "(to) ");
+    {
+      if (hostname)
+       {
+          host = hostname;
+          argc = 2;
+        }
+      else
+        another (&argc, &argv, "(to) ");
+    }
   if (argc < 2 || argc > 3)
     {
       printf ("usage: %s host-name [port]\n", argv[0]);
       code = -1;
       return;
     }
-  port = sp->s_port;
-  if (argc > 2)
+
+  if (!host)
+    host = argv[1];
+
+  if (argc == 3)
     {
       port = atoi (argv[2]);
       if (port <= 0 || port > 65535)
@@ -246,7 +258,10 @@ setpeer (argc, argv)
        }
       port = htons (port);
     }
-  host = hookup (argv[1], port);
+  else
+    port = sp->s_port;
+
+  host = hookup (host, port);
   if (host)
     {
       int overbose;
@@ -262,7 +277,7 @@ setpeer (argc, argv)
       strcpy (structname, "file"), stru = STRU_F;
       strcpy (bytename, "8"), bytesize = 8;
       if (autologin)
-       login (argv[1]);
+       login (host);

 #if defined(unix) && NBBY == 8
 /*

> ftp> open
> sorry, arguments too long

This was due to a bug in the command line processing in cases where
readline was being used, as I had brought up in another thread. Just
for the sake of completeness, I am repeating the patch here (attached
as ftp-cmd.diff and inline).

diff -urNp inetutils/ftp/cmds.c inetutils-build/ftp/cmds.c
--- inetutils/ftp/cmds.c        2007-07-21 18:35:51.000000000 +0530
+++ inetutils-build/ftp/cmds.c  2007-08-12 05:51:35.000000000 +0530
@@ -134,22 +134,70 @@ int
 another (pargc, pargv, prompt)
      int *pargc;
      char ***pargv;
-     char *prompt;
+     const char *prompt;
 {
   int len = strlen (line), ret;

+#if HAVE_LIBREADLINE
+  char *arg;
+
+  arg = readline (prompt);
+  if (arg && *arg)
+    add_history (arg);
+  else if (!arg)
+    {
+      putchar ('\n');
+      return 0;
+    }
+  else
+    {
+      free (arg);
+      return 0;
+    }
+
+  line = realloc (line, len + strlen (arg) + 2);
+  if (!line)
+    {
+      free (arg);
+      intr ();
+    }
+
+  line[len++] = ' ';
+  strcpy (&line[len], arg);
+  free (arg);
+#else
+  char *status;
+  int num;
+
   if (len >= sizeof (line) - 3)
     {
-      printf ("sorry, arguments too long\n");
+      printf ("Sorry, arguments too long.\n");
       intr ();
     }
-  printf ("(%s) ", prompt);
+
+  printf ("%s", prompt);
   line[len++] = ' ';
-  if (fgets (&line[len], sizeof (line) - len, stdin) == NULL)
+  status = fgets (&line[len], sizeof (line) - len, stdin);
+  num = strlen (&line[len]);
+  if (num == 0)
+    {
+      putchar ('\n');
+      return 0;
+    }
+  else if (status == NULL)
     intr ();
+
   len += strlen (&line[len]);
-  if (len > 0 && line[len - 1] == '\n')
-    line[len - 1] = '\0';
+  if (line[--len] == '\n')
+    line[len] = '\0';
+  else if (len == sizeof (line) - 2)
+    {
+      printf ("Sorry, input line too long.\n");
+      while ((len = getchar ()) != '\n' && len != EOF)
+        /* void */ ;
+      intr ();
+    }
+#endif
   makeargv ();
   ret = margc > *pargc;
   *pargc = margc;
@@ -178,7 +226,7 @@ setpeer (argc, argv)
       return;
     }
   if (argc < 2)
-    another (&argc, &argv, "to");
+    another (&argc, &argv, "(to) ");
   if (argc < 2 || argc > 3)
     {
       printf ("usage: %s host-name [port]\n", argv[0]);
@@ -478,9 +526,9 @@ put (argc, argv)
       argv[2] = argv[1];
       loc++;
     }
-  if (argc < 2 && !another (&argc, &argv, "local-file"))
+  if (argc < 2 && !another (&argc, &argv, "(local-file) "))
     goto usage;
-  if (argc < 3 && !another (&argc, &argv, "remote-file"))
+  if (argc < 3 && !another (&argc, &argv, "(remote-file) "))
     {
     usage:
       printf ("usage: %s local-file remote-file\n", argv[0]);
@@ -535,7 +583,7 @@ mput (argc, argv)
   sig_t oldintr;
   int ointer;

-  if (argc < 2 && !another (&argc, &argv, "local-files"))
+  if (argc < 2 && !another (&argc, &argv, "(local-files) "))
     {
       printf ("usage: %s local-files\n", argv[0]);
       code = -1;
@@ -727,9 +775,9 @@ getit (argc, argv, restartit, mode)
       argv[2] = argv[1];
       loc++;
     }
-  if (argc < 2 && !another (&argc, &argv, "remote-file"))
+  if (argc < 2 && !another (&argc, &argv, "(remote-file) "))
     goto usage;
-  if (argc < 3 && !another (&argc, &argv, "local-file"))
+  if (argc < 3 && !another (&argc, &argv, "(local-file) "))
     {
     usage:
       printf ("usage: %s remote-file [ local-file ]\n", argv[0]);
@@ -862,7 +910,7 @@ mget (argc, argv)
   int ch, ointer;
   char *cp, *tp, *tp2;

-  if (argc < 2 && !another (&argc, &argv, "remote-files"))
+  if (argc < 2 && !another (&argc, &argv, "(remote-files) "))
     {
       printf ("usage: %s remote-files\n", argv[0]);
       code = -1;
@@ -1251,7 +1299,7 @@ cd (argc, argv)
      char *argv[];
 {

-  if (argc < 2 && !another (&argc, &argv, "remote-directory"))
+  if (argc < 2 && !another (&argc, &argv, "(remote-directory) "))
     {
       printf ("usage: %s remote-directory\n", argv[0]);
       code = -1;
@@ -1323,7 +1371,7 @@ delete (argc, argv)
      char *argv[];
 {

-  if (argc < 2 && !another (&argc, &argv, "remote-file"))
+  if (argc < 2 && !another (&argc, &argv, "(remote-file) "))
     {
       printf ("usage: %s remote-file\n", argv[0]);
       code = -1;
@@ -1344,7 +1392,7 @@ mdelete (argc, argv)
   int ointer;
   char *cp;

-  if (argc < 2 && !another (&argc, &argv, "remote-files"))
+  if (argc < 2 && !another (&argc, &argv, "(remote-files) "))
     {
       printf ("usage: %s remote-files\n", argv[0]);
       code = -1;
@@ -1390,9 +1438,9 @@ renamefile (argc, argv)
      char *argv[];
 {

-  if (argc < 2 && !another (&argc, &argv, "from-name"))
+  if (argc < 2 && !another (&argc, &argv, "(from-name) "))
     goto usage;
-  if (argc < 3 && !another (&argc, &argv, "to-name"))
+  if (argc < 3 && !another (&argc, &argv, "(to-name) "))
     {
     usage:
       printf ("%s from-name to-name\n", argv[0]);
@@ -1462,9 +1510,9 @@ mls (argc, argv)
   int ointer, i;
   char *cmd, mode[1], *dest;

-  if (argc < 2 && !another (&argc, &argv, "remote-files"))
+  if (argc < 2 && !another (&argc, &argv, "(remote-files) "))
     goto usage;
-  if (argc < 3 && !another (&argc, &argv, "local-file"))
+  if (argc < 3 && !another (&argc, &argv, "(local-file) "))
     {
     usage:
       printf ("usage: %s remote-files local-file\n", argv[0]);
@@ -1593,7 +1641,7 @@ user (argc, argv)
   int n, aflag = 0;

   if (argc < 2)
-    another (&argc, &argv, "username");
+    another (&argc, &argv, "(username) ");
   if (argc < 2 || argc > 4)
     {
       printf ("usage: %s username [password] [account]\n", argv[0]);
@@ -1663,7 +1711,7 @@ makedir (argc, argv)
      char *argv[];
 {

-  if (argc < 2 && !another (&argc, &argv, "directory-name"))
+  if (argc < 2 && !another (&argc, &argv, "(directory-name) "))
     {
       printf ("usage: %s directory-name\n", argv[0]);
       code = -1;
@@ -1686,7 +1734,7 @@ removedir (argc, argv)
      char *argv[];
 {

-  if (argc < 2 && !another (&argc, &argv, "directory-name"))
+  if (argc < 2 && !another (&argc, &argv, "(directory-name) "))
     {
       printf ("usage: %s directory-name\n", argv[0]);
       code = -1;
@@ -1709,7 +1757,7 @@ quote (argc, argv)
      char *argv[];
 {

-  if (argc < 2 && !another (&argc, &argv, "command line to send"))
+  if (argc < 2 && !another (&argc, &argv, "(command line to send) "))
     {
       printf ("usage: %s line-to-send\n", argv[0]);
       code = -1;
@@ -1729,7 +1777,7 @@ site (argc, argv)
      char *argv[];
 {

-  if (argc < 2 && !another (&argc, &argv, "arguments to SITE command"))
+  if (argc < 2 && !another (&argc, &argv, "(arguments to SITE command) "))
     {
       printf ("usage: %s line-to-send\n", argv[0]);
       code = -1;
@@ -1775,9 +1823,9 @@ do_chmod (argc, argv)
      char *argv[];
 {

-  if (argc < 2 && !another (&argc, &argv, "mode"))
+  if (argc < 2 && !another (&argc, &argv, "(mode) "))
     goto usage;
-  if (argc < 3 && !another (&argc, &argv, "file-name"))
+  if (argc < 3 && !another (&argc, &argv, "(file-name) "))
     {
     usage:
       printf ("usage: %s mode file-name\n", argv[0]);
@@ -1987,7 +2035,7 @@ doproxy (argc, argv)
   struct cmd *c;
   sig_t oldintr;

-  if (argc < 2 && !another (&argc, &argv, "command"))
+  if (argc < 2 && !another (&argc, &argv, "(command) "))
     {
       printf ("usage: %s command\n", argv[0]);
       code = -1;
@@ -2150,7 +2198,7 @@ setnmap (argc, argv)
       code = mapflag;
       return;
     }
-  if (argc < 3 && !another (&argc, &argv, "mapout"))
+  if (argc < 3 && !another (&argc, &argv, "(mapout) "))
     {
       printf ("Usage: %s [mapin mapout]\n", argv[0]);
       code = -1;
@@ -2447,7 +2495,7 @@ macdef (argc, argv)
       code = -1;
       return;
     }
-  if (argc < 2 && !another (&argc, &argv, "macro name"))
+  if (argc < 2 && !another (&argc, &argv, "(macro name) "))
     {
       printf ("Usage: %s macro_name\n", argv[0]);
       code = -1;
@@ -2515,7 +2563,7 @@ sizecmd (argc, argv)
      char *argv[];
 {

-  if (argc < 2 && !another (&argc, &argv, "filename"))
+  if (argc < 2 && !another (&argc, &argv, "(filename) "))
     {
       printf ("usage: %s filename\n", argv[0]);
       code = -1;
@@ -2534,7 +2582,7 @@ modtime (argc, argv)
 {
   int overbose;

-  if (argc < 2 && !another (&argc, &argv, "filename"))
+  if (argc < 2 && !another (&argc, &argv, "(filename) "))
     {
       printf ("usage: %s filename\n", argv[0]);
       code = -1;
diff -urNp inetutils/ftp/domacro.c inetutils-build/ftp/domacro.c
--- inetutils/ftp/domacro.c     2006-10-21 23:38:45.000000000 +0530
+++ inetutils-build/ftp/domacro.c       2007-08-11 16:30:15.000000000 +0530
@@ -45,7 +45,7 @@ domacro (int argc, char *argv[])
   char *cp1, *cp2, line2[200];
   struct cmd *c;

-  if (argc < 2 && !another (&argc, &argv, "macro name"))
+  if (argc < 2 && !another (&argc, &argv, "(macro name) "))
     {
       printf ("Usage: %s macro_name.\n", argv[0]);
       code = -1;
diff -urNp inetutils/ftp/extern.h inetutils-build/ftp/extern.h
--- inetutils/ftp/extern.h      2006-10-21 20:54:21.000000000 +0530
+++ inetutils-build/ftp/extern.h        2007-08-11 07:52:43.000000000 +0530
@@ -37,7 +37,7 @@ void abortpt ();
 void abortrecv ();
 void abortsend ();
 void account (int, char **);
-int another (int *, char ***, char *);
+int another (int *, char ***, const char *);
 void blkfree (char **);
 void cd (int, char **);
 void cdup (int, char **);
diff -urNp inetutils/ftp/main.c inetutils-build/ftp/main.c
--- inetutils/ftp/main.c        2007-07-21 18:35:51.000000000 +0530
+++ inetutils-build/ftp/main.c  2007-08-11 07:51:03.000000000 +0530
@@ -287,7 +287,7 @@ cmdscanner (int top)
       if (line)
        {
          free (line);
-         line = 0;
+         line = NULL;
        }
       line = readline (prompt);
       if (!line)
@@ -309,7 +309,7 @@ cmdscanner (int top)
          fflush (stdout);
        }

-      if (fgets (line, sizeof line, stdin) == NULL)
+      if (fgets (line, sizeof (line), stdin) == NULL)
        quit (0, 0);
       l = strlen (line);
       if (l == 0)
@@ -322,7 +322,7 @@ cmdscanner (int top)
        }
       else if (l == sizeof (line) - 2)
        {
-         printf ("sorry, input line too long\n");
+         printf ("Sorry, input line too long.\n");
          while ((l = getchar ()) != '\n' && l != EOF)
            /* void */ ;
          break;

Comments?

Happy hacking,
Debarshi
-- 
GPG key ID: 63D4A5A7
Key server: pgp.mit.edu

Attachment: ftp-open.diff
Description: Text Data

Attachment: ftp-cmd.diff
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]