Add wxWebCredentials and use it in SetCredentials()

Prefer using a class encapsulating both the user name and the password
to using a pair of variables.
This commit is contained in:
Vadim Zeitlin
2021-01-10 01:22:40 +01:00
parent fe197d7527
commit 1e6d6be8bb
9 changed files with 87 additions and 24 deletions

View File

@@ -504,12 +504,11 @@ wxWebAuthChallenge::Source wxWebAuthChallenge::GetSource() const
}
void
wxWebAuthChallenge::SetCredentials(const wxString& user,
const wxString& password)
wxWebAuthChallenge::SetCredentials(const wxWebCredentials& cred)
{
wxCHECK_IMPL_VOID();
m_impl->SetCredentials(user, password);
m_impl->SetCredentials(cred);
}
//

View File

@@ -319,9 +319,15 @@ bool wxWebAuthChallengeCURL::Init()
return true;
}
void wxWebAuthChallengeCURL::SetCredentials(const wxString& user, const wxString& password)
void wxWebAuthChallengeCURL::SetCredentials(const wxWebCredentials& cred)
{
wxString authStr = wxString::Format("%s:%s", user, password);
const wxSecretString authStr =
wxString::Format
(
"%s:%s",
cred.GetUser(),
static_cast<const wxString&>(wxSecretString(cred.GetPassword()))
);
curl_easy_setopt(m_request.GetHandle(),
(GetSource() == wxWebAuthChallenge::Source_Proxy) ? CURLOPT_PROXYUSERPWD : CURLOPT_USERPWD,
static_cast<const char*>(authStr.mb_str()));

View File

@@ -505,16 +505,15 @@ bool wxWebAuthChallengeWinHTTP::Init()
}
void
wxWebAuthChallengeWinHTTP::SetCredentials(const wxString& user,
const wxString& password)
wxWebAuthChallengeWinHTTP::SetCredentials(const wxWebCredentials& cred)
{
if ( !::WinHttpSetCredentials
(
m_request.GetHandle(),
m_target,
m_selectedScheme,
user.wc_str(),
password.wc_str(),
cred.GetUser().wc_str(),
wxSecretString(cred.GetPassword()).wc_str(),
wxRESERVED_PARAM
) )
{