summaryrefslogtreecommitdiff
path: root/core/launcher
authorllornkcor <llornkcor>2002-07-18 03:11:17 (UTC)
committer llornkcor <llornkcor>2002-07-18 03:11:17 (UTC)
commit7fba4ce72b9201e3a04214c75a1031958090a618 (patch) (side-by-side diff)
tree77f7ea331fd38707f3c74dc5a67b47940ea36038 /core/launcher
parent786393948f3cd5f67a48f44a7a40422636f4b46e (diff)
downloadopie-7fba4ce72b9201e3a04214c75a1031958090a618.zip
opie-7fba4ce72b9201e3a04214c75a1031958090a618.tar.gz
opie-7fba4ce72b9201e3a04214c75a1031958090a618.tar.bz2
attempt for change ip back to hex range from string
Diffstat (limited to 'core/launcher') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/transferserver.cpp803
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
@@ -65,3 +65,3 @@ 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 );
}
@@ -84,5 +84,5 @@ QString SyncAuthentication::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()));
}
@@ -96,5 +96,5 @@ QString SyncAuthentication::ownerName()
if (QFile::exists(vfilename)) {
- Contact c;
- c = Contact::readVCard( vfilename )[0];
- return c.fullName();
+ Contact c;
+ c = Contact::readVCard( vfilename )[0];
+ return c.fullName();
}
@@ -115,9 +115,11 @@ int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
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;
@@ -145,3 +147,3 @@ bool SyncAuthentication::checkPassword( const QString& password )
if ( cpwd == "x" && spw )
- cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
+ cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
@@ -150,3 +152,3 @@ bool SyncAuthentication::checkPassword( const QString& password )
if ( cpwd == cpassword )
- return TRUE;
+ return TRUE;
#endif
@@ -159,12 +161,12 @@ bool SyncAuthentication::checkPassword( const QString& 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;
}
@@ -173,25 +175,25 @@ bool SyncAuthentication::checkPassword( const QString& 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;
+ }
}
@@ -201,3 +203,2 @@ bool SyncAuthentication::checkPassword( const QString& password )
-
ServerPI::ServerPI( int socket, QObject *parent , const char* name )
@@ -214,33 +215,33 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name )
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 ) ) );
}
@@ -269,3 +270,3 @@ void ServerPI::read()
while ( canReadLine() )
- process( readLine().stripWhiteSpace() );
+ process( readLine().stripWhiteSpace() );
}
@@ -277,5 +278,5 @@ bool ServerPI::checkReadFile( const QString& file )
if ( file[0] != "/" )
- filename = directory.path() + "/" + file;
+ filename = directory.path() + "/" + file;
else
- filename = file;
+ filename = file;
@@ -290,5 +291,5 @@ bool ServerPI::checkWriteFile( const QString& file )
if ( file[0] != "/" )
- filename = directory.path() + "/" + file;
+ filename = directory.path() + "/" + file;
else
- filename = file;
+ filename = file;
@@ -297,4 +298,4 @@ bool ServerPI::checkWriteFile( const QString& file )
if ( fi.exists() )
- if ( !QFile( filename ).remove() )
- return FALSE;
+ if ( !QFile( filename ).remove() )
+ return FALSE;
return TRUE;
@@ -316,3 +317,3 @@ void ServerPI::process( const QString& message )
if ( msg.count() >= 2 )
- arg = msg[1];
+ arg = msg[1];
@@ -332,5 +333,5 @@ void ServerPI::process( const QString& message )
if ( cmd == "QUIT" ) {
- send( "211 Good bye!" );
- delete this;
- return;
+ send( "211 Good bye!" );
+ delete this;
+ return;
}
@@ -339,3 +340,3 @@ void ServerPI::process( const QString& message )
if ( Connected == state )
- return;
+ return;
@@ -344,9 +345,9 @@ void ServerPI::process( const QString& message )
- 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;
}
@@ -356,9 +357,9 @@ void ServerPI::process( const QString& message )
- 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;
}
@@ -370,4 +371,4 @@ void ServerPI::process( const QString& message )
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" );
}
@@ -377,10 +378,10 @@ void ServerPI::process( const QString& message )
- 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" );
}
@@ -389,6 +390,6 @@ void ServerPI::process( const QString& message )
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" );
}
@@ -397,4 +398,4 @@ void ServerPI::process( const QString& message )
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" );
}
@@ -403,4 +404,4 @@ void ServerPI::process( const QString& message )
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" );
}
@@ -413,6 +414,6 @@ void ServerPI::process( const QString& message )
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" );
}
@@ -421,7 +422,7 @@ void ServerPI::process( const QString& message )
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 ) +")" );
}
@@ -430,6 +431,6 @@ void ServerPI::process( const QString& message )
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" );
}
@@ -438,6 +439,6 @@ void ServerPI::process( const QString& message )
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" );
}
@@ -446,6 +447,6 @@ void ServerPI::process( const QString& message )
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" );
}
@@ -458,11 +459,11 @@ void ServerPI::process( const QString& message )
else if ( cmd == "RETR" )
- if ( !args.isEmpty() && checkReadFile( absFilePath( args ) )
- || backupRestoreGzip( absFilePath( args ) ) ) {
- send( "150 File status okay" );
- 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" );
+ }
@@ -470,8 +471,8 @@ void ServerPI::process( const QString& message )
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" );
@@ -479,3 +480,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "STOU" ) {
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" );
}
@@ -484,3 +485,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "APPE" ) {
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" );
}
@@ -489,3 +490,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "ALLO" ) {
- send( "200 Command okay" );
+ send( "200 Command okay" );
}
@@ -494,3 +495,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "REST" ) {
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" );
}
@@ -499,14 +500,14 @@ void ServerPI::process( const QString& message )
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" );
+ }
}
@@ -515,13 +516,13 @@ void ServerPI::process( const QString& message )
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" );
+ }
}
@@ -530,7 +531,7 @@ void ServerPI::process( const QString& message )
else if ( cmd.contains( "ABOR" ) ) {
- dtp->close();
- if ( dtp->dtpMode() != ServerDTP::Idle )
- send( "426 Connection closed; transfer aborted" );
- 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" );
}
@@ -539,14 +540,14 @@ void ServerPI::process( const QString& message )
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" );
+ }
+ }
}
@@ -555,11 +556,11 @@ void ServerPI::process( const QString& message )
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" );
+ }
}
@@ -568,13 +569,13 @@ void ServerPI::process( const QString& message )
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" );
+ }
}
@@ -583,3 +584,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "PWD" ) {
- send( "257 \"" + directory.path() +"\"" );
+ send( "257 \"" + directory.path() +"\"" );
}
@@ -588,6 +589,6 @@ void ServerPI::process( const QString& message )
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" );
}
@@ -596,28 +597,28 @@ void ServerPI::process( const QString& message )
else if ( cmd == "SIZE" ) {
- QString filePath = absFilePath( args );
- QFileInfo fi( filePath );
- bool gzipfile = backupRestoreGzip( filePath );
- if ( !fi.exists() && !gzipfile )
- send( "500 Syntax error, command unrecognized" );
- 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) );
+ }
+ }
+ }
}
@@ -625,3 +626,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "NLST" ) {
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" );
}
@@ -630,3 +631,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "SITE" ) {
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" );
}
@@ -635,3 +636,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "SYST" ) {
- send( "215 UNIX Type: L8" );
+ send( "215 UNIX Type: L8" );
}
@@ -640,3 +641,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "STAT" ) {
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" );
}
@@ -645,3 +646,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "HELP" ) {
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" );
}
@@ -650,3 +651,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "NOOP" ) {
- send( "200 Command okay" );
+ send( "200 Command okay" );
}
@@ -655,3 +656,3 @@ void ServerPI::process( const QString& message )
else
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" );
@@ -663,3 +664,3 @@ 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 );
}
@@ -673,3 +674,3 @@ bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets )
qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(),
- targets.join(" ").latin1() );
+ targets.join(" ").latin1() );
return true;
@@ -682,6 +683,6 @@ void ServerPI::sendFile( const QString& file )
if ( passiv ) {
- wait[SendFile] = TRUE;
- waitfile = file;
- if ( waitsocket )
- newConnection( waitsocket );
+ wait[SendFile] = TRUE;
+ waitfile = file;
+ if ( waitsocket )
+ newConnection( waitsocket );
}
@@ -690,3 +691,3 @@ void ServerPI::sendFile( const QString& file )
if ( backupRestoreGzip( file, targets ) )
- dtp->sendGzipFile( file, targets, peeraddress, peerport );
+ dtp->sendGzipFile( file, targets, peeraddress, peerport );
else dtp->sendFile( file, peeraddress, peerport );
@@ -698,6 +699,6 @@ void ServerPI::retrieveFile( const QString& file )
if ( passiv ) {
- wait[RetrieveFile] = TRUE;
- waitfile = file;
- if ( waitsocket )
- newConnection( waitsocket );
+ wait[RetrieveFile] = TRUE;
+ waitfile = file;
+ if ( waitsocket )
+ newConnection( waitsocket );
}
@@ -706,5 +707,5 @@ void ServerPI::retrieveFile( const QString& file )
if ( backupRestoreGzip( file, targets ) )
- dtp->retrieveGzipFile( file, peeraddress, peerport );
+ dtp->retrieveGzipFile( file, peeraddress, peerport );
else
- dtp->retrieveFile( file, peeraddress, peerport );
+ dtp->retrieveFile( file, peeraddress, peerport );
}
@@ -719,3 +720,3 @@ bool ServerPI::parsePort( const QString& pp )
peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) +
- ( p[2].toInt() << 8 ) + p[3].toInt() );
+ ( p[2].toInt() << 8 ) + p[3].toInt() );
peerport = ( p[4].toInt() << 8 ) + p[5].toInt();
@@ -728,7 +729,7 @@ void ServerPI::dtpCompleted()
if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) {
- QString fn = dtp->fileName();
- if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) {
- QCopEnvelope e("QPE/System", "linkChanged(QString)" );
- e << fn;
- }
+ QString fn = dtp->fileName();
+ if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) {
+ QCopEnvelope e("QPE/System", "linkChanged(QString)" );
+ e << fn;
+ }
}
@@ -758,3 +759,3 @@ bool ServerPI::sendList( const QString& arg )
if ( !buffer.open( IO_WriteOnly ) )
- return FALSE;
+ return FALSE;
@@ -764,3 +765,3 @@ bool ServerPI::sendList( const QString& arg )
if ( fn.isEmpty() )
- fn = directory.path();
+ fn = directory.path();
@@ -771,3 +772,3 @@ bool ServerPI::sendList( const QString& arg )
if ( fi.isFile() ) {
- ts << fileListing( &fi ) << endl;
+ ts << fileListing( &fi ) << endl;
}
@@ -776,26 +777,26 @@ bool ServerPI::sendList( const QString& arg )
else if ( fi.isDir() ) {
- QDir dir( fn );
- const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden );
+ QDir dir( fn );
+ const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden );
- QFileInfoListIterator it( *list );
- QFileInfo *info;
+ QFileInfoListIterator it( *list );
+ QFileInfo *info;
- unsigned long total = 0;
- while ( ( info = it.current() ) ) {
- if ( info->fileName() != "." && info->fileName() != ".." )
- total += info->size();
- ++it;
- }
+ unsigned long total = 0;
+ while ( ( info = it.current() ) ) {
+ if ( info->fileName() != "." && info->fileName() != ".." )
+ total += info->size();
+ ++it;
+ }
- ts << "total " << QString::number( total / 1024 ) << endl;
+ 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;
+ }
}
@@ -803,9 +804,9 @@ bool ServerPI::sendList( const QString& arg )
if ( passiv ) {
- waitarray = buffer.buffer();
- wait[SendByteArray] = TRUE;
- if ( waitsocket )
- newConnection( waitsocket );
+ waitarray = buffer.buffer();
+ wait[SendByteArray] = TRUE;
+ if ( waitsocket )
+ newConnection( waitsocket );
}
else
- dtp->sendByteArray( buffer.buffer(), peeraddress, peerport );
+ dtp->sendByteArray( buffer.buffer(), peeraddress, peerport );
return TRUE;
@@ -820,7 +821,7 @@ QString ServerPI::fileListing( QFileInfo *info )
if ( info->isDir() )
- s += "d";
+ s += "d";
else if ( info->isSymLink() )
- s += "l";
+ s += "l";
else
- s += "-";
+ s += "-";
@@ -833,3 +834,3 @@ QString ServerPI::fileListing( QFileInfo *info )
if ( info->isDir() )
- subdirs = 2;
+ subdirs = 2;
// FIXME : this is to slow
@@ -853,5 +854,5 @@ QString ServerPI::fileListing( QFileInfo *info )
s += date.monthName( date.month() ) + " "
- + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " "
- + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":"
- + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " ";
+ + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " "
+ + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":"
+ + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " ";
@@ -902,8 +903,8 @@ void ServerPI::newConnection( int socket )
if ( wait[SendFile] ) {
- QStringList targets;
- if ( backupRestoreGzip( waitfile, targets ) )
- dtp->sendGzipFile( waitfile, targets );
- else
- dtp->sendFile( waitfile );
- dtp->setSocket( socket );
+ QStringList targets;
+ if ( backupRestoreGzip( waitfile, targets ) )
+ dtp->sendGzipFile( waitfile, targets );
+ else
+ dtp->sendFile( waitfile );
+ dtp->setSocket( socket );
}
@@ -912,5 +913,5 @@ void ServerPI::newConnection( int socket )
if ( backupRestoreGzip( waitfile ) )
- dtp->retrieveGzipFile( waitfile );
+ dtp->retrieveGzipFile( waitfile );
else
- dtp->retrieveFile( waitfile );
+ dtp->retrieveFile( waitfile );
dtp->setSocket( socket );
@@ -918,15 +919,15 @@ void ServerPI::newConnection( int 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;
}
@@ -939,3 +940,3 @@ QString ServerPI::absFilePath( const QString& file )
if ( file[0] != "/" )
- filepath = directory.path() + "/" + file;
+ filepath = directory.path() + "/" + file;
@@ -975,5 +976,5 @@ retrieveTargzProc( 0 ), gzipProc( 0 )
connect( retrieveTargzProc, SIGNAL( processExited() ),
- SIGNAL( completed() ) );
+ SIGNAL( completed() ) );
connect( retrieveTargzProc, SIGNAL( processExited() ),
- SLOT( extractTarDone() ) );
+ SLOT( extractTarDone() ) );
}
@@ -1018,6 +1019,6 @@ 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 );
}
@@ -1036,4 +1037,4 @@ void ServerDTP::connected()
qWarning("Error starting %s or %s",
- createTargzProc->arguments().join(" ").latin1(),
- gzipProc->arguments().join(" ").latin1() );
+ createTargzProc->arguments().join(" ").latin1(),
+ gzipProc->arguments().join(" ").latin1() );
break;
@@ -1091,6 +1092,6 @@ void ServerDTP::connectionClosed()
if ( SendFile == mode ) {
- if ( bytes_written == file.size() )
- emit completed();
- else
- emit failed();
+ if ( bytes_written == file.size() )
+ emit completed();
+ else
+ emit failed();
}
@@ -1099,6 +1100,6 @@ void ServerDTP::connectionClosed()
else if ( SendBuffer == mode ) {
- if ( bytes_written == buf.size() )
- emit completed();
- else
- emit failed();
+ if ( bytes_written == buf.size() )
+ emit completed();
+ else
+ emit failed();
}
@@ -1107,4 +1108,4 @@ void ServerDTP::connectionClosed()
else if ( RetrieveFile == mode ) {
- file.close();
- emit completed();
+ file.close();
+ emit completed();
}
@@ -1112,5 +1113,5 @@ void ServerDTP::connectionClosed()
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();
}
@@ -1119,4 +1120,4 @@ void ServerDTP::connectionClosed()
else if ( RetrieveBuffer == mode ) {
- buf.close();
- emit completed();
+ buf.close();
+ emit completed();
}
@@ -1133,14 +1134,14 @@ void ServerDTP::bytesWritten( int 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 );
- }
+ 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 );
+ }
}
@@ -1150,7 +1151,7 @@ void ServerDTP::bytesWritten( int bytes )
- 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;
+ }
}
@@ -1162,16 +1163,16 @@ void ServerDTP::readyRead()
if ( RetrieveFile == mode ) {
- QCString s;
- s.resize( bytesAvailable() );
- readBlock( s.data(), bytesAvailable() );
- file.writeBlock( s.data(), s.size() );
+ QCString s;
+ s.resize( bytesAvailable() );
+ readBlock( s.data(), bytesAvailable() );
+ file.writeBlock( s.data(), s.size() );
}
else if ( RetrieveGzipFile == mode ) {
- if ( !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() );
}
@@ -1179,6 +1180,6 @@ void ServerDTP::readyRead()
else if ( RetrieveBuffer == mode ) {
- QCString s;
- s.resize( bytesAvailable() );
- readBlock( s.data(), bytesAvailable() );
- buf.writeBlock( s.data(), s.size() );
+ QCString s;
+ s.resize( bytesAvailable() );
+ readBlock( s.data(), bytesAvailable() );
+ buf.writeBlock( s.data(), s.size() );
}
@@ -1192,7 +1193,7 @@ void ServerDTP::writeTargzBlock()
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() ) );
}
@@ -1204,3 +1205,3 @@ void ServerDTP::targzDone()
disconnect( createTargzProc, SIGNAL( readyReadStdout() ),
- this, SLOT( gzipTarBlock() ) );
+ this, SLOT( gzipTarBlock() ) );
gzipProc->closeStdin();
@@ -1212,4 +1213,4 @@ void ServerDTP::gzipTarBlock()
if ( !gzipProc->isRunning() ) {
- //qDebug("auto start gzip proc");
- gzipProc->start();
+ //qDebug("auto start gzip proc");
+ gzipProc->start();
}
@@ -1232,4 +1233,4 @@ void ServerDTP::sendFile( const QString fn )
void ServerDTP::sendGzipFile( const QString &fn,
- const QStringList &archiveTargets,
- const QHostAddress& host, Q_UINT16 port )
+ const QStringList &archiveTargets,
+ const QHostAddress& host, Q_UINT16 port )
{
@@ -1240,3 +1241,3 @@ void ServerDTP::sendGzipFile( const QString &fn,
void ServerDTP::sendGzipFile( const QString &fn,
- const QStringList &archiveTargets )
+ const QStringList &archiveTargets )
{
@@ -1251,7 +1252,7 @@ void ServerDTP::sendGzipFile( const QString &fn,
connect( createTargzProc,
- SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) );
+ SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) );
- gzipProc->setArguments( "gzip" );
+ gzipProc->setArguments( "gzip" );
connect( gzipProc, SIGNAL( readyReadStdout() ),
- SLOT( writeTargzBlock() ) );
+ SLOT( writeTargzBlock() ) );
}
@@ -1262,6 +1263,6 @@ void ServerDTP::gunzipDone()
disconnect( gzipProc, SIGNAL( processExited() ),
- this, SLOT( gunzipDone() ) );
+ this, SLOT( gunzipDone() ) );
retrieveTargzProc->closeStdin();
disconnect( gzipProc, SIGNAL( readyReadStdout() ),
- this, SLOT( tarExtractBlock() ) );
+ this, SLOT( tarExtractBlock() ) );
}
@@ -1272,5 +1273,5 @@ void ServerDTP::tarExtractBlock()
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");
}
@@ -1299,7 +1300,7 @@ void ServerDTP::retrieveGzipFile( const QString &fn )
- gzipProc->setArguments( "gunzip" );
+ gzipProc->setArguments( "gunzip" );
connect( gzipProc, SIGNAL( readyReadStdout() ),
- SLOT( tarExtractBlock() ) );
+ SLOT( tarExtractBlock() ) );
connect( gzipProc, SIGNAL( processExited() ),
- SLOT( gunzipDone() ) );
+ SLOT( gunzipDone() ) );
}