QtNetwork: convert some QDateTime::currentDateTime() to currentDateTimeUtc()
The latter is much faster as it doesn't have to deal with time zones. This change is safe, because the QDateTimes are only used for comparison with other QDateTimes, which, from a quick glance around, seem to be mostly, if not exclusively, in UTC. Comparsions work across time zones, but the comparison between UTC date-times is fastest. Credits to Milian Wolff, from whose QtWS15 talk this advice is taken. Change-Id: I6859d886d8dc8e0a52fbe394fbb7b93a87b4739a Reviewed-by: Milian Wolff <milian.wolff@kdab.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
parent
1e32ade79c
commit
474bee61e4
@ -216,7 +216,7 @@ QList<QNetworkCookie> QNetworkCookieJar::cookiesForUrl(const QUrl &url) const
|
|||||||
// It does not implement a very good cross-domain verification yet.
|
// It does not implement a very good cross-domain verification yet.
|
||||||
|
|
||||||
Q_D(const QNetworkCookieJar);
|
Q_D(const QNetworkCookieJar);
|
||||||
QDateTime now = QDateTime::currentDateTime();
|
const QDateTime now = QDateTime::currentDateTimeUtc();
|
||||||
QList<QNetworkCookie> result;
|
QList<QNetworkCookie> result;
|
||||||
bool isEncrypted = url.scheme().toLower() == QLatin1String("https");
|
bool isEncrypted = url.scheme().toLower() == QLatin1String("https");
|
||||||
|
|
||||||
@ -265,7 +265,7 @@ QList<QNetworkCookie> QNetworkCookieJar::cookiesForUrl(const QUrl &url) const
|
|||||||
bool QNetworkCookieJar::insertCookie(const QNetworkCookie &cookie)
|
bool QNetworkCookieJar::insertCookie(const QNetworkCookie &cookie)
|
||||||
{
|
{
|
||||||
Q_D(QNetworkCookieJar);
|
Q_D(QNetworkCookieJar);
|
||||||
QDateTime now = QDateTime::currentDateTime();
|
const QDateTime now = QDateTime::currentDateTimeUtc();
|
||||||
bool isDeletion = !cookie.isSessionCookie() &&
|
bool isDeletion = !cookie.isSessionCookie() &&
|
||||||
cookie.expirationDate() < now;
|
cookie.expirationDate() < now;
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ public:
|
|||||||
bool isNull() const;
|
bool isNull() const;
|
||||||
#if QT_DEPRECATED_SINCE(5,0)
|
#if QT_DEPRECATED_SINCE(5,0)
|
||||||
QT_DEPRECATED inline bool isValid() const {
|
QT_DEPRECATED inline bool isValid() const {
|
||||||
const QDateTime currentTime = QDateTime::currentDateTime();
|
const QDateTime currentTime = QDateTime::currentDateTimeUtc();
|
||||||
return currentTime >= effectiveDate() &&
|
return currentTime >= effectiveDate() &&
|
||||||
currentTime <= expiryDate() &&
|
currentTime <= expiryDate() &&
|
||||||
!isBlacklisted();
|
!isBlacklisted();
|
||||||
|
@ -215,6 +215,8 @@ init_context:
|
|||||||
return sslContext;
|
return sslContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QDateTime now = QDateTime::currentDateTimeUtc();
|
||||||
|
|
||||||
// Add all our CAs to this store.
|
// Add all our CAs to this store.
|
||||||
foreach (const QSslCertificate &caCertificate, sslContext->sslConfiguration.caCertificates()) {
|
foreach (const QSslCertificate &caCertificate, sslContext->sslConfiguration.caCertificates()) {
|
||||||
// From https://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html:
|
// From https://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html:
|
||||||
@ -228,7 +230,7 @@ init_context:
|
|||||||
// certificates mixed with valid ones.
|
// certificates mixed with valid ones.
|
||||||
//
|
//
|
||||||
// See also: QSslSocketBackendPrivate::verify()
|
// See also: QSslSocketBackendPrivate::verify()
|
||||||
if (caCertificate.expiryDate() >= QDateTime::currentDateTime()) {
|
if (caCertificate.expiryDate() >= now) {
|
||||||
q_X509_STORE_add_cert(q_SSL_CTX_get_cert_store(sslContext->ctx), (X509 *)caCertificate.handle());
|
q_X509_STORE_add_cert(q_SSL_CTX_get_cert_store(sslContext->ctx), (X509 *)caCertificate.handle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1660,6 +1660,7 @@ QList<QSslError> QSslSocketBackendPrivate::verify(const QList<QSslCertificate> &
|
|||||||
setDefaultCaCertificates(defaultCaCertificates() + systemCaCertificates());
|
setDefaultCaCertificates(defaultCaCertificates() + systemCaCertificates());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QDateTime now = QDateTime::currentDateTimeUtc();
|
||||||
foreach (const QSslCertificate &caCertificate, QSslConfiguration::defaultConfiguration().caCertificates()) {
|
foreach (const QSslCertificate &caCertificate, QSslConfiguration::defaultConfiguration().caCertificates()) {
|
||||||
// From https://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html:
|
// From https://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html:
|
||||||
//
|
//
|
||||||
@ -1672,7 +1673,7 @@ QList<QSslError> QSslSocketBackendPrivate::verify(const QList<QSslCertificate> &
|
|||||||
// certificates mixed with valid ones.
|
// certificates mixed with valid ones.
|
||||||
//
|
//
|
||||||
// See also: QSslContext::fromConfiguration()
|
// See also: QSslContext::fromConfiguration()
|
||||||
if (caCertificate.expiryDate() >= QDateTime::currentDateTime()) {
|
if (caCertificate.expiryDate() >= now) {
|
||||||
q_X509_STORE_add_cert(certStore, reinterpret_cast<X509 *>(caCertificate.handle()));
|
q_X509_STORE_add_cert(certStore, reinterpret_cast<X509 *>(caCertificate.handle()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user