author | mickeyl <mickeyl> | 2004-04-07 13:36:16 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-04-07 13:36:16 (UTC) |
commit | 4f1d28a25ce6180850c3d26bac9b638f0f25532b (patch) (unidiff) | |
tree | 59b4879b1065086c9a2e28f16f7d48540c8a9456 /core/launcher/transferserver.cpp | |
parent | 8af35b63a277ec14dcc4a0a6ca5bbe228e276b98 (diff) | |
download | opie-4f1d28a25ce6180850c3d26bac9b638f0f25532b.zip opie-4f1d28a25ce6180850c3d26bac9b638f0f25532b.tar.gz opie-4f1d28a25ce6180850c3d26bac9b638f0f25532b.tar.bz2 |
use Opie debugging framework
Diffstat (limited to 'core/launcher/transferserver.cpp') (more/less context) (show 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 | |||
@@ -8,74 +8,63 @@ | |||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
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> |
27 | #include <unistd.h> | 41 | #include <unistd.h> |
28 | #include <stdlib.h> | 42 | #include <stdlib.h> |
29 | #include <time.h> | 43 | #include <time.h> |
30 | 44 | ||
31 | #ifndef Q_OS_MACX | 45 | #ifndef Q_OS_MACX |
32 | #include <shadow.h> | 46 | #include <shadow.h> |
33 | #include <crypt.h> | 47 | #include <crypt.h> |
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) |
65 | : QServerSocket( port, 1, parent, name ) | 54 | : QServerSocket( port, 1, parent, name ) |
66 | { | 55 | { |
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 | ||
72 | void TransferServer::authorizeConnections() | 61 | void TransferServer::authorizeConnections() |
73 | { | 62 | { |
74 | QListIterator<ServerPI> it(connections); | 63 | QListIterator<ServerPI> it(connections); |
75 | while ( it.current() ) { | 64 | while ( it.current() ) { |
76 | if ( !it.current()->verifyAuthorised() ) { | 65 | if ( !it.current()->verifyAuthorised() ) { |
77 | disconnect( it.current(), SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) ); | 66 | disconnect( it.current(), SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) ); |
78 | connections.removeRef( it.current() ); | 67 | connections.removeRef( it.current() ); |
79 | } else | 68 | } else |
80 | ++it; | 69 | ++it; |
81 | } | 70 | } |
@@ -362,33 +351,33 @@ ServerPI::~ServerPI() | |||
362 | 351 | ||
363 | bool ServerPI::verifyAuthorised() | 352 | bool ServerPI::verifyAuthorised() |
364 | { | 353 | { |
365 | if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { | 354 | if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { |
366 | state = Forbidden; | 355 | state = Forbidden; |
367 | return FALSE; | 356 | return FALSE; |
368 | } | 357 | } |
369 | return TRUE; | 358 | return TRUE; |
370 | } | 359 | } |
371 | 360 | ||
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 | } |
377 | 366 | ||
378 | void ServerPI::send( const QString& msg ) | 367 | void ServerPI::send( const QString& msg ) |
379 | { | 368 | { |
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 | ||
385 | void ServerPI::read() | 374 | void ServerPI::read() |
386 | { | 375 | { |
387 | while ( canReadLine() ) | 376 | while ( canReadLine() ) |
388 | process( readLine().stripWhiteSpace() ); | 377 | process( readLine().stripWhiteSpace() ); |
389 | } | 378 | } |
390 | 379 | ||
391 | bool ServerPI::checkReadFile( const QString& file ) | 380 | bool ServerPI::checkReadFile( const QString& file ) |
392 | { | 381 | { |
393 | QString filename; | 382 | QString filename; |
394 | 383 | ||
@@ -411,49 +400,49 @@ bool ServerPI::checkWriteFile( const QString& file ) | |||
411 | filename = file; | 400 | filename = file; |
412 | 401 | ||
413 | QFileInfo fi( filename ); | 402 | QFileInfo fi( filename ); |
414 | 403 | ||
415 | if ( fi.exists() ) | 404 | if ( fi.exists() ) |
416 | if ( !QFile( filename ).remove() ) | 405 | if ( !QFile( filename ).remove() ) |
417 | return FALSE; | 406 | return FALSE; |
418 | return TRUE; | 407 | return TRUE; |
419 | } | 408 | } |
420 | 409 | ||
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 |
426 | QStringList msg = QStringList::split( " ", message ); | 415 | QStringList msg = QStringList::split( " ", message ); |
427 | if ( msg.isEmpty() ) return; | 416 | if ( msg.isEmpty() ) return; |
428 | 417 | ||
429 | // command token | 418 | // command token |
430 | QString cmd = msg[0].upper(); | 419 | QString cmd = msg[0].upper(); |
431 | 420 | ||
432 | // argument token | 421 | // argument token |
433 | QString arg; | 422 | QString arg; |
434 | if ( msg.count() >= 2 ) | 423 | if ( msg.count() >= 2 ) |
435 | arg = msg[1]; | 424 | arg = msg[1]; |
436 | 425 | ||
437 | // full argument string | 426 | // full argument string |
438 | QString args; | 427 | QString args; |
439 | if ( msg.count() >= 2 ) { | 428 | if ( msg.count() >= 2 ) { |
440 | QStringList copy( msg ); | 429 | QStringList copy( msg ); |
441 | // FIXME: for Qt3 | 430 | // FIXME: for Qt3 |
442 | // copy.pop_front() | 431 | // copy.pop_front() |
443 | copy.remove( copy.begin() ); | 432 | copy.remove( copy.begin() ); |
444 | args = copy.join( " " ); | 433 | args = copy.join( " " ); |
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 |
450 | if ( cmd == "QUIT" ) { | 439 | if ( cmd == "QUIT" ) { |
451 | send( "211 Good bye!" ); // No tr | 440 | send( "211 Good bye!" ); // No tr |
452 | close(); | 441 | close(); |
453 | return; | 442 | return; |
454 | } | 443 | } |
455 | 444 | ||
456 | // connected to client | 445 | // connected to client |
457 | if ( Connected == state ) | 446 | if ( Connected == state ) |
458 | return; | 447 | return; |
459 | 448 | ||
@@ -574,25 +563,25 @@ void ServerPI::process( const QString& message ) | |||
574 | 563 | ||
575 | // FTP SERVICE COMMANDS | 564 | // FTP SERVICE COMMANDS |
576 | 565 | ||
577 | 566 | ||
578 | // retrieve (RETR) | 567 | // retrieve (RETR) |
579 | else if ( cmd == "RETR" ) | 568 | else if ( cmd == "RETR" ) |
580 | if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) | 569 | if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) |
581 | || backupRestoreGzip( absFilePath( args ) ) ) { | 570 | || backupRestoreGzip( absFilePath( args ) ) ) { |
582 | send( "150 File status okay" ); // No tr | 571 | send( "150 File status okay" ); // No tr |
583 | sendFile( absFilePath( args ) ); | 572 | sendFile( absFilePath( args ) ); |
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 | } |
589 | 578 | ||
590 | // store (STOR) | 579 | // store (STOR) |
591 | else if ( cmd == "STOR" ) | 580 | else if ( cmd == "STOR" ) |
592 | if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { | 581 | if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { |
593 | send( "150 File status okay" ); // No tr | 582 | send( "150 File status okay" ); // No tr |
594 | retrieveFile( absFilePath( args ) ); | 583 | retrieveFile( absFilePath( args ) ); |
595 | } | 584 | } |
596 | else | 585 | else |
597 | send( "550 Requested action not taken" ); // No tr | 586 | send( "550 Requested action not taken" ); // No tr |
598 | 587 | ||
@@ -680,25 +669,25 @@ void ServerPI::process( const QString& message ) | |||
680 | else { | 669 | else { |
681 | QDir dir; | 670 | QDir dir; |
682 | if ( dir.rmdir( absFilePath( args ), TRUE ) ) | 671 | if ( dir.rmdir( absFilePath( args ), TRUE ) ) |
683 | send( "250 Requested file action okay, completed" ); // No tr | 672 | send( "250 Requested file action okay, completed" ); // No tr |
684 | else | 673 | else |
685 | send( "550 Requested action not taken" ); // No tr | 674 | send( "550 Requested action not taken" ); // No tr |
686 | } | 675 | } |
687 | } | 676 | } |
688 | 677 | ||
689 | // make directory (MKD) | 678 | // make directory (MKD) |
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 | } |
695 | else { | 684 | else { |
696 | QDir dir; | 685 | QDir dir; |
697 | if ( dir.mkdir( absFilePath( args ), TRUE ) ) | 686 | if ( dir.mkdir( absFilePath( args ), TRUE ) ) |
698 | send( "250 Requested file action okay, completed." ); // No tr | 687 | send( "250 Requested file action okay, completed." ); // No tr |
699 | else | 688 | else |
700 | send( "550 Requested action not taken" ); // No tr | 689 | send( "550 Requested action not taken" ); // No tr |
701 | } | 690 | } |
702 | } | 691 | } |
703 | 692 | ||
704 | // print working directory (PWD) | 693 | // print working directory (PWD) |
@@ -720,33 +709,33 @@ void ServerPI::process( const QString& message ) | |||
720 | QFileInfo fi( filePath ); | 709 | QFileInfo fi( filePath ); |
721 | bool gzipfile = backupRestoreGzip( filePath ); | 710 | bool gzipfile = backupRestoreGzip( filePath ); |
722 | if ( !fi.exists() && !gzipfile ) | 711 | if ( !fi.exists() && !gzipfile ) |
723 | send( "500 Syntax error, command unrecognized" ); // No tr | 712 | send( "500 Syntax error, command unrecognized" ); // No tr |
724 | else { | 713 | else { |
725 | if ( !gzipfile ) | 714 | if ( !gzipfile ) |
726 | send( "213 " + QString::number( fi.size() ) ); | 715 | send( "213 " + QString::number( fi.size() ) ); |
727 | else { | 716 | else { |
728 | Process duproc( QString("du") ); | 717 | Process duproc( QString("du") ); |
729 | duproc.addArgument("-s"); | 718 | duproc.addArgument("-s"); |
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 | } |
735 | else { | 724 | else { |
736 | QString size = out.left( out.find("\t") ); | 725 | QString size = out.left( out.find("\t") ); |
737 | int guess = size.toInt()/5; | 726 | int guess = size.toInt()/5; |
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 | } |
743 | } | 732 | } |
744 | } | 733 | } |
745 | } | 734 | } |
746 | // name list (NLST) | 735 | // name list (NLST) |
747 | else if ( cmd == "NLST" ) { | 736 | else if ( cmd == "NLST" ) { |
748 | send( "502 Command not implemented" ); // No tr | 737 | send( "502 Command not implemented" ); // No tr |
749 | } | 738 | } |
750 | 739 | ||
751 | // site parameters (SITE) | 740 | // site parameters (SITE) |
752 | else if ( cmd == "SITE" ) { | 741 | else if ( cmd == "SITE" ) { |
@@ -1017,50 +1006,50 @@ QString ServerPI::permissionString( QFileInfo *info ) | |||
1017 | if ( info->permission( QFileInfo::ReadOther ) ) s += "r"; | 1006 | if ( info->permission( QFileInfo::ReadOther ) ) s += "r"; |
1018 | else s += "-"; | 1007 | else s += "-"; |
1019 | if ( info->permission( QFileInfo::WriteOther ) ) s += "w"; | 1008 | if ( info->permission( QFileInfo::WriteOther ) ) s += "w"; |
1020 | else s += "-"; | 1009 | else s += "-"; |
1021 | if ( info->permission( QFileInfo::ExeOther ) ) s += "x"; | 1010 | if ( info->permission( QFileInfo::ExeOther ) ) s += "x"; |
1022 | else s += "-"; | 1011 | else s += "-"; |
1023 | 1012 | ||
1024 | return s; | 1013 | return s; |
1025 | } | 1014 | } |
1026 | 1015 | ||
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; |
1032 | 1021 | ||
1033 | if ( wait[SendFile] ) { | 1022 | if ( wait[SendFile] ) { |
1034 | QStringList targets; | 1023 | QStringList targets; |
1035 | if ( backupRestoreGzip( waitfile, targets ) ) | 1024 | if ( backupRestoreGzip( waitfile, targets ) ) |
1036 | dtp->sendGzipFile( waitfile, targets ); | 1025 | dtp->sendGzipFile( waitfile, targets ); |
1037 | else | 1026 | else |
1038 | dtp->sendFile( waitfile ); | 1027 | dtp->sendFile( waitfile ); |
1039 | dtp->setSocket( socket ); | 1028 | dtp->setSocket( 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 ); |
1045 | else | 1034 | else |
1046 | dtp->retrieveFile( waitfile, storFileSize ); | 1035 | dtp->retrieveFile( waitfile, storFileSize ); |
1047 | dtp->setSocket( socket ); | 1036 | dtp->setSocket( socket ); |
1048 | } | 1037 | } |
1049 | else if ( wait[SendByteArray] ) { | 1038 | else if ( wait[SendByteArray] ) { |
1050 | dtp->sendByteArray( waitarray ); | 1039 | dtp->sendByteArray( waitarray ); |
1051 | dtp->setSocket( socket ); | 1040 | dtp->setSocket( 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 ); |
1057 | } | 1046 | } |
1058 | else | 1047 | else |
1059 | waitsocket = socket; | 1048 | waitsocket = socket; |
1060 | 1049 | ||
1061 | for( int i = 0; i < 4; i++ ) | 1050 | for( int i = 0; i < 4; i++ ) |
1062 | wait[i] = FALSE; | 1051 | wait[i] = FALSE; |
1063 | } | 1052 | } |
1064 | 1053 | ||
1065 | QString ServerPI::absFilePath( const QString& file ) | 1054 | QString ServerPI::absFilePath( const QString& file ) |
1066 | { | 1055 | { |
@@ -1102,247 +1091,247 @@ ServerDTP::ServerDTP( QObject *parent, const char* name) | |||
1102 | SIGNAL( completed() ) ); | 1091 | SIGNAL( completed() ) ); |
1103 | connect( retrieveTargzProc, SIGNAL( processExited() ), | 1092 | connect( retrieveTargzProc, SIGNAL( processExited() ), |
1104 | SLOT( extractTarDone() ) ); | 1093 | SLOT( extractTarDone() ) ); |
1105 | } | 1094 | } |
1106 | 1095 | ||
1107 | ServerDTP::~ServerDTP() | 1096 | ServerDTP::~ServerDTP() |
1108 | { | 1097 | { |
1109 | buf.close(); | 1098 | buf.close(); |
1110 | if ( RetrieveFile == mode && file.isOpen() ) { | 1099 | if ( RetrieveFile == mode && file.isOpen() ) { |
1111 | // We're being shutdown before the client closed. | 1100 | // We're being shutdown before the client closed. |
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 | } |
1117 | } else { | 1106 | } else { |
1118 | file.close(); | 1107 | file.close(); |
1119 | } | 1108 | } |
1120 | createTargzProc->kill(); | 1109 | createTargzProc->kill(); |
1121 | } | 1110 | } |
1122 | 1111 | ||
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)" ); |
1128 | e << file.name(); | 1117 | e << file.name(); |
1129 | #endif | 1118 | #endif |
1130 | } | 1119 | } |
1131 | 1120 | ||
1132 | void ServerDTP::connected() | 1121 | void ServerDTP::connected() |
1133 | { | 1122 | { |
1134 | // send file mode | 1123 | // send file mode |
1135 | switch ( mode ) { | 1124 | switch ( mode ) { |
1136 | case SendFile : | 1125 | case SendFile : |
1137 | if ( !file.exists() || !file.open( IO_ReadOnly) ) { | 1126 | if ( !file.exists() || !file.open( IO_ReadOnly) ) { |
1138 | emit failed(); | 1127 | emit failed(); |
1139 | mode = Idle; | 1128 | mode = Idle; |
1140 | return; | 1129 | return; |
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; |
1146 | if ( file.size() == 0 ) { | 1135 | if ( file.size() == 0 ) { |
1147 | //make sure it doesn't hang on empty files | 1136 | //make sure it doesn't hang on empty files |
1148 | file.close(); | 1137 | file.close(); |
1149 | emit completed(); | 1138 | emit completed(); |
1150 | mode = Idle; | 1139 | mode = Idle; |
1151 | } else { | 1140 | } else { |
1152 | // Don't write more if there is plenty buffered already. | 1141 | // Don't write more if there is plenty buffered already. |
1153 | if ( bytesToWrite() <= block_size && !file.atEnd() ) { | 1142 | if ( bytesToWrite() <= block_size && !file.atEnd() ) { |
1154 | QCString s; | 1143 | QCString s; |
1155 | s.resize( block_size ); | 1144 | s.resize( block_size ); |
1156 | int bytes = file.readBlock( s.data(), block_size ); | 1145 | int bytes = file.readBlock( s.data(), block_size ); |
1157 | writeBlock( s.data(), bytes ); | 1146 | writeBlock( s.data(), bytes ); |
1158 | } | 1147 | } |
1159 | } | 1148 | } |
1160 | break; | 1149 | break; |
1161 | case SendGzipFile: | 1150 | case SendGzipFile: |
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", |
1172 | createTargzProc->arguments().join(" ").latin1()); | 1161 | createTargzProc->arguments().join(" ").latin1()); |
1173 | break; | 1162 | break; |
1174 | case SendBuffer: | 1163 | case SendBuffer: |
1175 | if ( !buf.open( IO_ReadOnly) ) { | 1164 | if ( !buf.open( IO_ReadOnly) ) { |
1176 | emit failed(); | 1165 | emit failed(); |
1177 | mode = Idle; | 1166 | mode = Idle; |
1178 | return; | 1167 | return; |
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() ) |
1184 | putch( buf.getch() ); | 1173 | putch( buf.getch() ); |
1185 | buf.close(); | 1174 | buf.close(); |
1186 | break; | 1175 | break; |
1187 | case RetrieveFile: | 1176 | case RetrieveFile: |
1188 | // retrieve file mode | 1177 | // retrieve file mode |
1189 | if ( file.exists() && !file.remove() ) { | 1178 | if ( file.exists() && !file.remove() ) { |
1190 | emit failed(); | 1179 | emit failed(); |
1191 | mode = Idle; | 1180 | mode = Idle; |
1192 | return; | 1181 | return; |
1193 | } | 1182 | } |
1194 | 1183 | ||
1195 | if ( !file.open( IO_WriteOnly) ) { | 1184 | if ( !file.open( IO_WriteOnly) ) { |
1196 | emit failed(); | 1185 | emit failed(); |
1197 | mode = Idle; | 1186 | mode = Idle; |
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: |
1206 | // retrieve buffer mode | 1195 | // retrieve buffer mode |
1207 | if ( !buf.open( IO_WriteOnly) ) { | 1196 | if ( !buf.open( IO_WriteOnly) ) { |
1208 | emit failed(); | 1197 | emit failed(); |
1209 | mode = Idle; | 1198 | mode = Idle; |
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 | } |
1218 | } | 1207 | } |
1219 | 1208 | ||
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 |
1225 | if ( SendFile == mode ) { | 1214 | if ( SendFile == mode ) { |
1226 | if ( bytes_written == file.size() ) | 1215 | if ( bytes_written == file.size() ) |
1227 | emit completed(); | 1216 | emit completed(); |
1228 | else | 1217 | else |
1229 | emit failed(); | 1218 | emit failed(); |
1230 | } | 1219 | } |
1231 | 1220 | ||
1232 | // send buffer mode | 1221 | // send buffer mode |
1233 | else if ( SendBuffer == mode ) { | 1222 | else if ( SendBuffer == mode ) { |
1234 | if ( bytes_written == buf.size() ) | 1223 | if ( bytes_written == buf.size() ) |
1235 | emit completed(); | 1224 | emit completed(); |
1236 | else | 1225 | else |
1237 | emit failed(); | 1226 | emit failed(); |
1238 | } | 1227 | } |
1239 | 1228 | ||
1240 | // retrieve file mode | 1229 | // retrieve file mode |
1241 | else if ( RetrieveFile == mode ) { | 1230 | else if ( RetrieveFile == mode ) { |
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(); |
1247 | } else { | 1236 | } else { |
1248 | emit completed(); | 1237 | emit completed(); |
1249 | } | 1238 | } |
1250 | } | 1239 | } |
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(); |
1256 | } | 1245 | } |
1257 | 1246 | ||
1258 | // retrieve buffer mode | 1247 | // retrieve buffer mode |
1259 | else if ( RetrieveBuffer == mode ) { | 1248 | else if ( RetrieveBuffer == mode ) { |
1260 | buf.close(); | 1249 | buf.close(); |
1261 | emit completed(); | 1250 | emit completed(); |
1262 | } | 1251 | } |
1263 | 1252 | ||
1264 | mode = Idle; | 1253 | mode = Idle; |
1265 | } | 1254 | } |
1266 | 1255 | ||
1267 | void ServerDTP::bytesWritten( int bytes ) | 1256 | void ServerDTP::bytesWritten( int bytes ) |
1268 | { | 1257 | { |
1269 | bytes_written += bytes; | 1258 | bytes_written += bytes; |
1270 | 1259 | ||
1271 | // send file mode | 1260 | // send file mode |
1272 | if ( SendFile == mode ) { | 1261 | if ( SendFile == mode ) { |
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(); |
1278 | mode = Idle; | 1267 | mode = Idle; |
1279 | } | 1268 | } |
1280 | else if( !file.atEnd() ) { | 1269 | else if( !file.atEnd() ) { |
1281 | QCString s; | 1270 | QCString s; |
1282 | s.resize( block_size ); | 1271 | s.resize( block_size ); |
1283 | int bytes = file.readBlock( s.data(), block_size ); | 1272 | int bytes = file.readBlock( s.data(), block_size ); |
1284 | writeBlock( s.data(), bytes ); | 1273 | writeBlock( s.data(), bytes ); |
1285 | } | 1274 | } |
1286 | } | 1275 | } |
1287 | 1276 | ||
1288 | // send buffer mode | 1277 | // send buffer mode |
1289 | if ( SendBuffer == mode ) { | 1278 | if ( SendBuffer == mode ) { |
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; |
1295 | } | 1284 | } |
1296 | } | 1285 | } |
1297 | } | 1286 | } |
1298 | 1287 | ||
1299 | void ServerDTP::readyRead() | 1288 | void ServerDTP::readyRead() |
1300 | { | 1289 | { |
1301 | // retrieve file mode | 1290 | // retrieve file mode |
1302 | if ( RetrieveFile == mode ) { | 1291 | if ( RetrieveFile == mode ) { |
1303 | QCString s; | 1292 | QCString s; |
1304 | s.resize( bytesAvailable() ); | 1293 | s.resize( bytesAvailable() ); |
1305 | readBlock( s.data(), bytesAvailable() ); | 1294 | readBlock( s.data(), bytesAvailable() ); |
1306 | file.writeBlock( s.data(), s.size() ); | 1295 | file.writeBlock( s.data(), s.size() ); |
1307 | } | 1296 | } |
1308 | else if ( RetrieveGzipFile == mode ) { | 1297 | else if ( RetrieveGzipFile == mode ) { |
1309 | if ( !retrieveTargzProc->isRunning() ) | 1298 | if ( !retrieveTargzProc->isRunning() ) |
1310 | retrieveTargzProc->start(); | 1299 | retrieveTargzProc->start(); |
1311 | 1300 | ||
1312 | QByteArray s; | 1301 | QByteArray s; |
1313 | s.resize( bytesAvailable() ); | 1302 | s.resize( bytesAvailable() ); |
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 |
1319 | else if ( RetrieveBuffer == mode ) { | 1308 | else if ( RetrieveBuffer == mode ) { |
1320 | QCString s; | 1309 | QCString s; |
1321 | s.resize( bytesAvailable() ); | 1310 | s.resize( bytesAvailable() ); |
1322 | readBlock( s.data(), bytesAvailable() ); | 1311 | readBlock( s.data(), bytesAvailable() ); |
1323 | buf.writeBlock( s.data(), s.size() ); | 1312 | buf.writeBlock( s.data(), s.size() ); |
1324 | } | 1313 | } |
1325 | } | 1314 | } |
1326 | 1315 | ||
1327 | void ServerDTP::writeTargzBlock() | 1316 | void ServerDTP::writeTargzBlock() |
1328 | { | 1317 | { |
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; |
1339 | disconnect( createTargzProc, SIGNAL( readyReadStdout() ), | 1328 | disconnect( createTargzProc, SIGNAL( readyReadStdout() ), |
1340 | this, SLOT( writeTargzBlock() ) ); | 1329 | this, SLOT( writeTargzBlock() ) ); |
1341 | } | 1330 | } |
1342 | 1331 | ||
1343 | void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) | 1332 | void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) |
1344 | { | 1333 | { |
1345 | file.setName( fn ); | 1334 | file.setName( fn ); |
1346 | mode = SendFile; | 1335 | mode = SendFile; |
1347 | connectToHost( host.toString(), port ); | 1336 | connectToHost( host.toString(), port ); |
1348 | } | 1337 | } |
@@ -1361,48 +1350,48 @@ void ServerDTP::sendGzipFile( const QString &fn, | |||
1361 | connectToHost( host.toString(), port ); | 1350 | connectToHost( host.toString(), port ); |
1362 | } | 1351 | } |
1363 | 1352 | ||
1364 | void ServerDTP::sendGzipFile( const QString &fn, | 1353 | void ServerDTP::sendGzipFile( const QString &fn, |
1365 | const QStringList &archiveTargets ) | 1354 | const QStringList &archiveTargets ) |
1366 | { | 1355 | { |
1367 | mode = SendGzipFile; | 1356 | mode = SendGzipFile; |
1368 | file.setName( fn ); | 1357 | file.setName( fn ); |
1369 | 1358 | ||
1370 | QStringList args = "targzip"; | 1359 | QStringList args = "targzip"; |
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, |
1376 | SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); | 1365 | SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); |
1377 | } | 1366 | } |
1378 | 1367 | ||
1379 | void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize ) | 1368 | void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize ) |
1380 | { | 1369 | { |
1381 | recvFileSize = fileSize; | 1370 | recvFileSize = fileSize; |
1382 | file.setName( fn ); | 1371 | file.setName( fn ); |
1383 | mode = RetrieveFile; | 1372 | mode = RetrieveFile; |
1384 | connectToHost( host.toString(), port ); | 1373 | connectToHost( host.toString(), port ); |
1385 | } | 1374 | } |
1386 | 1375 | ||
1387 | void ServerDTP::retrieveFile( const QString fn, int fileSize ) | 1376 | void ServerDTP::retrieveFile( const QString fn, int fileSize ) |
1388 | { | 1377 | { |
1389 | recvFileSize = fileSize; | 1378 | recvFileSize = fileSize; |
1390 | file.setName( fn ); | 1379 | file.setName( fn ); |
1391 | mode = RetrieveFile; | 1380 | mode = RetrieveFile; |
1392 | } | 1381 | } |
1393 | 1382 | ||
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; |
1399 | 1388 | ||
1400 | retrieveTargzProc->setArguments( "targunzip" ); | 1389 | retrieveTargzProc->setArguments( "targunzip" ); |
1401 | connect( retrieveTargzProc, SIGNAL( processExited() ), | 1390 | connect( retrieveTargzProc, SIGNAL( processExited() ), |
1402 | SLOT( extractTarDone() ) ); | 1391 | SLOT( extractTarDone() ) ); |
1403 | } | 1392 | } |
1404 | 1393 | ||
1405 | void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) | 1394 | void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) |
1406 | { | 1395 | { |
1407 | retrieveGzipFile( fn ); | 1396 | retrieveGzipFile( fn ); |
1408 | connectToHost( host.toString(), port ); | 1397 | connectToHost( host.toString(), port ); |