From 2526df506bda99f9497e83a4e6820557a722660e Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Sun, 24 Oct 2021 13:13:12 +0800 Subject: Remove pre-Win10 code paths in QtBase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mostly a removal of dynamically loaded API. They should all exist on Windows 10 1809 (Qt6's minimum supported version). accessibility parts left untouched to make sure MinGW still compiles. Task-number: QTBUG-84432 Pick-to: 6.2 Change-Id: I7a091fc967bd6b9d18ac2de39db16e3b4b9a76ea Reviewed-by: André de la Rocha --- src/network/kernel/qnetworkproxy_win.cpp | 142 ++++++------------------------- 1 file changed, 28 insertions(+), 114 deletions(-) (limited to 'src/network/kernel/qnetworkproxy_win.cpp') diff --git a/src/network/kernel/qnetworkproxy_win.cpp b/src/network/kernel/qnetworkproxy_win.cpp index 30663917ce..b633cd9bbd 100644 --- a/src/network/kernel/qnetworkproxy_win.cpp +++ b/src/network/kernel/qnetworkproxy_win.cpp @@ -45,109 +45,34 @@ #include #include #include -#include #include #include #include #include -#include #include - -/* - * Information on the WinHTTP DLL: - * http://msdn.microsoft.com/en-us/library/aa384122(VS.85).aspx example for WPAD - * - * http://msdn.microsoft.com/en-us/library/aa384097(VS.85).aspx WinHttpGetProxyForUrl - * http://msdn.microsoft.com/en-us/library/aa384096(VS.85).aspx WinHttpGetIEProxyConfigForCurrentUs - * http://msdn.microsoft.com/en-us/library/aa384095(VS.85).aspx WinHttpGetDefaultProxyConfiguration - */ - -// We don't want to include winhttp.h because that's not -// present in some Windows SDKs (I don't know why) -// So, instead, copy the definitions here - -typedef struct { - DWORD dwFlags; - DWORD dwAutoDetectFlags; - LPCWSTR lpszAutoConfigUrl; - LPVOID lpvReserved; - DWORD dwReserved; - BOOL fAutoLogonIfChallenged; -} WINHTTP_AUTOPROXY_OPTIONS; - -typedef struct { - DWORD dwAccessType; - LPWSTR lpszProxy; - LPWSTR lpszProxyBypass; -} WINHTTP_PROXY_INFO; - -typedef struct { - BOOL fAutoDetect; - LPWSTR lpszAutoConfigUrl; - LPWSTR lpszProxy; - LPWSTR lpszProxyBypass; -} WINHTTP_CURRENT_USER_IE_PROXY_CONFIG; - -#define WINHTTP_AUTOPROXY_AUTO_DETECT 0x00000001 -#define WINHTTP_AUTOPROXY_CONFIG_URL 0x00000002 - -#define WINHTTP_AUTO_DETECT_TYPE_DHCP 0x00000001 -#define WINHTTP_AUTO_DETECT_TYPE_DNS_A 0x00000002 - -#define WINHTTP_ACCESS_TYPE_DEFAULT_PROXY 0 -#define WINHTTP_ACCESS_TYPE_NO_PROXY 1 -#define WINHTTP_ACCESS_TYPE_NAMED_PROXY 3 - -#define WINHTTP_NO_PROXY_NAME NULL -#define WINHTTP_NO_PROXY_BYPASS NULL - -#define WINHTTP_ERROR_BASE 12000 -#define ERROR_WINHTTP_LOGIN_FAILURE (WINHTTP_ERROR_BASE + 15) -#define ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT (WINHTTP_ERROR_BASE + 167) -#define ERROR_WINHTTP_AUTODETECTION_FAILED (WINHTTP_ERROR_BASE + 180) +#include QT_BEGIN_NAMESPACE -typedef BOOL (WINAPI * PtrWinHttpGetProxyForUrl)(HINTERNET, LPCWSTR, WINHTTP_AUTOPROXY_OPTIONS*, WINHTTP_PROXY_INFO*); -typedef HINTERNET (WINAPI * PtrWinHttpOpen)(LPCWSTR, DWORD, LPCWSTR, LPCWSTR,DWORD); -typedef BOOL (WINAPI * PtrWinHttpGetDefaultProxyConfiguration)(WINHTTP_PROXY_INFO*); -typedef BOOL (WINAPI * PtrWinHttpGetIEProxyConfigForCurrentUser)(WINHTTP_CURRENT_USER_IE_PROXY_CONFIG*); -typedef BOOL (WINAPI * PtrWinHttpCloseHandle)(HINTERNET); -typedef BOOL (WINAPI * PtrCloseServiceHandle)(SC_HANDLE hSCObject); -static PtrWinHttpGetProxyForUrl ptrWinHttpGetProxyForUrl = 0; -static PtrWinHttpOpen ptrWinHttpOpen = 0; -static PtrWinHttpGetDefaultProxyConfiguration ptrWinHttpGetDefaultProxyConfiguration = 0; -static PtrWinHttpGetIEProxyConfigForCurrentUser ptrWinHttpGetIEProxyConfigForCurrentUser = 0; -static PtrWinHttpCloseHandle ptrWinHttpCloseHandle = 0; - - static bool currentProcessIsService() { - typedef BOOL (WINAPI *PtrGetUserName)(LPTSTR lpBuffer, LPDWORD lpnSize); - typedef BOOL (WINAPI *PtrLookupAccountName)(LPCTSTR lpSystemName, LPCTSTR lpAccountName, PSID Sid, - LPDWORD cbSid, LPTSTR ReferencedDomainName, LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse); - static PtrGetUserName ptrGetUserName = (PtrGetUserName)QSystemLibrary::resolve(QLatin1String("Advapi32"), "GetUserNameW"); - static PtrLookupAccountName ptrLookupAccountName = (PtrLookupAccountName)QSystemLibrary::resolve(QLatin1String("Advapi32"), "LookupAccountNameW"); - - if (ptrGetUserName && ptrLookupAccountName) { - wchar_t userName[UNLEN + 1] = L""; - DWORD size = UNLEN; - if (ptrGetUserName(userName, &size)) { - SID_NAME_USE type = SidTypeUser; - DWORD sidSize = 0; - DWORD domainSize = 0; - // first call is to get the correct size - bool bRet = ptrLookupAccountName(NULL, userName, NULL, &sidSize, NULL, &domainSize, &type); - if (bRet == FALSE && ERROR_INSUFFICIENT_BUFFER != GetLastError()) - return false; - QVarLengthArray buff(sidSize); - QVarLengthArray domainName(domainSize); - // second call to LookupAccountNameW actually gets the SID - // both the pointer to the buffer and the pointer to the domain name should not be NULL - if (ptrLookupAccountName(NULL, userName, buff.data(), &sidSize, domainName.data(), &domainSize, &type)) - return type != SidTypeUser; //returns true if the current user is not a user - } + wchar_t userName[UNLEN + 1] = L""; + DWORD size = UNLEN; + if (GetUserNameW(userName, &size)) { + SID_NAME_USE type = SidTypeUser; + DWORD sidSize = 0; + DWORD domainSize = 0; + // first call is to get the correct size + bool bRet = LookupAccountNameW(NULL, userName, NULL, &sidSize, NULL, &domainSize, &type); + if (bRet == FALSE && ERROR_INSUFFICIENT_BUFFER != GetLastError()) + return false; + QVarLengthArray buff(sidSize); + QVarLengthArray domainName(domainSize); + // second call to LookupAccountNameW actually gets the SID + // both the pointer to the buffer and the pointer to the domain name should not be NULL + if (LookupAccountNameW(NULL, userName, buff.data(), &sidSize, domainName.data(), &domainSize, &type)) + return type != SidTypeUser; //returns true if the current user is not a user } return false; } @@ -456,7 +381,7 @@ QWindowsSystemProxy::QWindowsSystemProxy() QWindowsSystemProxy::~QWindowsSystemProxy() { if (hHttpSession) - ptrWinHttpCloseHandle(hHttpSession); + WinHttpCloseHandle(hHttpSession); } void QWindowsSystemProxy::reset() @@ -486,20 +411,9 @@ void QWindowsSystemProxy::init() proxySettingsWatcher.addLocation(HKEY_LOCAL_MACHINE, QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings")); proxySettingsWatcher.addLocation(HKEY_LOCAL_MACHINE, QStringLiteral("Software\\Policies\\Microsoft\\Windows\\CurrentVersion\\Internet Settings")); - // load the winhttp.dll library - QSystemLibrary lib(L"winhttp"); - if (!lib.load()) - return; // failed to load - - ptrWinHttpOpen = (PtrWinHttpOpen)lib.resolve("WinHttpOpen"); - ptrWinHttpCloseHandle = (PtrWinHttpCloseHandle)lib.resolve("WinHttpCloseHandle"); - ptrWinHttpGetProxyForUrl = (PtrWinHttpGetProxyForUrl)lib.resolve("WinHttpGetProxyForUrl"); - ptrWinHttpGetDefaultProxyConfiguration = (PtrWinHttpGetDefaultProxyConfiguration)lib.resolve("WinHttpGetDefaultProxyConfiguration"); - ptrWinHttpGetIEProxyConfigForCurrentUser = (PtrWinHttpGetIEProxyConfigForCurrentUser)lib.resolve("WinHttpGetIEProxyConfigForCurrentUser"); - // Try to obtain the Internet Explorer configuration. WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyConfig; - const bool hasIEConfig = ptrWinHttpGetIEProxyConfigForCurrentUser(&ieProxyConfig); + const bool hasIEConfig = WinHttpGetIEProxyConfigForCurrentUser(&ieProxyConfig); if (hasIEConfig) { if (ieProxyConfig.lpszAutoConfigUrl) { autoConfigUrl = QString::fromWCharArray(ieProxyConfig.lpszAutoConfigUrl); @@ -524,7 +438,7 @@ void QWindowsSystemProxy::init() // attempt to get the default configuration instead // that config will serve as default if WPAD fails WINHTTP_PROXY_INFO proxyInfo; - if (ptrWinHttpGetDefaultProxyConfiguration(&proxyInfo) && + if (WinHttpGetDefaultProxyConfiguration(&proxyInfo) && proxyInfo.dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY) { // we got information from the registry // overwrite the IE configuration, if any @@ -542,11 +456,11 @@ void QWindowsSystemProxy::init() hHttpSession = NULL; if (ieProxyConfig.fAutoDetect || !autoConfigUrl.isEmpty()) { // open the handle and obtain the options - hHttpSession = ptrWinHttpOpen(L"Qt System Proxy access/1.0", - WINHTTP_ACCESS_TYPE_NO_PROXY, - WINHTTP_NO_PROXY_NAME, - WINHTTP_NO_PROXY_BYPASS, - 0); + hHttpSession = WinHttpOpen(L"Qt System Proxy access/1.0", + WINHTTP_ACCESS_TYPE_NO_PROXY, + WINHTTP_NO_PROXY_NAME, + WINHTTP_NO_PROXY_BYPASS, + 0); if (!hHttpSession) return; @@ -603,7 +517,7 @@ QList QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro urlQueryString = url.toString().left(2083); } - bool getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession, + bool getProxySucceeded = WinHttpGetProxyForUrl(sp->hHttpSession, reinterpret_cast(urlQueryString.utf16()), &sp->autoProxyOptions, &proxyInfo); @@ -621,7 +535,7 @@ QList QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro sp->autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL; sp->autoProxyOptions.lpszAutoConfigUrl = reinterpret_cast(sp->autoConfigUrl.utf16()); - getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession, + getProxySucceeded = WinHttpGetProxyForUrl(sp->hHttpSession, reinterpret_cast(urlQueryString.utf16()), &sp->autoProxyOptions, &proxyInfo); @@ -634,7 +548,7 @@ QList QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro // We first tried without AutoLogon, because this might prevent caching the result. // But now we've to enable it (http://msdn.microsoft.com/en-us/library/aa383153%28v=VS.85%29.aspx) sp->autoProxyOptions.fAutoLogonIfChallenged = TRUE; - getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession, + getProxySucceeded = WinHttpGetProxyForUrl(sp->hHttpSession, reinterpret_cast(urlQueryString.utf16()), &sp->autoProxyOptions, &proxyInfo); -- cgit v1.2.3