summaryrefslogtreecommitdiff
path: root/core/launcher/transferserver.cpp
Side-by-side diff
Diffstat (limited to 'core/launcher/transferserver.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/launcher/transferserver.cpp191
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
@@ -29,9 +29,10 @@
#include <qglobal.h>
#ifndef _OS_LINUX_
-extern "C" {
+extern "C"
+{
#include <uuid/uuid.h>
#define UUID_H_INCLUDED
}
@@ -58,9 +59,9 @@ extern "C" {
#include <qpe/version.h>
#include <qpe/qcopenvelope_qws.h>
#include "transferserver.h"
-#include "qprocess.h"
+#include <opie/oprocess.h>
const int block_size = 51200;
TransferServer::TransferServer( Q_UINT16 port, QObject *parent ,
@@ -72,9 +73,8 @@ TransferServer::TransferServer( Q_UINT16 port, QObject *parent ,
}
TransferServer::~TransferServer()
{
-
}
void TransferServer::newConnection( int socket )
{
@@ -84,14 +84,18 @@ 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();
}
@@ -99,9 +103,10 @@ 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;
@@ -162,9 +167,10 @@ 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;
}
@@ -229,14 +235,14 @@ bool SyncAuthentication::checkPassword( const QString& password )
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"), 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;
}
@@ -255,12 +261,14 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name )
peerport = peerPort();
peeraddress = peerAddress();
#ifndef INSECURE
+
if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
state = Forbidden;
startTimer( 0 );
- } else
+ }
+ else
#endif
{
connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
@@ -292,9 +300,8 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name )
}
ServerPI::~ServerPI()
{
-
}
void ServerPI::connectionClosed()
{
@@ -350,9 +357,10 @@ void ServerPI::process( const QString& message )
//qDebug( "Command: %s", message.latin1() );
// 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();
@@ -589,9 +597,10 @@ void ServerPI::process( const QString& message )
if ( file.remove() ) {
send( "250 Requested file action okay, completed" );
QCopEnvelope e("QPE/System", "linkChanged(QString)" );
e << file.name();
- } else {
+ }
+ else {
send( "550 Requested action not taken" );
}
}
}
@@ -733,9 +742,10 @@ void ServerPI::sendFile( const QString& file )
else {
QStringList targets;
if ( backupRestoreGzip( file, targets ) )
dtp->sendGzipFile( file, targets, peeraddress, peerport );
- else dtp->sendFile( file, peeraddress, peerport );
+ else
+ dtp->sendFile( file, peeraddress, peerport );
}
}
void ServerPI::retrieveFile( const QString& file )
@@ -757,9 +767,10 @@ 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 ) +
( p[2].toInt() << 8 ) + p[3].toInt() );
@@ -809,9 +820,10 @@ bool ServerPI::sendList( const QString& arg )
if ( fn.isEmpty() )
fn = directory.path();
QFileInfo fi( fn );
- if ( !fi.exists() ) return FALSE;
+ if ( !fi.exists() )
+ return FALSE;
// return file listing
if ( fi.isFile() ) {
ts << fileListing( &fi ) << endl;
@@ -857,9 +869,10 @@ 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
if ( info->isDir() )
@@ -907,43 +920,63 @@ 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;
}
void ServerPI::newConnection( int socket )
{
//qDebug( "New incomming connection" );
- if ( !passiv ) return;
+ if ( !passiv )
+ return ;
if ( wait[SendFile] ) {
QStringList targets;
if ( backupRestoreGzip( waitfile, targets ) )
@@ -977,9 +1010,10 @@ 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] != "/" )
filepath = directory.path() + "/" + file;
@@ -1003,24 +1037,21 @@ retrieveTargzProc( 0 ), gzipProc( 0 )
connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
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() ) );
}
ServerDTP::~ServerDTP()
@@ -1033,8 +1064,9 @@ ServerDTP::~ServerDTP()
void ServerDTP::extractTarDone()
{
qDebug("extract done");
#ifndef QT_NO_COP
+
QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" );
e << file.name();
#endif
}
@@ -1057,9 +1089,10 @@ void ServerDTP::connected()
//make sure it doesn't hang on empty files
file.close();
emit completed();
mode = Idle;
- } else {
+ }
+ else {
if( !file.atEnd() ) {
QCString s;
s.resize( block_size );
@@ -1076,12 +1109,12 @@ 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) ) {
emit failed();
@@ -1211,14 +1244,14 @@ void ServerDTP::readyRead()
file.writeBlock( s.data(), s.size() );
}
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
else if ( RetrieveBuffer == mode ) {
@@ -1228,38 +1261,37 @@ void ServerDTP::readyRead()
buf.writeBlock( s.data(), s.size() );
}
}
-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 )
{
@@ -1291,36 +1323,38 @@ void ServerDTP::sendGzipFile( const QString &fn,
QStringList args = "tar";
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()
{
qDebug("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 );
}
void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port )
@@ -1341,9 +1375,10 @@ void ServerDTP::retrieveGzipFile( const QString &fn )
qDebug("retrieveGzipFile %s", fn.latin1());
file.setName( fn );
mode = RetrieveGzipFile;
- gzipProc->setArguments( "gunzip" );
+ gzipProc->clearArguments();
+ *gzipProc << "gunzip";
connect( gzipProc, SIGNAL( readyReadStdout() ),
SLOT( tarExtractBlock() ) );
connect( gzipProc, SIGNAL( processExited() ),
SLOT( gunzipDone() ) );