Diffstat (limited to 'core/launcher/transferserver.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/launcher/transferserver.cpp | 107 |
1 files changed, 48 insertions, 59 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp index e32cf41..4b764e3 100644 --- a/core/launcher/transferserver.cpp +++ b/core/launcher/transferserver.cpp @@ -16,13 +16,27 @@ ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ -//#define _XOPEN_SOURCE +#include "transferserver.h" +/* OPIE */ +#include <opie2/odebug.h> #include <opie2/oglobal.h> +#include <qtopia/qprocess.h> +#include <qtopia/process.h> +#include <qtopia/private/contact.h> +#include <qtopia/version.h> +#ifdef Q_WS_QWS +#include <qtopia/qcopenvelope_qws.h> +#endif +using namespace Opie::Core; -#ifndef Q_OS_WIN32 +/* QT */ +#include <qtextstream.h> +#include <qmessagebox.h> + +/* STD */ #include <pwd.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> @@ -32,42 +46,17 @@ #include <shadow.h> #include <crypt.h> #endif /* Q_OS_MACX */ -#else -#include <stdlib.h> -#include <time.h> -#endif - - -#if defined(_OS_LINUX_) -#include <shadow.h> -#endif - -#include <qtextstream.h> -#include <qmessagebox.h> -//#include <qtopia/qcopchannel_qws.h> -#include <qtopia/process.h> -#include <qtopia/private/contact.h> -#include <qtopia/version.h> -#ifdef Q_WS_QWS -#include <qtopia/qcopenvelope_qws.h> -#endif - - -#include "transferserver.h" -#include <qtopia/qprocess.h> - const int block_size = 51200; -using namespace Opie::Core; TransferServer::TransferServer( Q_UINT16 port, QObject *parent, const char* name) : QServerSocket( port, 1, parent, name ) { connections.setAutoDelete( TRUE ); if ( !ok() ) - qWarning( "Failed to bind to port %d", port ); + owarn << "Failed to bind to port " << port << "" << oendl; } void TransferServer::authorizeConnections() { @@ -370,17 +359,17 @@ bool ServerPI::verifyAuthorised() } void ServerPI::connectionClosed() { - // qDebug( "Debug: Connection closed" ); + // odebug << "Debug: Connection closed" << oendl; emit connectionClosed(this); } void ServerPI::send( const QString& msg ) { QTextStream os( this ); os << msg << endl; - //qDebug( "Reply: %s", msg.latin1() ); + //odebug << "Reply: " << msg << "" << oendl; } void ServerPI::read() { @@ -419,9 +408,9 @@ bool ServerPI::checkWriteFile( const QString& file ) } void ServerPI::process( const QString& message ) { - //qDebug( "Command: %s", message.latin1() ); + //odebug << "Command: " << message << "" << oendl; // split message using "," as separator QStringList msg = QStringList::split( " ", message ); if ( msg.isEmpty() ) return; @@ -443,9 +432,9 @@ void ServerPI::process( const QString& message ) copy.remove( copy.begin() ); args = copy.join( " " ); } - //qDebug( "args: %s", args.latin1() ); + //odebug << "args: " << args << "" << oendl; // we always respond to QUIT, regardless of state if ( cmd == "QUIT" ) { send( "211 Good bye!" ); // No tr @@ -582,9 +571,9 @@ void ServerPI::process( const QString& message ) send( "150 File status okay" ); // No tr sendFile( absFilePath( args ) ); } else { - qDebug("550 Requested action not taken"); + odebug << "550 Requested action not taken" << oendl; send( "550 Requested action not taken" ); // No tr } // store (STOR) @@ -688,9 +677,9 @@ void ServerPI::process( const QString& message ) // make directory (MKD) else if ( cmd == "MKD" ) { if ( args.isEmpty() ) { - qDebug(" Error: no arg"); + odebug << " Error: no arg" << oendl; send( "500 Syntax error, command unrecognized" ); // No tr } else { QDir dir; @@ -728,17 +717,17 @@ void ServerPI::process( const QString& message ) Process duproc( QString("du") ); duproc.addArgument("-s"); QString in, out; if ( !duproc.exec(in, out) ) { - qDebug("du process failed; just sending back 1K"); + odebug << "du process failed; just sending back 1K" << oendl; send( "213 1024"); } else { QString size = out.left( out.find("\t") ); int guess = size.toInt()/5; if ( filePath.contains("doc") ) // No tr guess *= 1000; - qDebug("sending back gzip guess of %d", guess); + odebug << "sending back gzip guess of " << guess << "" << oendl; send( "213 " + QString::number(guess) ); } } } @@ -1025,9 +1014,9 @@ QString ServerPI::permissionString( QFileInfo *info ) } void ServerPI::newConnection( int socket ) { - //qDebug( "New incomming connection" ); + //odebug << "New incomming connection" << oendl; if ( !passiv ) return; if ( wait[SendFile] ) { @@ -1038,9 +1027,9 @@ void ServerPI::newConnection( int socket ) dtp->sendFile( waitfile ); dtp->setSocket( socket ); } else if ( wait[RetrieveFile] ) { - qDebug("check retrieve file"); + odebug << "check retrieve file" << oendl; if ( backupRestoreGzip( waitfile ) ) dtp->retrieveGzipFile( waitfile ); else dtp->retrieveFile( waitfile, storFileSize ); @@ -1050,9 +1039,9 @@ void ServerPI::newConnection( int socket ) dtp->sendByteArray( waitarray ); dtp->setSocket( socket ); } else if ( wait[RetrieveByteArray] ) { - qDebug("retrieve byte array"); + odebug << "retrieve byte array" << oendl; dtp->retrieveByteArray(); dtp->setSocket( socket ); } else @@ -1110,9 +1099,9 @@ ServerDTP::~ServerDTP() 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" ); + odebug << "STOR incomplete" << oendl; file.remove(); } } else { file.close(); @@ -1121,9 +1110,9 @@ ServerDTP::~ServerDTP() } void ServerDTP::extractTarDone() { - qDebug("extract done"); + odebug << "extract done" << oendl; #ifndef QT_NO_COP QCopEnvelope e( "QPE/System", "restoreDone(QString)" ); e << file.name(); #endif @@ -1139,9 +1128,9 @@ void ServerDTP::connected() mode = Idle; return; } - //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); + //odebug << "Debug: Sending file '" << file.name() << "'" << oendl; bytes_written = 0; if ( file.size() == 0 ) { //make sure it doesn't hang on empty files @@ -1160,14 +1149,14 @@ void ServerDTP::connected() break; case SendGzipFile: if ( createTargzProc->isRunning() ) { // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY - qWarning("Previous tar --gzip process is still running; killing it..."); + owarn << "Previous tar --gzip process is still running; killing it..." << oendl; createTargzProc->kill(); } bytes_written = 0; - qDebug("==>start send tar process"); + odebug << "==>start send tar process" << oendl; if ( !createTargzProc->start() ) qWarning("Error starting %s", createTargzProc->arguments().join(" ").latin1()); break; @@ -1177,9 +1166,9 @@ void ServerDTP::connected() mode = Idle; return; } - // qDebug( "Debug: Sending byte array" ); + // odebug << "Debug: Sending byte array" << oendl; bytes_written = 0; while( !buf.atEnd() ) putch( buf.getch() ); buf.close(); @@ -1196,31 +1185,31 @@ void ServerDTP::connected() emit failed(); mode = Idle; return; } - // qDebug( "Debug: Retrieving file %s", file.name().latin1() ); + // odebug << "Debug: Retrieving file " << file.name() << "" << oendl; break; case RetrieveGzipFile: - qDebug("=-> starting tar process to receive .tgz file"); + odebug << "=-> starting tar process to receive .tgz file" << oendl; break; case RetrieveBuffer: // retrieve buffer mode if ( !buf.open( IO_WriteOnly) ) { emit failed(); mode = Idle; return; } - // qDebug( "Debug: Retrieving byte array" ); + // odebug << "Debug: Retrieving byte array" << oendl; break; case Idle: - qDebug("connection established but mode set to Idle; BUG!"); + odebug << "connection established but mode set to Idle; BUG!" << oendl; break; } } void ServerDTP::connectionClosed() { - //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written ); + //odebug << "Debug: Data connection closed " << bytes_written << " bytes written" << oendl; // send file mode if ( SendFile == mode ) { if ( bytes_written == file.size() ) @@ -1240,18 +1229,18 @@ void ServerDTP::connectionClosed() // retrieve file mode else if ( RetrieveFile == mode ) { file.close(); if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { - qDebug( "STOR incomplete" ); + odebug << "STOR incomplete" << oendl; file.remove(); emit failed(); } else { emit completed(); } } else if ( RetrieveGzipFile == mode ) { - qDebug("Done writing ungzip file; closing input"); + odebug << "Done writing ungzip file; closing input" << oendl; retrieveTargzProc->flushStdin(); retrieveTargzProc->closeStdin(); } @@ -1271,9 +1260,9 @@ void ServerDTP::bytesWritten( int bytes ) // send file mode if ( SendFile == mode ) { if ( bytes_written == file.size() ) { - // qDebug( "Debug: Sending complete: %d bytes", file.size() ); + // odebug << "Debug: Sending complete: " << file.size() << " bytes" << oendl; file.close(); emit completed(); mode = Idle; } @@ -1288,9 +1277,9 @@ void ServerDTP::bytesWritten( int bytes ) // send buffer mode if ( SendBuffer == mode ) { if ( bytes_written == buf.size() ) { - // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); + // odebug << "Debug: Sending complete: " << buf.size() << " bytes" << oendl; emit completed(); mode = Idle; } } @@ -1312,9 +1301,9 @@ void ServerDTP::readyRead() QByteArray s; s.resize( bytesAvailable() ); readBlock( s.data(), bytesAvailable() ); retrieveTargzProc->writeToStdin( s ); - qDebug("wrote %d bytes to ungzip ", s.size() ); + odebug << "wrote " << s.size() << " bytes to ungzip " << oendl; } // retrieve buffer mode else if ( RetrieveBuffer == mode ) { QCString s; @@ -1327,14 +1316,14 @@ void ServerDTP::readyRead() void ServerDTP::writeTargzBlock() { QByteArray block = createTargzProc->readStdout(); writeBlock( block.data(), block.size() ); - qDebug("writeTargzBlock %d", block.size()); + odebug << "writeTargzBlock " << block.size() << "" << oendl; } void ServerDTP::targzDone() { - qDebug("tar and gzip done"); + odebug << "tar and gzip done" << oendl; emit completed(); mode = Idle; disconnect( createTargzProc, SIGNAL( readyReadStdout() ), this, SLOT( writeTargzBlock() ) ); @@ -1369,9 +1358,9 @@ void ServerDTP::sendGzipFile( const QString &fn, QStringList args = "targzip"; //args += "-cv"; args += archiveTargets; - qDebug("sendGzipFile %s", args.join(" ").latin1() ); + odebug << "sendGzipFile " << args.join(" ") << "" << oendl; createTargzProc->setArguments( args ); connect( createTargzProc, SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); } @@ -1392,9 +1381,9 @@ void ServerDTP::retrieveFile( const QString fn, int fileSize ) } void ServerDTP::retrieveGzipFile( const QString &fn ) { - qDebug("retrieveGzipFile %s", fn.latin1()); + odebug << "retrieveGzipFile " << fn << "" << oendl; file.setName( fn ); mode = RetrieveGzipFile; retrieveTargzProc->setArguments( "targunzip" ); |