summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@qt.io>2017-02-23 13:40:30 +0100
committerTimur Pocheptsov <timur.pocheptsov@qt.io>2017-02-24 21:16:09 +0000
commit14db1d5560254766746446069b6f2456e4444602 (patch)
tree55db7f088a5f205944865e8177d536071a2d9b5d /src/network
parente6d23860f08f59caa131bae8ca90f9e36e4dc033 (diff)
HSTS policy - fix API
API-review follow-up: 1. make a ctor explicit 2. add swap member-function 3. make move-assignment inlined 4. make comparison operators non-members 5. make d_ptr QSharedDataPointer (and private implementation - QSharedData). Change-Id: I3257ca03cccd0f1254c9b95461752911359352a5 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qhstspolicy.cpp32
-rw-r--r--src/network/access/qhstspolicy.h25
2 files changed, 30 insertions, 27 deletions
diff --git a/src/network/access/qhstspolicy.cpp b/src/network/access/qhstspolicy.cpp
index e8b4e0aeff..634bf4784b 100644
--- a/src/network/access/qhstspolicy.cpp
+++ b/src/network/access/qhstspolicy.cpp
@@ -63,7 +63,7 @@ QT_BEGIN_NAMESPACE
\sa QNetworkAccessManager::setStrictTransportSecurityEnabled()
*/
-class QHstsPolicyPrivate
+class QHstsPolicyPrivate : public QSharedData
{
public:
QUrl url;
@@ -78,6 +78,15 @@ public:
};
/*!
+ Returns \c true if the two policies have the same host and expiration date
+ while agreeing on whether to include or exclude subdomains.
+*/
+bool operator==(const QHstsPolicy &lhs, const QHstsPolicy &rhs)
+{
+ return *lhs.d == *rhs.d;
+}
+
+/*!
Constructs an invalid (expired) policy with empty host name and subdomains
not included.
*/
@@ -121,17 +130,7 @@ QHstsPolicy::~QHstsPolicy()
*/
QHstsPolicy &QHstsPolicy::operator=(const QHstsPolicy &other)
{
- *d = *other.d;
- return *this;
-}
-
-
-/*!
- Move-assignment operator.
-*/
-QHstsPolicy &QHstsPolicy::operator=(QHstsPolicy &&other) Q_DECL_NOTHROW
-{
- qSwap(d, other.d);
+ d = other.d;
return *this;
}
@@ -196,15 +195,6 @@ bool QHstsPolicy::includesSubDomains() const
}
/*!
- Returns \c true if the two policies have the same host and expiration date
- while agreeing on whether to include or exclude subdomains.
-*/
-bool QHstsPolicy::operator==(const QHstsPolicy &other) const
-{
- return *d == *other.d;
-}
-
-/*!
Return \c true if this policy has a valid expiration date and this date
is greater than QDateTime::currentGetDateTimeUtc().
diff --git a/src/network/access/qhstspolicy.h b/src/network/access/qhstspolicy.h
index 4260ac278c..45fa40dfe8 100644
--- a/src/network/access/qhstspolicy.h
+++ b/src/network/access/qhstspolicy.h
@@ -42,7 +42,7 @@
#include <QtNetwork/qtnetworkglobal.h>
-#include <QtCore/qscopedpointer.h>
+#include <QtCore/qshareddata.h>
#include <QtCore/qurl.h>
QT_BEGIN_NAMESPACE
@@ -55,13 +55,15 @@ class Q_NETWORK_EXPORT QHstsPolicy
public:
QHstsPolicy();
- QHstsPolicy(const QDateTime &expiry, bool includeSubDomains, const QString &host,
- QUrl::ParsingMode mode = QUrl::DecodedMode);
+ explicit QHstsPolicy(const QDateTime &expiry, bool includeSubDomains, const QString &host,
+ QUrl::ParsingMode mode = QUrl::DecodedMode);
QHstsPolicy(const QHstsPolicy &rhs);
QHstsPolicy &operator=(const QHstsPolicy &rhs);
- QHstsPolicy &operator=(QHstsPolicy &&rhs) Q_DECL_NOTHROW;
+ QHstsPolicy &operator=(QHstsPolicy &&other) Q_DECL_NOTHROW { swap(other); return *this; }
~QHstsPolicy();
+ void swap(QHstsPolicy &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
+
void setHost(const QString &host, QUrl::ParsingMode mode = QUrl::DecodedMode);
QString host(QUrl::ComponentFormattingOptions options = QUrl::FullyDecoded) const;
void setExpiry(const QDateTime &expiry);
@@ -69,14 +71,25 @@ public:
void setIncludesSubDomains(bool include);
bool includesSubDomains() const;
- bool operator==(const QHstsPolicy &rhs) const;
bool isExpired() const;
private:
- QScopedPointer<QHstsPolicyPrivate> d;
+ QSharedDataPointer<QHstsPolicyPrivate> d;
+
+ friend Q_NETWORK_EXPORT bool operator==(const QHstsPolicy &lhs, const QHstsPolicy &rhs);
};
+Q_DECLARE_SHARED(QHstsPolicy)
+
+Q_NETWORK_EXPORT bool operator==(const QHstsPolicy &lhs, const QHstsPolicy &rhs);
+
+inline bool operator!=(const QHstsPolicy &lhs, const QHstsPolicy &rhs)
+{
+ return !(lhs == rhs);
+}
+
+
QT_END_NAMESPACE
#endif // QHSTSPOLICY_H