Diffstat (limited to 'core/launcher/transferserver.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/launcher/transferserver.cpp | 851 |
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 @@ -64,7 +64,7 @@ void TransferServer::authorizeConnections() while ( it.current() ) { - if ( !it.current()->verifyAuthorised() ) { - disconnect( it.current(), SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) ); - connections.removeRef( it.current() ); - } else - ++it; + if ( !it.current()->verifyAuthorised() ) { + disconnect( it.current(), SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) ); + connections.removeRef( it.current() ); + } else + ++it; } @@ -106,5 +106,5 @@ QString SyncAuthentication::ownerName() if (QFile::exists(vfilename)) { - Contact c; - c = Contact::readVCard( vfilename )[0]; - return c.fullName(); + Contact c; + c = Contact::readVCard( vfilename )[0]; + return c.fullName(); } @@ -129,14 +129,14 @@ int SyncAuthentication::isAuthorized(QHostAddress peeraddress) Config cfg("Security"); - cfg.setGroup("Sync"); - // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); - uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); - - // QHostAddress allowed; - // allowed.setAddress(allowedstr); - // uint auth_peer = allowed.ip4Addr(); - uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); - uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined - ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); - - return (peeraddress.ip4Addr() & mask) == auth_peer; + cfg.setGroup("Sync"); + // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); + uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); + + // QHostAddress allowed; + // allowed.setAddress(allowedstr); + // uint auth_peer = allowed.ip4Addr(); + uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); + uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined + ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); + + return (peeraddress.ip4Addr() & mask) == auth_peer; } @@ -163,3 +163,3 @@ bool SyncAuthentication::checkPassword( const QString& password ) if ( cpwd == "x" && spw ) - cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); + cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); @@ -168,3 +168,3 @@ bool SyncAuthentication::checkPassword( const QString& password ) if ( cpwd == cpassword ) - return TRUE; + return TRUE; #endif @@ -204,18 +204,18 @@ bool SyncAuthentication::checkPassword( const QString& password ) if ( password.isEmpty() ) { - if ( denials < 3 || now > lastdenial+600 ) { - QMessageBox unauth( - tr("Sync Connection"), - tr("<p>An unauthorized system is requesting access to this device." - "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " - "please upgrade or change the security setting to use IntelliSync." ), - QMessageBox::Warning, - QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, - 0, QString::null, TRUE, WStyle_StaysOnTop); - unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); - unauth.exec(); + if ( denials < 3 || now > lastdenial+600 ) { + QMessageBox unauth( + tr("Sync Connection"), + tr("<p>An unauthorized system is requesting access to this device." + "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " + "please upgrade or change the security setting to use IntelliSync." ), + QMessageBox::Warning, + QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, + 0, QString::null, TRUE, WStyle_StaysOnTop); + unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); + unauth.exec(); - denials++; - lastdenial=now; - } - return FALSE; + denials++; + lastdenial=now; + } + return FALSE; @@ -234,55 +234,55 @@ bool SyncAuthentication::checkPassword( const QString& password ) if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) { - Config cfg( "Security" ); - cfg.setGroup("Sync"); - QStringList pwds = cfg.readListEntry("Passwords",' '); - for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) { + Config cfg( "Security" ); + cfg.setGroup("Sync"); + QStringList pwds = cfg.readListEntry("Passwords",' '); + for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) { #ifndef Q_OS_WIN32 - QString cpassword = QString::fromLocal8Bit( - crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) ); + QString cpassword = QString::fromLocal8Bit( + crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) ); #else - // ### revise - QString cpassword(""); + // ### revise + QString cpassword(""); #endif - if ( *it == cpassword ) { - lock--; - return TRUE; - } - } - - // Unrecognized system. Be careful... - QMessageBox unrecbox( - tr("Sync Connection"), - tr( "<p>An unrecognized system is requesting access to this device." - "<p>If you have just initiated a Sync for the first time, this is normal."), - QMessageBox::Warning, - QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, - 0, QString::null, TRUE, WStyle_StaysOnTop); - unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny")); - unrecbox.setButtonText(QMessageBox::Yes, tr("Allow")); - - if ( (denials > 2 && now < lastdenial+600) - || unrecbox.exec() != QMessageBox::Yes) - { - denials++; - lastdenial=now; - lock--; - return FALSE; - } else { - const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."; - char salt[2]; - salt[0]= salty[rand() % (sizeof(salty)-1)]; - salt[1]= salty[rand() % (sizeof(salty)-1)]; + if ( *it == cpassword ) { + lock--; + return TRUE; + } + } + + // Unrecognized system. Be careful... + QMessageBox unrecbox( + tr("Sync Connection"), + tr( "<p>An unrecognized system is requesting access to this device." + "<p>If you have just initiated a Sync for the first time, this is normal."), + QMessageBox::Warning, + QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, + 0, QString::null, TRUE, WStyle_StaysOnTop); + unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny")); + unrecbox.setButtonText(QMessageBox::Yes, tr("Allow")); + + if ( (denials > 2 && now < lastdenial+600) + || unrecbox.exec() != QMessageBox::Yes) + { + denials++; + lastdenial=now; + lock--; + return FALSE; + } else { + const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."; + char salt[2]; + salt[0]= salty[rand() % (sizeof(salty)-1)]; + salt[1]= salty[rand() % (sizeof(salty)-1)]; #ifndef Q_OS_WIN32 - QString cpassword = QString::fromLocal8Bit( - crypt( password.mid(8).local8Bit(), salt ) ); + QString cpassword = QString::fromLocal8Bit( + crypt( password.mid(8).local8Bit(), salt ) ); #else - //### revise - QString cpassword(""); + //### revise + QString cpassword(""); #endif - denials=0; - pwds.prepend(cpassword); - cfg.writeEntry("Passwords",pwds,' '); - lock--; - return TRUE; - } + denials=0; + pwds.prepend(cpassword); + cfg.writeEntry("Passwords",pwds,' '); + lock--; + return TRUE; + } } @@ -307,4 +307,4 @@ ServerPI::ServerPI( int socket, QObject *parent, const char* name ) if ( !SyncAuthentication::isAuthorized(peeraddress) ) { - state = Forbidden; - startTimer( 0 ); + state = Forbidden; + startTimer( 0 ); } else @@ -312,28 +312,28 @@ ServerPI::ServerPI( int socket, QObject *parent, const char* name ) { - connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); - connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); + connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); + connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); - passiv = FALSE; - for( int i = 0; i < 4; i++ ) - wait[i] = FALSE; + passiv = FALSE; + for( int i = 0; i < 4; i++ ) + wait[i] = FALSE; - send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr - state = Wait_USER; + send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr + state = Wait_USER; - dtp = new ServerDTP( this ); - connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); - connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); - connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) ); + dtp = new ServerDTP( this ); + connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); + connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); + connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) ); - directory = QDir::currentDirPath(); + directory = QDir::currentDirPath(); - static int p = 1024; + static int p = 1024; - while ( !serversocket || !serversocket->ok() ) { - delete serversocket; - serversocket = new ServerSocket( ++p, this ); - } - connect( serversocket, SIGNAL( newIncomming(int) ), - SLOT( newConnection(int) ) ); + while ( !serversocket || !serversocket->ok() ) { + delete serversocket; + serversocket = new ServerSocket( ++p, this ); + } + connect( serversocket, SIGNAL( newIncomming(int) ), + SLOT( newConnection(int) ) ); } @@ -354,4 +354,4 @@ bool ServerPI::verifyAuthorised() if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { - state = Forbidden; - return FALSE; + state = Forbidden; + return FALSE; } @@ -376,3 +376,3 @@ void ServerPI::read() while ( canReadLine() ) - process( readLine().stripWhiteSpace() ); + process( readLine().stripWhiteSpace() ); } @@ -384,5 +384,5 @@ bool ServerPI::checkReadFile( const QString& file ) if ( file[0] != "/" ) - filename = directory.path() + "/" + file; + filename = directory.path() + "/" + file; else - filename = file; + filename = file; @@ -397,5 +397,5 @@ bool ServerPI::checkWriteFile( const QString& file ) if ( file[0] != "/" ) - filename = directory.path() + "/" + file; + filename = directory.path() + "/" + file; else - filename = file; + filename = file; @@ -404,4 +404,4 @@ bool ServerPI::checkWriteFile( const QString& file ) if ( fi.exists() ) - if ( !QFile( filename ).remove() ) - return FALSE; + if ( !QFile( filename ).remove() ) + return FALSE; return TRUE; @@ -423,3 +423,3 @@ void ServerPI::process( const QString& message ) if ( msg.count() >= 2 ) - arg = msg[1]; + arg = msg[1]; @@ -439,5 +439,5 @@ void ServerPI::process( const QString& message ) if ( cmd == "QUIT" ) { - send( "211 Good bye!" ); // No tr - close(); - return; + send( "211 Good bye!" ); // No tr + close(); + return; } @@ -446,3 +446,3 @@ void ServerPI::process( const QString& message ) if ( Connected == state ) - return; + return; @@ -451,9 +451,9 @@ void ServerPI::process( const QString& message ) - if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { - send( "530 Please login with USER and PASS" ); // No tr - return; - } - send( "331 User name ok, need password" ); // No tr - state = Wait_PASS; - return; + if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { + send( "530 Please login with USER and PASS" ); // No tr + return; + } + send( "331 User name ok, need password" ); // No tr + state = Wait_PASS; + return; } @@ -463,9 +463,9 @@ void ServerPI::process( const QString& message ) - if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { - send( "530 Please login with USER and PASS" ); // No tr - return; - } - send( "230 User logged in, proceed" ); // No tr - state = Ready; - return; + if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { + send( "530 Please login with USER and PASS" ); // No tr + return; + } + send( "230 User logged in, proceed" ); // No tr + state = Ready; + return; } @@ -476,3 +476,3 @@ void ServerPI::process( const QString& message ) if ( cmd != "STOR" ) - storFileSize = -1; + storFileSize = -1; @@ -480,4 +480,4 @@ void ServerPI::process( const QString& message ) if ( cmd == "ACCT" ) { - // even wu-ftp does not support it - send( "502 Command not implemented" ); // No tr + // even wu-ftp does not support it + send( "502 Command not implemented" ); // No tr } @@ -487,10 +487,10 @@ void ServerPI::process( const QString& message ) - if ( !args.isEmpty() ) { - if ( directory.cd( args, TRUE ) ) - send( "250 Requested file action okay, completed" ); // No tr - else - send( "550 Requested action not taken" ); // No tr - } - else - send( "500 Syntax error, command unrecognized" ); // No tr + if ( !args.isEmpty() ) { + if ( directory.cd( args, TRUE ) ) + send( "250 Requested file action okay, completed" ); // No tr + else + send( "550 Requested action not taken" ); // No tr + } + else + send( "500 Syntax error, command unrecognized" ); // No tr } @@ -499,6 +499,6 @@ void ServerPI::process( const QString& message ) else if ( cmd == "CDUP" ) { - if ( directory.cdUp() ) - send( "250 Requested file action okay, completed" ); // No tr - else - send( "550 Requested action not taken" ); // No tr + if ( directory.cdUp() ) + send( "250 Requested file action okay, completed" ); // No tr + else + send( "550 Requested action not taken" ); // No tr } @@ -507,4 +507,4 @@ void ServerPI::process( const QString& message ) else if ( cmd == "SMNT" ) { - // even wu-ftp does not support it - send( "502 Command not implemented" ); // No tr + // even wu-ftp does not support it + send( "502 Command not implemented" ); // No tr } @@ -513,4 +513,4 @@ void ServerPI::process( const QString& message ) else if ( cmd == "REIN" ) { - // even wu-ftp does not support it - send( "502 Command not implemented" ); // No tr + // even wu-ftp does not support it + send( "502 Command not implemented" ); // No tr } @@ -523,6 +523,6 @@ void ServerPI::process( const QString& message ) else if ( cmd == "PORT" ) { - if ( parsePort( arg ) ) - send( "200 Command okay" ); // No tr - else - send( "500 Syntax error, command unrecognized" ); // No tr + if ( parsePort( arg ) ) + send( "200 Command okay" ); // No tr + else + send( "500 Syntax error, command unrecognized" ); // No tr } @@ -531,7 +531,7 @@ void ServerPI::process( const QString& message ) else if ( cmd == "PASV" ) { - passiv = TRUE; - send( "227 Entering Passive Mode (" // No tr - + address().toString().replace( QRegExp( "\\." ), "," ) + "," - + QString::number( ( serversocket->port() ) >> 8 ) + "," - + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); + passiv = TRUE; + send( "227 Entering Passive Mode (" // No tr + + address().toString().replace( QRegExp( "\\." ), "," ) + "," + + QString::number( ( serversocket->port() ) >> 8 ) + "," + + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); } @@ -540,6 +540,6 @@ void ServerPI::process( const QString& message ) else if ( cmd == "TYPE" ) { - if ( arg.upper() == "A" || arg.upper() == "I" ) - send( "200 Command okay" ); // No tr - else - send( "504 Command not implemented for that parameter" ); // No tr + if ( arg.upper() == "A" || arg.upper() == "I" ) + send( "200 Command okay" ); // No tr + else + send( "504 Command not implemented for that parameter" ); // No tr } @@ -548,6 +548,6 @@ void ServerPI::process( const QString& message ) else if ( cmd == "STRU" ) { - if ( arg.upper() == "F" ) - send( "200 Command okay" ); // No tr - else - send( "504 Command not implemented for that parameter" ); // No tr + if ( arg.upper() == "F" ) + send( "200 Command okay" ); // No tr + else + send( "504 Command not implemented for that parameter" ); // No tr } @@ -556,6 +556,6 @@ void ServerPI::process( const QString& message ) else if ( cmd == "MODE" ) { - if ( arg.upper() == "S" ) - send( "200 Command okay" ); // No tr - else - send( "504 Command not implemented for that parameter" ); // No tr + if ( arg.upper() == "S" ) + send( "200 Command okay" ); // No tr + else + send( "504 Command not implemented for that parameter" ); // No tr } @@ -568,11 +568,11 @@ void ServerPI::process( const QString& message ) else if ( cmd == "RETR" ) - if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) - || backupRestoreGzip( absFilePath( args ) ) ) { - send( "150 File status okay" ); // No tr - sendFile( absFilePath( args ) ); - } - else { + if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) + || backupRestoreGzip( absFilePath( args ) ) ) { + send( "150 File status okay" ); // No tr + sendFile( absFilePath( args ) ); + } + else { odebug << "550 Requested action not taken" << oendl; - send( "550 Requested action not taken" ); // No tr - } + send( "550 Requested action not taken" ); // No tr + } @@ -580,8 +580,8 @@ void ServerPI::process( const QString& message ) else if ( cmd == "STOR" ) - if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { - send( "150 File status okay" ); // No tr - retrieveFile( absFilePath( args ) ); - } - else - send( "550 Requested action not taken" ); // No tr + if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { + send( "150 File status okay" ); // No tr + retrieveFile( absFilePath( args ) ); + } + else + send( "550 Requested action not taken" ); // No tr @@ -589,3 +589,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "STOU" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } @@ -594,3 +594,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "APPE" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } @@ -599,4 +599,4 @@ void ServerPI::process( const QString& message ) else if ( cmd == "ALLO" ) { - storFileSize = args.toInt(); - send( "200 Command okay" ); // No tr + storFileSize = args.toInt(); + send( "200 Command okay" ); // No tr } @@ -605,3 +605,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "REST" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } @@ -610,14 +610,14 @@ void ServerPI::process( const QString& message ) else if ( cmd == "RNFR" ) { - renameFrom = QString::null; - if ( args.isEmpty() ) - send( "500 Syntax error, command unrecognized" ); // No tr - else { - QFile file( absFilePath( args ) ); - if ( file.exists() ) { - send( "350 File exists, ready for destination name" ); // No tr - renameFrom = absFilePath( args ); - } - else - send( "550 Requested action not taken" ); // No tr - } + renameFrom = QString::null; + if ( args.isEmpty() ) + send( "500 Syntax error, command unrecognized" ); // No tr + else { + QFile file( absFilePath( args ) ); + if ( file.exists() ) { + send( "350 File exists, ready for destination name" ); // No tr + renameFrom = absFilePath( args ); + } + else + send( "550 Requested action not taken" ); // No tr + } } @@ -626,13 +626,13 @@ void ServerPI::process( const QString& message ) else if ( cmd == "RNTO" ) { - if ( lastCommand != "RNFR" ) - send( "503 Bad sequence of commands" ); // No tr - else if ( args.isEmpty() ) - send( "500 Syntax error, command unrecognized" ); // No tr - else { - QDir dir( absFilePath( args ) ); - if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) - send( "250 Requested file action okay, completed." ); // No tr - else - send( "550 Requested action not taken" ); // No tr - } + if ( lastCommand != "RNFR" ) + send( "503 Bad sequence of commands" ); // No tr + else if ( args.isEmpty() ) + send( "500 Syntax error, command unrecognized" ); // No tr + else { + QDir dir( absFilePath( args ) ); + if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) + send( "250 Requested file action okay, completed." ); // No tr + else + send( "550 Requested action not taken" ); // No tr + } } @@ -641,7 +641,7 @@ void ServerPI::process( const QString& message ) else if ( cmd.contains( "ABOR" ) ) { - dtp->close(); - if ( dtp->dtpMode() != ServerDTP::Idle ) - send( "426 Connection closed; transfer aborted" ); // No tr - else - send( "226 Closing data connection" ); // No tr + dtp->close(); + if ( dtp->dtpMode() != ServerDTP::Idle ) + send( "426 Connection closed; transfer aborted" ); // No tr + else + send( "226 Closing data connection" ); // No tr } @@ -650,14 +650,14 @@ void ServerPI::process( const QString& message ) else if ( cmd == "DELE" ) { - if ( args.isEmpty() ) - send( "500 Syntax error, command unrecognized" ); // No tr - else { - QFile file( absFilePath( args ) ) ; - if ( file.remove() ) { - send( "250 Requested file action okay, completed" ); // No tr - QCopEnvelope e("QPE/System", "linkChanged(QString)" ); - e << file.name(); - } else { - send( "550 Requested action not taken" ); // No tr - } - } + if ( args.isEmpty() ) + send( "500 Syntax error, command unrecognized" ); // No tr + else { + QFile file( absFilePath( args ) ) ; + if ( file.remove() ) { + send( "250 Requested file action okay, completed" ); // No tr + QCopEnvelope e("QPE/System", "linkChanged(QString)" ); + e << file.name(); + } else { + send( "550 Requested action not taken" ); // No tr + } + } } @@ -666,11 +666,11 @@ void ServerPI::process( const QString& message ) else if ( cmd == "RMD" ) { - if ( args.isEmpty() ) - send( "500 Syntax error, command unrecognized" ); // No tr - else { - QDir dir; - if ( dir.rmdir( absFilePath( args ), TRUE ) ) - send( "250 Requested file action okay, completed" ); // No tr - else - send( "550 Requested action not taken" ); // No tr - } + if ( args.isEmpty() ) + send( "500 Syntax error, command unrecognized" ); // No tr + else { + QDir dir; + if ( dir.rmdir( absFilePath( args ), TRUE ) ) + send( "250 Requested file action okay, completed" ); // No tr + else + send( "550 Requested action not taken" ); // No tr + } } @@ -679,13 +679,13 @@ void ServerPI::process( const QString& message ) else if ( cmd == "MKD" ) { - if ( args.isEmpty() ) { + if ( args.isEmpty() ) { odebug << " Error: no arg" << oendl; - send( "500 Syntax error, command unrecognized" ); // No tr - } - else { - QDir dir; - if ( dir.mkdir( absFilePath( args ), TRUE ) ) - send( "250 Requested file action okay, completed." ); // No tr - else - send( "550 Requested action not taken" ); // No tr - } + send( "500 Syntax error, command unrecognized" ); // No tr + } + else { + QDir dir; + if ( dir.mkdir( absFilePath( args ), TRUE ) ) + send( "250 Requested file action okay, completed." ); // No tr + else + send( "550 Requested action not taken" ); // No tr + } } @@ -694,3 +694,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "PWD" ) { - send( "257 \"" + directory.path() +"\"" ); + send( "257 \"" + directory.path() +"\"" ); } @@ -699,6 +699,6 @@ void ServerPI::process( const QString& message ) else if ( cmd == "LIST" ) { - if ( sendList( absFilePath( args ) ) ) - send( "150 File status okay" ); // No tr - else - send( "500 Syntax error, command unrecognized" ); // No tr + if ( sendList( absFilePath( args ) ) ) + send( "150 File status okay" ); // No tr + else + send( "500 Syntax error, command unrecognized" ); // No tr } @@ -707,28 +707,28 @@ void ServerPI::process( const QString& message ) else if ( cmd == "SIZE" ) { - QString filePath = absFilePath( args ); - QFileInfo fi( filePath ); - bool gzipfile = backupRestoreGzip( filePath ); - if ( !fi.exists() && !gzipfile ) - send( "500 Syntax error, command unrecognized" ); // No tr - else { - if ( !gzipfile ) - send( "213 " + QString::number( fi.size() ) ); - else { - Process duproc( QString("du") ); - duproc.addArgument("-s"); - QString in, out; - if ( !duproc.exec(in, out) ) { + QString filePath = absFilePath( args ); + QFileInfo fi( filePath ); + bool gzipfile = backupRestoreGzip( filePath ); + if ( !fi.exists() && !gzipfile ) + send( "500 Syntax error, command unrecognized" ); // No tr + else { + if ( !gzipfile ) + send( "213 " + QString::number( fi.size() ) ); + else { + Process duproc( QString("du") ); + duproc.addArgument("-s"); + QString in, out; + if ( !duproc.exec(in, out) ) { odebug << "du process failed; just sending back 1K" << oendl; - send( "213 1024"); - } - else { - QString size = out.left( out.find("\t") ); - int guess = size.toInt()/5; - if ( filePath.contains("doc") ) // No tr - guess *= 1000; + send( "213 1024"); + } + else { + QString size = out.left( out.find("\t") ); + int guess = size.toInt()/5; + if ( filePath.contains("doc") ) // No tr + guess *= 1000; odebug << "sending back gzip guess of " << guess << "" << oendl; - send( "213 " + QString::number(guess) ); - } - } - } + send( "213 " + QString::number(guess) ); + } + } + } } @@ -736,3 +736,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "NLST" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } @@ -741,3 +741,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "SITE" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } @@ -746,3 +746,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "SYST" ) { - send( "215 UNIX Type: L8" ); // No tr + send( "215 UNIX Type: L8" ); // No tr } @@ -751,3 +751,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "STAT" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } @@ -756,3 +756,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "HELP" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } @@ -761,3 +761,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "NOOP" ) { - send( "200 Command okay" ); // No tr + send( "200 Command okay" ); // No tr } @@ -766,3 +766,3 @@ void ServerPI::process( const QString& message ) else - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr @@ -774,3 +774,3 @@ bool ServerPI::backupRestoreGzip( const QString &file ) return (file.find( "backup" ) != -1 && // No tr - file.findRev( ".tgz" ) == (int)file.length()-4 ); + file.findRev( ".tgz" ) == (int)file.length()-4 ); } @@ -783,4 +783,3 @@ bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) targets = info.dirPath( TRUE ); - qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), - targets.join(" ").latin1() ); + odebug << "ServerPI::backupRestoreGzip for " << file.latin1() << " = " << targets.join(" ").latin1() << oendl; return true; @@ -793,6 +792,6 @@ void ServerPI::sendFile( const QString& file ) if ( passiv ) { - wait[SendFile] = TRUE; - waitfile = file; - if ( waitsocket ) - newConnection( waitsocket ); + wait[SendFile] = TRUE; + waitfile = file; + if ( waitsocket ) + newConnection( waitsocket ); } @@ -801,3 +800,3 @@ void ServerPI::sendFile( const QString& file ) if ( backupRestoreGzip( file, targets ) ) - dtp->sendGzipFile( file, targets, peeraddress, peerport ); + dtp->sendGzipFile( file, targets, peeraddress, peerport ); else dtp->sendFile( file, peeraddress, peerport ); @@ -809,6 +808,6 @@ void ServerPI::retrieveFile( const QString& file ) if ( passiv ) { - wait[RetrieveFile] = TRUE; - waitfile = file; - if ( waitsocket ) - newConnection( waitsocket ); + wait[RetrieveFile] = TRUE; + waitfile = file; + if ( waitsocket ) + newConnection( waitsocket ); } @@ -817,5 +816,5 @@ void ServerPI::retrieveFile( const QString& file ) if ( backupRestoreGzip( file, targets ) ) - dtp->retrieveGzipFile( file, peeraddress, peerport ); + dtp->retrieveGzipFile( file, peeraddress, peerport ); else - dtp->retrieveFile( file, peeraddress, peerport, storFileSize ); + dtp->retrieveFile( file, peeraddress, peerport, storFileSize ); } @@ -830,3 +829,3 @@ bool ServerPI::parsePort( const QString& pp ) peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + - ( p[2].toInt() << 8 ) + p[3].toInt() ); + ( p[2].toInt() << 8 ) + p[3].toInt() ); peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); @@ -839,7 +838,7 @@ void ServerPI::dtpCompleted() if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { - QString fn = dtp->fileName(); - if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) { - QCopEnvelope e("QPE/System", "linkChanged(QString)" ); - e << fn; - } + QString fn = dtp->fileName(); + if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) { + QCopEnvelope e("QPE/System", "linkChanged(QString)" ); + e << fn; + } } @@ -872,3 +871,3 @@ bool ServerPI::sendList( const QString& arg ) if ( !buffer.open( IO_WriteOnly ) ) - return FALSE; + return FALSE; @@ -878,3 +877,3 @@ bool ServerPI::sendList( const QString& arg ) if ( fn.isEmpty() ) - fn = directory.path(); + fn = directory.path(); @@ -885,3 +884,3 @@ bool ServerPI::sendList( const QString& arg ) if ( fi.isFile() ) { - ts << fileListing( &fi ) << endl; + ts << fileListing( &fi ) << endl; } @@ -890,26 +889,26 @@ bool ServerPI::sendList( const QString& arg ) else if ( fi.isDir() ) { - QDir dir( fn ); - const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); + QDir dir( fn ); + const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); - QFileInfoListIterator it( *list ); - QFileInfo *info; + QFileInfoListIterator it( *list ); + QFileInfo *info; - unsigned long total = 0; - while ( ( info = it.current() ) ) { - if ( info->fileName() != "." && info->fileName() != ".." ) - total += info->size(); - ++it; - } + unsigned long total = 0; + while ( ( info = it.current() ) ) { + if ( info->fileName() != "." && info->fileName() != ".." ) + total += info->size(); + ++it; + } - ts << "total " << QString::number( total / 1024 ) << endl; // No tr + ts << "total " << QString::number( total / 1024 ) << endl; // No tr - it.toFirst(); - while ( ( info = it.current() ) ) { - if ( info->fileName() == "." || info->fileName() == ".." ) { - ++it; - continue; - } - ts << fileListing( info ) << endl; - ++it; - } + it.toFirst(); + while ( ( info = it.current() ) ) { + if ( info->fileName() == "." || info->fileName() == ".." ) { + ++it; + continue; + } + ts << fileListing( info ) << endl; + ++it; + } } @@ -917,9 +916,9 @@ bool ServerPI::sendList( const QString& arg ) if ( passiv ) { - waitarray = buffer.buffer(); - wait[SendByteArray] = TRUE; - if ( waitsocket ) - newConnection( waitsocket ); + waitarray = buffer.buffer(); + wait[SendByteArray] = TRUE; + if ( waitsocket ) + newConnection( waitsocket ); } else - dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); + dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); return TRUE; @@ -934,7 +933,7 @@ QString ServerPI::fileListing( QFileInfo *info ) if ( info->isDir() ) - s += "d"; + s += "d"; else if ( info->isSymLink() ) - s += "l"; + s += "l"; else - s += "-"; + s += "-"; @@ -947,3 +946,3 @@ QString ServerPI::fileListing( QFileInfo *info ) if ( info->isDir() ) - subdirs = 2; + subdirs = 2; // FIXME : this is to slow @@ -957,3 +956,3 @@ QString ServerPI::fileListing( QFileInfo *info ) if ( o.isEmpty() ) - o = QString::number(info->ownerId()); + o = QString::number(info->ownerId()); s += o.leftJustify( 8, ' ', TRUE ) + " "; @@ -963,3 +962,3 @@ QString ServerPI::fileListing( QFileInfo *info ) if ( g.isEmpty() ) - g = QString::number(info->groupId()); + g = QString::number(info->groupId()); s += g.leftJustify( 8, ' ', TRUE ) + " "; @@ -973,5 +972,5 @@ QString ServerPI::fileListing( QFileInfo *info ) s += date.monthName( date.month() ) + " " - + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " - + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" - + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; + + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " + + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" + + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; @@ -1022,8 +1021,8 @@ void ServerPI::newConnection( int socket ) if ( wait[SendFile] ) { - QStringList targets; - if ( backupRestoreGzip( waitfile, targets ) ) - dtp->sendGzipFile( waitfile, targets ); - else - dtp->sendFile( waitfile ); - dtp->setSocket( socket ); + QStringList targets; + if ( backupRestoreGzip( waitfile, targets ) ) + dtp->sendGzipFile( waitfile, targets ); + else + dtp->sendFile( waitfile ); + dtp->setSocket( socket ); } @@ -1032,5 +1031,5 @@ void ServerPI::newConnection( int socket ) if ( backupRestoreGzip( waitfile ) ) - dtp->retrieveGzipFile( waitfile ); + dtp->retrieveGzipFile( waitfile ); else - dtp->retrieveFile( waitfile, storFileSize ); + dtp->retrieveFile( waitfile, storFileSize ); dtp->setSocket( socket ); @@ -1038,4 +1037,4 @@ void ServerPI::newConnection( int socket ) else if ( wait[SendByteArray] ) { - dtp->sendByteArray( waitarray ); - dtp->setSocket( socket ); + dtp->sendByteArray( waitarray ); + dtp->setSocket( socket ); } @@ -1043,10 +1042,10 @@ void ServerPI::newConnection( int socket ) odebug << "retrieve byte array" << oendl; - dtp->retrieveByteArray(); - dtp->setSocket( socket ); + dtp->retrieveByteArray(); + dtp->setSocket( socket ); } else - waitsocket = socket; + waitsocket = socket; for( int i = 0; i < 4; i++ ) - wait[i] = FALSE; + wait[i] = FALSE; } @@ -1059,3 +1058,3 @@ QString ServerPI::absFilePath( const QString& file ) if ( file[0] != "/" ) - filepath = directory.path() + "/" + file; + filepath = directory.path() + "/" + file; @@ -1090,5 +1089,5 @@ ServerDTP::ServerDTP( QObject *parent, const char* name) connect( retrieveTargzProc, SIGNAL( processExited() ), - SIGNAL( completed() ) ); + SIGNAL( completed() ) ); connect( retrieveTargzProc, SIGNAL( processExited() ), - SLOT( extractTarDone() ) ); + SLOT( extractTarDone() ) ); } @@ -1099,10 +1098,10 @@ ServerDTP::~ServerDTP() if ( RetrieveFile == mode && file.isOpen() ) { - // We're being shutdown before the client closed. - file.close(); - if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { + // We're being shutdown before the client closed. + file.close(); + if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { odebug << "STOR incomplete" << oendl; - file.remove(); - } + file.remove(); + } } else { - file.close(); + file.close(); } @@ -1142,6 +1141,6 @@ void ServerDTP::connected() if ( bytesToWrite() <= block_size && !file.atEnd() ) { - QCString s; - s.resize( block_size ); - int bytes = file.readBlock( s.data(), block_size ); - writeBlock( s.data(), bytes ); + QCString s; + s.resize( block_size ); + int bytes = file.readBlock( s.data(), block_size ); + writeBlock( s.data(), bytes ); } @@ -1160,3 +1159,3 @@ void ServerDTP::connected() qWarning("Error starting %s", - createTargzProc->arguments().join(" ").latin1()); + createTargzProc->arguments().join(" ").latin1()); break; @@ -1214,6 +1213,6 @@ void ServerDTP::connectionClosed() if ( SendFile == mode ) { - if ( bytes_written == file.size() ) - emit completed(); - else - emit failed(); + if ( bytes_written == file.size() ) + emit completed(); + else + emit failed(); } @@ -1222,6 +1221,6 @@ void ServerDTP::connectionClosed() else if ( SendBuffer == mode ) { - if ( bytes_written == buf.size() ) - emit completed(); - else - emit failed(); + if ( bytes_written == buf.size() ) + emit completed(); + else + emit failed(); } @@ -1230,10 +1229,10 @@ void ServerDTP::connectionClosed() else if ( RetrieveFile == mode ) { - file.close(); - if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { + file.close(); + if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { odebug << "STOR incomplete" << oendl; - file.remove(); - emit failed(); - } else { - emit completed(); - } + file.remove(); + emit failed(); + } else { + emit completed(); + } } @@ -1242,4 +1241,4 @@ void ServerDTP::connectionClosed() odebug << "Done writing ungzip file; closing input" << oendl; - retrieveTargzProc->flushStdin(); - retrieveTargzProc->closeStdin(); + retrieveTargzProc->flushStdin(); + retrieveTargzProc->closeStdin(); } @@ -1248,4 +1247,4 @@ void ServerDTP::connectionClosed() else if ( RetrieveBuffer == mode ) { - buf.close(); - emit completed(); + buf.close(); + emit completed(); } @@ -1262,14 +1261,14 @@ void ServerDTP::bytesWritten( int bytes ) - if ( bytes_written == file.size() ) { + if ( bytes_written == file.size() ) { // odebug << "Debug: Sending complete: " << file.size() << " bytes" << oendl; - file.close(); - emit completed(); - mode = Idle; - } - else if( !file.atEnd() ) { - QCString s; - s.resize( block_size ); - int bytes = file.readBlock( s.data(), block_size ); - writeBlock( s.data(), bytes ); - } + file.close(); + emit completed(); + mode = Idle; + } + else if( !file.atEnd() ) { + QCString s; + s.resize( block_size ); + int bytes = file.readBlock( s.data(), block_size ); + writeBlock( s.data(), bytes ); + } } @@ -1279,7 +1278,7 @@ void ServerDTP::bytesWritten( int bytes ) - if ( bytes_written == buf.size() ) { + if ( bytes_written == buf.size() ) { // odebug << "Debug: Sending complete: " << buf.size() << " bytes" << oendl; - emit completed(); - mode = Idle; - } + emit completed(); + mode = Idle; + } } @@ -1291,15 +1290,15 @@ void ServerDTP::readyRead() if ( RetrieveFile == mode ) { - QCString s; - s.resize( bytesAvailable() ); - readBlock( s.data(), bytesAvailable() ); - file.writeBlock( s.data(), s.size() ); + QCString s; + s.resize( bytesAvailable() ); + readBlock( s.data(), bytesAvailable() ); + file.writeBlock( s.data(), s.size() ); } else if ( RetrieveGzipFile == mode ) { - if ( !retrieveTargzProc->isRunning() ) - retrieveTargzProc->start(); + if ( !retrieveTargzProc->isRunning() ) + retrieveTargzProc->start(); - QByteArray s; - s.resize( bytesAvailable() ); - readBlock( s.data(), bytesAvailable() ); - retrieveTargzProc->writeToStdin( s ); + QByteArray s; + s.resize( bytesAvailable() ); + readBlock( s.data(), bytesAvailable() ); + retrieveTargzProc->writeToStdin( s ); odebug << "wrote " << s.size() << " bytes to ungzip " << oendl; @@ -1308,6 +1307,6 @@ void ServerDTP::readyRead() else if ( RetrieveBuffer == mode ) { - QCString s; - s.resize( bytesAvailable() ); - readBlock( s.data(), bytesAvailable() ); - buf.writeBlock( s.data(), s.size() ); + QCString s; + s.resize( bytesAvailable() ); + readBlock( s.data(), bytesAvailable() ); + buf.writeBlock( s.data(), s.size() ); } @@ -1328,3 +1327,3 @@ void ServerDTP::targzDone() disconnect( createTargzProc, SIGNAL( readyReadStdout() ), - this, SLOT( writeTargzBlock() ) ); + this, SLOT( writeTargzBlock() ) ); } @@ -1345,4 +1344,4 @@ void ServerDTP::sendFile( const QString fn ) void ServerDTP::sendGzipFile( const QString &fn, - const QStringList &archiveTargets, - const QHostAddress& host, Q_UINT16 port ) + const QStringList &archiveTargets, + const QHostAddress& host, Q_UINT16 port ) { @@ -1353,3 +1352,3 @@ void ServerDTP::sendGzipFile( const QString &fn, void ServerDTP::sendGzipFile( const QString &fn, - const QStringList &archiveTargets ) + const QStringList &archiveTargets ) { @@ -1364,3 +1363,3 @@ void ServerDTP::sendGzipFile( const QString &fn, connect( createTargzProc, - SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); + SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); } @@ -1390,3 +1389,3 @@ void ServerDTP::retrieveGzipFile( const QString &fn ) connect( retrieveTargzProc, SIGNAL( processExited() ), - SLOT( extractTarDone() ) ); + SLOT( extractTarDone() ) ); } |