1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the Qt3Support module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef Q3FTP_H
43 #define Q3FTP_H
44 
45 #include <QtCore/qstring.h> // char*->QString conversion
46 #include <QtNetwork/qurlinfo.h>
47 #include <Qt3Support/q3networkprotocol.h>
48 
49 QT_BEGIN_HEADER
50 
51 QT_BEGIN_NAMESPACE
52 
53 QT_MODULE(Qt3Support)
54 
55 #ifndef QT_NO_NETWORKPROTOCOL_FTP
56 
57 class Q3Socket;
58 class Q3FtpCommand;
59 
60 class Q_COMPAT_EXPORT Q3Ftp : public Q3NetworkProtocol
61 {
62     Q_OBJECT
63 
64 public:
65     Q3Ftp(); // ### Qt 4.0: get rid of this overload
66     Q3Ftp( QObject *parent, const char *name=0 );
67     virtual ~Q3Ftp();
68 
69     int supportedOperations() const;
70 
71     // non-Q3NetworkProtocol functions:
72     enum State {
73 	Unconnected,
74 	HostLookup,
75 	Connecting,
76 	Connected,
77 	LoggedIn,
78 	Closing
79     };
80     enum Error {
81 	NoError,
82 	UnknownError,
83 	HostNotFound,
84 	ConnectionRefused,
85 	NotConnected
86     };
87     enum Command {
88 	None,
89 	ConnectToHost,
90 	Login,
91 	Close,
92 	List,
93 	Cd,
94 	Get,
95 	Put,
96 	Remove,
97 	Mkdir,
98 	Rmdir,
99 	Rename,
100 	RawCommand
101     };
102 
103     int connectToHost( const QString &host, Q_UINT16 port=21 );
104     int login( const QString &user=QString(), const QString &password=QString() );
105     int close();
106     int list( const QString &dir=QString() );
107     int cd( const QString &dir );
108     int get( const QString &file, QIODevice *dev=0 );
109     int put( const QByteArray &data, const QString &file );
110     int put( QIODevice *dev, const QString &file );
111     int remove( const QString &file );
112     int mkdir( const QString &dir );
113     int rmdir( const QString &dir );
114     int rename( const QString &oldname, const QString &newname );
115 
116     int rawCommand( const QString &command );
117 
118     Q_ULONG bytesAvailable() const;
119     Q_LONG readBlock( char *data, Q_ULONG maxlen );
120     QByteArray readAll();
121 
122     int currentId() const;
123     QIODevice* currentDevice() const;
124     Command currentCommand() const;
125     bool hasPendingCommands() const;
126     void clearPendingCommands();
127 
128     State state() const;
129 
130     Error error() const;
131     QString errorString() const;
132 
133 public Q_SLOTS:
134     void abort();
135 
136 Q_SIGNALS:
137     void stateChanged( int );
138     void listInfo( const QUrlInfo& );
139     void readyRead();
140     void dataTransferProgress( int, int );
141     void rawCommandReply( int, const QString& );
142 
143     void commandStarted( int );
144     void commandFinished( int, bool );
145     void done( bool );
146 
147 protected:
148     void parseDir( const QString &buffer, QUrlInfo &info ); // ### Qt 4.0: delete this? (not public API)
149     void operationListChildren( Q3NetworkOperation *op );
150     void operationMkDir( Q3NetworkOperation *op );
151     void operationRemove( Q3NetworkOperation *op );
152     void operationRename( Q3NetworkOperation *op );
153     void operationGet( Q3NetworkOperation *op );
154     void operationPut( Q3NetworkOperation *op );
155 
156     // ### Qt 4.0: delete these
157     // unused variables:
158     Q3Socket *commandSocket, *dataSocket;
159     bool connectionReady, passiveMode;
160     int getTotalSize, getDoneSize;
161     bool startGetOnFail;
162     int putToWrite, putWritten;
163     bool errorInListChildren;
164 
165 private:
166     void init();
167     int addCommand( Q3FtpCommand * );
168 
169     bool checkConnection( Q3NetworkOperation *op );
170 
171 private Q_SLOTS:
172     void startNextCommand();
173     void piFinished( const QString& );
174     void piError( int, const QString& );
175     void piConnectState( int );
176     void piFtpReply( int, const QString& );
177 
178 private Q_SLOTS:
179     void npListInfo( const QUrlInfo & );
180     void npDone( bool );
181     void npStateChanged( int );
182     void npDataTransferProgress( int, int );
183     void npReadyRead();
184 
185 protected Q_SLOTS:
186     // ### Qt 4.0: delete these
187     void hostFound();
188     void connected();
189     void closed();
190     void dataHostFound();
191     void dataConnected();
192     void dataClosed();
193     void dataReadyRead();
194     void dataBytesWritten( int nbytes );
195     void error( int );
196 };
197 
198 #endif // QT_NO_NETWORKPROTOCOL_FTP
199 
200 QT_END_NAMESPACE
201 
202 QT_END_HEADER
203 
204 #endif // Q3FTP_H
205