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 
00026 class QFileInfo;
00027 namespace Opie { namespace Core { class OProcess; } }
00028 
00029 class TransferServer : public QServerSocket
00030 {
00031     Q_OBJECT
00032 
00033 public:
00034     TransferServer( Q_UINT16 port, QObject *parent = 0, const char* name = 0 );
00035     virtual ~TransferServer();
00036 
00037     void newConnection( int socket );
00038 };
00039 
00040 class SyncAuthentication : QObject
00041 {
00042     Q_OBJECT
00043 
00044 public:
00045     static int isAuthorized(QHostAddress peeraddress);
00046     static bool checkPassword(const QString& pw);
00047     static bool checkUser(const QString& user);
00048 
00049     static QString serverId();
00050     static QString loginName();
00051     static QString ownerName();
00052 };
00053 
00054 
00055 class ServerDTP : public QSocket
00056 {
00057     Q_OBJECT
00058 
00059 public:
00060     ServerDTP( QObject *parent = 0, const char* name = 0 );
00061     ~ServerDTP();
00062 
00063     enum Mode{ Idle = 0, SendFile, SendGzipFile, SendBuffer,
00064                RetrieveFile, RetrieveGzipFile, RetrieveBuffer };
00065 
00066     void sendFile( const QString fn );
00067     void sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port );
00068     void sendGzipFile( const QString &fn, const QStringList &archiveTargets );
00069     void sendGzipFile( const QString &fn, const QStringList &archiveTargets,
00070                        const QHostAddress& host, Q_UINT16 port );
00071     void sendByteArray( const QByteArray& array );
00072     void sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port );
00073 
00074     void retrieveFile( const QString fn );
00075     void retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port );
00076     void retrieveGzipFile( const QString &fn );
00077     void retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port );
00078     void retrieveByteArray();
00079     void retrieveByteArray( const QHostAddress& host, Q_UINT16 port );
00080 
00081     Mode dtpMode() { return mode; }
00082     QByteArray buffer() { return buf.buffer(); }
00083     QString fileName() const { return file.name(); }
00084 
00085     void setSocket( int socket );
00086 
00087 signals:
00088     void completed();
00089     void failed();
00090 
00091 private slots:
00092     void connectionClosed();
00093     void connected();
00094     void bytesWritten( int bytes );
00095     void readyRead();
00096     void writeTargzBlock(Opie::Core::OProcess *, char *, int);
00097     void targzDone();
00098 
00099     void gzipTarBlock(Opie::Core::OProcess *, char *, int);
00100     void tarExtractBlock(Opie::Core::OProcess *, char *, int);
00101     void gunzipDone();
00102     void extractTarDone();
00103 
00104 private:
00105 
00106     unsigned long bytes_written;
00107     Mode mode;
00108     QFile file;
00109     QBuffer buf;
00110     Opie::Core::OProcess *createTargzProc;
00111     Opie::Core::OProcess *retrieveTargzProc;
00112     Opie::Core::OProcess *gzipProc;
00113 };
00114 
00115 class ServerSocket : public QServerSocket
00116 {
00117     Q_OBJECT
00118 
00119 public:
00120     ServerSocket( Q_UINT16 port, QObject *parent = 0, const char* name = 0 )
00121         : QServerSocket( port, 1, parent, name ) {}
00122 
00123     void newConnection( int socket ) { emit newIncomming( socket ); }
00124 signals:
00125     void newIncomming( int socket );
00126 };
00127 
00128 class ServerPI : public QSocket
00129 {
00130     Q_OBJECT
00131 
00132     enum State { Connected, Wait_USER, Wait_PASS, Ready, Forbidden };
00133     enum Transfer { SendFile = 0, RetrieveFile = 1, SendByteArray = 2, RetrieveByteArray = 3 };
00134 
00135 public:
00136     ServerPI( int socket, QObject *parent = 0, const char* name = 0 );
00137     virtual ~ServerPI();
00138 
00139 protected slots:
00140     void read();
00141     void send( const QString& msg );
00142     void process( const QString& command );
00143     void connectionClosed();
00144     void dtpCompleted();
00145     void dtpFailed();
00146     void dtpError( int );
00147     void newConnection( int socket );
00148 
00149 protected:
00150     bool checkReadFile( const QString& file );
00151     bool checkWriteFile( const QString& file );
00152     bool parsePort( const QString& pw );
00153     bool backupRestoreGzip( const QString &file, QStringList &targets );
00154     bool backupRestoreGzip( const QString &file );
00155 
00156     bool sendList( const QString& arg );
00157     void sendFile( const QString& file );
00158     void retrieveFile( const QString& file );
00159 
00160     QString permissionString( QFileInfo *info );
00161     QString fileListing( QFileInfo *info );
00162     QString absFilePath( const QString& file );
00163 
00164     void timerEvent( QTimerEvent *e );
00165 
00166 private:
00167     State state;
00168     Q_UINT16 peerport;
00169     QHostAddress peeraddress;
00170     bool passiv;
00171     bool wait[4];
00172     ServerDTP *dtp;
00173     ServerSocket *serversocket;
00174     QString waitfile;
00175     QDir directory;
00176     QByteArray waitarray;
00177     QString renameFrom;
00178     QString lastCommand;
00179     int waitsocket;
00180 };

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