-rw-r--r-- | core/qws/transferserver.h | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/core/qws/transferserver.h b/core/qws/transferserver.h new file mode 100644 index 0000000..1c5ab4b --- a/dev/null +++ b/core/qws/transferserver.h | |||
@@ -0,0 +1,179 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of the 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 OProcess; | ||
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 | class SyncAuthentication : QObject | ||
40 | { | ||
41 | Q_OBJECT | ||
42 | |||
43 | public: | ||
44 | static int isAuthorized(QHostAddress peeraddress); | ||
45 | static bool checkPassword(const QString& pw); | ||
46 | static bool checkUser(const QString& user); | ||
47 | |||
48 | static QString serverId(); | ||
49 | static QString loginName(); | ||
50 | static QString ownerName(); | ||
51 | }; | ||
52 | |||
53 | |||
54 | class ServerDTP : public QSocket | ||
55 | { | ||
56 | Q_OBJECT | ||
57 | |||
58 | public: | ||
59 | ServerDTP( QObject *parent = 0, const char* name = 0 ); | ||
60 | ~ServerDTP(); | ||
61 | |||
62 | enum Mode{ Idle = 0, SendFile, SendGzipFile, SendBuffer, | ||
63 | RetrieveFile, RetrieveGzipFile, RetrieveBuffer }; | ||
64 | |||
65 | void sendFile( const QString fn ); | ||
66 | void sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ); | ||
67 | void sendGzipFile( const QString &fn, const QStringList &archiveTargets ); | ||
68 | void sendGzipFile( const QString &fn, const QStringList &archiveTargets, | ||
69 | const QHostAddress& host, Q_UINT16 port ); | ||
70 | void sendByteArray( const QByteArray& array ); | ||
71 | void sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ); | ||
72 | |||
73 | void retrieveFile( const QString fn ); | ||
74 | void retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ); | ||
75 | void retrieveGzipFile( const QString &fn ); | ||
76 | void retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ); | ||
77 | void retrieveByteArray(); | ||
78 | void retrieveByteArray( const QHostAddress& host, Q_UINT16 port ); | ||
79 | |||
80 | Mode dtpMode() { return mode; } | ||
81 | QByteArray buffer() { return buf.buffer(); } | ||
82 | QString fileName() const { return file.name(); } | ||
83 | |||
84 | void setSocket( int socket ); | ||
85 | |||
86 | signals: | ||
87 | void completed(); | ||
88 | void failed(); | ||
89 | |||
90 | private slots: | ||
91 | void connectionClosed(); | ||
92 | void connected(); | ||
93 | void bytesWritten( int bytes ); | ||
94 | void readyRead(); | ||
95 | void writeTargzBlock(OProcess *, char *, int); | ||
96 | void targzDone(); | ||
97 | |||
98 | void gzipTarBlock(OProcess *, char *, int); | ||
99 | void tarExtractBlock(OProcess *, char *, int); | ||
100 | void gunzipDone(); | ||
101 | void extractTarDone(); | ||
102 | |||
103 | private: | ||
104 | |||
105 | unsigned long bytes_written; | ||
106 | Mode mode; | ||
107 | QFile file; | ||
108 | QBuffer buf; | ||
109 | OProcess *createTargzProc; | ||
110 | OProcess *retrieveTargzProc; | ||
111 | OProcess *gzipProc; | ||
112 | }; | ||
113 | |||
114 | class ServerSocket : public QServerSocket | ||
115 | { | ||
116 | Q_OBJECT | ||
117 | |||
118 | public: | ||
119 | ServerSocket( Q_UINT16 port, QObject *parent = 0, const char* name = 0 ) | ||
120 | : QServerSocket( port, 1, parent, name ) {} | ||
121 | |||
122 | void newConnection( int socket ) { emit newIncomming( socket ); } | ||
123 | signals: | ||
124 | void newIncomming( int socket ); | ||
125 | }; | ||
126 | |||
127 | class ServerPI : public QSocket | ||
128 | { | ||
129 | Q_OBJECT | ||
130 | |||
131 | enum State { Connected, Wait_USER, Wait_PASS, Ready, Forbidden }; | ||
132 | enum Transfer { SendFile = 0, RetrieveFile = 1, SendByteArray = 2, RetrieveByteArray = 3 }; | ||
133 | |||
134 | public: | ||
135 | ServerPI( int socket, QObject *parent = 0, const char* name = 0 ); | ||
136 | virtual ~ServerPI(); | ||
137 | |||
138 | protected slots: | ||
139 | void read(); | ||
140 | void send( const QString& msg ); | ||
141 | void process( const QString& command ); | ||
142 | void connectionClosed(); | ||
143 | void dtpCompleted(); | ||
144 | void dtpFailed(); | ||
145 | void dtpError( int ); | ||
146 | void newConnection( int socket ); | ||
147 | |||
148 | protected: | ||
149 | bool checkReadFile( const QString& file ); | ||
150 | bool checkWriteFile( const QString& file ); | ||
151 | bool parsePort( const QString& pw ); | ||
152 | bool backupRestoreGzip( const QString &file, QStringList &targets ); | ||
153 | bool backupRestoreGzip( const QString &file ); | ||
154 | |||
155 | bool sendList( const QString& arg ); | ||
156 | void sendFile( const QString& file ); | ||
157 | void retrieveFile( const QString& file ); | ||
158 | |||
159 | QString permissionString( QFileInfo *info ); | ||
160 | QString fileListing( QFileInfo *info ); | ||
161 | QString absFilePath( const QString& file ); | ||
162 | |||
163 | void timerEvent( QTimerEvent *e ); | ||
164 | |||
165 | private: | ||
166 | State state; | ||
167 | Q_UINT16 peerport; | ||
168 | QHostAddress peeraddress; | ||
169 | bool passiv; | ||
170 | bool wait[4]; | ||
171 | ServerDTP *dtp; | ||
172 | ServerSocket *serversocket; | ||
173 | QString waitfile; | ||
174 | QDir directory; | ||
175 | QByteArray waitarray; | ||
176 | QString renameFrom; | ||
177 | QString lastCommand; | ||
178 | int waitsocket; | ||
179 | }; | ||