version 1.81, 1999/09/30 12:18:03 |
version 1.82, 1999/09/30 23:51:27 |
Line 87 static int go_fetch __P((const char *)); |
|
Line 87 static int go_fetch __P((const char *)); |
|
static int fetch_ftp __P((const char *)); |
static int fetch_ftp __P((const char *)); |
static int fetch_url __P((const char *, const char *, char *, char *)); |
static int fetch_url __P((const char *, const char *, char *, char *)); |
static int parse_url __P((const char *, const char *, url_t *, char **, |
static int parse_url __P((const char *, const char *, url_t *, char **, |
char **, char **, char **, char **)); |
char **, char **, char **, in_port_t *, |
|
char **)); |
static void url_decode __P((char *)); |
static void url_decode __P((char *)); |
|
|
static int redirect_loop; |
static int redirect_loop; |
Line 115 auth_url(challenge, response, guser, gpa |
|
Line 116 auth_url(challenge, response, guser, gpa |
|
const char *gpass; |
const char *gpass; |
{ |
{ |
char *cp, *ep, *clear, *line, *realm, *scheme; |
char *cp, *ep, *clear, *line, *realm, *scheme; |
char user[BUFSIZ], *pass; |
char user[BUFSIZ], *pass; |
int rval; |
int rval; |
size_t len, clen, rlen; |
size_t len, clen, rlen; |
|
|
*response = NULL; |
*response = NULL; |
clear = realm = scheme = NULL; |
clear = realm = scheme = NULL; |
Line 206 base64_encode(clear, len, encoded) |
|
Line 207 base64_encode(clear, len, encoded) |
|
{ |
{ |
static const char enc[] = |
static const char enc[] = |
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
char *cp; |
char *cp; |
int i; |
int i; |
|
|
cp = encoded; |
cp = encoded; |
for (i = 0; i < len; i += 3) { |
for (i = 0; i < len; i += 3) { |
|
|
* "ftp://host//dir/file" "/dir/file" |
* "ftp://host//dir/file" "/dir/file" |
*/ |
*/ |
static int |
static int |
parse_url(url, desc, type, user, pass, host, port, path) |
parse_url(url, desc, type, user, pass, host, port, portnum, path) |
const char *url; |
const char *url; |
const char *desc; |
const char *desc; |
url_t *type; |
url_t *type; |
Line 290 parse_url(url, desc, type, user, pass, h |
|
Line 291 parse_url(url, desc, type, user, pass, h |
|
char **pass; |
char **pass; |
char **host; |
char **host; |
char **port; |
char **port; |
|
in_port_t *portnum; |
char **path; |
char **path; |
{ |
{ |
char *cp, *ep, *thost, *tport; |
const char *origurl; |
size_t len; |
char *cp, *ep, *thost, *tport; |
|
size_t len; |
|
|
if (url == NULL || desc == NULL || type == NULL || user == NULL |
if (url == NULL || desc == NULL || type == NULL || user == NULL |
|| pass == NULL || host == NULL || port == NULL || path == NULL) |
|| pass == NULL || host == NULL || port == NULL || portnum == NULL |
|
|| path == NULL) |
errx(1, "parse_url: invoked with NULL argument!"); |
errx(1, "parse_url: invoked with NULL argument!"); |
|
|
|
origurl = url; |
*type = UNKNOWN_URL_T; |
*type = UNKNOWN_URL_T; |
*user = *pass = *host = *port = *path = NULL; |
*user = *pass = *host = *port = *path = NULL; |
|
*portnum = 0; |
tport = NULL; |
tport = NULL; |
|
|
if (strncasecmp(url, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) { |
if (strncasecmp(url, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) { |
url += sizeof(HTTP_URL) - 1; |
url += sizeof(HTTP_URL) - 1; |
*type = HTTP_URL_T; |
*type = HTTP_URL_T; |
|
*portnum = HTTP_PORT; |
tport = httpport; |
tport = httpport; |
} else if (strncasecmp(url, FTP_URL, sizeof(FTP_URL) - 1) == 0) { |
} else if (strncasecmp(url, FTP_URL, sizeof(FTP_URL) - 1) == 0) { |
url += sizeof(FTP_URL) - 1; |
url += sizeof(FTP_URL) - 1; |
*type = FTP_URL_T; |
*type = FTP_URL_T; |
|
*portnum = FTP_PORT; |
tport = ftpport; |
tport = ftpport; |
} else if (strncasecmp(url, FILE_URL, sizeof(FILE_URL) - 1) == 0) { |
} else if (strncasecmp(url, FILE_URL, sizeof(FILE_URL) - 1) == 0) { |
url += sizeof(FILE_URL) - 1; |
url += sizeof(FILE_URL) - 1; |
Line 366 cleanup_parse_url: |
|
Line 374 cleanup_parse_url: |
|
if ((ep = strchr(cp, ']')) == NULL || |
if ((ep = strchr(cp, ']')) == NULL || |
(ep[1] != '\0' && ep[1] != '\0')) { |
(ep[1] != '\0' && ep[1] != '\0')) { |
warnx("Invalid address `%s' in %s `%s'", |
warnx("Invalid address `%s' in %s `%s'", |
thost, desc, url); |
thost, desc, origurl); |
goto cleanup_parse_url; |
goto cleanup_parse_url; |
} |
} |
len = ep - cp; /* change `[xxx]' -> `xxx' */ |
len = ep - cp; /* change `[xxx]' -> `xxx' */ |
Line 374 cleanup_parse_url: |
|
Line 382 cleanup_parse_url: |
|
thost[len] = '\0'; |
thost[len] = '\0'; |
if (! isipv6addr(thost)) { |
if (! isipv6addr(thost)) { |
warnx("Invalid IPv6 address `%s' in %s `%s'", |
warnx("Invalid IPv6 address `%s' in %s `%s'", |
thost, desc, url); |
thost, desc, origurl); |
goto cleanup_parse_url; |
goto cleanup_parse_url; |
} |
} |
cp = ep + 1; |
cp = ep + 1; |
Line 390 cleanup_parse_url: |
|
Line 398 cleanup_parse_url: |
|
|
|
/* look for [:port] */ |
/* look for [:port] */ |
if (cp != NULL) { |
if (cp != NULL) { |
long nport; |
long nport; |
|
|
nport = strtol(cp, &ep, 10); |
nport = strtol(cp, &ep, 10); |
if (nport < 1 || nport > MAX_IN_PORT_T || *ep != '\0') { |
if (*ep != '\0' && ep == cp) { |
warnx("Invalid port `%s' in %s `%s'", cp, desc, url); |
struct servent *svp; |
|
|
|
svp = getservbyname(cp, "tcp"); |
|
if (svp == NULL) { |
|
warnx("Unknown port `%s' in %s `%s'", |
|
cp, desc, origurl); |
|
goto cleanup_parse_url; |
|
} else |
|
nport = ntohs(svp->s_port); |
|
} else if (nport < 1 || nport > MAX_IN_PORT_T || *ep != '\0') { |
|
warnx("Invalid port `%s' in %s `%s'", cp, desc, |
|
origurl); |
goto cleanup_parse_url; |
goto cleanup_parse_url; |
} |
} |
|
*portnum = nport; |
tport = cp; |
tport = cp; |
} |
} |
|
|
if (tport != NULL); |
if (tport != NULL); |
*port = xstrdup(tport); |
*port = xstrdup(tport); |
if (*path == NULL) |
if (*path == NULL) |
Line 406 cleanup_parse_url: |
|
Line 427 cleanup_parse_url: |
|
|
|
if (debug) |
if (debug) |
fprintf(ttyout, |
fprintf(ttyout, |
"parse_url: user `%s' pass `%s' host %s:%s path `%s'\n", |
"parse_url: user `%s' pass `%s' host %s:%s(%d) path `%s'\n", |
*user ? *user : "<null>", *pass ? *pass : "<null>", |
*user ? *user : "<null>", *pass ? *pass : "<null>", |
*host ? *host : "<null>", *port ? *port : "<null>", |
*host ? *host : "<null>", *port ? *port : "<null>", |
*path ? *path : "<null>"); |
*portnum ? *portnum : -1, *path ? *path : "<null>"); |
|
|
return (0); |
return (0); |
} |
} |
|
|
|
|
jmp_buf httpabort; |
jmp_buf httpabort; |
|
|
/* |
/* |
Line 481 fetch_url(url, proxyenv, proxyauth, wwwa |
|
Line 501 fetch_url(url, proxyenv, proxyauth, wwwa |
|
(void)&decodedpath; |
(void)&decodedpath; |
#endif |
#endif |
|
|
if (parse_url(url, "URL", &urltype, &user, &pass, &host, &port, &path) |
if (parse_url(url, "URL", &urltype, &user, &pass, &host, &port, |
== -1) |
&portnum, &path) == -1) |
goto cleanup_fetch_url; |
goto cleanup_fetch_url; |
portnum = strtol(port, &ep, 10); |
|
if (*ep || port == ep) { |
|
struct servent *svp = getservbyname(port, "tcp"); |
|
if (svp != NULL) |
|
portnum = ntohs(svp->s_port); |
|
} |
|
|
|
if (urltype == FILE_URL_T && ! EMPTYSTRING(host) |
if (urltype == FILE_URL_T && ! EMPTYSTRING(host) |
&& strcasecmp(host, "localhost") != 0) { |
&& strcasecmp(host, "localhost") != 0) { |
Line 584 fetch_url(url, proxyenv, proxyauth, wwwa |
|
Line 598 fetch_url(url, proxyenv, proxyauth, wwwa |
|
strtol(np + 1, &ep, 10); |
strtol(np + 1, &ep, 10); |
if (*ep != '\0') |
if (*ep != '\0') |
continue; |
continue; |
if (portnum != |
if (np_port != portnum) |
htons((in_port_t)np_port)) |
|
continue; |
continue; |
} |
} |
plen = strlen(cp); |
plen = strlen(cp); |
Line 600 fetch_url(url, proxyenv, proxyauth, wwwa |
|
Line 613 fetch_url(url, proxyenv, proxyauth, wwwa |
|
|
|
if (isproxy) { |
if (isproxy) { |
if (parse_url(proxyenv, "proxy URL", &purltype, |
if (parse_url(proxyenv, "proxy URL", &purltype, |
&puser, &ppass, &phost, &pport, &ppath) |
&puser, &ppass, &phost, &pport, &portnum, |
== -1) |
&ppath) == -1) |
goto cleanup_fetch_url; |
goto cleanup_fetch_url; |
|
|
if ((purltype != HTTP_URL_T |
if ((purltype != HTTP_URL_T |
Line 650 fetch_url(url, proxyenv, proxyauth, wwwa |
|
Line 663 fetch_url(url, proxyenv, proxyauth, wwwa |
|
hp->h_length = sizeof(sin.sin_addr); |
hp->h_length = sizeof(sin.sin_addr); |
memcpy(&sin.sin_addr, hp->h_addr, hp->h_length); |
memcpy(&sin.sin_addr, hp->h_addr, hp->h_length); |
} |
} |
|
sin.sin_port = htons(portnum); |
if (port == NULL) { |
|
warnx("Unknown port for URL `%s'", url); |
|
goto cleanup_fetch_url; |
|
} |
|
portnum = strtol(port, &ep, 10); |
|
if (*ep || port == ep) { |
|
struct servent *svp = getservbyname(port, "tcp"); |
|
if (svp != NULL) |
|
portnum = ntohs(svp->s_port); |
|
} |
|
sin.sin_port = portnum; |
|
|
|
s = socket(AF_INET, SOCK_STREAM, 0); |
s = socket(AF_INET, SOCK_STREAM, 0); |
if (s == -1) { |
if (s == -1) { |
|
|
char *cp, *xargv[5], rempath[MAXPATHLEN]; |
char *cp, *xargv[5], rempath[MAXPATHLEN]; |
char *host, *path, *dir, *file, *user, *pass; |
char *host, *path, *dir, *file, *user, *pass; |
char *port; |
char *port; |
int dirhasglob, filehasglob, oautologin, rval, type, xargc; |
int dirhasglob, filehasglob, oautologin, rval, type, xargc; |
url_t urltype; |
in_port_t portnum; |
|
url_t urltype; |
|
|
host = path = dir = file = user = pass = NULL; |
host = path = dir = file = user = pass = NULL; |
port = NULL; |
port = NULL; |
|
|
|
|
if (strncasecmp(url, FTP_URL, sizeof(FTP_URL) - 1) == 0) { |
if (strncasecmp(url, FTP_URL, sizeof(FTP_URL) - 1) == 0) { |
if ((parse_url(url, "URL", &urltype, &user, &pass, |
if ((parse_url(url, "URL", &urltype, &user, &pass, |
&host, &port, &path) == -1) || |
&host, &port, &portnum, &path) == -1) || |
(user != NULL && *user == '\0') || |
(user != NULL && *user == '\0') || |
(pass != NULL && *pass == '\0') || |
(pass != NULL && *pass == '\0') || |
EMPTYSTRING(host)) { |
EMPTYSTRING(host)) { |