Commit Graph

69636 Commits

Author SHA1 Message Date
Vadim Zeitlin
aa7c6c3aa8 Switch to using WinHTTP for parsing URLs
It seems better to rely on the well-tested WinHTTP URL parsing functions
rather than on our own wxURI. It should also allow to support any new
URI schemas if support for them is ever added to WinHTTP.
2021-01-09 21:23:31 +01:00
Vadim Zeitlin
8ace65bbec Use more readable case-insensitive comparison function
IsSameAs(..., false) is not very clear, while CmpNoCase() hopefully is.

No real changes.
2021-01-09 21:06:18 +01:00
Vadim Zeitlin
88a3e9c0a3 Use symbolic constants for HTTP ports and status codes
No real changes, just avoid using raw numbers, which is not very
readable, notably for HTTP_STATUS_PROXY_AUTH_REQ which is not really a
well-known value.
2021-01-09 21:04:18 +01:00
Vadim Zeitlin
5d236edeed Ensure wxWebRequest is in idle state before starting it
Check that current state is State_Idle in wxWebRequest itself only once
instead of doing it in 2 (out of 3) wxWebRequestImpl implementations.

Also assert if this is not the case instead of silently doing nothing
which would surely be more difficult to debug.
2021-01-09 21:00:38 +01:00
Vadim Zeitlin
af13bdde80 Remove redundant assignment in wxWebResponseWinHTTP::GetStatus()
No changes, just remove the unnecessary line -- status was already
initialized as 0.
2021-01-09 20:53:30 +01:00
Vadim Zeitlin
8c0855ad25 Fix test for invalid WinHTTP session handle
INVALID_HANDLE_VALUE is not used for WinHTTP handles and WinHttpOpen()
returns NULL (0) and not INVALID_HANDLE_VALUE (-1).
2021-01-09 18:44:05 +01:00
Vadim Zeitlin
5d256988be Add wxMSWFormatMessage() and use it from other places
Don't duplicate calls to ::FormatMessage(), which is difficult to use
correctly, in wxCrashReport and wxWebRequestWinHTTP, but just reuse the
same code that was already present in wxSysErrorMsgStr() after
refactoring it into a reusable function allowing to specify the module
name to use for the error code lookup (before falling back to
interpreting it as system error code).

This fixes not trimming the trailing "\r\n" from the string in the other
places (wxWinHTTPErrorToString() had code to do it, but it was wrong,
while wxCrashContext::GetExceptionString() didn't do it at all) and
avoids duplication.
2021-01-09 17:41:49 +01:00
Vadim Zeitlin
2869e1ccd6 Implement wxSysErrorMsg() in terms of wxSysErrorMsgStr()
Instead of doing it the other way round, as it has several advantages:

1. wxSysErrorMsgStr() is not limited by the static buffer size any
   longer, i.e. doesn't truncate errors even longer than 1KiB.
2. Code is much simpler and more obviously correct.
3. We avoid an extra and absolutely unnecessary buffer copy.

No real changes.
2021-01-09 17:32:12 +01:00
Vadim Zeitlin
ccd2064ae8 Remove unnecessary use of __WXFUNCTION__ from wxLog code
Just micro cleanup: there doesn't seem to be any need to show which
function we're in as FormatMessage() is only called from a single place
anyhow, so shorten and simplify the code.
2021-01-09 17:21:02 +01:00
Vadim Zeitlin
c70ac66200 Simplify and make more robust wxWebSessionWinHTTP initialization
Rename Init() to Open() as we need this method to return bool to
indicate its success in order to avoid using non-initialized handle
later. Init() is also reserved, by convention, for the common part of
all class ctors in wx code.

Remove m_initialized entirely, it doesn't seem to be obviously better to
cache the failure to create a session than to retry doing it every time
(in fact, it would seem to be worse) and not having it is simpler.

This commit is best viewed ignoring white space.
2021-01-09 16:56:04 +01:00
Vadim Zeitlin
ec2ea5c7fa Handle request still in progress gracefully on shut down
Cancel the request and wait until it actually is cancelled when exiting
the sample.

This is a bit ugly, especially the busy-waiting part, but still better
than potentially crashing.
2021-01-06 23:54:51 +01:00
Vadim Zeitlin
d22956a56a Tiny simplification in wxWebRequestWinHTTP code
Add and use SetFailed(error) function for symmetry with the existing
SetFailedWithLastError().
2021-01-05 00:41:21 +01:00
Vadim Zeitlin
dbc1d9c40e Fix cancelling wxWebRequest under MSW
A cancelled request is not supposed to end up in the "failed" state, but
it did, resulting in showing an error in the webrequest sample after
pressing on the "Cancel" button, which was clearly unwanted.
2021-01-05 00:38:16 +01:00
Vadim Zeitlin
dd23d2cf25 Fix and simplify wxWebRequestImpl objects ref counting
When cancelling a request it was possible for it to be deleted while it
was still used from another thread.

Fix this and make the code much more obviously correct by simply
"locking" the request until the event generated by it is processed: now
IncRef() and DecRef() calls are always balanced as they're called from
ctor and dtor of StateEventProcessor helper only.
2021-01-05 00:26:49 +01:00
Vadim Zeitlin
d2dc11da4f Allow starting request by pressing "Enter" in the sample
Just a small ergonomic improvement.
2021-01-04 23:16:52 +01:00
Vadim Zeitlin
f89781bfdd Simplify status bar updates in the webrequest sample
Use wxLogStatus() to update the status bar, this is shorter and simpler
than using GetStatusBar()->SetStatusText(wxString::Format(...)).

Also use wxFrame::SetStatusText() which forwards to wxStatusBar method
with the same name when we want to just clear the status bar.

No real changes.
2021-01-04 02:13:53 +01:00
Vadim Zeitlin
6e546a3d4b Don't use wxSharedPtr<> in factory registration code
Shared ownership semantics again seems inappropriate here as we're not
actually sharing the pointers here, so just use raw pointers instead
(with C++11 we could use std::unique_ptr<>, but this is impossible with
our own map and scoped pointer implementations).

No real changes.
2021-01-04 02:06:10 +01:00
Vadim Zeitlin
989cafe535 Take raw pointer and not wxSharedPtr<> in SetData()
Using shared pointer seems to be ill-advised here, the stream shouldn't
be shared as it's going to be used by wxWebRequest itself and can't be
used by the application code in parallel, so the ownership transfer
semantics is more appropriate.

We could take a wxScopedPtr<> instead, but wx API takes ownership of raw
pointers everywhere else, so do it here too.

Incidentally fix a bug with calling IsOk() on a possibly null pointer.
2021-01-04 01:57:36 +01:00
Vadim Zeitlin
63f1260739 Skip wxWebRequest authentication tests when using NSURLSession
The NSURLSession-based backend is missing authentication support, so
these tests always fail there, skip them for now.
2020-12-30 14:41:17 +01:00
Vadim Zeitlin
a2a409f7a5 Remove references to non-existent wxWebRequest headers
Remove the platform-specific wxWebRequest headers from the files lists
and from MSVS 200x project files.

This should have been done in e5bd5a926c (Move backend-specific
wxWebRequest headers to private subdirs, 2020-12-26) manually, as
update-setup-h script doesn't remove the old files from the variable
definitions.

It notably fixes CMake build under MSW and Mac, which failed due to not
finding the referenced files.
2020-12-30 14:36:06 +01:00
Vadim Zeitlin
7b6c4cb9e9 Include required module before using check_c_source_compiles()
Fix CMake build with 3.10, which gave the following errors

CMake Error at build/cmake/init.cmake:321 (check_c_source_compiles):
  Unknown CMake command "check_c_source_compiles".
Call Stack (most recent call first):
  build/cmake/main.cmake:16 (include)
  CMakeLists.txt:69 (include)

previously. Apparently the required CheckCSourceCompiles module was
already included from somewhere else with later CMake versions, but not
with this one, so do include it explicitly.
2020-12-30 14:26:06 +01:00
Vadim Zeitlin
50424cba2c Change wxWebRequest and related objects to hide ref counting
Don't force the application code to deal with wxObjectDataPtr<> or,
worse, calling {Inc,Dec}Ref() manually by hiding it inside the wx
objects themselves and giving the value-like semantics to them.

There should be no real changes in the behaviour, but the API does
change significantly. Notably, wxWebRequest is not a wxEvtHandler itself
any longer, as this would be incompatible with the value semantics, and
an event handler needs to be specified when creating it, so that it
could be notified about the request state changes.
2020-12-30 02:02:20 +01:00
Vadim Zeitlin
04bbb844ae Allow constructing/assigning wxObjectDataPtr from compatible type
Generalize copy ctor and assignment operators to allow implicit
conversions from wxObjectDataPtr<D> to wxObjectDataPtr<B> if D is
implicitly convertible to B (e.g. if B is the base class and D is a
class derived from it).

This makes wxObjectDataPtr<> more like standard smart pointer classes
and more useful.
2020-12-30 01:02:47 +01:00
Vadim Zeitlin
be5f1344b6 Add some comments describing wxWebSession methods
No real changes.
2020-12-27 13:01:49 +01:00
Vadim Zeitlin
71d5729171 Make wxWebSessionFactory private
Having wxWebSessionFactory part of the public API implies keeping
compatibility with the possible ways of implementing it which is too
restrictive for no good reason, so move this class to the private header
and don't document it nor wxWebSession::RegisterFactory() (which is now
private).
2020-12-27 01:03:08 +01:00
Vadim Zeitlin
e5bd5a926c Move backend-specific wxWebRequest headers to private subdirs
There is no need to make these headers public and keeping them private
will allow making backwards-incompatible changes to them in the future.
2020-12-26 17:00:07 +01:00
Vadim Zeitlin
8b632bb892 Enable wxWebRequest tests by default
Don't require WX_TEST_WEBREQUEST_URL environment variable to be set, but
only allow defining it to override the default https://httpbin.org value
or to disable the tests by setting it to 0.
2020-12-26 16:43:03 +01:00
Vadim Zeitlin
6a064c85d4 Compile even less code when wxUSE_WEBREQUEST==0 in the test
Move the check slightly higher, there is no need to include the headers
if we're not going to compile any tests anyhow.
2020-12-26 16:00:03 +01:00
Maarten Bent
13d0e0a152 Fix linking with libcurl under MSW when using CMake
Enable CMP0060 policy to use full path for the library.
2020-12-26 15:56:56 +01:00
Maarten Bent
1f504d3c5c Fix using wxThreadHelper in DLL builds
Remove the unnecessary and actually harmful WXDLLIMPEXP_BASE from the
declaration of wxThreadHelperThread and wxThreadHelper classes that only
have inline methods.
2020-12-26 15:54:43 +01:00
Vadim Zeitlin
45757c6728 Fix harmless warnings about unused Objective C methods parameters
Add wxUnusedVar() to suppress them (WXUNUSED() can't be used with
Objective C functions).

No real changes.
2020-12-26 15:26:41 +01:00
Vadim Zeitlin
139db5cc16 Fix harmless warning about missing return type in initWithSession:
The return type defaults to "id" anyhow, but it's better to specify it
explicitly.
2020-12-26 12:31:07 +01:00
Vadim Zeitlin
889e974700 Fix typo in wxWebSessionDelegate name
No real changes, just add the missing "a".
2020-12-13 20:45:18 +01:00
Maarten Bent
2f77cbcdcd Remove accidental empty statement in wxWebRequest curl backend
No real changes, just avoid a warning.
2020-12-13 17:38:30 +01:00
Vadim Zeitlin
373a3f8c57 Remove obsolete Borland hdrstop pragmas from the new code
See f57f214122 (Remove BCC-specific hdrstop pragma from everywhere,
2020-10-12).
2020-12-13 17:29:05 +01:00
Vadim Zeitlin
edd45bd5a1 Disable wxUSE_WEBREQUEST when using MinGW32
We can't compile it with this compiler using WinHTTP backend.
2020-12-13 17:17:06 +01:00
Vadim Zeitlin
76499a3e8b Check curl_multi_init() return value
Return NULL wxWebRequest if this function fails.

Also get rid of another unnecessary Initialize() function.
2020-12-13 17:07:11 +01:00
Vadim Zeitlin
77d25edce2 Translate the error message given in case libcurl init failure
This message is user-visible and so should be translated.
2020-12-13 16:58:57 +01:00
Vadim Zeitlin
7027f66a9a Simplify code by folding {Initialize,Cleanu[}CURL() in the caller
There doesn't seem to be any need to have separate functions when they
are just trivial wrappers.
2020-12-13 16:58:47 +01:00
Vadim Zeitlin
9cc35c54d2 Simplify libcurl initialization by using CURL_GLOBAL_ALL
Using anything else is not recommended by libcurl documentation and it's
not clear why would we need it, so just follow the official advice and
pass CURL_GLOBAL_ALL.
2020-12-13 16:46:24 +01:00
Maarten Bent
ab795fa68c Check for winhttp.h presence in CMake too 2020-12-13 16:35:34 +01:00
Vadim Zeitlin
c6b83194f1 Fix configure wxWebRequest detection and warning logic
Only use wxUSE_WEBREQUEST_{URLSESSION,WINHTTP} under the platforms where
they make sense.

Turn wxUSE_WEBREQUEST off if no backends are available and warn about
it, even under MSW/macOS platforms where this wasn't done previously.
2020-12-13 16:34:47 +01:00
Vadim Zeitlin
181be127a5 Simplify wxUSE_WEBREQUEST_XXX logic
Remove automatic definition of wxUSE_WEBREQUEST depending on whether
wxUSE_WEBREQUEST_XXX are defined and follow the same approach as with
wxUSE_GRAPHICS_XXX, i.e. define wxUSE_WEBREQUEST_XXX as wxUSE_WEBREQUEST
by default instead.

Move wxUSE_WEBREQUEST_WINHTTP to wxMSW-specific file, it doesn't need to
be in common one (unfortunately this can't be done for the Mac-specific
wxUSE_WEBREQUEST_URLSESSION yet, because macOS-specific settings are not
injected into setup.h.in currently).

Also fix test for winhttp.h availability: it seems to be present in all
MinGW64 distributions, but not in MinGW32, so test for this and not for
gcc version.

Finally remove the now unnecessary test for macOS 10.9, as we only
support 10.10+ anyhow by now.
2020-12-13 16:34:47 +01:00
Maarten Bent
b7450f52ff Fixes to CMake build files for wxWebRequest
Fix wrong library name in wx_add_sample() for webrequest.

Also prefer to disable wxWebRequest if no backends for it are available,
for consistency with the other libraries.
2020-12-13 14:36:31 +01:00
Vadim Zeitlin
ff57081ff2 Fix --with-winhttp configure option
It was never defined because USE_WIN32 wasn't set at the time it was
tested. Fix this by just always defining this option, even though it
only makes sense for MSW.

Also fix the test for winhttp.h, it needs to include windows.h first, as
otherwise compiling the header would always fail.
2020-12-13 14:34:28 +01:00
Vadim Zeitlin
893ebbab0c Disable use of build system pkg-config files when cross-compiling
Using build system libraries for a different host doesn't make sense and
can be actively harmful, so set PKG_CONFIG_LIBDIR to prevent pkg-config
from finding them (it, or PKG_CONFIG_PATH, can still be set to some
host-appropriate directory manually before/when running configure).

This obviates the need for the changes in the previous commit, so revert
it.
2020-12-13 14:24:47 +01:00
Vadim Zeitlin
0db857a460 Disable libcurl test when building wxiOS
It's not really useful in this case and somehow breaks Travis CI build.
2020-12-13 03:18:01 +01:00
Vadim Zeitlin
59bc7e59d7 Get rid of public wxWebSession::GetHeaders()
This is unnecessary, it can be protected and we can initialize
wxWebRequest::m_headers directly in its ctor instead of using this
function (which also simplifies code and makes it impossible to forget
to do this).
2020-12-13 03:09:55 +01:00
Vadim Zeitlin
7b7f9fa6c0 Simplify header-parsing code in wxWebResponseCURL
Use BeforeFirst() when we only need to find the first colon instead of
wxSplit().

No real changes (except for pathological case when there is no colon at
all, which wasn't handled correctly by the original code and still
isn't, but in a slightly different way).
2020-12-13 02:53:07 +01:00
Vadim Zeitlin
b37c7417f6 Don't make wxWebRequest::SplitParameters() public
They're not necessary to use this class and we may consider exporting
them later, possibly with a better API and more tests, if really needed.

Also do change their API slightly by leaving only a single function and
returning the value instead of using an out parameter for it to make it
simpler to use.
2020-12-13 02:41:01 +01:00