diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-02-10 22:52:32 (GMT) |
---|---|---|
committer | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-02-10 22:53:49 (GMT) |
commit | 5f885bc5a294cd831f79b5570cb41f3cae2b8b19 (patch) | |
tree | 60240311725d449f33350f0f1012adcb54f45333 /src/network/access | |
parent | d792ec16f29a7cb34bada871127f701ba9480100 (diff) | |
download | Qt-5f885bc5a294cd831f79b5570cb41f3cae2b8b19.zip Qt-5f885bc5a294cd831f79b5570cb41f3cae2b8b19.tar.gz Qt-5f885bc5a294cd831f79b5570cb41f3cae2b8b19.tar.bz2 |
Fix networkAccessEnabled implementation.
Move QDisabledNetworkReply to more appropriate source files.
Return -1 from QDisabledNetworkReply::readData().
Always allow local access (via QNetworkAccessFileBackend).
Diffstat (limited to 'src/network/access')
-rw-r--r-- | src/network/access/qnetworkaccessmanager.cpp | 47 | ||||
-rw-r--r-- | src/network/access/qnetworkreplyimpl.cpp | 24 | ||||
-rw-r--r-- | src/network/access/qnetworkreplyimpl_p.h | 14 |
3 files changed, 43 insertions, 42 deletions
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 7f36570..07a8b1d 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -57,7 +57,6 @@ #include "QtCore/qbuffer.h" #include "QtCore/qurl.h" #include "QtCore/qvector.h" -#include "QtCore/qcoreapplication.h" #include "QtNetwork/qauthenticator.h" #include "QtNetwork/qsslconfiguration.h" #include "QtNetwork/qnetworkconfigmanager.h" @@ -760,46 +759,6 @@ bool QNetworkAccessManager::networkAccessEnabled() const return d->networkAccessEnabled; } -class QDisabledNetworkReply : public QNetworkReply -{ - Q_OBJECT - -public: - QDisabledNetworkReply(QObject *parent, const QNetworkRequest &req, - const QNetworkAccessManager::Operation op); - ~QDisabledNetworkReply(); - - void abort() { } -protected: - qint64 readData(char *, qint64) { return 0; } -}; - -QDisabledNetworkReply::QDisabledNetworkReply(QObject *parent, - const QNetworkRequest &req, - QNetworkAccessManager::Operation op) -: QNetworkReply(parent) -{ - setRequest(req); - setUrl(req.url()); - setOperation(op); - - qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError"); - - QString msg = QCoreApplication::translate("QNetworkAccessManager", - "Network access is disabled."); - setError(UnknownNetworkError, msg); - - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNetworkReply::NetworkError, UnknownNetworkError)); - QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); -} - -QDisabledNetworkReply::~QDisabledNetworkReply() -{ -} - -#include "qnetworkaccessmanager.moc" - /*! Returns a new QNetworkReply object to handle the operation \a op and request \a req. The device \a outgoingData is always 0 for Get and @@ -829,8 +788,12 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera return new QFileNetworkReply(this, req, op); } - if (!d->networkAccessEnabled) + // Return a disabled network reply if network access is disabled. + // Except if the scheme is empty or file://. + if (!d->networkAccessEnabled && !(req.url().scheme() == QLatin1String("file") || + req.url().scheme().isEmpty())) { return new QDisabledNetworkReply(this, req, op); + } QNetworkRequest request = req; if (!request.header(QNetworkRequest::ContentLengthHeader).isValid() && diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 9721e32..3cf21f0 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -856,6 +856,30 @@ bool QNetworkReplyImplPrivate::migrateBackend() return true; } +QDisabledNetworkReply::QDisabledNetworkReply(QObject *parent, + const QNetworkRequest &req, + QNetworkAccessManager::Operation op) +: QNetworkReply(parent) +{ + setRequest(req); + setUrl(req.url()); + setOperation(op); + + qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError"); + + QString msg = QCoreApplication::translate("QNetworkAccessManager", + "Network access is disabled."); + setError(UnknownNetworkError, msg); + + QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, + Q_ARG(QNetworkReply::NetworkError, UnknownNetworkError)); + QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); +} + +QDisabledNetworkReply::~QDisabledNetworkReply() +{ +} + QT_END_NAMESPACE #include "moc_qnetworkreplyimpl_p.cpp" diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h index 89b976f..639361e 100644 --- a/src/network/access/qnetworkreplyimpl_p.h +++ b/src/network/access/qnetworkreplyimpl_p.h @@ -193,6 +193,20 @@ public: Q_DECLARE_PUBLIC(QNetworkReplyImpl) }; +class QDisabledNetworkReply : public QNetworkReply +{ + Q_OBJECT + +public: + QDisabledNetworkReply(QObject *parent, const QNetworkRequest &req, + const QNetworkAccessManager::Operation op); + ~QDisabledNetworkReply(); + + void abort() { } +protected: + qint64 readData(char *, qint64) { return -1; } +}; + QT_END_NAMESPACE #endif |