00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __ftp_h__
00024 #define __ftp_h__
00025
00026 #include <config.h>
00027
00028 #include <sys/types.h>
00029 #include <sys/socket.h>
00030
00031 #include <qcstring.h>
00032 #include <qstring.h>
00033
00034 #include <kurl.h>
00035 #include <kio/slavebase.h>
00036 #include <kextsock.h>
00037 #include <ksocks.h>
00038
00039 struct FtpEntry
00040 {
00041 QString name;
00042 QString owner;
00043 QString group;
00044 QString link;
00045
00046 KIO::filesize_t size;
00047 mode_t type;
00048 mode_t access;
00049 time_t date;
00050 };
00051
00052
00053
00054
00055
00056 #ifdef KIO_FTP_PRIVATE_INCLUDE
00057 class FtpSocket;
00058
00059 class FtpTextReader
00060 {
00061 public:
00062 FtpTextReader() { textClear(); }
00063
00067 void textClear();
00068
00075 int textRead(FtpSocket *pSock);
00076
00080 const char* textLine() const { return m_szText; }
00081
00085 bool textTooLong() const { return m_bTextTruncated; }
00086
00090 bool textEOF() const { return m_bTextEOF; }
00091
00092 enum {
00093
00099 textReadBuffer = 2048,
00100
00105 textReadLimit = 1024
00106 };
00107
00108 private:
00112 bool m_bTextTruncated;
00113
00117 bool m_bTextEOF;
00118
00122 char m_szText[textReadBuffer];
00123
00127 int m_iTextLine;
00128
00132 int m_iTextBuff;
00133 };
00134 #endif // KIO_FTP_PRIVATE_INCLUDE
00135
00136
00137
00138
00139 #ifdef KIO_FTP_PRIVATE_INCLUDE
00140 class FtpSocket : public FtpTextReader, public KExtendedSocket
00141 {
00142 private:
00143
00144 FtpSocket() {}
00145 public:
00151 FtpSocket(const char* pszName)
00152 {
00153 m_pszName = pszName;
00154 m_server = -1;
00155 }
00156
00157 ~FtpSocket() { closeSocket(); }
00158
00162 void closeSocket();
00163
00169 int server() const { return m_server; }
00170
00174 void setServer(int i) { m_server = (i >= 0) ? i : -1; }
00175
00179 int sock() const { return (m_server != -1) ? m_server : fd(); }
00180
00184 void debugMessage(const char* pszMsg) const;
00185
00189 int errorMessage(int iErrorCode, const char* pszMsg) const;
00190
00194 int connectSocket(int iTimeOutSec, bool bControl);
00195
00199 bool setSocketOption(int opt, char*arg, socklen_t len) const;
00200
00204 long read(void* pData, long iMaxlen)
00205 {
00206 return KSocks::self()->read(sock(), pData, iMaxlen);
00207 }
00208
00212 long write(void* pData, long iMaxlen)
00213 {
00214 return KSocks::self()->write(sock(), pData, iMaxlen);
00215 }
00216
00220 int textRead()
00221 {
00222 return FtpTextReader::textRead(this);
00223 }
00224
00225 private:
00226 const char* m_pszName;
00227 int m_server;
00228 };
00229 #else
00230 class FtpSocket;
00231 #endif // KIO_FTP_PRIVATE_INCLUDE
00232
00233
00234
00235
00236 class Ftp : public KIO::SlaveBase
00237 {
00238
00239
00240 public:
00241 Ftp( const QCString &pool, const QCString &app );
00242 virtual ~Ftp();
00243
00244 virtual void setHost( const QString& host, int port, const QString& user, const QString& pass );
00245
00252 virtual void openConnection();
00253
00257 virtual void closeConnection();
00258
00259 virtual void stat( const KURL &url );
00260
00261 virtual void listDir( const KURL & url );
00262 virtual void mkdir( const KURL & url, int permissions );
00263 virtual void rename( const KURL & src, const KURL & dest, bool overwrite );
00264 virtual void del( const KURL & url, bool isfile );
00265 virtual void chmod( const KURL & url, int permissions );
00266
00267 virtual void get( const KURL& url );
00268 virtual void put( const KURL& url, int permissions, bool overwrite, bool resume);
00269
00270
00271 virtual void slave_status();
00272
00276 virtual void copy( const KURL &src, const KURL &dest, int permissions, bool overwrite );
00277
00278 private:
00279
00280
00281
00282
00283
00284
00285
00290 typedef enum {
00291 statusSuccess,
00292 statusClientError,
00293 statusServerError
00294 } StatusCode;
00295
00299 typedef enum {
00300 loginDefered,
00301 loginExplicit,
00302 loginImplicit
00303 } LoginMode;
00304
00315 bool ftpOpenConnection (LoginMode loginMode);
00316
00320 void ftpAutoLoginMacro ();
00321
00329 bool ftpLogin();
00330
00340 bool ftpSendCmd( const QCString& cmd, int maxretries = 1 );
00341
00348 bool ftpSize( const QString & path, char mode );
00349
00353 bool ftpFolder(const QString& path, bool bReportError);
00354
00366 bool ftpOpenCommand( const char *command, const QString & path, char mode,
00367 int errorcode, KIO::fileoffset_t offset = 0 );
00368
00375 bool ftpCloseCommand();
00376
00383 bool ftpDataMode(char cMode);
00384
00385
00386
00390 int ftpOpenDataConnection();
00391
00395 void ftpCloseDataConnection();
00396
00400 int ftpOpenPASVDataConnection();
00404 int ftpOpenEPSVDataConnection();
00408 int ftpOpenEPRTDataConnection();
00412 int ftpOpenPortDataConnection();
00413
00420 int ftpAcceptConnect();
00421
00422 bool ftpChmod( const QString & path, int permissions );
00423
00424
00425 bool ftpOpenDir( const QString & path );
00429 bool ftpReadDir(FtpEntry& ftpEnt);
00430
00434 void ftpCreateUDSEntry( const QString & filename, FtpEntry& ftpEnt, KIO::UDSEntry& entry, bool isDir );
00435
00436 void ftpShortStatAnswer( const QString& filename, bool isDir );
00437
00438 void ftpStatAnswerNotFound( const QString & path, const QString & filename );
00439
00445 bool ftpRename( const QString & src, const QString & dst, bool overwrite );
00446
00452 bool ftpOpenControlConnection( const QString & host, unsigned short int port );
00453
00457 void ftpCloseControlConnection();
00458
00467 const char* ftpResponse(int iOffset);
00468
00480 StatusCode ftpGet(int& iError, int iCopyFile, const KURL& url, KIO::fileoffset_t hCopyOffset);
00481
00492 StatusCode ftpPut(int& iError, int iCopyFile, const KURL& url, int permissions, bool overwrite, bool resume);
00493
00502 StatusCode ftpCopyPut(int& iError, int& iCopyFile, QString sCopyFile, const KURL& url, int permissions, bool overwrite);
00503
00512 StatusCode ftpCopyGet(int& iError, int& iCopyFile, QString sCopyFile, const KURL& url, int permissions, bool overwrite);
00513
00514 private:
00515
00516 QString m_host;
00517 unsigned short int m_port;
00518 QString m_user;
00519 QString m_pass;
00523 QString m_initialPath;
00524 KURL m_proxyURL;
00525
00529 QString m_currentPath;
00530
00534 int m_iRespCode;
00535
00539 int m_iRespType;
00540
00545 char m_cDataMode;
00546
00550 bool m_bLoggedOn;
00551
00556 bool m_bTextMode;
00557
00568 bool m_bBusy;
00569
00570 bool m_bPasv;
00571 bool m_bUseProxy;
00572
00573 KIO::filesize_t m_size;
00574 static KIO::filesize_t UnknownSize;
00575
00576 enum
00577 {
00578 epsvUnknown = 0x01,
00579 epsvAllUnknown = 0x02,
00580 eprtUnknown = 0x04,
00581 epsvAllSent = 0x10,
00582 pasvUnknown = 0x20,
00583 chmodUnknown = 0x100
00584 };
00585 int m_extControl;
00586
00590 FtpSocket *m_control;
00591
00595 FtpSocket *m_data;
00596 };
00597
00598 #endif