From f8add41b2e0b0371754521b44d95f87fa70a6ff2 Mon Sep 17 00:00:00 2001 From: ar Date: Sun, 02 May 2004 16:35:53 +0000 Subject: - convert qDebug to odebug --- (limited to 'core/launcher/transferserver.cpp') 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 @@ -62,11 +62,11 @@ void TransferServer::authorizeConnections() { QListIterator it(connections); 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; } } @@ -104,9 +104,9 @@ QString SyncAuthentication::ownerName() QString vfilename = Global::applicationFileName("addressbook", "businesscard.vcf"); if (QFile::exists(vfilename)) { - Contact c; - c = Contact::readVCard( vfilename )[0]; - return c.fullName(); + Contact c; + c = Contact::readVCard( vfilename )[0]; + return c.fullName(); } return QString::null; @@ -127,18 +127,18 @@ QString SyncAuthentication::loginName() 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; } bool SyncAuthentication::checkUser( const QString& user ) @@ -161,12 +161,12 @@ bool SyncAuthentication::checkPassword( const QString& password ) QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); if ( cpwd == "x" && spw ) - cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); + cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); // Note: some systems use more than crypt for passwords. QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); if ( cpwd == cpassword ) - return TRUE; + return TRUE; #endif static int lastdenial=0; @@ -202,22 +202,22 @@ bool SyncAuthentication::checkPassword( const QString& password ) // Detect old Qtopia Desktop (no password) and fail if ( password.isEmpty() ) { - if ( denials < 3 || now > lastdenial+600 ) { - QMessageBox unauth( - tr("Sync Connection"), - tr("

An unauthorized system is requesting access to this device." - "

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("

An unauthorized system is requesting access to this device." + "

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; } @@ -232,59 +232,59 @@ bool SyncAuthentication::checkPassword( const QString& password ) * we need to support old Sync software and QtopiaDesktop */ 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( "

An unrecognized system is requesting access to this device." - "

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( "

An unrecognized system is requesting access to this device." + "

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; + } } lock--; @@ -305,37 +305,37 @@ ServerPI::ServerPI( int socket, QObject *parent, const char* name ) #ifndef INSECURE if ( !SyncAuthentication::isAuthorized(peeraddress) ) { - state = Forbidden; - startTimer( 0 ); + state = Forbidden; + startTimer( 0 ); } else #endif { - 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) ) ); } } @@ -352,8 +352,8 @@ ServerPI::~ServerPI() bool ServerPI::verifyAuthorised() { if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { - state = Forbidden; - return FALSE; + state = Forbidden; + return FALSE; } return TRUE; } @@ -374,7 +374,7 @@ void ServerPI::send( const QString& msg ) void ServerPI::read() { while ( canReadLine() ) - process( readLine().stripWhiteSpace() ); + process( readLine().stripWhiteSpace() ); } bool ServerPI::checkReadFile( const QString& file ) @@ -382,9 +382,9 @@ bool ServerPI::checkReadFile( const QString& file ) QString filename; if ( file[0] != "/" ) - filename = directory.path() + "/" + file; + filename = directory.path() + "/" + file; else - filename = file; + filename = file; QFileInfo fi( filename ); return ( fi.exists() && fi.isReadable() ); @@ -395,15 +395,15 @@ bool ServerPI::checkWriteFile( const QString& file ) QString filename; if ( file[0] != "/" ) - filename = directory.path() + "/" + file; + filename = directory.path() + "/" + file; else - filename = file; + filename = file; QFileInfo fi( filename ); if ( fi.exists() ) - if ( !QFile( filename ).remove() ) - return FALSE; + if ( !QFile( filename ).remove() ) + return FALSE; return TRUE; } @@ -421,7 +421,7 @@ void ServerPI::process( const QString& message ) // argument token QString arg; if ( msg.count() >= 2 ) - arg = msg[1]; + arg = msg[1]; // full argument string QString args; @@ -437,82 +437,82 @@ void ServerPI::process( const QString& message ) // we always respond to QUIT, regardless of state if ( cmd == "QUIT" ) { - send( "211 Good bye!" ); // No tr - close(); - return; + send( "211 Good bye!" ); // No tr + close(); + return; } // connected to client if ( Connected == state ) - return; + return; // waiting for user name if ( Wait_USER == state ) { - 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; } // waiting for password if ( Wait_PASS == state ) { - 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; } // ACCESS CONTROL COMMANDS // Only an ALLO sent immediately before STOR is valid. if ( cmd != "STOR" ) - storFileSize = -1; + storFileSize = -1; // account (ACCT) 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 } // change working directory (CWD) else if ( cmd == "CWD" ) { - 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 } // change to parent directory (CDUP) 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 } // structure mount (SMNT) 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 } // reinitialize (REIN) 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 } @@ -521,43 +521,43 @@ void ServerPI::process( const QString& message ) // data port (PORT) 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 } // passive (PASV) 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 ) +")" ); } // representation type (TYPE) 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 } // file structure (STRU) 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 } // transfer mode (MODE) 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 } @@ -566,205 +566,205 @@ void ServerPI::process( const QString& message ) // retrieve (RETR) 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 + } // store (STOR) 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 // store unique (STOU) else if ( cmd == "STOU" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } // append (APPE) else if ( cmd == "APPE" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } // allocate (ALLO) else if ( cmd == "ALLO" ) { - storFileSize = args.toInt(); - send( "200 Command okay" ); // No tr + storFileSize = args.toInt(); + send( "200 Command okay" ); // No tr } // restart (REST) else if ( cmd == "REST" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } // rename from (RNFR) 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 + } } // rename to (RNTO) 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 + } } // abort (ABOR) 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 } // delete (DELE) 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 + } + } } // remove directory (RMD) 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 + } } // make directory (MKD) 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 + } } // print working directory (PWD) else if ( cmd == "PWD" ) { - send( "257 \"" + directory.path() +"\"" ); + send( "257 \"" + directory.path() +"\"" ); } // list (LIST) 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 } // size (SIZE) 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) ); + } + } + } } // name list (NLST) else if ( cmd == "NLST" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } // site parameters (SITE) else if ( cmd == "SITE" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } // system (SYST) else if ( cmd == "SYST" ) { - send( "215 UNIX Type: L8" ); // No tr + send( "215 UNIX Type: L8" ); // No tr } // status (STAT) else if ( cmd == "STAT" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } // help (HELP ) else if ( cmd == "HELP" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } // noop (NOOP) else if ( cmd == "NOOP" ) { - send( "200 Command okay" ); // No tr + send( "200 Command okay" ); // No tr } // not implemented else - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr lastCommand = cmd; } @@ -772,7 +772,7 @@ void ServerPI::process( const QString& message ) 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 ); } bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) @@ -781,8 +781,7 @@ bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) file.findRev( ".tgz" ) == (int)file.length()-4 ) { QFileInfo info( file ); 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; } return false; @@ -791,15 +790,15 @@ bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) 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 ); } else { QStringList targets; if ( backupRestoreGzip( file, targets ) ) - dtp->sendGzipFile( file, targets, peeraddress, peerport ); + dtp->sendGzipFile( file, targets, peeraddress, peerport ); else dtp->sendFile( file, peeraddress, peerport ); } } @@ -807,17 +806,17 @@ void ServerPI::sendFile( const QString& file ) 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 ); } else { QStringList targets; 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 ); } } @@ -828,7 +827,7 @@ bool ServerPI::parsePort( const QString& pp ) // h1,h2,h3,h4,p1,p2 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(); return TRUE; } @@ -837,11 +836,11 @@ void ServerPI::dtpCompleted() { send( "226 Closing data connection, file transfer successful" ); // No tr 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; + } } waitsocket = 0; dtp->close(); @@ -870,58 +869,58 @@ bool ServerPI::sendList( const QString& arg ) QBuffer buffer( listing ); if ( !buffer.open( IO_WriteOnly ) ) - return FALSE; + return FALSE; QTextStream ts( &buffer ); QString fn = arg; if ( fn.isEmpty() ) - fn = directory.path(); + fn = directory.path(); QFileInfo fi( fn ); if ( !fi.exists() ) return FALSE; // return file listing if ( fi.isFile() ) { - ts << fileListing( &fi ) << endl; + ts << fileListing( &fi ) << endl; } // return directory listing 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; + } } 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; } @@ -932,11 +931,11 @@ QString ServerPI::fileListing( QFileInfo *info ) // type char if ( info->isDir() ) - s += "d"; + s += "d"; else if ( info->isSymLink() ) - s += "l"; + s += "l"; else - s += "-"; + s += "-"; // permisson string s += permissionString( info ) + " "; @@ -945,7 +944,7 @@ QString ServerPI::fileListing( QFileInfo *info ) int subdirs = 1; if ( info->isDir() ) - subdirs = 2; + subdirs = 2; // FIXME : this is to slow //if ( info->isDir() ) //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); @@ -955,13 +954,13 @@ QString ServerPI::fileListing( QFileInfo *info ) // owner QString o = info->owner(); if ( o.isEmpty() ) - o = QString::number(info->ownerId()); + o = QString::number(info->ownerId()); s += o.leftJustify( 8, ' ', TRUE ) + " "; // group QString g = info->group(); if ( g.isEmpty() ) - g = QString::number(info->groupId()); + g = QString::number(info->groupId()); s += g.leftJustify( 8, ' ', TRUE ) + " "; // file size in bytes @@ -971,9 +970,9 @@ QString ServerPI::fileListing( QFileInfo *info ) QDate date = info->lastModified().date(); QTime time = info->lastModified().time(); 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 ) + " "; // file name s += info->fileName(); @@ -1020,35 +1019,35 @@ void ServerPI::newConnection( int socket ) if ( !passiv ) return; 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 ); } else if ( wait[RetrieveFile] ) { odebug << "check retrieve file" << oendl; if ( backupRestoreGzip( waitfile ) ) - dtp->retrieveGzipFile( waitfile ); + dtp->retrieveGzipFile( waitfile ); else - dtp->retrieveFile( waitfile, storFileSize ); + dtp->retrieveFile( waitfile, storFileSize ); dtp->setSocket( socket ); } else if ( wait[SendByteArray] ) { - dtp->sendByteArray( waitarray ); - dtp->setSocket( socket ); + dtp->sendByteArray( waitarray ); + dtp->setSocket( socket ); } else if ( wait[RetrieveByteArray] ) { 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; } QString ServerPI::absFilePath( const QString& file ) @@ -1057,7 +1056,7 @@ QString ServerPI::absFilePath( const QString& file ) QString filepath( file ); if ( file[0] != "/" ) - filepath = directory.path() + "/" + file; + filepath = directory.path() + "/" + file; return filepath; } @@ -1088,23 +1087,23 @@ ServerDTP::ServerDTP( QObject *parent, const char* name) retrieveTargzProc->setCommunication( QProcess::Stdin ); retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); connect( retrieveTargzProc, SIGNAL( processExited() ), - SIGNAL( completed() ) ); + SIGNAL( completed() ) ); connect( retrieveTargzProc, SIGNAL( processExited() ), - SLOT( extractTarDone() ) ); + SLOT( extractTarDone() ) ); } ServerDTP::~ServerDTP() { buf.close(); 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(); } createTargzProc->kill(); } @@ -1140,10 +1139,10 @@ void ServerDTP::connected() } else { // Don't write more if there is plenty buffered already. 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 ); } } break; @@ -1158,7 +1157,7 @@ void ServerDTP::connected() odebug << "==>start send tar process" << oendl; if ( !createTargzProc->start() ) qWarning("Error starting %s", - createTargzProc->arguments().join(" ").latin1()); + createTargzProc->arguments().join(" ").latin1()); break; case SendBuffer: if ( !buf.open( IO_ReadOnly) ) { @@ -1212,42 +1211,42 @@ void ServerDTP::connectionClosed() // send file mode if ( SendFile == mode ) { - if ( bytes_written == file.size() ) - emit completed(); - else - emit failed(); + if ( bytes_written == file.size() ) + emit completed(); + else + emit failed(); } // send buffer mode else if ( SendBuffer == mode ) { - if ( bytes_written == buf.size() ) - emit completed(); - else - emit failed(); + if ( bytes_written == buf.size() ) + emit completed(); + else + emit failed(); } // retrieve file mode 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(); + } } else if ( RetrieveGzipFile == mode ) { odebug << "Done writing ungzip file; closing input" << oendl; - retrieveTargzProc->flushStdin(); - retrieveTargzProc->closeStdin(); + retrieveTargzProc->flushStdin(); + retrieveTargzProc->closeStdin(); } // retrieve buffer mode else if ( RetrieveBuffer == mode ) { - buf.close(); - emit completed(); + buf.close(); + emit completed(); } mode = Idle; @@ -1260,28 +1259,28 @@ void ServerDTP::bytesWritten( int bytes ) // send file mode if ( SendFile == mode ) { - 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 ); + } } // send buffer mode if ( SendBuffer == mode ) { - 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; + } } } @@ -1289,27 +1288,27 @@ void ServerDTP::readyRead() { // retrieve file mode 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; } // retrieve buffer mode 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() ); } } @@ -1326,7 +1325,7 @@ void ServerDTP::targzDone() emit completed(); mode = Idle; disconnect( createTargzProc, SIGNAL( readyReadStdout() ), - this, SLOT( writeTargzBlock() ) ); + this, SLOT( writeTargzBlock() ) ); } void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) @@ -1343,15 +1342,15 @@ 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 ) { sendGzipFile( fn, archiveTargets ); connectToHost( host.toString(), port ); } void ServerDTP::sendGzipFile( const QString &fn, - const QStringList &archiveTargets ) + const QStringList &archiveTargets ) { mode = SendGzipFile; file.setName( fn ); @@ -1362,7 +1361,7 @@ void ServerDTP::sendGzipFile( const QString &fn, odebug << "sendGzipFile " << args.join(" ") << "" << oendl; createTargzProc->setArguments( args ); connect( createTargzProc, - SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); + SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); } void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize ) @@ -1388,7 +1387,7 @@ void ServerDTP::retrieveGzipFile( const QString &fn ) retrieveTargzProc->setArguments( "targunzip" ); connect( retrieveTargzProc, SIGNAL( processExited() ), - SLOT( extractTarDone() ) ); + SLOT( extractTarDone() ) ); } void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) -- cgit v0.9.0.2