author | llornkcor <llornkcor> | 2002-07-18 03:11:17 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-07-18 03:11:17 (UTC) |
commit | 7fba4ce72b9201e3a04214c75a1031958090a618 (patch) (side-by-side diff) | |
tree | 77f7ea331fd38707f3c74dc5a67b47940ea36038 | |
parent | 786393948f3cd5f67a48f44a7a40422636f4b46e (diff) | |
download | opie-7fba4ce72b9201e3a04214c75a1031958090a618.zip opie-7fba4ce72b9201e3a04214c75a1031958090a618.tar.gz opie-7fba4ce72b9201e3a04214c75a1031958090a618.tar.bz2 |
attempt for change ip back to hex range from string
-rw-r--r-- | core/launcher/transferserver.cpp | 803 |
1 files changed, 402 insertions, 401 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp index a6dab07..ed3e2c6 100644 --- a/core/launcher/transferserver.cpp +++ b/core/launcher/transferserver.cpp @@ -63,7 +63,7 @@ TransferServer::TransferServer( Q_UINT16 port, QObject *parent , : QServerSocket( port, 1, parent, name ) { if ( !ok() ) - qWarning( "Failed to bind to port %d", port ); + qWarning( "Failed to bind to port %d", port ); } TransferServer::~TransferServer() @@ -82,9 +82,9 @@ QString SyncAuthentication::serverId() cfg.setGroup("Sync"); QString r=cfg.readEntry("serverid"); if ( r.isEmpty() ) { - uuid_t uuid; - uuid_generate( uuid ); - cfg.writeEntry("serverid",(r = QUuid( uuid ).toString())); + uuid_t uuid; + uuid_generate( uuid ); + cfg.writeEntry("serverid",(r = QUuid( uuid ).toString())); } return r; } @@ -94,9 +94,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 ""; @@ -113,13 +113,15 @@ int SyncAuthentication::isAuthorized(QHostAddress peeraddress) { Config cfg("Security"); cfg.setGroup("Sync"); - QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); - QHostAddress allowed; - allowed.setAddress(allowedstr); - uint auth_peer = allowed.ip4Addr(); +// 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)); + ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits)); return (peeraddress.ip4Addr() & mask) == auth_peer; } @@ -143,12 +145,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; @@ -157,49 +159,48 @@ bool SyncAuthentication::checkPassword( const QString& password ) // Detect old Qtopia Desktop (no password) if ( password.isEmpty() ) { - if ( denials < 1 || now > lastdenial+600 ) { - QMessageBox::warning( 0,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."), - tr("Deny") ); - denials++; - lastdenial=now; - } - return FALSE; + if ( denials < 1 || now > lastdenial+600 ) { + QMessageBox::warning( 0,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."), + tr("Deny") ); + denials++; + lastdenial=now; + } + return FALSE; } // Second, check sync password... if ( password.left(6) == "Qtopia" ) { - QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); - Config cfg("Security"); - cfg.setGroup("Sync"); - QString pwds = cfg.readEntry("Passwords"); - if ( QStringList::split(QChar(' '),pwds).contains(cpassword) ) - return TRUE; - - // Unrecognized system. Be careful... - - if ( (denials > 2 && now < lastdenial+600) - || QMessageBox::warning(0,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."), - tr("Allow"),tr("Deny"))==1 ) - { - denials++; - lastdenial=now; - return FALSE; - } else { - denials=0; - cfg.writeEntry("Passwords",pwds+" "+cpassword); - return TRUE; - } + QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); + Config cfg("Security"); + cfg.setGroup("Sync"); + QString pwds = cfg.readEntry("Passwords"); + if ( QStringList::split(QChar(' '),pwds).contains(cpassword) ) + return TRUE; + + // Unrecognized system. Be careful... + + if ( (denials > 2 && now < lastdenial+600) + || QMessageBox::warning(0,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."), + tr("Allow"),tr("Deny"))==1 ) + { + denials++; + lastdenial=now; + return FALSE; + } else { + denials=0; + cfg.writeEntry("Passwords",pwds+" "+cpassword); + return TRUE; + } } return FALSE; } - ServerPI::ServerPI( int socket, QObject *parent , const char* name ) : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) { @@ -212,37 +213,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 +#endif { - connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); - connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); - - passiv = FALSE; - for( int i = 0; i < 4; i++ ) - wait[i] = FALSE; + connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); + connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); + + passiv = FALSE; + for( int i = 0; i < 4; i++ ) + wait[i] = FALSE; - send( "220 Qtopia " QPE_VERSION " FTP Server" ); - state = Wait_USER; + send( "220 Qtopia " QPE_VERSION " FTP Server" ); + 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 ) ) ); } } @@ -267,7 +268,7 @@ void ServerPI::send( const QString& msg ) void ServerPI::read() { while ( canReadLine() ) - process( readLine().stripWhiteSpace() ); + process( readLine().stripWhiteSpace() ); } bool ServerPI::checkReadFile( const QString& file ) @@ -275,9 +276,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() ); @@ -288,15 +289,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; } @@ -314,7 +315,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; @@ -330,37 +331,37 @@ void ServerPI::process( const QString& message ) // we always respond to QUIT, regardless of state if ( cmd == "QUIT" ) { - send( "211 Good bye!" ); - delete this; - return; + send( "211 Good bye!" ); + delete this; + 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" ); - return; - } - send( "331 User name ok, need password" ); - state = Wait_PASS; - return; + if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { + send( "530 Please login with USER and PASS" ); + return; + } + send( "331 User name ok, need password" ); + 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" ); - return; - } - send( "230 User logged in, proceed" ); - state = Ready; - return; + if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { + send( "530 Please login with USER and PASS" ); + return; + } + send( "230 User logged in, proceed" ); + state = Ready; + return; } // ACCESS CONTROL COMMANDS @@ -368,41 +369,41 @@ void ServerPI::process( const QString& message ) // account (ACCT) if ( cmd == "ACCT" ) { - // even wu-ftp does not support it - send( "502 Command not implemented" ); + // even wu-ftp does not support it + send( "502 Command not implemented" ); } // change working directory (CWD) else if ( cmd == "CWD" ) { - if ( !args.isEmpty() ) { - if ( directory.cd( args, TRUE ) ) - send( "250 Requested file action okay, completed" ); - else - send( "550 Requested action not taken" ); - } - else - send( "500 Syntax error, command unrecognized" ); + if ( !args.isEmpty() ) { + if ( directory.cd( args, TRUE ) ) + send( "250 Requested file action okay, completed" ); + else + send( "550 Requested action not taken" ); + } + else + send( "500 Syntax error, command unrecognized" ); } // change to parent directory (CDUP) else if ( cmd == "CDUP" ) { - if ( directory.cdUp() ) - send( "250 Requested file action okay, completed" ); - else - send( "550 Requested action not taken" ); + if ( directory.cdUp() ) + send( "250 Requested file action okay, completed" ); + else + send( "550 Requested action not taken" ); } // structure mount (SMNT) else if ( cmd == "SMNT" ) { - // even wu-ftp does not support it - send( "502 Command not implemented" ); + // even wu-ftp does not support it + send( "502 Command not implemented" ); } // reinitialize (REIN) else if ( cmd == "REIN" ) { - // even wu-ftp does not support it - send( "502 Command not implemented" ); + // even wu-ftp does not support it + send( "502 Command not implemented" ); } @@ -411,43 +412,43 @@ void ServerPI::process( const QString& message ) // data port (PORT) else if ( cmd == "PORT" ) { - if ( parsePort( arg ) ) - send( "200 Command okay" ); - else - send( "500 Syntax error, command unrecognized" ); + if ( parsePort( arg ) ) + send( "200 Command okay" ); + else + send( "500 Syntax error, command unrecognized" ); } // passive (PASV) else if ( cmd == "PASV" ) { - passiv = TRUE; - send( "227 Entering Passive Mode (" - + address().toString().replace( QRegExp( "\\." ), "," ) + "," - + QString::number( ( serversocket->port() ) >> 8 ) + "," - + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); + passiv = TRUE; + send( "227 Entering Passive Mode (" + + 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" ); - else - send( "504 Command not implemented for that parameter" ); + if ( arg.upper() == "A" || arg.upper() == "I" ) + send( "200 Command okay" ); + else + send( "504 Command not implemented for that parameter" ); } // file structure (STRU) else if ( cmd == "STRU" ) { - if ( arg.upper() == "F" ) - send( "200 Command okay" ); - else - send( "504 Command not implemented for that parameter" ); + if ( arg.upper() == "F" ) + send( "200 Command okay" ); + else + send( "504 Command not implemented for that parameter" ); } // transfer mode (MODE) else if ( cmd == "MODE" ) { - if ( arg.upper() == "S" ) - send( "200 Command okay" ); - else - send( "504 Command not implemented for that parameter" ); + if ( arg.upper() == "S" ) + send( "200 Command okay" ); + else + send( "504 Command not implemented for that parameter" ); } @@ -456,204 +457,204 @@ 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" ); - sendFile( absFilePath( args ) ); - } - else { - qDebug("550 Requested action not taken"); - send( "550 Requested action not taken" ); - } + if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) + || backupRestoreGzip( absFilePath( args ) ) ) { + send( "150 File status okay" ); + sendFile( absFilePath( args ) ); + } + else { + qDebug("550 Requested action not taken"); + send( "550 Requested action not taken" ); + } // store (STOR) else if ( cmd == "STOR" ) - if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { - send( "150 File status okay" ); - retrieveFile( absFilePath( args ) ); - } - else - send( "550 Requested action not taken" ); + if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { + send( "150 File status okay" ); + retrieveFile( absFilePath( args ) ); + } + else + send( "550 Requested action not taken" ); // store unique (STOU) else if ( cmd == "STOU" ) { - send( "502 Command not implemented" ); + send( "502 Command not implemented" ); } // append (APPE) else if ( cmd == "APPE" ) { - send( "502 Command not implemented" ); + send( "502 Command not implemented" ); } // allocate (ALLO) else if ( cmd == "ALLO" ) { - send( "200 Command okay" ); + send( "200 Command okay" ); } // restart (REST) else if ( cmd == "REST" ) { - send( "502 Command not implemented" ); + send( "502 Command not implemented" ); } // rename from (RNFR) else if ( cmd == "RNFR" ) { - renameFrom = QString::null; - if ( args.isEmpty() ) - send( "500 Syntax error, command unrecognized" ); - else { - QFile file( absFilePath( args ) ); - if ( file.exists() ) { - send( "350 File exists, ready for destination name" ); - renameFrom = absFilePath( args ); - } - else - send( "550 Requested action not taken" ); - } + renameFrom = QString::null; + if ( args.isEmpty() ) + send( "500 Syntax error, command unrecognized" ); + else { + QFile file( absFilePath( args ) ); + if ( file.exists() ) { + send( "350 File exists, ready for destination name" ); + renameFrom = absFilePath( args ); + } + else + send( "550 Requested action not taken" ); + } } // rename to (RNTO) else if ( cmd == "RNTO" ) { - if ( lastCommand != "RNFR" ) - send( "503 Bad sequence of commands" ); - else if ( args.isEmpty() ) - send( "500 Syntax error, command unrecognized" ); - else { - QDir dir( absFilePath( args ) ); - if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) - send( "250 Requested file action okay, completed." ); - else - send( "550 Requested action not taken" ); - } + if ( lastCommand != "RNFR" ) + send( "503 Bad sequence of commands" ); + else if ( args.isEmpty() ) + send( "500 Syntax error, command unrecognized" ); + else { + QDir dir( absFilePath( args ) ); + if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) + send( "250 Requested file action okay, completed." ); + else + send( "550 Requested action not taken" ); + } } // abort (ABOR) else if ( cmd.contains( "ABOR" ) ) { - dtp->close(); - if ( dtp->dtpMode() != ServerDTP::Idle ) - send( "426 Connection closed; transfer aborted" ); - else - send( "226 Closing data connection" ); + dtp->close(); + if ( dtp->dtpMode() != ServerDTP::Idle ) + send( "426 Connection closed; transfer aborted" ); + else + send( "226 Closing data connection" ); } // delete (DELE) else if ( cmd == "DELE" ) { - if ( args.isEmpty() ) - send( "500 Syntax error, command unrecognized" ); - else { - QFile file( absFilePath( args ) ) ; - if ( file.remove() ) { - send( "250 Requested file action okay, completed" ); - QCopEnvelope e("QPE/System", "linkChanged(QString)" ); - e << file.name(); - } else { - send( "550 Requested action not taken" ); - } - } + if ( args.isEmpty() ) + send( "500 Syntax error, command unrecognized" ); + else { + QFile file( absFilePath( args ) ) ; + if ( file.remove() ) { + send( "250 Requested file action okay, completed" ); + QCopEnvelope e("QPE/System", "linkChanged(QString)" ); + e << file.name(); + } else { + send( "550 Requested action not taken" ); + } + } } // remove directory (RMD) else if ( cmd == "RMD" ) { - if ( args.isEmpty() ) - send( "500 Syntax error, command unrecognized" ); - else { - QDir dir; - if ( dir.rmdir( absFilePath( args ), TRUE ) ) - send( "250 Requested file action okay, completed" ); - else - send( "550 Requested action not taken" ); - } + if ( args.isEmpty() ) + send( "500 Syntax error, command unrecognized" ); + else { + QDir dir; + if ( dir.rmdir( absFilePath( args ), TRUE ) ) + send( "250 Requested file action okay, completed" ); + else + send( "550 Requested action not taken" ); + } } // make directory (MKD) else if ( cmd == "MKD" ) { - if ( args.isEmpty() ) { - qDebug(" Error: no arg"); - send( "500 Syntax error, command unrecognized" ); - } - else { - QDir dir; - if ( dir.mkdir( absFilePath( args ), TRUE ) ) - send( "250 Requested file action okay, completed." ); - else - send( "550 Requested action not taken" ); - } + if ( args.isEmpty() ) { + qDebug(" Error: no arg"); + send( "500 Syntax error, command unrecognized" ); + } + else { + QDir dir; + if ( dir.mkdir( absFilePath( args ), TRUE ) ) + send( "250 Requested file action okay, completed." ); + else + send( "550 Requested action not taken" ); + } } // 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" ); - else - send( "500 Syntax error, command unrecognized" ); + if ( sendList( absFilePath( args ) ) ) + send( "150 File status okay" ); + else + send( "500 Syntax error, command unrecognized" ); } // 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" ); - 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) ) { - qDebug("du process failed; just sending back 1K"); - send( "213 1024"); - } - else { - QString size = out.left( out.find("\t") ); - int guess = size.toInt()/5; - if ( filePath.contains("doc") ) - guess *= 1000; - qDebug("sending back gzip guess of %d", guess); - send( "213 " + QString::number(guess) ); - } - } - } + QString filePath = absFilePath( args ); + QFileInfo fi( filePath ); + bool gzipfile = backupRestoreGzip( filePath ); + if ( !fi.exists() && !gzipfile ) + send( "500 Syntax error, command unrecognized" ); + 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) ) { + qDebug("du process failed; just sending back 1K"); + send( "213 1024"); + } + else { + QString size = out.left( out.find("\t") ); + int guess = size.toInt()/5; + if ( filePath.contains("doc") ) + guess *= 1000; + qDebug("sending back gzip guess of %d", guess); + send( "213 " + QString::number(guess) ); + } + } + } } // name list (NLST) else if ( cmd == "NLST" ) { - send( "502 Command not implemented" ); + send( "502 Command not implemented" ); } // site parameters (SITE) else if ( cmd == "SITE" ) { - send( "502 Command not implemented" ); + send( "502 Command not implemented" ); } // system (SYST) else if ( cmd == "SYST" ) { - send( "215 UNIX Type: L8" ); + send( "215 UNIX Type: L8" ); } // status (STAT) else if ( cmd == "STAT" ) { - send( "502 Command not implemented" ); + send( "502 Command not implemented" ); } // help (HELP ) else if ( cmd == "HELP" ) { - send( "502 Command not implemented" ); + send( "502 Command not implemented" ); } // noop (NOOP) else if ( cmd == "NOOP" ) { - send( "200 Command okay" ); + send( "200 Command okay" ); } // not implemented else - send( "502 Command not implemented" ); + send( "502 Command not implemented" ); lastCommand = cmd; } @@ -661,7 +662,7 @@ void ServerPI::process( const QString& message ) bool ServerPI::backupRestoreGzip( const QString &file ) { return (file.find( "backup" ) != -1 && - file.findRev( ".tgz" ) == (int)file.length()-4 ); + file.findRev( ".tgz" ) == (int)file.length()-4 ); } bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) @@ -671,7 +672,7 @@ bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) QFileInfo info( file ); targets = info.dirPath( TRUE ); qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), - targets.join(" ").latin1() ); + targets.join(" ").latin1() ); return true; } return false; @@ -680,15 +681,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 ); } } @@ -696,17 +697,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 ); + dtp->retrieveFile( file, peeraddress, peerport ); } } @@ -717,7 +718,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; } @@ -726,11 +727,11 @@ void ServerPI::dtpCompleted() { send( "226 Closing data connection, file transfer successful" ); 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(); @@ -756,58 +757,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; + ts << "total " << QString::number( total / 1024 ) << endl; - 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; } @@ -818,11 +819,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 ) + " "; @@ -831,7 +832,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(); @@ -851,9 +852,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(); @@ -900,35 +901,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] ) { qDebug("check retrieve file"); if ( backupRestoreGzip( waitfile ) ) - dtp->retrieveGzipFile( waitfile ); + dtp->retrieveGzipFile( waitfile ); else - dtp->retrieveFile( waitfile ); + dtp->retrieveFile( waitfile ); dtp->setSocket( socket ); } else if ( wait[SendByteArray] ) { - dtp->sendByteArray( waitarray ); - dtp->setSocket( socket ); + dtp->sendByteArray( waitarray ); + dtp->setSocket( socket ); } else if ( wait[RetrieveByteArray] ) { - qDebug("retrieve byte array"); - dtp->retrieveByteArray(); - dtp->setSocket( socket ); + qDebug("retrieve byte array"); + 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 ) @@ -937,7 +938,7 @@ QString ServerPI::absFilePath( const QString& file ) QString filepath( file ); if ( file[0] != "/" ) - filepath = directory.path() + "/" + file; + filepath = directory.path() + "/" + file; return filepath; } @@ -973,9 +974,9 @@ retrieveTargzProc( 0 ), gzipProc( 0 ) 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() @@ -1016,10 +1017,10 @@ void ServerDTP::connected() } else { if( !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; @@ -1034,8 +1035,8 @@ void ServerDTP::connected() qDebug("==>start send tar process"); if ( !createTargzProc->start() ) qWarning("Error starting %s or %s", - createTargzProc->arguments().join(" ").latin1(), - gzipProc->arguments().join(" ").latin1() ); + createTargzProc->arguments().join(" ").latin1(), + gzipProc->arguments().join(" ").latin1() ); break; case SendBuffer: if ( !buf.open( IO_ReadOnly) ) { @@ -1089,36 +1090,36 @@ 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(); - emit completed(); + file.close(); + emit completed(); } else if ( RetrieveGzipFile == mode ) { - qDebug("Done writing ungzip file; closing input"); - gzipProc->flushStdin(); - gzipProc->closeStdin(); + qDebug("Done writing ungzip file; closing input"); + gzipProc->flushStdin(); + gzipProc->closeStdin(); } // retrieve buffer mode else if ( RetrieveBuffer == mode ) { - buf.close(); - emit completed(); + buf.close(); + emit completed(); } mode = Idle; @@ -1131,28 +1132,28 @@ void ServerDTP::bytesWritten( int bytes ) // send file mode if ( SendFile == mode ) { - if ( bytes_written == file.size() ) { - // qDebug( "Debug: Sending complete: %d bytes", file.size() ); - 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 ); - } + if ( bytes_written == file.size() ) { + // qDebug( "Debug: Sending complete: %d bytes", file.size() ); + 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() ) { - // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); - emit completed(); - mode = Idle; - } + if ( bytes_written == buf.size() ) { + // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); + emit completed(); + mode = Idle; + } } } @@ -1160,27 +1161,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 ( !gzipProc->isRunning() ) - gzipProc->start(); - - QByteArray s; - s.resize( bytesAvailable() ); - readBlock( s.data(), bytesAvailable() ); - gzipProc->writeToStdin( s ); - qDebug("wrote %d bytes to ungzip ", s.size() ); + if ( !gzipProc->isRunning() ) + gzipProc->start(); + + QByteArray s; + s.resize( bytesAvailable() ); + readBlock( s.data(), bytesAvailable() ); + gzipProc->writeToStdin( s ); + qDebug("wrote %d bytes to ungzip ", s.size() ); } // 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() ); } } @@ -1190,11 +1191,11 @@ void ServerDTP::writeTargzBlock() writeBlock( block.data(), block.size() ); qDebug("writeTargzBlock %d", block.size()); if ( !createTargzProc->isRunning() ) { - qDebug("tar and gzip done"); - emit completed(); - mode = Idle; - disconnect( gzipProc, SIGNAL( readyReadStdout() ), - this, SLOT( writeTargzBlock() ) ); + qDebug("tar and gzip done"); + emit completed(); + mode = Idle; + disconnect( gzipProc, SIGNAL( readyReadStdout() ), + this, SLOT( writeTargzBlock() ) ); } } @@ -1202,7 +1203,7 @@ void ServerDTP::targzDone() { //qDebug("targz done"); disconnect( createTargzProc, SIGNAL( readyReadStdout() ), - this, SLOT( gzipTarBlock() ) ); + this, SLOT( gzipTarBlock() ) ); gzipProc->closeStdin(); } @@ -1210,8 +1211,8 @@ void ServerDTP::gzipTarBlock() { //qDebug("gzipTarBlock"); if ( !gzipProc->isRunning() ) { - //qDebug("auto start gzip proc"); - gzipProc->start(); + //qDebug("auto start gzip proc"); + gzipProc->start(); } gzipProc->writeToStdin( createTargzProc->readStdout() ); } @@ -1230,15 +1231,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 ); @@ -1249,30 +1250,30 @@ void ServerDTP::sendGzipFile( const QString &fn, qDebug("sendGzipFile %s", args.join(" ").latin1() ); createTargzProc->setArguments( args ); connect( createTargzProc, - SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) ); + SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) ); - gzipProc->setArguments( "gzip" ); + gzipProc->setArguments( "gzip" ); connect( gzipProc, SIGNAL( readyReadStdout() ), - SLOT( writeTargzBlock() ) ); + SLOT( writeTargzBlock() ) ); } void ServerDTP::gunzipDone() { qDebug("gunzipDone"); disconnect( gzipProc, SIGNAL( processExited() ), - this, SLOT( gunzipDone() ) ); + this, SLOT( gunzipDone() ) ); retrieveTargzProc->closeStdin(); disconnect( gzipProc, SIGNAL( readyReadStdout() ), - this, SLOT( tarExtractBlock() ) ); + this, SLOT( tarExtractBlock() ) ); } void ServerDTP::tarExtractBlock() { qDebug("ungzipTarBlock"); if ( !retrieveTargzProc->isRunning() ) { - qDebug("auto start ungzip proc"); - if ( !retrieveTargzProc->start() ) - qWarning(" failed to start tar -x process"); + qDebug("auto start ungzip proc"); + if ( !retrieveTargzProc->start() ) + qWarning(" failed to start tar -x process"); } retrieveTargzProc->writeToStdin( gzipProc->readStdout() ); } @@ -1297,11 +1298,11 @@ void ServerDTP::retrieveGzipFile( const QString &fn ) file.setName( fn ); mode = RetrieveGzipFile; - gzipProc->setArguments( "gunzip" ); + gzipProc->setArguments( "gunzip" ); connect( gzipProc, SIGNAL( readyReadStdout() ), - SLOT( tarExtractBlock() ) ); + SLOT( tarExtractBlock() ) ); connect( gzipProc, SIGNAL( processExited() ), - SLOT( gunzipDone() ) ); + SLOT( gunzipDone() ) ); } void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) |