Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/network/access/qnetworkaccessftpbackend.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information ([email protected])
     4** All rights reserved.
     5** Contact: Nokia Corporation ([email protected])
    56**
    67** This file is part of the QtNetwork module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you
     37** @nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4343#include "qnetworkaccessmanager_p.h"
    4444#include "QtNetwork/qauthenticator.h"
     45
    4546
    4647#ifndef QT_NO_FTP
     
    8283}
    8384
    84 class QNetworkAccessFtpIODevice: public QIODevice
    85 {
    86     //Q_OBJECT
    87 public:
    88     QNetworkAccessFtpBackend *backend;
    89     bool eof;
    90 
    91     inline QNetworkAccessFtpIODevice(QNetworkAccessFtpBackend *parent)
    92         : QIODevice(parent), backend(parent), eof(false)
    93         { open(ReadOnly); }
    94 
    95     bool isSequential() const { return true; }
    96     bool atEnd() const { return backend->upstreamBytesAvailable() == 0; }
    97 
    98     qint64 bytesAvailable() const { return backend->upstreamBytesAvailable(); }
    99     qint64 bytesToWrite() const { return backend->downstreamBytesToConsume(); }
    100 protected:
    101     qint64 readData(char *data, qint64 maxlen)
    102     {
    103         const QByteArray toSend = backend->readUpstream();
    104         maxlen = qMin<qint64>(maxlen, toSend.size());
    105         if (!maxlen)
    106             return eof ? -1 : 0;
    107 
    108         backend->upstreamBytesConsumed(maxlen);
    109         memcpy(data, toSend.constData(), maxlen);
    110         return maxlen;
    111     }
    112 
    113     qint64 writeData(const char *, qint64)
    114     { return -1; }
    115 
    116     friend class QNetworkAccessFtpBackend;
    117 };
    118 
    119 class QNetworkAccessFtpFtp: public QFtp, public QNetworkAccessCache::CacheableObject
     85class QNetworkAccessCachedFtpConnection: public QFtp, public QNetworkAccessCache::CacheableObject
    12086{
    12187    // Q_OBJECT
    12288public:
    123     QNetworkAccessFtpFtp()
     89    QNetworkAccess()
    12490    {
    12591        setExpires(true);
     
    183149    state = LoggingIn;
    184150
    185     QNetworkAccessCache* cache = QNetworkAccessManagerPrivate::getCache(this);
     151    QNetworkAccessCache* tCache(this);
    186152    QByteArray cacheKey = makeCacheKey(url);
    187     if (!cache->requestEntry(cacheKey, this,
     153    if (!ache->requestEntry(cacheKey, this,
    188154                             SLOT(ftpConnectionReady(QNetworkAccessCache::CacheableObject*)))) {
    189         ftp = new QNetworkAccessFtpFtp;
     155        ftp = new QNetworkAccess;
    190156#ifndef QT_NO_NETWORKPROXY
    191157        if (proxy.type() == QNetworkProxy::FtpCachingProxy)
     
    195161        ftp->login(url.userName(), url.password());
    196162
    197         cache->addEntry(cacheKey, ftp);
     163        ache->addEntry(cacheKey, ftp);
    198164        ftpConnectionReady(ftp);
    199165    }
    200166
    201     uploadDevice = new QNetworkAccessFtpIODevice(this);
     167    // Put operation
     168    if (operation() == QNetworkAccessManager::PutOperation) {
     169        uploadDevice = QNonContiguousByteDeviceFactory::wrap(createUploadByteDevice());
     170        uploadDevice->setParent(this);
     171    }
    202172}
    203173
     
    213183}
    214184
    215 void QNetworkAccessFtpBackend::closeUpstreamChannel()
    216 {
    217     if (operation() == QNetworkAccessManager::PutOperation) {
    218         Q_ASSERT(uploadDevice);
    219         uploadDevice->eof = true;
    220         if (!upstreamBytesAvailable())
    221             emit uploadDevice->readyRead();
    222     }
    223 }
    224 
    225185bool QNetworkAccessFtpBackend::waitForDownstreamReadyRead(int ms)
    226186{
     
    240200}
    241201
    242 bool QNetworkAccessFtpBackend::waitForUpstreamBytesWritten(int ms)
    243 {
    244     Q_UNUSED(ms);
    245     qCritical("QNetworkAccess: FTP backend does not support waitForBytesWritten()");
    246     return false;
    247 }
    248 
    249 void QNetworkAccessFtpBackend::upstreamReadyRead()
    250 {
    251     // uh... how does QFtp operate?
    252 }
    253 
    254202void QNetworkAccessFtpBackend::downstreamReadyWrite()
    255203{
     
    260208void QNetworkAccessFtpBackend::ftpConnectionReady(QNetworkAccessCache::CacheableObject *o)
    261209{
    262     ftp = static_cast<QNetworkAccessFtpFtp *>(o);
     210    ftp = static_cast<QNetworkAccess *>(o);
    263211    connect(ftp, SIGNAL(done(bool)), SLOT(ftpDone()));
    264212    connect(ftp, SIGNAL(rawCommandReply(int,QString)), SLOT(ftpRawCommandReply(int,QString)));
     
    280228
    281229        QByteArray key = makeCacheKey(url());
    282         QNetworkAccessManagerPrivate::getCache(this)->releaseEntry(key);
     230        QNetworkAccessManagerPrivate::getCache(this)->releaseEntry(key);
    283231
    284232        ftp = 0;
     
    331279        // we're not connected, so remove the cache entry:
    332280        QByteArray key = makeCacheKey(url());
    333         QNetworkAccessManagerPrivate::getCache(this)->removeEntry(key);
     281        QNetworkAccessManagerPrivate::getCache(this)->removeEntry(key);
    334282
    335283        disconnect(ftp, 0, this, 0);
     
    408356void QNetworkAccessFtpBackend::ftpReadyRead()
    409357{
    410     writeDownstreamData(ftp->readAll());
     358    QByteArray data = ftp->readAll();
     359    QByteDataBuffer list;
     360    list.append(data);
     361    data.clear(); // important because of implicit sharing!
     362    writeDownstreamData(list);
    411363}
    412364
Note: See TracChangeset for help on using the changeset viewer.