wget: allow dots in header field names.
wget: code shrink function old new delta gethdr 211 190 -21 wget_main 2609 2557 -52 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-73) Total: -73 bytes
This commit is contained in:
parent
512a545f0d
commit
06783a5140
@ -25,7 +25,7 @@ struct host_info {
|
|||||||
|
|
||||||
static void parse_url(char *url, struct host_info *h);
|
static void parse_url(char *url, struct host_info *h);
|
||||||
static FILE *open_socket(len_and_sockaddr *lsa);
|
static FILE *open_socket(len_and_sockaddr *lsa);
|
||||||
static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc);
|
static char *gethdr(char *buf, size_t bufsiz, FILE *fp /*,int *istrunc*/ );
|
||||||
static int ftpcmd(const char *s1, const char *s2, FILE *fp, char *buf);
|
static int ftpcmd(const char *s1, const char *s2, FILE *fp, char *buf);
|
||||||
|
|
||||||
/* Globals (can be accessed from signal handlers */
|
/* Globals (can be accessed from signal handlers */
|
||||||
@ -94,7 +94,7 @@ int wget_main(int argc, char **argv)
|
|||||||
char buf[512];
|
char buf[512];
|
||||||
struct host_info server, target;
|
struct host_info server, target;
|
||||||
len_and_sockaddr *lsa;
|
len_and_sockaddr *lsa;
|
||||||
int n, status;
|
int status;
|
||||||
int port;
|
int port;
|
||||||
int try = 5;
|
int try = 5;
|
||||||
unsigned opt;
|
unsigned opt;
|
||||||
@ -301,7 +301,7 @@ int wget_main(int argc, char **argv)
|
|||||||
switch (status) {
|
switch (status) {
|
||||||
case 0:
|
case 0:
|
||||||
case 100:
|
case 100:
|
||||||
while (gethdr(buf, sizeof(buf), sfp, &n) != NULL)
|
while (gethdr(buf, sizeof(buf), sfp /*, &n*/) != NULL)
|
||||||
/* eat all remaining headers */;
|
/* eat all remaining headers */;
|
||||||
goto read_response;
|
goto read_response;
|
||||||
case 200:
|
case 200:
|
||||||
@ -324,7 +324,7 @@ int wget_main(int argc, char **argv)
|
|||||||
/*
|
/*
|
||||||
* Retrieve HTTP headers.
|
* Retrieve HTTP headers.
|
||||||
*/
|
*/
|
||||||
while ((str = gethdr(buf, sizeof(buf), sfp, &n)) != NULL) {
|
while ((str = gethdr(buf, sizeof(buf), sfp /*, &n*/)) != NULL) {
|
||||||
/* gethdr did already convert the "FOO:" string to lowercase */
|
/* gethdr did already convert the "FOO:" string to lowercase */
|
||||||
smalluint key = index_in_strings(keywords, *&buf) + 1;
|
smalluint key = index_in_strings(keywords, *&buf) + 1;
|
||||||
if (key == KEY_content_length) {
|
if (key == KEY_content_length) {
|
||||||
@ -457,39 +457,40 @@ int wget_main(int argc, char **argv)
|
|||||||
if (!(opt & WGET_OPT_QUIET))
|
if (!(opt & WGET_OPT_QUIET))
|
||||||
progressmeter(-1);
|
progressmeter(-1);
|
||||||
|
|
||||||
do {
|
/* Loops only if chunked */
|
||||||
|
while (1) {
|
||||||
while (content_len > 0 || !got_clen) {
|
while (content_len > 0 || !got_clen) {
|
||||||
|
int n;
|
||||||
unsigned rdsz = sizeof(buf);
|
unsigned rdsz = sizeof(buf);
|
||||||
|
|
||||||
if (content_len < sizeof(buf) && (chunked || got_clen))
|
if (content_len < sizeof(buf) && (chunked || got_clen))
|
||||||
rdsz = (unsigned)content_len;
|
rdsz = (unsigned)content_len;
|
||||||
n = safe_fread(buf, rdsz, dfp);
|
n = safe_fread(buf, rdsz, dfp);
|
||||||
if (n <= 0)
|
if (n <= 0) {
|
||||||
break;
|
if (ferror(dfp)) {
|
||||||
if (full_write(output_fd, buf, n) != n) {
|
/* perror will not work: ferror doesn't set errno */
|
||||||
bb_perror_msg_and_die(bb_msg_write_error);
|
bb_error_msg_and_die(bb_msg_read_error);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
xwrite(output_fd, buf, n);
|
||||||
#if ENABLE_FEATURE_WGET_STATUSBAR
|
#if ENABLE_FEATURE_WGET_STATUSBAR
|
||||||
transferred += n;
|
transferred += n;
|
||||||
#endif
|
#endif
|
||||||
if (got_clen) {
|
if (got_clen)
|
||||||
content_len -= n;
|
content_len -= n;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (chunked) {
|
if (!chunked)
|
||||||
|
break;
|
||||||
|
|
||||||
safe_fgets(buf, sizeof(buf), dfp); /* This is a newline */
|
safe_fgets(buf, sizeof(buf), dfp); /* This is a newline */
|
||||||
safe_fgets(buf, sizeof(buf), dfp);
|
safe_fgets(buf, sizeof(buf), dfp);
|
||||||
content_len = STRTOOFF(buf, NULL, 16);
|
content_len = STRTOOFF(buf, NULL, 16);
|
||||||
/* FIXME: error check? */
|
/* FIXME: error check? */
|
||||||
if (content_len == 0) {
|
if (content_len == 0)
|
||||||
chunked = 0; /* all done! */
|
break; /* all done! */
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (n == 0 && ferror(dfp)) {
|
|
||||||
bb_perror_msg_and_die(bb_msg_read_error);
|
|
||||||
}
|
|
||||||
} while (chunked);
|
|
||||||
|
|
||||||
if (!(opt & WGET_OPT_QUIET))
|
if (!(opt & WGET_OPT_QUIET))
|
||||||
progressmeter(1);
|
progressmeter(1);
|
||||||
@ -580,12 +581,12 @@ static FILE *open_socket(len_and_sockaddr *lsa)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc)
|
static char *gethdr(char *buf, size_t bufsiz, FILE *fp /*, int *istrunc*/)
|
||||||
{
|
{
|
||||||
char *s, *hdrval;
|
char *s, *hdrval;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
*istrunc = 0;
|
/* *istrunc = 0; */
|
||||||
|
|
||||||
/* retrieve header line */
|
/* retrieve header line */
|
||||||
if (fgets(buf, bufsiz, fp) == NULL)
|
if (fgets(buf, bufsiz, fp) == NULL)
|
||||||
@ -593,12 +594,12 @@ static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc)
|
|||||||
|
|
||||||
/* see if we are at the end of the headers */
|
/* see if we are at the end of the headers */
|
||||||
for (s = buf; *s == '\r'; ++s)
|
for (s = buf; *s == '\r'; ++s)
|
||||||
;
|
continue;
|
||||||
if (s[0] == '\n')
|
if (*s == '\n')
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* convert the header name to lower case */
|
/* convert the header name to lower case */
|
||||||
for (s = buf; isalnum(*s) || *s == '-'; ++s)
|
for (s = buf; isalnum(*s) || *s == '-' || *s == '.'; ++s)
|
||||||
*s = tolower(*s);
|
*s = tolower(*s);
|
||||||
|
|
||||||
/* verify we are at the end of the header name */
|
/* verify we are at the end of the header name */
|
||||||
@ -606,24 +607,23 @@ static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc)
|
|||||||
bb_error_msg_and_die("bad header line: %s", buf);
|
bb_error_msg_and_die("bad header line: %s", buf);
|
||||||
|
|
||||||
/* locate the start of the header value */
|
/* locate the start of the header value */
|
||||||
for (*s++ = '\0'; *s == ' ' || *s == '\t'; ++s)
|
*s++ = '\0';
|
||||||
;
|
hdrval = skip_whitespace(s);
|
||||||
hdrval = s;
|
|
||||||
|
|
||||||
/* locate the end of header */
|
/* locate the end of header */
|
||||||
while (*s != '\0' && *s != '\r' && *s != '\n')
|
while (*s && *s != '\r' && *s != '\n')
|
||||||
++s;
|
++s;
|
||||||
|
|
||||||
/* end of header found */
|
/* end of header found */
|
||||||
if (*s != '\0') {
|
if (*s) {
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
return hdrval;
|
return hdrval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Rats! The buffer isn't big enough to hold the entire header value. */
|
/* Rats! The buffer isn't big enough to hold the entire header value. */
|
||||||
while (c = getc(fp), c != EOF && c != '\n')
|
while (c = getc(fp), c != EOF && c != '\n')
|
||||||
;
|
continue;
|
||||||
*istrunc = 1;
|
/* *istrunc = 1; */
|
||||||
return hdrval;
|
return hdrval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user