summaryrefslogtreecommitdiff
path: root/core/launcher/transferserver.cpp
Side-by-side diff
Diffstat (limited to 'core/launcher/transferserver.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/transferserver.cpp107
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
@@ -14,62 +14,51 @@
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** 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>
#include <time.h>
#ifndef Q_OS_MACX
#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()
{
QListIterator<ServerPI> it(connections);
while ( it.current() ) {
@@ -368,21 +357,21 @@ bool ServerPI::verifyAuthorised()
}
return TRUE;
}
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()
{
while ( canReadLine() )
process( readLine().stripWhiteSpace() );
@@ -417,13 +406,13 @@ bool ServerPI::checkWriteFile( const QString& file )
return FALSE;
return TRUE;
}
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;
// command token
@@ -441,13 +430,13 @@ void ServerPI::process( const QString& message )
// FIXME: for Qt3
// copy.pop_front()
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
close();
return;
@@ -580,13 +569,13 @@ void ServerPI::process( const QString& message )
if ( !args.isEmpty() && checkReadFile( absFilePath( args ) )
|| backupRestoreGzip( absFilePath( args ) ) ) {
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)
else if ( cmd == "STOR" )
if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) {
@@ -686,13 +675,13 @@ 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;
if ( dir.mkdir( absFilePath( args ), TRUE ) )
send( "250 Requested file action okay, completed." ); // No tr
@@ -726,21 +715,21 @@ void ServerPI::process( const QString& message )
send( "213 " + QString::number( fi.size() ) );
else {
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) );
}
}
}
}
// name list (NLST)
@@ -1023,38 +1012,38 @@ QString ServerPI::permissionString( QFileInfo *info )
return s;
}
void ServerPI::newConnection( int socket )
{
- //qDebug( "New incomming connection" );
+ //odebug << "New incomming connection" << oendl;
if ( !passiv ) return;
if ( wait[SendFile] ) {
QStringList targets;
if ( backupRestoreGzip( waitfile, targets ) )
dtp->sendGzipFile( waitfile, targets );
else
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 );
dtp->setSocket( socket );
}
else if ( wait[SendByteArray] ) {
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
waitsocket = socket;
@@ -1108,24 +1097,24 @@ 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" );
+ odebug << "STOR incomplete" << oendl;
file.remove();
}
} else {
file.close();
}
createTargzProc->kill();
}
void ServerDTP::extractTarDone()
{
- qDebug("extract done");
+ odebug << "extract done" << oendl;
#ifndef QT_NO_COP
QCopEnvelope e( "QPE/System", "restoreDone(QString)" );
e << file.name();
#endif
}
@@ -1137,13 +1126,13 @@ void ServerDTP::connected()
if ( !file.exists() || !file.open( IO_ReadOnly) ) {
emit failed();
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
file.close();
emit completed();
@@ -1158,30 +1147,30 @@ 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;
case SendBuffer:
if ( !buf.open( IO_ReadOnly) ) {
emit failed();
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();
break;
case RetrieveFile:
@@ -1194,35 +1183,35 @@ void ServerDTP::connected()
if ( !file.open( IO_WriteOnly) ) {
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() )
emit completed();
else
@@ -1238,22 +1227,22 @@ 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();
}
// retrieve buffer mode
else if ( RetrieveBuffer == mode ) {
@@ -1269,13 +1258,13 @@ void ServerDTP::bytesWritten( int bytes )
bytes_written += 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;
}
else if( !file.atEnd() ) {
QCString s;
@@ -1286,13 +1275,13 @@ 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;
}
}
}
@@ -1310,13 +1299,13 @@ void ServerDTP::readyRead()
retrieveTargzProc->start();
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;
s.resize( bytesAvailable() );
readBlock( s.data(), bytesAvailable() );
@@ -1325,18 +1314,18 @@ 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() ) );
}
@@ -1367,13 +1356,13 @@ void ServerDTP::sendGzipFile( const QString &fn,
mode = SendGzipFile;
file.setName( 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() ) );
}
void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize )
@@ -1390,13 +1379,13 @@ void ServerDTP::retrieveFile( const QString fn, int fileSize )
file.setName( fn );
mode = RetrieveFile;
}
void ServerDTP::retrieveGzipFile( const QString &fn )
{
- qDebug("retrieveGzipFile %s", fn.latin1());
+ odebug << "retrieveGzipFile " << fn << "" << oendl;
file.setName( fn );
mode = RetrieveGzipFile;
retrieveTargzProc->setArguments( "targunzip" );
connect( retrieveTargzProc, SIGNAL( processExited() ),
SLOT( extractTarDone() ) );