On Tue, 24 Jul 2007, Matthew Woehlke wrote:
> This rough patch adds a '--ask-password' option to wget. About all that can be
It's a good rule to send patches inlined rather than attached as that
makes them easy to comment on.
> said for it is that it works; hopefully it will serve as a useful proof of
> concept and possible a starting point for a fully-developed feature.
Hmm, what's there to prove? Anyway...
> Index: src/http.c
> ===================================================================
> --- src/http.c (revision 2295)
> +++ src/http.c (working copy)
> @@ -31,6 +31,7 @@
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> +#include <termios.h> /* FIXME probably not portable? */
> #ifdef HAVE_UNISTD_H
> # include <unistd.h>
> #endif
AC_SYS_POSIX_TERMIOS
> @@ -1419,7 +1421,29 @@
> passwd = u->passwd;
> search_netrc (u->host, (const char **)&user, (const char **)&passwd, 0);
> user = user ? user : (opt.http_user ? opt.http_user : opt.user);
> + if (opt.ask_passwd)
> + {
> + int in_fd = fileno(stdin);
Standard input is used for URLs; you probably want to use "stderr" here.
Formatting (ditto all the function calls below).
> + struct termios attr;
> + tcflag_t old_flags;
> + int n;
Formatting.
> + printf("URL \"%s\"\nPassword for user \"%s\": ", u->url, user);
Standard output is used for storing remote files; you definitely want to
use "stderr" here.
> + /* TODO check error */
> + tcgetattr(in_fd, &attr);
isatty() beforehand perhaps?
> + old_flags = attr.c_lflag;
> + attr.c_lflag &= ~ECHO;
> + tcsetattr(in_fd, TCSANOW, &attr);
> + fgets(buffer, sizeof(buffer), stdin);
> + attr.c_lflag = old_flags;
> + tcsetattr(in_fd, TCSANOW, &attr);
> + n = strlen(buffer) - 1;
> + if (n >= 0 && buffer[n] == '\n') buffer[n] = 0;
Formatting.
Otherwise it looks OK, I think. Though I am not sure whether it is
really needed given that many years have passed and nobody wanted such a
feature. But the decision is up to the maintainer (once you sort out
technical problems).
Maciej