Commit Graph

54 Commits

Author SHA1 Message Date
40cef71282 Reduce scope of variables
* libwget/bar.c: Likewise
* libwget/console.c: Likewise
* libwget/encoding.c: Likewise
* libwget/hashmap.c: Likewise
* libwget/io.c: Likewise
* libwget/md5.c: Likewise
* libwget/netrc.c: Likewise
* libwget/ssl_gnutls.c: Likewise
* libwget/xml.c: Likewise
* src/job.c: Likewise
* src/plugin.c: Likewise
* libwget/hashfile.c: Include local private.h
* src/host.c: Remove unused find_free_job_context struct

Found by: cppcheck
2017-10-05 00:27:31 +05:30
6948deae02 Use type bool instead of char
* include/wget/wget.h: Use type bool instead of char
* libwget/bar.c: Likewise
* libwget/base64.c: Likewise
* libwget/cookie.c: Likewise
* libwget/encoding.c: Likewise
* libwget/hsts.c: Likewise
* libwget/http.h: Likewise
* libwget/http_highlevel.c: Likewise
* libwget/http_parse.c: Likewise
* libwget/ip.c: Likewise
* libwget/iri.c: Likewise
* libwget/logger.c: Likewise
* libwget/net.h: Likewise
* libwget/ocsp.c: Likewise
* libwget/tls_session.c: Likewise
* libwget/vector.c: Likewise
* src/plugin.c: Likewise
* src/wget_host.h: Likewise
* src/wget_job.h: Likewise
* src/wget_plugin.h: Likewise
* tests/test-plugin-dummy.c: Likewise
2017-09-22 13:08:49 +00:00
00d8ff861a Assign enum values explicitly
* src/wget_options.h (stats_format_t enum): Likewise
* src/options.c (help_section_t enum): Likewise
* libwget/css_tokenizer.h: Likewise
* libwget/bar.c (_bar_slot_status_t enum): likewise
* src/host.c (host_docs_get): Initialize 'host_docsp'
* src/wget.c (add_statistics): Add call to host_docs_add()
2017-09-19 10:40:34 +05:30
07f6b81dc8 * libwget/bar.c(_bar_set_progress): Fix progress bar printf command to fit total size 2017-08-09 13:07:42 +02:00
d1560c3a0e * libwget/bar.c: Deduplicate code in function wget_bar_set_slots 2017-08-08 17:34:34 +02:00
88cba6b5a6 * libwget/bar.c: SPlit duplicated code into function 2017-08-07 17:15:13 +02:00
0bfd6388a8 * libwget/bar.c: Replace redundant variable bar->max_slots with bar->nslots 2017-08-07 15:25:17 +02:00
109b86dd70 * libwget/bar.c(wget_bar_init): Fix progress bar memory allocation value 2017-08-07 14:34:51 +02:00
93c9613b5c Add documentation for wget_bar_set_slots 2017-08-07 14:25:02 +02:00
e606417a4a Fix doxygen warnings
* README.md: Mark options
* docs/wget2_manual.md: Mark URLs
* libwget/bar.c: Fix doc for bar_init(),
  add doxygen close tag at end of file
* libwget/buffer.c: Fix doc for wget_buffer_reset()
* libwget/console.c: Move unused tag to front of param
* libwget/hpkp.c: Fix documented params for wget_hpkp_new()
* libwget/iri.c: Fix doc for wget_iri_supported()
* libwget/net.c: Fix doc for wget_tcp_printf()
* libwget/utils.c: Move unused tag to front of param
2017-07-21 11:12:23 +02:00
eb1095efcc Check slot value in wget_bar_slot_deregister()
* libwget/bar.c (wget_bar_init): Remove redundant xfree()s,
  (wget_bar_slot_downloaded): Check value of 'slot' param
2017-06-17 20:26:31 +02:00
c6ee3d79ad Fix syntax-check 'sc_prohibit_have_config_h'
* cfg.mk: Remove sc_prohibit_have_config_h from local-checks-to-skip
* libwget/*.c: Include <config.h> unconditionally
* src/*.c: Likewise
* tests/*.c: Likewise
2017-04-30 22:01:34 +02:00
c4377ef786 * libwget/bar.c: Allocate all memory for progress display together 2017-04-27 18:50:01 +02:00
bc4010fa39 Fix progress bar when off_t is 32 bits
* include/wget/wget.h: Amend prototype of wget_human_readable()
* libwget/bar.c: Use uint64_t instead of off_t
* libwget/utils.c (wget_human_readable): Change 3rd param off_t -> uint64_t
2017-04-12 11:48:15 +02:00
ec396c577f Fix URLs to HTTPS where possible 2017-02-28 15:31:30 +01:00
0117ec4ff5 Fix integer overflow in ratio calculation
* libwget/bar.c (_bar_update_slot): Fix integer overflow in ratio calculation

Fixes #125
2016-11-15 15:12:41 +01:00
37b732f95a * libwget/bar.c (_bar_set_progress): Typecast the right value to integer 2016-11-12 16:00:40 +01:00
b049eb6d3a Fix gcc/clang warnings from the new manywarnings feature
* configure.ac: Suppress -Wunsuffixed-float-constants for gcc,
  add -Wno-disabled-macro-expansion to clang flags
* examples/getstream.c: Removed 'unused' attributes from argc and argv.
* include/wget/wget.h: Fix slot to int for bar functions.
* libwget/bar.c: Fix slot to int for bar functions, cast to int,
  change type of bitfield 'redraw' to unsigned.
* libwget/hsts.c (wget_hsts_new): Fix int to bitfield conversion.
* libwget/http.c: Cast printf %p format to (void *).
* src/wget.c: Cast printf %p format to (void *),
  remove ACTION_DONE from enum actions.
* src/wget_host.h: Fix double declaration of host_remove_job()
* tests/libtest.c (wget_test_check_filesystem): Fix type of 'rc'.
* tests/test-idn-robots.c: Fix comma to semikolon at end of line.
* tests/test.c (test_strcasecmp_ascii): Fix type of loop variable.
2016-11-02 22:19:41 +01:00
861385a6c8 Separate progress bar logic into library and application parts
* include/wget/wget.h: Remove struct _wget_bar_ctx and wget_bat_ctx_t,
  amend prototypes of wget_bar functions,
  new function wget_bar_write_line()
* libwget/bar.c: Bunch of cleanups and code rearrangements
* src/wget_progress.h: Remove
* src/Makefile.am: Remove src/wget_progress.h
* src/bar.c: Remove mutex usage,
  (_error_write) call wget_bar_write_line
* src/log.c: Remove redundant param checks
* src/wget.c: Add struct _body_callback_context,
  always call bar_slot_begin() on begin of new download,
  use downloader->id as progress slot
* src/wget_bar.h: Amend prototypes of bar_ functions
2016-10-13 16:39:59 +02:00
968e665973 Call bar_update_slot() from main thread
* libwget/bar.c: Fix typos,
  (wget_bar_set_slots): Init mem only when needed,
  add comments describing Escape sequences
* src/bar.c (bar_update_slots): Take nslots as param
* src/wget.c: Move call to bar_update_slots() from worker to main thread
* src/wget_bar.h: Amend prototype of bar_update_slots()
2016-10-12 17:09:09 +02:00
49ab9740e1 Fix progress bar details
* include/wget/wget.h: wget_get_screen_size() must not be pure
* libwget/bar.c (_bar_get_width): Leave one space right to avoid linebreaks
* libwget/utils.c (wget_human_readable): Align # of bytes
* src/bar.c (wget_get_screen_size): Fix return value
2016-10-05 11:49:45 +02:00
40340af300 Export a new function for determining screen dimensions
* include/wget/wget.h: New function wget_get_screen_size. Replaces old
wget_determine_screen_width
* libwget/bar.c (_bar_get_width): Use wget_get_screen_size instead of
wget_determine_screen_width
* libwget/utils.c: Replace function wget_determine_screen_width with a
more generic wget_get_screen_size.
2016-10-04 21:31:34 +02:00
354c8624d1 Handle SIGWINCH for progress bar
* include/wget/wget.h: New function wget_bar_screen_resized, as an
indicator that the screen size may have changed. Also, wget_bar_update
may now modify the *bar parameter
* libwget/bar.c: Move detection code for screen size into a separate
function called _bar_get_width.
  (wget_bar_update): Check if the screen width has changed and
reallocate more space if necessary
* src/wget.c: Install a new signal handler for SIGWINCH
2016-10-04 21:30:00 +02:00
e10cf1d1f3 Move window size detection to libwget
* include/wget/wget.h: Declare new function wget_determine_screen_width.
Also change prototype of wget_bar_init to not accept a max_width
parameter
* src/utils.c: Move function determine_screen_width from here ...
* libwget/utils.c: ... to here.
* src/utils.{c,h}: Delete empty file
* src/Makefile.am: Remove source files utils.{c,h}
* src/bar.c: Move detection of screen width from here ...
* libwget/bar.c: ... to here
* tests/test.c: wget_bar_init() no longer takes a max_width parameter
2016-10-04 20:29:30 +02:00
4cdffd2def Cleaner API for progress bar within libwget
* include/wget/wget.h (_wget_bar_ctx): Remove unused elements
expected_size and filename. Rename slotpos to _slotpos to reflect that
it should not be used by the client.
* include/wget/wget.h: Remove declaration for old API functions
bar_register and bar_deregister. Define declarations for
wget_bar_slot_begin, wget_bar_slot_register and
wget_bar_slot_deregister.
* libwget/bar.c (_bar_slot_status_t): Define new enum to store the
status of a slot of the progress bar.
  (_bar_slot_t): Remove unused element last_ctx. Also, define slot
  elements: filename, file_size, bytes_downloaded and status.
  (wget_bar_slot_begin): Define new function. Invoked when the client
  has started downloading a new file.
  (wget_bar_slot_register): New function to register a new file in a
  progress bar slot.
  (wget_bar_deregister): Remove old function
  (wget_bar_slot_deregister): New function, called after file has
  finished downloading. Successfully or unsuccessfully.
  (wget_bar_deregister): Remove old function
  (_bar_set_progress): last_ctx is no longer used. Instead data is
  stored within the slot struct itself
  (_bar_update_slot): Same
  (_bar_print_final): Same
  (wget_bar_deinit): Free the filename stored in the slot
* src/bar.c: Edit to reflect the changes in libwget API
* src/wget.c (_get_header): Same
  (http_send_request): Same
  (http_receive_response): Same
* src/wget_bar.h: Same
2016-10-04 20:23:56 +02:00
6a115f1b1e * libwget/bar.c: Remove mutex stdout
The mutex stdout was meant to ensure that multiple routines don't write
to the screen concurrently. However, this mutex is not required, since
such syncronization should be handled by the client using the library.
All other library methods for the progress avoid any form
synchronization primitives for this reason
2016-10-03 13:12:31 +02:00
9568b0c87e Rename include/libwget.h to include/wget/wget.h+wgetver.h 2016-09-30 09:47:32 +02:00
51c1c42e7a * libwget/bar.c: Cosmetics, param check for wget_bar_init() 2016-09-29 11:52:23 +02:00
a8d6956247 Don't dereference NULL pointer when copying filename
* libwget/bar.c (wget_bar_deregister): Make sure filename is not NULL
before calling strdup() on it
2016-09-29 09:33:38 +02:00
f633c3c75a Support dynamic thread allocation in progress bar
* include/libwget.h.in: Add new function wget_bar_set_slots
* libwget/bar.c (_wget_bar_st): Add new struct member max_slots to store
the maximum number of slots of the progress bar
  (wget_bar_init): Initialize the memory for all the possible
progress_bars
  (wget_bar_set_slots): New function to modify the number of progress
slots at runtime. Can only increase the number of slots, not decrease.
* src/bar.c(bar_init): Remove unneeded variable lf. bar_init() is
invoked before any threads are created, hence do not print the required
newlines. This is now done by wget_bar_set_slots
  (bar_update_slots): Wget2 interface for libwget's wget_bar_set_slots
  (_error_write): Fix the position of acquiring the mutex. Don't make
  changes to the screen while some other progress bar function may be
  running
* src/bar.h: New function bar_update_slots
* src/wget.c: Create global variable nthreads.
  (downloader_thread): Update the number of progress bar slots
* src/wget.h: New global variable nthreads
2016-09-27 22:17:37 +02:00
21bc107c1a Make wget_bar_update update the entire progress 2016-09-26 16:56:12 +02:00
99a59c129f Draw animated progress bar for unknown file size
* libwget/bar.c: Use a tick counter and draw an animated progress bar,
similar to Wget 1.x when the file size is unknown
2016-09-26 16:56:07 +02:00
2d12a06f83 Improved progress bar functioning 2016-09-23 17:07:51 +02:00
c988b1ccb0 Clean up progress bar code
Saving the max, cols and ratio to the slot structure was an optimization
used to prevent unneeded refreshes of the progress bar on slow
connections. However, with the asynchronous progress bar, this
optimization is no longer necessary as we refresh the progress bar far
fewer times already. Also, as other elements like the ETA are added to
the progress bar, these checks will only cause more problems as the ETA
would need to be updated even if no data has been downloaded in some
time.

* libwget/bar.c: Remove ratio, max, cur, cols and first from the
_wget_slot_st struct and eliminate all references to them.
2016-09-23 14:43:57 +02:00
56d46d9b26 Print a different progress bar when size is unknown
* libwget/bar.c(_wget_bar_st): New struct members known_size and
unknown_size to denote the character with which the progress bar is
filled in these two cases
  (wget_bar_init): Initialize the new struct members with the right data
  (wget_bar_update): Choose and print the right character based on
  whether the size is known or not.
  (_bar_print_final): Same
  (wget_bar_deinit): Free the struct members
2016-09-23 14:41:03 +02:00
8fecbcb6bd Improve accuracy of wget_human_readable
* libwget/utils.c (wget_human_readable): Set acc to 1000 and print to 2
decimal places. This is similar to the settings used in Wget 1.x.
* libwget/bar.c (_bar_slot_t): Define element human_size to be as large
as _BAR_DOWNBYTES_SIZE.
2016-09-20 17:06:18 +02:00
58ecced947 Use wget_human_readable() from Wget1.x
* bootstrap.conf: Remove module 'human'
* include/libwget.h.in: Amend wget_human_readable()
* libwget/bar.c: Use new function wget_human_readable()
* libwget/utils.c: Replace wget_human_readable()
* src/wget.c: Use new function wget_human_readable()
2016-09-20 16:39:39 +02:00
6417de198a Print human readable total number of bytes in progress bar
* include/libwget.h.in: Add wget_human_readable_alloc()
* libwget/utils.c: Add wget_human_readable_alloc()
* libwget/bar.c: Use wget_human_readable_alloc()
* src/bar.c (bar_init): Set log function after call to wget_bar_init()
* src/wget.c (main): Use wget_human_readable() to print bottom line of bar
2016-09-20 13:59:36 +02:00
2406808c22 Retain a copy of download context for progress bar
When the screen is scrolled or resized, we often need to redraw the
entire progress bar. However, when some threads have completed
downloading, this can cause those progress slots to become blank since
their contexts were deleted and hence lost. To prevent this, keep a copy
of the last context in the slot, so we can access it later for printing
the progress bar.

* libwget/bar.c (_bar_slot_t): New member, last_ctx
  (wget_bar_deregister): Create a copy of the context just before we
  deregister. This ensures that we copy the latest data for printing
  (wget_bar_update): If no context is registered, then try printing the
  last context available
  (_bar_print_final): Make the method signature similar to
  wget_bar_update for consistency
2016-09-19 16:55:26 +02:00
8368a98e98 Use gnulib human module for human readable file size
* bootstrap.conf: Add the human module and its dependency unistd
* include/libwget.h.in: Replace method signature for wget_human_readable
* libwget/bar.c (_bar_slot_t): Add a new struct memeber for storing the
human readable string that it printed on the progress bar
  (wget_bar_init): Initialise the new human_size struct member
  (wget_bar_update): Use the new wget_human_readable() method
  (_bar_print_final): Same
  (wget_bar_deinit): Free the allocated memory for each slot
* libwget/utils.c (wget_human_readable): Replace the old function with a
call to the human_readable() method from gnulib
2016-09-16 16:37:03 +02:00
99b1551215 Separate out the last update of the progress bar
When the progress bar is updated for the last time (whether exiting due
to error, or download complete), we may want to print information not
normally presented in the progress bar, like total time taken. To allow
this, separate out the printing of the last update of the progress bar

* include/libwget.h.in (_wget_bar_ctx): Remove unused members, final and
cond
* libwget/bar.c: Separate out the bar slot selection for reuse.
(_bar_print_final): New method for printing the last update of a
progress bar
2016-09-16 16:37:03 +02:00
3e94ef82ba Fix wget_bar_free() 2016-09-16 16:37:03 +02:00
22aff5c3d9 Better naming of functions 2016-09-16 16:37:03 +02:00
6bbbca576d Separate out bar_deinit and free'ing memory
* libwget/bar.c (wget_bar_init): Invoke wget_bar_deinit() to free up the
memory allocated to the various progress bar sections. Similarly, invoke
wget_bar_free() to free up the memory allocated to the progress bar
itself
2016-09-16 16:37:03 +02:00
21e050a614 Use xfree, xmalloc and xcalloc
* libwget/bar.c: Replace all calls to free(), malloc() and calloc() with
xfree(), xmalloc() and xcalloc() respectively
* libwget/hashmap.c: Same
2016-09-16 16:37:03 +02:00
e2b83d153c Change tabs to spaces when not at Beginning of line 2016-09-16 16:37:03 +02:00
8cf9159bca Make compiler happy about strict-prototypes and shadowed variables 2016-09-16 16:37:03 +02:00
f04b680a08 Create an asynchronous progress bar
Give the progress bar its own thread and let it update the entire
display asynchronously at a specified time interval. The existing
implementation refreshes the progress bar for each network packet
downloaded. Over multiple downloader threads and a high speed network
connection this can lead to far too many redrawings of the screen. Also,
each of the downloader threads will block while trying to acquire the
thread mutex because another thread just retrieved a packet. While I
haven't profiled it, it seems like there would be extremely high lock
contention in the existing implementation. Instead, with a separate
thread, we can update all the progress bar slots simultaneously at
regular intervals.

    * bootstrap.conf: Include Gnulib module "ioctl"
    * include/libwget.h.in: Define always_inline, flatten and deprecated
	compiler attributes for both GCC and Clang
    * include/libwget.h.in: Export new functions wget_human_readable,
	wget_bar_register and wget_bar_deregister.
    * include/libwget.h.in (wget_http_response_t): Add new element
	"cur_downloaded" to struct. This element keeps a track of the raw
	number of bytes downloaded in the response
        (_wget_bar_ctx): Define new struct for storing the progress bar
	context.
    * libwget/bar.c: Fix display of downloaded ratio. Ensure it does not
	exceed 100% by comparing the raw downloaded bytes instead of
	uncompressed downloaded bytes.
	Add support for printing the filename and downloaded bytes to the
	progress bar.
    * libwget/http.c (wget_http_response_cb): Store the raw number of
	bytes downloaded from the network in the response data
    * libwget/utils.c (wget_human_readable): New function to convert an
	int value to a human readable string
    * src/bar.c: Use the entire screen width instead of just 70 columns
	for the progress bar.
	Provide methods to register and deregister a progress bar
	context
	(wget_bar_update_thread): New method for the progress bar thread
	to update the output periodically.
    * src/bar.h: Same
    * src/job.h: Move definition of struct DOWNLOADER from main.c to
        here
    * src/progress.h: Move definition of _body_callback_context from
        main.c to here
    * src/utils.c: Add new method to determine the width of the screen
    * src/utils.h: Same
    * src/wget.c: Use the new progress bar contexts. Update, register
    and deregister them
        (main): Deinit the progress bar only if it was enabled
    * src/Makefile.am: Add new files, progress.h, utils.c, utils.h
2016-09-16 16:37:03 +02:00
aa389831a8 Use bitfields in structs where possible 2016-07-11 14:53:36 +02:00
a51946b22b Fix compiler warnings
* include/libwget.h.in (wget_bar_init, wget_bar_update,
wget_bar_print): Change types to int and off_t.
* libwget/bar.c (wget_bar_init, wget_bar_update,
wget_bar_print): Change types to int and off_t.
* src/wget.c (_prepare_file): Add prototype.  Change type of rc to
size_t.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2016-03-20 14:42:56 +01:00