summaryrefslogtreecommitdiff
path: root/core/launcher/transferserver.cpp
Unidiff
Diffstat (limited to 'core/launcher/transferserver.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/transferserver.cpp851
1 files changed, 425 insertions, 426 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index 4b764e3..c3f936e 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -63,9 +63,9 @@ void TransferServer::authorizeConnections()
63 QListIterator<ServerPI> it(connections); 63 QListIterator<ServerPI> it(connections);
64 while ( it.current() ) { 64 while ( it.current() ) {
65 if ( !it.current()->verifyAuthorised() ) { 65 if ( !it.current()->verifyAuthorised() ) {
66 disconnect( it.current(), SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) ); 66 disconnect( it.current(), SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) );
67 connections.removeRef( it.current() ); 67 connections.removeRef( it.current() );
68 } else 68 } else
69 ++it; 69 ++it;
70 } 70 }
71} 71}
@@ -105,7 +105,7 @@ QString SyncAuthentication::ownerName()
105 "businesscard.vcf"); 105 "businesscard.vcf");
106 if (QFile::exists(vfilename)) { 106 if (QFile::exists(vfilename)) {
107 Contact c; 107 Contact c;
108 c = Contact::readVCard( vfilename )[0]; 108 c = Contact::readVCard( vfilename )[0];
109 return c.fullName(); 109 return c.fullName();
110 } 110 }
111 111
@@ -128,16 +128,16 @@ int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
128{ 128{
129 Config cfg("Security"); 129 Config cfg("Security");
130 cfg.setGroup("Sync"); 130 cfg.setGroup("Sync");
131 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); 131 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
132 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); 132 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100);
133 133
134 // QHostAddress allowed; 134 // QHostAddress allowed;
135 // allowed.setAddress(allowedstr); 135 // allowed.setAddress(allowedstr);
136 // uint auth_peer = allowed.ip4Addr(); 136 // uint auth_peer = allowed.ip4Addr();
137 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); 137 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24);
138 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined 138 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined
139 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); 139 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits));
140 140
141 return (peeraddress.ip4Addr() & mask) == auth_peer; 141 return (peeraddress.ip4Addr() & mask) == auth_peer;
142} 142}
143 143
@@ -162,10 +162,10 @@ bool SyncAuthentication::checkPassword( const QString& password )
162 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); 162 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
163 if ( cpwd == "x" && spw ) 163 if ( cpwd == "x" && spw )
164 cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); 164 cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
165 165
166 // Note: some systems use more than crypt for passwords. 166 // Note: some systems use more than crypt for passwords.
167 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); 167 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
168 if ( cpwd == cpassword ) 168 if ( cpwd == cpassword )
169 return TRUE; 169 return TRUE;
170#endif 170#endif
171 171
@@ -203,20 +203,20 @@ bool SyncAuthentication::checkPassword( const QString& password )
203 // Detect old Qtopia Desktop (no password) and fail 203 // Detect old Qtopia Desktop (no password) and fail
204 if ( password.isEmpty() ) { 204 if ( password.isEmpty() ) {
205 if ( denials < 3 || now > lastdenial+600 ) { 205 if ( denials < 3 || now > lastdenial+600 ) {
206 QMessageBox unauth( 206 QMessageBox unauth(
207 tr("Sync Connection"), 207 tr("Sync Connection"),
208 tr("<p>An unauthorized system is requesting access to this device." 208 tr("<p>An unauthorized system is requesting access to this device."
209 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " 209 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, "
210 "please upgrade or change the security setting to use IntelliSync." ), 210 "please upgrade or change the security setting to use IntelliSync." ),
211 QMessageBox::Warning, 211 QMessageBox::Warning,
212 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, 212 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton,
213 0, QString::null, TRUE, WStyle_StaysOnTop); 213 0, QString::null, TRUE, WStyle_StaysOnTop);
214 unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); 214 unauth.setButtonText(QMessageBox::Cancel, tr("Deny"));
215 unauth.exec(); 215 unauth.exec();
216 216
217 denials++; 217 denials++;
218 lastdenial=now; 218 lastdenial=now;
219 } 219 }
220 return FALSE; 220 return FALSE;
221 221
222 } 222 }
@@ -233,57 +233,57 @@ bool SyncAuthentication::checkPassword( const QString& password )
233 */ 233 */
234 if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) { 234 if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) {
235 Config cfg( "Security" ); 235 Config cfg( "Security" );
236 cfg.setGroup("Sync"); 236 cfg.setGroup("Sync");
237 QStringList pwds = cfg.readListEntry("Passwords",' '); 237 QStringList pwds = cfg.readListEntry("Passwords",' ');
238 for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) { 238 for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) {
239#ifndef Q_OS_WIN32 239#ifndef Q_OS_WIN32
240 QString cpassword = QString::fromLocal8Bit( 240 QString cpassword = QString::fromLocal8Bit(
241 crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) ); 241 crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) );
242#else 242#else
243 // ### revise 243 // ### revise
244 QString cpassword(""); 244 QString cpassword("");
245#endif 245#endif
246 if ( *it == cpassword ) { 246 if ( *it == cpassword ) {
247 lock--; 247 lock--;
248 return TRUE; 248 return TRUE;
249 } 249 }
250 } 250 }
251 251
252 // Unrecognized system. Be careful... 252 // Unrecognized system. Be careful...
253 QMessageBox unrecbox( 253 QMessageBox unrecbox(
254 tr("Sync Connection"), 254 tr("Sync Connection"),
255 tr("<p>An unrecognized system is requesting access to this device." 255 tr( "<p>An unrecognized system is requesting access to this device."
256 "<p>If you have just initiated a Sync for the first time, this is normal."), 256 "<p>If you have just initiated a Sync for the first time, this is normal."),
257 QMessageBox::Warning, 257 QMessageBox::Warning,
258 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, 258 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton,
259 0, QString::null, TRUE, WStyle_StaysOnTop); 259 0, QString::null, TRUE, WStyle_StaysOnTop);
260 unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny")); 260 unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny"));
261 unrecbox.setButtonText(QMessageBox::Yes, tr("Allow")); 261 unrecbox.setButtonText(QMessageBox::Yes, tr("Allow"));
262 262
263 if ( (denials > 2 && now < lastdenial+600) 263 if ( (denials > 2 && now < lastdenial+600)
264 || unrecbox.exec() != QMessageBox::Yes) 264 || unrecbox.exec() != QMessageBox::Yes)
265 { 265 {
266 denials++; 266 denials++;
267 lastdenial=now; 267 lastdenial=now;
268 lock--; 268 lock--;
269 return FALSE; 269 return FALSE;
270 } else { 270 } else {
271 const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."; 271 const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/.";
272 char salt[2]; 272 char salt[2];
273 salt[0]= salty[rand() % (sizeof(salty)-1)]; 273 salt[0]= salty[rand() % (sizeof(salty)-1)];
274 salt[1]= salty[rand() % (sizeof(salty)-1)]; 274 salt[1]= salty[rand() % (sizeof(salty)-1)];
275#ifndef Q_OS_WIN32 275#ifndef Q_OS_WIN32
276 QString cpassword = QString::fromLocal8Bit( 276 QString cpassword = QString::fromLocal8Bit(
277 crypt( password.mid(8).local8Bit(), salt ) ); 277 crypt( password.mid(8).local8Bit(), salt ) );
278#else 278#else
279 //### revise 279 //### revise
280 QString cpassword(""); 280 QString cpassword("");
281#endif 281#endif
282 denials=0; 282 denials=0;
283 pwds.prepend(cpassword); 283 pwds.prepend(cpassword);
284 cfg.writeEntry("Passwords",pwds,' '); 284 cfg.writeEntry("Passwords",pwds,' ');
285 lock--; 285 lock--;
286 return TRUE; 286 return TRUE;
287 } 287 }
288 } 288 }
289 lock--; 289 lock--;
@@ -306,35 +306,35 @@ ServerPI::ServerPI( int socket, QObject *parent, const char* name )
306#ifndef INSECURE 306#ifndef INSECURE
307 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 307 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
308 state = Forbidden; 308 state = Forbidden;
309 startTimer( 0 ); 309 startTimer( 0 );
310 } else 310 } else
311#endif 311#endif
312 { 312 {
313 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 313 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
314 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 314 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
315 315
316 passiv = FALSE; 316 passiv = FALSE;
317 for( int i = 0; i < 4; i++ ) 317 for( int i = 0; i < 4; i++ )
318 wait[i] = FALSE; 318 wait[i] = FALSE;
319 319
320 send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr 320 send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr
321 state = Wait_USER; 321 state = Wait_USER;
322 322
323 dtp = new ServerDTP( this ); 323 dtp = new ServerDTP( this );
324 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); 324 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) );
325 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); 325 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) );
326 connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) ); 326 connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) );
327 327
328 328
329 directory = QDir::currentDirPath(); 329 directory = QDir::currentDirPath();
330 330
331 static int p = 1024; 331 static int p = 1024;
332 332
333 while ( !serversocket || !serversocket->ok() ) { 333 while ( !serversocket || !serversocket->ok() ) {
334 delete serversocket; 334 delete serversocket;
335 serversocket = new ServerSocket( ++p, this ); 335 serversocket = new ServerSocket( ++p, this );
336 } 336 }
337 connect( serversocket, SIGNAL( newIncomming(int) ), 337 connect( serversocket, SIGNAL( newIncomming(int) ),
338 SLOT( newConnection(int) ) ); 338 SLOT( newConnection(int) ) );
339 } 339 }
340} 340}
@@ -353,6 +353,6 @@ bool ServerPI::verifyAuthorised()
353{ 353{
354 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { 354 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) {
355 state = Forbidden; 355 state = Forbidden;
356 return FALSE; 356 return FALSE;
357 } 357 }
358 return TRUE; 358 return TRUE;
@@ -375,5 +375,5 @@ void ServerPI::read()
375{ 375{
376 while ( canReadLine() ) 376 while ( canReadLine() )
377 process( readLine().stripWhiteSpace() ); 377 process( readLine().stripWhiteSpace() );
378} 378}
379 379
@@ -383,7 +383,7 @@ bool ServerPI::checkReadFile( const QString& file )
383 383
384 if ( file[0] != "/" ) 384 if ( file[0] != "/" )
385 filename = directory.path() + "/" + file; 385 filename = directory.path() + "/" + file;
386 else 386 else
387 filename = file; 387 filename = file;
388 388
389 QFileInfo fi( filename ); 389 QFileInfo fi( filename );
@@ -396,13 +396,13 @@ bool ServerPI::checkWriteFile( const QString& file )
396 396
397 if ( file[0] != "/" ) 397 if ( file[0] != "/" )
398 filename = directory.path() + "/" + file; 398 filename = directory.path() + "/" + file;
399 else 399 else
400 filename = file; 400 filename = file;
401 401
402 QFileInfo fi( filename ); 402 QFileInfo fi( filename );
403 403
404 if ( fi.exists() ) 404 if ( fi.exists() )
405 if ( !QFile( filename ).remove() ) 405 if ( !QFile( filename ).remove() )
406 return FALSE; 406 return FALSE;
407 return TRUE; 407 return TRUE;
408} 408}
@@ -422,5 +422,5 @@ void ServerPI::process( const QString& message )
422 QString arg; 422 QString arg;
423 if ( msg.count() >= 2 ) 423 if ( msg.count() >= 2 )
424 arg = msg[1]; 424 arg = msg[1];
425 425
426 // full argument string 426 // full argument string
@@ -438,23 +438,23 @@ void ServerPI::process( const QString& message )
438 // we always respond to QUIT, regardless of state 438 // we always respond to QUIT, regardless of state
439 if ( cmd == "QUIT" ) { 439 if ( cmd == "QUIT" ) {
440 send( "211 Good bye!" ); // No tr 440 send( "211 Good bye!" ); // No tr
441 close(); 441 close();
442 return; 442 return;
443 } 443 }
444 444
445 // connected to client 445 // connected to client
446 if ( Connected == state ) 446 if ( Connected == state )
447 return; 447 return;
448 448
449 // waiting for user name 449 // waiting for user name
450 if ( Wait_USER == state ) { 450 if ( Wait_USER == state ) {
451 451
452 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { 452 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
453 send( "530 Please login with USER and PASS" ); // No tr 453 send( "530 Please login with USER and PASS" ); // No tr
454 return; 454 return;
455 } 455 }
456 send( "331 User name ok, need password" ); // No tr 456 send( "331 User name ok, need password" ); // No tr
457 state = Wait_PASS; 457 state = Wait_PASS;
458 return; 458 return;
459 } 459 }
460 460
@@ -462,11 +462,11 @@ void ServerPI::process( const QString& message )
462 if ( Wait_PASS == state ) { 462 if ( Wait_PASS == state ) {
463 463
464 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { 464 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
465 send( "530 Please login with USER and PASS" ); // No tr 465 send( "530 Please login with USER and PASS" ); // No tr
466 return; 466 return;
467 } 467 }
468 send( "230 User logged in, proceed" ); // No tr 468 send( "230 User logged in, proceed" ); // No tr
469 state = Ready; 469 state = Ready;
470 return; 470 return;
471 } 471 }
472 472
@@ -475,10 +475,10 @@ void ServerPI::process( const QString& message )
475 // Only an ALLO sent immediately before STOR is valid. 475 // Only an ALLO sent immediately before STOR is valid.
476 if ( cmd != "STOR" ) 476 if ( cmd != "STOR" )
477 storFileSize = -1; 477 storFileSize = -1;
478 478
479 // account (ACCT) 479 // account (ACCT)
480 if ( cmd == "ACCT" ) { 480 if ( cmd == "ACCT" ) {
481 // even wu-ftp does not support it 481 // even wu-ftp does not support it
482 send( "502 Command not implemented" ); // No tr 482 send( "502 Command not implemented" ); // No tr
483 } 483 }
484 484
@@ -486,32 +486,32 @@ void ServerPI::process( const QString& message )
486 else if ( cmd == "CWD" ) { 486 else if ( cmd == "CWD" ) {
487 487
488 if ( !args.isEmpty() ) { 488 if ( !args.isEmpty() ) {
489 if ( directory.cd( args, TRUE ) ) 489 if ( directory.cd( args, TRUE ) )
490 send( "250 Requested file action okay, completed" ); // No tr 490 send( "250 Requested file action okay, completed" ); // No tr
491 else 491 else
492 send( "550 Requested action not taken" ); // No tr 492 send( "550 Requested action not taken" ); // No tr
493 } 493 }
494 else 494 else
495 send( "500 Syntax error, command unrecognized" ); // No tr 495 send( "500 Syntax error, command unrecognized" ); // No tr
496 } 496 }
497 497
498 // change to parent directory (CDUP) 498 // change to parent directory (CDUP)
499 else if ( cmd == "CDUP" ) { 499 else if ( cmd == "CDUP" ) {
500 if ( directory.cdUp() ) 500 if ( directory.cdUp() )
501 send( "250 Requested file action okay, completed" ); // No tr 501 send( "250 Requested file action okay, completed" ); // No tr
502 else 502 else
503 send( "550 Requested action not taken" ); // No tr 503 send( "550 Requested action not taken" ); // No tr
504 } 504 }
505 505
506 // structure mount (SMNT) 506 // structure mount (SMNT)
507 else if ( cmd == "SMNT" ) { 507 else if ( cmd == "SMNT" ) {
508 // even wu-ftp does not support it 508 // even wu-ftp does not support it
509 send( "502 Command not implemented" ); // No tr 509 send( "502 Command not implemented" ); // No tr
510 } 510 }
511 511
512 // reinitialize (REIN) 512 // reinitialize (REIN)
513 else if ( cmd == "REIN" ) { 513 else if ( cmd == "REIN" ) {
514 // even wu-ftp does not support it 514 // even wu-ftp does not support it
515 send( "502 Command not implemented" ); // No tr 515 send( "502 Command not implemented" ); // No tr
516 } 516 }
517 517
@@ -522,41 +522,41 @@ void ServerPI::process( const QString& message )
522 // data port (PORT) 522 // data port (PORT)
523 else if ( cmd == "PORT" ) { 523 else if ( cmd == "PORT" ) {
524 if ( parsePort( arg ) ) 524 if ( parsePort( arg ) )
525 send( "200 Command okay" ); // No tr 525 send( "200 Command okay" ); // No tr
526 else 526 else
527 send( "500 Syntax error, command unrecognized" ); // No tr 527 send( "500 Syntax error, command unrecognized" ); // No tr
528 } 528 }
529 529
530 // passive (PASV) 530 // passive (PASV)
531 else if ( cmd == "PASV" ) { 531 else if ( cmd == "PASV" ) {
532 passiv = TRUE; 532 passiv = TRUE;
533 send( "227 Entering Passive Mode (" // No tr 533 send( "227 Entering Passive Mode (" // No tr
534 + address().toString().replace( QRegExp( "\\." ), "," ) + "," 534 + address().toString().replace( QRegExp( "\\." ), "," ) + ","
535 + QString::number( ( serversocket->port() ) >> 8 ) + "," 535 + QString::number( ( serversocket->port() ) >> 8 ) + ","
536 + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); 536 + QString::number( ( serversocket->port() ) & 0xFF ) +")" );
537 } 537 }
538 538
539 // representation type (TYPE) 539 // representation type (TYPE)
540 else if ( cmd == "TYPE" ) { 540 else if ( cmd == "TYPE" ) {
541 if ( arg.upper() == "A" || arg.upper() == "I" ) 541 if ( arg.upper() == "A" || arg.upper() == "I" )
542 send( "200 Command okay" ); // No tr 542 send( "200 Command okay" ); // No tr
543 else 543 else
544 send( "504 Command not implemented for that parameter" ); // No tr 544 send( "504 Command not implemented for that parameter" ); // No tr
545 } 545 }
546 546
547 // file structure (STRU) 547 // file structure (STRU)
548 else if ( cmd == "STRU" ) { 548 else if ( cmd == "STRU" ) {
549 if ( arg.upper() == "F" ) 549 if ( arg.upper() == "F" )
550 send( "200 Command okay" ); // No tr 550 send( "200 Command okay" ); // No tr
551 else 551 else
552 send( "504 Command not implemented for that parameter" ); // No tr 552 send( "504 Command not implemented for that parameter" ); // No tr
553 } 553 }
554 554
555 // transfer mode (MODE) 555 // transfer mode (MODE)
556 else if ( cmd == "MODE" ) { 556 else if ( cmd == "MODE" ) {
557 if ( arg.upper() == "S" ) 557 if ( arg.upper() == "S" )
558 send( "200 Command okay" ); // No tr 558 send( "200 Command okay" ); // No tr
559 else 559 else
560 send( "504 Command not implemented for that parameter" ); // No tr 560 send( "504 Command not implemented for that parameter" ); // No tr
561 } 561 }
562 562
@@ -567,203 +567,203 @@ void ServerPI::process( const QString& message )
567 // retrieve (RETR) 567 // retrieve (RETR)
568 else if ( cmd == "RETR" ) 568 else if ( cmd == "RETR" )
569 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) 569 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) )
570 || backupRestoreGzip( absFilePath( args ) ) ) { 570 || backupRestoreGzip( absFilePath( args ) ) ) {
571 send( "150 File status okay" ); // No tr 571 send( "150 File status okay" ); // No tr
572 sendFile( absFilePath( args ) ); 572 sendFile( absFilePath( args ) );
573 } 573 }
574 else { 574 else {
575 odebug << "550 Requested action not taken" << oendl; 575 odebug << "550 Requested action not taken" << oendl;
576 send( "550 Requested action not taken" ); // No tr 576 send( "550 Requested action not taken" ); // No tr
577 } 577 }
578 578
579 // store (STOR) 579 // store (STOR)
580 else if ( cmd == "STOR" ) 580 else if ( cmd == "STOR" )
581 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { 581 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) {
582 send( "150 File status okay" ); // No tr 582 send( "150 File status okay" ); // No tr
583 retrieveFile( absFilePath( args ) ); 583 retrieveFile( absFilePath( args ) );
584 } 584 }
585 else 585 else
586 send( "550 Requested action not taken" ); // No tr 586 send( "550 Requested action not taken" ); // No tr
587 587
588 // store unique (STOU) 588 // store unique (STOU)
589 else if ( cmd == "STOU" ) { 589 else if ( cmd == "STOU" ) {
590 send( "502 Command not implemented" ); // No tr 590 send( "502 Command not implemented" ); // No tr
591 } 591 }
592 592
593 // append (APPE) 593 // append (APPE)
594 else if ( cmd == "APPE" ) { 594 else if ( cmd == "APPE" ) {
595 send( "502 Command not implemented" ); // No tr 595 send( "502 Command not implemented" ); // No tr
596 } 596 }
597 597
598 // allocate (ALLO) 598 // allocate (ALLO)
599 else if ( cmd == "ALLO" ) { 599 else if ( cmd == "ALLO" ) {
600 storFileSize = args.toInt(); 600 storFileSize = args.toInt();
601 send( "200 Command okay" ); // No tr 601 send( "200 Command okay" ); // No tr
602 } 602 }
603 603
604 // restart (REST) 604 // restart (REST)
605 else if ( cmd == "REST" ) { 605 else if ( cmd == "REST" ) {
606 send( "502 Command not implemented" ); // No tr 606 send( "502 Command not implemented" ); // No tr
607 } 607 }
608 608
609 // rename from (RNFR) 609 // rename from (RNFR)
610 else if ( cmd == "RNFR" ) { 610 else if ( cmd == "RNFR" ) {
611 renameFrom = QString::null; 611 renameFrom = QString::null;
612 if ( args.isEmpty() ) 612 if ( args.isEmpty() )
613 send( "500 Syntax error, command unrecognized" ); // No tr 613 send( "500 Syntax error, command unrecognized" ); // No tr
614 else { 614 else {
615 QFile file( absFilePath( args ) ); 615 QFile file( absFilePath( args ) );
616 if ( file.exists() ) { 616 if ( file.exists() ) {
617 send( "350 File exists, ready for destination name" ); // No tr 617 send( "350 File exists, ready for destination name" ); // No tr
618 renameFrom = absFilePath( args ); 618 renameFrom = absFilePath( args );
619 } 619 }
620 else 620 else
621 send( "550 Requested action not taken" ); // No tr 621 send( "550 Requested action not taken" ); // No tr
622 } 622 }
623 } 623 }
624 624
625 // rename to (RNTO) 625 // rename to (RNTO)
626 else if ( cmd == "RNTO" ) { 626 else if ( cmd == "RNTO" ) {
627 if ( lastCommand != "RNFR" ) 627 if ( lastCommand != "RNFR" )
628 send( "503 Bad sequence of commands" ); // No tr 628 send( "503 Bad sequence of commands" ); // No tr
629 else if ( args.isEmpty() ) 629 else if ( args.isEmpty() )
630 send( "500 Syntax error, command unrecognized" ); // No tr 630 send( "500 Syntax error, command unrecognized" ); // No tr
631 else { 631 else {
632 QDir dir( absFilePath( args ) ); 632 QDir dir( absFilePath( args ) );
633 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) 633 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) )
634 send( "250 Requested file action okay, completed." ); // No tr 634 send( "250 Requested file action okay, completed." ); // No tr
635 else 635 else
636 send( "550 Requested action not taken" ); // No tr 636 send( "550 Requested action not taken" ); // No tr
637 } 637 }
638 } 638 }
639 639
640 // abort (ABOR) 640 // abort (ABOR)
641 else if ( cmd.contains( "ABOR" ) ) { 641 else if ( cmd.contains( "ABOR" ) ) {
642 dtp->close(); 642 dtp->close();
643 if ( dtp->dtpMode() != ServerDTP::Idle ) 643 if ( dtp->dtpMode() != ServerDTP::Idle )
644 send( "426 Connection closed; transfer aborted" ); // No tr 644 send( "426 Connection closed; transfer aborted" ); // No tr
645 else 645 else
646 send( "226 Closing data connection" ); // No tr 646 send( "226 Closing data connection" ); // No tr
647 } 647 }
648 648
649 // delete (DELE) 649 // delete (DELE)
650 else if ( cmd == "DELE" ) { 650 else if ( cmd == "DELE" ) {
651 if ( args.isEmpty() ) 651 if ( args.isEmpty() )
652 send( "500 Syntax error, command unrecognized" ); // No tr 652 send( "500 Syntax error, command unrecognized" ); // No tr
653 else { 653 else {
654 QFile file( absFilePath( args ) ) ; 654 QFile file( absFilePath( args ) ) ;
655 if ( file.remove() ) { 655 if ( file.remove() ) {
656 send( "250 Requested file action okay, completed" ); // No tr 656 send( "250 Requested file action okay, completed" ); // No tr
657 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 657 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
658 e << file.name(); 658 e << file.name();
659 } else { 659 } else {
660 send( "550 Requested action not taken" ); // No tr 660 send( "550 Requested action not taken" ); // No tr
661 } 661 }
662 } 662 }
663 } 663 }
664 664
665 // remove directory (RMD) 665 // remove directory (RMD)
666 else if ( cmd == "RMD" ) { 666 else if ( cmd == "RMD" ) {
667 if ( args.isEmpty() ) 667 if ( args.isEmpty() )
668 send( "500 Syntax error, command unrecognized" ); // No tr 668 send( "500 Syntax error, command unrecognized" ); // No tr
669 else { 669 else {
670 QDir dir; 670 QDir dir;
671 if ( dir.rmdir( absFilePath( args ), TRUE ) ) 671 if ( dir.rmdir( absFilePath( args ), TRUE ) )
672 send( "250 Requested file action okay, completed" ); // No tr 672 send( "250 Requested file action okay, completed" ); // No tr
673 else 673 else
674 send( "550 Requested action not taken" ); // No tr 674 send( "550 Requested action not taken" ); // No tr
675 } 675 }
676 } 676 }
677 677
678 // make directory (MKD) 678 // make directory (MKD)
679 else if ( cmd == "MKD" ) { 679 else if ( cmd == "MKD" ) {
680 if ( args.isEmpty() ) { 680 if ( args.isEmpty() ) {
681 odebug << " Error: no arg" << oendl; 681 odebug << " Error: no arg" << oendl;
682 send( "500 Syntax error, command unrecognized" ); // No tr 682 send( "500 Syntax error, command unrecognized" ); // No tr
683 } 683 }
684 else { 684 else {
685 QDir dir; 685 QDir dir;
686 if ( dir.mkdir( absFilePath( args ), TRUE ) ) 686 if ( dir.mkdir( absFilePath( args ), TRUE ) )
687 send( "250 Requested file action okay, completed." ); // No tr 687 send( "250 Requested file action okay, completed." ); // No tr
688 else 688 else
689 send( "550 Requested action not taken" ); // No tr 689 send( "550 Requested action not taken" ); // No tr
690 } 690 }
691 } 691 }
692 692
693 // print working directory (PWD) 693 // print working directory (PWD)
694 else if ( cmd == "PWD" ) { 694 else if ( cmd == "PWD" ) {
695 send( "257 \"" + directory.path() +"\"" ); 695 send( "257 \"" + directory.path() +"\"" );
696 } 696 }
697 697
698 // list (LIST) 698 // list (LIST)
699 else if ( cmd == "LIST" ) { 699 else if ( cmd == "LIST" ) {
700 if ( sendList( absFilePath( args ) ) ) 700 if ( sendList( absFilePath( args ) ) )
701 send( "150 File status okay" ); // No tr 701 send( "150 File status okay" ); // No tr
702 else 702 else
703 send( "500 Syntax error, command unrecognized" ); // No tr 703 send( "500 Syntax error, command unrecognized" ); // No tr
704 } 704 }
705 705
706 // size (SIZE) 706 // size (SIZE)
707 else if ( cmd == "SIZE" ) { 707 else if ( cmd == "SIZE" ) {
708 QString filePath = absFilePath( args ); 708 QString filePath = absFilePath( args );
709 QFileInfo fi( filePath ); 709 QFileInfo fi( filePath );
710 bool gzipfile = backupRestoreGzip( filePath ); 710 bool gzipfile = backupRestoreGzip( filePath );
711 if ( !fi.exists() && !gzipfile ) 711 if ( !fi.exists() && !gzipfile )
712 send( "500 Syntax error, command unrecognized" ); // No tr 712 send( "500 Syntax error, command unrecognized" ); // No tr
713 else { 713 else {
714 if ( !gzipfile ) 714 if ( !gzipfile )
715 send( "213 " + QString::number( fi.size() ) ); 715 send( "213 " + QString::number( fi.size() ) );
716 else { 716 else {
717 Process duproc( QString("du") ); 717 Process duproc( QString("du") );
718 duproc.addArgument("-s"); 718 duproc.addArgument("-s");
719 QString in, out; 719 QString in, out;
720 if ( !duproc.exec(in, out) ) { 720 if ( !duproc.exec(in, out) ) {
721 odebug << "du process failed; just sending back 1K" << oendl; 721 odebug << "du process failed; just sending back 1K" << oendl;
722 send( "213 1024"); 722 send( "213 1024");
723 } 723 }
724 else { 724 else {
725 QString size = out.left( out.find("\t") ); 725 QString size = out.left( out.find("\t") );
726 int guess = size.toInt()/5; 726 int guess = size.toInt()/5;
727 if ( filePath.contains("doc") ) // No tr 727 if ( filePath.contains("doc") ) // No tr
728 guess *= 1000; 728 guess *= 1000;
729 odebug << "sending back gzip guess of " << guess << "" << oendl; 729 odebug << "sending back gzip guess of " << guess << "" << oendl;
730 send( "213 " + QString::number(guess) ); 730 send( "213 " + QString::number(guess) );
731 } 731 }
732 } 732 }
733 } 733 }
734 } 734 }
735 // name list (NLST) 735 // name list (NLST)
736 else if ( cmd == "NLST" ) { 736 else if ( cmd == "NLST" ) {
737 send( "502 Command not implemented" ); // No tr 737 send( "502 Command not implemented" ); // No tr
738 } 738 }
739 739
740 // site parameters (SITE) 740 // site parameters (SITE)
741 else if ( cmd == "SITE" ) { 741 else if ( cmd == "SITE" ) {
742 send( "502 Command not implemented" ); // No tr 742 send( "502 Command not implemented" ); // No tr
743 } 743 }
744 744
745 // system (SYST) 745 // system (SYST)
746 else if ( cmd == "SYST" ) { 746 else if ( cmd == "SYST" ) {
747 send( "215 UNIX Type: L8" ); // No tr 747 send( "215 UNIX Type: L8" ); // No tr
748 } 748 }
749 749
750 // status (STAT) 750 // status (STAT)
751 else if ( cmd == "STAT" ) { 751 else if ( cmd == "STAT" ) {
752 send( "502 Command not implemented" ); // No tr 752 send( "502 Command not implemented" ); // No tr
753 } 753 }
754 754
755 // help (HELP ) 755 // help (HELP )
756 else if ( cmd == "HELP" ) { 756 else if ( cmd == "HELP" ) {
757 send( "502 Command not implemented" ); // No tr 757 send( "502 Command not implemented" ); // No tr
758 } 758 }
759 759
760 // noop (NOOP) 760 // noop (NOOP)
761 else if ( cmd == "NOOP" ) { 761 else if ( cmd == "NOOP" ) {
762 send( "200 Command okay" ); // No tr 762 send( "200 Command okay" ); // No tr
763 } 763 }
764 764
765 // not implemented 765 // not implemented
766 else 766 else
767 send( "502 Command not implemented" ); // No tr 767 send( "502 Command not implemented" ); // No tr
768 768
769 lastCommand = cmd; 769 lastCommand = cmd;
@@ -773,5 +773,5 @@ bool ServerPI::backupRestoreGzip( const QString &file )
773{ 773{
774 return (file.find( "backup" ) != -1 && // No tr 774 return (file.find( "backup" ) != -1 && // No tr
775 file.findRev( ".tgz" ) == (int)file.length()-4 ); 775 file.findRev( ".tgz" ) == (int)file.length()-4 );
776} 776}
777 777
@@ -782,6 +782,5 @@ bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets )
782 QFileInfo info( file ); 782 QFileInfo info( file );
783 targets = info.dirPath( TRUE ); 783 targets = info.dirPath( TRUE );
784 qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), 784 odebug << "ServerPI::backupRestoreGzip for " << file.latin1() << " = " << targets.join(" ").latin1() << oendl;
785 targets.join(" ").latin1() );
786 return true; 785 return true;
787 } 786 }
@@ -792,13 +791,13 @@ void ServerPI::sendFile( const QString& file )
792{ 791{
793 if ( passiv ) { 792 if ( passiv ) {
794 wait[SendFile] = TRUE; 793 wait[SendFile] = TRUE;
795 waitfile = file; 794 waitfile = file;
796 if ( waitsocket ) 795 if ( waitsocket )
797 newConnection( waitsocket ); 796 newConnection( waitsocket );
798 } 797 }
799 else { 798 else {
800 QStringList targets; 799 QStringList targets;
801 if ( backupRestoreGzip( file, targets ) ) 800 if ( backupRestoreGzip( file, targets ) )
802 dtp->sendGzipFile( file, targets, peeraddress, peerport ); 801 dtp->sendGzipFile( file, targets, peeraddress, peerport );
803 else dtp->sendFile( file, peeraddress, peerport ); 802 else dtp->sendFile( file, peeraddress, peerport );
804 } 803 }
@@ -808,15 +807,15 @@ void ServerPI::retrieveFile( const QString& file )
808{ 807{
809 if ( passiv ) { 808 if ( passiv ) {
810 wait[RetrieveFile] = TRUE; 809 wait[RetrieveFile] = TRUE;
811 waitfile = file; 810 waitfile = file;
812 if ( waitsocket ) 811 if ( waitsocket )
813 newConnection( waitsocket ); 812 newConnection( waitsocket );
814 } 813 }
815 else { 814 else {
816 QStringList targets; 815 QStringList targets;
817 if ( backupRestoreGzip( file, targets ) ) 816 if ( backupRestoreGzip( file, targets ) )
818 dtp->retrieveGzipFile( file, peeraddress, peerport ); 817 dtp->retrieveGzipFile( file, peeraddress, peerport );
819 else 818 else
820 dtp->retrieveFile( file, peeraddress, peerport, storFileSize ); 819 dtp->retrieveFile( file, peeraddress, peerport, storFileSize );
821 } 820 }
822} 821}
@@ -829,5 +828,5 @@ bool ServerPI::parsePort( const QString& pp )
829 // h1,h2,h3,h4,p1,p2 828 // h1,h2,h3,h4,p1,p2
830 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + 829 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) +
831 ( p[2].toInt() << 8 ) + p[3].toInt() ); 830 ( p[2].toInt() << 8 ) + p[3].toInt() );
832 peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); 831 peerport = ( p[4].toInt() << 8 ) + p[5].toInt();
833 return TRUE; 832 return TRUE;
@@ -838,9 +837,9 @@ void ServerPI::dtpCompleted()
838 send( "226 Closing data connection, file transfer successful" ); // No tr 837 send( "226 Closing data connection, file transfer successful" ); // No tr
839 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { 838 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) {
840 QString fn = dtp->fileName(); 839 QString fn = dtp->fileName();
841 if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) { 840 if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) {
842 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 841 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
843 e << fn; 842 e << fn;
844 } 843 }
845 } 844 }
846 waitsocket = 0; 845 waitsocket = 0;
@@ -871,5 +870,5 @@ bool ServerPI::sendList( const QString& arg )
871 870
872 if ( !buffer.open( IO_WriteOnly ) ) 871 if ( !buffer.open( IO_WriteOnly ) )
873 return FALSE; 872 return FALSE;
874 873
875 QTextStream ts( &buffer ); 874 QTextStream ts( &buffer );
@@ -877,5 +876,5 @@ bool ServerPI::sendList( const QString& arg )
877 876
878 if ( fn.isEmpty() ) 877 if ( fn.isEmpty() )
879 fn = directory.path(); 878 fn = directory.path();
880 879
881 QFileInfo fi( fn ); 880 QFileInfo fi( fn );
@@ -884,43 +883,43 @@ bool ServerPI::sendList( const QString& arg )
884 // return file listing 883 // return file listing
885 if ( fi.isFile() ) { 884 if ( fi.isFile() ) {
886 ts << fileListing( &fi ) << endl; 885 ts << fileListing( &fi ) << endl;
887 } 886 }
888 887
889 // return directory listing 888 // return directory listing
890 else if ( fi.isDir() ) { 889 else if ( fi.isDir() ) {
891 QDir dir( fn ); 890 QDir dir( fn );
892 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); 891 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden );
893 892
894 QFileInfoListIterator it( *list ); 893 QFileInfoListIterator it( *list );
895 QFileInfo *info; 894 QFileInfo *info;
896 895
897 unsigned long total = 0; 896 unsigned long total = 0;
898 while ( ( info = it.current() ) ) { 897 while ( ( info = it.current() ) ) {
899 if ( info->fileName() != "." && info->fileName() != ".." ) 898 if ( info->fileName() != "." && info->fileName() != ".." )
900 total += info->size(); 899 total += info->size();
901 ++it; 900 ++it;
902 } 901 }
903 902
904 ts << "total " << QString::number( total / 1024 ) << endl; // No tr 903 ts << "total " << QString::number( total / 1024 ) << endl; // No tr
905 904
906 it.toFirst(); 905 it.toFirst();
907 while ( ( info = it.current() ) ) { 906 while ( ( info = it.current() ) ) {
908 if ( info->fileName() == "." || info->fileName() == ".." ) { 907 if ( info->fileName() == "." || info->fileName() == ".." ) {
909 ++it; 908 ++it;
910 continue; 909 continue;
911 } 910 }
912 ts << fileListing( info ) << endl; 911 ts << fileListing( info ) << endl;
913 ++it; 912 ++it;
914 } 913 }
915 } 914 }
916 915
917 if ( passiv ) { 916 if ( passiv ) {
918 waitarray = buffer.buffer(); 917 waitarray = buffer.buffer();
919 wait[SendByteArray] = TRUE; 918 wait[SendByteArray] = TRUE;
920 if ( waitsocket ) 919 if ( waitsocket )
921 newConnection( waitsocket ); 920 newConnection( waitsocket );
922 } 921 }
923 else 922 else
924 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); 923 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport );
925 return TRUE; 924 return TRUE;
926} 925}
@@ -933,9 +932,9 @@ QString ServerPI::fileListing( QFileInfo *info )
933 // type char 932 // type char
934 if ( info->isDir() ) 933 if ( info->isDir() )
935 s += "d"; 934 s += "d";
936 else if ( info->isSymLink() ) 935 else if ( info->isSymLink() )
937 s += "l"; 936 s += "l";
938 else 937 else
939 s += "-"; 938 s += "-";
940 939
941 // permisson string 940 // permisson string
@@ -946,5 +945,5 @@ QString ServerPI::fileListing( QFileInfo *info )
946 945
947 if ( info->isDir() ) 946 if ( info->isDir() )
948 subdirs = 2; 947 subdirs = 2;
949 // FIXME : this is to slow 948 // FIXME : this is to slow
950 //if ( info->isDir() ) 949 //if ( info->isDir() )
@@ -956,5 +955,5 @@ QString ServerPI::fileListing( QFileInfo *info )
956 QString o = info->owner(); 955 QString o = info->owner();
957 if ( o.isEmpty() ) 956 if ( o.isEmpty() )
958 o = QString::number(info->ownerId()); 957 o = QString::number(info->ownerId());
959 s += o.leftJustify( 8, ' ', TRUE ) + " "; 958 s += o.leftJustify( 8, ' ', TRUE ) + " ";
960 959
@@ -962,5 +961,5 @@ QString ServerPI::fileListing( QFileInfo *info )
962 QString g = info->group(); 961 QString g = info->group();
963 if ( g.isEmpty() ) 962 if ( g.isEmpty() )
964 g = QString::number(info->groupId()); 963 g = QString::number(info->groupId());
965 s += g.leftJustify( 8, ' ', TRUE ) + " "; 964 s += g.leftJustify( 8, ' ', TRUE ) + " ";
966 965
@@ -972,7 +971,7 @@ QString ServerPI::fileListing( QFileInfo *info )
972 QTime time = info->lastModified().time(); 971 QTime time = info->lastModified().time();
973 s += date.monthName( date.month() ) + " " 972 s += date.monthName( date.month() ) + " "
974 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " 973 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " "
975 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" 974 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":"
976 + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; 975 + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " ";
977 976
978 // file name 977 // file name
@@ -1021,33 +1020,33 @@ void ServerPI::newConnection( int socket )
1021 1020
1022 if ( wait[SendFile] ) { 1021 if ( wait[SendFile] ) {
1023 QStringList targets; 1022 QStringList targets;
1024 if ( backupRestoreGzip( waitfile, targets ) ) 1023 if ( backupRestoreGzip( waitfile, targets ) )
1025 dtp->sendGzipFile( waitfile, targets ); 1024 dtp->sendGzipFile( waitfile, targets );
1026 else 1025 else
1027 dtp->sendFile( waitfile ); 1026 dtp->sendFile( waitfile );
1028 dtp->setSocket( socket ); 1027 dtp->setSocket( socket );
1029 } 1028 }
1030 else if ( wait[RetrieveFile] ) { 1029 else if ( wait[RetrieveFile] ) {
1031 odebug << "check retrieve file" << oendl; 1030 odebug << "check retrieve file" << oendl;
1032 if ( backupRestoreGzip( waitfile ) ) 1031 if ( backupRestoreGzip( waitfile ) )
1033 dtp->retrieveGzipFile( waitfile ); 1032 dtp->retrieveGzipFile( waitfile );
1034 else 1033 else
1035 dtp->retrieveFile( waitfile, storFileSize ); 1034 dtp->retrieveFile( waitfile, storFileSize );
1036 dtp->setSocket( socket ); 1035 dtp->setSocket( socket );
1037 } 1036 }
1038 else if ( wait[SendByteArray] ) { 1037 else if ( wait[SendByteArray] ) {
1039 dtp->sendByteArray( waitarray ); 1038 dtp->sendByteArray( waitarray );
1040 dtp->setSocket( socket ); 1039 dtp->setSocket( socket );
1041 } 1040 }
1042 else if ( wait[RetrieveByteArray] ) { 1041 else if ( wait[RetrieveByteArray] ) {
1043 odebug << "retrieve byte array" << oendl; 1042 odebug << "retrieve byte array" << oendl;
1044 dtp->retrieveByteArray(); 1043 dtp->retrieveByteArray();
1045 dtp->setSocket( socket ); 1044 dtp->setSocket( socket );
1046 } 1045 }
1047 else 1046 else
1048 waitsocket = socket; 1047 waitsocket = socket;
1049 1048
1050 for( int i = 0; i < 4; i++ ) 1049 for( int i = 0; i < 4; i++ )
1051 wait[i] = FALSE; 1050 wait[i] = FALSE;
1052} 1051}
1053 1052
@@ -1058,5 +1057,5 @@ QString ServerPI::absFilePath( const QString& file )
1058 QString filepath( file ); 1057 QString filepath( file );
1059 if ( file[0] != "/" ) 1058 if ( file[0] != "/" )
1060 filepath = directory.path() + "/" + file; 1059 filepath = directory.path() + "/" + file;
1061 1060
1062 return filepath; 1061 return filepath;
@@ -1089,7 +1088,7 @@ ServerDTP::ServerDTP( QObject *parent, const char* name)
1089 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1088 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1090 connect( retrieveTargzProc, SIGNAL( processExited() ), 1089 connect( retrieveTargzProc, SIGNAL( processExited() ),
1091 SIGNAL( completed() ) ); 1090 SIGNAL( completed() ) );
1092 connect( retrieveTargzProc, SIGNAL( processExited() ), 1091 connect( retrieveTargzProc, SIGNAL( processExited() ),
1093 SLOT( extractTarDone() ) ); 1092 SLOT( extractTarDone() ) );
1094} 1093}
1095 1094
@@ -1098,12 +1097,12 @@ ServerDTP::~ServerDTP()
1098 buf.close(); 1097 buf.close();
1099 if ( RetrieveFile == mode && file.isOpen() ) { 1098 if ( RetrieveFile == mode && file.isOpen() ) {
1100 // We're being shutdown before the client closed. 1099 // We're being shutdown before the client closed.
1101 file.close(); 1100 file.close();
1102 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { 1101 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) {
1103 odebug << "STOR incomplete" << oendl; 1102 odebug << "STOR incomplete" << oendl;
1104 file.remove(); 1103 file.remove();
1105 } 1104 }
1106 } else { 1105 } else {
1107 file.close(); 1106 file.close();
1108 } 1107 }
1109 createTargzProc->kill(); 1108 createTargzProc->kill();
@@ -1141,8 +1140,8 @@ void ServerDTP::connected()
1141 // Don't write more if there is plenty buffered already. 1140 // Don't write more if there is plenty buffered already.
1142 if ( bytesToWrite() <= block_size && !file.atEnd() ) { 1141 if ( bytesToWrite() <= block_size && !file.atEnd() ) {
1143 QCString s; 1142 QCString s;
1144 s.resize( block_size ); 1143 s.resize( block_size );
1145 int bytes = file.readBlock( s.data(), block_size ); 1144 int bytes = file.readBlock( s.data(), block_size );
1146 writeBlock( s.data(), bytes ); 1145 writeBlock( s.data(), bytes );
1147 } 1146 }
1148 } 1147 }
@@ -1159,5 +1158,5 @@ void ServerDTP::connected()
1159 if ( !createTargzProc->start() ) 1158 if ( !createTargzProc->start() )
1160 qWarning("Error starting %s", 1159 qWarning("Error starting %s",
1161 createTargzProc->arguments().join(" ").latin1()); 1160 createTargzProc->arguments().join(" ").latin1());
1162 break; 1161 break;
1163 case SendBuffer: 1162 case SendBuffer:
@@ -1213,40 +1212,40 @@ void ServerDTP::connectionClosed()
1213 // send file mode 1212 // send file mode
1214 if ( SendFile == mode ) { 1213 if ( SendFile == mode ) {
1215 if ( bytes_written == file.size() ) 1214 if ( bytes_written == file.size() )
1216 emit completed(); 1215 emit completed();
1217 else 1216 else
1218 emit failed(); 1217 emit failed();
1219 } 1218 }
1220 1219
1221 // send buffer mode 1220 // send buffer mode
1222 else if ( SendBuffer == mode ) { 1221 else if ( SendBuffer == mode ) {
1223 if ( bytes_written == buf.size() ) 1222 if ( bytes_written == buf.size() )
1224 emit completed(); 1223 emit completed();
1225 else 1224 else
1226 emit failed(); 1225 emit failed();
1227 } 1226 }
1228 1227
1229 // retrieve file mode 1228 // retrieve file mode
1230 else if ( RetrieveFile == mode ) { 1229 else if ( RetrieveFile == mode ) {
1231 file.close(); 1230 file.close();
1232 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { 1231 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) {
1233 odebug << "STOR incomplete" << oendl; 1232 odebug << "STOR incomplete" << oendl;
1234 file.remove(); 1233 file.remove();
1235 emit failed(); 1234 emit failed();
1236 } else { 1235 } else {
1237 emit completed(); 1236 emit completed();
1238 } 1237 }
1239 } 1238 }
1240 1239
1241 else if ( RetrieveGzipFile == mode ) { 1240 else if ( RetrieveGzipFile == mode ) {
1242 odebug << "Done writing ungzip file; closing input" << oendl; 1241 odebug << "Done writing ungzip file; closing input" << oendl;
1243 retrieveTargzProc->flushStdin(); 1242 retrieveTargzProc->flushStdin();
1244 retrieveTargzProc->closeStdin(); 1243 retrieveTargzProc->closeStdin();
1245 } 1244 }
1246 1245
1247 // retrieve buffer mode 1246 // retrieve buffer mode
1248 else if ( RetrieveBuffer == mode ) { 1247 else if ( RetrieveBuffer == mode ) {
1249 buf.close(); 1248 buf.close();
1250 emit completed(); 1249 emit completed();
1251 } 1250 }
1252 1251
@@ -1261,16 +1260,16 @@ void ServerDTP::bytesWritten( int bytes )
1261 if ( SendFile == mode ) { 1260 if ( SendFile == mode ) {
1262 1261
1263 if ( bytes_written == file.size() ) { 1262 if ( bytes_written == file.size() ) {
1264 // odebug << "Debug: Sending complete: " << file.size() << " bytes" << oendl; 1263 // odebug << "Debug: Sending complete: " << file.size() << " bytes" << oendl;
1265 file.close(); 1264 file.close();
1266 emit completed(); 1265 emit completed();
1267 mode = Idle; 1266 mode = Idle;
1268 } 1267 }
1269 else if( !file.atEnd() ) { 1268 else if( !file.atEnd() ) {
1270 QCString s; 1269 QCString s;
1271 s.resize( block_size ); 1270 s.resize( block_size );
1272 int bytes = file.readBlock( s.data(), block_size ); 1271 int bytes = file.readBlock( s.data(), block_size );
1273 writeBlock( s.data(), bytes ); 1272 writeBlock( s.data(), bytes );
1274 } 1273 }
1275 } 1274 }
1276 1275
@@ -1278,9 +1277,9 @@ void ServerDTP::bytesWritten( int bytes )
1278 if ( SendBuffer == mode ) { 1277 if ( SendBuffer == mode ) {
1279 1278
1280 if ( bytes_written == buf.size() ) { 1279 if ( bytes_written == buf.size() ) {
1281 // odebug << "Debug: Sending complete: " << buf.size() << " bytes" << oendl; 1280 // odebug << "Debug: Sending complete: " << buf.size() << " bytes" << oendl;
1282 emit completed(); 1281 emit completed();
1283 mode = Idle; 1282 mode = Idle;
1284 } 1283 }
1285 } 1284 }
1286} 1285}
@@ -1290,25 +1289,25 @@ void ServerDTP::readyRead()
1290 // retrieve file mode 1289 // retrieve file mode
1291 if ( RetrieveFile == mode ) { 1290 if ( RetrieveFile == mode ) {
1292 QCString s; 1291 QCString s;
1293 s.resize( bytesAvailable() ); 1292 s.resize( bytesAvailable() );
1294 readBlock( s.data(), bytesAvailable() ); 1293 readBlock( s.data(), bytesAvailable() );
1295 file.writeBlock( s.data(), s.size() ); 1294 file.writeBlock( s.data(), s.size() );
1296 } 1295 }
1297 else if ( RetrieveGzipFile == mode ) { 1296 else if ( RetrieveGzipFile == mode ) {
1298 if ( !retrieveTargzProc->isRunning() ) 1297 if ( !retrieveTargzProc->isRunning() )
1299 retrieveTargzProc->start(); 1298 retrieveTargzProc->start();
1300 1299
1301 QByteArray s; 1300 QByteArray s;
1302 s.resize( bytesAvailable() ); 1301 s.resize( bytesAvailable() );
1303 readBlock( s.data(), bytesAvailable() ); 1302 readBlock( s.data(), bytesAvailable() );
1304 retrieveTargzProc->writeToStdin( s ); 1303 retrieveTargzProc->writeToStdin( s );
1305 odebug << "wrote " << s.size() << " bytes to ungzip " << oendl; 1304 odebug << "wrote " << s.size() << " bytes to ungzip " << oendl;
1306 } 1305 }
1307 // retrieve buffer mode 1306 // retrieve buffer mode
1308 else if ( RetrieveBuffer == mode ) { 1307 else if ( RetrieveBuffer == mode ) {
1309 QCString s; 1308 QCString s;
1310 s.resize( bytesAvailable() ); 1309 s.resize( bytesAvailable() );
1311 readBlock( s.data(), bytesAvailable() ); 1310 readBlock( s.data(), bytesAvailable() );
1312 buf.writeBlock( s.data(), s.size() ); 1311 buf.writeBlock( s.data(), s.size() );
1313 } 1312 }
1314} 1313}
@@ -1327,5 +1326,5 @@ void ServerDTP::targzDone()
1327 mode = Idle; 1326 mode = Idle;
1328 disconnect( createTargzProc, SIGNAL( readyReadStdout() ), 1327 disconnect( createTargzProc, SIGNAL( readyReadStdout() ),
1329 this, SLOT( writeTargzBlock() ) ); 1328 this, SLOT( writeTargzBlock() ) );
1330} 1329}
1331 1330
@@ -1344,6 +1343,6 @@ void ServerDTP::sendFile( const QString fn )
1344 1343
1345void ServerDTP::sendGzipFile( const QString &fn, 1344void ServerDTP::sendGzipFile( const QString &fn,
1346 const QStringList &archiveTargets, 1345 const QStringList &archiveTargets,
1347 const QHostAddress& host, Q_UINT16 port ) 1346 const QHostAddress& host, Q_UINT16 port )
1348{ 1347{
1349 sendGzipFile( fn, archiveTargets ); 1348 sendGzipFile( fn, archiveTargets );
@@ -1352,5 +1351,5 @@ void ServerDTP::sendGzipFile( const QString &fn,
1352 1351
1353void ServerDTP::sendGzipFile( const QString &fn, 1352void ServerDTP::sendGzipFile( const QString &fn,
1354 const QStringList &archiveTargets ) 1353 const QStringList &archiveTargets )
1355{ 1354{
1356 mode = SendGzipFile; 1355 mode = SendGzipFile;
@@ -1363,5 +1362,5 @@ void ServerDTP::sendGzipFile( const QString &fn,
1363 createTargzProc->setArguments( args ); 1362 createTargzProc->setArguments( args );
1364 connect( createTargzProc, 1363 connect( createTargzProc,
1365 SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); 1364 SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) );
1366} 1365}
1367 1366
@@ -1389,5 +1388,5 @@ void ServerDTP::retrieveGzipFile( const QString &fn )
1389 retrieveTargzProc->setArguments( "targunzip" ); 1388 retrieveTargzProc->setArguments( "targunzip" );
1390 connect( retrieveTargzProc, SIGNAL( processExited() ), 1389 connect( retrieveTargzProc, SIGNAL( processExited() ),
1391 SLOT( extractTarDone() ) ); 1390 SLOT( extractTarDone() ) );
1392} 1391}
1393 1392