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
qabstractnetworkcache.cpp
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
6#include "qnetworkrequest_p.h"
8
9#include <qdatastream.h>
10#include <qdatetime.h>
11#include <qurl.h>
12#include <qhash.h>
13
14#include <qdebug.h>
15
17
19{
20
21public:
26
28 {
29 return
30 url == other.url
31 && lastModified == other.lastModified
32 && expirationDate == other.expirationDate
33 && saveToDisk == other.saveToDisk
35 }
36
43
44 static void save(QDataStream &out, const QNetworkCacheMetaData &metaData);
45 static void load(QDataStream &in, QNetworkCacheMetaData &metaData);
46};
47Q_GLOBAL_STATIC(QNetworkCacheMetaDataPrivate, metadata_shared_invalid)
48
49
91
96{
97 // QSharedDataPointer takes care of freeing d
98}
99
107
116
131{
132 if (d == other.d)
133 return true;
134 if (d && other.d)
135 return *d == *other.d;
136 return false;
137}
138
151{
152 return !(*d == *metadata_shared_invalid());
153}
154
168{
169 return d->saveToDisk;
170}
171
179{
180 d->saveToDisk = allow;
181}
182
189{
190 return d->url;
191}
192
201{
202 auto *p = d.data();
203 p->url = url;
204 p->url.setPassword(QString());
205 p->url.setFragment(QString());
206}
207
218
228
237{
238 return d->headers;
239}
240
249{
250 d->headers = headers;
251}
252
260
268
276
284
296
308
322
324{
325 out << quint32(hash.size());
328 while (it != end) {
329 out << int(it.key()) << it.value();
330 ++it;
331 }
332 return out;
333}
334
336{
337 // note: if you change the contents of the meta data here
338 // remember to bump the cache version in qnetworkdiskcache.cpp CurrentCacheVersion
339 out << metaData.url();
340 out << metaData.expirationDate();
341 out << metaData.lastModified();
342 out << metaData.saveToDisk();
343 out << metaData.attributes();
344 out << metaData.rawHeaders();
345}
346
360
362{
363 hash.clear();
364 QDataStream::Status oldStatus = in.status();
365 in.resetStatus();
366 hash.clear();
367
368 quint32 n;
369 in >> n;
370
371 for (quint32 i = 0; i < n; ++i) {
372 if (in.status() != QDataStream::Ok)
373 break;
374
375 int k;
376 QVariant t;
377 in >> k >> t;
379 }
380
381 if (in.status() != QDataStream::Ok)
382 hash.clear();
383 if (oldStatus != QDataStream::Ok)
384 in.setStatus(oldStatus);
385 return in;
386}
387
389{
390 auto *p = metaData.d.data();
391 in >> p->url;
392 in >> p->expirationDate;
393 in >> p->lastModified;
394 in >> p->saveToDisk;
395 in >> p->attributes;
397 metaData.setRawHeaders(list);
398}
399
421
429
440
539
540#include "moc_qabstractnetworkcache.cpp"
virtual ~QAbstractNetworkCache()
Destroys the cache.
QAbstractNetworkCache(QObject *parent=nullptr)
Constructs an abstract network cache with the given parent.
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore\reentrant
Definition qdatetime.h:283
const_iterator ConstIterator
Qt-style synonym for QHash::const_iterator.
Definition qhash.h:1289
Definition qlist.h:75
static void save(QDataStream &out, const QNetworkCacheMetaData &metaData)
bool operator==(const QNetworkCacheMetaDataPrivate &other) const
QNetworkCacheMetaData::AttributesMap attributes
static void load(QDataStream &in, QNetworkCacheMetaData &metaData)
The QNetworkCacheMetaData class provides cache information.
bool saveToDisk() const
Returns is this cache should be allowed to be stored on disk.
QDataStream & operator>>(QDataStream &in, QNetworkCacheMetaData &metaData)
void setUrl(const QUrl &url)
Sets the URL this network cache meta data to be url.
void setSaveToDisk(bool allow)
Sets whether this network cache meta data and associated content should be allowed to be stored on di...
void setRawHeaders(const RawHeaderList &headers)
Sets the raw headers to list.
void setExpirationDate(const QDateTime &dateTime)
Sets the date and time when the meta data expires to dateTime.
bool isValid() const
Returns true if this network cache meta data has attributes that have been set otherwise false.
bool operator==(const QNetworkCacheMetaData &other) const
Returns true if this meta data is equal to the other meta data; otherwise returns false.
QUrl url() const
Returns the URL this network cache meta data is referring to.
AttributesMap attributes() const
RawHeaderList rawHeaders() const
Returns a list of all raw headers that are set in this meta data.
void setLastModified(const QDateTime &dateTime)
Sets the date and time when the meta data was last modified to dateTime.
QDateTime lastModified() const
Returns the date and time when the meta data was last modified.
QNetworkCacheMetaData & operator=(QNetworkCacheMetaData &&other) noexcept
QNetworkCacheMetaData()
Constructs an invalid network cache meta data.
QDataStream & operator<<(QDataStream &out, const QNetworkCacheMetaData &metaData)
QDateTime expirationDate() const
Returns the date and time when the meta data expires.
~QNetworkCacheMetaData()
Destroys the network cache meta data.
void setAttributes(const AttributesMap &attributes)
void setHeaders(const QHttpHeaders &headers)
static QHttpHeaders fromRawToHttp(const RawHeadersList &raw)
static RawHeadersList fromHttpToRaw(const QHttpHeaders &headers)
\inmodule QtCore
Definition qobject.h:103
T * data()
Returns a pointer to the shared data object.
Definition qshareddata.h:47
\inmodule QtCore
Definition qshareddata.h:19
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
QString url(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
Definition qurl.cpp:2817
\inmodule QtCore
Definition qvariant.h:65
QHash< int, QWidget * > hash
[35multi]
QSet< QString >::iterator it
Q_NETWORK_EXPORT bool compareStrict(const QHttpHeaders &left, const QHttpHeaders &right)
Combined button and popup list for selecting options.
static QDataStream & operator<<(QDataStream &out, const QNetworkCacheMetaData::AttributesMap &hash)
static QDataStream & operator>>(QDataStream &in, QNetworkCacheMetaData::AttributesMap &hash)
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
GLuint GLuint end
GLfloat n
GLdouble GLdouble t
Definition qopenglext.h:243
GLuint in
GLfloat GLfloat p
[1]
unsigned int quint32
Definition qtypes.h:50
QList< int > list
[14]
QTextStream out(stdout)
[7]
QUrl url("example.com")
[constructor-url-reference]
QDateTime dateTime
[12]
QSharedPointer< T > other(t)
[5]