author | sandman <sandman> | 2002-12-17 19:16:18 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-12-17 19:16:18 (UTC) |
commit | f36c70938c8c2907a1b61637af3bd589262b4b5e (patch) (unidiff) | |
tree | 7ed7429477ad0b17ea131fddcc5cab9fff088b26 /core/launcher/transferserver.cpp | |
parent | b6a03145553d7f536b04fc3355718cfdd72c590d (diff) | |
download | opie-f36c70938c8c2907a1b61637af3bd589262b4b5e.zip opie-f36c70938c8c2907a1b61637af3bd589262b4b5e.tar.gz opie-f36c70938c8c2907a1b61637af3bd589262b4b5e.tar.bz2 |
replaced the private QProcess copy for the FTP server with the already
available libopie/OProcess
Diffstat (limited to 'core/launcher/transferserver.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/launcher/transferserver.cpp | 2145 |
1 files changed, 1090 insertions, 1055 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp index cbda247..0337a94 100644 --- a/core/launcher/transferserver.cpp +++ b/core/launcher/transferserver.cpp | |||
@@ -25,17 +25,18 @@ | |||
25 | #include <time.h> | 25 | #include <time.h> |
26 | #include <shadow.h> | 26 | #include <shadow.h> |
27 | 27 | ||
28 | /* we need the _OS_LINUX stuff first ! */ | 28 | /* we need the _OS_LINUX stuff first ! */ |
29 | #include <qglobal.h> | 29 | #include <qglobal.h> |
30 | 30 | ||
31 | #ifndef _OS_LINUX_ | 31 | #ifndef _OS_LINUX_ |
32 | 32 | ||
33 | extern "C" { | 33 | extern "C" |
34 | { | ||
34 | #include <uuid/uuid.h> | 35 | #include <uuid/uuid.h> |
35 | #define UUID_H_INCLUDED | 36 | #define UUID_H_INCLUDED |
36 | } | 37 | } |
37 | 38 | ||
38 | #endif // not defined linux | 39 | #endif // not defined linux |
39 | 40 | ||
40 | #if defined(_OS_LINUX_) | 41 | #if defined(_OS_LINUX_) |
41 | #include <shadow.h> | 42 | #include <shadow.h> |
@@ -43,1347 +44,1381 @@ extern "C" { | |||
43 | 44 | ||
44 | #include <qdir.h> | 45 | #include <qdir.h> |
45 | #include <qfile.h> | 46 | #include <qfile.h> |
46 | #include <qtextstream.h> | 47 | #include <qtextstream.h> |
47 | #include <qdatastream.h> | 48 | #include <qdatastream.h> |
48 | #include <qmessagebox.h> | 49 | #include <qmessagebox.h> |
49 | #include <qstringlist.h> | 50 | #include <qstringlist.h> |
50 | #include <qfileinfo.h> | 51 | #include <qfileinfo.h> |
51 | #include <qregexp.h> | 52 | #include <qregexp.h> |
52 | //#include <qpe/qcopchannel_qws.h> | 53 | //#include <qpe/qcopchannel_qws.h> |
53 | #include <qpe/process.h> | 54 | #include <qpe/process.h> |
54 | #include <qpe/global.h> | 55 | #include <qpe/global.h> |
55 | #include <qpe/config.h> | 56 | #include <qpe/config.h> |
56 | #include <qpe/contact.h> | 57 | #include <qpe/contact.h> |
57 | #include <qpe/quuid.h> | 58 | #include <qpe/quuid.h> |
58 | #include <qpe/version.h> | 59 | #include <qpe/version.h> |
59 | #include <qpe/qcopenvelope_qws.h> | 60 | #include <qpe/qcopenvelope_qws.h> |
60 | 61 | ||
61 | #include "transferserver.h" | 62 | #include "transferserver.h" |
62 | #include "qprocess.h" | 63 | #include <opie/oprocess.h> |
63 | 64 | ||
64 | const int block_size = 51200; | 65 | const int block_size = 51200; |
65 | 66 | ||
66 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent , | 67 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent , |
67 | const char* name ) | 68 | const char* name ) |
68 | : QServerSocket( port, 1, parent, name ) | 69 | : QServerSocket( port, 1, parent, name ) |
69 | { | 70 | { |
70 | if ( !ok() ) | 71 | if ( !ok() ) |
71 | qWarning( "Failed to bind to port %d", port ); | 72 | qWarning( "Failed to bind to port %d", port ); |
72 | } | 73 | } |
73 | 74 | ||
74 | TransferServer::~TransferServer() | 75 | TransferServer::~TransferServer() |
75 | { | 76 | { |
76 | |||
77 | } | 77 | } |
78 | 78 | ||
79 | void TransferServer::newConnection( int socket ) | 79 | void TransferServer::newConnection( int socket ) |
80 | { | 80 | { |
81 | (void) new ServerPI( socket, this ); | 81 | (void) new ServerPI( socket, this ); |
82 | } | 82 | } |
83 | 83 | ||
84 | /* | 84 | /* |
85 | * small class in anonymous namespace | 85 | * small class in anonymous namespace |
86 | * to generate a QUUid for us | 86 | * to generate a QUUid for us |
87 | */ | 87 | */ |
88 | namespace { | 88 | namespace |
89 | struct UidGen { | 89 | { |
90 | QString uuid(); | 90 | struct UidGen |
91 | }; | 91 | { |
92 | QString uuid(); | ||
93 | }; | ||
92 | #if !defined(_OS_LINUX_) | 94 | #if !defined(_OS_LINUX_) |
93 | QString UidGen::uuid() { | 95 | |
94 | uuid_t uuid; | 96 | QString UidGen::uuid() |
95 | uuid_generate( uuid ); | 97 | { |
96 | return QUUid( uuid ).toString(); | 98 | uuid_t uuid; |
97 | } | 99 | uuid_generate( uuid ); |
100 | return QUUid( uuid ).toString(); | ||
101 | } | ||
98 | #else | 102 | #else |
99 | /* | 103 | /* |
100 | * linux got a /proc/sys/kernel/random/uuid file | 104 | * linux got a /proc/sys/kernel/random/uuid file |
101 | * it'll generate the uuids for us | 105 | * it'll generate the uuids for us |
102 | */ | 106 | */ |
103 | QString UidGen::uuid() { | 107 | QString UidGen::uuid() |
104 | QFile file( "/proc/sys/kernel/random/uuid" ); | 108 | { |
105 | if (!file.open(IO_ReadOnly ) ) | 109 | QFile file( "/proc/sys/kernel/random/uuid" ); |
106 | return QString::null; | 110 | if (!file.open(IO_ReadOnly ) ) |
107 | 111 | return QString::null; | |
108 | QTextStream stream(&file); | 112 | |
109 | 113 | QTextStream stream(&file); | |
110 | return "{" + stream.read().stripWhiteSpace() + "}"; | 114 | |
111 | } | 115 | return "{" + stream.read().stripWhiteSpace() + "}"; |
116 | } | ||
112 | #endif | 117 | #endif |
113 | } | 118 | } |
114 | 119 | ||
115 | QString SyncAuthentication::serverId() | 120 | QString SyncAuthentication::serverId() |
116 | { | 121 | { |
117 | Config cfg("Security"); | 122 | Config cfg("Security"); |
118 | cfg.setGroup("Sync"); | 123 | cfg.setGroup("Sync"); |
119 | QString r=cfg.readEntry("serverid"); | 124 | QString r = cfg.readEntry("serverid"); |
120 | if ( r.isEmpty() ) { | 125 | if ( r.isEmpty() ) { |
121 | UidGen gen; | 126 | UidGen gen; |
122 | r = gen.uuid(); | 127 | r = gen.uuid(); |
123 | cfg.writeEntry("serverid", r ); | 128 | cfg.writeEntry("serverid", r ); |
124 | } | 129 | } |
125 | return r; | 130 | return r; |
126 | } | 131 | } |
127 | 132 | ||
128 | QString SyncAuthentication::ownerName() | 133 | QString SyncAuthentication::ownerName() |
129 | { | 134 | { |
130 | QString vfilename = Global::applicationFileName("addressbook", | 135 | QString vfilename = Global::applicationFileName("addressbook", |
131 | "businesscard.vcf"); | 136 | "businesscard.vcf"); |
132 | if (QFile::exists(vfilename)) { | 137 | if (QFile::exists(vfilename)) { |
133 | Contact c; | 138 | Contact c; |
134 | c = Contact::readVCard( vfilename )[0]; | 139 | c = Contact::readVCard( vfilename )[0]; |
135 | return c.fullName(); | 140 | return c.fullName(); |
136 | } | 141 | } |
137 | 142 | ||
138 | return ""; | 143 | return ""; |
139 | } | 144 | } |
140 | 145 | ||
141 | QString SyncAuthentication::loginName() | 146 | QString SyncAuthentication::loginName() |
142 | { | 147 | { |
143 | struct passwd *pw; | 148 | struct passwd *pw; |
144 | pw = getpwuid( geteuid() ); | 149 | pw = getpwuid( geteuid() ); |
145 | return QString::fromLocal8Bit( pw->pw_name ); | 150 | return QString::fromLocal8Bit( pw->pw_name ); |
146 | } | 151 | } |
147 | 152 | ||
148 | int SyncAuthentication::isAuthorized(QHostAddress peeraddress) | 153 | int SyncAuthentication::isAuthorized(QHostAddress peeraddress) |
149 | { | 154 | { |
150 | Config cfg("Security"); | 155 | Config cfg("Security"); |
151 | cfg.setGroup("Sync"); | 156 | cfg.setGroup("Sync"); |
152 | // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); | 157 | // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); |
153 | uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100); | 158 | uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); |
154 | 159 | ||
155 | // QHostAddress allowed; | 160 | // QHostAddress allowed; |
156 | // allowed.setAddress(allowedstr); | 161 | // allowed.setAddress(allowedstr); |
157 | // uint auth_peer = allowed.ip4Addr(); | 162 | // uint auth_peer = allowed.ip4Addr(); |
158 | uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); | 163 | uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); |
159 | uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined | 164 | uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined |
160 | ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits)); | 165 | ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); |
161 | return (peeraddress.ip4Addr() & mask) == auth_peer; | 166 | return (peeraddress.ip4Addr() & mask) == auth_peer; |
162 | } | 167 | } |
163 | 168 | ||
164 | bool SyncAuthentication::checkUser( const QString& user ) | 169 | bool SyncAuthentication::checkUser( const QString& user ) |
165 | { | 170 | { |
166 | if ( user.isEmpty() ) return FALSE; | 171 | if ( user.isEmpty() ) |
167 | QString euser = loginName(); | 172 | return FALSE; |
168 | return user == euser; | 173 | QString euser = loginName(); |
174 | return user == euser; | ||
169 | } | 175 | } |
170 | 176 | ||
171 | bool SyncAuthentication::checkPassword( const QString& password ) | 177 | bool SyncAuthentication::checkPassword( const QString& password ) |
172 | { | 178 | { |
173 | #ifdef ALLOW_UNIX_USER_FTP | 179 | #ifdef ALLOW_UNIX_USER_FTP |
174 | // First, check system password... | 180 | // First, check system password... |
175 | 181 | ||
176 | struct passwd *pw = 0; | 182 | struct passwd *pw = 0; |
177 | struct spwd *spw = 0; | 183 | struct spwd *spw = 0; |
178 | 184 | ||
179 | pw = getpwuid( geteuid() ); | 185 | pw = getpwuid( geteuid() ); |
180 | spw = getspnam( pw->pw_name ); | 186 | spw = getspnam( pw->pw_name ); |
181 | 187 | ||
182 | QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); | 188 | QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); |
183 | if ( cpwd == "x" && spw ) | 189 | if ( cpwd == "x" && spw ) |
184 | cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); | 190 | cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); |
185 | 191 | ||
186 | // Note: some systems use more than crypt for passwords. | 192 | // Note: some systems use more than crypt for passwords. |
187 | QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); | 193 | QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); |
188 | if ( cpwd == cpassword ) | 194 | if ( cpwd == cpassword ) |
189 | return TRUE; | 195 | return TRUE; |
190 | #endif | 196 | #endif |
191 | 197 | ||
192 | static int lastdenial=0; | 198 | static int lastdenial = 0; |
193 | static int denials=0; | 199 | static int denials = 0; |
194 | int now = time(0); | 200 | int now = time(0); |
195 | 201 | ||
196 | // Detect old Qtopia Desktop (no password) | 202 | // Detect old Qtopia Desktop (no password) |
197 | if ( password.isEmpty() ) { | 203 | if ( password.isEmpty() ) { |
198 | if ( denials < 1 || now > lastdenial+600 ) { | 204 | if ( denials < 1 || now > lastdenial + 600 ) { |
199 | QMessageBox::warning( 0,tr("Sync Connection"), | 205 | QMessageBox::warning( 0, tr("Sync Connection"), |
200 | tr("<p>An unauthorized system is requesting access to this device." | 206 | tr("<p>An unauthorized system is requesting access to this device." |
201 | "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " | 207 | "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " |
202 | "please upgrade."), | 208 | "please upgrade."), |
203 | tr("Deny") ); | 209 | tr("Deny") ); |
204 | denials++; | 210 | denials++; |
205 | lastdenial=now; | 211 | lastdenial = now; |
206 | } | 212 | } |
207 | return FALSE; | 213 | return FALSE; |
208 | } | 214 | } |
209 | 215 | ||
210 | // Second, check sync password... | 216 | // Second, check sync password... |
211 | QString pass = password.left(6); | 217 | QString pass = password.left(6); |
212 | /* old QtopiaDesktops are sending | 218 | /* old QtopiaDesktops are sending |
213 | * rootme newer versions got a Qtopia | 219 | * rootme newer versions got a Qtopia |
214 | * prefixed. Qtopia prefix will suceed | 220 | * prefixed. Qtopia prefix will suceed |
215 | * until the sync software syncs up | 221 | * until the sync software syncs up |
216 | * FIXME | 222 | * FIXME |
217 | */ | 223 | */ |
218 | if ( pass == "rootme" || pass == "Qtopia") { | 224 | if ( pass == "rootme" || pass == "Qtopia") { |
219 | 225 | ||
220 | QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); | 226 | QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); |
221 | Config cfg("Security"); | 227 | Config cfg("Security"); |
222 | cfg.setGroup("Sync"); | 228 | cfg.setGroup("Sync"); |
223 | QString pwds = cfg.readEntry("Passwords"); | 229 | QString pwds = cfg.readEntry("Passwords"); |
224 | if ( QStringList::split(QChar(' '),pwds).contains(cpassword) ) | 230 | if ( QStringList::split(QChar(' '), pwds).contains(cpassword) ) |
225 | return TRUE; | 231 | return TRUE; |
226 | 232 | ||
227 | // Unrecognized system. Be careful... | 233 | // Unrecognized system. Be careful... |
228 | 234 | ||
229 | if ( (denials > 2 && now < lastdenial+600) | 235 | if ( (denials > 2 && now < lastdenial + 600) |
230 | || QMessageBox::warning(0,tr("Sync Connection"), | 236 | || QMessageBox::warning(0, tr("Sync Connection"), |
231 | tr("<p>An unrecognized system is requesting access to this device." | 237 | tr("<p>An unrecognized system is requesting access to this device." |
232 | "<p>If you have just initiated a Sync for the first time, this is normal."), | 238 | "<p>If you have just initiated a Sync for the first time, this is normal."), |
233 | tr("Allow"),tr("Deny"), 0, 1, 1 ) ==1 ) | 239 | tr("Allow"), tr("Deny"), 0, 1, 1 ) == 1 ) { |
234 | { | 240 | denials++; |
235 | denials++; | 241 | lastdenial = now; |
236 | lastdenial=now; | 242 | return FALSE; |
237 | return FALSE; | 243 | } |
238 | } else { | 244 | else { |
239 | denials=0; | 245 | denials = 0; |
240 | cfg.writeEntry("Passwords",pwds+" "+cpassword); | 246 | cfg.writeEntry("Passwords", pwds + " " + cpassword); |
241 | return TRUE; | 247 | return TRUE; |
242 | } | 248 | } |
243 | } | 249 | } |
244 | 250 | ||
245 | return FALSE; | 251 | return FALSE; |
246 | } | 252 | } |
247 | 253 | ||
248 | ServerPI::ServerPI( int socket, QObject *parent , const char* name ) | 254 | ServerPI::ServerPI( int socket, QObject *parent , const char* name ) |
249 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) | 255 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) |
250 | { | 256 | { |
251 | state = Connected; | 257 | state = Connected; |
252 | 258 | ||
253 | setSocket( socket ); | 259 | setSocket( socket ); |
254 | 260 | ||
255 | peerport = peerPort(); | 261 | peerport = peerPort(); |
256 | peeraddress = peerAddress(); | 262 | peeraddress = peerAddress(); |
257 | 263 | ||
258 | #ifndef INSECURE | 264 | #ifndef INSECURE |
259 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { | 265 | |
260 | state = Forbidden; | 266 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { |
261 | startTimer( 0 ); | 267 | state = Forbidden; |
262 | } else | 268 | startTimer( 0 ); |
269 | } | ||
270 | else | ||
263 | #endif | 271 | #endif |
264 | { | 272 | { |
265 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); | 273 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); |
266 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 274 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
267 | 275 | ||
268 | passiv = FALSE; | 276 | passiv = FALSE; |
269 | for( int i = 0; i < 4; i++ ) | 277 | for ( int i = 0; i < 4; i++ ) |
270 | wait[i] = FALSE; | 278 | wait[i] = FALSE; |
271 | 279 | ||
272 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); | 280 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); |
273 | state = Wait_USER; | 281 | state = Wait_USER; |
274 | 282 | ||
275 | dtp = new ServerDTP( this ); | 283 | dtp = new ServerDTP( this ); |
276 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); | 284 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); |
277 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); | 285 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); |
278 | connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); | 286 | connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); |
279 | 287 | ||
280 | 288 | ||
281 | directory = QDir::currentDirPath(); | 289 | directory = QDir::currentDirPath(); |
282 | 290 | ||
283 | static int p = 1024; | 291 | static int p = 1024; |
284 | 292 | ||
285 | while ( !serversocket || !serversocket->ok() ) { | 293 | while ( !serversocket || !serversocket->ok() ) { |
286 | delete serversocket; | 294 | delete serversocket; |
287 | serversocket = new ServerSocket( ++p, this ); | 295 | serversocket = new ServerSocket( ++p, this ); |
288 | } | 296 | } |
289 | connect( serversocket, SIGNAL( newIncomming( int ) ), | 297 | connect( serversocket, SIGNAL( newIncomming( int ) ), |
290 | SLOT( newConnection( int ) ) ); | 298 | SLOT( newConnection( int ) ) ); |
291 | } | 299 | } |
292 | } | 300 | } |
293 | 301 | ||
294 | ServerPI::~ServerPI() | 302 | ServerPI::~ServerPI() |
295 | { | 303 | { |
296 | |||
297 | } | 304 | } |
298 | 305 | ||
299 | void ServerPI::connectionClosed() | 306 | void ServerPI::connectionClosed() |
300 | { | 307 | { |
301 | // qDebug( "Debug: Connection closed" ); | 308 | // qDebug( "Debug: Connection closed" ); |
302 | delete this; | 309 | delete this; |
303 | } | 310 | } |
304 | 311 | ||
305 | void ServerPI::send( const QString& msg ) | 312 | void ServerPI::send( const QString& msg ) |
306 | { | 313 | { |
307 | QTextStream os( this ); | 314 | QTextStream os( this ); |
308 | os << msg << endl; | 315 | os << msg << endl; |
309 | //qDebug( "Reply: %s", msg.latin1() ); | 316 | //qDebug( "Reply: %s", msg.latin1() ); |
310 | } | 317 | } |
311 | 318 | ||
312 | void ServerPI::read() | 319 | void ServerPI::read() |
313 | { | 320 | { |
314 | while ( canReadLine() ) | 321 | while ( canReadLine() ) |
315 | process( readLine().stripWhiteSpace() ); | 322 | process( readLine().stripWhiteSpace() ); |
316 | } | 323 | } |
317 | 324 | ||
318 | bool ServerPI::checkReadFile( const QString& file ) | 325 | bool ServerPI::checkReadFile( const QString& file ) |
319 | { | 326 | { |
320 | QString filename; | 327 | QString filename; |
321 | 328 | ||
322 | if ( file[0] != "/" ) | 329 | if ( file[0] != "/" ) |
323 | filename = directory.path() + "/" + file; | 330 | filename = directory.path() + "/" + file; |
324 | else | 331 | else |
325 | filename = file; | 332 | filename = file; |
326 | 333 | ||
327 | QFileInfo fi( filename ); | 334 | QFileInfo fi( filename ); |
328 | return ( fi.exists() && fi.isReadable() ); | 335 | return ( fi.exists() && fi.isReadable() ); |
329 | } | 336 | } |
330 | 337 | ||
331 | bool ServerPI::checkWriteFile( const QString& file ) | 338 | bool ServerPI::checkWriteFile( const QString& file ) |
332 | { | 339 | { |
333 | QString filename; | 340 | QString filename; |
334 | 341 | ||
335 | if ( file[0] != "/" ) | 342 | if ( file[0] != "/" ) |
336 | filename = directory.path() + "/" + file; | 343 | filename = directory.path() + "/" + file; |
337 | else | 344 | else |
338 | filename = file; | 345 | filename = file; |
339 | 346 | ||
340 | QFileInfo fi( filename ); | 347 | QFileInfo fi( filename ); |
341 | 348 | ||
342 | if ( fi.exists() ) | 349 | if ( fi.exists() ) |
343 | if ( !QFile( filename ).remove() ) | 350 | if ( !QFile( filename ).remove() ) |
344 | return FALSE; | 351 | return FALSE; |
345 | return TRUE; | 352 | return TRUE; |
346 | } | 353 | } |
347 | 354 | ||
348 | void ServerPI::process( const QString& message ) | 355 | void ServerPI::process( const QString& message ) |
349 | { | 356 | { |
350 | //qDebug( "Command: %s", message.latin1() ); | 357 | //qDebug( "Command: %s", message.latin1() ); |
351 | 358 | ||
352 | // split message using "," as separator | 359 | // split message using "," as separator |
353 | QStringList msg = QStringList::split( " ", message ); | 360 | QStringList msg = QStringList::split( " ", message ); |
354 | if ( msg.isEmpty() ) return; | 361 | if ( msg.isEmpty() ) |
355 | 362 | return ; | |
356 | // command token | 363 | |
357 | QString cmd = msg[0].upper(); | 364 | // command token |
358 | 365 | QString cmd = msg[0].upper(); | |
359 | // argument token | 366 | |
360 | QString arg; | 367 | // argument token |
361 | if ( msg.count() >= 2 ) | 368 | QString arg; |
362 | arg = msg[1]; | 369 | if ( msg.count() >= 2 ) |
363 | 370 | arg = msg[1]; | |
364 | // full argument string | 371 | |
365 | QString args; | 372 | // full argument string |
366 | if ( msg.count() >= 2 ) { | 373 | QString args; |
367 | QStringList copy( msg ); | 374 | if ( msg.count() >= 2 ) { |
368 | // FIXME: for Qt3 | 375 | QStringList copy( msg ); |
369 | // copy.pop_front() | 376 | // FIXME: for Qt3 |
370 | copy.remove( copy.begin() ); | 377 | // copy.pop_front() |
371 | args = copy.join( " " ); | 378 | copy.remove( copy.begin() ); |
372 | } | 379 | args = copy.join( " " ); |
373 | 380 | } | |
374 | //qDebug( "args: %s", args.latin1() ); | 381 | |
375 | 382 | //qDebug( "args: %s", args.latin1() ); | |
376 | // we always respond to QUIT, regardless of state | 383 | |
377 | if ( cmd == "QUIT" ) { | 384 | // we always respond to QUIT, regardless of state |
378 | send( "211 Good bye!" ); | 385 | if ( cmd == "QUIT" ) { |
379 | delete this; | 386 | send( "211 Good bye!" ); |
380 | return; | 387 | delete this; |
381 | } | 388 | return ; |
382 | 389 | } | |
383 | // connected to client | 390 | |
384 | if ( Connected == state ) | 391 | // connected to client |
385 | return; | 392 | if ( Connected == state ) |
386 | 393 | return ; | |
387 | // waiting for user name | 394 | |
388 | if ( Wait_USER == state ) { | 395 | // waiting for user name |
389 | 396 | if ( Wait_USER == state ) { | |
390 | if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { | 397 | |
391 | send( "530 Please login with USER and PASS" ); | 398 | if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { |
392 | return; | 399 | send( "530 Please login with USER and PASS" ); |
393 | } | 400 | return ; |
394 | send( "331 User name ok, need password" ); | 401 | } |
395 | state = Wait_PASS; | 402 | send( "331 User name ok, need password" ); |
396 | return; | 403 | state = Wait_PASS; |
397 | } | 404 | return ; |
398 | 405 | } | |
399 | // waiting for password | 406 | |
400 | if ( Wait_PASS == state ) { | 407 | // waiting for password |
401 | 408 | if ( Wait_PASS == state ) { | |
402 | if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { | 409 | |
403 | send( "530 Please login with USER and PASS" ); | 410 | if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { |
404 | return; | 411 | send( "530 Please login with USER and PASS" ); |
405 | } | 412 | return ; |
406 | send( "230 User logged in, proceed" ); | 413 | } |
407 | state = Ready; | 414 | send( "230 User logged in, proceed" ); |
408 | return; | 415 | state = Ready; |
409 | } | 416 | return ; |
410 | 417 | } | |
411 | // ACCESS CONTROL COMMANDS | 418 | |
412 | 419 | // ACCESS CONTROL COMMANDS | |
413 | 420 | ||
414 | // account (ACCT) | 421 | |
415 | if ( cmd == "ACCT" ) { | 422 | // account (ACCT) |
416 | // even wu-ftp does not support it | 423 | if ( cmd == "ACCT" ) { |
417 | send( "502 Command not implemented" ); | 424 | // even wu-ftp does not support it |
418 | } | 425 | send( "502 Command not implemented" ); |
419 | 426 | } | |
420 | // change working directory (CWD) | 427 | |
421 | else if ( cmd == "CWD" ) { | 428 | // change working directory (CWD) |
422 | 429 | else if ( cmd == "CWD" ) { | |
423 | if ( !args.isEmpty() ) { | 430 | |
424 | if ( directory.cd( args, TRUE ) ) | 431 | if ( !args.isEmpty() ) { |
425 | send( "250 Requested file action okay, completed" ); | 432 | if ( directory.cd( args, TRUE ) ) |
426 | else | 433 | send( "250 Requested file action okay, completed" ); |
427 | send( "550 Requested action not taken" ); | 434 | else |
428 | } | 435 | send( "550 Requested action not taken" ); |
429 | else | 436 | } |
430 | send( "500 Syntax error, command unrecognized" ); | 437 | else |
431 | } | 438 | send( "500 Syntax error, command unrecognized" ); |
432 | 439 | } | |
433 | // change to parent directory (CDUP) | 440 | |
434 | else if ( cmd == "CDUP" ) { | 441 | // change to parent directory (CDUP) |
435 | if ( directory.cdUp() ) | 442 | else if ( cmd == "CDUP" ) { |
436 | send( "250 Requested file action okay, completed" ); | 443 | if ( directory.cdUp() ) |
437 | else | 444 | send( "250 Requested file action okay, completed" ); |
438 | send( "550 Requested action not taken" ); | 445 | else |
439 | } | 446 | send( "550 Requested action not taken" ); |
440 | 447 | } | |
441 | // structure mount (SMNT) | 448 | |
442 | else if ( cmd == "SMNT" ) { | 449 | // structure mount (SMNT) |
443 | // even wu-ftp does not support it | 450 | else if ( cmd == "SMNT" ) { |
444 | send( "502 Command not implemented" ); | 451 | // even wu-ftp does not support it |
445 | } | 452 | send( "502 Command not implemented" ); |
446 | 453 | } | |
447 | // reinitialize (REIN) | 454 | |
448 | else if ( cmd == "REIN" ) { | 455 | // reinitialize (REIN) |
449 | // even wu-ftp does not support it | 456 | else if ( cmd == "REIN" ) { |
450 | send( "502 Command not implemented" ); | 457 | // even wu-ftp does not support it |
451 | } | 458 | send( "502 Command not implemented" ); |
452 | 459 | } | |
453 | 460 | ||
454 | // TRANSFER PARAMETER COMMANDS | 461 | |
455 | 462 | // TRANSFER PARAMETER COMMANDS | |
456 | 463 | ||
457 | // data port (PORT) | 464 | |
458 | else if ( cmd == "PORT" ) { | 465 | // data port (PORT) |
459 | if ( parsePort( arg ) ) | 466 | else if ( cmd == "PORT" ) { |
460 | send( "200 Command okay" ); | 467 | if ( parsePort( arg ) ) |
461 | else | 468 | send( "200 Command okay" ); |
462 | send( "500 Syntax error, command unrecognized" ); | 469 | else |
463 | } | 470 | send( "500 Syntax error, command unrecognized" ); |
464 | 471 | } | |
465 | // passive (PASV) | 472 | |
466 | else if ( cmd == "PASV" ) { | 473 | // passive (PASV) |
467 | passiv = TRUE; | 474 | else if ( cmd == "PASV" ) { |
468 | send( "227 Entering Passive Mode (" | 475 | passiv = TRUE; |
469 | + address().toString().replace( QRegExp( "\\." ), "," ) + "," | 476 | send( "227 Entering Passive Mode (" |
470 | + QString::number( ( serversocket->port() ) >> 8 ) + "," | 477 | + address().toString().replace( QRegExp( "\\." ), "," ) + "," |
471 | + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); | 478 | + QString::number( ( serversocket->port() ) >> 8 ) + "," |
472 | } | 479 | + QString::number( ( serversocket->port() ) & 0xFF ) + ")" ); |
473 | 480 | } | |
474 | // representation type (TYPE) | 481 | |
475 | else if ( cmd == "TYPE" ) { | 482 | // representation type (TYPE) |
476 | if ( arg.upper() == "A" || arg.upper() == "I" ) | 483 | else if ( cmd == "TYPE" ) { |
477 | send( "200 Command okay" ); | 484 | if ( arg.upper() == "A" || arg.upper() == "I" ) |
478 | else | 485 | send( "200 Command okay" ); |
479 | send( "504 Command not implemented for that parameter" ); | 486 | else |
480 | } | 487 | send( "504 Command not implemented for that parameter" ); |
481 | 488 | } | |
482 | // file structure (STRU) | 489 | |
483 | else if ( cmd == "STRU" ) { | 490 | // file structure (STRU) |
484 | if ( arg.upper() == "F" ) | 491 | else if ( cmd == "STRU" ) { |
485 | send( "200 Command okay" ); | 492 | if ( arg.upper() == "F" ) |
486 | else | 493 | send( "200 Command okay" ); |
487 | send( "504 Command not implemented for that parameter" ); | 494 | else |
488 | } | 495 | send( "504 Command not implemented for that parameter" ); |
489 | 496 | } | |
490 | // transfer mode (MODE) | 497 | |
491 | else if ( cmd == "MODE" ) { | 498 | // transfer mode (MODE) |
492 | if ( arg.upper() == "S" ) | 499 | else if ( cmd == "MODE" ) { |
493 | send( "200 Command okay" ); | 500 | if ( arg.upper() == "S" ) |
494 | else | 501 | send( "200 Command okay" ); |
495 | send( "504 Command not implemented for that parameter" ); | 502 | else |
496 | } | 503 | send( "504 Command not implemented for that parameter" ); |
497 | 504 | } | |
498 | 505 | ||
499 | // FTP SERVICE COMMANDS | 506 | |
500 | 507 | // FTP SERVICE COMMANDS | |
501 | 508 | ||
502 | // retrieve (RETR) | 509 | |
503 | else if ( cmd == "RETR" ) | 510 | // retrieve (RETR) |
504 | if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) | 511 | else if ( cmd == "RETR" ) |
505 | || backupRestoreGzip( absFilePath( args ) ) ) { | 512 | if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) |
506 | send( "150 File status okay" ); | 513 | || backupRestoreGzip( absFilePath( args ) ) ) { |
507 | sendFile( absFilePath( args ) ); | 514 | send( "150 File status okay" ); |
508 | } | 515 | sendFile( absFilePath( args ) ); |
509 | else { | 516 | } |
510 | qDebug("550 Requested action not taken"); | 517 | else { |
511 | send( "550 Requested action not taken" ); | 518 | qDebug("550 Requested action not taken"); |
512 | } | 519 | send( "550 Requested action not taken" ); |
513 | 520 | } | |
514 | // store (STOR) | 521 | |
515 | else if ( cmd == "STOR" ) | 522 | // store (STOR) |
516 | if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { | 523 | else if ( cmd == "STOR" ) |
517 | send( "150 File status okay" ); | 524 | if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { |
518 | retrieveFile( absFilePath( args ) ); | 525 | send( "150 File status okay" ); |
519 | } | 526 | retrieveFile( absFilePath( args ) ); |
520 | else | 527 | } |
521 | send( "550 Requested action not taken" ); | 528 | else |
522 | 529 | send( "550 Requested action not taken" ); | |
523 | // store unique (STOU) | 530 | |
524 | else if ( cmd == "STOU" ) { | 531 | // store unique (STOU) |
525 | send( "502 Command not implemented" ); | 532 | else if ( cmd == "STOU" ) { |
526 | } | 533 | send( "502 Command not implemented" ); |
527 | 534 | } | |
528 | // append (APPE) | 535 | |
529 | else if ( cmd == "APPE" ) { | 536 | // append (APPE) |
530 | send( "502 Command not implemented" ); | 537 | else if ( cmd == "APPE" ) { |
531 | } | 538 | send( "502 Command not implemented" ); |
532 | 539 | } | |
533 | // allocate (ALLO) | 540 | |
534 | else if ( cmd == "ALLO" ) { | 541 | // allocate (ALLO) |
535 | send( "200 Command okay" ); | 542 | else if ( cmd == "ALLO" ) { |
536 | } | 543 | send( "200 Command okay" ); |
537 | 544 | } | |
538 | // restart (REST) | 545 | |
539 | else if ( cmd == "REST" ) { | 546 | // restart (REST) |
540 | send( "502 Command not implemented" ); | 547 | else if ( cmd == "REST" ) { |
541 | } | 548 | send( "502 Command not implemented" ); |
542 | 549 | } | |
543 | // rename from (RNFR) | 550 | |
544 | else if ( cmd == "RNFR" ) { | 551 | // rename from (RNFR) |
545 | renameFrom = QString::null; | 552 | else if ( cmd == "RNFR" ) { |
546 | if ( args.isEmpty() ) | 553 | renameFrom = QString::null; |
547 | send( "500 Syntax error, command unrecognized" ); | 554 | if ( args.isEmpty() ) |
548 | else { | 555 | send( "500 Syntax error, command unrecognized" ); |
549 | QFile file( absFilePath( args ) ); | 556 | else { |
550 | if ( file.exists() ) { | 557 | QFile file( absFilePath( args ) ); |
551 | send( "350 File exists, ready for destination name" ); | 558 | if ( file.exists() ) { |
552 | renameFrom = absFilePath( args ); | 559 | send( "350 File exists, ready for destination name" ); |
553 | } | 560 | renameFrom = absFilePath( args ); |
554 | else | 561 | } |
555 | send( "550 Requested action not taken" ); | 562 | else |
556 | } | 563 | send( "550 Requested action not taken" ); |
557 | } | 564 | } |
558 | 565 | } | |
559 | // rename to (RNTO) | 566 | |
560 | else if ( cmd == "RNTO" ) { | 567 | // rename to (RNTO) |
561 | if ( lastCommand != "RNFR" ) | 568 | else if ( cmd == "RNTO" ) { |
562 | send( "503 Bad sequence of commands" ); | 569 | if ( lastCommand != "RNFR" ) |
563 | else if ( args.isEmpty() ) | 570 | send( "503 Bad sequence of commands" ); |
564 | send( "500 Syntax error, command unrecognized" ); | 571 | else if ( args.isEmpty() ) |
565 | else { | 572 | send( "500 Syntax error, command unrecognized" ); |
566 | QDir dir( absFilePath( args ) ); | 573 | else { |
567 | if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) | 574 | QDir dir( absFilePath( args ) ); |
568 | send( "250 Requested file action okay, completed." ); | 575 | if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) |
569 | else | 576 | send( "250 Requested file action okay, completed." ); |
570 | send( "550 Requested action not taken" ); | 577 | else |
571 | } | 578 | send( "550 Requested action not taken" ); |
572 | } | 579 | } |
573 | 580 | } | |
574 | // abort (ABOR) | 581 | |
575 | else if ( cmd.contains( "ABOR" ) ) { | 582 | // abort (ABOR) |
576 | dtp->close(); | 583 | else if ( cmd.contains( "ABOR" ) ) { |
577 | if ( dtp->dtpMode() != ServerDTP::Idle ) | 584 | dtp->close(); |
578 | send( "426 Connection closed; transfer aborted" ); | 585 | if ( dtp->dtpMode() != ServerDTP::Idle ) |
579 | else | 586 | send( "426 Connection closed; transfer aborted" ); |
580 | send( "226 Closing data connection" ); | 587 | else |
581 | } | 588 | send( "226 Closing data connection" ); |
582 | 589 | } | |
583 | // delete (DELE) | 590 | |
584 | else if ( cmd == "DELE" ) { | 591 | // delete (DELE) |
585 | if ( args.isEmpty() ) | 592 | else if ( cmd == "DELE" ) { |
586 | send( "500 Syntax error, command unrecognized" ); | 593 | if ( args.isEmpty() ) |
587 | else { | 594 | send( "500 Syntax error, command unrecognized" ); |
588 | QFile file( absFilePath( args ) ) ; | 595 | else { |
589 | if ( file.remove() ) { | 596 | QFile file( absFilePath( args ) ) ; |
590 | send( "250 Requested file action okay, completed" ); | 597 | if ( file.remove() ) { |
591 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); | 598 | send( "250 Requested file action okay, completed" ); |
592 | e << file.name(); | 599 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); |
593 | } else { | 600 | e << file.name(); |
594 | send( "550 Requested action not taken" ); | 601 | } |
595 | } | 602 | else { |
596 | } | 603 | send( "550 Requested action not taken" ); |
597 | } | 604 | } |
598 | 605 | } | |
599 | // remove directory (RMD) | 606 | } |
600 | else if ( cmd == "RMD" ) { | 607 | |
601 | if ( args.isEmpty() ) | 608 | // remove directory (RMD) |
602 | send( "500 Syntax error, command unrecognized" ); | 609 | else if ( cmd == "RMD" ) { |
603 | else { | 610 | if ( args.isEmpty() ) |
604 | QDir dir; | 611 | send( "500 Syntax error, command unrecognized" ); |
605 | if ( dir.rmdir( absFilePath( args ), TRUE ) ) | 612 | else { |
606 | send( "250 Requested file action okay, completed" ); | 613 | QDir dir; |
607 | else | 614 | if ( dir.rmdir( absFilePath( args ), TRUE ) ) |
608 | send( "550 Requested action not taken" ); | 615 | send( "250 Requested file action okay, completed" ); |
609 | } | 616 | else |
610 | } | 617 | send( "550 Requested action not taken" ); |
611 | 618 | } | |
612 | // make directory (MKD) | 619 | } |
613 | else if ( cmd == "MKD" ) { | 620 | |
614 | if ( args.isEmpty() ) { | 621 | // make directory (MKD) |
615 | qDebug(" Error: no arg"); | 622 | else if ( cmd == "MKD" ) { |
616 | send( "500 Syntax error, command unrecognized" ); | 623 | if ( args.isEmpty() ) { |
617 | } | 624 | qDebug(" Error: no arg"); |
618 | else { | 625 | send( "500 Syntax error, command unrecognized" ); |
619 | QDir dir; | 626 | } |
620 | if ( dir.mkdir( absFilePath( args ), TRUE ) ) | 627 | else { |
621 | send( "250 Requested file action okay, completed." ); | 628 | QDir dir; |
622 | else | 629 | if ( dir.mkdir( absFilePath( args ), TRUE ) ) |
623 | send( "550 Requested action not taken" ); | 630 | send( "250 Requested file action okay, completed." ); |
624 | } | 631 | else |
625 | } | 632 | send( "550 Requested action not taken" ); |
626 | 633 | } | |
627 | // print working directory (PWD) | 634 | } |
628 | else if ( cmd == "PWD" ) { | 635 | |
629 | send( "257 \"" + directory.path() +"\"" ); | 636 | // print working directory (PWD) |
630 | } | 637 | else if ( cmd == "PWD" ) { |
631 | 638 | send( "257 \"" + directory.path() + "\"" ); | |
632 | // list (LIST) | 639 | } |
633 | else if ( cmd == "LIST" ) { | 640 | |
634 | if ( sendList( absFilePath( args ) ) ) | 641 | // list (LIST) |
635 | send( "150 File status okay" ); | 642 | else if ( cmd == "LIST" ) { |
636 | else | 643 | if ( sendList( absFilePath( args ) ) ) |
637 | send( "500 Syntax error, command unrecognized" ); | 644 | send( "150 File status okay" ); |
638 | } | 645 | else |
639 | 646 | send( "500 Syntax error, command unrecognized" ); | |
640 | // size (SIZE) | 647 | } |
641 | else if ( cmd == "SIZE" ) { | 648 | |
642 | QString filePath = absFilePath( args ); | 649 | // size (SIZE) |
643 | QFileInfo fi( filePath ); | 650 | else if ( cmd == "SIZE" ) { |
644 | bool gzipfile = backupRestoreGzip( filePath ); | 651 | QString filePath = absFilePath( args ); |
645 | if ( !fi.exists() && !gzipfile ) | 652 | QFileInfo fi( filePath ); |
646 | send( "500 Syntax error, command unrecognized" ); | 653 | bool gzipfile = backupRestoreGzip( filePath ); |
647 | else { | 654 | if ( !fi.exists() && !gzipfile ) |
648 | if ( !gzipfile ) | 655 | send( "500 Syntax error, command unrecognized" ); |
649 | send( "213 " + QString::number( fi.size() ) ); | 656 | else { |
650 | else { | 657 | if ( !gzipfile ) |
651 | Process duproc( QString("du") ); | 658 | send( "213 " + QString::number( fi.size() ) ); |
652 | duproc.addArgument("-s"); | 659 | else { |
653 | QString in, out; | 660 | Process duproc( QString("du") ); |
654 | if ( !duproc.exec(in, out) ) { | 661 | duproc.addArgument("-s"); |
655 | qDebug("du process failed; just sending back 1K"); | 662 | QString in, out; |
656 | send( "213 1024"); | 663 | if ( !duproc.exec(in, out) ) { |
657 | } | 664 | qDebug("du process failed; just sending back 1K"); |
658 | else { | 665 | send( "213 1024"); |
659 | QString size = out.left( out.find("\t") ); | 666 | } |
660 | int guess = size.toInt()/5; | 667 | else { |
661 | if ( filePath.contains("doc") ) | 668 | QString size = out.left( out.find("\t") ); |
662 | guess *= 1000; | 669 | int guess = size.toInt() / 5; |
663 | qDebug("sending back gzip guess of %d", guess); | 670 | if ( filePath.contains("doc") ) |
664 | send( "213 " + QString::number(guess) ); | 671 | guess *= 1000; |
665 | } | 672 | qDebug("sending back gzip guess of %d", guess); |
666 | } | 673 | send( "213 " + QString::number(guess) ); |
667 | } | 674 | } |
668 | } | 675 | } |
669 | // name list (NLST) | 676 | } |
670 | else if ( cmd == "NLST" ) { | 677 | } |
671 | send( "502 Command not implemented" ); | 678 | // name list (NLST) |
672 | } | 679 | else if ( cmd == "NLST" ) { |
673 | 680 | send( "502 Command not implemented" ); | |
674 | // site parameters (SITE) | 681 | } |
675 | else if ( cmd == "SITE" ) { | 682 | |
676 | send( "502 Command not implemented" ); | 683 | // site parameters (SITE) |
677 | } | 684 | else if ( cmd == "SITE" ) { |
678 | 685 | send( "502 Command not implemented" ); | |
679 | // system (SYST) | 686 | } |
680 | else if ( cmd == "SYST" ) { | 687 | |
681 | send( "215 UNIX Type: L8" ); | 688 | // system (SYST) |
682 | } | 689 | else if ( cmd == "SYST" ) { |
683 | 690 | send( "215 UNIX Type: L8" ); | |
684 | // status (STAT) | 691 | } |
685 | else if ( cmd == "STAT" ) { | 692 | |
686 | send( "502 Command not implemented" ); | 693 | // status (STAT) |
687 | } | 694 | else if ( cmd == "STAT" ) { |
688 | 695 | send( "502 Command not implemented" ); | |
689 | // help (HELP ) | 696 | } |
690 | else if ( cmd == "HELP" ) { | 697 | |
691 | send( "502 Command not implemented" ); | 698 | // help (HELP ) |
692 | } | 699 | else if ( cmd == "HELP" ) { |
693 | 700 | send( "502 Command not implemented" ); | |
694 | // noop (NOOP) | 701 | } |
695 | else if ( cmd == "NOOP" ) { | 702 | |
696 | send( "200 Command okay" ); | 703 | // noop (NOOP) |
697 | } | 704 | else if ( cmd == "NOOP" ) { |
698 | 705 | send( "200 Command okay" ); | |
699 | // not implemented | 706 | } |
700 | else | 707 | |
701 | send( "502 Command not implemented" ); | 708 | // not implemented |
702 | 709 | else | |
703 | lastCommand = cmd; | 710 | send( "502 Command not implemented" ); |
711 | |||
712 | lastCommand = cmd; | ||
704 | } | 713 | } |
705 | 714 | ||
706 | bool ServerPI::backupRestoreGzip( const QString &file ) | 715 | bool ServerPI::backupRestoreGzip( const QString &file ) |
707 | { | 716 | { |
708 | return (file.find( "backup" ) != -1 && | 717 | return (file.find( "backup" ) != -1 && |
709 | file.findRev( ".tgz" ) == (int)file.length()-4 ); | 718 | file.findRev( ".tgz" ) == (int)file.length() - 4 ); |
710 | } | 719 | } |
711 | 720 | ||
712 | bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) | 721 | bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) |
713 | { | 722 | { |
714 | if ( file.find( "backup" ) != -1 && | 723 | if ( file.find( "backup" ) != -1 && |
715 | file.findRev( ".tgz" ) == (int)file.length()-4 ) { | 724 | file.findRev( ".tgz" ) == (int)file.length() - 4 ) { |
716 | QFileInfo info( file ); | 725 | QFileInfo info( file ); |
717 | targets = info.dirPath( TRUE ); | 726 | targets = info.dirPath( TRUE ); |
718 | qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), | 727 | qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), |
719 | targets.join(" ").latin1() ); | 728 | targets.join(" ").latin1() ); |
720 | return true; | 729 | return true; |
721 | } | 730 | } |
722 | return false; | 731 | return false; |
723 | } | 732 | } |
724 | 733 | ||
725 | void ServerPI::sendFile( const QString& file ) | 734 | void ServerPI::sendFile( const QString& file ) |
726 | { | 735 | { |
727 | if ( passiv ) { | 736 | if ( passiv ) { |
728 | wait[SendFile] = TRUE; | 737 | wait[SendFile] = TRUE; |
729 | waitfile = file; | 738 | waitfile = file; |
730 | if ( waitsocket ) | 739 | if ( waitsocket ) |
731 | newConnection( waitsocket ); | 740 | newConnection( waitsocket ); |
732 | } | 741 | } |
733 | else { | 742 | else { |
734 | QStringList targets; | 743 | QStringList targets; |
735 | if ( backupRestoreGzip( file, targets ) ) | 744 | if ( backupRestoreGzip( file, targets ) ) |
736 | dtp->sendGzipFile( file, targets, peeraddress, peerport ); | 745 | dtp->sendGzipFile( file, targets, peeraddress, peerport ); |
737 | else dtp->sendFile( file, peeraddress, peerport ); | 746 | else |
738 | } | 747 | dtp->sendFile( file, peeraddress, peerport ); |
748 | } | ||
739 | } | 749 | } |
740 | 750 | ||
741 | void ServerPI::retrieveFile( const QString& file ) | 751 | void ServerPI::retrieveFile( const QString& file ) |
742 | { | 752 | { |
743 | if ( passiv ) { | 753 | if ( passiv ) { |
744 | wait[RetrieveFile] = TRUE; | 754 | wait[RetrieveFile] = TRUE; |
745 | waitfile = file; | 755 | waitfile = file; |
746 | if ( waitsocket ) | 756 | if ( waitsocket ) |
747 | newConnection( waitsocket ); | 757 | newConnection( waitsocket ); |
748 | } | 758 | } |
749 | else { | 759 | else { |
750 | QStringList targets; | 760 | QStringList targets; |
751 | if ( backupRestoreGzip( file, targets ) ) | 761 | if ( backupRestoreGzip( file, targets ) ) |
752 | dtp->retrieveGzipFile( file, peeraddress, peerport ); | 762 | dtp->retrieveGzipFile( file, peeraddress, peerport ); |
753 | else | 763 | else |
754 | dtp->retrieveFile( file, peeraddress, peerport ); | 764 | dtp->retrieveFile( file, peeraddress, peerport ); |
755 | } | 765 | } |
756 | } | 766 | } |
757 | 767 | ||
758 | bool ServerPI::parsePort( const QString& pp ) | 768 | bool ServerPI::parsePort( const QString& pp ) |
759 | { | 769 | { |
760 | QStringList p = QStringList::split( ",", pp ); | 770 | QStringList p = QStringList::split( ",", pp ); |
761 | if ( p.count() != 6 ) return FALSE; | 771 | if ( p.count() != 6 ) |
762 | 772 | return FALSE; | |
763 | // h1,h2,h3,h4,p1,p2 | 773 | |
764 | peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + | 774 | // h1,h2,h3,h4,p1,p2 |
765 | ( p[2].toInt() << 8 ) + p[3].toInt() ); | 775 | peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + |
766 | peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); | 776 | ( p[2].toInt() << 8 ) + p[3].toInt() ); |
767 | return TRUE; | 777 | peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); |
778 | return TRUE; | ||
768 | } | 779 | } |
769 | 780 | ||
770 | void ServerPI::dtpCompleted() | 781 | void ServerPI::dtpCompleted() |
771 | { | 782 | { |
772 | send( "226 Closing data connection, file transfer successful" ); | 783 | send( "226 Closing data connection, file transfer successful" ); |
773 | if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { | 784 | if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { |
774 | QString fn = dtp->fileName(); | 785 | QString fn = dtp->fileName(); |
775 | if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) { | 786 | if ( fn.right(8) == ".desktop" && fn.find("/Documents/") >= 0 ) { |
776 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); | 787 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); |
777 | e << fn; | 788 | e << fn; |
778 | } | 789 | } |
779 | } | 790 | } |
780 | waitsocket = 0; | 791 | waitsocket = 0; |
781 | dtp->close(); | 792 | dtp->close(); |
782 | } | 793 | } |
783 | 794 | ||
784 | void ServerPI::dtpFailed() | 795 | void ServerPI::dtpFailed() |
785 | { | 796 | { |
786 | dtp->close(); | 797 | dtp->close(); |
787 | waitsocket = 0; | 798 | waitsocket = 0; |
788 | send( "451 Requested action aborted: local error in processing" ); | 799 | send( "451 Requested action aborted: local error in processing" ); |
789 | } | 800 | } |
790 | 801 | ||
791 | void ServerPI::dtpError( int ) | 802 | void ServerPI::dtpError( int ) |
792 | { | 803 | { |
793 | dtp->close(); | 804 | dtp->close(); |
794 | waitsocket = 0; | 805 | waitsocket = 0; |
795 | send( "451 Requested action aborted: local error in processing" ); | 806 | send( "451 Requested action aborted: local error in processing" ); |
796 | } | 807 | } |
797 | 808 | ||
798 | bool ServerPI::sendList( const QString& arg ) | 809 | bool ServerPI::sendList( const QString& arg ) |
799 | { | 810 | { |
800 | QByteArray listing; | 811 | QByteArray listing; |
801 | QBuffer buffer( listing ); | 812 | QBuffer buffer( listing ); |
802 | 813 | ||
803 | if ( !buffer.open( IO_WriteOnly ) ) | 814 | if ( !buffer.open( IO_WriteOnly ) ) |
804 | return FALSE; | 815 | return FALSE; |
805 | 816 | ||
806 | QTextStream ts( &buffer ); | 817 | QTextStream ts( &buffer ); |
807 | QString fn = arg; | 818 | QString fn = arg; |
808 | 819 | ||
809 | if ( fn.isEmpty() ) | 820 | if ( fn.isEmpty() ) |
810 | fn = directory.path(); | 821 | fn = directory.path(); |
811 | 822 | ||
812 | QFileInfo fi( fn ); | 823 | QFileInfo fi( fn ); |
813 | if ( !fi.exists() ) return FALSE; | 824 | if ( !fi.exists() ) |
814 | 825 | return FALSE; | |
815 | // return file listing | 826 | |
816 | if ( fi.isFile() ) { | 827 | // return file listing |
817 | ts << fileListing( &fi ) << endl; | 828 | if ( fi.isFile() ) { |
818 | } | 829 | ts << fileListing( &fi ) << endl; |
819 | 830 | } | |
820 | // return directory listing | 831 | |
821 | else if ( fi.isDir() ) { | 832 | // return directory listing |
822 | QDir dir( fn ); | 833 | else if ( fi.isDir() ) { |
823 | const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); | 834 | QDir dir( fn ); |
824 | 835 | const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); | |
825 | QFileInfoListIterator it( *list ); | 836 | |
826 | QFileInfo *info; | 837 | QFileInfoListIterator it( *list ); |
827 | 838 | QFileInfo *info; | |
828 | unsigned long total = 0; | 839 | |
829 | while ( ( info = it.current() ) ) { | 840 | unsigned long total = 0; |
830 | if ( info->fileName() != "." && info->fileName() != ".." ) | 841 | while ( ( info = it.current() ) ) { |
831 | total += info->size(); | 842 | if ( info->fileName() != "." && info->fileName() != ".." ) |
832 | ++it; | 843 | total += info->size(); |
833 | } | 844 | ++it; |
834 | 845 | } | |
835 | ts << "total " << QString::number( total / 1024 ) << endl; | 846 | |
836 | 847 | ts << "total " << QString::number( total / 1024 ) << endl; | |
837 | it.toFirst(); | 848 | |
838 | while ( ( info = it.current() ) ) { | 849 | it.toFirst(); |
839 | if ( info->fileName() == "." || info->fileName() == ".." ) { | 850 | while ( ( info = it.current() ) ) { |
840 | ++it; | 851 | if ( info->fileName() == "." || info->fileName() == ".." ) { |
841 | continue; | 852 | ++it; |
842 | } | 853 | continue; |
843 | ts << fileListing( info ) << endl; | 854 | } |
844 | ++it; | 855 | ts << fileListing( info ) << endl; |
845 | } | 856 | ++it; |
846 | } | 857 | } |
847 | 858 | } | |
848 | if ( passiv ) { | 859 | |
849 | waitarray = buffer.buffer(); | 860 | if ( passiv ) { |
850 | wait[SendByteArray] = TRUE; | 861 | waitarray = buffer.buffer(); |
851 | if ( waitsocket ) | 862 | wait[SendByteArray] = TRUE; |
852 | newConnection( waitsocket ); | 863 | if ( waitsocket ) |
853 | } | 864 | newConnection( waitsocket ); |
854 | else | 865 | } |
855 | dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); | 866 | else |
856 | return TRUE; | 867 | dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); |
868 | return TRUE; | ||
857 | } | 869 | } |
858 | 870 | ||
859 | QString ServerPI::fileListing( QFileInfo *info ) | 871 | QString ServerPI::fileListing( QFileInfo *info ) |
860 | { | 872 | { |
861 | if ( !info ) return QString::null; | 873 | if ( !info ) |
862 | QString s; | 874 | return QString::null; |
875 | QString s; | ||
863 | 876 | ||
864 | // type char | 877 | // type char |
865 | if ( info->isDir() ) | 878 | if ( info->isDir() ) |
866 | s += "d"; | 879 | s += "d"; |
867 | else if ( info->isSymLink() ) | 880 | else if ( info->isSymLink() ) |
868 | s += "l"; | 881 | s += "l"; |
869 | else | 882 | else |
870 | s += "-"; | 883 | s += "-"; |
871 | 884 | ||
872 | // permisson string | 885 | // permisson string |
873 | s += permissionString( info ) + " "; | 886 | s += permissionString( info ) + " "; |
874 | 887 | ||
875 | // number of hardlinks | 888 | // number of hardlinks |
876 | int subdirs = 1; | 889 | int subdirs = 1; |
877 | 890 | ||
878 | if ( info->isDir() ) | 891 | if ( info->isDir() ) |
879 | subdirs = 2; | 892 | subdirs = 2; |
880 | // FIXME : this is to slow | 893 | // FIXME : this is to slow |
881 | //if ( info->isDir() ) | 894 | //if ( info->isDir() ) |
882 | //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); | 895 | //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); |
883 | 896 | ||
884 | s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; | 897 | s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; |
885 | 898 | ||
886 | // owner | 899 | // owner |
887 | s += info->owner().leftJustify( 8, ' ', TRUE ) + " "; | 900 | s += info->owner().leftJustify( 8, ' ', TRUE ) + " "; |
888 | 901 | ||
889 | // group | 902 | // group |
890 | s += info->group().leftJustify( 8, ' ', TRUE ) + " "; | 903 | s += info->group().leftJustify( 8, ' ', TRUE ) + " "; |
891 | 904 | ||
892 | // file size in bytes | 905 | // file size in bytes |
893 | s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; | 906 | s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; |
894 | 907 | ||
895 | // last modified date | 908 | // last modified date |
896 | QDate date = info->lastModified().date(); | 909 | QDate date = info->lastModified().date(); |
897 | QTime time = info->lastModified().time(); | 910 | QTime time = info->lastModified().time(); |
898 | s += date.monthName( date.month() ) + " " | 911 | s += date.monthName( date.month() ) + " " |
899 | + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " | 912 | + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " |
900 | + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" | 913 | + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" |
901 | + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; | 914 | + QString::number( time.minute() ).rightJustify( 2, '0', TRUE ) + " "; |
902 | 915 | ||
903 | // file name | 916 | // file name |
904 | s += info->fileName(); | 917 | s += info->fileName(); |
905 | 918 | ||
906 | return s; | 919 | return s; |
907 | } | 920 | } |
908 | 921 | ||
909 | QString ServerPI::permissionString( QFileInfo *info ) | 922 | QString ServerPI::permissionString( QFileInfo *info ) |
910 | { | 923 | { |
911 | if ( !info ) return QString( "---------" ); | 924 | if ( !info ) |
912 | QString s; | 925 | return QString( "---------" ); |
913 | 926 | QString s; | |
914 | // user | 927 | |
915 | if ( info->permission( QFileInfo::ReadUser ) ) s += "r"; | 928 | // user |
916 | else s += "-"; | 929 | if ( info->permission( QFileInfo::ReadUser ) ) |
917 | if ( info->permission( QFileInfo::WriteUser ) ) s += "w"; | 930 | s += "r"; |
918 | else s += "-"; | 931 | else |
919 | if ( info->permission( QFileInfo::ExeUser ) ) s += "x"; | 932 | s += "-"; |
920 | else s += "-"; | 933 | if ( info->permission( QFileInfo::WriteUser ) ) |
921 | 934 | s += "w"; | |
922 | // group | 935 | else |
923 | if ( info->permission( QFileInfo::ReadGroup ) ) s += "r"; | 936 | s += "-"; |
924 | else s += "-"; | 937 | if ( info->permission( QFileInfo::ExeUser ) ) |
925 | if ( info->permission( QFileInfo::WriteGroup ) )s += "w"; | 938 | s += "x"; |
926 | else s += "-"; | 939 | else |
927 | if ( info->permission( QFileInfo::ExeGroup ) ) s += "x"; | 940 | s += "-"; |
928 | else s += "-"; | 941 | |
929 | 942 | // group | |
930 | // exec | 943 | if ( info->permission( QFileInfo::ReadGroup ) ) |
931 | if ( info->permission( QFileInfo::ReadOther ) ) s += "r"; | 944 | s += "r"; |
932 | else s += "-"; | 945 | else |
933 | if ( info->permission( QFileInfo::WriteOther ) ) s += "w"; | 946 | s += "-"; |
934 | else s += "-"; | 947 | if ( info->permission( QFileInfo::WriteGroup ) ) |
935 | if ( info->permission( QFileInfo::ExeOther ) ) s += "x"; | 948 | s += "w"; |
936 | else s += "-"; | 949 | else |
937 | 950 | s += "-"; | |
938 | return s; | 951 | if ( info->permission( QFileInfo::ExeGroup ) ) |
952 | s += "x"; | ||
953 | else | ||
954 | s += "-"; | ||
955 | |||
956 | // exec | ||
957 | if ( info->permission( QFileInfo::ReadOther ) ) | ||
958 | s += "r"; | ||
959 | else | ||
960 | s += "-"; | ||
961 | if ( info->permission( QFileInfo::WriteOther ) ) | ||
962 | s += "w"; | ||
963 | else | ||
964 | s += "-"; | ||
965 | if ( info->permission( QFileInfo::ExeOther ) ) | ||
966 | s += "x"; | ||
967 | else | ||
968 | s += "-"; | ||
969 | |||
970 | return s; | ||
939 | } | 971 | } |
940 | 972 | ||
941 | void ServerPI::newConnection( int socket ) | 973 | void ServerPI::newConnection( int socket ) |
942 | { | 974 | { |
943 | //qDebug( "New incomming connection" ); | 975 | //qDebug( "New incomming connection" ); |
944 | 976 | ||
945 | if ( !passiv ) return; | 977 | if ( !passiv ) |
946 | 978 | return ; | |
947 | if ( wait[SendFile] ) { | 979 | |
948 | QStringList targets; | 980 | if ( wait[SendFile] ) { |
949 | if ( backupRestoreGzip( waitfile, targets ) ) | 981 | QStringList targets; |
950 | dtp->sendGzipFile( waitfile, targets ); | 982 | if ( backupRestoreGzip( waitfile, targets ) ) |
951 | else | 983 | dtp->sendGzipFile( waitfile, targets ); |
952 | dtp->sendFile( waitfile ); | 984 | else |
953 | dtp->setSocket( socket ); | 985 | dtp->sendFile( waitfile ); |
954 | } | 986 | dtp->setSocket( socket ); |
955 | else if ( wait[RetrieveFile] ) { | 987 | } |
956 | qDebug("check retrieve file"); | 988 | else if ( wait[RetrieveFile] ) { |
957 | if ( backupRestoreGzip( waitfile ) ) | 989 | qDebug("check retrieve file"); |
958 | dtp->retrieveGzipFile( waitfile ); | 990 | if ( backupRestoreGzip( waitfile ) ) |
959 | else | 991 | dtp->retrieveGzipFile( waitfile ); |
960 | dtp->retrieveFile( waitfile ); | 992 | else |
961 | dtp->setSocket( socket ); | 993 | dtp->retrieveFile( waitfile ); |
962 | } | 994 | dtp->setSocket( socket ); |
963 | else if ( wait[SendByteArray] ) { | 995 | } |
964 | dtp->sendByteArray( waitarray ); | 996 | else if ( wait[SendByteArray] ) { |
965 | dtp->setSocket( socket ); | 997 | dtp->sendByteArray( waitarray ); |
966 | } | 998 | dtp->setSocket( socket ); |
967 | else if ( wait[RetrieveByteArray] ) { | 999 | } |
968 | qDebug("retrieve byte array"); | 1000 | else if ( wait[RetrieveByteArray] ) { |
969 | dtp->retrieveByteArray(); | 1001 | qDebug("retrieve byte array"); |
970 | dtp->setSocket( socket ); | 1002 | dtp->retrieveByteArray(); |
971 | } | 1003 | dtp->setSocket( socket ); |
972 | else | 1004 | } |
973 | waitsocket = socket; | 1005 | else |
974 | 1006 | waitsocket = socket; | |
975 | for( int i = 0; i < 4; i++ ) | 1007 | |
976 | wait[i] = FALSE; | 1008 | for ( int i = 0; i < 4; i++ ) |
1009 | wait[i] = FALSE; | ||
977 | } | 1010 | } |
978 | 1011 | ||
979 | QString ServerPI::absFilePath( const QString& file ) | 1012 | QString ServerPI::absFilePath( const QString& file ) |
980 | { | 1013 | { |
981 | if ( file.isEmpty() ) return file; | 1014 | if ( file.isEmpty() ) |
1015 | return file; | ||
982 | 1016 | ||
983 | QString filepath( file ); | 1017 | QString filepath( file ); |
984 | if ( file[0] != "/" ) | 1018 | if ( file[0] != "/" ) |
985 | filepath = directory.path() + "/" + file; | 1019 | filepath = directory.path() + "/" + file; |
986 | 1020 | ||
987 | return filepath; | 1021 | return filepath; |
988 | } | 1022 | } |
989 | 1023 | ||
990 | 1024 | ||
991 | void ServerPI::timerEvent( QTimerEvent * ) | 1025 | void ServerPI::timerEvent( QTimerEvent * ) |
992 | { | 1026 | { |
993 | connectionClosed(); | 1027 | connectionClosed(); |
994 | } | 1028 | } |
995 | 1029 | ||
996 | 1030 | ||
997 | ServerDTP::ServerDTP( QObject *parent, const char* name) | 1031 | ServerDTP::ServerDTP( QObject *parent, const char* name) |
998 | : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), | 1032 | : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), |
999 | retrieveTargzProc( 0 ), gzipProc( 0 ) | 1033 | retrieveTargzProc( 0 ), gzipProc( 0 ) |
1000 | { | 1034 | { |
1001 | 1035 | ||
1002 | connect( this, SIGNAL( connected() ), SLOT( connected() ) ); | 1036 | connect( this, SIGNAL( connected() ), SLOT( connected() ) ); |
1003 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 1037 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
1004 | connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); | 1038 | connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); |
1005 | connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); | 1039 | connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); |
1006 | 1040 | ||
1007 | gzipProc = new QProcess( this, "gzipProc" ); | 1041 | gzipProc = new OProcess( this, "gzipProc" ); |
1008 | gzipProc->setCommunication( QProcess::Stdin | QProcess::Stdout ); | 1042 | |
1009 | 1043 | createTargzProc = new OProcess( QString("tar"), this, "createTargzProc"); | |
1010 | createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); | 1044 | createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); |
1011 | createTargzProc->setCommunication( QProcess::Stdout ); | 1045 | connect( createTargzProc, SIGNAL( processExited(OProcess *) ), SLOT( targzDone() ) ); |
1012 | createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); | 1046 | |
1013 | connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); | 1047 | QStringList args = "tar"; |
1014 | 1048 | args += "-xv"; | |
1015 | QStringList args = "tar"; | 1049 | retrieveTargzProc = new OProcess( args, this, "retrieveTargzProc" ); |
1016 | args += "-xv"; | 1050 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); |
1017 | retrieveTargzProc = new QProcess( args, this, "retrieveTargzProc" ); | 1051 | connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ), |
1018 | retrieveTargzProc->setCommunication( QProcess::Stdin ); | 1052 | SIGNAL( completed() ) ); |
1019 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); | 1053 | connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ), |
1020 | connect( retrieveTargzProc, SIGNAL( processExited() ), | 1054 | SLOT( extractTarDone() ) ); |
1021 | SIGNAL( completed() ) ); | ||
1022 | connect( retrieveTargzProc, SIGNAL( processExited() ), | ||
1023 | SLOT( extractTarDone() ) ); | ||
1024 | } | 1055 | } |
1025 | 1056 | ||
1026 | ServerDTP::~ServerDTP() | 1057 | ServerDTP::~ServerDTP() |
1027 | { | 1058 | { |
1028 | buf.close(); | 1059 | buf.close(); |
1029 | file.close(); | 1060 | file.close(); |
1030 | createTargzProc->kill(); | 1061 | createTargzProc->kill(); |
1031 | } | 1062 | } |
1032 | 1063 | ||
1033 | void ServerDTP::extractTarDone() | 1064 | void ServerDTP::extractTarDone() |
1034 | { | 1065 | { |
1035 | qDebug("extract done"); | 1066 | qDebug("extract done"); |
1036 | #ifndef QT_NO_COP | 1067 | #ifndef QT_NO_COP |
1037 | QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); | 1068 | |
1038 | e << file.name(); | 1069 | QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); |
1070 | e << file.name(); | ||
1039 | #endif | 1071 | #endif |
1040 | } | 1072 | } |
1041 | 1073 | ||
1042 | void ServerDTP::connected() | 1074 | void ServerDTP::connected() |
1043 | { | 1075 | { |
1044 | // send file mode | 1076 | // send file mode |
1045 | switch ( mode ) { | 1077 | switch ( mode ) { |
1046 | case SendFile : | 1078 | case SendFile : |
1047 | if ( !file.exists() || !file.open( IO_ReadOnly) ) { | 1079 | if ( !file.exists() || !file.open( IO_ReadOnly) ) { |
1048 | emit failed(); | 1080 | emit failed(); |
1049 | mode = Idle; | 1081 | mode = Idle; |
1050 | return; | 1082 | return ; |
1051 | } | 1083 | } |
1052 | 1084 | ||
1053 | //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); | 1085 | //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); |
1054 | 1086 | ||
1055 | bytes_written = 0; | 1087 | bytes_written = 0; |
1056 | if ( file.size() == 0 ) { | 1088 | if ( file.size() == 0 ) { |
1057 | //make sure it doesn't hang on empty files | 1089 | //make sure it doesn't hang on empty files |
1058 | file.close(); | 1090 | file.close(); |
1059 | emit completed(); | 1091 | emit completed(); |
1060 | mode = Idle; | 1092 | mode = Idle; |
1061 | } else { | 1093 | } |
1062 | 1094 | else { | |
1063 | if( !file.atEnd() ) { | 1095 | |
1064 | QCString s; | 1096 | if ( !file.atEnd() ) { |
1065 | s.resize( block_size ); | 1097 | QCString s; |
1066 | int bytes = file.readBlock( s.data(), block_size ); | 1098 | s.resize( block_size ); |
1067 | writeBlock( s.data(), bytes ); | 1099 | int bytes = file.readBlock( s.data(), block_size ); |
1068 | } | 1100 | writeBlock( s.data(), bytes ); |
1069 | } | 1101 | } |
1070 | break; | 1102 | } |
1071 | case SendGzipFile: | 1103 | break; |
1072 | if ( createTargzProc->isRunning() ) { | 1104 | case SendGzipFile: |
1073 | // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY | 1105 | if ( createTargzProc->isRunning() ) { |
1074 | qWarning("Previous tar --gzip process is still running; killing it..."); | 1106 | // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY |
1075 | createTargzProc->kill(); | 1107 | qWarning("Previous tar --gzip process is still running; killing it..."); |
1076 | } | 1108 | createTargzProc->kill(); |
1077 | 1109 | } | |
1078 | bytes_written = 0; | 1110 | |
1079 | qDebug("==>start send tar process"); | 1111 | bytes_written = 0; |
1080 | if ( !createTargzProc->start() ) | 1112 | qDebug("==>start send tar process"); |
1081 | qWarning("Error starting %s or %s", | 1113 | if ( !createTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdout) ) |
1082 | createTargzProc->arguments().join(" ").latin1(), | 1114 | qWarning("Error starting %s or %s", |
1083 | gzipProc->arguments().join(" ").latin1() ); | 1115 | createTargzProc->args()[0].data(), |
1084 | break; | 1116 | gzipProc->args()[0].data()); |
1085 | case SendBuffer: | 1117 | break; |
1086 | if ( !buf.open( IO_ReadOnly) ) { | 1118 | case SendBuffer: |
1087 | emit failed(); | 1119 | if ( !buf.open( IO_ReadOnly) ) { |
1088 | mode = Idle; | 1120 | emit failed(); |
1089 | return; | 1121 | mode = Idle; |
1090 | } | 1122 | return ; |
1091 | 1123 | } | |
1092 | // qDebug( "Debug: Sending byte array" ); | 1124 | |
1093 | bytes_written = 0; | 1125 | // qDebug( "Debug: Sending byte array" ); |
1094 | while( !buf.atEnd() ) | 1126 | bytes_written = 0; |
1095 | putch( buf.getch() ); | 1127 | while ( !buf.atEnd() ) |
1096 | buf.close(); | 1128 | putch( buf.getch() ); |
1097 | break; | 1129 | buf.close(); |
1098 | case RetrieveFile: | 1130 | break; |
1099 | // retrieve file mode | 1131 | case RetrieveFile: |
1100 | if ( file.exists() && !file.remove() ) { | 1132 | // retrieve file mode |
1101 | emit failed(); | 1133 | if ( file.exists() && !file.remove() ) { |
1102 | mode = Idle; | 1134 | emit failed(); |
1103 | return; | 1135 | mode = Idle; |
1104 | } | 1136 | return ; |
1105 | 1137 | } | |
1106 | if ( !file.open( IO_WriteOnly) ) { | 1138 | |
1107 | emit failed(); | 1139 | if ( !file.open( IO_WriteOnly) ) { |
1108 | mode = Idle; | 1140 | emit failed(); |
1109 | return; | 1141 | mode = Idle; |
1110 | } | 1142 | return ; |
1111 | // qDebug( "Debug: Retrieving file %s", file.name().latin1() ); | 1143 | } |
1112 | break; | 1144 | // qDebug( "Debug: Retrieving file %s", file.name().latin1() ); |
1113 | case RetrieveGzipFile: | 1145 | break; |
1114 | qDebug("=-> starting tar process to receive .tgz file"); | 1146 | case RetrieveGzipFile: |
1115 | break; | 1147 | qDebug("=-> starting tar process to receive .tgz file"); |
1116 | case RetrieveBuffer: | 1148 | break; |
1117 | // retrieve buffer mode | 1149 | case RetrieveBuffer: |
1118 | if ( !buf.open( IO_WriteOnly) ) { | 1150 | // retrieve buffer mode |
1119 | emit failed(); | 1151 | if ( !buf.open( IO_WriteOnly) ) { |
1120 | mode = Idle; | 1152 | emit failed(); |
1121 | return; | 1153 | mode = Idle; |
1122 | } | 1154 | return ; |
1123 | // qDebug( "Debug: Retrieving byte array" ); | 1155 | } |
1124 | break; | 1156 | // qDebug( "Debug: Retrieving byte array" ); |
1125 | case Idle: | 1157 | break; |
1126 | qDebug("connection established but mode set to Idle; BUG!"); | 1158 | case Idle: |
1127 | break; | 1159 | qDebug("connection established but mode set to Idle; BUG!"); |
1128 | } | 1160 | break; |
1161 | } | ||
1129 | } | 1162 | } |
1130 | 1163 | ||
1131 | void ServerDTP::connectionClosed() | 1164 | void ServerDTP::connectionClosed() |
1132 | { | 1165 | { |
1133 | //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written ); | 1166 | //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written ); |
1134 | 1167 | ||
1135 | // send file mode | 1168 | // send file mode |
1136 | if ( SendFile == mode ) { | 1169 | if ( SendFile == mode ) { |
1137 | if ( bytes_written == file.size() ) | 1170 | if ( bytes_written == file.size() ) |
1138 | emit completed(); | 1171 | emit completed(); |
1139 | else | 1172 | else |
1140 | emit failed(); | 1173 | emit failed(); |
1141 | } | 1174 | } |
1142 | 1175 | ||
1143 | // send buffer mode | 1176 | // send buffer mode |
1144 | else if ( SendBuffer == mode ) { | 1177 | else if ( SendBuffer == mode ) { |
1145 | if ( bytes_written == buf.size() ) | 1178 | if ( bytes_written == buf.size() ) |
1146 | emit completed(); | 1179 | emit completed(); |
1147 | else | 1180 | else |
1148 | emit failed(); | 1181 | emit failed(); |
1149 | } | 1182 | } |
1150 | 1183 | ||
1151 | // retrieve file mode | 1184 | // retrieve file mode |
1152 | else if ( RetrieveFile == mode ) { | 1185 | else if ( RetrieveFile == mode ) { |
1153 | file.close(); | 1186 | file.close(); |
1154 | emit completed(); | 1187 | emit completed(); |
1155 | } | 1188 | } |
1156 | 1189 | ||
1157 | else if ( RetrieveGzipFile == mode ) { | 1190 | else if ( RetrieveGzipFile == mode ) { |
1158 | qDebug("Done writing ungzip file; closing input"); | 1191 | qDebug("Done writing ungzip file; closing input"); |
1159 | gzipProc->flushStdin(); | 1192 | gzipProc->flushStdin(); |
1160 | gzipProc->closeStdin(); | 1193 | gzipProc->closeStdin(); |
1161 | } | 1194 | } |
1162 | 1195 | ||
1163 | // retrieve buffer mode | 1196 | // retrieve buffer mode |
1164 | else if ( RetrieveBuffer == mode ) { | 1197 | else if ( RetrieveBuffer == mode ) { |
1165 | buf.close(); | 1198 | buf.close(); |
1166 | emit completed(); | 1199 | emit completed(); |
1167 | } | 1200 | } |
1168 | 1201 | ||
1169 | mode = Idle; | 1202 | mode = Idle; |
1170 | } | 1203 | } |
1171 | 1204 | ||
1172 | void ServerDTP::bytesWritten( int bytes ) | 1205 | void ServerDTP::bytesWritten( int bytes ) |
1173 | { | 1206 | { |
1174 | bytes_written += bytes; | 1207 | bytes_written += bytes; |
1175 | 1208 | ||
1176 | // send file mode | 1209 | // send file mode |
1177 | if ( SendFile == mode ) { | 1210 | if ( SendFile == mode ) { |
1178 | 1211 | ||
1179 | if ( bytes_written == file.size() ) { | 1212 | if ( bytes_written == file.size() ) { |
1180 | // qDebug( "Debug: Sending complete: %d bytes", file.size() ); | 1213 | // qDebug( "Debug: Sending complete: %d bytes", file.size() ); |
1181 | file.close(); | 1214 | file.close(); |
1182 | emit completed(); | 1215 | emit completed(); |
1183 | mode = Idle; | 1216 | mode = Idle; |
1184 | } | 1217 | } |
1185 | else if( !file.atEnd() ) { | 1218 | else if ( !file.atEnd() ) { |
1186 | QCString s; | 1219 | QCString s; |
1187 | s.resize( block_size ); | 1220 | s.resize( block_size ); |
1188 | int bytes = file.readBlock( s.data(), block_size ); | 1221 | int bytes = file.readBlock( s.data(), block_size ); |
1189 | writeBlock( s.data(), bytes ); | 1222 | writeBlock( s.data(), bytes ); |
1190 | } | 1223 | } |
1191 | } | 1224 | } |
1192 | 1225 | ||
1193 | // send buffer mode | 1226 | // send buffer mode |
1194 | if ( SendBuffer == mode ) { | 1227 | if ( SendBuffer == mode ) { |
1195 | 1228 | ||
1196 | if ( bytes_written == buf.size() ) { | 1229 | if ( bytes_written == buf.size() ) { |
1197 | // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); | 1230 | // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); |
1198 | emit completed(); | 1231 | emit completed(); |
1199 | mode = Idle; | 1232 | mode = Idle; |
1200 | } | 1233 | } |
1201 | } | 1234 | } |
1202 | } | 1235 | } |
1203 | 1236 | ||
1204 | void ServerDTP::readyRead() | 1237 | void ServerDTP::readyRead() |
1205 | { | 1238 | { |
1206 | // retrieve file mode | 1239 | // retrieve file mode |
1207 | if ( RetrieveFile == mode ) { | 1240 | if ( RetrieveFile == mode ) { |
1208 | QCString s; | 1241 | QCString s; |
1209 | s.resize( bytesAvailable() ); | 1242 | s.resize( bytesAvailable() ); |
1210 | readBlock( s.data(), bytesAvailable() ); | 1243 | readBlock( s.data(), bytesAvailable() ); |
1211 | file.writeBlock( s.data(), s.size() ); | 1244 | file.writeBlock( s.data(), s.size() ); |
1212 | } | 1245 | } |
1213 | else if ( RetrieveGzipFile == mode ) { | 1246 | else if ( RetrieveGzipFile == mode ) { |
1214 | if ( !gzipProc->isRunning() ) | 1247 | if ( !gzipProc->isRunning() ) |
1215 | gzipProc->start(); | 1248 | gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout )); |
1216 | 1249 | ||
1217 | QByteArray s; | 1250 | QByteArray s; |
1218 | s.resize( bytesAvailable() ); | 1251 | s.resize( bytesAvailable() ); |
1219 | readBlock( s.data(), bytesAvailable() ); | 1252 | readBlock( s.data(), bytesAvailable() ); |
1220 | gzipProc->writeToStdin( s ); | 1253 | gzipProc->writeStdin( s.data(), s.size() ); |
1221 | qDebug("wrote %d bytes to ungzip ", s.size() ); | 1254 | qDebug("wrote %d bytes to ungzip ", s.size() ); |
1222 | } | 1255 | } |
1223 | // retrieve buffer mode | 1256 | // retrieve buffer mode |
1224 | else if ( RetrieveBuffer == mode ) { | 1257 | else if ( RetrieveBuffer == mode ) { |
1225 | QCString s; | 1258 | QCString s; |
1226 | s.resize( bytesAvailable() ); | 1259 | s.resize( bytesAvailable() ); |
1227 | readBlock( s.data(), bytesAvailable() ); | 1260 | readBlock( s.data(), bytesAvailable() ); |
1228 | buf.writeBlock( s.data(), s.size() ); | 1261 | buf.writeBlock( s.data(), s.size() ); |
1229 | } | 1262 | } |
1230 | } | 1263 | } |
1231 | 1264 | ||
1232 | void ServerDTP::writeTargzBlock() | 1265 | void ServerDTP::writeTargzBlock(OProcess *, char *buffer, int buflen) |
1233 | { | 1266 | { |
1234 | QByteArray block = gzipProc->readStdout(); | 1267 | writeBlock( buffer, buflen ); |
1235 | writeBlock( block.data(), block.size() ); | 1268 | qDebug("writeTargzBlock %d", buflen); |
1236 | qDebug("writeTargzBlock %d", block.size()); | 1269 | if ( !createTargzProc->isRunning() ) { |
1237 | if ( !createTargzProc->isRunning() ) { | 1270 | qDebug("tar and gzip done"); |
1238 | qDebug("tar and gzip done"); | 1271 | emit completed(); |
1239 | emit completed(); | 1272 | mode = Idle; |
1240 | mode = Idle; | 1273 | disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int ) ), |
1241 | disconnect( gzipProc, SIGNAL( readyReadStdout() ), | 1274 | this, SLOT( writeTargzBlock(OProcess *, char *, int) ) ); |
1242 | this, SLOT( writeTargzBlock() ) ); | 1275 | } |
1243 | } | ||
1244 | } | 1276 | } |
1245 | 1277 | ||
1246 | void ServerDTP::targzDone() | 1278 | void ServerDTP::targzDone() |
1247 | { | 1279 | { |
1248 | //qDebug("targz done"); | 1280 | //qDebug("targz done"); |
1249 | disconnect( createTargzProc, SIGNAL( readyReadStdout() ), | 1281 | disconnect( createTargzProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), |
1250 | this, SLOT( gzipTarBlock() ) ); | 1282 | this, SLOT( gzipTarBlock(OProcess *, char *, int) ) ); |
1251 | gzipProc->closeStdin(); | 1283 | gzipProc->closeStdin(); |
1252 | } | 1284 | } |
1253 | 1285 | ||
1254 | void ServerDTP::gzipTarBlock() | 1286 | void ServerDTP::gzipTarBlock(OProcess *, char *buffer, int buflen) |
1255 | { | 1287 | { |
1256 | //qDebug("gzipTarBlock"); | 1288 | //qDebug("gzipTarBlock"); |
1257 | if ( !gzipProc->isRunning() ) { | 1289 | if ( !gzipProc->isRunning() ) { |
1258 | //qDebug("auto start gzip proc"); | 1290 | //qDebug("auto start gzip proc"); |
1259 | gzipProc->start(); | 1291 | gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout )); |
1260 | } | 1292 | } |
1261 | gzipProc->writeToStdin( createTargzProc->readStdout() ); | 1293 | gzipProc->writeStdin( buffer, buflen ); |
1262 | } | 1294 | } |
1263 | 1295 | ||
1264 | void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) | 1296 | void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) |
1265 | { | 1297 | { |
1266 | file.setName( fn ); | 1298 | file.setName( fn ); |
1267 | mode = SendFile; | 1299 | mode = SendFile; |
1268 | connectToHost( host.toString(), port ); | 1300 | connectToHost( host.toString(), port ); |
1269 | } | 1301 | } |
1270 | 1302 | ||
1271 | void ServerDTP::sendFile( const QString fn ) | 1303 | void ServerDTP::sendFile( const QString fn ) |
1272 | { | 1304 | { |
1273 | file.setName( fn ); | 1305 | file.setName( fn ); |
1274 | mode = SendFile; | 1306 | mode = SendFile; |
1275 | } | 1307 | } |
1276 | 1308 | ||
1277 | void ServerDTP::sendGzipFile( const QString &fn, | 1309 | void ServerDTP::sendGzipFile( const QString &fn, |
1278 | const QStringList &archiveTargets, | 1310 | const QStringList &archiveTargets, |
1279 | const QHostAddress& host, Q_UINT16 port ) | 1311 | const QHostAddress& host, Q_UINT16 port ) |
1280 | { | 1312 | { |
1281 | sendGzipFile( fn, archiveTargets ); | 1313 | sendGzipFile( fn, archiveTargets ); |
1282 | connectToHost( host.toString(), port ); | 1314 | connectToHost( host.toString(), port ); |
1283 | } | 1315 | } |
1284 | 1316 | ||
1285 | void ServerDTP::sendGzipFile( const QString &fn, | 1317 | void ServerDTP::sendGzipFile( const QString &fn, |
1286 | const QStringList &archiveTargets ) | 1318 | const QStringList &archiveTargets ) |
1287 | { | 1319 | { |
1288 | mode = SendGzipFile; | 1320 | mode = SendGzipFile; |
1289 | file.setName( fn ); | 1321 | file.setName( fn ); |
1290 | 1322 | ||
1291 | QStringList args = "tar"; | 1323 | QStringList args = "tar"; |
1292 | args += "-cv"; | 1324 | args += "-cv"; |
1293 | args += archiveTargets; | 1325 | args += archiveTargets; |
1294 | qDebug("sendGzipFile %s", args.join(" ").latin1() ); | 1326 | qDebug("sendGzipFile %s", args.join(" ").latin1() ); |
1295 | createTargzProc->setArguments( args ); | 1327 | createTargzProc->clearArguments( ); |
1296 | connect( createTargzProc, | 1328 | *createTargzProc << args; |
1297 | SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) ); | 1329 | connect( createTargzProc, |
1298 | 1330 | SIGNAL( receivedStdout(OProcess *, char *, int) ), SLOT( gzipTarBlock(OProcess *, char *, int) ) ); | |
1299 | gzipProc->setArguments( "gzip" ); | 1331 | |
1300 | connect( gzipProc, SIGNAL( readyReadStdout() ), | 1332 | gzipProc->clearArguments( ); |
1301 | SLOT( writeTargzBlock() ) ); | 1333 | *gzipProc << "gzip"; |
1334 | connect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), | ||
1335 | SLOT( writeTargzBlock(OProcess *, char *, int) ) ); | ||
1302 | } | 1336 | } |
1303 | 1337 | ||
1304 | void ServerDTP::gunzipDone() | 1338 | void ServerDTP::gunzipDone() |
1305 | { | 1339 | { |
1306 | qDebug("gunzipDone"); | 1340 | qDebug("gunzipDone"); |
1307 | disconnect( gzipProc, SIGNAL( processExited() ), | 1341 | disconnect( gzipProc, SIGNAL( processExited() ), |
1308 | this, SLOT( gunzipDone() ) ); | 1342 | this, SLOT( gunzipDone() ) ); |
1309 | retrieveTargzProc->closeStdin(); | 1343 | retrieveTargzProc->closeStdin(); |
1310 | disconnect( gzipProc, SIGNAL( readyReadStdout() ), | 1344 | disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), |
1311 | this, SLOT( tarExtractBlock() ) ); | 1345 | this, SLOT( tarExtractBlock(OProcess *, char *, int) ) ); |
1312 | } | 1346 | } |
1313 | 1347 | ||
1314 | void ServerDTP::tarExtractBlock() | 1348 | void ServerDTP::tarExtractBlock(OProcess *, char *buffer, int buflen) |
1315 | { | 1349 | { |
1316 | qDebug("ungzipTarBlock"); | 1350 | qDebug("tarExtractBlock"); |
1317 | if ( !retrieveTargzProc->isRunning() ) { | 1351 | if ( !retrieveTargzProc->isRunning() ) { |
1318 | qDebug("auto start ungzip proc"); | 1352 | qDebug("auto start ungzip proc"); |
1319 | if ( !retrieveTargzProc->start() ) | 1353 | if ( !retrieveTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdin) ) |
1320 | qWarning(" failed to start tar -x process"); | 1354 | qWarning(" failed to start tar -x process"); |
1321 | } | 1355 | } |
1322 | retrieveTargzProc->writeToStdin( gzipProc->readStdout() ); | 1356 | retrieveTargzProc->writeStdin( buffer, buflen ); |
1323 | } | 1357 | } |
1324 | 1358 | ||
1325 | 1359 | ||
1326 | void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) | 1360 | void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) |
1327 | { | 1361 | { |
1328 | file.setName( fn ); | 1362 | file.setName( fn ); |
1329 | mode = RetrieveFile; | 1363 | mode = RetrieveFile; |
1330 | connectToHost( host.toString(), port ); | 1364 | connectToHost( host.toString(), port ); |
1331 | } | 1365 | } |
1332 | 1366 | ||
1333 | void ServerDTP::retrieveFile( const QString fn ) | 1367 | void ServerDTP::retrieveFile( const QString fn ) |
1334 | { | 1368 | { |
1335 | file.setName( fn ); | 1369 | file.setName( fn ); |
1336 | mode = RetrieveFile; | 1370 | mode = RetrieveFile; |
1337 | } | 1371 | } |
1338 | 1372 | ||
1339 | void ServerDTP::retrieveGzipFile( const QString &fn ) | 1373 | void ServerDTP::retrieveGzipFile( const QString &fn ) |
1340 | { | 1374 | { |
1341 | qDebug("retrieveGzipFile %s", fn.latin1()); | 1375 | qDebug("retrieveGzipFile %s", fn.latin1()); |
1342 | file.setName( fn ); | 1376 | file.setName( fn ); |
1343 | mode = RetrieveGzipFile; | 1377 | mode = RetrieveGzipFile; |
1344 | 1378 | ||
1345 | gzipProc->setArguments( "gunzip" ); | 1379 | gzipProc->clearArguments(); |
1346 | connect( gzipProc, SIGNAL( readyReadStdout() ), | 1380 | *gzipProc << "gunzip"; |
1347 | SLOT( tarExtractBlock() ) ); | 1381 | connect( gzipProc, SIGNAL( readyReadStdout() ), |
1348 | connect( gzipProc, SIGNAL( processExited() ), | 1382 | SLOT( tarExtractBlock() ) ); |
1349 | SLOT( gunzipDone() ) ); | 1383 | connect( gzipProc, SIGNAL( processExited() ), |
1384 | SLOT( gunzipDone() ) ); | ||
1350 | } | 1385 | } |
1351 | 1386 | ||
1352 | void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) | 1387 | void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) |
1353 | { | 1388 | { |
1354 | retrieveGzipFile( fn ); | 1389 | retrieveGzipFile( fn ); |
1355 | connectToHost( host.toString(), port ); | 1390 | connectToHost( host.toString(), port ); |
1356 | } | 1391 | } |
1357 | 1392 | ||
1358 | void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ) | 1393 | void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ) |
1359 | { | 1394 | { |
1360 | buf.setBuffer( array ); | 1395 | buf.setBuffer( array ); |
1361 | mode = SendBuffer; | 1396 | mode = SendBuffer; |
1362 | connectToHost( host.toString(), port ); | 1397 | connectToHost( host.toString(), port ); |
1363 | } | 1398 | } |
1364 | 1399 | ||
1365 | void ServerDTP::sendByteArray( const QByteArray& array ) | 1400 | void ServerDTP::sendByteArray( const QByteArray& array ) |
1366 | { | 1401 | { |
1367 | buf.setBuffer( array ); | 1402 | buf.setBuffer( array ); |
1368 | mode = SendBuffer; | 1403 | mode = SendBuffer; |
1369 | } | 1404 | } |
1370 | 1405 | ||
1371 | void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port ) | 1406 | void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port ) |
1372 | { | 1407 | { |
1373 | buf.setBuffer( QByteArray() ); | 1408 | buf.setBuffer( QByteArray() ); |
1374 | mode = RetrieveBuffer; | 1409 | mode = RetrieveBuffer; |
1375 | connectToHost( host.toString(), port ); | 1410 | connectToHost( host.toString(), port ); |
1376 | } | 1411 | } |
1377 | 1412 | ||
1378 | void ServerDTP::retrieveByteArray() | 1413 | void ServerDTP::retrieveByteArray() |
1379 | { | 1414 | { |
1380 | buf.setBuffer( QByteArray() ); | 1415 | buf.setBuffer( QByteArray() ); |
1381 | mode = RetrieveBuffer; | 1416 | mode = RetrieveBuffer; |
1382 | } | 1417 | } |
1383 | 1418 | ||
1384 | void ServerDTP::setSocket( int socket ) | 1419 | void ServerDTP::setSocket( int socket ) |
1385 | { | 1420 | { |
1386 | QSocket::setSocket( socket ); | 1421 | QSocket::setSocket( socket ); |
1387 | connected(); | 1422 | connected(); |
1388 | } | 1423 | } |
1389 | 1424 | ||