| 1 | /****************************************************************************
 | 
|---|
| 2 | ** $Id: qftp.h 2 2005-11-16 15:49:26Z dmik $
 | 
|---|
| 3 | **
 | 
|---|
| 4 | ** Definition of QFtp class.
 | 
|---|
| 5 | **
 | 
|---|
| 6 | ** Created : 970521
 | 
|---|
| 7 | **
 | 
|---|
| 8 | ** Copyright (C) 1997-2000 Trolltech AS.  All rights reserved.
 | 
|---|
| 9 | **
 | 
|---|
| 10 | ** This file is part of the network module of the Qt GUI Toolkit.
 | 
|---|
| 11 | **
 | 
|---|
| 12 | ** This file may be distributed under the terms of the Q Public License
 | 
|---|
| 13 | ** as defined by Trolltech AS of Norway and appearing in the file
 | 
|---|
| 14 | ** LICENSE.QPL included in the packaging of this file.
 | 
|---|
| 15 | **
 | 
|---|
| 16 | ** This file may be distributed and/or modified under the terms of the
 | 
|---|
| 17 | ** GNU General Public License version 2 as published by the Free Software
 | 
|---|
| 18 | ** Foundation and appearing in the file LICENSE.GPL included in the
 | 
|---|
| 19 | ** packaging of this file.
 | 
|---|
| 20 | **
 | 
|---|
| 21 | ** Licensees holding valid Qt Enterprise Edition licenses may use this
 | 
|---|
| 22 | ** file in accordance with the Qt Commercial License Agreement provided
 | 
|---|
| 23 | ** with the Software.
 | 
|---|
| 24 | **
 | 
|---|
| 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 | 
|---|
| 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 | 
|---|
| 27 | **
 | 
|---|
| 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 | 
|---|
| 29 | **   information about Qt Commercial License Agreements.
 | 
|---|
| 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
 | 
|---|
| 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
 | 
|---|
| 32 | **
 | 
|---|
| 33 | ** Contact info@trolltech.com if any conditions of this licensing are
 | 
|---|
| 34 | ** not clear to you.
 | 
|---|
| 35 | **
 | 
|---|
| 36 | **********************************************************************/
 | 
|---|
| 37 | 
 | 
|---|
| 38 | #ifndef QFTP_H
 | 
|---|
| 39 | #define QFTP_H
 | 
|---|
| 40 | 
 | 
|---|
| 41 | #ifndef QT_H
 | 
|---|
| 42 | #include "qstring.h" // char*->QString conversion
 | 
|---|
| 43 | #include "qurlinfo.h"
 | 
|---|
| 44 | #include "qnetworkprotocol.h"
 | 
|---|
| 45 | #endif // QT_H
 | 
|---|
| 46 | 
 | 
|---|
| 47 | #if !defined( QT_MODULE_NETWORK ) || defined( QT_LICENSE_PROFESSIONAL ) || defined( QT_INTERNAL_NETWORK )
 | 
|---|
| 48 | #define QM_EXPORT_FTP
 | 
|---|
| 49 | #else
 | 
|---|
| 50 | #define QM_EXPORT_FTP Q_EXPORT
 | 
|---|
| 51 | #endif
 | 
|---|
| 52 | 
 | 
|---|
| 53 | #ifndef QT_NO_NETWORKPROTOCOL_FTP
 | 
|---|
| 54 | 
 | 
|---|
| 55 | 
 | 
|---|
| 56 | class QSocket;
 | 
|---|
| 57 | class QFtpCommand;
 | 
|---|
| 58 | 
 | 
|---|
| 59 | class QM_EXPORT_FTP QFtp : public QNetworkProtocol
 | 
|---|
| 60 | {
 | 
|---|
| 61 |     Q_OBJECT
 | 
|---|
| 62 | 
 | 
|---|
| 63 | public:
 | 
|---|
| 64 |     QFtp(); // ### Qt 4.0: get rid of this overload
 | 
|---|
| 65 |     QFtp( QObject *parent, const char *name=0 );
 | 
|---|
| 66 |     virtual ~QFtp();
 | 
|---|
| 67 | 
 | 
|---|
| 68 |     int supportedOperations() const;
 | 
|---|
| 69 | 
 | 
|---|
| 70 |     // non-QNetworkProtocol functions:
 | 
|---|
| 71 |     enum State {
 | 
|---|
| 72 |         Unconnected,
 | 
|---|
| 73 |         HostLookup,
 | 
|---|
| 74 |         Connecting,
 | 
|---|
| 75 |         Connected,
 | 
|---|
| 76 |         LoggedIn,
 | 
|---|
| 77 |         Closing
 | 
|---|
| 78 |     };
 | 
|---|
| 79 |     enum Error {
 | 
|---|
| 80 |         NoError,
 | 
|---|
| 81 |         UnknownError,
 | 
|---|
| 82 |         HostNotFound,
 | 
|---|
| 83 |         ConnectionRefused,
 | 
|---|
| 84 |         NotConnected
 | 
|---|
| 85 |     };
 | 
|---|
| 86 |     enum Command {
 | 
|---|
| 87 |         None,
 | 
|---|
| 88 |         ConnectToHost,
 | 
|---|
| 89 |         Login,
 | 
|---|
| 90 |         Close,
 | 
|---|
| 91 |         List,
 | 
|---|
| 92 |         Cd,
 | 
|---|
| 93 |         Get,
 | 
|---|
| 94 |         Put,
 | 
|---|
| 95 |         Remove,
 | 
|---|
| 96 |         Mkdir,
 | 
|---|
| 97 |         Rmdir,
 | 
|---|
| 98 |         Rename,
 | 
|---|
| 99 |         RawCommand
 | 
|---|
| 100 |     };
 | 
|---|
| 101 | 
 | 
|---|
| 102 |     int connectToHost( const QString &host, Q_UINT16 port=21 );
 | 
|---|
| 103 |     int login( const QString &user=QString::null, const QString &password=QString::null );
 | 
|---|
| 104 |     int close();
 | 
|---|
| 105 |     int list( const QString &dir=QString::null );
 | 
|---|
| 106 |     int cd( const QString &dir );
 | 
|---|
| 107 |     int get( const QString &file, QIODevice *dev=0 );
 | 
|---|
| 108 |     int put( const QByteArray &data, const QString &file );
 | 
|---|
| 109 |     int put( QIODevice *dev, const QString &file );
 | 
|---|
| 110 |     int remove( const QString &file );
 | 
|---|
| 111 |     int mkdir( const QString &dir );
 | 
|---|
| 112 |     int rmdir( const QString &dir );
 | 
|---|
| 113 |     int rename( const QString &oldname, const QString &newname );
 | 
|---|
| 114 | 
 | 
|---|
| 115 |     int rawCommand( const QString &command );
 | 
|---|
| 116 | 
 | 
|---|
| 117 |     Q_ULONG bytesAvailable() const;
 | 
|---|
| 118 |     Q_LONG readBlock( char *data, Q_ULONG maxlen );
 | 
|---|
| 119 |     QByteArray readAll();
 | 
|---|
| 120 | 
 | 
|---|
| 121 |     int currentId() const;
 | 
|---|
| 122 |     QIODevice* currentDevice() const;
 | 
|---|
| 123 |     Command currentCommand() const;
 | 
|---|
| 124 |     bool hasPendingCommands() const;
 | 
|---|
| 125 |     void clearPendingCommands();
 | 
|---|
| 126 | 
 | 
|---|
| 127 |     State state() const;
 | 
|---|
| 128 | 
 | 
|---|
| 129 |     Error error() const;
 | 
|---|
| 130 |     QString errorString() const;
 | 
|---|
| 131 | 
 | 
|---|
| 132 | public slots:
 | 
|---|
| 133 |     void abort();
 | 
|---|
| 134 | 
 | 
|---|
| 135 | signals:
 | 
|---|
| 136 |     void stateChanged( int );
 | 
|---|
| 137 |     void listInfo( const QUrlInfo& );
 | 
|---|
| 138 |     void readyRead();
 | 
|---|
| 139 |     void dataTransferProgress( int, int );
 | 
|---|
| 140 |     void rawCommandReply( int, const QString& );
 | 
|---|
| 141 | 
 | 
|---|
| 142 |     void commandStarted( int );
 | 
|---|
| 143 |     void commandFinished( int, bool );
 | 
|---|
| 144 |     void done( bool );
 | 
|---|
| 145 | 
 | 
|---|
| 146 | protected:
 | 
|---|
| 147 |     void parseDir( const QString &buffer, QUrlInfo &info ); // ### Qt 4.0: delete this? (not public API)
 | 
|---|
| 148 |     void operationListChildren( QNetworkOperation *op );
 | 
|---|
| 149 |     void operationMkDir( QNetworkOperation *op );
 | 
|---|
| 150 |     void operationRemove( QNetworkOperation *op );
 | 
|---|
| 151 |     void operationRename( QNetworkOperation *op );
 | 
|---|
| 152 |     void operationGet( QNetworkOperation *op );
 | 
|---|
| 153 |     void operationPut( QNetworkOperation *op );
 | 
|---|
| 154 | 
 | 
|---|
| 155 |     // ### Qt 4.0: delete these
 | 
|---|
| 156 |     // unused variables:
 | 
|---|
| 157 |     QSocket *commandSocket, *dataSocket;
 | 
|---|
| 158 |     bool connectionReady, passiveMode;
 | 
|---|
| 159 |     int getTotalSize, getDoneSize;
 | 
|---|
| 160 |     bool startGetOnFail;
 | 
|---|
| 161 |     int putToWrite, putWritten;
 | 
|---|
| 162 |     bool errorInListChildren;
 | 
|---|
| 163 | 
 | 
|---|
| 164 | private:
 | 
|---|
| 165 |     void init();
 | 
|---|
| 166 |     int addCommand( QFtpCommand * );
 | 
|---|
| 167 | 
 | 
|---|
| 168 |     bool checkConnection( QNetworkOperation *op );
 | 
|---|
| 169 | 
 | 
|---|
| 170 | private slots:
 | 
|---|
| 171 |     void startNextCommand();
 | 
|---|
| 172 |     void piFinished( const QString& );
 | 
|---|
| 173 |     void piError( int, const QString& );
 | 
|---|
| 174 |     void piConnectState( int );
 | 
|---|
| 175 |     void piFtpReply( int, const QString& );
 | 
|---|
| 176 | 
 | 
|---|
| 177 | private slots:
 | 
|---|
| 178 |     void npListInfo( const QUrlInfo & );
 | 
|---|
| 179 |     void npDone( bool );
 | 
|---|
| 180 |     void npStateChanged( int );
 | 
|---|
| 181 |     void npDataTransferProgress( int, int );
 | 
|---|
| 182 |     void npReadyRead();
 | 
|---|
| 183 | 
 | 
|---|
| 184 | protected slots:
 | 
|---|
| 185 |     // ### Qt 4.0: delete these
 | 
|---|
| 186 |     void hostFound();
 | 
|---|
| 187 |     void connected();
 | 
|---|
| 188 |     void closed();
 | 
|---|
| 189 |     void dataHostFound();
 | 
|---|
| 190 |     void dataConnected();
 | 
|---|
| 191 |     void dataClosed();
 | 
|---|
| 192 |     void dataReadyRead();
 | 
|---|
| 193 |     void dataBytesWritten( int nbytes );
 | 
|---|
| 194 |     void error( int );
 | 
|---|
| 195 | };
 | 
|---|
| 196 | 
 | 
|---|
| 197 | #endif // QT_NO_NETWORKPROTOCOL_FTP
 | 
|---|
| 198 | 
 | 
|---|
| 199 | #endif // QFTP_H
 | 
|---|