Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qhsts_p.h
Go to the documentation of this file.
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
33
34class QHttpHeaders;
35
37{
38public:
39
40 void updateFromHeaders(const QHttpHeaders &headers,
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
54private:
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.
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
92{
93public:
94
95 bool parse(const QHttpHeaders &headers);
96
97 QDateTime expirationDate() const { return expiry; }
98 bool includeSubDomains() const { return subDomainsFound; }
99
100private:
101
102 bool parseSTSHeader();
103 bool parseDirective();
104 bool processDirective(const QByteArray &name, const QByteArray &value);
105 bool nextToken();
106
109
110 QDateTime expiry;
111 int tokenPos = 0;
112 bool maxAgeFound = false;
113 qint64 maxAge = 0;
114 bool subDomainsFound = false;
115};
116
118
119#endif
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore\reentrant
Definition qdatetime.h:283
bool includeSubDomains() const
Definition qhsts_p.h:98
QDateTime expirationDate() const
Definition qhsts_p.h:97
\inmodule QtCore
Definition qstringview.h:78
constexpr qsizetype size() const noexcept
Returns the size of this string view, in UTF-16 code units (that is, surrogate pairs count as two for...
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
b clear()
Token token
Definition keywords.cpp:444
Combined button and popup list for selecting options.
static QString header(const QString &name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLboolean r
[2]
GLuint name
GLfloat n
static bool operator<(const QSettingsIniKey &k1, const QSettingsIniKey &k2)
#define Q_AUTOTEST_EXPORT
long long qint64
Definition qtypes.h:60
QUrl url("example.com")
[constructor-url-reference]