Qt 4.8
Public Functions | Public Variables | List of all members
QWindowsSystemProxy Class Reference

Public Functions

void init ()
 
 QWindowsSystemProxy ()
 
 ~QWindowsSystemProxy ()
 

Public Variables

QString autoConfigUrl
 
WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions
 
QList< QNetworkProxydefaultResult
 
bool functional
 
HINTERNET hHttpSession
 
bool initialized
 
bool isAutoConfig
 
QMutex mutex
 
QStringList proxyBypass
 
QStringList proxyServerList
 

Detailed Description

Definition at line 365 of file qnetworkproxy_win.cpp.

Constructors and Destructors

◆ QWindowsSystemProxy()

QWindowsSystemProxy::QWindowsSystemProxy ( )

◆ ~QWindowsSystemProxy()

QWindowsSystemProxy::~QWindowsSystemProxy ( )

Definition at line 395 of file qnetworkproxy_win.cpp.

396 {
397  if (hHttpSession)
399 }
static PtrWinHttpCloseHandle ptrWinHttpCloseHandle

Functions

◆ init()

void QWindowsSystemProxy::init ( )

Definition at line 401 of file qnetworkproxy_win.cpp.

Referenced by init().

402 {
403  if (initialized)
404  return;
405  initialized = true;
406 
407 #ifdef Q_OS_WINCE
408  // Windows CE does not have any of the following API
409  return;
410 #else
411  // load the winhttp.dll library
412  QSystemLibrary lib(L"winhttp");
413  if (!lib.load())
414  return; // failed to load
415 
416  ptrWinHttpOpen = (PtrWinHttpOpen)lib.resolve("WinHttpOpen");
417  ptrWinHttpCloseHandle = (PtrWinHttpCloseHandle)lib.resolve("WinHttpCloseHandle");
418  ptrWinHttpGetProxyForUrl = (PtrWinHttpGetProxyForUrl)lib.resolve("WinHttpGetProxyForUrl");
419  ptrWinHttpGetDefaultProxyConfiguration = (PtrWinHttpGetDefaultProxyConfiguration)lib.resolve("WinHttpGetDefaultProxyConfiguration");
420  ptrWinHttpGetIEProxyConfigForCurrentUser = (PtrWinHttpGetIEProxyConfigForCurrentUser)lib.resolve("WinHttpGetIEProxyConfigForCurrentUser");
421  ptrOpenSCManager = (PtrOpenSCManager) QSystemLibrary(L"advapi32").resolve("OpenSCManagerW");
422  ptrEnumServicesStatusEx = (PtrEnumServicesStatusEx) QSystemLibrary(L"advapi32").resolve("EnumServicesStatusExW");
423  ptrCloseServiceHandle = (PtrCloseServiceHandle) QSystemLibrary(L"advapi32").resolve("CloseServiceHandle");
424 
425  // Try to obtain the Internet Explorer configuration.
427  const bool hasIEConfig = ptrWinHttpGetIEProxyConfigForCurrentUser(&ieProxyConfig);
428  if (hasIEConfig) {
429  if (ieProxyConfig.lpszAutoConfigUrl) {
431  GlobalFree(ieProxyConfig.lpszAutoConfigUrl);
432  }
433  if (ieProxyConfig.lpszProxy) {
434  // http://msdn.microsoft.com/en-us/library/aa384250%28VS.85%29.aspx speaks only about a "proxy URL",
435  // not multiple URLs. However we tested this and it can return multiple URLs. So we use splitSpaceSemicolon
436  // on it.
438  GlobalFree(ieProxyConfig.lpszProxy);
439  }
440  if (ieProxyConfig.lpszProxyBypass) {
442  GlobalFree(ieProxyConfig.lpszProxyBypass);
443  }
444  }
445 
446  if (!hasIEConfig ||
448  // no user configuration
449  // attempt to get the default configuration instead
450  // that config will serve as default if WPAD fails
451  WINHTTP_PROXY_INFO proxyInfo;
452  if (ptrWinHttpGetDefaultProxyConfiguration(&proxyInfo) &&
454  // we got information from the registry
455  // overwrite the IE configuration, if any
456 
459  }
460 
461  if (proxyInfo.lpszProxy)
462  GlobalFree(proxyInfo.lpszProxy);
463  if (proxyInfo.lpszProxyBypass)
464  GlobalFree(proxyInfo.lpszProxyBypass);
465  }
466 
467  hHttpSession = NULL;
468  if (ieProxyConfig.fAutoDetect || !autoConfigUrl.isEmpty()) {
469  // open the handle and obtain the options
470  hHttpSession = ptrWinHttpOpen(L"Qt System Proxy access/1.0",
474  0);
475  if (!hHttpSession)
476  return;
477 
478  isAutoConfig = true;
479  memset(&autoProxyOptions, 0, sizeof autoProxyOptions);
481  //Although it is possible to specify dwFlags = WINHTTP_AUTOPROXY_AUTO_DETECT | WINHTTP_AUTOPROXY_CONFIG_URL
482  //this has poor performance (WPAD is attempted for every url, taking 2.5 seconds per interface,
483  //before the configured pac file is used)
484  if (ieProxyConfig.fAutoDetect) {
488  } else {
491  }
492  }
493 
495 #endif
496 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
#define WINHTTP_NO_PROXY_NAME
static PtrEnumServicesStatusEx ptrEnumServicesStatusEx
static QStringList splitSpaceSemicolon(const QString &source)
static PtrCloseServiceHandle ptrCloseServiceHandle
BOOL(WINAPI * PtrWinHttpGetProxyForUrl)(HINTERNET, LPCWSTR, WINHTTP_AUTOPROXY_OPTIONS *, WINHTTP_PROXY_INFO *)
static PtrWinHttpCloseHandle ptrWinHttpCloseHandle
BOOL(WINAPI * PtrWinHttpCloseHandle)(HINTERNET)
#define WINHTTP_AUTOPROXY_AUTO_DETECT
BOOL(WINAPI * PtrEnumServicesStatusEx)(SC_HANDLE hSCManager, SC_ENUM_TYPE InfoLevel, DWORD dwServiceType, DWORD dwServiceState, LPBYTE lpServices, DWORD cbBufSize, LPDWORD pcbBytesNeeded, LPDWORD lpServicesReturned, LPDWORD lpResumeHandle, LPCWSTR pszGroupName)
#define WINHTTP_AUTO_DETECT_TYPE_DHCP
static bool currentProcessIsService()
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
SC_HANDLE(WINAPI * PtrOpenSCManager)(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
#define WINHTTP_ACCESS_TYPE_NAMED_PROXY
BOOL(WINAPI * PtrWinHttpGetIEProxyConfigForCurrentUser)(WINHTTP_CURRENT_USER_IE_PROXY_CONFIG *)
WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions
HINTERNET(WINAPI * PtrWinHttpOpen)(LPCWSTR, DWORD, LPCWSTR, LPCWSTR, DWORD)
#define WINHTTP_ACCESS_TYPE_NO_PROXY
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define WINHTTP_AUTO_DETECT_TYPE_DNS_A
static PtrOpenSCManager ptrOpenSCManager
BOOL(WINAPI * PtrWinHttpGetDefaultProxyConfiguration)(WINHTTP_PROXY_INFO *)
BOOL(WINAPI * PtrCloseServiceHandle)(SC_HANDLE hSCObject)
void * resolve(const char *symbol)
static PtrWinHttpGetDefaultProxyConfiguration ptrWinHttpGetDefaultProxyConfiguration
#define WINHTTP_AUTOPROXY_CONFIG_URL
static PtrWinHttpOpen ptrWinHttpOpen
#define WINHTTP_NO_PROXY_BYPASS
static PtrWinHttpGetIEProxyConfigForCurrentUser ptrWinHttpGetIEProxyConfigForCurrentUser
static PtrWinHttpGetProxyForUrl ptrWinHttpGetProxyForUrl
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

Properties

◆ autoConfigUrl

QString QWindowsSystemProxy::autoConfigUrl

Definition at line 377 of file qnetworkproxy_win.cpp.

Referenced by init().

◆ autoProxyOptions

WINHTTP_AUTOPROXY_OPTIONS QWindowsSystemProxy::autoProxyOptions

Definition at line 375 of file qnetworkproxy_win.cpp.

Referenced by init().

◆ defaultResult

QList<QNetworkProxy> QWindowsSystemProxy::defaultResult

Definition at line 380 of file qnetworkproxy_win.cpp.

Referenced by init(), and QWindowsSystemProxy().

◆ functional

bool QWindowsSystemProxy::functional

Definition at line 383 of file qnetworkproxy_win.cpp.

Referenced by init().

◆ hHttpSession

HINTERNET QWindowsSystemProxy::hHttpSession

Definition at line 374 of file qnetworkproxy_win.cpp.

Referenced by init(), and ~QWindowsSystemProxy().

◆ initialized

bool QWindowsSystemProxy::initialized

Definition at line 382 of file qnetworkproxy_win.cpp.

Referenced by init().

◆ isAutoConfig

bool QWindowsSystemProxy::isAutoConfig

Definition at line 384 of file qnetworkproxy_win.cpp.

Referenced by init().

◆ mutex

QMutex QWindowsSystemProxy::mutex

Definition at line 372 of file qnetworkproxy_win.cpp.

Referenced by init().

◆ proxyBypass

QStringList QWindowsSystemProxy::proxyBypass

Definition at line 379 of file qnetworkproxy_win.cpp.

Referenced by init().

◆ proxyServerList

QStringList QWindowsSystemProxy::proxyServerList

Definition at line 378 of file qnetworkproxy_win.cpp.

Referenced by init().


The documentation for this class was generated from the following file: