diff options
author | jkh <jkh@FreeBSD.org> | 2000-09-25 20:19:43 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 2000-09-25 20:19:43 +0000 |
commit | 03870bb44ff4b30367f7ebf9f87c568280bf19ba (patch) | |
tree | 3860bb1a2c0b30fadbf5a82b27762e233237b5cc | |
parent | 4892f3a914467b489d8c5f640d5f6120a0783be1 (diff) | |
download | FreeBSD-src-03870bb44ff4b30367f7ebf9f87c568280bf19ba.zip FreeBSD-src-03870bb44ff4b30367f7ebf9f87c568280bf19ba.tar.gz |
Fix the http proxy fetch code.
Submitted by: Philipp Mergenthaler <p@i609.hadiko.de>
PR: 21449
-rw-r--r-- | release/sysinstall/http.c | 37 | ||||
-rw-r--r-- | release/sysinstall/media.c | 15 | ||||
-rw-r--r-- | release/sysinstall/sysinstall.h | 1 | ||||
-rw-r--r-- | usr.sbin/sade/sade.h | 1 | ||||
-rw-r--r-- | usr.sbin/sysinstall/http.c | 37 | ||||
-rw-r--r-- | usr.sbin/sysinstall/media.c | 15 | ||||
-rw-r--r-- | usr.sbin/sysinstall/sysinstall.h | 1 |
7 files changed, 79 insertions, 28 deletions
diff --git a/release/sysinstall/http.c b/release/sysinstall/http.c index 1dfcbf5..dc9d687 100644 --- a/release/sysinstall/http.c +++ b/release/sysinstall/http.c @@ -18,8 +18,8 @@ mediaInitHTTP(Device *dev) */ int rv, s, af; - bool el; /* end of header line */ - char *cp, buf[PATH_MAX], req[BUFSIZ]; + bool el, found=FALSE; /* end of header line */ + char *cp, *rel, buf[PATH_MAX], req[BUFSIZ]; struct addrinfo hints, *res, *res0; af = variable_cmp(VAR_IPV6_ENABLE, "YES") ? AF_INET : AF_UNSPEC; @@ -48,8 +48,23 @@ mediaInitHTTP(Device *dev) variable_get(VAR_HTTP_HOST),variable_get(VAR_HTTP_PORT)); return FALSE; } + /* If the release is specified as "__RELEASE" or "any", then just + * assume that the path the user gave is ok. + */ + rel = variable_get(VAR_RELNAME); + /* + msgConfirm("rel: -%s-", rel); + */ + if (strcmp(rel, "__RELEASE") && strcmp(rel, "any")) { + sprintf(req, "%s/pub/FreeBSD/releases/"MACHINE"/%s", + variable_get(VAR_FTP_PATH), rel); + variable_set2(VAR_HTTP_PATH, req, 0); + } else { + variable_set2(VAR_HTTP_PATH, variable_get(VAR_FTP_PATH), 0); + } - sprintf(req,"GET / HTTP/1.0\r\n\r\n"); + msgNotify("Checking access to\n %s", variable_get(VAR_HTTP_PATH)); + sprintf(req,"HEAD %s/ HTTP/1.0\r\n\r\n", variable_get(VAR_HTTP_PATH)); write(s,req,strlen(req)); /* * scan the headers of the response @@ -63,6 +78,12 @@ mediaInitHTTP(Device *dev) while (rv>0) { if ((*cp == '\012') && el) { /* reached end of a header line */ + if (!strncmp(buf,"HTTP",4)) { + if (strtol((char *)(buf+9),0,0) == 200) { + found = TRUE; + } + } + if (!strncmp(buf,"Server: ",8)) { if (!strncmp(buf,"Server: Squid",13)) { variable_set2(VAR_HTTP_FTP_MODE,";type=i",0); @@ -85,7 +106,10 @@ mediaInitHTTP(Device *dev) } } close(s); - return TRUE; + if (!found) + msgConfirm("No such directory: %s\n" + "please check the URL and try again.", variable_get(VAR_HTTP_PATH)); + return found; } @@ -125,9 +149,8 @@ mediaGetHTTP(Device *dev, char *file, Boolean probe) return NULL; } - sprintf(req,"GET %s/%s/%s%s HTTP/1.0\r\n\r\n", - variable_get(VAR_FTP_PATH), variable_get(VAR_RELNAME), - file, variable_get(VAR_HTTP_FTP_MODE)); + sprintf(req,"GET %s/%s%s HTTP/1.0\r\n\r\n", + variable_get(VAR_HTTP_PATH), file, variable_get(VAR_HTTP_FTP_MODE)); if (isDebug()) { msgDebug("sending http request: %s",req); diff --git a/release/sysinstall/media.c b/release/sysinstall/media.c index 305fb79..91996e1 100644 --- a/release/sysinstall/media.c +++ b/release/sysinstall/media.c @@ -50,6 +50,7 @@ #include <resolv.h> static Boolean got_intr = FALSE; +static Boolean ftp_skip_resolve = FALSE; /* timeout handler */ static void @@ -392,7 +393,7 @@ mediaSetFTP(dialogMenuItem *self) msgDebug("dir = `%s'\n", dir ? dir : "/"); msgDebug("port # = `%d'\n", FtpPort); } - if (variable_get(VAR_NAMESERVER)) { + if (!ftp_skip_resolve && variable_get(VAR_NAMESERVER)) { msgNotify("Looking up host %s.", hostname); if (isDebug()) msgDebug("Starting DNS.\n"); @@ -452,22 +453,22 @@ mediaSetFTPPassive(dialogMenuItem *self) int mediaSetHTTP(dialogMenuItem *self) { + Boolean tmp; int result; - char *cp, *idx, hbuf[MAXHOSTNAMELEN], *hostname, *var_hostname; + char *cp, *idx, hbuf[MAXHOSTNAMELEN], *hostname; int HttpPort; int what = DITEM_RESTORE; - var_hostname = variable_get(VAR_NAMESERVER); - variable_unset(VAR_NAMESERVER); + tmp = ftp_skip_resolve; + ftp_skip_resolve = TRUE; result = mediaSetFTP(self); - if (var_hostname) - variable_set2(VAR_NAMESERVER, var_hostname, 0); + ftp_skip_resolve = tmp; if (DITEM_STATUS(result) != DITEM_SUCCESS) return result; - cp = variable_get_value(VAR_HTTP_PATH, + cp = variable_get_value(VAR_HTTP_PROXY, "Please enter the address of the HTTP proxy in this format:\n" " hostname:port (the ':port' is optional, default is 3128)",0); if (!cp) diff --git a/release/sysinstall/sysinstall.h b/release/sysinstall/sysinstall.h index 5049470..ba9f7b9 100644 --- a/release/sysinstall/sysinstall.h +++ b/release/sysinstall/sysinstall.h @@ -112,6 +112,7 @@ #define VAR_FTP_USER "ftpUser" #define VAR_FTP_HOST "ftpHost" #define VAR_HTTP_PATH "_httpPath" +#define VAR_HTTP_PROXY "httpProxy" #define VAR_HTTP_PORT "httpPort" #define VAR_HTTP_HOST "httpHost" #define VAR_HTTP_FTP_MODE "httpFtpMode" diff --git a/usr.sbin/sade/sade.h b/usr.sbin/sade/sade.h index 5049470..ba9f7b9 100644 --- a/usr.sbin/sade/sade.h +++ b/usr.sbin/sade/sade.h @@ -112,6 +112,7 @@ #define VAR_FTP_USER "ftpUser" #define VAR_FTP_HOST "ftpHost" #define VAR_HTTP_PATH "_httpPath" +#define VAR_HTTP_PROXY "httpProxy" #define VAR_HTTP_PORT "httpPort" #define VAR_HTTP_HOST "httpHost" #define VAR_HTTP_FTP_MODE "httpFtpMode" diff --git a/usr.sbin/sysinstall/http.c b/usr.sbin/sysinstall/http.c index 1dfcbf5..dc9d687 100644 --- a/usr.sbin/sysinstall/http.c +++ b/usr.sbin/sysinstall/http.c @@ -18,8 +18,8 @@ mediaInitHTTP(Device *dev) */ int rv, s, af; - bool el; /* end of header line */ - char *cp, buf[PATH_MAX], req[BUFSIZ]; + bool el, found=FALSE; /* end of header line */ + char *cp, *rel, buf[PATH_MAX], req[BUFSIZ]; struct addrinfo hints, *res, *res0; af = variable_cmp(VAR_IPV6_ENABLE, "YES") ? AF_INET : AF_UNSPEC; @@ -48,8 +48,23 @@ mediaInitHTTP(Device *dev) variable_get(VAR_HTTP_HOST),variable_get(VAR_HTTP_PORT)); return FALSE; } + /* If the release is specified as "__RELEASE" or "any", then just + * assume that the path the user gave is ok. + */ + rel = variable_get(VAR_RELNAME); + /* + msgConfirm("rel: -%s-", rel); + */ + if (strcmp(rel, "__RELEASE") && strcmp(rel, "any")) { + sprintf(req, "%s/pub/FreeBSD/releases/"MACHINE"/%s", + variable_get(VAR_FTP_PATH), rel); + variable_set2(VAR_HTTP_PATH, req, 0); + } else { + variable_set2(VAR_HTTP_PATH, variable_get(VAR_FTP_PATH), 0); + } - sprintf(req,"GET / HTTP/1.0\r\n\r\n"); + msgNotify("Checking access to\n %s", variable_get(VAR_HTTP_PATH)); + sprintf(req,"HEAD %s/ HTTP/1.0\r\n\r\n", variable_get(VAR_HTTP_PATH)); write(s,req,strlen(req)); /* * scan the headers of the response @@ -63,6 +78,12 @@ mediaInitHTTP(Device *dev) while (rv>0) { if ((*cp == '\012') && el) { /* reached end of a header line */ + if (!strncmp(buf,"HTTP",4)) { + if (strtol((char *)(buf+9),0,0) == 200) { + found = TRUE; + } + } + if (!strncmp(buf,"Server: ",8)) { if (!strncmp(buf,"Server: Squid",13)) { variable_set2(VAR_HTTP_FTP_MODE,";type=i",0); @@ -85,7 +106,10 @@ mediaInitHTTP(Device *dev) } } close(s); - return TRUE; + if (!found) + msgConfirm("No such directory: %s\n" + "please check the URL and try again.", variable_get(VAR_HTTP_PATH)); + return found; } @@ -125,9 +149,8 @@ mediaGetHTTP(Device *dev, char *file, Boolean probe) return NULL; } - sprintf(req,"GET %s/%s/%s%s HTTP/1.0\r\n\r\n", - variable_get(VAR_FTP_PATH), variable_get(VAR_RELNAME), - file, variable_get(VAR_HTTP_FTP_MODE)); + sprintf(req,"GET %s/%s%s HTTP/1.0\r\n\r\n", + variable_get(VAR_HTTP_PATH), file, variable_get(VAR_HTTP_FTP_MODE)); if (isDebug()) { msgDebug("sending http request: %s",req); diff --git a/usr.sbin/sysinstall/media.c b/usr.sbin/sysinstall/media.c index 305fb79..91996e1 100644 --- a/usr.sbin/sysinstall/media.c +++ b/usr.sbin/sysinstall/media.c @@ -50,6 +50,7 @@ #include <resolv.h> static Boolean got_intr = FALSE; +static Boolean ftp_skip_resolve = FALSE; /* timeout handler */ static void @@ -392,7 +393,7 @@ mediaSetFTP(dialogMenuItem *self) msgDebug("dir = `%s'\n", dir ? dir : "/"); msgDebug("port # = `%d'\n", FtpPort); } - if (variable_get(VAR_NAMESERVER)) { + if (!ftp_skip_resolve && variable_get(VAR_NAMESERVER)) { msgNotify("Looking up host %s.", hostname); if (isDebug()) msgDebug("Starting DNS.\n"); @@ -452,22 +453,22 @@ mediaSetFTPPassive(dialogMenuItem *self) int mediaSetHTTP(dialogMenuItem *self) { + Boolean tmp; int result; - char *cp, *idx, hbuf[MAXHOSTNAMELEN], *hostname, *var_hostname; + char *cp, *idx, hbuf[MAXHOSTNAMELEN], *hostname; int HttpPort; int what = DITEM_RESTORE; - var_hostname = variable_get(VAR_NAMESERVER); - variable_unset(VAR_NAMESERVER); + tmp = ftp_skip_resolve; + ftp_skip_resolve = TRUE; result = mediaSetFTP(self); - if (var_hostname) - variable_set2(VAR_NAMESERVER, var_hostname, 0); + ftp_skip_resolve = tmp; if (DITEM_STATUS(result) != DITEM_SUCCESS) return result; - cp = variable_get_value(VAR_HTTP_PATH, + cp = variable_get_value(VAR_HTTP_PROXY, "Please enter the address of the HTTP proxy in this format:\n" " hostname:port (the ':port' is optional, default is 3128)",0); if (!cp) diff --git a/usr.sbin/sysinstall/sysinstall.h b/usr.sbin/sysinstall/sysinstall.h index 5049470..ba9f7b9 100644 --- a/usr.sbin/sysinstall/sysinstall.h +++ b/usr.sbin/sysinstall/sysinstall.h @@ -112,6 +112,7 @@ #define VAR_FTP_USER "ftpUser" #define VAR_FTP_HOST "ftpHost" #define VAR_HTTP_PATH "_httpPath" +#define VAR_HTTP_PROXY "httpProxy" #define VAR_HTTP_PORT "httpPort" #define VAR_HTTP_HOST "httpHost" #define VAR_HTTP_FTP_MODE "httpFtpMode" |