Diffstat (limited to 'core/launcher/transferserver.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/launcher/transferserver.cpp | 191 |
1 files changed, 113 insertions, 78 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp index cbda247..0337a94 100644 --- a/core/launcher/transferserver.cpp +++ b/core/launcher/transferserver.cpp @@ -30,7 +30,8 @@ #ifndef _OS_LINUX_ -extern "C" { +extern "C" +{ #include <uuid/uuid.h> #define UUID_H_INCLUDED } @@ -59,7 +60,7 @@ extern "C" { #include <qpe/qcopenvelope_qws.h> #include "transferserver.h" -#include "qprocess.h" +#include <opie/oprocess.h> const int block_size = 51200; @@ -73,7 +74,6 @@ TransferServer::TransferServer( Q_UINT16 port, QObject *parent , TransferServer::~TransferServer() { - } void TransferServer::newConnection( int socket ) @@ -85,12 +85,16 @@ void TransferServer::newConnection( int socket ) * small class in anonymous namespace * to generate a QUUid for us */ -namespace { - struct UidGen { +namespace +{ +struct UidGen +{ QString uuid(); }; #if !defined(_OS_LINUX_) - QString UidGen::uuid() { + +QString UidGen::uuid() +{ uuid_t uuid; uuid_generate( uuid ); return QUUid( uuid ).toString(); @@ -100,7 +104,8 @@ namespace { * linux got a /proc/sys/kernel/random/uuid file * it'll generate the uuids for us */ - QString UidGen::uuid() { +QString UidGen::uuid() +{ QFile file( "/proc/sys/kernel/random/uuid" ); if (!file.open(IO_ReadOnly ) ) return QString::null; @@ -163,7 +168,8 @@ int SyncAuthentication::isAuthorized(QHostAddress peeraddress) bool SyncAuthentication::checkUser( const QString& user ) { - if ( user.isEmpty() ) return FALSE; + if ( user.isEmpty() ) + return FALSE; QString euser = loginName(); return user == euser; } @@ -230,12 +236,12 @@ bool SyncAuthentication::checkPassword( const QString& password ) || 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"), 0, 1, 1 ) ==1 ) - { + tr("Allow"), tr("Deny"), 0, 1, 1 ) == 1 ) { denials++; lastdenial=now; return FALSE; - } else { + } + else { denials=0; cfg.writeEntry("Passwords",pwds+" "+cpassword); return TRUE; @@ -256,10 +262,12 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name ) peeraddress = peerAddress(); #ifndef INSECURE + if ( !SyncAuthentication::isAuthorized(peeraddress) ) { state = Forbidden; startTimer( 0 ); - } else + } + else #endif { connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); @@ -293,7 +301,6 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name ) ServerPI::~ServerPI() { - } void ServerPI::connectionClosed() @@ -351,7 +358,8 @@ void ServerPI::process( const QString& message ) // split message using "," as separator QStringList msg = QStringList::split( " ", message ); - if ( msg.isEmpty() ) return; + if ( msg.isEmpty() ) + return ; // command token QString cmd = msg[0].upper(); @@ -590,7 +598,8 @@ void ServerPI::process( const QString& message ) send( "250 Requested file action okay, completed" ); QCopEnvelope e("QPE/System", "linkChanged(QString)" ); e << file.name(); - } else { + } + else { send( "550 Requested action not taken" ); } } @@ -734,7 +743,8 @@ void ServerPI::sendFile( const QString& file ) QStringList targets; if ( backupRestoreGzip( file, targets ) ) dtp->sendGzipFile( file, targets, peeraddress, peerport ); - else dtp->sendFile( file, peeraddress, peerport ); + else + dtp->sendFile( file, peeraddress, peerport ); } } @@ -758,7 +768,8 @@ void ServerPI::retrieveFile( const QString& file ) bool ServerPI::parsePort( const QString& pp ) { QStringList p = QStringList::split( ",", pp ); - if ( p.count() != 6 ) return FALSE; + if ( p.count() != 6 ) + return FALSE; // h1,h2,h3,h4,p1,p2 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + @@ -810,7 +821,8 @@ bool ServerPI::sendList( const QString& arg ) fn = directory.path(); QFileInfo fi( fn ); - if ( !fi.exists() ) return FALSE; + if ( !fi.exists() ) + return FALSE; // return file listing if ( fi.isFile() ) { @@ -858,7 +870,8 @@ bool ServerPI::sendList( const QString& arg ) QString ServerPI::fileListing( QFileInfo *info ) { - if ( !info ) return QString::null; + if ( !info ) + return QString::null; QString s; // type char @@ -908,32 +921,51 @@ QString ServerPI::fileListing( QFileInfo *info ) QString ServerPI::permissionString( QFileInfo *info ) { - if ( !info ) return QString( "---------" ); + if ( !info ) + return QString( "---------" ); QString s; // 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 += "-"; return s; } @@ -942,7 +974,8 @@ void ServerPI::newConnection( int socket ) { //qDebug( "New incomming connection" ); - if ( !passiv ) return; + if ( !passiv ) + return ; if ( wait[SendFile] ) { QStringList targets; @@ -978,7 +1011,8 @@ void ServerPI::newConnection( int socket ) QString ServerPI::absFilePath( const QString& file ) { - if ( file.isEmpty() ) return file; + if ( file.isEmpty() ) + return file; QString filepath( file ); if ( file[0] != "/" ) @@ -1004,22 +1038,19 @@ retrieveTargzProc( 0 ), gzipProc( 0 ) connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); - gzipProc = new QProcess( this, "gzipProc" ); - gzipProc->setCommunication( QProcess::Stdin | QProcess::Stdout ); + gzipProc = new OProcess( this, "gzipProc" ); - createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); - createTargzProc->setCommunication( QProcess::Stdout ); + createTargzProc = new OProcess( QString("tar"), this, "createTargzProc"); createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); - connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); + connect( createTargzProc, SIGNAL( processExited(OProcess *) ), SLOT( targzDone() ) ); QStringList args = "tar"; args += "-xv"; - retrieveTargzProc = new QProcess( args, this, "retrieveTargzProc" ); - retrieveTargzProc->setCommunication( QProcess::Stdin ); + retrieveTargzProc = new OProcess( args, this, "retrieveTargzProc" ); retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); - connect( retrieveTargzProc, SIGNAL( processExited() ), + connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ), SIGNAL( completed() ) ); - connect( retrieveTargzProc, SIGNAL( processExited() ), + connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ), SLOT( extractTarDone() ) ); } @@ -1034,6 +1065,7 @@ void ServerDTP::extractTarDone() { qDebug("extract done"); #ifndef QT_NO_COP + QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); e << file.name(); #endif @@ -1058,7 +1090,8 @@ void ServerDTP::connected() file.close(); emit completed(); mode = Idle; - } else { + } + else { if( !file.atEnd() ) { QCString s; @@ -1077,10 +1110,10 @@ void ServerDTP::connected() bytes_written = 0; qDebug("==>start send tar process"); - if ( !createTargzProc->start() ) + if ( !createTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdout) ) qWarning("Error starting %s or %s", - createTargzProc->arguments().join(" ").latin1(), - gzipProc->arguments().join(" ").latin1() ); + createTargzProc->args()[0].data(), + gzipProc->args()[0].data()); break; case SendBuffer: if ( !buf.open( IO_ReadOnly) ) { @@ -1212,12 +1245,12 @@ void ServerDTP::readyRead() } else if ( RetrieveGzipFile == mode ) { if ( !gzipProc->isRunning() ) - gzipProc->start(); + gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout )); QByteArray s; s.resize( bytesAvailable() ); readBlock( s.data(), bytesAvailable() ); - gzipProc->writeToStdin( s ); + gzipProc->writeStdin( s.data(), s.size() ); qDebug("wrote %d bytes to ungzip ", s.size() ); } // retrieve buffer mode @@ -1229,36 +1262,35 @@ void ServerDTP::readyRead() } } -void ServerDTP::writeTargzBlock() +void ServerDTP::writeTargzBlock(OProcess *, char *buffer, int buflen) { - QByteArray block = gzipProc->readStdout(); - writeBlock( block.data(), block.size() ); - qDebug("writeTargzBlock %d", block.size()); + writeBlock( buffer, buflen ); + qDebug("writeTargzBlock %d", buflen); if ( !createTargzProc->isRunning() ) { qDebug("tar and gzip done"); emit completed(); mode = Idle; - disconnect( gzipProc, SIGNAL( readyReadStdout() ), - this, SLOT( writeTargzBlock() ) ); + disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int ) ), + this, SLOT( writeTargzBlock(OProcess *, char *, int) ) ); } } void ServerDTP::targzDone() { //qDebug("targz done"); - disconnect( createTargzProc, SIGNAL( readyReadStdout() ), - this, SLOT( gzipTarBlock() ) ); + disconnect( createTargzProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), + this, SLOT( gzipTarBlock(OProcess *, char *, int) ) ); gzipProc->closeStdin(); } -void ServerDTP::gzipTarBlock() +void ServerDTP::gzipTarBlock(OProcess *, char *buffer, int buflen) { //qDebug("gzipTarBlock"); if ( !gzipProc->isRunning() ) { //qDebug("auto start gzip proc"); - gzipProc->start(); + gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout )); } - gzipProc->writeToStdin( createTargzProc->readStdout() ); + gzipProc->writeStdin( buffer, buflen ); } void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) @@ -1292,13 +1324,15 @@ void ServerDTP::sendGzipFile( const QString &fn, args += "-cv"; args += archiveTargets; qDebug("sendGzipFile %s", args.join(" ").latin1() ); - createTargzProc->setArguments( args ); + createTargzProc->clearArguments( ); + *createTargzProc << args; connect( createTargzProc, - SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) ); + SIGNAL( receivedStdout(OProcess *, char *, int) ), SLOT( gzipTarBlock(OProcess *, char *, int) ) ); - gzipProc->setArguments( "gzip" ); - connect( gzipProc, SIGNAL( readyReadStdout() ), - SLOT( writeTargzBlock() ) ); + gzipProc->clearArguments( ); + *gzipProc << "gzip"; + connect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), + SLOT( writeTargzBlock(OProcess *, char *, int) ) ); } void ServerDTP::gunzipDone() @@ -1307,19 +1341,19 @@ void ServerDTP::gunzipDone() disconnect( gzipProc, SIGNAL( processExited() ), this, SLOT( gunzipDone() ) ); retrieveTargzProc->closeStdin(); - disconnect( gzipProc, SIGNAL( readyReadStdout() ), - this, SLOT( tarExtractBlock() ) ); + disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), + this, SLOT( tarExtractBlock(OProcess *, char *, int) ) ); } -void ServerDTP::tarExtractBlock() +void ServerDTP::tarExtractBlock(OProcess *, char *buffer, int buflen) { - qDebug("ungzipTarBlock"); + qDebug("tarExtractBlock"); if ( !retrieveTargzProc->isRunning() ) { qDebug("auto start ungzip proc"); - if ( !retrieveTargzProc->start() ) + if ( !retrieveTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdin) ) qWarning(" failed to start tar -x process"); } - retrieveTargzProc->writeToStdin( gzipProc->readStdout() ); + retrieveTargzProc->writeStdin( buffer, buflen ); } @@ -1342,7 +1376,8 @@ void ServerDTP::retrieveGzipFile( const QString &fn ) file.setName( fn ); mode = RetrieveGzipFile; - gzipProc->setArguments( "gunzip" ); + gzipProc->clearArguments(); + *gzipProc << "gunzip"; connect( gzipProc, SIGNAL( readyReadStdout() ), SLOT( tarExtractBlock() ) ); connect( gzipProc, SIGNAL( processExited() ), |