Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

transferserver.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 #include <qserversocket.h>
00021 #include <qsocket.h>
00022 #include <qdir.h>
00023 #include <qfile.h>
00024 #include <qbuffer.h>
00025 #include <qlist.h>
00026 
00027 class QFileInfo;
00028 class QProcess;
00029 class ServerPI;
00030 
00031 class TransferServer : public QServerSocket
00032 {
00033     Q_OBJECT
00034 
00035 public:
00036     TransferServer( Q_UINT16 port, QObject *parent = 0, const char* name = 0 );
00037     virtual ~TransferServer();
00038 
00039     void newConnection( int socket );
00040     void authorizeConnections();
00041 
00042 protected slots:
00043     void closed(ServerPI *);
00044 
00045 private:
00046     QList<ServerPI> connections;
00047 };
00048 
00049 class SyncAuthentication : QObject
00050 {
00051     Q_OBJECT
00052 
00053 public:
00054     static int isAuthorized(QHostAddress peeraddress);
00055     static bool checkPassword(const QString& pw);
00056     static bool checkUser(const QString& user);
00057 
00058     static QString serverId();
00059     static QString loginName();
00060     static QString ownerName();
00061 };
00062 
00063 
00064 class ServerDTP : public QSocket
00065 {
00066     Q_OBJECT
00067 
00068 public:
00069     ServerDTP( QObject *parent = 0, const char* name = 0 );
00070     ~ServerDTP();
00071 
00072     enum Mode{ Idle = 0, SendFile, SendGzipFile, SendBuffer,
00073                RetrieveFile, RetrieveGzipFile, RetrieveBuffer };
00074 
00075     void sendFile( const QString fn );
00076     void sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port );
00077     void sendGzipFile( const QString &fn, const QStringList &archiveTargets );
00078     void sendGzipFile( const QString &fn, const QStringList &archiveTargets,
00079                        const QHostAddress& host, Q_UINT16 port );
00080     void sendByteArray( const QByteArray& array );
00081     void sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port );
00082 
00083     void retrieveFile( const QString fn, int fileSize );
00084     void retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize );
00085     void retrieveGzipFile( const QString &fn );
00086     void retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port );
00087     void retrieveByteArray();
00088     void retrieveByteArray( const QHostAddress& host, Q_UINT16 port );
00089 
00090     Mode dtpMode() { return mode; }
00091     QByteArray buffer() { return buf.buffer(); }
00092     QString fileName() const { return file.name(); }
00093 
00094     void setSocket( int socket );
00095 
00096 signals:
00097     void completed();
00098     void failed();
00099 
00100 private slots:
00101     void connectionClosed();
00102     void connected();
00103     void bytesWritten( int bytes );
00104     void readyRead();
00105     void writeTargzBlock();
00106     void targzDone();
00107     void extractTarDone();
00108 
00109 private:
00110 
00111     unsigned long bytes_written;
00112     Mode mode;
00113     QFile file;
00114     QBuffer buf;
00115     QProcess *createTargzProc;
00116     QProcess *retrieveTargzProc;
00117     int recvFileSize;
00118 };
00119 
00120 class ServerSocket : public QServerSocket
00121 {
00122     Q_OBJECT
00123 
00124 public:
00125     ServerSocket( Q_UINT16 port, QObject *parent = 0, const char* name = 0 )
00126         : QServerSocket( port, 1, parent, name ) {}
00127 
00128     void newConnection( int socket ) { emit newIncomming( socket ); }
00129 signals:
00130     void newIncomming( int socket );
00131 };
00132 
00133 class ServerPI : public QSocket
00134 {
00135     Q_OBJECT
00136 
00137     enum State { Connected, Wait_USER, Wait_PASS, Ready, Forbidden };
00138     enum Transfer { SendFile = 0, RetrieveFile = 1, SendByteArray = 2, RetrieveByteArray = 3 };
00139 
00140 public:
00141     ServerPI( int socket, QObject *parent = 0, const char* name = 0 );
00142     virtual ~ServerPI();
00143 
00144     bool verifyAuthorised();
00145 
00146 signals:
00147     void connectionClosed(ServerPI *);
00148 
00149 protected slots:
00150     void read();
00151     void send( const QString& msg );
00152     void process( const QString& command );
00153     void connectionClosed();
00154     void dtpCompleted();
00155     void dtpFailed();
00156     void dtpError( int );
00157     void newConnection( int socket );
00158 
00159 protected:
00160     bool checkReadFile( const QString& file );
00161     bool checkWriteFile( const QString& file );
00162     bool parsePort( const QString& pw );
00163     bool backupRestoreGzip( const QString &file, QStringList &targets );
00164     bool backupRestoreGzip( const QString &file );
00165 
00166     bool sendList( const QString& arg );
00167     void sendFile( const QString& file );
00168     void retrieveFile( const QString& file );
00169 
00170     QString permissionString( QFileInfo *info );
00171     QString fileListing( QFileInfo *info );
00172     QString absFilePath( const QString& file );
00173 
00174     void timerEvent( QTimerEvent *e );
00175 
00176 private:
00177     State state;
00178     Q_UINT16 peerport;
00179     QHostAddress peeraddress;
00180     bool passiv;
00181     bool wait[4];
00182     ServerDTP *dtp;
00183     ServerSocket *serversocket;
00184     QString waitfile;
00185     QDir directory;
00186     QByteArray waitarray;
00187     QString renameFrom;
00188     QString lastCommand;
00189     int waitsocket;
00190     int storFileSize;
00191 };

Generated on Sat Nov 5 16:15:34 2005 for OPIE by  doxygen 1.4.2