diff options
author | jkh <jkh@FreeBSD.org> | 2000-01-25 05:56:49 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 2000-01-25 05:56:49 +0000 |
commit | b6f601a801926a106b3328c65333116714d51c76 (patch) | |
tree | 817a80d613c18f3380e23ea375b7e65282fddb05 /usr.sbin/sysinstall/http.c | |
parent | 8cd8c3184d4856344fb6419a35ab3bd51851584b (diff) | |
download | FreeBSD-src-b6f601a801926a106b3328c65333116714d51c76.zip FreeBSD-src-b6f601a801926a106b3328c65333116714d51c76.tar.gz |
o Fix http proxy code for various extentions and deal with FTP archive
format changes.
o Make anonymous ftp setup more analy retentive.
PR: 16070
Submitted by: Philipp Mergenthaler <un1i@rz.uni-karlsruhe.de>
Diffstat (limited to 'usr.sbin/sysinstall/http.c')
-rw-r--r-- | usr.sbin/sysinstall/http.c | 175 |
1 files changed, 86 insertions, 89 deletions
diff --git a/usr.sbin/sysinstall/http.c b/usr.sbin/sysinstall/http.c index 0fcf159..14220bb 100644 --- a/usr.sbin/sysinstall/http.c +++ b/usr.sbin/sysinstall/http.c @@ -11,38 +11,31 @@ Boolean mediaInitHTTP(Device *dev) { /* - * Some proxies think that files with the extension ".ai" are postscript - * files and use "ascii mode" instead of "binary mode" for ftp. - * The FTP server then translates all LF to CRLF. - * I don't know how to handle this elegantly... - * Squid uses ascii mode, ftpget uses binary mode and both tell us: - * "Content-Type: application/postscript" - * - * Probably the safest way would be to get the file, look at its checksum - * and, if it doesn't match, replace all CRLF by LF and check again. + * Some proxies fetch files with certain extensions in "ascii mode" instead + * of "binary mode" for FTP. The FTP server then translates all LF to CRLF. * * You can force Squid to use binary mode by appending ";type=i" to the URL, - * which is what I do here. - * + * which is what I do here. For other proxies, the LF->CRLF substitution + * is reverted in distExtract(). */ extern int h_errno; int rv,s; - bool el; /* end of header line */ - char *cp, buf[PATH_MAX], req[1000]; + bool el; /* end of header line */ + char *cp, buf[PATH_MAX], req[BUFSIZ]; struct sockaddr_in peer; struct hostent *peer_in; s=socket(PF_INET, SOCK_STREAM, 6); /* tcp */ if (s == -1) { - msgConfirm("Network error"); - return FALSE; + msgConfirm("Network error"); + return FALSE; } peer_in=gethostbyname(variable_get(VAR_HTTP_HOST)); if (peer_in == NULL) { - msgConfirm("%s",hstrerror(h_errno)); - return FALSE; + msgConfirm("%s",hstrerror(h_errno)); + return FALSE; } peer.sin_len=peer_in->h_length; @@ -52,9 +45,9 @@ mediaInitHTTP(Device *dev) rv=connect(s,(struct sockaddr *)&peer,sizeof(peer)); if (rv == -1) { - msgConfirm("Couldn't connect to proxy %s:%s", - variable_get(VAR_HTTP_HOST),variable_get(VAR_FTP_PORT)); - return FALSE; + msgConfirm("Couldn't connect to proxy %s:%s", + variable_get(VAR_HTTP_HOST),variable_get(VAR_HTTP_PORT)); + return FALSE; } sprintf(req,"GET / HTTP/1.0\r\n\r\n"); @@ -69,28 +62,28 @@ mediaInitHTTP(Device *dev) rv=read(s,cp,1); variable_set2(VAR_HTTP_FTP_MODE,"",0); while (rv>0) { - if ((*cp == '\012') && el) { - /* reached end of a header line */ - if (!strncmp(buf,"Server: ",8)) { - if (!strncmp(buf,"Server: Squid",13)) { - variable_set2(VAR_HTTP_FTP_MODE,";type=i",1); - } else { - variable_set2(VAR_HTTP_FTP_MODE,"",1); - } - } - /* ignore other headers */ - /* check for "\015\012" at beginning of line, i.e. end of headers */ - if ((cp-buf) == 1) - break; - cp=buf; - rv=read(s,cp,1); - } else { - el=FALSE; - if (*cp == '\015') - el=TRUE; - cp++; - rv=read(s,cp,1); - } + if ((*cp == '\012') && el) { + /* reached end of a header line */ + if (!strncmp(buf,"Server: ",8)) { + if (!strncmp(buf,"Server: Squid",13)) { + variable_set2(VAR_HTTP_FTP_MODE,";type=i",0); + } else { + variable_set2(VAR_HTTP_FTP_MODE,"",0); + } + } + /* ignore other headers */ + /* check for "\015\012" at beginning of line, i.e. end of headers */ + if ((cp-buf) == 1) + break; + cp=buf; + rv=read(s,cp,1); + } else { + el=FALSE; + if (*cp == '\015') + el=TRUE; + cp++; + rv=read(s,cp,1); + } } close(s); return TRUE; @@ -103,14 +96,14 @@ mediaGetHTTP(Device *dev, char *file, Boolean probe) FILE *fp; int rv,s; bool el; /* end of header line */ - char *cp, buf[PATH_MAX], req[1000]; + char *cp, buf[PATH_MAX], req[BUFSIZ]; struct sockaddr_in peer; struct hostent *peer_in; s=socket(PF_INET, SOCK_STREAM, 6); /* tcp */ if (s == -1) { - msgConfirm("Network error"); - return NULL; + msgConfirm("Network error"); + return NULL; } peer_in=gethostbyname(variable_get(VAR_HTTP_HOST)); @@ -121,16 +114,18 @@ mediaGetHTTP(Device *dev, char *file, Boolean probe) rv=connect(s,(struct sockaddr *)&peer,sizeof(peer)); if (rv == -1) { - msgConfirm("Couldn't connect to proxy %s:%s", - variable_get(VAR_HTTP_HOST),variable_get(VAR_FTP_PORT)); - return NULL; + msgConfirm("Couldn't connect to proxy %s:%s", + variable_get(VAR_HTTP_HOST),variable_get(VAR_FTP_PORT)); + 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)); + + if (isDebug()) { + msgDebug("sending http request: %s",req); } - - sprintf(req,"GET ftp://%s:%s%s%s/%s%s HTTP/1.0\r\n\r\n", - variable_get(VAR_FTP_HOST), variable_get(VAR_FTP_PORT), - "/pub/FreeBSD/", variable_get(VAR_RELNAME), - file,variable_get(VAR_HTTP_FTP_MODE)); - msgDebug("sending http request: %s",req); write(s,req,strlen(req)); /* @@ -142,41 +137,43 @@ mediaGetHTTP(Device *dev, char *file, Boolean probe) el=FALSE; rv=read(s,cp,1); while (rv>0) { - if ((*cp == '\012') && el) { - /* reached end of a header line */ - if (!strncmp(buf,"HTTP",4)) { - rv=strtol((char *)(buf+9),0,0); - *(cp-1)='\0'; /* chop the CRLF off */ - if (rv >= 500) { - msgConfirm("Server error %s, you could try an other server",buf); - return NULL; - } else if (rv == 404) { - msgConfirm("%s was not found, maybe directory or release-version are wrong?",req); - return NULL; - } else if (rv >= 400) { - msgConfirm("Client error %s, you could try an other server",buf); - return NULL; - } else if (rv >= 300) { - msgConfirm("Error %s,",buf); - return NULL; - } else if (rv != 200) { - msgConfirm("Error %s when trying to fetch %s",buf,req); - return NULL; - } - } - /* ignore other headers */ - /* check for "\015\012" at beginning of line, i.e. end of headers */ - if ((cp-buf) == 1) - break; - cp=buf; - rv=read(s,cp,1); - } else { - el=FALSE; - if (*cp == '\015') - el=TRUE; - cp++; - rv=read(s,cp,1); - } + if ((*cp == '\012') && el) { + /* reached end of a header line */ + if (!strncmp(buf,"HTTP",4)) { + rv=strtol((char *)(buf+9),0,0); + *(cp-1)='\0'; /* chop the CRLF off */ + if (probe && (rv != 200)) { + return NULL; + } else if (rv >= 500) { + msgConfirm("Server error %s when sending %s, you could try an other server",buf, req); + return NULL; + } else if (rv == 404) { + msgConfirm("%s was not found, maybe directory or release-version are wrong?",req); + return NULL; + } else if (rv >= 400) { + msgConfirm("Client error %s, you could try an other server",buf); + return NULL; + } else if (rv >= 300) { + msgConfirm("Error %s,",buf); + return NULL; + } else if (rv != 200) { + msgConfirm("Error %s when sending %s, you could try an other server",buf, req); + return NULL; + } + } + /* ignore other headers */ + /* check for "\015\012" at beginning of line, i.e. end of headers */ + if ((cp-buf) == 1) + break; + cp=buf; + rv=read(s,cp,1); + } else { + el=FALSE; + if (*cp == '\015') + el=TRUE; + cp++; + rv=read(s,cp,1); + } } fp=fdopen(s,"r"); return fp; |