| 1 | // Copyright (C) 2017 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QHSTS_P_H |
| 5 | #define QHSTS_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists for the convenience |
| 12 | // of the Network Access API. This header file may change from |
| 13 | // version to version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtNetwork/private/qtnetworkglobal_p.h> |
| 19 | |
| 20 | #include <QtNetwork/qhstspolicy.h> |
| 21 | |
| 22 | #include <QtCore/qbytearray.h> |
| 23 | #include <QtCore/qdatetime.h> |
| 24 | #include <QtCore/qstring.h> |
| 25 | #include <QtCore/qglobal.h> |
| 26 | #include <QtCore/qpair.h> |
| 27 | #include <QtCore/qurl.h> |
| 28 | #include <QtCore/qcontainerfwd.h> |
| 29 | |
| 30 | #include <map> |
| 31 | |
| 32 | QT_BEGIN_NAMESPACE |
| 33 | |
| 34 | class ; |
| 35 | |
| 36 | class Q_AUTOTEST_EXPORT QHstsCache |
| 37 | { |
| 38 | public: |
| 39 | |
| 40 | void (const QHttpHeaders &, |
| 41 | const QUrl &url); |
| 42 | void updateFromPolicies(const QList<QHstsPolicy> &hosts); |
| 43 | void updateKnownHost(const QUrl &url, const QDateTime &expires, |
| 44 | bool includeSubDomains); |
| 45 | bool isKnownHost(const QUrl &url) const; |
| 46 | void clear(); |
| 47 | |
| 48 | QList<QHstsPolicy> policies() const; |
| 49 | |
| 50 | #if QT_CONFIG(settings) |
| 51 | void setStore(class QHstsStore *store); |
| 52 | #endif // QT_CONFIG(settings) |
| 53 | |
| 54 | private: |
| 55 | |
| 56 | void updateKnownHost(const QString &hostName, const QDateTime &expires, |
| 57 | bool includeSubDomains); |
| 58 | |
| 59 | struct HostName |
| 60 | { |
| 61 | explicit HostName(const QString &n) : name(n) { } |
| 62 | explicit HostName(QStringView r) : fragment(r) { } |
| 63 | |
| 64 | bool operator < (const HostName &rhs) const |
| 65 | { |
| 66 | if (fragment.size()) { |
| 67 | if (rhs.fragment.size()) |
| 68 | return fragment < rhs.fragment; |
| 69 | return fragment < QStringView{rhs.name}; |
| 70 | } |
| 71 | |
| 72 | if (rhs.fragment.size()) |
| 73 | return QStringView{name} < rhs.fragment; |
| 74 | return name < rhs.name; |
| 75 | } |
| 76 | |
| 77 | // We use 'name' for a HostName object contained in our dictionary; |
| 78 | // we use 'fragment' only during lookup, when chopping the complete host |
| 79 | // name, removing subdomain names (such HostName object is 'transient', it |
| 80 | // must not outlive the original QString object. |
| 81 | QString name; |
| 82 | QStringView fragment; |
| 83 | }; |
| 84 | |
| 85 | mutable std::map<HostName, QHstsPolicy> knownHosts; |
| 86 | #if QT_CONFIG(settings) |
| 87 | QHstsStore *hstsStore = nullptr; |
| 88 | #endif // QT_CONFIG(settings) |
| 89 | }; |
| 90 | |
| 91 | class Q_AUTOTEST_EXPORT |
| 92 | { |
| 93 | public: |
| 94 | |
| 95 | bool (const QHttpHeaders &); |
| 96 | |
| 97 | QDateTime () const { return expiry; } |
| 98 | bool includeSubDomains() const { return subDomainsFound; } |
| 99 | |
| 100 | private: |
| 101 | |
| 102 | bool (); |
| 103 | bool (); |
| 104 | bool (const QByteArray &name, const QByteArray &value); |
| 105 | bool (); |
| 106 | |
| 107 | QByteArray ; |
| 108 | QByteArray ; |
| 109 | |
| 110 | QDateTime ; |
| 111 | int = 0; |
| 112 | bool = false; |
| 113 | qint64 = 0; |
| 114 | bool subDomainsFound = false; |
| 115 | }; |
| 116 | |
| 117 | QT_END_NAMESPACE |
| 118 | |
| 119 | #endif |
| 120 | |