Qt 6.x
The Qt SDK
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
35{
36public:
37
38 void updateFromHeaders(const QList<QPair<QByteArray, QByteArray>> &headers,
39 const QUrl &url);
40 void updateFromPolicies(const QList<QHstsPolicy> &hosts);
41 void updateKnownHost(const QUrl &url, const QDateTime &expires,
42 bool includeSubDomains);
43 bool isKnownHost(const QUrl &url) const;
44 void clear();
45
46 QList<QHstsPolicy> policies() const;
47
48#if QT_CONFIG(settings)
49 void setStore(class QHstsStore *store);
50#endif // QT_CONFIG(settings)
51
52private:
53
54 void updateKnownHost(const QString &hostName, const QDateTime &expires,
55 bool includeSubDomains);
56
57 struct HostName
58 {
59 explicit HostName(const QString &n) : name(n) { }
60 explicit HostName(QStringView r) : fragment(r) { }
61
62 bool operator < (const HostName &rhs) const
63 {
64 if (fragment.size()) {
65 if (rhs.fragment.size())
66 return fragment < rhs.fragment;
67 return fragment < QStringView{rhs.name};
68 }
69
70 if (rhs.fragment.size())
71 return QStringView{name} < rhs.fragment;
72 return name < rhs.name;
73 }
74
75 // We use 'name' for a HostName object contained in our dictionary;
76 // we use 'fragment' only during lookup, when chopping the complete host
77 // name, removing subdomain names (such HostName object is 'transient', it
78 // must not outlive the original QString object.
80 QStringView fragment;
81 };
82
83 mutable std::map<HostName, QHstsPolicy> knownHosts;
84#if QT_CONFIG(settings)
85 QHstsStore *hstsStore = nullptr;
86#endif // QT_CONFIG(settings)
87};
88
90{
91public:
92
93 bool parse(const QList<QPair<QByteArray, QByteArray>> &headers);
94
95 QDateTime expirationDate() const { return expiry; }
96 bool includeSubDomains() const { return subDomainsFound; }
97
98private:
99
100 bool parseSTSHeader();
101 bool parseDirective();
102 bool processDirective(const QByteArray &name, const QByteArray &value);
103 bool nextToken();
104
107
108 QDateTime expiry;
109 int tokenPos = 0;
110 bool maxAgeFound = false;
111 qint64 maxAge = 0;
112 bool subDomainsFound = false;
113};
114
116
117#endif
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore\reentrant
Definition qdatetime.h:257
bool includeSubDomains() const
Definition qhsts_p.h:96
QDateTime expirationDate() const
Definition qhsts_p.h:95
Definition qlist.h:74
\inmodule QtCore
Definition qstringview.h:76
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
Definition qurl.h:94
b clear()
Token token
Definition keywords.cpp:444
Combined button and popup list for selecting options.
std::pair< T1, T2 > QPair
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:55
QUrl url("example.com")
[constructor-url-reference]