Diffstat (limited to 'core/launcher/transferserver.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/launcher/transferserver.h | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/core/launcher/transferserver.h b/core/launcher/transferserver.h new file mode 100644 index 0000000..076e460 --- a/dev/null +++ b/core/launcher/transferserver.h | |||
@@ -0,0 +1,168 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #include <qserversocket.h> | ||
21 | #include <qsocket.h> | ||
22 | #include <qdir.h> | ||
23 | #include <qfile.h> | ||
24 | #include <qbuffer.h> | ||
25 | |||
26 | class QFileInfo; | ||
27 | class QProcess; | ||
28 | class TransferServer : public QServerSocket | ||
29 | { | ||
30 | Q_OBJECT | ||
31 | |||
32 | public: | ||
33 | TransferServer( Q_UINT16 port, QObject *parent = 0, const char* name = 0 ); | ||
34 | virtual ~TransferServer(); | ||
35 | |||
36 | void newConnection( int socket ); | ||
37 | }; | ||
38 | |||
39 | |||
40 | class ServerDTP : public QSocket | ||
41 | { | ||
42 | Q_OBJECT | ||
43 | |||
44 | public: | ||
45 | ServerDTP( QObject *parent = 0, const char* name = 0 ); | ||
46 | ~ServerDTP(); | ||
47 | |||
48 | enum Mode{ Idle = 0, SendFile, SendGzipFile, SendBuffer, | ||
49 | RetrieveFile, RetrieveGzipFile, RetrieveBuffer }; | ||
50 | |||
51 | void sendFile( const QString fn ); | ||
52 | void sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ); | ||
53 | void sendGzipFile( const QString &fn, const QStringList &archiveTargets ); | ||
54 | void sendGzipFile( const QString &fn, const QStringList &archiveTargets, | ||
55 | const QHostAddress& host, Q_UINT16 port ); | ||
56 | void sendByteArray( const QByteArray& array ); | ||
57 | void sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ); | ||
58 | |||
59 | void retrieveFile( const QString fn ); | ||
60 | void retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ); | ||
61 | void retrieveGzipFile( const QString &fn ); | ||
62 | void retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ); | ||
63 | void retrieveByteArray(); | ||
64 | void retrieveByteArray( const QHostAddress& host, Q_UINT16 port ); | ||
65 | |||
66 | Mode dtpMode() { return mode; } | ||
67 | QByteArray buffer() { return buf.buffer(); } | ||
68 | |||
69 | void setSocket( int socket ); | ||
70 | |||
71 | signals: | ||
72 | void completed(); | ||
73 | void failed(); | ||
74 | |||
75 | private slots: | ||
76 | void connectionClosed(); | ||
77 | void connected(); | ||
78 | void bytesWritten( int bytes ); | ||
79 | void readyRead(); | ||
80 | void writeTargzBlock(); | ||
81 | void targzDone(); | ||
82 | |||
83 | void gzipTarBlock(); | ||
84 | void tarExtractBlock(); | ||
85 | void gunzipDone(); | ||
86 | void extractTarDone(); | ||
87 | |||
88 | private: | ||
89 | |||
90 | unsigned long bytes_written; | ||
91 | Mode mode; | ||
92 | QFile file; | ||
93 | QBuffer buf; | ||
94 | QProcess *createTargzProc; | ||
95 | QProcess *retrieveTargzProc; | ||
96 | QProcess *gzipProc; | ||
97 | }; | ||
98 | |||
99 | class ServerSocket : public QServerSocket | ||
100 | { | ||
101 | Q_OBJECT | ||
102 | |||
103 | public: | ||
104 | ServerSocket( Q_UINT16 port, QObject *parent = 0, const char* name = 0 ) | ||
105 | : QServerSocket( port, 1, parent, name ) {} | ||
106 | |||
107 | void newConnection( int socket ) { emit newIncomming( socket ); } | ||
108 | signals: | ||
109 | void newIncomming( int socket ); | ||
110 | }; | ||
111 | |||
112 | class ServerPI : public QSocket | ||
113 | { | ||
114 | Q_OBJECT | ||
115 | |||
116 | enum State { Connected, Wait_USER, Wait_PASS, Ready, Forbidden }; | ||
117 | enum Transfer { SendFile = 0, RetrieveFile = 1, SendByteArray = 2, RetrieveByteArray = 3 }; | ||
118 | |||
119 | public: | ||
120 | ServerPI( int socket, QObject *parent = 0, const char* name = 0 ); | ||
121 | virtual ~ServerPI(); | ||
122 | |||
123 | protected slots: | ||
124 | void read(); | ||
125 | void send( const QString& msg ); | ||
126 | void process( const QString& command ); | ||
127 | void connectionClosed(); | ||
128 | void dtpCompleted(); | ||
129 | void dtpFailed(); | ||
130 | void dtpError( int ); | ||
131 | void newConnection( int socket ); | ||
132 | |||
133 | protected: | ||
134 | bool checkUser( const QString& user ); | ||
135 | bool checkPassword( const QString& pw ); | ||
136 | bool checkReadFile( const QString& file ); | ||
137 | bool checkWriteFile( const QString& file ); | ||
138 | bool parsePort( const QString& pw ); | ||
139 | bool backupRestoreGzip( const QString &file, QStringList &targets ); | ||
140 | bool backupRestoreGzip( const QString &file ); | ||
141 | |||
142 | bool sendList( const QString& arg ); | ||
143 | void sendFile( const QString& file ); | ||
144 | void retrieveFile( const QString& file ); | ||
145 | |||
146 | QString permissionString( QFileInfo *info ); | ||
147 | QString fileListing( QFileInfo *info ); | ||
148 | QString absFilePath( const QString& file ); | ||
149 | |||
150 | void timerEvent( QTimerEvent *e ); | ||
151 | |||
152 | private: | ||
153 | State state; | ||
154 | Q_UINT16 peerport; | ||
155 | QHostAddress peeraddress; | ||
156 | bool passiv; | ||
157 | bool wait[4]; | ||
158 | ServerDTP *dtp; | ||
159 | ServerSocket *serversocket; | ||
160 | QString waitfile; | ||
161 | QDir directory; | ||
162 | QByteArray waitarray; | ||
163 | QString renameFrom; | ||
164 | QString lastCommand; | ||
165 | int waitsocket; | ||
166 | }; | ||
167 | |||
168 | bool accessAuthorized(QHostAddress peeraddress); | ||