Commit Graph

56 Commits

Author SHA1 Message Date
188989e067 Update copyright year 2024-01-07 12:41:02 +01:00
15ba1db248 Update copyrights 2023-08-31 12:57:30 +02:00
d72b05a70e Windows console width detection and update checks
* libwget/utils.c (wget_get_screen_size): Add implementation for _WIN32.
* src/bar.c (bar_update_thread): Add implementation for _WIN32.

Copyright-paperwork-exempt: Yes
Co-authored-by: Tim Rühsen <tim.ruehsen@gmx.de
2023-07-09 11:46:00 +02:00
3dc7f71098 Update copyright year 2022-02-25 17:46:43 +01:00
22162f82b2 Update copyright year 2021-01-22 21:58:38 +01:00
59d9ecd9c0 * Update copyright year to 2020 2020-01-10 00:33:02 +01:00
e1c7ad7b2f * libwget/utils.c: Improve C99 compliancy 2019-09-24 10:49:31 +02:00
4b9edbad2d Update Copyright statements to be compatible with update-copyright module 2019-09-10 23:41:56 +02:00
12f1a03693 Changed G_GNUC_WGET prefix to WGET_GCC
* include/wget/wget.h: Changed G_GNUC_WGET prefix to WGET_GCC
* */*.[ch]: Likewise
2019-08-08 17:13:24 +02:00
32aa8091b4 * libwget/utils.c (wget_strnglob): Return NULL if malloc fails 2019-06-27 15:01:10 +02:00
73b7441e9a Move wget_restrict_file_name() to src/utils.c
* fuzz/libwget_utils_fuzzer.c: Remove test code for wget_restrict_file_name()
* include/wget/wget.h: Remove wget_restrict_file_name() prototype
* libwget/utils.c: Remove wget_restrict_file_name()
* src/utils.c: Add wget_restrict_file_name()
* src/wget_utils.h: Add wget_restrict_file_name() prototype
* tests/Makefile.am: Add ../src/utils.c to libtest_la_SOURCES
* tests/libtest.c: Include ../src/wget_utils.h
2019-06-21 12:47:06 +02:00
cdb3600791 Update copyrigght to 2019 2019-01-02 12:42:53 +01:00
d9c23038c0 * libwget/utils.c: Cleanup wget_match_tail(_nocase) 2018-12-25 21:27:21 +01:00
3688ffb941 Update copyright to 2018 2018-04-30 20:52:11 +02:00
332b689925 Remove _GL_INLINE from functions
* libwget/hashmap.c: Likewise
* libwget/iri.c: Likewise
* libwget/ssl_gnutls.c: Likewise
* libwget/utils.c: Likewise

Gcc 4.1.3 on NetBSD 5.1 errors when duplicate _GL_INLINE is given as a
function attribute.
From the gnulib manual: "C code ordinarily should not use inline. Typically it
is better to let the compiler figure out whether to inline, as compilers are
pretty good about optimization nowadays. In this sense, inline is like
register, another keyword that is typically no longer needed"
2018-04-30 20:07:49 +02:00
62ea505f64 Use libwget's print-like functions instead the stdio ones
* include/wget/wget.h: Amend return type of wget_bar_print(), wget_bar_vprintf()
* libwget/Makefile.am: Replace fprintf in generated css_tokenizer.c
* libwget/bar.c: Replace *printf by wget_*printf,
  (_bar_set_progress): Generate progress bar with memcpy/memset
* libwget/hpkp.c: Replace *printf by wget_*printf
* libwget/cookie.c: Likewise
* libwget/hpkp.c: Likewise
* libwget/hsts.c: Likewise
* libwget/http.c: Likewise
* libwget/http_parse.c: Likewise
* libwget/io.c: Likewise
* libwget/net.c: Likewise
* libwget/ocsp.c: Likewise
* libwget/pipe.c: Likewise
* libwget/ssl_gnutls.c: Likewise
* libwget/utils.c: Likewise
* libwget/xml.c: Likewise

The intention is to not pull in (large) code parts from libc when
linking statically, the performance is better and we have no
portability issues on non-POSIX platforms (e.g. Windows).
2018-03-28 19:24:28 +02:00
fa679ee9ad Fix warnings
* configure.ac: Add -Wno-assign-enum -Wno-unreachable-code to gnulib warnings
* libwget/thread.c: Add #pragmas to silence warnings from gnulib includes
* libwget/utils.c: Likewise
* src/log.c: Likewise
* src/wget.c: Likewise
* src/bar.c: Make _terminate_thread static
* tests/test-gpg-styles.c: Make urls static
2018-01-11 15:16:01 +01:00
e7de66fd83 * libwget/utils.c: Fix unsigned integer overflow
* wget_match_tail: Likewise
* wget_match_tail_nocase: Likewise

Found by fuzzing
2017-08-15 02:19:57 +05:30
5237253098 * libwget/utils.c: Fix param name in docs of wget_strnglob() 2017-08-03 11:47:27 +02:00
081af4173e Fix make syntax-check due to double word 2017-07-29 23:38:47 +02:00
824c21036f Revert "Prevent tiny memory allocations when globbing"
This reverts commit 2d7fe3e9fc.

With the above patch, a tiny memory allocation is avoided, but in doing
so, it misses an important case. The glob(3) call never returns a
success when the file does not already exist at the given path.
2017-07-29 22:31:55 +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
a795da5c41 * libwget/utils.c: Fix param in docs of wget_strglob() 2017-06-15 21:00:38 +02:00
590f740ccd Fix clang -Wconversion warnings
* include/wget/wget.h (wget_ready_2_transfer): Change 'mode' to int
* libwget/io.c: Likewise
* libwget/hpkp.c: Explicit int to bit conversion
* libwget/http.c: Likewise
* libwget/net.c: Likewise
* libwget/ocsp.c: Likewise
* libwget/ssl_gnutls.c: Likewise
* tests/libtest.c: Likewise
* libwget/iri.c (wget_iri_unescape_inline): Explicit int to char conversion
* libwget/utils.c: Likewise
2017-05-25 15:33:50 +02:00
2a45890b4c MinGW cleanup
* include/wget/wget.h: Add const to first param of wget_restrict_file_name
* libwget/utils.c: Likewise
* tests/libtest.c: Remove debug output, start/stop ftp server thread,
  popen() without 'b'.
* tests/test-iri.c: Skip test on _WIN32
2017-05-24 11:34:53 +02:00
b67539e4f6 * libwget/utils.c (wget_restrict_file_name): Explicitely use signed char 2017-05-23 15:41:22 +02:00
96ecf96ddd Make _restrict_file_name() public as wget_restrict_file_name()
* include/wget/wget.h: Add wget_restrict_file_name() declaration,
  add WGET_RESTRICT_* defines.
* libwget/utils.c: Add wget_restrict_file_name() definition.
* src/options.c (parse_restrict_names): Use WGET_RESTRICT_*,
  default to WGET_RESTRICT_NAMES_WINDOWS in _WIN32.
* src/wget.c: Remove restrict_file_name(),
  (get_local_filename): Use wget_restrict_file_name().
* src/wget_options.h: Remove RESTRICT_NAMES_* defines.
* tests/libtest.c (_scan_for_unexpected): Use wget_restrict_file_name(),
  (wget_test): Use wget_restrict_file_name().

Reported-by: Akash Rawal
2017-05-23 12:29:05 +02:00
6246345ef7 Remove nonnull attribute from some functions
* include/wget/wget.h: Remove nonnull attribute from some functions
* libwget/encoding.c: Add explicit checks for NULL
* libwget/io.c: Likewise
* libwget/pipe.c: Likewise
* libwget/strlcpy.c: Likewise
* libwget/utils.c: Likewise
2017-05-15 10:28:03 +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
2d7fe3e9fc Prevent tiny memory allocations when globbing
* libwget/utils.c: Rename wget_strnglob to wget_strglob. It now calls
glob on the entire string.
* include/wget/wget.h: Change protoype of wget_strnglob
* src/options.c: Change calls to wget_strnglob to use new wget_strglob
calls
2017-04-27 18:31:15 +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
3c2ad8154f * libwget/utils.c (wget_get_screen_size): Fix return value 2017-04-06 12:24:38 +02:00
db05090e61 * libwget/utils.c: Silence -Wunused-parameter if HAVE_IOCTL is undefined 2017-04-06 10:57:10 +02:00
d31de86454 Add support for 'no_proxy' environment variable
* include/wget/wget.h: Add flag 'proxied' to wget_http_connection_t,
  add arg 'proxied' to wget_http_request_to_buffer(),
  add new function declaration wget_http_set_no_proxy(),
  add new function declaration wget_http_match_no_proxy().
* libwget/http.c: Add variable 'no_proxies',
  (wget_http_open): Check host against 'no_proxy' and set 'conn->proxied'
  when appropriate,
  (wget_http_send_request): Call wget_http_request_to_buffer() with
   conn->proxied,
  (wget_http_request_to_buffer): Check 'proxied',
  (_parse_proxies): Cleanup,
  (_parse_no_proxies): New function,
  (wget_http_set_no_proxy): New function,
  (wget_http_match_no_proxy): New function
* libwget/init.c (wget_global_deinit): Free no_proxy memory
* libwget/ip.c: Add code in comments (for later use)
* libwget/utils.c (wget_match_tail, wget_match_tail_nocase): Cleanup
* src/options.c (init): Handle 'no_proxy' env variable
* src/wget_options.h (struct config): Add no_proxy member
2017-04-05 11:37:33 +02:00
ec396c577f Fix URLs to HTTPS where possible 2017-02-28 15:31:30 +01:00
c545263d54 Support tilde expansion of filenames from wgetrc
* src/options.c (_shell_expand): New function to perform tilde
expansion on a given string
(parse_filename): Parse the input string and perform shell expansion on
it using _shell_expand
(parse_string): Set the parser functions for various options that may be
set from a config file to use parse_filename
(wget_strnglob): Run glob() on only the specified part of the string
2017-02-22 16:28:10 +01: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
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
9568b0c87e Rename include/libwget.h to include/wget/wget.h+wgetver.h 2016-09-30 09:47:32 +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
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
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
79dd277c12 Refactoring to separate send, receive and HTTP state machine
* examples/websequencediagram.c (main): Call wget_http_request_set_body()
  and wget_http_send_request() instead of wget_http_send_request_with_body().
* include/libwget.h.in: Add WGET_HTTP_USER_DATA, wget_get_timemillis(),
  extend wget_thread_cond_wait(), add body, user_data, body_length to
  wget_http_request_t, remove wget_http_send_request_with_body(),
  add wget_http_request_get_int(), wget_http_request_set_ptr(),
  wget_http_request_get_ptr(), wget_http_request_set_body().
* libwget/http.c: Add wget_http_request_get_int(),
  wget_http_request_set_ptr(), wget_http_request_get_ptr(),
  wget_http_request_set_body(),
  remove wget_http_send_request_with_body(),
  (wget_http_request_to_buffer): add body to request buffer.
* libwget/http_highlevel.c (wget_http_get): Replace
  wget_http_send_request_with_body()
* libwget/iri.c: Use c-ctype.h instead of ctype.h
  (wget_iri_parse): Allow any numbers of / after scheme:
  (wget_iri_parse): Catch URIs without /after scheme:
* libwget/list.c (wget_list_browse): Small code rearrangement
* libwget/metalink.c (_add_mirror): Check mirror.iri for NULL
* libwget/ssl_gnutls.c (send_ocsp_request): Replace
  wget_http_send_request_with_body()
* libwget/thread.c (wget_thread_cond_signal): Add timeout param
* libwget/utils.c: New function wget_get_timemillis()
* src/blacklist.c: Include wget.h instead of log.h
* src/blacklist.h: Fix indentation
* src/host.c: Add queueing stuff
* src/host.h: Reflect changes in host.c
* src/job.c: Remove queueing stuff
* src/job.h: Reflect changes in job.c
* src/log.c: Sync stdout/stderr to correct output order
* src/log.h: Remove shortcuts of print functions
* src/wget.c: Remove download_part() and http_get().
  Add http_send_request(), http_receive_response(), try_connection(),
  establish_connection(), add_statistics(), process_response_header().
  Amend downloader_thread() to reflect the changes.
* src/wget.h: Add shortcut defines for print functions.
* tests/libtest.c (_http_server_thread): Fix compiler warning,
  fix debug message.
  New function _write_msg() to print server messages yellow.
  (wget_test) Add -d to wget command line.
* tests/test-metalink.c (main): Add tests for V3 and V4 metalink
  files read from command line (-i, --force-metalink)
* tests/test.c (test_iri_parse): Add test for slash-less mailto: URI
2016-07-11 14:53:36 +02:00
0aca05a47d * libwget/utils.c: Fix docs, rename function param 2016-02-06 20:58:21 +01:00
dd3c2f63b2 Updated copyright year for all relevant files 2016-01-25 13:06:21 +01:00
3f435c0d1f Add docs for utils functions
* docs/Makefile.am: Add libwget-utils.3
* libwget/utils.c: Add utils function docs
2016-01-19 11:21:37 +01:00
f2c5bfa961 Add gnulib module inline
* autogen.sh: Add gnulib module inline
* configure.ac: Remove AC_C_INLINE
* libwget/hashmap.c: Replace inline by _GL_INLINE
* libwget/iri.c: Replace inline by _GL_INLINE
* libwget/ssl_gnutls.c: Replace inline by _GL_INLINE
* libwget/utils.c: Replace inline by _GL_INLINE
* libwget/xalloc.c: Replace inline by _GL_INLINE,
  include config.h
2016-01-12 17:35:39 +01:00