summaryrefslogtreecommitdiffstats
path: root/src/network/access
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-09-27 11:08:55 +0200
committerLiang Qi <liang.qi@qt.io>2018-09-27 11:08:55 +0200
commitd0fcaa7eaaae85ddbf0a78efa59b341380c101a4 (patch)
tree9b3422ae33ef9dfcda0af228c56c3d2eeed7b0c3 /src/network/access
parentf6ce2d42b3cbe049ebcf1a2349a5cd4dde2c6d24 (diff)
parent5e64957ee4162ecf4456306a530a68761c2b127f (diff)
Merge remote-tracking branch 'origin/5.11' into 5.12
Conflicts: src/corelib/global/qconfig-bootstrapped.h src/widgets/util/qcompleter.cpp Change-Id: I4f44f0f074982530f2f2e750ce696230b2754cf3
Diffstat (limited to 'src/network/access')
-rw-r--r--src/network/access/access.pri14
-rw-r--r--src/network/access/qftp.cpp4
-rw-r--r--src/network/access/qhsts.cpp19
-rw-r--r--src/network/access/qhsts_p.h8
-rw-r--r--src/network/access/qhstsstore_p.h2
-rw-r--r--src/network/access/qnetworkaccessftpbackend.cpp2
-rw-r--r--src/network/access/qnetworkaccessmanager.cpp13
-rw-r--r--src/network/access/qnetworkaccessmanager_p.h7
-rw-r--r--src/network/access/qnetworkrequest.cpp6
9 files changed, 60 insertions, 15 deletions
diff --git a/src/network/access/access.pri b/src/network/access/access.pri
index b068f96283..8a92308f12 100644
--- a/src/network/access/access.pri
+++ b/src/network/access/access.pri
@@ -24,8 +24,7 @@ HEADERS += \
access/qabstractnetworkcache.h \
access/qnetworkfile_p.h \
access/qhsts_p.h \
- access/qhstspolicy.h \
- access/qhstsstore_p.h
+ access/qhstspolicy.h
SOURCES += \
access/qnetworkaccessauthenticationmanager.cpp \
@@ -45,8 +44,7 @@ SOURCES += \
access/qabstractnetworkcache.cpp \
access/qnetworkfile.cpp \
access/qhsts.cpp \
- access/qhstspolicy.cpp \
- access/qhstsstore.cpp
+ access/qhstspolicy.cpp
qtConfig(ftp) {
HEADERS += \
@@ -66,6 +64,14 @@ qtConfig(networkdiskcache) {
SOURCES += access/qnetworkdiskcache.cpp
}
+qtConfig(settings) {
+ HEADERS += \
+ access/qhstsstore_p.h
+
+ SOURCES += \
+ access/qhstsstore.cpp
+}
+
mac: LIBS_PRIVATE += -framework Security
wasm {
diff --git a/src/network/access/qftp.cpp b/src/network/access/qftp.cpp
index 719e3536b4..feece4ebaf 100644
--- a/src/network/access/qftp.cpp
+++ b/src/network/access/qftp.cpp
@@ -525,7 +525,7 @@ static void _q_parseUnixDir(const QStringList &tokens, const QString &userName,
// Resolve the modification date by parsing all possible formats
QDateTime dateTime;
int n = 0;
-#ifndef QT_NO_DATESTRING
+#if QT_CONFIG(datestring)
do {
dateTime = QLocale::c().toDateTime(dateString, formats.at(n++));
} while (n < formats.size() && (!dateTime.isValid()));
@@ -600,7 +600,7 @@ static void _q_parseDosDir(const QStringList &tokens, const QString &userName, Q
info->setWritable(info->isFile());
QDateTime dateTime;
-#ifndef QT_NO_DATESTRING
+#if QT_CONFIG(datestring)
dateTime = QLocale::c().toDateTime(tokens.at(1), QLatin1String("MM-dd-yy hh:mmAP"));
if (dateTime.date().year() < 1971) {
dateTime.setDate(QDate(dateTime.date().year() + 100,
diff --git a/src/network/access/qhsts.cpp b/src/network/access/qhsts.cpp
index a015feb044..ce70b6af90 100644
--- a/src/network/access/qhsts.cpp
+++ b/src/network/access/qhsts.cpp
@@ -37,13 +37,16 @@
**
****************************************************************************/
-#include "qhstsstore_p.h"
#include "qhsts_p.h"
#include "QtCore/private/qipaddress_p.h"
#include "QtCore/qvector.h"
#include "QtCore/qlist.h"
+#if QT_CONFIG(settings)
+#include "qhstsstore_p.h"
+#endif // QT_CONFIG(settings)
+
QT_BEGIN_NAMESPACE
static bool is_valid_domain_name(const QString &host)
@@ -83,8 +86,10 @@ void QHstsCache::updateFromHeaders(const QList<QPair<QByteArray, QByteArray>> &h
QHstsHeaderParser parser;
if (parser.parse(headers)) {
updateKnownHost(url.host(), parser.expirationDate(), parser.includeSubDomains());
+#if QT_CONFIG(settings)
if (hstsStore)
hstsStore->synchronize();
+#endif // QT_CONFIG(settings)
}
}
@@ -93,12 +98,14 @@ void QHstsCache::updateFromPolicies(const QVector<QHstsPolicy> &policies)
for (const auto &policy : policies)
updateKnownHost(policy.host(), policy.expiry(), policy.includesSubDomains());
+#if QT_CONFIG(settings)
if (hstsStore && policies.size()) {
// These policies are coming either from store or from QNAM's setter
// function. As a result we can notice expired or new policies, time
// to sync ...
hstsStore->synchronize();
}
+#endif // QT_CONFIG(settings)
}
void QHstsCache::updateKnownHost(const QUrl &url, const QDateTime &expires,
@@ -108,8 +115,10 @@ void QHstsCache::updateKnownHost(const QUrl &url, const QDateTime &expires,
return;
updateKnownHost(url.host(), expires, includeSubDomains);
+#if QT_CONFIG(settings)
if (hstsStore)
hstsStore->synchronize();
+#endif // QT_CONFIG(settings)
}
void QHstsCache::updateKnownHost(const QString &host, const QDateTime &expires,
@@ -137,8 +146,10 @@ void QHstsCache::updateKnownHost(const QString &host, const QDateTime &expires,
}
knownHosts.insert(pos, {hostName, newPolicy});
+#if QT_CONFIG(settings)
if (hstsStore)
hstsStore->addToObserved(newPolicy);
+#endif // QT_CONFIG(settings)
return;
}
@@ -149,8 +160,10 @@ void QHstsCache::updateKnownHost(const QString &host, const QDateTime &expires,
else
return;
+#if QT_CONFIG(settings)
if (hstsStore)
hstsStore->addToObserved(newPolicy);
+#endif // QT_CONFIG(settings)
}
bool QHstsCache::isKnownHost(const QUrl &url) const
@@ -187,10 +200,12 @@ bool QHstsCache::isKnownHost(const QUrl &url) const
if (pos != knownHosts.end()) {
if (pos->second.isExpired()) {
knownHosts.erase(pos);
+#if QT_CONFIG(settings)
if (hstsStore) {
// Inform our store that this policy has expired.
hstsStore->addToObserved(pos->second);
}
+#endif // QT_CONFIG(settings)
} else if (!superDomainMatch || pos->second.includesSubDomains()) {
return true;
}
@@ -221,6 +236,7 @@ QVector<QHstsPolicy> QHstsCache::policies() const
return values;
}
+#if QT_CONFIG(settings)
void QHstsCache::setStore(QHstsStore *store)
{
// Caller retains ownership of store, which must outlive this cache.
@@ -248,6 +264,7 @@ void QHstsCache::setStore(QHstsStore *store)
updateFromPolicies(restored);
}
}
+#endif // QT_CONFIG(settings)
// The parser is quite simple: 'nextToken' knowns exactly what kind of tokens
// are valid and it will return false if something else was found; then
diff --git a/src/network/access/qhsts_p.h b/src/network/access/qhsts_p.h
index bc8708341d..c219d9eab5 100644
--- a/src/network/access/qhsts_p.h
+++ b/src/network/access/qhsts_p.h
@@ -69,8 +69,6 @@ QT_BEGIN_NAMESPACE
template<typename T> class QList;
template <typename T> class QVector;
-class QHstsStore;
-
class Q_AUTOTEST_EXPORT QHstsCache
{
public:
@@ -85,7 +83,9 @@ public:
QVector<QHstsPolicy> policies() const;
- void setStore(QHstsStore *store);
+#if QT_CONFIG(settings)
+ void setStore(class QHstsStore *store);
+#endif // QT_CONFIG(settings)
private:
@@ -119,7 +119,9 @@ private:
};
mutable std::map<HostName, QHstsPolicy> knownHosts;
+#if QT_CONFIG(settings)
QHstsStore *hstsStore = nullptr;
+#endif // QT_CONFIG(settings)
};
class Q_AUTOTEST_EXPORT QHstsHeaderParser
diff --git a/src/network/access/qhstsstore_p.h b/src/network/access/qhstsstore_p.h
index 13042839c4..e82596b250 100644
--- a/src/network/access/qhstsstore_p.h
+++ b/src/network/access/qhstsstore_p.h
@@ -53,6 +53,8 @@
#include <QtNetwork/private/qtnetworkglobal_p.h>
+QT_REQUIRE_CONFIG(settings);
+
#include <QtCore/qsettings.h>
#include <QtCore/qvector.h>
diff --git a/src/network/access/qnetworkaccessftpbackend.cpp b/src/network/access/qnetworkaccessftpbackend.cpp
index 269845ed39..fd6589b396 100644
--- a/src/network/access/qnetworkaccessftpbackend.cpp
+++ b/src/network/access/qnetworkaccessftpbackend.cpp
@@ -423,7 +423,7 @@ void QNetworkAccessFtpBackend::ftpRawCommandReply(int code, const QString &text)
if (id == sizeId) {
// reply to the size command
setHeader(QNetworkRequest::ContentLengthHeader, text.toLongLong());
-#ifndef QT_NO_DATESTRING
+#if QT_CONFIG(datestring)
} else if (id == mdtmId) {
QDateTime dt = QDateTime::fromString(text, QLatin1String("yyyyMMddHHmmss"));
setHeader(QNetworkRequest::LastModifiedHeader, dt);
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index 375b8763ee..263469ce38 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -48,6 +48,10 @@
#include "qhstspolicy.h"
#include "qhsts_p.h"
+#if QT_CONFIG(settings)
+#include "qhstsstore_p.h"
+#endif // QT_CONFIG(settings)
+
#include "QtNetwork/qnetworksession.h"
#include "QtNetwork/private/qsharednetworksession_p.h"
@@ -763,9 +767,14 @@ bool QNetworkAccessManager::isStrictTransportSecurityEnabled() const
void QNetworkAccessManager::enableStrictTransportSecurityStore(bool enabled, const QString &storeDir)
{
+#if QT_CONFIG(settings)
Q_D(QNetworkAccessManager);
d->stsStore.reset(enabled ? new QHstsStore(storeDir) : nullptr);
d->stsCache.setStore(d->stsStore.data());
+#else
+ Q_UNUSED(enabled) Q_UNUSED(storeDir)
+ qWarning("HSTS permanent store requires the feature 'settings' enabled");
+#endif // QT_CONFIG(settings)
}
/*!
@@ -779,8 +788,12 @@ void QNetworkAccessManager::enableStrictTransportSecurityStore(bool enabled, con
bool QNetworkAccessManager::isStrictTransportSecurityStoreEnabled() const
{
+#if QT_CONFIG(settings)
Q_D(const QNetworkAccessManager);
return bool(d->stsStore.data());
+#else
+ return false;
+#endif // QT_CONFIG(settings)
}
/*!
diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h
index ffed24a314..5cab4928e4 100644
--- a/src/network/access/qnetworkaccessmanager_p.h
+++ b/src/network/access/qnetworkaccessmanager_p.h
@@ -56,7 +56,6 @@
#include "qnetworkaccesscache_p.h"
#include "qnetworkaccessbackend_p.h"
#include "qnetworkrequest.h"
-#include "qhstsstore_p.h"
#include "qhsts_p.h"
#include "private/qobject_p.h"
#include "QtNetwork/qnetworkproxy.h"
@@ -66,6 +65,10 @@
#include "QtNetwork/qnetworkconfigmanager.h"
#endif
+#if QT_CONFIG(settings)
+#include "qhstsstore_p.h"
+#endif // QT_CONFIG(settings)
+
QT_BEGIN_NAMESPACE
class QAuthenticator;
@@ -215,7 +218,9 @@ public:
Q_AUTOTEST_EXPORT static void clearConnectionCache(QNetworkAccessManager *manager);
QHstsCache stsCache;
+#if QT_CONFIG(settings)
QScopedPointer<QHstsStore> stsStore;
+#endif // QT_CONFIG(settings)
bool stsEnabled = false;
#ifndef QT_NO_BEARERMANAGEMENT
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index 57529761ee..689eecfbb9 100644
--- a/src/network/access/qnetworkrequest.cpp
+++ b/src/network/access/qnetworkrequest.cpp
@@ -47,7 +47,7 @@
#include "QtCore/qdatetime.h"
#include <ctype.h>
-#ifndef QT_NO_DATESTRING
+#if QT_CONFIG(datestring)
# include <stdio.h>
#endif
@@ -1273,7 +1273,7 @@ QDateTime QNetworkHeadersPrivate::fromHttpDate(const QByteArray &value)
int pos = value.indexOf(',');
QDateTime dt;
-#ifndef QT_NO_DATESTRING
+#if QT_CONFIG(datestring)
if (pos == -1) {
// no comma -> asctime(3) format
dt = QDateTime::fromString(QString::fromLatin1(value), Qt::TextDate);
@@ -1300,7 +1300,7 @@ QDateTime QNetworkHeadersPrivate::fromHttpDate(const QByteArray &value)
dt = c.toDateTime(sansWeekday, QLatin1String("dd-MMM-yy hh:mm:ss 'GMT'"));
}
}
-#endif // QT_NO_DATESTRING
+#endif // datestring
if (dt.isValid())
dt.setTimeSpec(Qt::UTC);