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 @@ -31,5 +31,6 @@ #ifndef _OS_LINUX_ -extern "C" { +extern "C" +{ #include <uuid/uuid.h> #define UUID_H_INCLUDED @@ -60,5 +61,5 @@ extern "C" { #include "transferserver.h" -#include "qprocess.h" +#include <opie/oprocess.h> const int block_size = 51200; @@ -74,5 +75,4 @@ TransferServer::TransferServer( Q_UINT16 port, QObject *parent , TransferServer::~TransferServer() { - } @@ -86,10 +86,14 @@ void TransferServer::newConnection( int socket ) * 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 ); @@ -101,5 +105,6 @@ namespace { * 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 ) ) @@ -164,5 +169,6 @@ 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; @@ -231,10 +237,10 @@ bool SyncAuthentication::checkPassword( const QString& password ) 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); @@ -257,8 +263,10 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name ) #ifndef INSECURE + if ( !SyncAuthentication::isAuthorized(peeraddress) ) { state = Forbidden; startTimer( 0 ); - } else + } + else #endif { @@ -294,5 +302,4 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name ) ServerPI::~ServerPI() { - } @@ -352,5 +359,6 @@ 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 @@ -591,5 +599,6 @@ void ServerPI::process( const QString& message ) QCopEnvelope e("QPE/System", "linkChanged(QString)" ); e << file.name(); - } else { + } + else { send( "550 Requested action not taken" ); } @@ -735,5 +744,6 @@ void ServerPI::sendFile( const QString& file ) if ( backupRestoreGzip( file, targets ) ) dtp->sendGzipFile( file, targets, peeraddress, peerport ); - else dtp->sendFile( file, peeraddress, peerport ); + else + dtp->sendFile( file, peeraddress, peerport ); } } @@ -759,5 +769,6 @@ 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 @@ -811,5 +822,6 @@ bool ServerPI::sendList( const QString& arg ) QFileInfo fi( fn ); - if ( !fi.exists() ) return FALSE; + if ( !fi.exists() ) + return FALSE; // return file listing @@ -859,5 +871,6 @@ bool ServerPI::sendList( const QString& arg ) QString ServerPI::fileListing( QFileInfo *info ) { - if ( !info ) return QString::null; + if ( !info ) + return QString::null; QString s; @@ -909,30 +922,49 @@ 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; @@ -943,5 +975,6 @@ void ServerPI::newConnection( int socket ) //qDebug( "New incomming connection" ); - if ( !passiv ) return; + if ( !passiv ) + return ; if ( wait[SendFile] ) { @@ -979,5 +1012,6 @@ void ServerPI::newConnection( int socket ) QString ServerPI::absFilePath( const QString& file ) { - if ( file.isEmpty() ) return file; + if ( file.isEmpty() ) + return file; QString filepath( file ); @@ -1005,20 +1039,17 @@ retrieveTargzProc( 0 ), gzipProc( 0 ) 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() ) ); } @@ -1035,4 +1066,5 @@ void ServerDTP::extractTarDone() qDebug("extract done"); #ifndef QT_NO_COP + QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); e << file.name(); @@ -1059,5 +1091,6 @@ void ServerDTP::connected() emit completed(); mode = Idle; - } else { + } + else { if( !file.atEnd() ) { @@ -1078,8 +1111,8 @@ 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: @@ -1213,10 +1246,10 @@ 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() ); } @@ -1230,15 +1263,14 @@ 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) ) ); } } @@ -1247,17 +1279,17 @@ 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 ); } @@ -1293,11 +1325,13 @@ void ServerDTP::sendGzipFile( const QString &fn, 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) ) ); } @@ -1308,17 +1342,17 @@ void ServerDTP::gunzipDone() 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 ); } @@ -1343,5 +1377,6 @@ void ServerDTP::retrieveGzipFile( const QString &fn ) mode = RetrieveGzipFile; - gzipProc->setArguments( "gunzip" ); + gzipProc->clearArguments(); + *gzipProc << "gunzip"; connect( gzipProc, SIGNAL( readyReadStdout() ), SLOT( tarExtractBlock() ) ); |