version 1.105, 2012/04/30 13:41:26 |
version 1.106, 2012/08/14 20:47:08 |
|
|
{ |
{ |
char pbuf[NI_MAXSERV], hbuf[NI_MAXHOST], *cp, *portnum, *path, ststr[4]; |
char pbuf[NI_MAXSERV], hbuf[NI_MAXHOST], *cp, *portnum, *path, ststr[4]; |
char *hosttail, *cause = "unknown", *newline, *host, *port, *buf = NULL; |
char *hosttail, *cause = "unknown", *newline, *host, *port, *buf = NULL; |
char *epath, *redirurl, *loctail; |
char *epath, *redirurl, *loctail, *h, *p; |
int error, i, isftpurl = 0, isfileurl = 0, isredirect = 0, rval = -1; |
int error, i, isftpurl = 0, isfileurl = 0, isredirect = 0, rval = -1; |
struct addrinfo hints, *res0, *res, *ares = NULL; |
struct addrinfo hints, *res0, *res, *ares = NULL; |
const char * volatile savefile; |
const char * volatile savefile; |
|
|
size_t len, wlen; |
size_t len, wlen; |
#ifndef SMALL |
#ifndef SMALL |
char *sslpath = NULL, *sslhost = NULL; |
char *sslpath = NULL, *sslhost = NULL; |
char *locbase, *full_host = NULL; |
char *locbase, *full_host = NULL, *auth = NULL; |
const char *scheme; |
const char *scheme; |
int ishttpsurl = 0; |
int ishttpsurl = 0; |
SSL_CTX *ssl_ctx = NULL; |
SSL_CTX *ssl_ctx = NULL; |
|
|
} |
} |
|
|
noslash: |
noslash: |
|
|
|
#ifndef SMALL |
|
/* |
|
* Look for auth header in host, since now host does not |
|
* contain the path. Basic auth from RFC 2617, valid |
|
* characters for path are in RFC 3986 section 3.3. |
|
*/ |
|
if (proxyenv == NULL && |
|
(!strcmp(scheme, HTTP_URL) || !strcmp(scheme, HTTPS_URL))) { |
|
if ((p = strchr(host, '@')) != NULL) { |
|
size_t authlen = (strlen(host) + 5) * 4 / 3; |
|
*p = 0; /* Kill @ */ |
|
if ((auth = malloc(authlen)) == NULL) |
|
err(1, "Can't allocate memory for " |
|
"authorization"); |
|
if (b64_ntop(host, strlen(host), |
|
auth, authlen) == -1) |
|
errx(1, "error in base64 encoding"); |
|
host = p + 1; |
|
} |
|
} |
|
#endif /* SMALL */ |
|
|
if (outfile) |
if (outfile) |
savefile = outfile; |
savefile = outfile; |
else { |
else { |
|
|
if ((full_host = strdup(host)) == NULL) |
if ((full_host = strdup(host)) == NULL) |
errx(1, "Cannot allocate memory for hostname"); |
errx(1, "Cannot allocate memory for hostname"); |
if (debug) |
if (debug) |
fprintf(ttyout, "host %s, port %s, path %s, save as %s.\n", |
fprintf(ttyout, "host %s, port %s, path %s, " |
host, portnum, path, savefile); |
"save as %s, auth %s.\n", |
|
host, portnum, path, savefile, auth); |
#endif /* !SMALL */ |
#endif /* !SMALL */ |
|
|
memset(&hints, 0, sizeof(hints)); |
memset(&hints, 0, sizeof(hints)); |
|
|
else |
else |
restart_point = 0; |
restart_point = 0; |
} |
} |
#endif /* !SMALL */ |
if (auth) { |
|
ftp_printf(fin, ssl, |
|
"GET /%s %s\r\nAuthorization: Basic %s\r\nHost: ", |
|
epath, restart_point ? |
|
"HTTP/1.1\r\nConnection: close" : "HTTP/1.0", |
|
auth); |
|
free(auth); |
|
auth = NULL; |
|
} else |
|
#endif /* SMALL */ |
ftp_printf(fin, ssl, "GET /%s %s\r\nHost: ", epath, |
ftp_printf(fin, ssl, "GET /%s %s\r\nHost: ", epath, |
#ifndef SMALL |
"HTTP/1.0"); |
restart_point ? "HTTP/1.1\r\nConnection: close" : |
|
#endif /* !SMALL */ |
|
"HTTP/1.0"); |
|
if (strchr(host, ':')) { |
if (strchr(host, ':')) { |
char *h, *p; |
|
|
|
/* |
/* |
* strip off scoped address portion, since it's |
* strip off scoped address portion, since it's |
* local to node |
* local to node |
|
|
SSL_free(ssl); |
SSL_free(ssl); |
} |
} |
free(full_host); |
free(full_host); |
|
free(auth); |
#endif /* !SMALL */ |
#endif /* !SMALL */ |
if (fin != NULL) |
if (fin != NULL) |
fclose(fin); |
fclose(fin); |