-rw-r--r-- | core/launcher/transferserver.cpp | 803 |
1 files changed, 402 insertions, 401 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp index a6dab07..ed3e2c6 100644 --- a/core/launcher/transferserver.cpp +++ b/core/launcher/transferserver.cpp | |||
@@ -63,7 +63,7 @@ TransferServer::TransferServer( Q_UINT16 port, QObject *parent , | |||
63 | : QServerSocket( port, 1, parent, name ) | 63 | : QServerSocket( port, 1, parent, name ) |
64 | { | 64 | { |
65 | if ( !ok() ) | 65 | if ( !ok() ) |
66 | qWarning( "Failed to bind to port %d", port ); | 66 | qWarning( "Failed to bind to port %d", port ); |
67 | } | 67 | } |
68 | 68 | ||
69 | TransferServer::~TransferServer() | 69 | TransferServer::~TransferServer() |
@@ -82,9 +82,9 @@ QString SyncAuthentication::serverId() | |||
82 | cfg.setGroup("Sync"); | 82 | cfg.setGroup("Sync"); |
83 | QString r=cfg.readEntry("serverid"); | 83 | QString r=cfg.readEntry("serverid"); |
84 | if ( r.isEmpty() ) { | 84 | if ( r.isEmpty() ) { |
85 | uuid_t uuid; | 85 | uuid_t uuid; |
86 | uuid_generate( uuid ); | 86 | uuid_generate( uuid ); |
87 | cfg.writeEntry("serverid",(r = QUuid( uuid ).toString())); | 87 | cfg.writeEntry("serverid",(r = QUuid( uuid ).toString())); |
88 | } | 88 | } |
89 | return r; | 89 | return r; |
90 | } | 90 | } |
@@ -94,9 +94,9 @@ QString SyncAuthentication::ownerName() | |||
94 | QString vfilename = Global::applicationFileName("addressbook", | 94 | QString vfilename = Global::applicationFileName("addressbook", |
95 | "businesscard.vcf"); | 95 | "businesscard.vcf"); |
96 | if (QFile::exists(vfilename)) { | 96 | if (QFile::exists(vfilename)) { |
97 | Contact c; | 97 | Contact c; |
98 | c = Contact::readVCard( vfilename )[0]; | 98 | c = Contact::readVCard( vfilename )[0]; |
99 | return c.fullName(); | 99 | return c.fullName(); |
100 | } | 100 | } |
101 | 101 | ||
102 | return ""; | 102 | return ""; |
@@ -113,13 +113,15 @@ int SyncAuthentication::isAuthorized(QHostAddress peeraddress) | |||
113 | { | 113 | { |
114 | Config cfg("Security"); | 114 | Config cfg("Security"); |
115 | cfg.setGroup("Sync"); | 115 | cfg.setGroup("Sync"); |
116 | QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); | 116 | // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); |
117 | QHostAddress allowed; | 117 | uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100); |
118 | allowed.setAddress(allowedstr); | 118 | |
119 | uint auth_peer = allowed.ip4Addr(); | 119 | // QHostAddress allowed; |
120 | // allowed.setAddress(allowedstr); | ||
121 | // uint auth_peer = allowed.ip4Addr(); | ||
120 | uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); | 122 | uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); |
121 | uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined | 123 | uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined |
122 | ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits)); | 124 | ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits)); |
123 | return (peeraddress.ip4Addr() & mask) == auth_peer; | 125 | return (peeraddress.ip4Addr() & mask) == auth_peer; |
124 | } | 126 | } |
125 | 127 | ||
@@ -143,12 +145,12 @@ bool SyncAuthentication::checkPassword( const QString& password ) | |||
143 | 145 | ||
144 | QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); | 146 | QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); |
145 | if ( cpwd == "x" && spw ) | 147 | if ( cpwd == "x" && spw ) |
146 | cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); | 148 | cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); |
147 | 149 | ||
148 | // Note: some systems use more than crypt for passwords. | 150 | // Note: some systems use more than crypt for passwords. |
149 | QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); | 151 | QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); |
150 | if ( cpwd == cpassword ) | 152 | if ( cpwd == cpassword ) |
151 | return TRUE; | 153 | return TRUE; |
152 | #endif | 154 | #endif |
153 | 155 | ||
154 | static int lastdenial=0; | 156 | static int lastdenial=0; |
@@ -157,49 +159,48 @@ bool SyncAuthentication::checkPassword( const QString& password ) | |||
157 | 159 | ||
158 | // Detect old Qtopia Desktop (no password) | 160 | // Detect old Qtopia Desktop (no password) |
159 | if ( password.isEmpty() ) { | 161 | if ( password.isEmpty() ) { |
160 | if ( denials < 1 || now > lastdenial+600 ) { | 162 | if ( denials < 1 || now > lastdenial+600 ) { |
161 | QMessageBox::warning( 0,tr("Sync Connection"), | 163 | QMessageBox::warning( 0,tr("Sync Connection"), |
162 | tr("<p>An unauthorized system is requesting access to this device." | 164 | tr("<p>An unauthorized system is requesting access to this device." |
163 | "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " | 165 | "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " |
164 | "please upgrade."), | 166 | "please upgrade."), |
165 | tr("Deny") ); | 167 | tr("Deny") ); |
166 | denials++; | 168 | denials++; |
167 | lastdenial=now; | 169 | lastdenial=now; |
168 | } | 170 | } |
169 | return FALSE; | 171 | return FALSE; |
170 | } | 172 | } |
171 | 173 | ||
172 | // Second, check sync password... | 174 | // Second, check sync password... |
173 | if ( password.left(6) == "Qtopia" ) { | 175 | if ( password.left(6) == "Qtopia" ) { |
174 | QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); | 176 | QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); |
175 | Config cfg("Security"); | 177 | Config cfg("Security"); |
176 | cfg.setGroup("Sync"); | 178 | cfg.setGroup("Sync"); |
177 | QString pwds = cfg.readEntry("Passwords"); | 179 | QString pwds = cfg.readEntry("Passwords"); |
178 | if ( QStringList::split(QChar(' '),pwds).contains(cpassword) ) | 180 | if ( QStringList::split(QChar(' '),pwds).contains(cpassword) ) |
179 | return TRUE; | 181 | return TRUE; |
180 | 182 | ||
181 | // Unrecognized system. Be careful... | 183 | // Unrecognized system. Be careful... |
182 | 184 | ||
183 | if ( (denials > 2 && now < lastdenial+600) | 185 | if ( (denials > 2 && now < lastdenial+600) |
184 | || QMessageBox::warning(0,tr("Sync Connection"), | 186 | || QMessageBox::warning(0,tr("Sync Connection"), |
185 | tr("<p>An unrecognized system is requesting access to this device." | 187 | tr("<p>An unrecognized system is requesting access to this device." |
186 | "<p>If you have just initiated a Sync for the first time, this is normal."), | 188 | "<p>If you have just initiated a Sync for the first time, this is normal."), |
187 | tr("Allow"),tr("Deny"))==1 ) | 189 | tr("Allow"),tr("Deny"))==1 ) |
188 | { | 190 | { |
189 | denials++; | 191 | denials++; |
190 | lastdenial=now; | 192 | lastdenial=now; |
191 | return FALSE; | 193 | return FALSE; |
192 | } else { | 194 | } else { |
193 | denials=0; | 195 | denials=0; |
194 | cfg.writeEntry("Passwords",pwds+" "+cpassword); | 196 | cfg.writeEntry("Passwords",pwds+" "+cpassword); |
195 | return TRUE; | 197 | return TRUE; |
196 | } | 198 | } |
197 | } | 199 | } |
198 | 200 | ||
199 | return FALSE; | 201 | return FALSE; |
200 | } | 202 | } |
201 | 203 | ||
202 | |||
203 | ServerPI::ServerPI( int socket, QObject *parent , const char* name ) | 204 | ServerPI::ServerPI( int socket, QObject *parent , const char* name ) |
204 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) | 205 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) |
205 | { | 206 | { |
@@ -212,37 +213,37 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name ) | |||
212 | 213 | ||
213 | #ifndef INSECURE | 214 | #ifndef INSECURE |
214 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { | 215 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { |
215 | state = Forbidden; | 216 | state = Forbidden; |
216 | startTimer( 0 ); | 217 | startTimer( 0 ); |
217 | } else | 218 | } else |
218 | #endif | 219 | #endif |
219 | { | 220 | { |
220 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); | 221 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); |
221 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 222 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
222 | 223 | ||
223 | passiv = FALSE; | 224 | passiv = FALSE; |
224 | for( int i = 0; i < 4; i++ ) | 225 | for( int i = 0; i < 4; i++ ) |
225 | wait[i] = FALSE; | 226 | wait[i] = FALSE; |
226 | 227 | ||
227 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); | 228 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); |
228 | state = Wait_USER; | 229 | state = Wait_USER; |
229 | 230 | ||
230 | dtp = new ServerDTP( this ); | 231 | dtp = new ServerDTP( this ); |
231 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); | 232 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); |
232 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); | 233 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); |
233 | connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); | 234 | connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); |
234 | 235 | ||
235 | 236 | ||
236 | directory = QDir::currentDirPath(); | 237 | directory = QDir::currentDirPath(); |
237 | 238 | ||
238 | static int p = 1024; | 239 | static int p = 1024; |
239 | 240 | ||
240 | while ( !serversocket || !serversocket->ok() ) { | 241 | while ( !serversocket || !serversocket->ok() ) { |
241 | delete serversocket; | 242 | delete serversocket; |
242 | serversocket = new ServerSocket( ++p, this ); | 243 | serversocket = new ServerSocket( ++p, this ); |
243 | } | 244 | } |
244 | connect( serversocket, SIGNAL( newIncomming( int ) ), | 245 | connect( serversocket, SIGNAL( newIncomming( int ) ), |
245 | SLOT( newConnection( int ) ) ); | 246 | SLOT( newConnection( int ) ) ); |
246 | } | 247 | } |
247 | } | 248 | } |
248 | 249 | ||
@@ -267,7 +268,7 @@ void ServerPI::send( const QString& msg ) | |||
267 | void ServerPI::read() | 268 | void ServerPI::read() |
268 | { | 269 | { |
269 | while ( canReadLine() ) | 270 | while ( canReadLine() ) |
270 | process( readLine().stripWhiteSpace() ); | 271 | process( readLine().stripWhiteSpace() ); |
271 | } | 272 | } |
272 | 273 | ||
273 | bool ServerPI::checkReadFile( const QString& file ) | 274 | bool ServerPI::checkReadFile( const QString& file ) |
@@ -275,9 +276,9 @@ bool ServerPI::checkReadFile( const QString& file ) | |||
275 | QString filename; | 276 | QString filename; |
276 | 277 | ||
277 | if ( file[0] != "/" ) | 278 | if ( file[0] != "/" ) |
278 | filename = directory.path() + "/" + file; | 279 | filename = directory.path() + "/" + file; |
279 | else | 280 | else |
280 | filename = file; | 281 | filename = file; |
281 | 282 | ||
282 | QFileInfo fi( filename ); | 283 | QFileInfo fi( filename ); |
283 | return ( fi.exists() && fi.isReadable() ); | 284 | return ( fi.exists() && fi.isReadable() ); |
@@ -288,15 +289,15 @@ bool ServerPI::checkWriteFile( const QString& file ) | |||
288 | QString filename; | 289 | QString filename; |
289 | 290 | ||
290 | if ( file[0] != "/" ) | 291 | if ( file[0] != "/" ) |
291 | filename = directory.path() + "/" + file; | 292 | filename = directory.path() + "/" + file; |
292 | else | 293 | else |
293 | filename = file; | 294 | filename = file; |
294 | 295 | ||
295 | QFileInfo fi( filename ); | 296 | QFileInfo fi( filename ); |
296 | 297 | ||
297 | if ( fi.exists() ) | 298 | if ( fi.exists() ) |
298 | if ( !QFile( filename ).remove() ) | 299 | if ( !QFile( filename ).remove() ) |
299 | return FALSE; | 300 | return FALSE; |
300 | return TRUE; | 301 | return TRUE; |
301 | } | 302 | } |
302 | 303 | ||
@@ -314,7 +315,7 @@ void ServerPI::process( const QString& message ) | |||
314 | // argument token | 315 | // argument token |
315 | QString arg; | 316 | QString arg; |
316 | if ( msg.count() >= 2 ) | 317 | if ( msg.count() >= 2 ) |
317 | arg = msg[1]; | 318 | arg = msg[1]; |
318 | 319 | ||
319 | // full argument string | 320 | // full argument string |
320 | QString args; | 321 | QString args; |
@@ -330,37 +331,37 @@ void ServerPI::process( const QString& message ) | |||
330 | 331 | ||
331 | // we always respond to QUIT, regardless of state | 332 | // we always respond to QUIT, regardless of state |
332 | if ( cmd == "QUIT" ) { | 333 | if ( cmd == "QUIT" ) { |
333 | send( "211 Good bye!" ); | 334 | send( "211 Good bye!" ); |
334 | delete this; | 335 | delete this; |
335 | return; | 336 | return; |
336 | } | 337 | } |
337 | 338 | ||
338 | // connected to client | 339 | // connected to client |
339 | if ( Connected == state ) | 340 | if ( Connected == state ) |
340 | return; | 341 | return; |
341 | 342 | ||
342 | // waiting for user name | 343 | // waiting for user name |
343 | if ( Wait_USER == state ) { | 344 | if ( Wait_USER == state ) { |
344 | 345 | ||
345 | if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { | 346 | if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { |
346 | send( "530 Please login with USER and PASS" ); | 347 | send( "530 Please login with USER and PASS" ); |
347 | return; | 348 | return; |
348 | } | 349 | } |
349 | send( "331 User name ok, need password" ); | 350 | send( "331 User name ok, need password" ); |
350 | state = Wait_PASS; | 351 | state = Wait_PASS; |
351 | return; | 352 | return; |
352 | } | 353 | } |
353 | 354 | ||
354 | // waiting for password | 355 | // waiting for password |
355 | if ( Wait_PASS == state ) { | 356 | if ( Wait_PASS == state ) { |
356 | 357 | ||
357 | if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { | 358 | if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { |
358 | send( "530 Please login with USER and PASS" ); | 359 | send( "530 Please login with USER and PASS" ); |
359 | return; | 360 | return; |
360 | } | 361 | } |
361 | send( "230 User logged in, proceed" ); | 362 | send( "230 User logged in, proceed" ); |
362 | state = Ready; | 363 | state = Ready; |
363 | return; | 364 | return; |
364 | } | 365 | } |
365 | 366 | ||
366 | // ACCESS CONTROL COMMANDS | 367 | // ACCESS CONTROL COMMANDS |
@@ -368,41 +369,41 @@ void ServerPI::process( const QString& message ) | |||
368 | 369 | ||
369 | // account (ACCT) | 370 | // account (ACCT) |
370 | if ( cmd == "ACCT" ) { | 371 | if ( cmd == "ACCT" ) { |
371 | // even wu-ftp does not support it | 372 | // even wu-ftp does not support it |
372 | send( "502 Command not implemented" ); | 373 | send( "502 Command not implemented" ); |
373 | } | 374 | } |
374 | 375 | ||
375 | // change working directory (CWD) | 376 | // change working directory (CWD) |
376 | else if ( cmd == "CWD" ) { | 377 | else if ( cmd == "CWD" ) { |
377 | 378 | ||
378 | if ( !args.isEmpty() ) { | 379 | if ( !args.isEmpty() ) { |
379 | if ( directory.cd( args, TRUE ) ) | 380 | if ( directory.cd( args, TRUE ) ) |
380 | send( "250 Requested file action okay, completed" ); | 381 | send( "250 Requested file action okay, completed" ); |
381 | else | 382 | else |
382 | send( "550 Requested action not taken" ); | 383 | send( "550 Requested action not taken" ); |
383 | } | 384 | } |
384 | else | 385 | else |
385 | send( "500 Syntax error, command unrecognized" ); | 386 | send( "500 Syntax error, command unrecognized" ); |
386 | } | 387 | } |
387 | 388 | ||
388 | // change to parent directory (CDUP) | 389 | // change to parent directory (CDUP) |
389 | else if ( cmd == "CDUP" ) { | 390 | else if ( cmd == "CDUP" ) { |
390 | if ( directory.cdUp() ) | 391 | if ( directory.cdUp() ) |
391 | send( "250 Requested file action okay, completed" ); | 392 | send( "250 Requested file action okay, completed" ); |
392 | else | 393 | else |
393 | send( "550 Requested action not taken" ); | 394 | send( "550 Requested action not taken" ); |
394 | } | 395 | } |
395 | 396 | ||
396 | // structure mount (SMNT) | 397 | // structure mount (SMNT) |
397 | else if ( cmd == "SMNT" ) { | 398 | else if ( cmd == "SMNT" ) { |
398 | // even wu-ftp does not support it | 399 | // even wu-ftp does not support it |
399 | send( "502 Command not implemented" ); | 400 | send( "502 Command not implemented" ); |
400 | } | 401 | } |
401 | 402 | ||
402 | // reinitialize (REIN) | 403 | // reinitialize (REIN) |
403 | else if ( cmd == "REIN" ) { | 404 | else if ( cmd == "REIN" ) { |
404 | // even wu-ftp does not support it | 405 | // even wu-ftp does not support it |
405 | send( "502 Command not implemented" ); | 406 | send( "502 Command not implemented" ); |
406 | } | 407 | } |
407 | 408 | ||
408 | 409 | ||
@@ -411,43 +412,43 @@ void ServerPI::process( const QString& message ) | |||
411 | 412 | ||
412 | // data port (PORT) | 413 | // data port (PORT) |
413 | else if ( cmd == "PORT" ) { | 414 | else if ( cmd == "PORT" ) { |
414 | if ( parsePort( arg ) ) | 415 | if ( parsePort( arg ) ) |
415 | send( "200 Command okay" ); | 416 | send( "200 Command okay" ); |
416 | else | 417 | else |
417 | send( "500 Syntax error, command unrecognized" ); | 418 | send( "500 Syntax error, command unrecognized" ); |
418 | } | 419 | } |
419 | 420 | ||
420 | // passive (PASV) | 421 | // passive (PASV) |
421 | else if ( cmd == "PASV" ) { | 422 | else if ( cmd == "PASV" ) { |
422 | passiv = TRUE; | 423 | passiv = TRUE; |
423 | send( "227 Entering Passive Mode (" | 424 | send( "227 Entering Passive Mode (" |
424 | + address().toString().replace( QRegExp( "\\." ), "," ) + "," | 425 | + address().toString().replace( QRegExp( "\\." ), "," ) + "," |
425 | + QString::number( ( serversocket->port() ) >> 8 ) + "," | 426 | + QString::number( ( serversocket->port() ) >> 8 ) + "," |
426 | + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); | 427 | + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); |
427 | } | 428 | } |
428 | 429 | ||
429 | // representation type (TYPE) | 430 | // representation type (TYPE) |
430 | else if ( cmd == "TYPE" ) { | 431 | else if ( cmd == "TYPE" ) { |
431 | if ( arg.upper() == "A" || arg.upper() == "I" ) | 432 | if ( arg.upper() == "A" || arg.upper() == "I" ) |
432 | send( "200 Command okay" ); | 433 | send( "200 Command okay" ); |
433 | else | 434 | else |
434 | send( "504 Command not implemented for that parameter" ); | 435 | send( "504 Command not implemented for that parameter" ); |
435 | } | 436 | } |
436 | 437 | ||
437 | // file structure (STRU) | 438 | // file structure (STRU) |
438 | else if ( cmd == "STRU" ) { | 439 | else if ( cmd == "STRU" ) { |
439 | if ( arg.upper() == "F" ) | 440 | if ( arg.upper() == "F" ) |
440 | send( "200 Command okay" ); | 441 | send( "200 Command okay" ); |
441 | else | 442 | else |
442 | send( "504 Command not implemented for that parameter" ); | 443 | send( "504 Command not implemented for that parameter" ); |
443 | } | 444 | } |
444 | 445 | ||
445 | // transfer mode (MODE) | 446 | // transfer mode (MODE) |
446 | else if ( cmd == "MODE" ) { | 447 | else if ( cmd == "MODE" ) { |
447 | if ( arg.upper() == "S" ) | 448 | if ( arg.upper() == "S" ) |
448 | send( "200 Command okay" ); | 449 | send( "200 Command okay" ); |
449 | else | 450 | else |
450 | send( "504 Command not implemented for that parameter" ); | 451 | send( "504 Command not implemented for that parameter" ); |
451 | } | 452 | } |
452 | 453 | ||
453 | 454 | ||
@@ -456,204 +457,204 @@ void ServerPI::process( const QString& message ) | |||
456 | 457 | ||
457 | // retrieve (RETR) | 458 | // retrieve (RETR) |
458 | else if ( cmd == "RETR" ) | 459 | else if ( cmd == "RETR" ) |
459 | if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) | 460 | if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) |
460 | || backupRestoreGzip( absFilePath( args ) ) ) { | 461 | || backupRestoreGzip( absFilePath( args ) ) ) { |
461 | send( "150 File status okay" ); | 462 | send( "150 File status okay" ); |
462 | sendFile( absFilePath( args ) ); | 463 | sendFile( absFilePath( args ) ); |
463 | } | 464 | } |
464 | else { | 465 | else { |
465 | qDebug("550 Requested action not taken"); | 466 | qDebug("550 Requested action not taken"); |
466 | send( "550 Requested action not taken" ); | 467 | send( "550 Requested action not taken" ); |
467 | } | 468 | } |
468 | 469 | ||
469 | // store (STOR) | 470 | // store (STOR) |
470 | else if ( cmd == "STOR" ) | 471 | else if ( cmd == "STOR" ) |
471 | if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { | 472 | if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { |
472 | send( "150 File status okay" ); | 473 | send( "150 File status okay" ); |
473 | retrieveFile( absFilePath( args ) ); | 474 | retrieveFile( absFilePath( args ) ); |
474 | } | 475 | } |
475 | else | 476 | else |
476 | send( "550 Requested action not taken" ); | 477 | send( "550 Requested action not taken" ); |
477 | 478 | ||
478 | // store unique (STOU) | 479 | // store unique (STOU) |
479 | else if ( cmd == "STOU" ) { | 480 | else if ( cmd == "STOU" ) { |
480 | send( "502 Command not implemented" ); | 481 | send( "502 Command not implemented" ); |
481 | } | 482 | } |
482 | 483 | ||
483 | // append (APPE) | 484 | // append (APPE) |
484 | else if ( cmd == "APPE" ) { | 485 | else if ( cmd == "APPE" ) { |
485 | send( "502 Command not implemented" ); | 486 | send( "502 Command not implemented" ); |
486 | } | 487 | } |
487 | 488 | ||
488 | // allocate (ALLO) | 489 | // allocate (ALLO) |
489 | else if ( cmd == "ALLO" ) { | 490 | else if ( cmd == "ALLO" ) { |
490 | send( "200 Command okay" ); | 491 | send( "200 Command okay" ); |
491 | } | 492 | } |
492 | 493 | ||
493 | // restart (REST) | 494 | // restart (REST) |
494 | else if ( cmd == "REST" ) { | 495 | else if ( cmd == "REST" ) { |
495 | send( "502 Command not implemented" ); | 496 | send( "502 Command not implemented" ); |
496 | } | 497 | } |
497 | 498 | ||
498 | // rename from (RNFR) | 499 | // rename from (RNFR) |
499 | else if ( cmd == "RNFR" ) { | 500 | else if ( cmd == "RNFR" ) { |
500 | renameFrom = QString::null; | 501 | renameFrom = QString::null; |
501 | if ( args.isEmpty() ) | 502 | if ( args.isEmpty() ) |
502 | send( "500 Syntax error, command unrecognized" ); | 503 | send( "500 Syntax error, command unrecognized" ); |
503 | else { | 504 | else { |
504 | QFile file( absFilePath( args ) ); | 505 | QFile file( absFilePath( args ) ); |
505 | if ( file.exists() ) { | 506 | if ( file.exists() ) { |
506 | send( "350 File exists, ready for destination name" ); | 507 | send( "350 File exists, ready for destination name" ); |
507 | renameFrom = absFilePath( args ); | 508 | renameFrom = absFilePath( args ); |
508 | } | 509 | } |
509 | else | 510 | else |
510 | send( "550 Requested action not taken" ); | 511 | send( "550 Requested action not taken" ); |
511 | } | 512 | } |
512 | } | 513 | } |
513 | 514 | ||
514 | // rename to (RNTO) | 515 | // rename to (RNTO) |
515 | else if ( cmd == "RNTO" ) { | 516 | else if ( cmd == "RNTO" ) { |
516 | if ( lastCommand != "RNFR" ) | 517 | if ( lastCommand != "RNFR" ) |
517 | send( "503 Bad sequence of commands" ); | 518 | send( "503 Bad sequence of commands" ); |
518 | else if ( args.isEmpty() ) | 519 | else if ( args.isEmpty() ) |
519 | send( "500 Syntax error, command unrecognized" ); | 520 | send( "500 Syntax error, command unrecognized" ); |
520 | else { | 521 | else { |
521 | QDir dir( absFilePath( args ) ); | 522 | QDir dir( absFilePath( args ) ); |
522 | if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) | 523 | if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) |
523 | send( "250 Requested file action okay, completed." ); | 524 | send( "250 Requested file action okay, completed." ); |
524 | else | 525 | else |
525 | send( "550 Requested action not taken" ); | 526 | send( "550 Requested action not taken" ); |
526 | } | 527 | } |
527 | } | 528 | } |
528 | 529 | ||
529 | // abort (ABOR) | 530 | // abort (ABOR) |
530 | else if ( cmd.contains( "ABOR" ) ) { | 531 | else if ( cmd.contains( "ABOR" ) ) { |
531 | dtp->close(); | 532 | dtp->close(); |
532 | if ( dtp->dtpMode() != ServerDTP::Idle ) | 533 | if ( dtp->dtpMode() != ServerDTP::Idle ) |
533 | send( "426 Connection closed; transfer aborted" ); | 534 | send( "426 Connection closed; transfer aborted" ); |
534 | else | 535 | else |
535 | send( "226 Closing data connection" ); | 536 | send( "226 Closing data connection" ); |
536 | } | 537 | } |
537 | 538 | ||
538 | // delete (DELE) | 539 | // delete (DELE) |
539 | else if ( cmd == "DELE" ) { | 540 | else if ( cmd == "DELE" ) { |
540 | if ( args.isEmpty() ) | 541 | if ( args.isEmpty() ) |
541 | send( "500 Syntax error, command unrecognized" ); | 542 | send( "500 Syntax error, command unrecognized" ); |
542 | else { | 543 | else { |
543 | QFile file( absFilePath( args ) ) ; | 544 | QFile file( absFilePath( args ) ) ; |
544 | if ( file.remove() ) { | 545 | if ( file.remove() ) { |
545 | send( "250 Requested file action okay, completed" ); | 546 | send( "250 Requested file action okay, completed" ); |
546 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); | 547 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); |
547 | e << file.name(); | 548 | e << file.name(); |
548 | } else { | 549 | } else { |
549 | send( "550 Requested action not taken" ); | 550 | send( "550 Requested action not taken" ); |
550 | } | 551 | } |
551 | } | 552 | } |
552 | } | 553 | } |
553 | 554 | ||
554 | // remove directory (RMD) | 555 | // remove directory (RMD) |
555 | else if ( cmd == "RMD" ) { | 556 | else if ( cmd == "RMD" ) { |
556 | if ( args.isEmpty() ) | 557 | if ( args.isEmpty() ) |
557 | send( "500 Syntax error, command unrecognized" ); | 558 | send( "500 Syntax error, command unrecognized" ); |
558 | else { | 559 | else { |
559 | QDir dir; | 560 | QDir dir; |
560 | if ( dir.rmdir( absFilePath( args ), TRUE ) ) | 561 | if ( dir.rmdir( absFilePath( args ), TRUE ) ) |
561 | send( "250 Requested file action okay, completed" ); | 562 | send( "250 Requested file action okay, completed" ); |
562 | else | 563 | else |
563 | send( "550 Requested action not taken" ); | 564 | send( "550 Requested action not taken" ); |
564 | } | 565 | } |
565 | } | 566 | } |
566 | 567 | ||
567 | // make directory (MKD) | 568 | // make directory (MKD) |
568 | else if ( cmd == "MKD" ) { | 569 | else if ( cmd == "MKD" ) { |
569 | if ( args.isEmpty() ) { | 570 | if ( args.isEmpty() ) { |
570 | qDebug(" Error: no arg"); | 571 | qDebug(" Error: no arg"); |
571 | send( "500 Syntax error, command unrecognized" ); | 572 | send( "500 Syntax error, command unrecognized" ); |
572 | } | 573 | } |
573 | else { | 574 | else { |
574 | QDir dir; | 575 | QDir dir; |
575 | if ( dir.mkdir( absFilePath( args ), TRUE ) ) | 576 | if ( dir.mkdir( absFilePath( args ), TRUE ) ) |
576 | send( "250 Requested file action okay, completed." ); | 577 | send( "250 Requested file action okay, completed." ); |
577 | else | 578 | else |
578 | send( "550 Requested action not taken" ); | 579 | send( "550 Requested action not taken" ); |
579 | } | 580 | } |
580 | } | 581 | } |
581 | 582 | ||
582 | // print working directory (PWD) | 583 | // print working directory (PWD) |
583 | else if ( cmd == "PWD" ) { | 584 | else if ( cmd == "PWD" ) { |
584 | send( "257 \"" + directory.path() +"\"" ); | 585 | send( "257 \"" + directory.path() +"\"" ); |
585 | } | 586 | } |
586 | 587 | ||
587 | // list (LIST) | 588 | // list (LIST) |
588 | else if ( cmd == "LIST" ) { | 589 | else if ( cmd == "LIST" ) { |
589 | if ( sendList( absFilePath( args ) ) ) | 590 | if ( sendList( absFilePath( args ) ) ) |
590 | send( "150 File status okay" ); | 591 | send( "150 File status okay" ); |
591 | else | 592 | else |
592 | send( "500 Syntax error, command unrecognized" ); | 593 | send( "500 Syntax error, command unrecognized" ); |
593 | } | 594 | } |
594 | 595 | ||
595 | // size (SIZE) | 596 | // size (SIZE) |
596 | else if ( cmd == "SIZE" ) { | 597 | else if ( cmd == "SIZE" ) { |
597 | QString filePath = absFilePath( args ); | 598 | QString filePath = absFilePath( args ); |
598 | QFileInfo fi( filePath ); | 599 | QFileInfo fi( filePath ); |
599 | bool gzipfile = backupRestoreGzip( filePath ); | 600 | bool gzipfile = backupRestoreGzip( filePath ); |
600 | if ( !fi.exists() && !gzipfile ) | 601 | if ( !fi.exists() && !gzipfile ) |
601 | send( "500 Syntax error, command unrecognized" ); | 602 | send( "500 Syntax error, command unrecognized" ); |
602 | else { | 603 | else { |
603 | if ( !gzipfile ) | 604 | if ( !gzipfile ) |
604 | send( "213 " + QString::number( fi.size() ) ); | 605 | send( "213 " + QString::number( fi.size() ) ); |
605 | else { | 606 | else { |
606 | Process duproc( QString("du") ); | 607 | Process duproc( QString("du") ); |
607 | duproc.addArgument("-s"); | 608 | duproc.addArgument("-s"); |
608 | QString in, out; | 609 | QString in, out; |
609 | if ( !duproc.exec(in, out) ) { | 610 | if ( !duproc.exec(in, out) ) { |
610 | qDebug("du process failed; just sending back 1K"); | 611 | qDebug("du process failed; just sending back 1K"); |
611 | send( "213 1024"); | 612 | send( "213 1024"); |
612 | } | 613 | } |
613 | else { | 614 | else { |
614 | QString size = out.left( out.find("\t") ); | 615 | QString size = out.left( out.find("\t") ); |
615 | int guess = size.toInt()/5; | 616 | int guess = size.toInt()/5; |
616 | if ( filePath.contains("doc") ) | 617 | if ( filePath.contains("doc") ) |
617 | guess *= 1000; | 618 | guess *= 1000; |
618 | qDebug("sending back gzip guess of %d", guess); | 619 | qDebug("sending back gzip guess of %d", guess); |
619 | send( "213 " + QString::number(guess) ); | 620 | send( "213 " + QString::number(guess) ); |
620 | } | 621 | } |
621 | } | 622 | } |
622 | } | 623 | } |
623 | } | 624 | } |
624 | // name list (NLST) | 625 | // name list (NLST) |
625 | else if ( cmd == "NLST" ) { | 626 | else if ( cmd == "NLST" ) { |
626 | send( "502 Command not implemented" ); | 627 | send( "502 Command not implemented" ); |
627 | } | 628 | } |
628 | 629 | ||
629 | // site parameters (SITE) | 630 | // site parameters (SITE) |
630 | else if ( cmd == "SITE" ) { | 631 | else if ( cmd == "SITE" ) { |
631 | send( "502 Command not implemented" ); | 632 | send( "502 Command not implemented" ); |
632 | } | 633 | } |
633 | 634 | ||
634 | // system (SYST) | 635 | // system (SYST) |
635 | else if ( cmd == "SYST" ) { | 636 | else if ( cmd == "SYST" ) { |
636 | send( "215 UNIX Type: L8" ); | 637 | send( "215 UNIX Type: L8" ); |
637 | } | 638 | } |
638 | 639 | ||
639 | // status (STAT) | 640 | // status (STAT) |
640 | else if ( cmd == "STAT" ) { | 641 | else if ( cmd == "STAT" ) { |
641 | send( "502 Command not implemented" ); | 642 | send( "502 Command not implemented" ); |
642 | } | 643 | } |
643 | 644 | ||
644 | // help (HELP ) | 645 | // help (HELP ) |
645 | else if ( cmd == "HELP" ) { | 646 | else if ( cmd == "HELP" ) { |
646 | send( "502 Command not implemented" ); | 647 | send( "502 Command not implemented" ); |
647 | } | 648 | } |
648 | 649 | ||
649 | // noop (NOOP) | 650 | // noop (NOOP) |
650 | else if ( cmd == "NOOP" ) { | 651 | else if ( cmd == "NOOP" ) { |
651 | send( "200 Command okay" ); | 652 | send( "200 Command okay" ); |
652 | } | 653 | } |
653 | 654 | ||
654 | // not implemented | 655 | // not implemented |
655 | else | 656 | else |
656 | send( "502 Command not implemented" ); | 657 | send( "502 Command not implemented" ); |
657 | 658 | ||
658 | lastCommand = cmd; | 659 | lastCommand = cmd; |
659 | } | 660 | } |
@@ -661,7 +662,7 @@ void ServerPI::process( const QString& message ) | |||
661 | bool ServerPI::backupRestoreGzip( const QString &file ) | 662 | bool ServerPI::backupRestoreGzip( const QString &file ) |
662 | { | 663 | { |
663 | return (file.find( "backup" ) != -1 && | 664 | return (file.find( "backup" ) != -1 && |
664 | file.findRev( ".tgz" ) == (int)file.length()-4 ); | 665 | file.findRev( ".tgz" ) == (int)file.length()-4 ); |
665 | } | 666 | } |
666 | 667 | ||
667 | bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) | 668 | bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) |
@@ -671,7 +672,7 @@ bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) | |||
671 | QFileInfo info( file ); | 672 | QFileInfo info( file ); |
672 | targets = info.dirPath( TRUE ); | 673 | targets = info.dirPath( TRUE ); |
673 | qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), | 674 | qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), |
674 | targets.join(" ").latin1() ); | 675 | targets.join(" ").latin1() ); |
675 | return true; | 676 | return true; |
676 | } | 677 | } |
677 | return false; | 678 | return false; |
@@ -680,15 +681,15 @@ bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) | |||
680 | void ServerPI::sendFile( const QString& file ) | 681 | void ServerPI::sendFile( const QString& file ) |
681 | { | 682 | { |
682 | if ( passiv ) { | 683 | if ( passiv ) { |
683 | wait[SendFile] = TRUE; | 684 | wait[SendFile] = TRUE; |
684 | waitfile = file; | 685 | waitfile = file; |
685 | if ( waitsocket ) | 686 | if ( waitsocket ) |
686 | newConnection( waitsocket ); | 687 | newConnection( waitsocket ); |
687 | } | 688 | } |
688 | else { | 689 | else { |
689 | QStringList targets; | 690 | QStringList targets; |
690 | if ( backupRestoreGzip( file, targets ) ) | 691 | if ( backupRestoreGzip( file, targets ) ) |
691 | dtp->sendGzipFile( file, targets, peeraddress, peerport ); | 692 | dtp->sendGzipFile( file, targets, peeraddress, peerport ); |
692 | else dtp->sendFile( file, peeraddress, peerport ); | 693 | else dtp->sendFile( file, peeraddress, peerport ); |
693 | } | 694 | } |
694 | } | 695 | } |
@@ -696,17 +697,17 @@ void ServerPI::sendFile( const QString& file ) | |||
696 | void ServerPI::retrieveFile( const QString& file ) | 697 | void ServerPI::retrieveFile( const QString& file ) |
697 | { | 698 | { |
698 | if ( passiv ) { | 699 | if ( passiv ) { |
699 | wait[RetrieveFile] = TRUE; | 700 | wait[RetrieveFile] = TRUE; |
700 | waitfile = file; | 701 | waitfile = file; |
701 | if ( waitsocket ) | 702 | if ( waitsocket ) |
702 | newConnection( waitsocket ); | 703 | newConnection( waitsocket ); |
703 | } | 704 | } |
704 | else { | 705 | else { |
705 | QStringList targets; | 706 | QStringList targets; |
706 | if ( backupRestoreGzip( file, targets ) ) | 707 | if ( backupRestoreGzip( file, targets ) ) |
707 | dtp->retrieveGzipFile( file, peeraddress, peerport ); | 708 | dtp->retrieveGzipFile( file, peeraddress, peerport ); |
708 | else | 709 | else |
709 | dtp->retrieveFile( file, peeraddress, peerport ); | 710 | dtp->retrieveFile( file, peeraddress, peerport ); |
710 | } | 711 | } |
711 | } | 712 | } |
712 | 713 | ||
@@ -717,7 +718,7 @@ bool ServerPI::parsePort( const QString& pp ) | |||
717 | 718 | ||
718 | // h1,h2,h3,h4,p1,p2 | 719 | // h1,h2,h3,h4,p1,p2 |
719 | peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + | 720 | peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + |
720 | ( p[2].toInt() << 8 ) + p[3].toInt() ); | 721 | ( p[2].toInt() << 8 ) + p[3].toInt() ); |
721 | peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); | 722 | peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); |
722 | return TRUE; | 723 | return TRUE; |
723 | } | 724 | } |
@@ -726,11 +727,11 @@ void ServerPI::dtpCompleted() | |||
726 | { | 727 | { |
727 | send( "226 Closing data connection, file transfer successful" ); | 728 | send( "226 Closing data connection, file transfer successful" ); |
728 | if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { | 729 | if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { |
729 | QString fn = dtp->fileName(); | 730 | QString fn = dtp->fileName(); |
730 | if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) { | 731 | if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) { |
731 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); | 732 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); |
732 | e << fn; | 733 | e << fn; |
733 | } | 734 | } |
734 | } | 735 | } |
735 | waitsocket = 0; | 736 | waitsocket = 0; |
736 | dtp->close(); | 737 | dtp->close(); |
@@ -756,58 +757,58 @@ bool ServerPI::sendList( const QString& arg ) | |||
756 | QBuffer buffer( listing ); | 757 | QBuffer buffer( listing ); |
757 | 758 | ||
758 | if ( !buffer.open( IO_WriteOnly ) ) | 759 | if ( !buffer.open( IO_WriteOnly ) ) |
759 | return FALSE; | 760 | return FALSE; |
760 | 761 | ||
761 | QTextStream ts( &buffer ); | 762 | QTextStream ts( &buffer ); |
762 | QString fn = arg; | 763 | QString fn = arg; |
763 | 764 | ||
764 | if ( fn.isEmpty() ) | 765 | if ( fn.isEmpty() ) |
765 | fn = directory.path(); | 766 | fn = directory.path(); |
766 | 767 | ||
767 | QFileInfo fi( fn ); | 768 | QFileInfo fi( fn ); |
768 | if ( !fi.exists() ) return FALSE; | 769 | if ( !fi.exists() ) return FALSE; |
769 | 770 | ||
770 | // return file listing | 771 | // return file listing |
771 | if ( fi.isFile() ) { | 772 | if ( fi.isFile() ) { |
772 | ts << fileListing( &fi ) << endl; | 773 | ts << fileListing( &fi ) << endl; |
773 | } | 774 | } |
774 | 775 | ||
775 | // return directory listing | 776 | // return directory listing |
776 | else if ( fi.isDir() ) { | 777 | else if ( fi.isDir() ) { |
777 | QDir dir( fn ); | 778 | QDir dir( fn ); |
778 | const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); | 779 | const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); |
779 | 780 | ||
780 | QFileInfoListIterator it( *list ); | 781 | QFileInfoListIterator it( *list ); |
781 | QFileInfo *info; | 782 | QFileInfo *info; |
782 | 783 | ||
783 | unsigned long total = 0; | 784 | unsigned long total = 0; |
784 | while ( ( info = it.current() ) ) { | 785 | while ( ( info = it.current() ) ) { |
785 | if ( info->fileName() != "." && info->fileName() != ".." ) | 786 | if ( info->fileName() != "." && info->fileName() != ".." ) |
786 | total += info->size(); | 787 | total += info->size(); |
787 | ++it; | 788 | ++it; |
788 | } | 789 | } |
789 | 790 | ||
790 | ts << "total " << QString::number( total / 1024 ) << endl; | 791 | ts << "total " << QString::number( total / 1024 ) << endl; |
791 | 792 | ||
792 | it.toFirst(); | 793 | it.toFirst(); |
793 | while ( ( info = it.current() ) ) { | 794 | while ( ( info = it.current() ) ) { |
794 | if ( info->fileName() == "." || info->fileName() == ".." ) { | 795 | if ( info->fileName() == "." || info->fileName() == ".." ) { |
795 | ++it; | 796 | ++it; |
796 | continue; | 797 | continue; |
797 | } | 798 | } |
798 | ts << fileListing( info ) << endl; | 799 | ts << fileListing( info ) << endl; |
799 | ++it; | 800 | ++it; |
800 | } | 801 | } |
801 | } | 802 | } |
802 | 803 | ||
803 | if ( passiv ) { | 804 | if ( passiv ) { |
804 | waitarray = buffer.buffer(); | 805 | waitarray = buffer.buffer(); |
805 | wait[SendByteArray] = TRUE; | 806 | wait[SendByteArray] = TRUE; |
806 | if ( waitsocket ) | 807 | if ( waitsocket ) |
807 | newConnection( waitsocket ); | 808 | newConnection( waitsocket ); |
808 | } | 809 | } |
809 | else | 810 | else |
810 | dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); | 811 | dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); |
811 | return TRUE; | 812 | return TRUE; |
812 | } | 813 | } |
813 | 814 | ||
@@ -818,11 +819,11 @@ QString ServerPI::fileListing( QFileInfo *info ) | |||
818 | 819 | ||
819 | // type char | 820 | // type char |
820 | if ( info->isDir() ) | 821 | if ( info->isDir() ) |
821 | s += "d"; | 822 | s += "d"; |
822 | else if ( info->isSymLink() ) | 823 | else if ( info->isSymLink() ) |
823 | s += "l"; | 824 | s += "l"; |
824 | else | 825 | else |
825 | s += "-"; | 826 | s += "-"; |
826 | 827 | ||
827 | // permisson string | 828 | // permisson string |
828 | s += permissionString( info ) + " "; | 829 | s += permissionString( info ) + " "; |
@@ -831,7 +832,7 @@ QString ServerPI::fileListing( QFileInfo *info ) | |||
831 | int subdirs = 1; | 832 | int subdirs = 1; |
832 | 833 | ||
833 | if ( info->isDir() ) | 834 | if ( info->isDir() ) |
834 | subdirs = 2; | 835 | subdirs = 2; |
835 | // FIXME : this is to slow | 836 | // FIXME : this is to slow |
836 | //if ( info->isDir() ) | 837 | //if ( info->isDir() ) |
837 | //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); | 838 | //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); |
@@ -851,9 +852,9 @@ QString ServerPI::fileListing( QFileInfo *info ) | |||
851 | QDate date = info->lastModified().date(); | 852 | QDate date = info->lastModified().date(); |
852 | QTime time = info->lastModified().time(); | 853 | QTime time = info->lastModified().time(); |
853 | s += date.monthName( date.month() ) + " " | 854 | s += date.monthName( date.month() ) + " " |
854 | + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " | 855 | + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " |
855 | + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" | 856 | + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" |
856 | + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; | 857 | + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; |
857 | 858 | ||
858 | // file name | 859 | // file name |
859 | s += info->fileName(); | 860 | s += info->fileName(); |
@@ -900,35 +901,35 @@ void ServerPI::newConnection( int socket ) | |||
900 | if ( !passiv ) return; | 901 | if ( !passiv ) return; |
901 | 902 | ||
902 | if ( wait[SendFile] ) { | 903 | if ( wait[SendFile] ) { |
903 | QStringList targets; | 904 | QStringList targets; |
904 | if ( backupRestoreGzip( waitfile, targets ) ) | 905 | if ( backupRestoreGzip( waitfile, targets ) ) |
905 | dtp->sendGzipFile( waitfile, targets ); | 906 | dtp->sendGzipFile( waitfile, targets ); |
906 | else | 907 | else |
907 | dtp->sendFile( waitfile ); | 908 | dtp->sendFile( waitfile ); |
908 | dtp->setSocket( socket ); | 909 | dtp->setSocket( socket ); |
909 | } | 910 | } |
910 | else if ( wait[RetrieveFile] ) { | 911 | else if ( wait[RetrieveFile] ) { |
911 | qDebug("check retrieve file"); | 912 | qDebug("check retrieve file"); |
912 | if ( backupRestoreGzip( waitfile ) ) | 913 | if ( backupRestoreGzip( waitfile ) ) |
913 | dtp->retrieveGzipFile( waitfile ); | 914 | dtp->retrieveGzipFile( waitfile ); |
914 | else | 915 | else |
915 | dtp->retrieveFile( waitfile ); | 916 | dtp->retrieveFile( waitfile ); |
916 | dtp->setSocket( socket ); | 917 | dtp->setSocket( socket ); |
917 | } | 918 | } |
918 | else if ( wait[SendByteArray] ) { | 919 | else if ( wait[SendByteArray] ) { |
919 | dtp->sendByteArray( waitarray ); | 920 | dtp->sendByteArray( waitarray ); |
920 | dtp->setSocket( socket ); | 921 | dtp->setSocket( socket ); |
921 | } | 922 | } |
922 | else if ( wait[RetrieveByteArray] ) { | 923 | else if ( wait[RetrieveByteArray] ) { |
923 | qDebug("retrieve byte array"); | 924 | qDebug("retrieve byte array"); |
924 | dtp->retrieveByteArray(); | 925 | dtp->retrieveByteArray(); |
925 | dtp->setSocket( socket ); | 926 | dtp->setSocket( socket ); |
926 | } | 927 | } |
927 | else | 928 | else |
928 | waitsocket = socket; | 929 | waitsocket = socket; |
929 | 930 | ||
930 | for( int i = 0; i < 4; i++ ) | 931 | for( int i = 0; i < 4; i++ ) |
931 | wait[i] = FALSE; | 932 | wait[i] = FALSE; |
932 | } | 933 | } |
933 | 934 | ||
934 | QString ServerPI::absFilePath( const QString& file ) | 935 | QString ServerPI::absFilePath( const QString& file ) |
@@ -937,7 +938,7 @@ QString ServerPI::absFilePath( const QString& file ) | |||
937 | 938 | ||
938 | QString filepath( file ); | 939 | QString filepath( file ); |
939 | if ( file[0] != "/" ) | 940 | if ( file[0] != "/" ) |
940 | filepath = directory.path() + "/" + file; | 941 | filepath = directory.path() + "/" + file; |
941 | 942 | ||
942 | return filepath; | 943 | return filepath; |
943 | } | 944 | } |
@@ -973,9 +974,9 @@ retrieveTargzProc( 0 ), gzipProc( 0 ) | |||
973 | retrieveTargzProc->setCommunication( QProcess::Stdin ); | 974 | retrieveTargzProc->setCommunication( QProcess::Stdin ); |
974 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); | 975 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); |
975 | connect( retrieveTargzProc, SIGNAL( processExited() ), | 976 | connect( retrieveTargzProc, SIGNAL( processExited() ), |
976 | SIGNAL( completed() ) ); | 977 | SIGNAL( completed() ) ); |
977 | connect( retrieveTargzProc, SIGNAL( processExited() ), | 978 | connect( retrieveTargzProc, SIGNAL( processExited() ), |
978 | SLOT( extractTarDone() ) ); | 979 | SLOT( extractTarDone() ) ); |
979 | } | 980 | } |
980 | 981 | ||
981 | ServerDTP::~ServerDTP() | 982 | ServerDTP::~ServerDTP() |
@@ -1016,10 +1017,10 @@ void ServerDTP::connected() | |||
1016 | } else { | 1017 | } else { |
1017 | 1018 | ||
1018 | if( !file.atEnd() ) { | 1019 | if( !file.atEnd() ) { |
1019 | QCString s; | 1020 | QCString s; |
1020 | s.resize( block_size ); | 1021 | s.resize( block_size ); |
1021 | int bytes = file.readBlock( s.data(), block_size ); | 1022 | int bytes = file.readBlock( s.data(), block_size ); |
1022 | writeBlock( s.data(), bytes ); | 1023 | writeBlock( s.data(), bytes ); |
1023 | } | 1024 | } |
1024 | } | 1025 | } |
1025 | break; | 1026 | break; |
@@ -1034,8 +1035,8 @@ void ServerDTP::connected() | |||
1034 | qDebug("==>start send tar process"); | 1035 | qDebug("==>start send tar process"); |
1035 | if ( !createTargzProc->start() ) | 1036 | if ( !createTargzProc->start() ) |
1036 | qWarning("Error starting %s or %s", | 1037 | qWarning("Error starting %s or %s", |
1037 | createTargzProc->arguments().join(" ").latin1(), | 1038 | createTargzProc->arguments().join(" ").latin1(), |
1038 | gzipProc->arguments().join(" ").latin1() ); | 1039 | gzipProc->arguments().join(" ").latin1() ); |
1039 | break; | 1040 | break; |
1040 | case SendBuffer: | 1041 | case SendBuffer: |
1041 | if ( !buf.open( IO_ReadOnly) ) { | 1042 | if ( !buf.open( IO_ReadOnly) ) { |
@@ -1089,36 +1090,36 @@ void ServerDTP::connectionClosed() | |||
1089 | 1090 | ||
1090 | // send file mode | 1091 | // send file mode |
1091 | if ( SendFile == mode ) { | 1092 | if ( SendFile == mode ) { |
1092 | if ( bytes_written == file.size() ) | 1093 | if ( bytes_written == file.size() ) |
1093 | emit completed(); | 1094 | emit completed(); |
1094 | else | 1095 | else |
1095 | emit failed(); | 1096 | emit failed(); |
1096 | } | 1097 | } |
1097 | 1098 | ||
1098 | // send buffer mode | 1099 | // send buffer mode |
1099 | else if ( SendBuffer == mode ) { | 1100 | else if ( SendBuffer == mode ) { |
1100 | if ( bytes_written == buf.size() ) | 1101 | if ( bytes_written == buf.size() ) |
1101 | emit completed(); | 1102 | emit completed(); |
1102 | else | 1103 | else |
1103 | emit failed(); | 1104 | emit failed(); |
1104 | } | 1105 | } |
1105 | 1106 | ||
1106 | // retrieve file mode | 1107 | // retrieve file mode |
1107 | else if ( RetrieveFile == mode ) { | 1108 | else if ( RetrieveFile == mode ) { |
1108 | file.close(); | 1109 | file.close(); |
1109 | emit completed(); | 1110 | emit completed(); |
1110 | } | 1111 | } |
1111 | 1112 | ||
1112 | else if ( RetrieveGzipFile == mode ) { | 1113 | else if ( RetrieveGzipFile == mode ) { |
1113 | qDebug("Done writing ungzip file; closing input"); | 1114 | qDebug("Done writing ungzip file; closing input"); |
1114 | gzipProc->flushStdin(); | 1115 | gzipProc->flushStdin(); |
1115 | gzipProc->closeStdin(); | 1116 | gzipProc->closeStdin(); |
1116 | } | 1117 | } |
1117 | 1118 | ||
1118 | // retrieve buffer mode | 1119 | // retrieve buffer mode |
1119 | else if ( RetrieveBuffer == mode ) { | 1120 | else if ( RetrieveBuffer == mode ) { |
1120 | buf.close(); | 1121 | buf.close(); |
1121 | emit completed(); | 1122 | emit completed(); |
1122 | } | 1123 | } |
1123 | 1124 | ||
1124 | mode = Idle; | 1125 | mode = Idle; |
@@ -1131,28 +1132,28 @@ void ServerDTP::bytesWritten( int bytes ) | |||
1131 | // send file mode | 1132 | // send file mode |
1132 | if ( SendFile == mode ) { | 1133 | if ( SendFile == mode ) { |
1133 | 1134 | ||
1134 | if ( bytes_written == file.size() ) { | 1135 | if ( bytes_written == file.size() ) { |
1135 | // qDebug( "Debug: Sending complete: %d bytes", file.size() ); | 1136 | // qDebug( "Debug: Sending complete: %d bytes", file.size() ); |
1136 | file.close(); | 1137 | file.close(); |
1137 | emit completed(); | 1138 | emit completed(); |
1138 | mode = Idle; | 1139 | mode = Idle; |
1139 | } | 1140 | } |
1140 | else if( !file.atEnd() ) { | 1141 | else if( !file.atEnd() ) { |
1141 | QCString s; | 1142 | QCString s; |
1142 | s.resize( block_size ); | 1143 | s.resize( block_size ); |
1143 | int bytes = file.readBlock( s.data(), block_size ); | 1144 | int bytes = file.readBlock( s.data(), block_size ); |
1144 | writeBlock( s.data(), bytes ); | 1145 | writeBlock( s.data(), bytes ); |
1145 | } | 1146 | } |
1146 | } | 1147 | } |
1147 | 1148 | ||
1148 | // send buffer mode | 1149 | // send buffer mode |
1149 | if ( SendBuffer == mode ) { | 1150 | if ( SendBuffer == mode ) { |
1150 | 1151 | ||
1151 | if ( bytes_written == buf.size() ) { | 1152 | if ( bytes_written == buf.size() ) { |
1152 | // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); | 1153 | // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); |
1153 | emit completed(); | 1154 | emit completed(); |
1154 | mode = Idle; | 1155 | mode = Idle; |
1155 | } | 1156 | } |
1156 | } | 1157 | } |
1157 | } | 1158 | } |
1158 | 1159 | ||
@@ -1160,27 +1161,27 @@ void ServerDTP::readyRead() | |||
1160 | { | 1161 | { |
1161 | // retrieve file mode | 1162 | // retrieve file mode |
1162 | if ( RetrieveFile == mode ) { | 1163 | if ( RetrieveFile == mode ) { |
1163 | QCString s; | 1164 | QCString s; |
1164 | s.resize( bytesAvailable() ); | 1165 | s.resize( bytesAvailable() ); |
1165 | readBlock( s.data(), bytesAvailable() ); | 1166 | readBlock( s.data(), bytesAvailable() ); |
1166 | file.writeBlock( s.data(), s.size() ); | 1167 | file.writeBlock( s.data(), s.size() ); |
1167 | } | 1168 | } |
1168 | else if ( RetrieveGzipFile == mode ) { | 1169 | else if ( RetrieveGzipFile == mode ) { |
1169 | if ( !gzipProc->isRunning() ) | 1170 | if ( !gzipProc->isRunning() ) |
1170 | gzipProc->start(); | 1171 | gzipProc->start(); |
1171 | 1172 | ||
1172 | QByteArray s; | 1173 | QByteArray s; |
1173 | s.resize( bytesAvailable() ); | 1174 | s.resize( bytesAvailable() ); |
1174 | readBlock( s.data(), bytesAvailable() ); | 1175 | readBlock( s.data(), bytesAvailable() ); |
1175 | gzipProc->writeToStdin( s ); | 1176 | gzipProc->writeToStdin( s ); |
1176 | qDebug("wrote %d bytes to ungzip ", s.size() ); | 1177 | qDebug("wrote %d bytes to ungzip ", s.size() ); |
1177 | } | 1178 | } |
1178 | // retrieve buffer mode | 1179 | // retrieve buffer mode |
1179 | else if ( RetrieveBuffer == mode ) { | 1180 | else if ( RetrieveBuffer == mode ) { |
1180 | QCString s; | 1181 | QCString s; |
1181 | s.resize( bytesAvailable() ); | 1182 | s.resize( bytesAvailable() ); |
1182 | readBlock( s.data(), bytesAvailable() ); | 1183 | readBlock( s.data(), bytesAvailable() ); |
1183 | buf.writeBlock( s.data(), s.size() ); | 1184 | buf.writeBlock( s.data(), s.size() ); |
1184 | } | 1185 | } |
1185 | } | 1186 | } |
1186 | 1187 | ||
@@ -1190,11 +1191,11 @@ void ServerDTP::writeTargzBlock() | |||
1190 | writeBlock( block.data(), block.size() ); | 1191 | writeBlock( block.data(), block.size() ); |
1191 | qDebug("writeTargzBlock %d", block.size()); | 1192 | qDebug("writeTargzBlock %d", block.size()); |
1192 | if ( !createTargzProc->isRunning() ) { | 1193 | if ( !createTargzProc->isRunning() ) { |
1193 | qDebug("tar and gzip done"); | 1194 | qDebug("tar and gzip done"); |
1194 | emit completed(); | 1195 | emit completed(); |
1195 | mode = Idle; | 1196 | mode = Idle; |
1196 | disconnect( gzipProc, SIGNAL( readyReadStdout() ), | 1197 | disconnect( gzipProc, SIGNAL( readyReadStdout() ), |
1197 | this, SLOT( writeTargzBlock() ) ); | 1198 | this, SLOT( writeTargzBlock() ) ); |
1198 | } | 1199 | } |
1199 | } | 1200 | } |
1200 | 1201 | ||
@@ -1202,7 +1203,7 @@ void ServerDTP::targzDone() | |||
1202 | { | 1203 | { |
1203 | //qDebug("targz done"); | 1204 | //qDebug("targz done"); |
1204 | disconnect( createTargzProc, SIGNAL( readyReadStdout() ), | 1205 | disconnect( createTargzProc, SIGNAL( readyReadStdout() ), |
1205 | this, SLOT( gzipTarBlock() ) ); | 1206 | this, SLOT( gzipTarBlock() ) ); |
1206 | gzipProc->closeStdin(); | 1207 | gzipProc->closeStdin(); |
1207 | } | 1208 | } |
1208 | 1209 | ||
@@ -1210,8 +1211,8 @@ void ServerDTP::gzipTarBlock() | |||
1210 | { | 1211 | { |
1211 | //qDebug("gzipTarBlock"); | 1212 | //qDebug("gzipTarBlock"); |
1212 | if ( !gzipProc->isRunning() ) { | 1213 | if ( !gzipProc->isRunning() ) { |
1213 | //qDebug("auto start gzip proc"); | 1214 | //qDebug("auto start gzip proc"); |
1214 | gzipProc->start(); | 1215 | gzipProc->start(); |
1215 | } | 1216 | } |
1216 | gzipProc->writeToStdin( createTargzProc->readStdout() ); | 1217 | gzipProc->writeToStdin( createTargzProc->readStdout() ); |
1217 | } | 1218 | } |
@@ -1230,15 +1231,15 @@ void ServerDTP::sendFile( const QString fn ) | |||
1230 | } | 1231 | } |
1231 | 1232 | ||
1232 | void ServerDTP::sendGzipFile( const QString &fn, | 1233 | void ServerDTP::sendGzipFile( const QString &fn, |
1233 | const QStringList &archiveTargets, | 1234 | const QStringList &archiveTargets, |
1234 | const QHostAddress& host, Q_UINT16 port ) | 1235 | const QHostAddress& host, Q_UINT16 port ) |
1235 | { | 1236 | { |
1236 | sendGzipFile( fn, archiveTargets ); | 1237 | sendGzipFile( fn, archiveTargets ); |
1237 | connectToHost( host.toString(), port ); | 1238 | connectToHost( host.toString(), port ); |
1238 | } | 1239 | } |
1239 | 1240 | ||
1240 | void ServerDTP::sendGzipFile( const QString &fn, | 1241 | void ServerDTP::sendGzipFile( const QString &fn, |
1241 | const QStringList &archiveTargets ) | 1242 | const QStringList &archiveTargets ) |
1242 | { | 1243 | { |
1243 | mode = SendGzipFile; | 1244 | mode = SendGzipFile; |
1244 | file.setName( fn ); | 1245 | file.setName( fn ); |
@@ -1249,30 +1250,30 @@ void ServerDTP::sendGzipFile( const QString &fn, | |||
1249 | qDebug("sendGzipFile %s", args.join(" ").latin1() ); | 1250 | qDebug("sendGzipFile %s", args.join(" ").latin1() ); |
1250 | createTargzProc->setArguments( args ); | 1251 | createTargzProc->setArguments( args ); |
1251 | connect( createTargzProc, | 1252 | connect( createTargzProc, |
1252 | SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) ); | 1253 | SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) ); |
1253 | 1254 | ||
1254 | gzipProc->setArguments( "gzip" ); | 1255 | gzipProc->setArguments( "gzip" ); |
1255 | connect( gzipProc, SIGNAL( readyReadStdout() ), | 1256 | connect( gzipProc, SIGNAL( readyReadStdout() ), |
1256 | SLOT( writeTargzBlock() ) ); | 1257 | SLOT( writeTargzBlock() ) ); |
1257 | } | 1258 | } |
1258 | 1259 | ||
1259 | void ServerDTP::gunzipDone() | 1260 | void ServerDTP::gunzipDone() |
1260 | { | 1261 | { |
1261 | qDebug("gunzipDone"); | 1262 | qDebug("gunzipDone"); |
1262 | disconnect( gzipProc, SIGNAL( processExited() ), | 1263 | disconnect( gzipProc, SIGNAL( processExited() ), |
1263 | this, SLOT( gunzipDone() ) ); | 1264 | this, SLOT( gunzipDone() ) ); |
1264 | retrieveTargzProc->closeStdin(); | 1265 | retrieveTargzProc->closeStdin(); |
1265 | disconnect( gzipProc, SIGNAL( readyReadStdout() ), | 1266 | disconnect( gzipProc, SIGNAL( readyReadStdout() ), |
1266 | this, SLOT( tarExtractBlock() ) ); | 1267 | this, SLOT( tarExtractBlock() ) ); |
1267 | } | 1268 | } |
1268 | 1269 | ||
1269 | void ServerDTP::tarExtractBlock() | 1270 | void ServerDTP::tarExtractBlock() |
1270 | { | 1271 | { |
1271 | qDebug("ungzipTarBlock"); | 1272 | qDebug("ungzipTarBlock"); |
1272 | if ( !retrieveTargzProc->isRunning() ) { | 1273 | if ( !retrieveTargzProc->isRunning() ) { |
1273 | qDebug("auto start ungzip proc"); | 1274 | qDebug("auto start ungzip proc"); |
1274 | if ( !retrieveTargzProc->start() ) | 1275 | if ( !retrieveTargzProc->start() ) |
1275 | qWarning(" failed to start tar -x process"); | 1276 | qWarning(" failed to start tar -x process"); |
1276 | } | 1277 | } |
1277 | retrieveTargzProc->writeToStdin( gzipProc->readStdout() ); | 1278 | retrieveTargzProc->writeToStdin( gzipProc->readStdout() ); |
1278 | } | 1279 | } |
@@ -1297,11 +1298,11 @@ void ServerDTP::retrieveGzipFile( const QString &fn ) | |||
1297 | file.setName( fn ); | 1298 | file.setName( fn ); |
1298 | mode = RetrieveGzipFile; | 1299 | mode = RetrieveGzipFile; |
1299 | 1300 | ||
1300 | gzipProc->setArguments( "gunzip" ); | 1301 | gzipProc->setArguments( "gunzip" ); |
1301 | connect( gzipProc, SIGNAL( readyReadStdout() ), | 1302 | connect( gzipProc, SIGNAL( readyReadStdout() ), |
1302 | SLOT( tarExtractBlock() ) ); | 1303 | SLOT( tarExtractBlock() ) ); |
1303 | connect( gzipProc, SIGNAL( processExited() ), | 1304 | connect( gzipProc, SIGNAL( processExited() ), |
1304 | SLOT( gunzipDone() ) ); | 1305 | SLOT( gunzipDone() ) ); |
1305 | } | 1306 | } |
1306 | 1307 | ||
1307 | void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) | 1308 | void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) |