/* Globals (can be accessed from signal handlers */
static off_t content_len; /* Content-length of the file */
static off_t beg_range; /* Range at which continue begins */
-#ifdef CONFIG_FEATURE_WGET_STATUSBAR
+#if ENABLE_FEATURE_WGET_STATUSBAR
static off_t transferred; /* Number of bytes transferred so far */
#endif
static int chunked; /* chunked transfer encoding */
-#ifdef CONFIG_FEATURE_WGET_STATUSBAR
+#if ENABLE_FEATURE_WGET_STATUSBAR
static void progressmeter(int flag);
static char *curfile; /* Name of current file being transferred */
static struct timeval start; /* Time a transfer started */
return ret;
}
-#ifdef CONFIG_FEATURE_WGET_AUTHENTICATION
+#if ENABLE_FEATURE_WGET_AUTHENTICATION
/*
* Base64-encode character string and return the string.
*/
// will destroy trailing / by storing '\0' in last byte!
if (*target.path && target.path[strlen(target.path)-1] != '/') {
fname_out =
-#ifdef CONFIG_FEATURE_WGET_STATUSBAR
+#if ENABLE_FEATURE_WGET_STATUSBAR
curfile =
#endif
bb_get_last_path_component(target.path);
}
if (!fname_out || !fname_out[0]) {
fname_out =
-#ifdef CONFIG_FEATURE_WGET_STATUSBAR
+#if ENABLE_FEATURE_WGET_STATUSBAR
curfile =
#endif
"index.html";
}
if (dir_prefix != NULL)
fname_out = concat_path_file(dir_prefix, fname_out);
-#ifdef CONFIG_FEATURE_WGET_STATUSBAR
+#if ENABLE_FEATURE_WGET_STATUSBAR
} else {
curfile = bb_get_last_path_component(fname_out);
#endif
*/
if (use_proxy) {
const char *format = "GET %stp://%s:%d/%s HTTP/1.1\r\n";
-#ifdef CONFIG_FEATURE_WGET_IP6_LITERAL
+#if ENABLE_FEATURE_WGET_IP6_LITERAL
if (strchr(target.host, ':'))
format = "GET %stp://[%s]:%d/%s HTTP/1.1\r\n";
#endif
fprintf(sfp, "Host: %s\r\nUser-Agent: %s\r\n", target.host,
user_agent);
-#ifdef CONFIG_FEATURE_WGET_AUTHENTICATION
+#if ENABLE_FEATURE_WGET_AUTHENTICATION
if (target.user) {
fprintf(sfp, "Authorization: Basic %s\r\n",
base64enc((unsigned char*)target.user, buf, sizeof(buf)));
#endif
if (beg_range)
- fprintf(sfp, "Range: bytes="OFF_FMT"-\r\n", beg_range);
+ fprintf(sfp, "Range: bytes=%"OFF_FMT"-\r\n", beg_range);
#if ENABLE_FEATURE_WGET_LONG_OPTIONS
if (extra_headers)
fputs(extra_headers, sfp);
break;
/*FALLTHRU*/
default:
- chomp(buf);
- bb_error_msg_and_die("server returned error %s: %s", s, buf);
+ /* Show first line only and kill any ESC tricks */
+ buf[strcspn(buf, "\n\r\x1b")] = '\0';
+ bb_error_msg_and_die("server returned error: %s", buf);
}
/*
pasv_error:
bb_error_msg_and_die("bad response to %s: %s", "PASV", buf);
}
- // Response is "227 garbageN1,N2,N3,N4,P1,P2
+ // Response is "227 garbageN1,N2,N3,N4,P1,P2[)]
// Server's IP is N1.N2.N3.N4 (we ignore it)
// Server's port for data connection is P1*256+P2
+ s = strrchr(buf, ')');
+ if (s && !s[1]) s[0] = '\0';
s = strrchr(buf, ',');
if (!s) goto pasv_error;
port = xatol_range(s+1, 0, 255);
dfp = open_socket(&s_in);
if (beg_range) {
- sprintf(buf, "REST "OFF_FMT, beg_range);
+ sprintf(buf, "REST %"OFF_FMT, beg_range);
if (ftpcmd(buf, NULL, sfp, buf) == 350)
content_len -= beg_range;
}
if (full_write(output_fd, buf, n) != n) {
bb_perror_msg_and_die(bb_msg_write_error);
}
-#ifdef CONFIG_FEATURE_WGET_STATUSBAR
+#if ENABLE_FEATURE_WGET_STATUSBAR
transferred += n;
#endif
if (got_clen) {
pp = h->host;
-#ifdef CONFIG_FEATURE_WGET_IP6_LITERAL
+#if ENABLE_FEATURE_WGET_IP6_LITERAL
if (h->host[0] == '[') {
char *ep;
{
FILE *fp;
- fp = fdopen(xconnect(s_in), "r+");
+ /* glibc 2.4 seems to try seeking on it - ??! */
+ /* hopefully it understands what ESPIPE means... */
+ fp = fdopen(xconnect_tcp_v4(s_in), "r+");
if (fp == NULL)
bb_perror_msg_and_die("fdopen");
return NULL;
/* see if we are at the end of the headers */
- for (s = buf ; *s == '\r' ; ++s)
+ for (s = buf; *s == '\r'; ++s)
;
if (s[0] == '\n')
return NULL;
/* convert the header name to lower case */
- for (s = buf ; isalnum(*s) || *s == '-' ; ++s)
+ for (s = buf; isalnum(*s) || *s == '-'; ++s)
*s = tolower(*s);
/* verify we are at the end of the header name */
bb_error_msg_and_die("bad header line: %s", buf);
/* locate the start of the header value */
- for (*s++ = '\0' ; *s == ' ' || *s == '\t' ; ++s)
+ for (*s++ = '\0'; *s == ' ' || *s == '\t'; ++s)
;
hdrval = s;
return result;
}
-#ifdef CONFIG_FEATURE_WGET_STATUSBAR
+#if ENABLE_FEATURE_WGET_STATUSBAR
/* Stuff below is from BSD rcp util.c, as added to openshh.
* Original copyright notice is retained at the end of this file.
*/
static int
getttywidth(void)
{
- int width=0;
+ int width;
get_terminal_width_height(0, &width, NULL);
- return (width);
+ return width;
}
static void
char buf[256];
if (flag == -1) { /* first call to progressmeter */
- (void) gettimeofday(&start, (struct timezone *) 0);
+ gettimeofday(&start, (struct timezone *) 0);
lastupdate = start;
lastsize = 0;
totalsize = content_len + beg_range; /* as content_len changes.. */
}
- (void) gettimeofday(&now, (struct timezone *) 0);
+ gettimeofday(&now, (struct timezone *) 0);
ratio = 100;
if (totalsize != 0 && !chunked) {
- ratio = (int) (100 * (transferred+beg_range) / totalsize);
+ /* long long helps to have working ETA even if !LFS */
+ ratio = (int) (100 * (unsigned long long)(transferred+beg_range) / totalsize);
ratio = MIN(ratio, 100);
}
i++;
abbrevsize >>= 10;
}
- /* See http://en.wikipedia.org/wiki/Tera */
+ /* see http://en.wikipedia.org/wiki/Tera */
fprintf(stderr, "%6d %c%c ", (int)abbrevsize, " KMGTPEZY"[i], i?'B':' ');
timersub(&now, &lastupdate, &tvwait);
fprintf(stderr, "--:--:-- ETA");
} else {
/* to_download / (transferred/elapsed) - elapsed: */
- int eta = (int) (to_download*elapsed/transferred - elapsed);
+ int eta = (int) ((unsigned long long)to_download*elapsed/transferred - elapsed);
+ /* (long long helps to have working ETA even if !LFS) */
i = eta % 3600;
fprintf(stderr, "%02d:%02d:%02d ETA", eta / 3600, i / 60, i % 60);
}