Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qnetworkaccesscache_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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// Qt-Security score:significant reason:default
4
5#ifndef QNETWORKACCESSCACHE_P_H
6#define QNETWORKACCESSCACHE_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of the Network Access API. This header file may change from
14// version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtNetwork/private/qtnetworkglobal_p.h>
20#include "QtCore/qobject.h"
21#include "QtCore/qbasictimer.h"
22#include "QtCore/qbytearray.h"
23#include <QtCore/qflags.h>
24#include "QtCore/qhash.h"
25#include "QtCore/qmetatype.h"
26
28
29class QNetworkRequest;
30class QUrl;
31
32// this class is not about caching files but about
33// caching objects used by QNetworkAccessManager, e.g. existing TCP connections
34// or credentials.
36{
38public:
39 struct Node;
42 {
43 friend class QNetworkAccessCache;
44 QByteArray key;
45 bool expires;
46 bool shareable;
47 qint64 expiryTimeoutSeconds = -1;
48 public:
49 enum class Option {
50 Expires = 0x01,
51 Shareable = 0x02,
52 };
53 typedef QFlags<Option> Options; // #### QTBUG-127269
54
55 virtual ~CacheableObject();
56 virtual void dispose() = 0;
57 inline QByteArray cacheKey() const { return key; }
58 protected:
59 explicit CacheableObject(Options options);
60 };
61
63
64 void clear();
65
66 void addEntry(const QByteArray &key, CacheableObject *entry, qint64 connectionCacheExpiryTimeoutSeconds = -1);
67 bool hasEntry(const QByteArray &key) const;
68 CacheableObject *requestEntryNow(const QByteArray &key);
69 void releaseEntry(const QByteArray &key);
70 void removeEntry(const QByteArray &key);
71
74
75protected:
76 void timerEvent(QTimerEvent *) override;
77
78private:
79 // idea copied from qcache.h
80 NodeHash hash;
81 Node *firstExpiringNode = nullptr;
82 Node *lastExpiringNode = nullptr;
83
84 QBasicTimer timer;
85
86 void linkEntry(const QByteArray &key);
87 bool unlinkEntry(const QByteArray &key);
88 void updateTimer();
89 bool emitEntryReady(Node *node, QObject *target, const char *member);
90};
91
92Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkAccessCache::CacheableObject::Options)
93
94QT_END_NAMESPACE
95
96#endif
The QHttp1Configuration class controls HTTP/1 parameters and settings.
void cacheCredentialsSlot(const QHttpNetworkRequest &request, QAuthenticator *authenticator)
QSharedPointer< char > downloadBuffer
QHttpNetworkReply * httpReply
void readBufferSizeChanged(qint64 size)
void synchronousAuthenticationRequiredSlot(const QHttpNetworkRequest &request, QAuthenticator *)
void synchronousFinishedWithErrorSlot(QNetworkReply::NetworkError errorCode, const QString &detail=QString())
void socketStartedConnecting()
std::shared_ptr< QAtomicInt > pendingDownloadData
void sslErrorsSlot(const QList< QSslError > &errors)
QNetworkAccessCachedHttpConnection * httpConnection
void redirected(const QUrl &url, int httpStatus, int maxRedirectsRemainig)
void downloadMetaData(const QHttpHeaders &, int, const QString &, bool, QSharedPointer< char >, qint64, qint64, bool, bool)
void downloadProgress(qint64, qint64)
QHttpNetworkRequest httpRequest
void preSharedKeyAuthenticationRequiredSlot(QSslPreSharedKeyAuthenticator *authenticator)
QHttp1Configuration http1Parameters
void proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)
void sslErrors(const QList< QSslError > &, bool *, QList< QSslError > *)
void error(QNetworkReply::NetworkError, const QString &)
void synchronousProxyAuthenticationRequiredSlot(const QNetworkProxy &, QAuthenticator *)
void finishedWithErrorSlot(QNetworkReply::NetworkError errorCode, const QString &detail=QString())
std::unique_ptr< QSslConfiguration > incomingSslConfiguration
void readBufferFreed(qint64 size)
QHttp2Configuration http2Parameters
static QThreadStorage< QNetworkAccessCache * > connections
std::shared_ptr< QAtomicInt > pendingDownloadProgress
QNetworkReply::NetworkError incomingErrorCode
void downloadData(const QByteArray &)
std::shared_ptr< QNetworkAccessAuthenticationManager > authenticationManager
void dataReadProgressSlot(qint64 done, qint64 total)
void preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *)
void sslConfigurationChanged(const QSslConfiguration &)
void cacheCredentials(const QUrl &url, const QAuthenticator *auth)
QNetworkAuthenticationCredential fetchCachedCredentials(const QUrl &url, const QAuthenticator *auth=nullptr)
Fetch the credential data from the credential cache.
QNetworkAuthenticationCredential fetchCachedProxyCredentials(const QNetworkProxy &proxy, const QAuthenticator *auth=nullptr)
void cacheProxyCredentials(const QNetworkProxy &proxy, const QAuthenticator *auth)
QHash< QByteArray, Node * > NodeHash
void timerEvent(QTimerEvent *) override
This event handler can be reimplemented in a subclass to receive timer events for the object.
QNetworkAccessCachedHttpConnection(quint16 connectionCount, const QString &hostName, quint16 port, bool encrypt, bool isLocalSocket, QHttpNetworkConnection::ConnectionType connectionType)
The QNetworkAccessManager class allows the application to send network requests and receive replies.
qint64 size() const override
Returns the size of the complete device or -1 if unknown.
bool atEnd() const override
Returns true if everything has been read and the read pointer cannot be advanced anymore.
void processedData(qint64 pos, qint64 amount)
const char * readPointer(qint64 maximumLength, qint64 &len) override
Return a byte pointer for at most maximumLength bytes of that device.
bool advanceReadPointer(qint64 a) override
will advance the internal read pointer by amount bytes.
bool reset() override
Moves the internal read pointer back to the beginning.
\inmodule QtCore
QT_REQUIRE_CONFIG(http)
static QNetworkReply::NetworkError statusCodeFromHttp(int httpStatusCode, const QUrl &url)
static QByteArray makeCacheKey(QUrl &url, QNetworkProxy *proxy, const QString &peerVerifyName)
static QString makeServerErrorString(int code, const QUrl &url, const QString &reasonPhrase)
bool operator<(const QNetworkAuthenticationCredential &t1, const QNetworkAuthenticationCredential &t2)
Q_DECLARE_TYPEINFO(QNetworkAuthenticationCredential, Q_RELOCATABLE_TYPE)