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 /core/launcher | |
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 @@ -64,5 +64,5 @@ TransferServer::TransferServer( Q_UINT16 port, QObject *parent , { if ( !ok() ) - qWarning( "Failed to bind to port %d", port ); + qWarning( "Failed to bind to port %d", port ); } @@ -83,7 +83,7 @@ QString SyncAuthentication::serverId() 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; @@ -95,7 +95,7 @@ QString SyncAuthentication::ownerName() "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(); } @@ -114,11 +114,13 @@ 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; } @@ -144,10 +146,10 @@ 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 @@ -158,41 +160,41 @@ 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; + } } @@ -200,5 +202,4 @@ bool SyncAuthentication::checkPassword( const QString& password ) } - ServerPI::ServerPI( int socket, QObject *parent , const char* name ) : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) @@ -213,35 +214,35 @@ 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 ) ) ); } } @@ -268,5 +269,5 @@ void ServerPI::read() { while ( canReadLine() ) - process( readLine().stripWhiteSpace() ); + process( readLine().stripWhiteSpace() ); } @@ -276,7 +277,7 @@ bool ServerPI::checkReadFile( const QString& file ) if ( file[0] != "/" ) - filename = directory.path() + "/" + file; + filename = directory.path() + "/" + file; else - filename = file; + filename = file; QFileInfo fi( filename ); @@ -289,13 +290,13 @@ bool ServerPI::checkWriteFile( const QString& file ) 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; } @@ -315,5 +316,5 @@ void ServerPI::process( const QString& message ) QString arg; if ( msg.count() >= 2 ) - arg = msg[1]; + arg = msg[1]; // full argument string @@ -331,23 +332,23 @@ 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; } @@ -355,11 +356,11 @@ void ServerPI::process( const QString& message ) 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; } @@ -369,6 +370,6 @@ 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" ); } @@ -376,32 +377,32 @@ void ServerPI::process( const QString& message ) 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" ); } @@ -412,41 +413,41 @@ 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" ); } @@ -457,202 +458,202 @@ 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; @@ -662,5 +663,5 @@ 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 ); } @@ -672,5 +673,5 @@ bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) targets = info.dirPath( TRUE ); qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), - targets.join(" ").latin1() ); + targets.join(" ").latin1() ); return true; } @@ -681,13 +682,13 @@ 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 ); } @@ -697,15 +698,15 @@ 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 ); } } @@ -718,5 +719,5 @@ 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; @@ -727,9 +728,9 @@ 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; @@ -757,5 +758,5 @@ bool ServerPI::sendList( const QString& arg ) if ( !buffer.open( IO_WriteOnly ) ) - return FALSE; + return FALSE; QTextStream ts( &buffer ); @@ -763,5 +764,5 @@ bool ServerPI::sendList( const QString& arg ) if ( fn.isEmpty() ) - fn = directory.path(); + fn = directory.path(); QFileInfo fi( fn ); @@ -770,43 +771,43 @@ bool ServerPI::sendList( const QString& arg ) // 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; } @@ -819,9 +820,9 @@ 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 @@ -832,5 +833,5 @@ QString ServerPI::fileListing( QFileInfo *info ) if ( info->isDir() ) - subdirs = 2; + subdirs = 2; // FIXME : this is to slow //if ( info->isDir() ) @@ -852,7 +853,7 @@ QString ServerPI::fileListing( QFileInfo *info ) 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 @@ -901,33 +902,33 @@ 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 ); } 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; } @@ -938,5 +939,5 @@ QString ServerPI::absFilePath( const QString& file ) QString filepath( file ); if ( file[0] != "/" ) - filepath = directory.path() + "/" + file; + filepath = directory.path() + "/" + file; return filepath; @@ -974,7 +975,7 @@ retrieveTargzProc( 0 ), gzipProc( 0 ) retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); connect( retrieveTargzProc, SIGNAL( processExited() ), - SIGNAL( completed() ) ); + SIGNAL( completed() ) ); connect( retrieveTargzProc, SIGNAL( processExited() ), - SLOT( extractTarDone() ) ); + SLOT( extractTarDone() ) ); } @@ -1017,8 +1018,8 @@ void ServerDTP::connected() 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 ); } } @@ -1035,6 +1036,6 @@ void ServerDTP::connected() 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: @@ -1090,34 +1091,34 @@ 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(); } @@ -1132,16 +1133,16 @@ void ServerDTP::bytesWritten( int bytes ) 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 ); + } } @@ -1149,9 +1150,9 @@ void ServerDTP::bytesWritten( int bytes ) 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; + } } } @@ -1161,25 +1162,25 @@ 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() ); } } @@ -1191,9 +1192,9 @@ void ServerDTP::writeTargzBlock() 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() ) ); } } @@ -1203,5 +1204,5 @@ void ServerDTP::targzDone() //qDebug("targz done"); disconnect( createTargzProc, SIGNAL( readyReadStdout() ), - this, SLOT( gzipTarBlock() ) ); + this, SLOT( gzipTarBlock() ) ); gzipProc->closeStdin(); } @@ -1211,6 +1212,6 @@ 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() ); @@ -1231,6 +1232,6 @@ 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 ); @@ -1239,5 +1240,5 @@ void ServerDTP::sendGzipFile( const QString &fn, void ServerDTP::sendGzipFile( const QString &fn, - const QStringList &archiveTargets ) + const QStringList &archiveTargets ) { mode = SendGzipFile; @@ -1250,9 +1251,9 @@ void ServerDTP::sendGzipFile( const QString &fn, 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() ) ); } @@ -1261,8 +1262,8 @@ 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() ) ); } @@ -1271,7 +1272,7 @@ 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() ); @@ -1298,9 +1299,9 @@ void ServerDTP::retrieveGzipFile( const QString &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() ) ); } |