aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/wget.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/networking/wget.c b/networking/wget.c
index 1991a1072..013b87801 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -13,8 +13,9 @@
13//usage: IF_FEATURE_WGET_LONG_OPTIONS( 13//usage: IF_FEATURE_WGET_LONG_OPTIONS(
14//usage: "[-c|--continue] [-s|--spider] [-q|--quiet] [-O|--output-document FILE]\n" 14//usage: "[-c|--continue] [-s|--spider] [-q|--quiet] [-O|--output-document FILE]\n"
15//usage: " [--header 'header: value'] [-Y|--proxy on/off] [-P DIR]\n" 15//usage: " [--header 'header: value'] [-Y|--proxy on/off] [-P DIR]\n"
16//usage: " [--no-check-certificate] [-U|--user-agent AGENT]" 16/* Since we ignore these opts, we don't show them in --help */
17//usage: IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..." 17/* //usage: " [--no-check-certificate] [--no-cache]" */
18//usage: " [-U|--user-agent AGENT]" IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..."
18//usage: ) 19//usage: )
19//usage: IF_NOT_FEATURE_WGET_LONG_OPTIONS( 20//usage: IF_NOT_FEATURE_WGET_LONG_OPTIONS(
20//usage: "[-csq] [-O FILE] [-Y on/off] [-P DIR] [-U AGENT]" 21//usage: "[-csq] [-O FILE] [-Y on/off] [-P DIR] [-U AGENT]"
@@ -35,8 +36,11 @@
35 36
36#include "libbb.h" 37#include "libbb.h"
37 38
38//#define log_io(...) bb_error_msg(__VA_ARGS__) 39#if 0
39#define log_io(...) ((void)0) 40# define log_io(...) bb_error_msg(__VA_ARGS__)
41#else
42# define log_io(...) ((void)0)
43#endif
40 44
41 45
42struct host_info { 46struct host_info {
@@ -316,8 +320,6 @@ static char *gethdr(FILE *fp)
316 char *s, *hdrval; 320 char *s, *hdrval;
317 int c; 321 int c;
318 322
319 /* *istrunc = 0; */
320
321 /* retrieve header line */ 323 /* retrieve header line */
322 c = fgets_and_trim(fp); 324 c = fgets_and_trim(fp);
323 325
@@ -348,6 +350,14 @@ static char *gethdr(FILE *fp)
348 return hdrval; 350 return hdrval;
349} 351}
350 352
353static void reset_beg_range_to_zero(void)
354{
355 //bb_error_msg("restart failed");
356 G.beg_range = 0;
357 xlseek(G.output_fd, 0, SEEK_SET);
358 ftruncate(G.output_fd, 0);
359}
360
351static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa) 361static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa)
352{ 362{
353 FILE *sfp; 363 FILE *sfp;
@@ -415,10 +425,12 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_
415 425
416 *dfpp = open_socket(lsa); 426 *dfpp = open_socket(lsa);
417 427
418 if (G.beg_range) { 428 if (G.beg_range != 0) {
419 sprintf(G.wget_buf, "REST %"OFF_FMT"u", G.beg_range); 429 sprintf(G.wget_buf, "REST %"OFF_FMT"u", G.beg_range);
420 if (ftpcmd(G.wget_buf, NULL, sfp) == 350) 430 if (ftpcmd(G.wget_buf, NULL, sfp) == 350)
421 G.content_len -= G.beg_range; 431 G.content_len -= G.beg_range;
432 else
433 reset_beg_range_to_zero();
422 } 434 }
423 435
424 if (ftpcmd("RETR ", target->path, sfp) > 150) 436 if (ftpcmd("RETR ", target->path, sfp) > 150)
@@ -675,7 +687,7 @@ static void download_one_url(const char *url)
675 } 687 }
676#endif 688#endif
677 689
678 if (G.beg_range) 690 if (G.beg_range != 0)
679 fprintf(sfp, "Range: bytes=%"OFF_FMT"u-\r\n", G.beg_range); 691 fprintf(sfp, "Range: bytes=%"OFF_FMT"u-\r\n", G.beg_range);
680 692
681#if ENABLE_FEATURE_WGET_LONG_OPTIONS 693#if ENABLE_FEATURE_WGET_LONG_OPTIONS
@@ -742,15 +754,23 @@ However, in real world it was observed that some web servers
742(e.g. Boa/0.94.14rc21) simply use code 204 when file size is zero. 754(e.g. Boa/0.94.14rc21) simply use code 204 when file size is zero.
743*/ 755*/
744 case 204: 756 case 204:
757 if (G.beg_range != 0) {
758 /* "Range:..." was not honored by the server.
759 * Restart download from the beginning.
760 */
761 reset_beg_range_to_zero();
762 }
745 break; 763 break;
746 case 300: /* redirection */ 764 case 300: /* redirection */
747 case 301: 765 case 301:
748 case 302: 766 case 302:
749 case 303: 767 case 303:
750 break; 768 break;
751 case 206: 769 case 206: /* Partial Content */
752 if (G.beg_range) 770 if (G.beg_range != 0)
771 /* "Range:..." worked. Good. */
753 break; 772 break;
773 /* Partial Content even though we did not ask for it??? */
754 /* fall through */ 774 /* fall through */
755 default: 775 default:
756 bb_error_msg_and_die("server returned error: %s", sanitize_string(G.wget_buf)); 776 bb_error_msg_and_die("server returned error: %s", sanitize_string(G.wget_buf));
@@ -878,6 +898,8 @@ int wget_main(int argc UNUSED_PARAM, char **argv)
878 "post-data\0" Required_argument "\xfd" 898 "post-data\0" Required_argument "\xfd"
879 /* Ignored (we don't do ssl) */ 899 /* Ignored (we don't do ssl) */
880 "no-check-certificate\0" No_argument "\xfc" 900 "no-check-certificate\0" No_argument "\xfc"
901 /* Ignored (we don't support caching) */
902 "no-cache\0" No_argument "\xfb"
881 ; 903 ;
882#endif 904#endif
883 905