src/network/access/qnetworkaccessbackend.cpp
changeset 30 5dc02b23752f
parent 29 b72c6db6890b
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
    44 #include "qnetworkrequest.h"
    44 #include "qnetworkrequest.h"
    45 #include "qnetworkreply.h"
    45 #include "qnetworkreply.h"
    46 #include "qnetworkreply_p.h"
    46 #include "qnetworkreply_p.h"
    47 #include "QtCore/qhash.h"
    47 #include "QtCore/qhash.h"
    48 #include "QtCore/qmutex.h"
    48 #include "QtCore/qmutex.h"
       
    49 #include "QtNetwork/qnetworksession.h"
    49 
    50 
    50 #include "qnetworkaccesscachebackend_p.h"
    51 #include "qnetworkaccesscachebackend_p.h"
    51 #include "qabstractnetworkcache.h"
    52 #include "qabstractnetworkcache.h"
       
    53 #include "qhostinfo.h"
    52 
    54 
    53 #include "private/qnoncontiguousbytedevice_p.h"
    55 #include "private/qnoncontiguousbytedevice_p.h"
    54 
    56 
    55 QT_BEGIN_NAMESPACE
    57 QT_BEGIN_NAMESPACE
    56 
    58 
   118 {
   120 {
   119     QNonContiguousByteDevice* device = 0;
   121     QNonContiguousByteDevice* device = 0;
   120 
   122 
   121     if (reply->outgoingDataBuffer)
   123     if (reply->outgoingDataBuffer)
   122         device = QNonContiguousByteDeviceFactory::create(reply->outgoingDataBuffer);
   124         device = QNonContiguousByteDeviceFactory::create(reply->outgoingDataBuffer);
   123     else
   125     else if (reply->outgoingData) {
   124         device = QNonContiguousByteDeviceFactory::create(reply->outgoingData);
   126         device = QNonContiguousByteDeviceFactory::create(reply->outgoingData);
       
   127     } else {
       
   128         return 0;
       
   129     }
   125 
   130 
   126     bool bufferDisallowed =
   131     bool bufferDisallowed =
   127             reply->request.attribute(QNetworkRequest::DoNotBufferUploadDataAttribute,
   132             reply->request.attribute(QNetworkRequest::DoNotBufferUploadDataAttribute,
   128                           QVariant(false)) == QVariant(true);
   133                           QVariant(false)) == QVariant(true);
   129     if (bufferDisallowed)
   134     if (bufferDisallowed)
   320 void QNetworkAccessBackend::authenticationRequired(QAuthenticator *authenticator)
   325 void QNetworkAccessBackend::authenticationRequired(QAuthenticator *authenticator)
   321 {
   326 {
   322     manager->authenticationRequired(this, authenticator);
   327     manager->authenticationRequired(this, authenticator);
   323 }
   328 }
   324 
   329 
       
   330 void QNetworkAccessBackend::cacheCredentials(QAuthenticator *authenticator)
       
   331 {
       
   332     manager->addCredentials(this->reply->url, authenticator);
       
   333 }
       
   334 
   325 void QNetworkAccessBackend::metaDataChanged()
   335 void QNetworkAccessBackend::metaDataChanged()
   326 {
   336 {
   327     reply->metaDataChanged();
   337     reply->metaDataChanged();
   328 }
   338 }
   329 
   339 
   339 #else
   349 #else
   340     Q_UNUSED(errors);
   350     Q_UNUSED(errors);
   341 #endif
   351 #endif
   342 }
   352 }
   343 
   353 
       
   354 #ifndef QT_NO_BEARERMANAGEMENT
       
   355 
       
   356 /*!
       
   357     Starts the backend.  Returns true if the backend is started.  Returns false if the backend
       
   358     could not be started due to an unopened or roaming session.  The caller should recall this
       
   359     function once the session has been opened or the roaming process has finished.
       
   360 */
       
   361 bool QNetworkAccessBackend::start()
       
   362 {
       
   363     if (!manager->networkSession) {
       
   364         open();
       
   365         return true;
       
   366     }
       
   367 
       
   368     // This is not ideal.
       
   369     const QString host = reply->url.host();
       
   370     if (host == QLatin1String("localhost") ||
       
   371         QHostAddress(host) == QHostAddress::LocalHost ||
       
   372         QHostAddress(host) == QHostAddress::LocalHostIPv6) {
       
   373         // Don't need an open session for localhost access.
       
   374         open();
       
   375         return true;
       
   376     }
       
   377 
       
   378     if (manager->networkSession->isOpen() &&
       
   379         manager->networkSession->state() == QNetworkSession::Connected) {
       
   380         open();
       
   381         return true;
       
   382     }
       
   383 
       
   384     return false;
       
   385 }
       
   386 #endif
       
   387 
   344 QT_END_NAMESPACE
   388 QT_END_NAMESPACE