Published in <sxsd7gfnv17.fsf@florida.arsdigita.de>.
+2000-11-01 Hrvoje Niksic <hniksic@arsdigita.com>
+
+ * main.c (main): In case of opt.downloaded overflowing, print
+ <overflow> instead of a totally bogus random value.
+
+ * retr.c (retrieve_from_file): Ditto.
+
+ * recur.c (recursive_retrieve): Ditto.
+
+ * main.c (main): Ditto.
+
+ * http.c (http_loop): Ditto.
+
+ * ftp.c (ftp_loop_internal): Use downloaded_increase() instead of
+ `+=', and downloaded_exceeds_quota() instead of the simple-minded
+ check.
+ (ftp_retrieve_list): Ditto.
+ (ftp_retrieve_dirs): Ditto.
+ (ftp_retrieve_glob): Ditto.
+
+ * retr.c (downloaded_increase): New function. Notice overflows of
+ opt.downloaded.
+ (downloaded_exceeds_quota): Make sure that opt.downloaded is not
+ used if it overflowed.
+
+ * options.h (struct options): New member downloaded_overflow.
+
+2000-11-01 Hrvoje Niksic <hniksic@arsdigita.com>
+
+ * wget.h (enum): Remove extra space after last enumeration.
+
2000-11-01 Hrvoje Niksic <hniksic@arsdigita.com>
* main.c (main): Use legible_very_long() for printing
/* --dont-remove-listing was specified, so do count this towards the
number of bytes and files downloaded. */
{
- opt.downloaded += len;
+ downloaded_increase (len);
opt.numurls++;
}
downloaded if they're going to be deleted. People seeding proxies,
for instance, may want to know how many bytes and files they've
downloaded through it. */
- opt.downloaded += len;
+ downloaded_increase (len);
opt.numurls++;
if (opt.delete_after)
while (f)
{
- if (opt.quota && opt.downloaded > opt.quota)
+ if (downloaded_exceeds_quota ())
{
--depth;
return QUOTEXC;
{
int len;
- if (opt.quota && opt.downloaded > opt.quota)
+ if (downloaded_exceeds_quota ())
break;
if (f->type != FT_DIRECTORY)
continue;
}
}
freefileinfo (start);
- if (opt.quota && opt.downloaded > opt.quota)
+ if (downloaded_exceeds_quota ())
return QUOTEXC;
else
/* #### Should we return `res' here? */
tms, u->url, hstat.len, hstat.contlen, locf, count);
}
++opt.numurls;
- opt.downloaded += hstat.len;
+ downloaded_increase (hstat.len);
/* Remember that we downloaded the file for later ".orig" code. */
if (*dt & ADDED_HTML_EXTENSION)
tms, u->url, hstat.len, locf, count);
}
++opt.numurls;
- opt.downloaded += hstat.len;
+ downloaded_increase (hstat.len);
/* Remember that we downloaded the file for later ".orig" code. */
if (*dt & ADDED_HTML_EXTENSION)
"%s URL:%s [%ld/%ld] -> \"%s\" [%d]\n",
tms, u->url, hstat.len, hstat.contlen, locf, count);
++opt.numurls;
- opt.downloaded += hstat.len;
+ downloaded_increase (hstat.len);
/* Remember that we downloaded the file for later ".orig" code. */
if (*dt & ADDED_HTML_EXTENSION)
{
logprintf (LOG_NOTQUIET,
_("\nFINISHED --%s--\nDownloaded: %s bytes in %d files\n"),
- time_str (NULL), legible_very_long (opt.downloaded),
+ time_str (NULL),
+ (opt.downloaded_overflow ?
+ "<overflow>" : legible_very_long (opt.downloaded)),
opt.numurls);
/* Print quota warning, if exceeded. */
- if (opt.quota && opt.downloaded > opt.quota)
+ if (downloaded_exceeds_quota ())
logprintf (LOG_NOTQUIET,
_("Download quota (%s bytes) EXCEEDED!\n"),
legible (opt.quota));
long quota; /* Maximum number of bytes to
retrieve. */
VERY_LONG_TYPE downloaded; /* How much we downloaded already. */
+ int downloaded_overflow; /* Whether the above overflowed. */
int numurls; /* Number of successfully downloaded
URLs */
assert (this_url != NULL);
assert (file != NULL);
/* If quota was exceeded earlier, bail out. */
- if (opt.quota && (opt.downloaded > opt.quota))
+ if (downloaded_exceeds_quota ())
return QUOTEXC;
/* Cache the current URL in the list. */
if (first_time)
for (cur_url = url_list; cur_url; cur_url = cur_url->next)
{
/* If quota was exceeded earlier, bail out. */
- if (opt.quota && (opt.downloaded > opt.quota))
+ if (downloaded_exceeds_quota ())
break;
/* Parse the URL for convenient use in other functions, as well
as to get the optimized form. It also checks URL integrity. */
FREE_MAYBE (canon_this_url);
/* Decrement the recursion depth. */
--depth;
- if (opt.quota && (opt.downloaded > opt.quota))
+ if (downloaded_exceeds_quota ())
return QUOTEXC;
else
return RETROK;
char *filename, *new_file;
int dt;
- if (opt.quota && opt.downloaded > opt.quota)
+ if (downloaded_exceeds_quota ())
{
status = QUOTEXC;
break;
{
logputs (LOG_VERBOSE, (n1 == n2) ? _("Giving up.\n\n") : _("Retrying.\n\n"));
}
+
+/* Increment opt.downloaded by BY_HOW_MUCH. If an overflow occurs,
+ set opt.downloaded_overflow to 1. */
+void
+downloaded_increase (unsigned long by_how_much)
+{
+ VERY_LONG_TYPE old;
+ if (opt.downloaded_overflow)
+ return;
+ old = opt.downloaded;
+ opt.downloaded += by_how_much;
+ if (opt.downloaded < old) /* carry flag, where are you when I
+ need you? */
+ {
+ /* Overflow. */
+ opt.downloaded_overflow = 1;
+ opt.downloaded = ~((VERY_LONG_TYPE)0);
+ }
+}
+
+/* Return non-zero if the downloaded amount of bytes exceeds the
+ desired quota. If quota is not set or if the amount overflowed, 0
+ is returned. */
+int
+downloaded_exceeds_quota (void)
+{
+ if (!opt.quota)
+ return 0;
+ if (opt.downloaded_overflow)
+ /* We don't really no. (Wildly) assume not. */
+ return 0;
+
+ return opt.downloaded > opt.quota;
+}
void printwhat PARAMS ((int, int));
+void downloaded_increase PARAMS ((unsigned long));
+int downloaded_exceeds_quota PARAMS ((void));
+
#endif /* RETR_H */
HEAD_ONLY = 0x0004, /* only send the HEAD request */
SEND_NOCACHE = 0x0008, /* send Pragma: no-cache directive */
ACCEPTRANGES = 0x0010, /* Accept-ranges header was found */
- ADDED_HTML_EXTENSION = 0x0020, /* added ".html" extension due to -E */
+ ADDED_HTML_EXTENSION = 0x0020 /* added ".html" extension due to -E */
};
/* Universal error type -- used almost everywhere.