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 | |||
@@ -18,9 +18,23 @@ | |||
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | //#define _XOPEN_SOURCE | 20 | #include "transferserver.h" |
21 | 21 | ||
22 | /* OPIE */ | ||
23 | #include <opie2/odebug.h> | ||
22 | #include <opie2/oglobal.h> | 24 | #include <opie2/oglobal.h> |
25 | #include <qtopia/qprocess.h> | ||
26 | #include <qtopia/process.h> | ||
27 | #include <qtopia/private/contact.h> | ||
28 | #include <qtopia/version.h> | ||
29 | #ifdef Q_WS_QWS | ||
30 | #include <qtopia/qcopenvelope_qws.h> | ||
31 | #endif | ||
32 | using namespace Opie::Core; | ||
23 | 33 | ||
24 | #ifndef Q_OS_WIN32 | 34 | /* QT */ |
35 | #include <qtextstream.h> | ||
36 | #include <qmessagebox.h> | ||
37 | |||
38 | /* STD */ | ||
25 | #include <pwd.h> | 39 | #include <pwd.h> |
26 | #include <sys/types.h> | 40 | #include <sys/types.h> |
@@ -34,31 +48,6 @@ | |||
34 | #endif /* Q_OS_MACX */ | 48 | #endif /* Q_OS_MACX */ |
35 | 49 | ||
36 | #else | ||
37 | #include <stdlib.h> | ||
38 | #include <time.h> | ||
39 | #endif | ||
40 | |||
41 | |||
42 | #if defined(_OS_LINUX_) | ||
43 | #include <shadow.h> | ||
44 | #endif | ||
45 | |||
46 | #include <qtextstream.h> | ||
47 | #include <qmessagebox.h> | ||
48 | //#include <qtopia/qcopchannel_qws.h> | ||
49 | #include <qtopia/process.h> | ||
50 | #include <qtopia/private/contact.h> | ||
51 | #include <qtopia/version.h> | ||
52 | #ifdef Q_WS_QWS | ||
53 | #include <qtopia/qcopenvelope_qws.h> | ||
54 | #endif | ||
55 | |||
56 | |||
57 | #include "transferserver.h" | ||
58 | #include <qtopia/qprocess.h> | ||
59 | |||
60 | const int block_size = 51200; | 50 | const int block_size = 51200; |
61 | 51 | ||
62 | using namespace Opie::Core; | ||
63 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent, | 52 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent, |
64 | const char* name) | 53 | const char* name) |
@@ -67,5 +56,5 @@ TransferServer::TransferServer( Q_UINT16 port, QObject *parent, | |||
67 | connections.setAutoDelete( TRUE ); | 56 | connections.setAutoDelete( TRUE ); |
68 | if ( !ok() ) | 57 | if ( !ok() ) |
69 | qWarning( "Failed to bind to port %d", port ); | 58 | owarn << "Failed to bind to port " << port << "" << oendl; |
70 | } | 59 | } |
71 | 60 | ||
@@ -372,5 +361,5 @@ bool ServerPI::verifyAuthorised() | |||
372 | void ServerPI::connectionClosed() | 361 | void ServerPI::connectionClosed() |
373 | { | 362 | { |
374 | // qDebug( "Debug: Connection closed" ); | 363 | // odebug << "Debug: Connection closed" << oendl; |
375 | emit connectionClosed(this); | 364 | emit connectionClosed(this); |
376 | } | 365 | } |
@@ -380,5 +369,5 @@ void ServerPI::send( const QString& msg ) | |||
380 | QTextStream os( this ); | 369 | QTextStream os( this ); |
381 | os << msg << endl; | 370 | os << msg << endl; |
382 | //qDebug( "Reply: %s", msg.latin1() ); | 371 | //odebug << "Reply: " << msg << "" << oendl; |
383 | } | 372 | } |
384 | 373 | ||
@@ -421,5 +410,5 @@ bool ServerPI::checkWriteFile( const QString& file ) | |||
421 | void ServerPI::process( const QString& message ) | 410 | void ServerPI::process( const QString& message ) |
422 | { | 411 | { |
423 | //qDebug( "Command: %s", message.latin1() ); | 412 | //odebug << "Command: " << message << "" << oendl; |
424 | 413 | ||
425 | // split message using "," as separator | 414 | // split message using "," as separator |
@@ -445,5 +434,5 @@ void ServerPI::process( const QString& message ) | |||
445 | } | 434 | } |
446 | 435 | ||
447 | //qDebug( "args: %s", args.latin1() ); | 436 | //odebug << "args: " << args << "" << oendl; |
448 | 437 | ||
449 | // we always respond to QUIT, regardless of state | 438 | // we always respond to QUIT, regardless of state |
@@ -584,5 +573,5 @@ void ServerPI::process( const QString& message ) | |||
584 | } | 573 | } |
585 | else { | 574 | else { |
586 | qDebug("550 Requested action not taken"); | 575 | odebug << "550 Requested action not taken" << oendl; |
587 | send( "550 Requested action not taken" ); // No tr | 576 | send( "550 Requested action not taken" ); // No tr |
588 | } | 577 | } |
@@ -690,5 +679,5 @@ void ServerPI::process( const QString& message ) | |||
690 | else if ( cmd == "MKD" ) { | 679 | else if ( cmd == "MKD" ) { |
691 | if ( args.isEmpty() ) { | 680 | if ( args.isEmpty() ) { |
692 | qDebug(" Error: no arg"); | 681 | odebug << " Error: no arg" << oendl; |
693 | send( "500 Syntax error, command unrecognized" ); // No tr | 682 | send( "500 Syntax error, command unrecognized" ); // No tr |
694 | } | 683 | } |
@@ -730,5 +719,5 @@ void ServerPI::process( const QString& message ) | |||
730 | QString in, out; | 719 | QString in, out; |
731 | if ( !duproc.exec(in, out) ) { | 720 | if ( !duproc.exec(in, out) ) { |
732 | qDebug("du process failed; just sending back 1K"); | 721 | odebug << "du process failed; just sending back 1K" << oendl; |
733 | send( "213 1024"); | 722 | send( "213 1024"); |
734 | } | 723 | } |
@@ -738,5 +727,5 @@ void ServerPI::process( const QString& message ) | |||
738 | if ( filePath.contains("doc") ) // No tr | 727 | if ( filePath.contains("doc") ) // No tr |
739 | guess *= 1000; | 728 | guess *= 1000; |
740 | qDebug("sending back gzip guess of %d", guess); | 729 | odebug << "sending back gzip guess of " << guess << "" << oendl; |
741 | send( "213 " + QString::number(guess) ); | 730 | send( "213 " + QString::number(guess) ); |
742 | } | 731 | } |
@@ -1027,5 +1016,5 @@ QString ServerPI::permissionString( QFileInfo *info ) | |||
1027 | void ServerPI::newConnection( int socket ) | 1016 | void ServerPI::newConnection( int socket ) |
1028 | { | 1017 | { |
1029 | //qDebug( "New incomming connection" ); | 1018 | //odebug << "New incomming connection" << oendl; |
1030 | 1019 | ||
1031 | if ( !passiv ) return; | 1020 | if ( !passiv ) return; |
@@ -1040,5 +1029,5 @@ void ServerPI::newConnection( int socket ) | |||
1040 | } | 1029 | } |
1041 | else if ( wait[RetrieveFile] ) { | 1030 | else if ( wait[RetrieveFile] ) { |
1042 | qDebug("check retrieve file"); | 1031 | odebug << "check retrieve file" << oendl; |
1043 | if ( backupRestoreGzip( waitfile ) ) | 1032 | if ( backupRestoreGzip( waitfile ) ) |
1044 | dtp->retrieveGzipFile( waitfile ); | 1033 | dtp->retrieveGzipFile( waitfile ); |
@@ -1052,5 +1041,5 @@ void ServerPI::newConnection( int socket ) | |||
1052 | } | 1041 | } |
1053 | else if ( wait[RetrieveByteArray] ) { | 1042 | else if ( wait[RetrieveByteArray] ) { |
1054 | qDebug("retrieve byte array"); | 1043 | odebug << "retrieve byte array" << oendl; |
1055 | dtp->retrieveByteArray(); | 1044 | dtp->retrieveByteArray(); |
1056 | dtp->setSocket( socket ); | 1045 | dtp->setSocket( socket ); |
@@ -1112,5 +1101,5 @@ ServerDTP::~ServerDTP() | |||
1112 | file.close(); | 1101 | file.close(); |
1113 | if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { | 1102 | if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { |
1114 | qDebug( "STOR incomplete" ); | 1103 | odebug << "STOR incomplete" << oendl; |
1115 | file.remove(); | 1104 | file.remove(); |
1116 | } | 1105 | } |
@@ -1123,5 +1112,5 @@ ServerDTP::~ServerDTP() | |||
1123 | void ServerDTP::extractTarDone() | 1112 | void ServerDTP::extractTarDone() |
1124 | { | 1113 | { |
1125 | qDebug("extract done"); | 1114 | odebug << "extract done" << oendl; |
1126 | #ifndef QT_NO_COP | 1115 | #ifndef QT_NO_COP |
1127 | QCopEnvelope e( "QPE/System", "restoreDone(QString)" ); | 1116 | QCopEnvelope e( "QPE/System", "restoreDone(QString)" ); |
@@ -1141,5 +1130,5 @@ void ServerDTP::connected() | |||
1141 | } | 1130 | } |
1142 | 1131 | ||
1143 | //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); | 1132 | //odebug << "Debug: Sending file '" << file.name() << "'" << oendl; |
1144 | 1133 | ||
1145 | bytes_written = 0; | 1134 | bytes_written = 0; |
@@ -1162,10 +1151,10 @@ void ServerDTP::connected() | |||
1162 | if ( createTargzProc->isRunning() ) { | 1151 | if ( createTargzProc->isRunning() ) { |
1163 | // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY | 1152 | // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY |
1164 | qWarning("Previous tar --gzip process is still running; killing it..."); | 1153 | owarn << "Previous tar --gzip process is still running; killing it..." << oendl; |
1165 | createTargzProc->kill(); | 1154 | createTargzProc->kill(); |
1166 | } | 1155 | } |
1167 | 1156 | ||
1168 | bytes_written = 0; | 1157 | bytes_written = 0; |
1169 | qDebug("==>start send tar process"); | 1158 | odebug << "==>start send tar process" << oendl; |
1170 | if ( !createTargzProc->start() ) | 1159 | if ( !createTargzProc->start() ) |
1171 | qWarning("Error starting %s", | 1160 | qWarning("Error starting %s", |
@@ -1179,5 +1168,5 @@ void ServerDTP::connected() | |||
1179 | } | 1168 | } |
1180 | 1169 | ||
1181 | // qDebug( "Debug: Sending byte array" ); | 1170 | // odebug << "Debug: Sending byte array" << oendl; |
1182 | bytes_written = 0; | 1171 | bytes_written = 0; |
1183 | while( !buf.atEnd() ) | 1172 | while( !buf.atEnd() ) |
@@ -1198,8 +1187,8 @@ void ServerDTP::connected() | |||
1198 | return; | 1187 | return; |
1199 | } | 1188 | } |
1200 | // qDebug( "Debug: Retrieving file %s", file.name().latin1() ); | 1189 | // odebug << "Debug: Retrieving file " << file.name() << "" << oendl; |
1201 | break; | 1190 | break; |
1202 | case RetrieveGzipFile: | 1191 | case RetrieveGzipFile: |
1203 | qDebug("=-> starting tar process to receive .tgz file"); | 1192 | odebug << "=-> starting tar process to receive .tgz file" << oendl; |
1204 | break; | 1193 | break; |
1205 | case RetrieveBuffer: | 1194 | case RetrieveBuffer: |
@@ -1210,8 +1199,8 @@ void ServerDTP::connected() | |||
1210 | return; | 1199 | return; |
1211 | } | 1200 | } |
1212 | // qDebug( "Debug: Retrieving byte array" ); | 1201 | // odebug << "Debug: Retrieving byte array" << oendl; |
1213 | break; | 1202 | break; |
1214 | case Idle: | 1203 | case Idle: |
1215 | qDebug("connection established but mode set to Idle; BUG!"); | 1204 | odebug << "connection established but mode set to Idle; BUG!" << oendl; |
1216 | break; | 1205 | break; |
1217 | } | 1206 | } |
@@ -1220,5 +1209,5 @@ void ServerDTP::connected() | |||
1220 | void ServerDTP::connectionClosed() | 1209 | void ServerDTP::connectionClosed() |
1221 | { | 1210 | { |
1222 | //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written ); | 1211 | //odebug << "Debug: Data connection closed " << bytes_written << " bytes written" << oendl; |
1223 | 1212 | ||
1224 | // send file mode | 1213 | // send file mode |
@@ -1242,5 +1231,5 @@ void ServerDTP::connectionClosed() | |||
1242 | file.close(); | 1231 | file.close(); |
1243 | if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { | 1232 | if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { |
1244 | qDebug( "STOR incomplete" ); | 1233 | odebug << "STOR incomplete" << oendl; |
1245 | file.remove(); | 1234 | file.remove(); |
1246 | emit failed(); | 1235 | emit failed(); |
@@ -1251,5 +1240,5 @@ void ServerDTP::connectionClosed() | |||
1251 | 1240 | ||
1252 | else if ( RetrieveGzipFile == mode ) { | 1241 | else if ( RetrieveGzipFile == mode ) { |
1253 | qDebug("Done writing ungzip file; closing input"); | 1242 | odebug << "Done writing ungzip file; closing input" << oendl; |
1254 | retrieveTargzProc->flushStdin(); | 1243 | retrieveTargzProc->flushStdin(); |
1255 | retrieveTargzProc->closeStdin(); | 1244 | retrieveTargzProc->closeStdin(); |
@@ -1273,5 +1262,5 @@ void ServerDTP::bytesWritten( int bytes ) | |||
1273 | 1262 | ||
1274 | if ( bytes_written == file.size() ) { | 1263 | if ( bytes_written == file.size() ) { |
1275 | // qDebug( "Debug: Sending complete: %d bytes", file.size() ); | 1264 | // odebug << "Debug: Sending complete: " << file.size() << " bytes" << oendl; |
1276 | file.close(); | 1265 | file.close(); |
1277 | emit completed(); | 1266 | emit completed(); |
@@ -1290,5 +1279,5 @@ void ServerDTP::bytesWritten( int bytes ) | |||
1290 | 1279 | ||
1291 | if ( bytes_written == buf.size() ) { | 1280 | if ( bytes_written == buf.size() ) { |
1292 | // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); | 1281 | // odebug << "Debug: Sending complete: " << buf.size() << " bytes" << oendl; |
1293 | emit completed(); | 1282 | emit completed(); |
1294 | mode = Idle; | 1283 | mode = Idle; |
@@ -1314,5 +1303,5 @@ void ServerDTP::readyRead() | |||
1314 | readBlock( s.data(), bytesAvailable() ); | 1303 | readBlock( s.data(), bytesAvailable() ); |
1315 | retrieveTargzProc->writeToStdin( s ); | 1304 | retrieveTargzProc->writeToStdin( s ); |
1316 | qDebug("wrote %d bytes to ungzip ", s.size() ); | 1305 | odebug << "wrote " << s.size() << " bytes to ungzip " << oendl; |
1317 | } | 1306 | } |
1318 | // retrieve buffer mode | 1307 | // retrieve buffer mode |
@@ -1329,10 +1318,10 @@ void ServerDTP::writeTargzBlock() | |||
1329 | QByteArray block = createTargzProc->readStdout(); | 1318 | QByteArray block = createTargzProc->readStdout(); |
1330 | writeBlock( block.data(), block.size() ); | 1319 | writeBlock( block.data(), block.size() ); |
1331 | qDebug("writeTargzBlock %d", block.size()); | 1320 | odebug << "writeTargzBlock " << block.size() << "" << oendl; |
1332 | } | 1321 | } |
1333 | 1322 | ||
1334 | void ServerDTP::targzDone() | 1323 | void ServerDTP::targzDone() |
1335 | { | 1324 | { |
1336 | qDebug("tar and gzip done"); | 1325 | odebug << "tar and gzip done" << oendl; |
1337 | emit completed(); | 1326 | emit completed(); |
1338 | mode = Idle; | 1327 | mode = Idle; |
@@ -1371,5 +1360,5 @@ void ServerDTP::sendGzipFile( const QString &fn, | |||
1371 | //args += "-cv"; | 1360 | //args += "-cv"; |
1372 | args += archiveTargets; | 1361 | args += archiveTargets; |
1373 | qDebug("sendGzipFile %s", args.join(" ").latin1() ); | 1362 | odebug << "sendGzipFile " << args.join(" ") << "" << oendl; |
1374 | createTargzProc->setArguments( args ); | 1363 | createTargzProc->setArguments( args ); |
1375 | connect( createTargzProc, | 1364 | connect( createTargzProc, |
@@ -1394,5 +1383,5 @@ void ServerDTP::retrieveFile( const QString fn, int fileSize ) | |||
1394 | void ServerDTP::retrieveGzipFile( const QString &fn ) | 1383 | void ServerDTP::retrieveGzipFile( const QString &fn ) |
1395 | { | 1384 | { |
1396 | qDebug("retrieveGzipFile %s", fn.latin1()); | 1385 | odebug << "retrieveGzipFile " << fn << "" << oendl; |
1397 | file.setName( fn ); | 1386 | file.setName( fn ); |
1398 | mode = RetrieveGzipFile; | 1387 | mode = RetrieveGzipFile; |