summaryrefslogtreecommitdiffstats
path: root/usr.bin/ftp/fetch.c
diff options
context:
space:
mode:
authoralex <alex@FreeBSD.org>2001-08-30 02:30:33 +0000
committeralex <alex@FreeBSD.org>2001-08-30 02:30:33 +0000
commit30bc91ada7d358a229e6c23987d421e53d3bd2b1 (patch)
tree586c0f8b981f521fbf2574e032f0dc9d1591cb45 /usr.bin/ftp/fetch.c
parentb4c97b92690a22af4509abe0deac1b4a4e3e6330 (diff)
downloadFreeBSD-src-30bc91ada7d358a229e6c23987d421e53d3bd2b1.zip
FreeBSD-src-30bc91ada7d358a229e6c23987d421e53d3bd2b1.tar.gz
Add support for proper URI encoding, using strvisx(3)'s VIS_HTTPSTYLE.
Requests through a proxy are still broken for URIs that contain blanks, since this required a bigger rewrite of the whole function.
Diffstat (limited to 'usr.bin/ftp/fetch.c')
-rw-r--r--usr.bin/ftp/fetch.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c
index cce524d..ee31d3e 100644
--- a/usr.bin/ftp/fetch.c
+++ b/usr.bin/ftp/fetch.c
@@ -65,6 +65,7 @@ __RCSID_SOURCE("$NetBSD: fetch.c,v 1.16.2.1 1997/11/18 01:00:22 mellon Exp $");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <vis.h>
#include "ftp_var.h"
@@ -104,7 +105,7 @@ url_get(origline, proxyenv)
char *port;
volatile int s;
size_t len;
- char c, *cp, *ep, *http_buffer, *portnum, *path, buf[4096];
+ char c, *cp, *ep, *http_buffer, *portnum, *path, *uri, buf[4096];
const char *savefile;
char *line, *proxy, *host;
volatile sig_t oldintr;
@@ -160,6 +161,11 @@ url_get(origline, proxyenv)
goto cleanup_url_get;
}
+ uri = (char *) calloc(strlen(path) * 4 + 1, sizeof(char));
+ if (uri == NULL)
+ errx(1, "Can't allocate memory for URI.");
+ strvisx(uri, path, strlen(path), VIS_HTTPSTYLE);
+
if (proxyenv != NULL) { /* use proxy */
proxy = strdup(proxyenv);
if (proxy == NULL)
@@ -198,7 +204,7 @@ url_get(origline, proxyenv)
if (debug)
printf("host %s, port %s, path %s, save as %s.\n",
- host, portnum, path, savefile);
+ host, portnum, uri, savefile);
if (! EMPTYSTRING(portnum)) {
port = portnum;
@@ -279,12 +285,13 @@ url_get(origline, proxyenv)
if (!proxy) {
printf("Requesting %s\n", origline);
len = asprintf(&http_buffer,
- "GET /%s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n", path, host);
+ "GET /%s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n", uri, host);
} else {
printf("Requesting %s (via %s)\n", origline, proxyenv);
len = asprintf(&http_buffer,
"GET %s HTTP/1.0\r\n\r\n", path);
}
+ free(uri);
if (len < 0) {
warnx("Failed to format HTTP request");
goto cleanup_url_get;
OpenPOWER on IntegriCloud