summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/launcher/transferserver.cpp595
1 files changed, 293 insertions, 302 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index 0337a94..371400e 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -19,3 +19,8 @@
**********************************************************************/
-#define _XOPEN_SOURCE
+//#define _XOPEN_SOURCE
+
+#include <qtopia/global.h>
+#include <qtopia/qpeapplication.h>
+
+#ifndef Q_OS_WIN32
#include <pwd.h>
@@ -26,15 +31,9 @@
#include <shadow.h>
+#include <crypt.h>
-/* we need the _OS_LINUX stuff first ! */
-#include <qglobal.h>
-
-#ifndef _OS_LINUX_
-
-extern "C"
-{
-#include <uuid/uuid.h>
-#define UUID_H_INCLUDED
-}
+#else
+#include <stdlib.h>
+#include <time.h>
+#endif
-#endif // not defined linux
@@ -52,13 +51,17 @@ extern "C"
#include <qregexp.h>
-//#include <qpe/qcopchannel_qws.h>
-#include <qpe/process.h>
-#include <qpe/global.h>
-#include <qpe/config.h>
-#include <qpe/contact.h>
-#include <qpe/quuid.h>
-#include <qpe/version.h>
-#include <qpe/qcopenvelope_qws.h>
+//#include <qtopia/qcopchannel_qws.h>
+#include <qtopia/process.h>
+#include <qtopia/global.h>
+#include <qtopia/config.h>
+#include <qtopia/private/contact.h>
+#include <qtopia/quuid.h>
+#include <qtopia/version.h>
+#ifdef Q_WS_QWS
+#include <qtopia/qcopenvelope_qws.h>
+#endif
+
+#include "launcherglobal.h"
#include "transferserver.h"
-#include <opie/oprocess.h>
+#include <qtopia/qprocess.h>
@@ -70,2 +73,3 @@ TransferServer::TransferServer( Q_UINT16 port, QObject *parent ,
{
+ connections.setAutoDelete( TRUE );
if ( !ok() )
@@ -74,45 +78,28 @@ TransferServer::TransferServer( Q_UINT16 port, QObject *parent ,
-TransferServer::~TransferServer()
+void TransferServer::authorizeConnections()
{
+ QListIterator<ServerPI> it(connections);
+ while ( it.current() ) {
+ if ( !it.current()->verifyAuthorised() ) {
+ disconnect( it.current(), SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) );
+ connections.removeRef( it.current() );
+ } else
+ ++it;
}
-
-void TransferServer::newConnection( int socket )
-{
- (void) new ServerPI( socket, this );
}
-/*
- * small class in anonymous namespace
- * to generate a QUUid for us
- */
-namespace
-{
-struct UidGen
+void TransferServer::closed(ServerPI *item)
{
- QString uuid();
-};
-#if !defined(_OS_LINUX_)
+ connections.removeRef(item);
+}
-QString UidGen::uuid()
+TransferServer::~TransferServer()
{
- uuid_t uuid;
- uuid_generate( uuid );
- return QUUid( uuid ).toString();
}
-#else
-/*
-* linux got a /proc/sys/kernel/random/uuid file
-* it'll generate the uuids for us
-*/
-QString UidGen::uuid()
-{
- QFile file( "/proc/sys/kernel/random/uuid" );
- if (!file.open(IO_ReadOnly ) )
- return QString::null;
-
- QTextStream stream(&file);
- return "{" + stream.read().stripWhiteSpace() + "}";
-}
-#endif
+void TransferServer::newConnection( int socket )
+{
+ ServerPI *ptr = new ServerPI( socket, this );
+ connect( ptr, SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) );
+ connections.append( ptr );
}
@@ -124,5 +111,5 @@ QString SyncAuthentication::serverId()
QString r = cfg.readEntry("serverid");
+
if ( r.isEmpty() ) {
- UidGen gen;
- r = gen.uuid();
+ r = Opie::Global::uuid();
cfg.writeEntry("serverid", r );
@@ -142,3 +129,3 @@ QString SyncAuthentication::ownerName()
- return "";
+ return QString::null;
}
@@ -147,5 +134,10 @@ QString SyncAuthentication::loginName()
{
- struct passwd *pw;
+ struct passwd *pw = 0L;
+#ifndef Q_OS_WIN32
pw = getpwuid( geteuid() );
return QString::fromLocal8Bit( pw->pw_name );
+#else
+ //### revise
+ return QString();
+#endif
}
@@ -165,2 +157,3 @@ int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits));
+
return (peeraddress.ip4Addr() & mask) == auth_peer;
@@ -170,4 +163,3 @@ bool SyncAuthentication::checkUser( const QString& user )
{
- if ( user.isEmpty() )
- return FALSE;
+ if ( user.isEmpty() ) return FALSE;
QString euser = loginName();
@@ -204,3 +196,4 @@ bool SyncAuthentication::checkPassword( const QString& password )
if ( denials < 1 || now > lastdenial + 600 ) {
- QMessageBox::warning( 0, tr("Sync Connection"),
+ QMessageBox unauth(
+ tr("Sync Connection"),
tr("<p>An unauthorized system is requesting access to this device."
@@ -208,3 +201,8 @@ bool SyncAuthentication::checkPassword( const QString& password )
"please upgrade."),
- tr("Deny") );
+ QMessageBox::Warning,
+ QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton,
+ 0, QString::null, TRUE, WStyle_StaysOnTop);
+ unauth.setButtonText(QMessageBox::Cancel, tr("Deny"));
+ unauth.exec();
+
denials++;
@@ -216,32 +214,59 @@ bool SyncAuthentication::checkPassword( const QString& password )
// Second, check sync password...
- QString pass = password.left(6);
- /* old QtopiaDesktops are sending
- * rootme newer versions got a Qtopia
- * prefixed. Qtopia prefix will suceed
- * until the sync software syncs up
- * FIXME
- */
- if ( pass == "rootme" || pass == "Qtopia") {
-
- QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) );
- Config cfg("Security");
+
+ static int lock=0;
+ if ( lock ) return FALSE;
+
+ ++lock;
+ if ( password.left(6) == "Qtopia" ) {
+ Config cfg( QPEApplication::qpeDir()+"/etc/Security.conf", Config::File );
cfg.setGroup("Sync");
- QString pwds = cfg.readEntry("Passwords");
- if ( QStringList::split(QChar(' '), pwds).contains(cpassword) )
+ QStringList pwds = cfg.readListEntry("Passwords",' ');
+ for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) {
+#ifndef Q_OS_WIN32
+ QString cpassword = QString::fromLocal8Bit(
+ crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) );
+#else
+ // ### revise
+ QString cpassword("");
+#endif
+ if ( *it == cpassword ) {
+ lock--;
return TRUE;
+ }
+ }
// Unrecognized system. Be careful...
-
- if ( (denials > 2 && now < lastdenial + 600)
- || QMessageBox::warning(0, tr("Sync Connection"),
+ QMessageBox unrecbox(
+ tr("Sync Connection"),
tr("<p>An unrecognized system is requesting access to this device."
"<p>If you have just initiated a Sync for the first time, this is normal."),
- tr("Allow"), tr("Deny"), 0, 1, 1 ) == 1 ) {
+ QMessageBox::Warning,
+ QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton,
+ 0, QString::null, TRUE, WStyle_StaysOnTop);
+ unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny"));
+ unrecbox.setButtonText(QMessageBox::Yes, tr("Allow"));
+
+ if ( (denials > 2 && now < lastdenial+600)
+ || unrecbox.exec() != QMessageBox::Yes)
+ {
denials++;
lastdenial = now;
+ lock--;
return FALSE;
- }
- else {
+ } else {
+ const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/.";
+ char salt[2];
+ salt[0]= salty[rand() % (sizeof(salty)-1)];
+ salt[1]= salty[rand() % (sizeof(salty)-1)];
+#ifndef Q_OS_WIN32
+ QString cpassword = QString::fromLocal8Bit(
+ crypt( password.mid(8).local8Bit(), salt ) );
+#else
+ //### revise
+ QString cpassword("");
+#endif
denials = 0;
- cfg.writeEntry("Passwords", pwds + " " + cpassword);
+ pwds.prepend(cpassword);
+ cfg.writeEntry("Passwords",pwds,' ');
+ lock--;
return TRUE;
@@ -249,2 +274,3 @@ bool SyncAuthentication::checkPassword( const QString& password )
}
+ lock--;
@@ -253,4 +279,6 @@ bool SyncAuthentication::checkPassword( const QString& password )
+
ServerPI::ServerPI( int socket, QObject *parent , const char* name )
- : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 )
+ : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ),
+ storFileSize(-1)
{
@@ -264,3 +292,2 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name )
#ifndef INSECURE
-
if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
@@ -268,4 +295,3 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name )
startTimer( 0 );
- }
- else
+ } else
#endif
@@ -279,3 +305,3 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name )
- send( "220 Qtopia " QPE_VERSION " FTP Server" );
+ send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr
state = Wait_USER;
@@ -303,2 +329,15 @@ ServerPI::~ServerPI()
{
+ close();
+ dtp->close();
+ delete dtp;
+ delete serversocket;
+}
+
+bool ServerPI::verifyAuthorised()
+{
+ if ( !SyncAuthentication::isAuthorized(peerAddress()) ) {
+ state = Forbidden;
+ return FALSE;
+ }
+ return TRUE;
}
@@ -308,3 +347,3 @@ void ServerPI::connectionClosed()
// qDebug( "Debug: Connection closed" );
- delete this;
+ emit connectionClosed(this);
}
@@ -360,4 +399,3 @@ void ServerPI::process( const QString& message )
QStringList msg = QStringList::split( " ", message );
- if ( msg.isEmpty() )
- return ;
+ if ( msg.isEmpty() ) return;
@@ -385,4 +423,4 @@ void ServerPI::process( const QString& message )
if ( cmd == "QUIT" ) {
- send( "211 Good bye!" );
- delete this;
+ send( "211 Good bye!" ); // No tr
+ close();
return ;
@@ -398,6 +436,6 @@ void ServerPI::process( const QString& message )
if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
- send( "530 Please login with USER and PASS" );
+ send( "530 Please login with USER and PASS" ); // No tr
return ;
}
- send( "331 User name ok, need password" );
+ send( "331 User name ok, need password" ); // No tr
state = Wait_PASS;
@@ -410,6 +448,6 @@ void ServerPI::process( const QString& message )
if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
- send( "530 Please login with USER and PASS" );
+ send( "530 Please login with USER and PASS" ); // No tr
return ;
}
- send( "230 User logged in, proceed" );
+ send( "230 User logged in, proceed" ); // No tr
state = Ready;
@@ -420,2 +458,5 @@ void ServerPI::process( const QString& message )
+ // Only an ALLO sent immediately before STOR is valid.
+ if ( cmd != "STOR" )
+ storFileSize = -1;
@@ -424,3 +465,3 @@ void ServerPI::process( const QString& message )
// even wu-ftp does not support it
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" ); // No tr
}
@@ -432,8 +473,8 @@ void ServerPI::process( const QString& message )
if ( directory.cd( args, TRUE ) )
- send( "250 Requested file action okay, completed" );
+ send( "250 Requested file action okay, completed" ); // No tr
else
- send( "550 Requested action not taken" );
+ send( "550 Requested action not taken" ); // No tr
}
else
- send( "500 Syntax error, command unrecognized" );
+ send( "500 Syntax error, command unrecognized" ); // No tr
}
@@ -443,5 +484,5 @@ void ServerPI::process( const QString& message )
if ( directory.cdUp() )
- send( "250 Requested file action okay, completed" );
+ send( "250 Requested file action okay, completed" ); // No tr
else
- send( "550 Requested action not taken" );
+ send( "550 Requested action not taken" ); // No tr
}
@@ -451,3 +492,3 @@ void ServerPI::process( const QString& message )
// even wu-ftp does not support it
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" ); // No tr
}
@@ -457,3 +498,3 @@ void ServerPI::process( const QString& message )
// even wu-ftp does not support it
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" ); // No tr
}
@@ -467,5 +508,5 @@ void ServerPI::process( const QString& message )
if ( parsePort( arg ) )
- send( "200 Command okay" );
+ send( "200 Command okay" ); // No tr
else
- send( "500 Syntax error, command unrecognized" );
+ send( "500 Syntax error, command unrecognized" ); // No tr
}
@@ -475,3 +516,3 @@ void ServerPI::process( const QString& message )
passiv = TRUE;
- send( "227 Entering Passive Mode ("
+ send( "227 Entering Passive Mode (" // No tr
+ address().toString().replace( QRegExp( "\\." ), "," ) + ","
@@ -484,5 +525,5 @@ void ServerPI::process( const QString& message )
if ( arg.upper() == "A" || arg.upper() == "I" )
- send( "200 Command okay" );
+ send( "200 Command okay" ); // No tr
else
- send( "504 Command not implemented for that parameter" );
+ send( "504 Command not implemented for that parameter" ); // No tr
}
@@ -492,5 +533,5 @@ void ServerPI::process( const QString& message )
if ( arg.upper() == "F" )
- send( "200 Command okay" );
+ send( "200 Command okay" ); // No tr
else
- send( "504 Command not implemented for that parameter" );
+ send( "504 Command not implemented for that parameter" ); // No tr
}
@@ -500,5 +541,5 @@ void ServerPI::process( const QString& message )
if ( arg.upper() == "S" )
- send( "200 Command okay" );
+ send( "200 Command okay" ); // No tr
else
- send( "504 Command not implemented for that parameter" );
+ send( "504 Command not implemented for that parameter" ); // No tr
}
@@ -513,3 +554,3 @@ void ServerPI::process( const QString& message )
|| backupRestoreGzip( absFilePath( args ) ) ) {
- send( "150 File status okay" );
+ send( "150 File status okay" ); // No tr
sendFile( absFilePath( args ) );
@@ -518,3 +559,3 @@ void ServerPI::process( const QString& message )
qDebug("550 Requested action not taken");
- send( "550 Requested action not taken" );
+ send( "550 Requested action not taken" ); // No tr
}
@@ -524,3 +565,3 @@ void ServerPI::process( const QString& message )
if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) {
- send( "150 File status okay" );
+ send( "150 File status okay" ); // No tr
retrieveFile( absFilePath( args ) );
@@ -528,3 +569,3 @@ void ServerPI::process( const QString& message )
else
- send( "550 Requested action not taken" );
+ send( "550 Requested action not taken" ); // No tr
@@ -532,3 +573,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "STOU" ) {
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" ); // No tr
}
@@ -537,3 +578,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "APPE" ) {
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" ); // No tr
}
@@ -542,3 +583,4 @@ void ServerPI::process( const QString& message )
else if ( cmd == "ALLO" ) {
- send( "200 Command okay" );
+ storFileSize = args.toInt();
+ send( "200 Command okay" ); // No tr
}
@@ -547,3 +589,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "REST" ) {
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" ); // No tr
}
@@ -554,3 +596,3 @@ void ServerPI::process( const QString& message )
if ( args.isEmpty() )
- send( "500 Syntax error, command unrecognized" );
+ send( "500 Syntax error, command unrecognized" ); // No tr
else {
@@ -558,3 +600,3 @@ void ServerPI::process( const QString& message )
if ( file.exists() ) {
- send( "350 File exists, ready for destination name" );
+ send( "350 File exists, ready for destination name" ); // No tr
renameFrom = absFilePath( args );
@@ -562,3 +604,3 @@ void ServerPI::process( const QString& message )
else
- send( "550 Requested action not taken" );
+ send( "550 Requested action not taken" ); // No tr
}
@@ -569,5 +611,5 @@ void ServerPI::process( const QString& message )
if ( lastCommand != "RNFR" )
- send( "503 Bad sequence of commands" );
+ send( "503 Bad sequence of commands" ); // No tr
else if ( args.isEmpty() )
- send( "500 Syntax error, command unrecognized" );
+ send( "500 Syntax error, command unrecognized" ); // No tr
else {
@@ -575,5 +617,5 @@ void ServerPI::process( const QString& message )
if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) )
- send( "250 Requested file action okay, completed." );
+ send( "250 Requested file action okay, completed." ); // No tr
else
- send( "550 Requested action not taken" );
+ send( "550 Requested action not taken" ); // No tr
}
@@ -585,5 +627,5 @@ void ServerPI::process( const QString& message )
if ( dtp->dtpMode() != ServerDTP::Idle )
- send( "426 Connection closed; transfer aborted" );
+ send( "426 Connection closed; transfer aborted" ); // No tr
else
- send( "226 Closing data connection" );
+ send( "226 Closing data connection" ); // No tr
}
@@ -593,3 +635,3 @@ void ServerPI::process( const QString& message )
if ( args.isEmpty() )
- send( "500 Syntax error, command unrecognized" );
+ send( "500 Syntax error, command unrecognized" ); // No tr
else {
@@ -597,8 +639,7 @@ void ServerPI::process( const QString& message )
if ( file.remove() ) {
- send( "250 Requested file action okay, completed" );
+ send( "250 Requested file action okay, completed" ); // No tr
QCopEnvelope e("QPE/System", "linkChanged(QString)" );
e << file.name();
- }
- else {
- send( "550 Requested action not taken" );
+ } else {
+ send( "550 Requested action not taken" ); // No tr
}
@@ -610,3 +651,3 @@ void ServerPI::process( const QString& message )
if ( args.isEmpty() )
- send( "500 Syntax error, command unrecognized" );
+ send( "500 Syntax error, command unrecognized" ); // No tr
else {
@@ -614,5 +655,5 @@ void ServerPI::process( const QString& message )
if ( dir.rmdir( absFilePath( args ), TRUE ) )
- send( "250 Requested file action okay, completed" );
+ send( "250 Requested file action okay, completed" ); // No tr
else
- send( "550 Requested action not taken" );
+ send( "550 Requested action not taken" ); // No tr
}
@@ -624,3 +665,3 @@ void ServerPI::process( const QString& message )
qDebug(" Error: no arg");
- send( "500 Syntax error, command unrecognized" );
+ send( "500 Syntax error, command unrecognized" ); // No tr
}
@@ -629,5 +670,5 @@ void ServerPI::process( const QString& message )
if ( dir.mkdir( absFilePath( args ), TRUE ) )
- send( "250 Requested file action okay, completed." );
+ send( "250 Requested file action okay, completed." ); // No tr
else
- send( "550 Requested action not taken" );
+ send( "550 Requested action not taken" ); // No tr
}
@@ -643,5 +684,5 @@ void ServerPI::process( const QString& message )
if ( sendList( absFilePath( args ) ) )
- send( "150 File status okay" );
+ send( "150 File status okay" ); // No tr
else
- send( "500 Syntax error, command unrecognized" );
+ send( "500 Syntax error, command unrecognized" ); // No tr
}
@@ -654,3 +695,3 @@ void ServerPI::process( const QString& message )
if ( !fi.exists() && !gzipfile )
- send( "500 Syntax error, command unrecognized" );
+ send( "500 Syntax error, command unrecognized" ); // No tr
else {
@@ -669,3 +710,3 @@ void ServerPI::process( const QString& message )
int guess = size.toInt() / 5;
- if ( filePath.contains("doc") )
+ if ( filePath.contains("doc") ) // No tr
guess *= 1000;
@@ -679,3 +720,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "NLST" ) {
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" ); // No tr
}
@@ -684,3 +725,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "SITE" ) {
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" ); // No tr
}
@@ -689,3 +730,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "SYST" ) {
- send( "215 UNIX Type: L8" );
+ send( "215 UNIX Type: L8" ); // No tr
}
@@ -694,3 +735,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "STAT" ) {
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" ); // No tr
}
@@ -699,3 +740,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "HELP" ) {
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" ); // No tr
}
@@ -704,3 +745,3 @@ void ServerPI::process( const QString& message )
else if ( cmd == "NOOP" ) {
- send( "200 Command okay" );
+ send( "200 Command okay" ); // No tr
}
@@ -709,3 +750,3 @@ void ServerPI::process( const QString& message )
else
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" ); // No tr
@@ -716,3 +757,3 @@ bool ServerPI::backupRestoreGzip( const QString &file )
{
- return (file.find( "backup" ) != -1 &&
+ return (file.find( "backup" ) != -1 && // No tr
file.findRev( ".tgz" ) == (int)file.length() - 4 );
@@ -722,3 +763,3 @@ bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets )
{
- if ( file.find( "backup" ) != -1 &&
+ if ( file.find( "backup" ) != -1 && // No tr
file.findRev( ".tgz" ) == (int)file.length() - 4 ) {
@@ -745,4 +786,3 @@ void ServerPI::sendFile( const QString& file )
dtp->sendGzipFile( file, targets, peeraddress, peerport );
- else
- dtp->sendFile( file, peeraddress, peerport );
+ else dtp->sendFile( file, peeraddress, peerport );
}
@@ -763,3 +803,3 @@ void ServerPI::retrieveFile( const QString& file )
else
- dtp->retrieveFile( file, peeraddress, peerport );
+ dtp->retrieveFile( file, peeraddress, peerport, storFileSize );
}
@@ -770,4 +810,3 @@ bool ServerPI::parsePort( const QString& pp )
QStringList p = QStringList::split( ",", pp );
- if ( p.count() != 6 )
- return FALSE;
+ if ( p.count() != 6 ) return FALSE;
@@ -782,3 +821,3 @@ void ServerPI::dtpCompleted()
{
- send( "226 Closing data connection, file transfer successful" );
+ send( "226 Closing data connection, file transfer successful" ); // No tr
if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) {
@@ -792,2 +831,3 @@ void ServerPI::dtpCompleted()
dtp->close();
+ storFileSize = -1;
}
@@ -798,3 +838,4 @@ void ServerPI::dtpFailed()
waitsocket = 0;
- send( "451 Requested action aborted: local error in processing" );
+ send( "451 Requested action aborted: local error in processing" ); // No tr
+ storFileSize = -1;
}
@@ -805,3 +846,4 @@ void ServerPI::dtpError( int )
waitsocket = 0;
- send( "451 Requested action aborted: local error in processing" );
+ send( "451 Requested action aborted: local error in processing" ); // No tr
+ storFileSize = -1;
}
@@ -823,4 +865,3 @@ bool ServerPI::sendList( const QString& arg )
QFileInfo fi( fn );
- if ( !fi.exists() )
- return FALSE;
+ if ( !fi.exists() ) return FALSE;
@@ -846,3 +887,3 @@ bool ServerPI::sendList( const QString& arg )
- ts << "total " << QString::number( total / 1024 ) << endl;
+ ts << "total " << QString::number( total / 1024 ) << endl; // No tr
@@ -872,4 +913,3 @@ QString ServerPI::fileListing( QFileInfo *info )
{
- if ( !info )
- return QString::null;
+ if ( !info ) return QString::null;
QString s;
@@ -899,6 +939,12 @@ QString ServerPI::fileListing( QFileInfo *info )
// owner
- s += info->owner().leftJustify( 8, ' ', TRUE ) + " ";
+ QString o = info->owner();
+ if ( o.isEmpty() )
+ o = QString::number(info->ownerId());
+ s += o.leftJustify( 8, ' ', TRUE ) + " ";
// group
- s += info->group().leftJustify( 8, ' ', TRUE ) + " ";
+ QString g = info->group();
+ if ( g.isEmpty() )
+ g = QString::number(info->groupId());
+ s += g.leftJustify( 8, ' ', TRUE ) + " ";
@@ -923,4 +969,3 @@ QString ServerPI::permissionString( QFileInfo *info )
{
- if ( !info )
- return QString( "---------" );
+ if ( !info ) return QString( "---------" );
QString s;
@@ -928,42 +973,24 @@ QString ServerPI::permissionString( QFileInfo *info )
// user
- if ( info->permission( QFileInfo::ReadUser ) )
- s += "r";
- else
- s += "-";
- if ( info->permission( QFileInfo::WriteUser ) )
- s += "w";
- else
- s += "-";
- if ( info->permission( QFileInfo::ExeUser ) )
- s += "x";
- else
- s += "-";
+ if ( info->permission( QFileInfo::ReadUser ) ) s += "r";
+ else s += "-";
+ if ( info->permission( QFileInfo::WriteUser ) ) s += "w";
+ else s += "-";
+ if ( info->permission( QFileInfo::ExeUser ) ) s += "x";
+ else s += "-";
// group
- if ( info->permission( QFileInfo::ReadGroup ) )
- s += "r";
- else
- s += "-";
- if ( info->permission( QFileInfo::WriteGroup ) )
- s += "w";
- else
- s += "-";
- if ( info->permission( QFileInfo::ExeGroup ) )
- s += "x";
- else
- s += "-";
+ if ( info->permission( QFileInfo::ReadGroup ) ) s += "r";
+ else s += "-";
+ if ( info->permission( QFileInfo::WriteGroup ) )s += "w";
+ else s += "-";
+ if ( info->permission( QFileInfo::ExeGroup ) ) s += "x";
+ else s += "-";
// exec
- if ( info->permission( QFileInfo::ReadOther ) )
- s += "r";
- else
- s += "-";
- if ( info->permission( QFileInfo::WriteOther ) )
- s += "w";
- else
- s += "-";
- if ( info->permission( QFileInfo::ExeOther ) )
- s += "x";
- else
- s += "-";
+ if ( info->permission( QFileInfo::ReadOther ) ) s += "r";
+ else s += "-";
+ if ( info->permission( QFileInfo::WriteOther ) ) s += "w";
+ else s += "-";
+ if ( info->permission( QFileInfo::ExeOther ) ) s += "x";
+ else s += "-";
@@ -976,4 +1003,3 @@ void ServerPI::newConnection( int socket )
- if ( !passiv )
- return ;
+ if ( !passiv ) return;
@@ -992,3 +1018,3 @@ void ServerPI::newConnection( int socket )
else
- dtp->retrieveFile( waitfile );
+ dtp->retrieveFile( waitfile, storFileSize );
dtp->setSocket( socket );
@@ -1013,4 +1039,3 @@ QString ServerPI::absFilePath( const QString& file )
{
- if ( file.isEmpty() )
- return file;
+ if ( file.isEmpty() ) return file;
@@ -1032,3 +1057,3 @@ ServerDTP::ServerDTP( QObject *parent, const char* name)
: QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ),
- retrieveTargzProc( 0 ), gzipProc( 0 )
+ retrieveTargzProc( 0 )
{
@@ -1040,15 +1065,13 @@ ServerDTP::ServerDTP( QObject *parent, const char* name)
- gzipProc = new OProcess( this, "gzipProc" );
-
- createTargzProc = new OProcess( QString("tar"), this, "createTargzProc");
+ createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); // No tr
+ createTargzProc->setCommunication( QProcess::Stdout );
createTargzProc->setWorkingDirectory( QDir::rootDirPath() );
- connect( createTargzProc, SIGNAL( processExited(OProcess *) ), SLOT( targzDone() ) );
+ connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) );
- QStringList args = "tar";
- args += "-xv";
- retrieveTargzProc = new OProcess( args, this, "retrieveTargzProc" );
+ retrieveTargzProc = new QProcess( this, "retrieveTargzProc" );
+ retrieveTargzProc->setCommunication( QProcess::Stdin );
retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() );
- connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ),
+ connect( retrieveTargzProc, SIGNAL( processExited() ),
SIGNAL( completed() ) );
- connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ),
+ connect( retrieveTargzProc, SIGNAL( processExited() ),
SLOT( extractTarDone() ) );
@@ -1059,3 +1082,12 @@ ServerDTP::~ServerDTP()
buf.close();
+ if ( RetrieveFile == mode && file.isOpen() ) {
+ // We're being shutdown before the client closed.
+ file.close();
+ if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) {
+ qDebug( "STOR incomplete" );
+ file.remove();
+ }
+ } else {
file.close();
+ }
createTargzProc->kill();
@@ -1067,4 +1099,3 @@ void ServerDTP::extractTarDone()
#ifndef QT_NO_COP
-
- QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" );
+ QCopEnvelope e( "QPE/System", "restoreDone(QString)" );
e << file.name();
@@ -1092,6 +1123,5 @@ void ServerDTP::connected()
mode = Idle;
- }
- else {
-
- if ( !file.atEnd() ) {
+ } else {
+ // Don't write more if there is plenty buffered already.
+ if ( bytesToWrite() <= block_size && !file.atEnd() ) {
QCString s;
@@ -1112,6 +1142,5 @@ void ServerDTP::connected()
qDebug("==>start send tar process");
- if ( !createTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdout) )
- qWarning("Error starting %s or %s",
- createTargzProc->args()[0].data(),
- gzipProc->args()[0].data());
+ if ( !createTargzProc->start() )
+ qWarning("Error starting %s",
+ createTargzProc->arguments().join(" ").latin1());
break;
@@ -1186,4 +1215,10 @@ void ServerDTP::connectionClosed()
file.close();
+ if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) {
+ qDebug( "STOR incomplete" );
+ file.remove();
+ emit failed();
+ } else {
emit completed();
}
+ }
@@ -1191,4 +1226,4 @@ void ServerDTP::connectionClosed()
qDebug("Done writing ungzip file; closing input");
- gzipProc->flushStdin();
- gzipProc->closeStdin();
+ retrieveTargzProc->flushStdin();
+ retrieveTargzProc->closeStdin();
}
@@ -1246,4 +1281,4 @@ void ServerDTP::readyRead()
else if ( RetrieveGzipFile == mode ) {
- if ( !gzipProc->isRunning() )
- gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout ));
+ if ( !retrieveTargzProc->isRunning() )
+ retrieveTargzProc->start();
@@ -1252,3 +1287,3 @@ void ServerDTP::readyRead()
readBlock( s.data(), bytesAvailable() );
- gzipProc->writeStdin( s.data(), s.size() );
+ retrieveTargzProc->writeToStdin( s );
qDebug("wrote %d bytes to ungzip ", s.size() );
@@ -1264,13 +1299,7 @@ void ServerDTP::readyRead()
-void ServerDTP::writeTargzBlock(OProcess *, char *buffer, int buflen)
+void ServerDTP::writeTargzBlock()
{
- writeBlock( buffer, buflen );
- qDebug("writeTargzBlock %d", buflen);
- if ( !createTargzProc->isRunning() ) {
- qDebug("tar and gzip done");
- emit completed();
- mode = Idle;
- disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int ) ),
- this, SLOT( writeTargzBlock(OProcess *, char *, int) ) );
- }
+ QByteArray block = createTargzProc->readStdout();
+ writeBlock( block.data(), block.size() );
+ qDebug("writeTargzBlock %d", block.size());
}
@@ -1279,16 +1308,7 @@ void ServerDTP::targzDone()
{
- //qDebug("targz done");
- disconnect( createTargzProc, SIGNAL( receivedStdout(OProcess *, char *, int) ),
- this, SLOT( gzipTarBlock(OProcess *, char *, int) ) );
- gzipProc->closeStdin();
-}
-
-void ServerDTP::gzipTarBlock(OProcess *, char *buffer, int buflen)
-{
- //qDebug("gzipTarBlock");
- if ( !gzipProc->isRunning() ) {
- //qDebug("auto start gzip proc");
- gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout ));
- }
- gzipProc->writeStdin( buffer, buflen );
+ qDebug("tar and gzip done");
+ emit completed();
+ mode = Idle;
+ disconnect( createTargzProc, SIGNAL( readyReadStdout() ),
+ this, SLOT( writeTargzBlock() ) );
}
@@ -1322,41 +1342,14 @@ void ServerDTP::sendGzipFile( const QString &fn,
- QStringList args = "tar";
- args += "-cv";
+ QStringList args = "targzip";
+ //args += "-cv";
args += archiveTargets;
qDebug("sendGzipFile %s", args.join(" ").latin1() );
- createTargzProc->clearArguments( );
- *createTargzProc << args;
+ createTargzProc->setArguments( args );
connect( createTargzProc,
- SIGNAL( receivedStdout(OProcess *, char *, int) ), SLOT( gzipTarBlock(OProcess *, char *, int) ) );
-
- gzipProc->clearArguments( );
- *gzipProc << "gzip";
- connect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ),
- SLOT( writeTargzBlock(OProcess *, char *, int) ) );
+ SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) );
}
-void ServerDTP::gunzipDone()
-{
- qDebug("gunzipDone");
- disconnect( gzipProc, SIGNAL( processExited() ),
- this, SLOT( gunzipDone() ) );
- retrieveTargzProc->closeStdin();
- disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ),
- this, SLOT( tarExtractBlock(OProcess *, char *, int) ) );
-}
-
-void ServerDTP::tarExtractBlock(OProcess *, char *buffer, int buflen)
-{
- qDebug("tarExtractBlock");
- if ( !retrieveTargzProc->isRunning() ) {
- qDebug("auto start ungzip proc");
- if ( !retrieveTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdin) )
- qWarning(" failed to start tar -x process");
- }
- retrieveTargzProc->writeStdin( buffer, buflen );
-}
-
-
-void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port )
+void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize )
{
+ recvFileSize = fileSize;
file.setName( fn );
@@ -1366,4 +1359,5 @@ void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT
-void ServerDTP::retrieveFile( const QString fn )
+void ServerDTP::retrieveFile( const QString fn, int fileSize )
{
+ recvFileSize = fileSize;
file.setName( fn );
@@ -1378,8 +1372,5 @@ void ServerDTP::retrieveGzipFile( const QString &fn )
- gzipProc->clearArguments();
- *gzipProc << "gunzip";
- connect( gzipProc, SIGNAL( readyReadStdout() ),
- SLOT( tarExtractBlock() ) );
- connect( gzipProc, SIGNAL( processExited() ),
- SLOT( gunzipDone() ) );
+ retrieveTargzProc->setArguments( "targunzip" );
+ connect( retrieveTargzProc, SIGNAL( processExited() ),
+ SLOT( extractTarDone() ) );
}