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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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).
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.
Remove the unnecessary and actually harmful WXDLLIMPEXP_BASE from the
declaration of wxThreadHelperThread and wxThreadHelper classes that only
have inline methods.
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.
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.
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.
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.
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.
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.
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).
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).
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.