Some minor cleanup of the proxy detect
This commit is contained in:
parent
233c901704
commit
b20317ca84
|
@ -210,13 +210,13 @@ bool KICAD_CURL_EASY::SetURL( const std::string& aURL )
|
|||
if( KIPLATFORM::ENV::GetSystemProxyConfig( aURL, cfg ) )
|
||||
{
|
||||
curl_easy_setopt( m_CURL, CURLOPT_PROXY, static_cast<const char*>( cfg.host.c_str() ) );
|
||||
if( cfg.username != "" )
|
||||
if( !cfg.username.empty() )
|
||||
{
|
||||
curl_easy_setopt( m_CURL, CURLOPT_PROXYUSERNAME,
|
||||
static_cast<const char*>( cfg.username.c_str() ) );
|
||||
}
|
||||
|
||||
if( cfg.password != "" )
|
||||
if( !cfg.password.empty() )
|
||||
{
|
||||
curl_easy_setopt( m_CURL, CURLOPT_PROXYPASSWORD,
|
||||
static_cast<const char*>( cfg.password.c_str() ) );
|
||||
|
|
|
@ -122,11 +122,14 @@ wxString KIPLATFORM::ENV::GetUserCachePath()
|
|||
|
||||
bool KIPLATFORM::ENV::GetSystemProxyConfig( const wxString& aURL, PROXY_CONFIG& aCfg )
|
||||
{
|
||||
bool autoProxy = false;
|
||||
// Original source from Microsoft sample (public domain)
|
||||
// https://github.com/microsoft/Windows-classic-samples/blob/main/Samples/WinhttpProxy/cpp/GetProxy.cpp#L844
|
||||
bool autoProxyDetect = false;
|
||||
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyConfig = { 0 };
|
||||
WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions = { 0 };
|
||||
WINHTTP_PROXY_INFO autoProxyInfo = { 0 };
|
||||
HINTERNET session = NULL;
|
||||
bool success = false;
|
||||
|
||||
if( WinHttpGetIEProxyConfigForCurrentUser( &ieProxyConfig ) )
|
||||
{
|
||||
|
@ -134,21 +137,21 @@ bool KIPLATFORM::ENV::GetSystemProxyConfig( const wxString& aURL, PROXY_CONFIG&
|
|||
// we use the ie config simply to handle it off to the other win32 api
|
||||
if( ieProxyConfig.fAutoDetect )
|
||||
{
|
||||
autoProxy = true;
|
||||
autoProxyDetect = true;
|
||||
}
|
||||
|
||||
if( ieProxyConfig.lpszAutoConfigUrl != NULL )
|
||||
{
|
||||
autoProxy = true;
|
||||
autoProxyDetect = true;
|
||||
autoProxyOptions.lpszAutoConfigUrl = ieProxyConfig.lpszAutoConfigUrl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
autoProxy = true;
|
||||
autoProxyDetect = true;
|
||||
}
|
||||
|
||||
if( autoProxy )
|
||||
if( autoProxyDetect )
|
||||
{
|
||||
// either we use the ie url or we set the auto detect mode
|
||||
if( autoProxyOptions.lpszAutoConfigUrl != NULL )
|
||||
|
@ -164,7 +167,7 @@ bool KIPLATFORM::ENV::GetSystemProxyConfig( const wxString& aURL, PROXY_CONFIG&
|
|||
|
||||
autoProxyOptions.fAutoLogonIfChallenged = TRUE;
|
||||
|
||||
autoProxy =
|
||||
autoProxyDetect =
|
||||
WinHttpGetProxyForUrl( session, aURL.c_str(), &autoProxyOptions, &autoProxyInfo );
|
||||
|
||||
if( session )
|
||||
|
@ -173,7 +176,7 @@ bool KIPLATFORM::ENV::GetSystemProxyConfig( const wxString& aURL, PROXY_CONFIG&
|
|||
}
|
||||
}
|
||||
|
||||
if( autoProxy )
|
||||
if( autoProxyDetect )
|
||||
{
|
||||
if( autoProxyInfo.dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY )
|
||||
{
|
||||
|
@ -187,10 +190,8 @@ bool KIPLATFORM::ENV::GetSystemProxyConfig( const wxString& aURL, PROXY_CONFIG&
|
|||
aCfg.host = tokenizer.GetNextToken();
|
||||
}
|
||||
|
||||
return true;
|
||||
success = true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -202,14 +203,41 @@ bool KIPLATFORM::ENV::GetSystemProxyConfig( const wxString& aURL, PROXY_CONFIG&
|
|||
|
||||
if(aCfg.host != ":" && aCfg.host != "::")
|
||||
{
|
||||
return true;
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
// We have to clean up the strings the win32 api returned
|
||||
if( autoProxyInfo.lpszProxy )
|
||||
{
|
||||
GlobalFree( autoProxyInfo.lpszProxy );
|
||||
autoProxyInfo.lpszProxy = NULL;
|
||||
}
|
||||
|
||||
if( autoProxyInfo.lpszProxyBypass )
|
||||
{
|
||||
GlobalFree( autoProxyInfo.lpszProxyBypass );
|
||||
autoProxyInfo.lpszProxyBypass = NULL;
|
||||
}
|
||||
|
||||
if( ieProxyConfig.lpszAutoConfigUrl != NULL )
|
||||
{
|
||||
GlobalFree( ieProxyConfig.lpszAutoConfigUrl );
|
||||
ieProxyConfig.lpszAutoConfigUrl = NULL;
|
||||
}
|
||||
|
||||
if( ieProxyConfig.lpszProxy != NULL )
|
||||
{
|
||||
GlobalFree( ieProxyConfig.lpszProxy );
|
||||
ieProxyConfig.lpszProxy = NULL;
|
||||
}
|
||||
|
||||
if( ieProxyConfig.lpszProxyBypass != NULL )
|
||||
{
|
||||
GlobalFree( ieProxyConfig.lpszProxyBypass );
|
||||
ieProxyConfig.lpszProxyBypass = NULL;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue