Re: [ftp] missing new line in debug+verbose mode

2016-12-08 Thread Todd C. Miller
That will add an extra newline in the proxy case where it does:

fprintf(ttyout, "Requesting %s", origline);

...

fprintf(ttyout, " (via %s)\n", proxyurl);

There is actually a newline printed for the non-proxy case but it
happens too late.

We either need to avoid printing a newline in the "Requesting"
message for the proxyurl case or just avoid splitting the message
in the first place, which is what I've done below.

 - todd

Index: usr.bin/ftp/fetch.c
===
RCS file: /cvs/src/usr.bin/ftp/fetch.c,v
retrieving revision 1.150
diff -u -p -u -r1.150 fetch.c
--- usr.bin/ftp/fetch.c 8 Dec 2016 19:31:17 -   1.150
+++ usr.bin/ftp/fetch.c 8 Dec 2016 19:43:25 -
@@ -624,9 +624,6 @@ noslash:
fin = fdopen(s, "r+");
 #endif /* !SMALL */
 
-   if (verbose)
-   fprintf(ttyout, "Requesting %s", origline);
-
/*
 * Construct and send the request. Proxy requests don't want leading /.
 */
@@ -636,8 +633,10 @@ noslash:
 
epath = url_encode(path);
if (proxyurl) {
-   if (verbose)
-   fprintf(ttyout, " (via %s)\n", proxyurl);
+   if (verbose) {
+   fprintf(ttyout, "Requesting %s (via %s)\n",
+   origline, proxyurl);
+   }
/*
 * Host: directive must use the destination host address for
 * the original URI (path).
@@ -653,6 +652,8 @@ noslash:
"Host: %s\r\n%s%s\r\n\r\n",
epath, proxyhost, buf ? buf : "", httpuseragent);
} else {
+   if (verbose)
+   fprintf(ttyout, "Requesting %s\n", origline);
 #ifndef SMALL
if (resume) {
struct stat stbuf;
@@ -712,8 +713,6 @@ noslash:
 #endif /* !SMALL */
ftp_printf(fin, tls, "\r\n%s%s\r\n\r\n",
buf ? buf : "", httpuseragent);
-   if (verbose)
-   fprintf(ttyout, "\n");
}
free(epath);
 



[ftp] missing new line in debug+verbose mode

2016-12-08 Thread Jiri B
See 'GET /url...' location in the output in the first example:

j.

$ ftp -o /dev/null -M -d http://ftp.eu.openbsd.org/pub/OpenBSD/snapshots/amd64/
host ftp.eu.openbsd.org, port (null), path pub/OpenBSD/snapshots/amd64/, save 
as /dev/null, auth (null).
Trying 77.238.36.16...
Requesting http://ftp.eu.openbsd.org/pub/OpenBSD/snapshots/amd64/GET 
/pub/OpenBSD/snapshots/amd64/ HTTP/1.0
Host: ftp.eu.openbsd.org
User-Agent: OpenBSD ftp


received 'HTTP/1.1 200 OK'
received 'Date: Thu, 08 Dec 2016 18:06:35 GMT'
received 'Server: Apache/2.2.22 (Ubuntu)'
received 'Vary: Accept-Encoding'
received 'Content-Length: 6018'
received 'Connection: close'
received 'Content-Type: text/html;charset=UTF-8'
6018 bytes received in 0.01 seconds (670.27 KB/s)

$ ftp -o /dev/null -M -d -V 
http://ftp.eu.openbsd.org/pub/OpenBSD/snapshots/amd64/
host ftp.eu.openbsd.org, port (null), path pub/OpenBSD/snapshots/amd64/, save 
as /dev/null, auth (null).
GET /pub/OpenBSD/snapshots/amd64/ HTTP/1.0
Host: ftp.eu.openbsd.org
User-Agent: OpenBSD ftp


received 'HTTP/1.1 200 OK'
received 'Date: Thu, 08 Dec 2016 18:06:44 GMT'
received 'Server: Apache/2.2.22 (Ubuntu)'
received 'Vary: Accept-Encoding'
received 'Content-Length: 6018'
received 'Connection: close'
received 'Content-Type: text/html;charset=UTF-8'

Index: fetch.c
===
RCS file: /cvs/src/usr.bin/ftp/fetch.c,v
retrieving revision 1.149
diff -u -p -u -p -r1.149 fetch.c
--- fetch.c 20 Aug 2016 20:18:42 -  1.149
+++ fetch.c 8 Dec 2016 18:16:44 -
@@ -625,7 +625,7 @@ noslash:
 #endif /* !SMALL */
 
if (verbose)
-   fprintf(ttyout, "Requesting %s", origline);
+   fprintf(ttyout, "Requesting %s\n", origline);
 
/*
 * Construct and send the request. Proxy requests don't want leading /.


$ /home/jirib/cvs/openbsd-src/usr.bin/ftp/obj/ftp -o /dev/null -M -d 
http://ftp.eu.openbsd.org/pub/OpenBSD/snapshots/amd64/
host ftp.eu.openbsd.org, port (null), path pub/OpenBSD/snapshots/amd64/, save 
as /dev/null, auth (null).
Trying 77.238.36.56...
Requesting http://ftp.eu.openbsd.org/pub/OpenBSD/snapshots/amd64/
GET /pub/OpenBSD/snapshots/amd64/ HTTP/1.0
Host: ftp.eu.openbsd.org
User-Agent: OpenBSD ftp


received 'HTTP/1.1 200 OK'
received 'Date: Thu, 08 Dec 2016 18:10:51 GMT'
received 'Server: Apache/2.2.22 (Ubuntu)'
received 'Vary: Accept-Encoding'
received 'Content-Length: 6018'
received 'Connection: close'
received 'Content-Type: text/html;charset=UTF-8'
6018 bytes received in 0.00 seconds (49.48 MB/s)

And comparison with curl:

$ curl -i -v -o /dev/null -s 
http://ftp.eu.openbsd.org/pub/OpenBSD/snapshots/amd64/  

*   Trying 77.238.36.56...
* TCP_NODELAY set
* Connected to ftp.eu.openbsd.org (77.238.36.56) port 80 (#0)
> GET /pub/OpenBSD/snapshots/amd64/ HTTP/1.1
> Host: ftp.eu.openbsd.org
> User-Agent: curl/7.51.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Thu, 08 Dec 2016 18:25:18 GMT
< Server: Apache/2.2.22 (Ubuntu)
< Vary: Accept-Encoding
< Content-Length: 6018
< Content-Type: text/html;charset=UTF-8
<
{ [2724 bytes data]
* Curl_http_done: called premature == 0
* Connection #0 to host ftp.eu.openbsd.org left intact