6#ifndef QT_NO_NETWORKPROXY
28 wchar_t userName[UNLEN + 1] = L
"";
30 if (GetUserNameW(userName, &
size)) {
31 SID_NAME_USE
type = SidTypeUser;
35 bool bRet = LookupAccountNameW(NULL, userName, NULL, &sidSize, NULL, &domainSize, &
type);
36 if (bRet == FALSE && ERROR_INSUFFICIENT_BUFFER != GetLastError())
42 if (LookupAccountNameW(NULL, userName, buff.
data(), &sidSize, domainName.
data(), &domainSize, &
type))
43 return type != SidTypeUser;
57 if (semicolon != -1 && (
end == -1 || semicolon <
end))
88 if (
entry ==
"<local>"_L1) {
95 const auto netaddrs = iface.addressEntries();
97 if (ipAddress.
isInSubnet(netaddr.ip(), netaddr.prefixLength())) {
109 if (
rx.match(host).hasMatch())
120 QNetworkProxy::Capabilities requiredCaps;
121 switch (
query.queryType()) {
184 bool checkTags = !requiredTag.
isEmpty()
207 if (scheme ==
"http"_L1 || scheme ==
"https"_L1) {
210 }
else if (scheme ==
"socks"_L1 || scheme ==
"socks5"_L1) {
213 }
else if (scheme ==
"ftp"_L1) {
239 if (checkTags && taggedProxies.
contains(requiredTag)) {
248 if (!checkTags || requiredTag !=
"http"_L1) {
253 for (
int i = 0;
i <
result.count();
i++) {
264class QRegistryWatcher {
265 Q_DISABLE_COPY_MOVE(QRegistryWatcher)
267 QRegistryWatcher() =
default;
272 if (RegOpenKeyEx(hive,
reinterpret_cast<const wchar_t*
>(
path.utf16()), 0, KEY_READ, &openedKey) != ERROR_SUCCESS)
275 const DWORD
filter = REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_ATTRIBUTES |
276 REG_NOTIFY_CHANGE_LAST_SET | REG_NOTIFY_CHANGE_SECURITY;
280 if (RegNotifyChangeKeyValue(openedKey,
true,
filter,
handle,
true) != ERROR_SUCCESS) {
284 m_watchEvents.append(
handle);
285 m_registryHandles.append(openedKey);
288 bool hasChanged()
const {
290 WaitForMultipleObjects(m_watchEvents.size(), m_watchEvents.data(),
false, 0) < WAIT_OBJECT_0 + m_watchEvents.size();
293 bool isEmpty()
const {
294 return m_watchEvents.isEmpty();
300 for (HKEY
key :
std::as_const(m_registryHandles))
303 m_watchEvents.clear();
304 m_registryHandles.clear();
307 ~QRegistryWatcher() {
344 : hHttpSession(0), initialized(
false), functional(
false), isAutoConfig(
false)
368 bool proxySettingsChanged =
false;
383 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyConfig;
384 const bool hasIEConfig = WinHttpGetIEProxyConfigForCurrentUser(&ieProxyConfig);
386 if (ieProxyConfig.lpszAutoConfigUrl) {
388 GlobalFree(ieProxyConfig.lpszAutoConfigUrl);
390 if (ieProxyConfig.lpszProxy) {
395 GlobalFree(ieProxyConfig.lpszProxy);
397 if (ieProxyConfig.lpszProxyBypass) {
399 GlobalFree(ieProxyConfig.lpszProxyBypass);
408 WINHTTP_PROXY_INFO proxyInfo;
409 if (WinHttpGetDefaultProxyConfiguration(&proxyInfo) &&
410 proxyInfo.dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY) {
418 if (proxyInfo.lpszProxy)
419 GlobalFree(proxyInfo.lpszProxy);
420 if (proxyInfo.lpszProxyBypass)
421 GlobalFree(proxyInfo.lpszProxyBypass);
427 hHttpSession = WinHttpOpen(L
"Qt System Proxy access/1.0",
428 WINHTTP_ACCESS_TYPE_NO_PROXY,
429 WINHTTP_NO_PROXY_NAME,
430 WINHTTP_NO_PROXY_BYPASS,
441 if (ieProxyConfig.fAutoDetect) {
444 WINHTTP_AUTO_DETECT_TYPE_DNS_A;
463 return sp->defaultResult;
465 if (
sp->isAutoConfig) {
466 WINHTTP_PROXY_INFO proxyInfo;
474 return sp->defaultResult;
481 if (urlQueryString.
size() > 2083) {
484 qWarning(
"Proxy query URL too long for windows API, try with truncated URL");
488 bool getProxySucceeded = WinHttpGetProxyForUrl(
sp->hHttpSession,
489 reinterpret_cast<LPCWSTR
>(urlQueryString.
utf16()),
490 &
sp->autoProxyOptions,
492 DWORD getProxyError = GetLastError();
494 if (!getProxySucceeded
495 && (ERROR_WINHTTP_AUTODETECTION_FAILED == getProxyError)) {
497 if (
sp->autoConfigUrl.isEmpty()) {
500 sp->isAutoConfig =
false;
503 sp->autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL;
504 sp->autoProxyOptions.lpszAutoConfigUrl =
505 reinterpret_cast<LPCWSTR
>(
sp->autoConfigUrl.utf16());
506 getProxySucceeded = WinHttpGetProxyForUrl(
sp->hHttpSession,
507 reinterpret_cast<LPCWSTR
>(urlQueryString.
utf16()),
508 &
sp->autoProxyOptions,
510 getProxyError = GetLastError();
514 if (!getProxySucceeded
515 && (ERROR_WINHTTP_LOGIN_FAILURE == getProxyError)) {
518 sp->autoProxyOptions.fAutoLogonIfChallenged = TRUE;
519 getProxySucceeded = WinHttpGetProxyForUrl(
sp->hHttpSession,
520 reinterpret_cast<LPCWSTR
>(urlQueryString.
utf16()),
521 &
sp->autoProxyOptions,
523 getProxyError = GetLastError();
526 if (!getProxySucceeded
527 && (ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT == getProxyError)) {
530 sp->isAutoConfig =
false;
533 if (getProxySucceeded) {
537 if (proxyInfo.lpszProxy)
538 GlobalFree(proxyInfo.lpszProxy);
539 if (proxyInfo.lpszProxyBypass)
540 GlobalFree(proxyInfo.lpszProxyBypass);
542 if (proxyInfo.dwAccessType == WINHTTP_ACCESS_TYPE_NO_PROXY)
543 return sp->defaultResult;
545 return sp->defaultResult;
554 return sp->defaultResult;
559 return sp->defaultResult;
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
T value(const Key &key) const noexcept
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
The QHostAddress class provides an IP address.
bool isInSubnet(const QHostAddress &subnet, int netmask) const
void setAddress(quint32 ip4Addr)
Set the IPv4 address specified by ip4Addr.
static QPair< QHostAddress, int > parseSubnet(const QString &subnet)
void append(parameter_type t)
The QNetworkAddressEntry class stores one IP address supported by a network interface,...
The QNetworkInterface class provides a listing of the host's IP addresses and network interfaces.
static QList< QNetworkInterface > allInterfaces()
Returns a listing of all the network interfaces found on the host machine.
static QList< QNetworkProxy > systemProxyForQuery(const QNetworkProxyQuery &query=QNetworkProxyQuery())
This function takes the query request, query, examines the details of the type of socket or request a...
The QNetworkProxyQuery class is used to query the proxy settings for a socket.
The QNetworkProxy class provides a network layer proxy.
ProxyType
This enum describes the types of network proxying provided in Qt.
Capabilities capabilities() const
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
QString hostName() const
Returns the host name of the proxy host.
@ SctpTunnelingCapability
@ SctpListeningCapability
quint16 port() const
Returns the port of the proxy host.
static QRegularExpression fromWildcard(QStringView pattern, Qt::CaseSensitivity cs=Qt::CaseInsensitive, WildcardConversionOptions options=DefaultWildcardConversion)
constexpr bool isEmpty() const noexcept
Returns whether this string view is empty - that is, whether {size() == 0}.
constexpr QStringView left(qsizetype n) const noexcept
QString toString() const
Returns a deep copy of this string view's data as a QString.
constexpr QStringView mid(qsizetype pos, qsizetype n=-1) const noexcept
Returns the substring of length length starting at position start in this object.
uint toUInt(bool *ok=nullptr, int base=10) const
Returns the string view converted to an {unsigned int} using base base, which is 10 by default and mu...
\macro QT_RESTRICTED_CAST_FROM_ASCII
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
void clear()
Clears the contents of the string and makes it null.
qsizetype size() const
Returns the number of characters in this string.
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static QString fromWCharArray(const wchar_t *string, qsizetype size=-1)
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
QString url(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
QString scheme() const
Returns the scheme of the URL.
void setScheme(const QString &scheme)
Sets the scheme of the URL to scheme.
QString toString(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
QStringList proxyServerList
QList< QNetworkProxy > defaultResult
WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions
QRegistryWatcher proxySettingsWatcher
list append(new Employee("Blackpool", "Stephen"))
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage return DBusPendingCall DBusPendingCall return DBusPendingCall return dbus_int32_t return DBusServer * server
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
static QStringList splitSpaceSemicolon(const QString &source)
static QList< QNetworkProxy > removeDuplicateProxies(const QList< QNetworkProxy > &proxyList)
static bool isBypassed(const QString &host, const QStringList &bypassList)
static QList< QNetworkProxy > filterProxyListByCapabilities(const QList< QNetworkProxy > &proxyList, const QNetworkProxyQuery &query)
static QList< QNetworkProxy > parseServerList(const QNetworkProxyQuery &query, const QStringList &proxyList)
static bool currentProcessIsService()
GLuint64 GLenum void * handle
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLsizei GLsizei GLchar * source
GLsizei const GLchar *const * path
#define QStringLiteral(str)
QUrl url("example.com")
[constructor-url-reference]