Commit Graph

76 Commits

Author SHA1 Message Date
3ff2da8b6f * libwget/http.c: Reorder switch cases in ascending order 2017-05-03 20:48:51 +02:00
5523ae7ab9 * libwget/http.c: Implement Wayback Machine's X-Archive-Orig-last-modified HTTP header 2017-05-03 20:48:35 +02:00
e0b3dc1d26 Make wget_http_connection_t an abstract type
* include/wget/wget.h: Convert wget_http_connection_t to forward declaration
 * libwget/http.h: Move wget_http_connection_t definition here
 * libwget/Makefile.am: Add new file http.h
 * libwget/http.c: Include http.h and add accessor functions
 * libwget/http_highlevel.c: Include http.h
 * src/wget.c: Replace access to wget_http_connection_t with accessor function calls
2017-05-03 15:37:50 +02:00
8a93319b47 Rename strlcpy to wget_strlcpy
* include/wget/wget.h: Rename and remove gnulib deps.
* libwget/strlcpy.c: Rename function and fall back to strlcpy.
* */*.c: Rename strlcpy to wget_strlcpy.
2017-05-02 11:36:51 +02:00
5687254219 Amend --http-proxy and --https-proxy behavior
* libwget/http.c (_parse_proxies): Alloc vector on demand
* src/options.c (wget_http_set_http_proxy): Return # of proxies
  successfully parsed,
  (wget_http_set_https_proxy). Likewise.
* src/options.c (init): Empty and undefined proxy variable is the same.
* tests/test.c (test_set_proxy): Amend tests.
2017-05-02 10:53:03 +02:00
569a646876 Remove unnecessary while loop & add test
* libwget/http.c (_parse_proxies): Remove non-required `while`
* tests/test.c (test_set_proxy): Add test with leading whitespaces
2017-05-02 10:39:57 +02:00
88cc3ead0f Add tests for wget_http_set_http(s)_proxy() functions
* tests/test.c (test_set_proxy): Add tests for wget_http_set_http_proxy()
* tests/test.c (test_set_proxy): Add tests for wget_http_set_https_proxy()
* libwget/http.c (wget_http_set_http_proxy): Return length of http_proxies if no parse error
* libwget/http.c (wget_http_set_https_proxy): Return length of https_proxies if no parse error
2017-05-02 10:36:11 +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
bc06128232 Fix space-tab sequences (syntax-check) 2017-04-29 20:40:14 +02:00
d46ecad443 Add error handler for decompression
* include/wget/wget.h: New functions wget_decompress_set_error_handler()
  and wget_decompress_get_context().
* libwget/decompressor.c: New functions wget_decompress_set_error_handler()
  and wget_decompress_get_context().
* libwget/http.c: Implement and set decompressor error handler.
2017-04-26 12:21:25 +02:00
8f0aa96537 Hide wget_cookie_st
* include/wget/wget.h: Remove struct wget_cookie_st declaration,
  add wget_cookie_to_setcookie(),
  add wget_cookie_parse_setcookie(),
  change wget_http_parse_setcookie() cookie param.
* libwget/cookie.c: Add struct wget_cookie_st declaration,
  (wget_cookie_init): Use xcalloc(),
  (wget_cookie_to_setcookie): New function,
  (wget_cookie_parse_setcookie): New function,
  (_wget_cookie_normalize_cookie): Fix host_only flag.
* libwget/http.c (wget_http_parse_setcookie): Code moved to
  wget_http_parse_setcookie(),
  (wget_http_parse_response_header): Amend cookie handling.
* tests/test.c (test_cookies): Amend test code and test data.
2017-04-20 16:02:18 +02:00
9f2dd3a199 Fix spelling issues found by ka7/misspell_fixer
* include/wget/wget.h: Fix typo
* libwget/base64.c: Likewise
* libwget/http.c: Likewise
* src/wget.c: Likewise
2017-04-19 11:29:55 +02:00
4af4c56b6e *libwget/http.c: Remove unused attribute from used parameters 2017-04-07 16:26:22 +02:00
44bd257de8 * libwget/http.c (wget_http_open): Disable push for HTTP/2 connections 2017-04-07 15:43:20 +02:00
d4f9c8ca48 Fix -Wundef warnings
* libwget/decompressor.c: #if -> #ifdef
* libwget/http.c: Likewise
* libwget/net.c: Likewise
* src/wget.c: Likewise
2017-04-05 16:33:39 +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
c2593de780 * libwget/http.c: Avoid signed integer overflow due to intermediate ptrdiff_t by casting operands to uintptr_t 2017-04-02 21:40:45 +05:30
7171aff7e8 Use atoll() instead of atol() for time_t variables
* libwget/cookie.c: Use atoll() instead of atol()
* libwget/hsts.c: Likewise
* libwget/http.c: Likewise
* libwget/ocsp.c: Likewise
* libwget/tls_session.c: Likewise
* libwget/hpkp.c: Change type of maxage from long to time_t
2017-03-29 16:18:26 +02:00
52e7349c12 Fix resource leak
* libwget/http.c (_on_header_callback): Prevent leaking memory when
there is an empty HTTP2 response

Reported-by: Coverity Scan (cid: 165231)
2017-03-28 13:23:55 +02:00
62a41fbd2d Fix regression regarding chunked transfer-encoding
* libwget/http.c (wget_http_get_response_cb): Save data when chunk
  complete in one data packet.
* tests/Makefile.am: Add new test 'test-chunked'
* tests/test-chunked.c: New test
2017-03-25 20:35:05 +01:00
12d4cafa2d Fix chunk overflow in HTTP download for 32bit systems
* libwget/http.c: Check for pointer overflow
* tests/test-bad-chunk.c: Adjust tests

Reported-by: Dagobert Michelsen
2017-03-23 11:25:21 +01:00
c415b03df6 * libwget/hsts.c: Be compliant with Wget 1.x 2017-03-08 11:45:24 +01:00
01d445b8db Fix crash on unexpected server PUSH PROMISE (http/2)
* libwget/http.c (_on_frame_recv_callback): Check for valid context,
  (_on_header_callback): Likewise
2017-03-03 11:57:14 +01:00
e01926d2e2 Allow new 'expires' format for Set-Cookie header
* libwget/http.c (wget_http_parse_full_date): Allow format
  '1 Mar 2027 09:23:12 GMT'
* tests/test.c (test_cookies): Test new format
2017-03-03 10:45:01 +01:00
4a7cebd3fa * libwget/http.c (_on_frame_recv_callback): Fix decompressor init 2017-03-01 16:29:40 +01:00
ec396c577f Fix URLs to HTTPS where possible 2017-02-28 15:31:30 +01:00
5ad2356257 * libwget/http.c (wget_http_get_response): Check if body member is set 2017-02-28 12:57:05 +01:00
5b2888ac9c Add brotli decompression, Accept-Encoding 'br' 2017-02-24 12:59:55 +01:00
2b448ffa92 Fix memleak in HPKP
* include/wget/wget.h: Changed declaration of wget_hpkp_free()
* libwget/hpkp.c: Use wget_hpkp_free() as destructor function
* libwget/http.c (wget_http_free_hpkp_entries): Amended
* tests/test.c: Fix typos
2017-02-22 13:16:40 +01:00
afc4d5a1af HPKP API redesign 2017-02-22 13:16:40 +01:00
89fed7e4db HPKP: Fix memory leaks
* src/wget.c (main, process_response_header): add debug traces
 * libwget/http.c (wget_http_parse_public_key_pins): fix memory leaks
 * libwget/hpkp.c (__wget_hpkp_free, wget_hpkp_db_load): fix memory
   leaks
2017-02-22 13:13:54 +01:00
4d263eb628 HPKP: use vector rather than linked list for b64 pins 2017-02-22 13:13:54 +01:00
17e2d3d2f9 HPKP: add log traces + fix bugs 2017-02-22 13:13:54 +01:00
584b15e67e Prototype HPKP functions
* include/wget/wget.h: new public function wget_hpkp_db_init().
 * libwget/hpkp.c: new file.
2017-02-22 12:46:01 +01:00
874a209fb4 HPKP: initial commit 2017-02-22 12:46:01 +01:00
bfcd65c12b Use typedefs for function pointer arguments
* include/wget/wget.h: Add typedefs
* libwget/cookie.c: Use typedefs
* libwget/css.c: Likewise
* libwget/css_url.c: Likewise
* libwget/decompressor.c: Likewise
* libwget/hashmap.c: Likewise
* libwget/hsts.c: Likewise
* libwget/http.c: Likewise
* libwget/init.c: Likewise
* libwget/io.c: Likewise
* libwget/list.c: Likewise
* libwget/logger.c: Likewise
* libwget/metalink.c: Likewise
* libwget/net.c: Likewise
* libwget/netrc.c: Likewise
* libwget/ocsp.c: Likewise
* libwget/private.h: Likewise
* libwget/robots.c: Likewise
* libwget/stringmap.c: Likewise
* libwget/tls_session.c: Likewise
* libwget/vector.c: Likewise
* libwget/xml.c: Likewise
* src/blacklist.c: Likewise
* src/host.c: Likewise
* src/options.c: Likewise
* src/wget.c: Likewise
* tests/stringmap_perf.c: Likewise
* tests/test.c: Likewise
2017-01-23 14:43:17 +01:00
43f30f309e Rename wget_str_[v]asprintf to wget_[v]aprintf
* include/wget/wget.h: Rename wget_str_[v]asprintf to wget_[v]aprintf
* libwget/http.c: Likewise
* libwget/iri.c: Likewise
* libwget/printf.c: Likewise
* libwget/vector.c: Likewise
* src/options.c: Likewise
* tests/test-metalink.c: Likewise
2016-12-21 11:54:36 +01:00
40b8da056e Reduce redundant code by using strchrnul()
* bootstrap.conf: Add gnulib module strchrnul
* libwget/http.c (_parse_proxies): Remove redundant code
* libwget/ssl_gnutls.c (wget_ssl_open): Likewise
2016-12-16 15:41:58 +01:00
82bd6fee89 * libwget/http.c: Ignore Transfer-Encoding for HTTP/2 requests 2016-12-02 16:41:25 +01:00
8b1a701c21 Use wget_strdup() instead of strdup()
* examples/getstream.c: Use wget_strdup().
* libwget/cookie.c: Likewise.
* libwget/encoding.c: Likewise.
* libwget/http.c: Likewise.
* libwget/iri.c: Likewise.
* libwget/netrc.c: Likewise.
* src/options.c: Likewise.
* src/wget.c: Likewise.
* tests/test.c: Likewise.
2016-11-03 09:58:09 +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
5225421c31 Make --header replace wget's standard headers
* libwget/http.c (wget_http_create_request): Add 'Host' header
  to header list,
  (wget_http_send_request): Do not add 'Host' hard-coded,
  (wget_http_request_to_buffer): Special treatment of 'Content-Length'
* src/wget.c (http_create_request): Replace wget's HTTP headers by
  user-provided headers, except 'Cookie' headers which will be appended.
2016-10-14 12:51:12 +02:00
21099bcf7f * libwget/http.c: Fix update of downloaded bytes for progress bar 2016-10-11 15:56:54 +02:00
bc0fc2b28d * libwget/http.c: Support compression for HTTP/2 2016-10-10 15:44:55 +02:00
7be16cf925 * libwget/http.c: Remove unused struct _body_callback_context 2016-10-03 13:04:22 +02:00
9568b0c87e Rename include/libwget.h to include/wget/wget.h+wgetver.h 2016-09-30 09:47:32 +02:00
849cc8acd0 * libwget/http.c: Check WITH_LIBNGHTTP2 before referring nghttp2_nv 2016-09-28 19:36:30 +02:00
664cbc14ee Fix race condition when pipelining reuqests
* libwget/http.c: Add streamid to debug messages
* src/progress.h: Remove member downloader and head from _body_callback_context
* src/wget.c (downloader_thread): Keep track of locking,
  (_get_header): Remove reference to downloader,
  (http_send_request): Replace downloader with job

With HTTP/2 pipelining (parallel streams per connection) is active.
The bug fixed stops file descriptor leaks and writing data into wrong
files.
2016-09-28 17:07:19 +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