Diffstat (limited to 'core/launcher/transferserver.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/launcher/transferserver.cpp | 191 |
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 | |||
@@ -27,13 +27,14 @@ | |||
27 | 27 | ||
28 | /* we need the _OS_LINUX stuff first ! */ | 28 | /* we need the _OS_LINUX stuff first ! */ |
29 | #include <qglobal.h> | 29 | #include <qglobal.h> |
30 | 30 | ||
31 | #ifndef _OS_LINUX_ | 31 | #ifndef _OS_LINUX_ |
32 | 32 | ||
33 | extern "C" { | 33 | extern "C" |
34 | { | ||
34 | #include <uuid/uuid.h> | 35 | #include <uuid/uuid.h> |
35 | #define UUID_H_INCLUDED | 36 | #define UUID_H_INCLUDED |
36 | } | 37 | } |
37 | 38 | ||
38 | #endif // not defined linux | 39 | #endif // not defined linux |
39 | 40 | ||
@@ -56,13 +57,13 @@ extern "C" { | |||
56 | #include <qpe/contact.h> | 57 | #include <qpe/contact.h> |
57 | #include <qpe/quuid.h> | 58 | #include <qpe/quuid.h> |
58 | #include <qpe/version.h> | 59 | #include <qpe/version.h> |
59 | #include <qpe/qcopenvelope_qws.h> | 60 | #include <qpe/qcopenvelope_qws.h> |
60 | 61 | ||
61 | #include "transferserver.h" | 62 | #include "transferserver.h" |
62 | #include "qprocess.h" | 63 | #include <opie/oprocess.h> |
63 | 64 | ||
64 | const int block_size = 51200; | 65 | const int block_size = 51200; |
65 | 66 | ||
66 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent , | 67 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent , |
67 | const char* name ) | 68 | const char* name ) |
68 | : QServerSocket( port, 1, parent, name ) | 69 | : QServerSocket( port, 1, parent, name ) |
@@ -70,40 +71,44 @@ TransferServer::TransferServer( Q_UINT16 port, QObject *parent , | |||
70 | if ( !ok() ) | 71 | if ( !ok() ) |
71 | qWarning( "Failed to bind to port %d", port ); | 72 | qWarning( "Failed to bind to port %d", port ); |
72 | } | 73 | } |
73 | 74 | ||
74 | TransferServer::~TransferServer() | 75 | TransferServer::~TransferServer() |
75 | { | 76 | { |
76 | |||
77 | } | 77 | } |
78 | 78 | ||
79 | void TransferServer::newConnection( int socket ) | 79 | void TransferServer::newConnection( int socket ) |
80 | { | 80 | { |
81 | (void) new ServerPI( socket, this ); | 81 | (void) new ServerPI( socket, this ); |
82 | } | 82 | } |
83 | 83 | ||
84 | /* | 84 | /* |
85 | * small class in anonymous namespace | 85 | * small class in anonymous namespace |
86 | * to generate a QUUid for us | 86 | * to generate a QUUid for us |
87 | */ | 87 | */ |
88 | namespace { | 88 | namespace |
89 | struct UidGen { | 89 | { |
90 | struct UidGen | ||
91 | { | ||
90 | QString uuid(); | 92 | QString uuid(); |
91 | }; | 93 | }; |
92 | #if !defined(_OS_LINUX_) | 94 | #if !defined(_OS_LINUX_) |
93 | QString UidGen::uuid() { | 95 | |
96 | QString UidGen::uuid() | ||
97 | { | ||
94 | uuid_t uuid; | 98 | uuid_t uuid; |
95 | uuid_generate( uuid ); | 99 | uuid_generate( uuid ); |
96 | return QUUid( uuid ).toString(); | 100 | return QUUid( uuid ).toString(); |
97 | } | 101 | } |
98 | #else | 102 | #else |
99 | /* | 103 | /* |
100 | * linux got a /proc/sys/kernel/random/uuid file | 104 | * linux got a /proc/sys/kernel/random/uuid file |
101 | * it'll generate the uuids for us | 105 | * it'll generate the uuids for us |
102 | */ | 106 | */ |
103 | QString UidGen::uuid() { | 107 | QString UidGen::uuid() |
108 | { | ||
104 | QFile file( "/proc/sys/kernel/random/uuid" ); | 109 | QFile file( "/proc/sys/kernel/random/uuid" ); |
105 | if (!file.open(IO_ReadOnly ) ) | 110 | if (!file.open(IO_ReadOnly ) ) |
106 | return QString::null; | 111 | return QString::null; |
107 | 112 | ||
108 | QTextStream stream(&file); | 113 | QTextStream stream(&file); |
109 | 114 | ||
@@ -160,13 +165,14 @@ int SyncAuthentication::isAuthorized(QHostAddress peeraddress) | |||
160 | ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits)); | 165 | ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits)); |
161 | return (peeraddress.ip4Addr() & mask) == auth_peer; | 166 | return (peeraddress.ip4Addr() & mask) == auth_peer; |
162 | } | 167 | } |
163 | 168 | ||
164 | bool SyncAuthentication::checkUser( const QString& user ) | 169 | bool SyncAuthentication::checkUser( const QString& user ) |
165 | { | 170 | { |
166 | if ( user.isEmpty() ) return FALSE; | 171 | if ( user.isEmpty() ) |
172 | return FALSE; | ||
167 | QString euser = loginName(); | 173 | QString euser = loginName(); |
168 | return user == euser; | 174 | return user == euser; |
169 | } | 175 | } |
170 | 176 | ||
171 | bool SyncAuthentication::checkPassword( const QString& password ) | 177 | bool SyncAuthentication::checkPassword( const QString& password ) |
172 | { | 178 | { |
@@ -227,18 +233,18 @@ bool SyncAuthentication::checkPassword( const QString& password ) | |||
227 | // Unrecognized system. Be careful... | 233 | // Unrecognized system. Be careful... |
228 | 234 | ||
229 | if ( (denials > 2 && now < lastdenial+600) | 235 | if ( (denials > 2 && now < lastdenial+600) |
230 | || QMessageBox::warning(0,tr("Sync Connection"), | 236 | || QMessageBox::warning(0,tr("Sync Connection"), |
231 | tr("<p>An unrecognized system is requesting access to this device." | 237 | tr("<p>An unrecognized system is requesting access to this device." |
232 | "<p>If you have just initiated a Sync for the first time, this is normal."), | 238 | "<p>If you have just initiated a Sync for the first time, this is normal."), |
233 | tr("Allow"),tr("Deny"), 0, 1, 1 ) ==1 ) | 239 | tr("Allow"), tr("Deny"), 0, 1, 1 ) == 1 ) { |
234 | { | ||
235 | denials++; | 240 | denials++; |
236 | lastdenial=now; | 241 | lastdenial=now; |
237 | return FALSE; | 242 | return FALSE; |
238 | } else { | 243 | } |
244 | else { | ||
239 | denials=0; | 245 | denials=0; |
240 | cfg.writeEntry("Passwords",pwds+" "+cpassword); | 246 | cfg.writeEntry("Passwords",pwds+" "+cpassword); |
241 | return TRUE; | 247 | return TRUE; |
242 | } | 248 | } |
243 | } | 249 | } |
244 | 250 | ||
@@ -253,16 +259,18 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name ) | |||
253 | setSocket( socket ); | 259 | setSocket( socket ); |
254 | 260 | ||
255 | peerport = peerPort(); | 261 | peerport = peerPort(); |
256 | peeraddress = peerAddress(); | 262 | peeraddress = peerAddress(); |
257 | 263 | ||
258 | #ifndef INSECURE | 264 | #ifndef INSECURE |
265 | |||
259 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { | 266 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { |
260 | state = Forbidden; | 267 | state = Forbidden; |
261 | startTimer( 0 ); | 268 | startTimer( 0 ); |
262 | } else | 269 | } |
270 | else | ||
263 | #endif | 271 | #endif |
264 | { | 272 | { |
265 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); | 273 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); |
266 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 274 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
267 | 275 | ||
268 | passiv = FALSE; | 276 | passiv = FALSE; |
@@ -290,13 +298,12 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name ) | |||
290 | SLOT( newConnection( int ) ) ); | 298 | SLOT( newConnection( int ) ) ); |
291 | } | 299 | } |
292 | } | 300 | } |
293 | 301 | ||
294 | ServerPI::~ServerPI() | 302 | ServerPI::~ServerPI() |
295 | { | 303 | { |
296 | |||
297 | } | 304 | } |
298 | 305 | ||
299 | void ServerPI::connectionClosed() | 306 | void ServerPI::connectionClosed() |
300 | { | 307 | { |
301 | // qDebug( "Debug: Connection closed" ); | 308 | // qDebug( "Debug: Connection closed" ); |
302 | delete this; | 309 | delete this; |
@@ -348,13 +355,14 @@ bool ServerPI::checkWriteFile( const QString& file ) | |||
348 | void ServerPI::process( const QString& message ) | 355 | void ServerPI::process( const QString& message ) |
349 | { | 356 | { |
350 | //qDebug( "Command: %s", message.latin1() ); | 357 | //qDebug( "Command: %s", message.latin1() ); |
351 | 358 | ||
352 | // split message using "," as separator | 359 | // split message using "," as separator |
353 | QStringList msg = QStringList::split( " ", message ); | 360 | QStringList msg = QStringList::split( " ", message ); |
354 | if ( msg.isEmpty() ) return; | 361 | if ( msg.isEmpty() ) |
362 | return ; | ||
355 | 363 | ||
356 | // command token | 364 | // command token |
357 | QString cmd = msg[0].upper(); | 365 | QString cmd = msg[0].upper(); |
358 | 366 | ||
359 | // argument token | 367 | // argument token |
360 | QString arg; | 368 | QString arg; |
@@ -587,13 +595,14 @@ void ServerPI::process( const QString& message ) | |||
587 | else { | 595 | else { |
588 | QFile file( absFilePath( args ) ) ; | 596 | QFile file( absFilePath( args ) ) ; |
589 | if ( file.remove() ) { | 597 | if ( file.remove() ) { |
590 | send( "250 Requested file action okay, completed" ); | 598 | send( "250 Requested file action okay, completed" ); |
591 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); | 599 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); |
592 | e << file.name(); | 600 | e << file.name(); |
593 | } else { | 601 | } |
602 | else { | ||
594 | send( "550 Requested action not taken" ); | 603 | send( "550 Requested action not taken" ); |
595 | } | 604 | } |
596 | } | 605 | } |
597 | } | 606 | } |
598 | 607 | ||
599 | // remove directory (RMD) | 608 | // remove directory (RMD) |
@@ -731,13 +740,14 @@ void ServerPI::sendFile( const QString& file ) | |||
731 | newConnection( waitsocket ); | 740 | newConnection( waitsocket ); |
732 | } | 741 | } |
733 | else { | 742 | else { |
734 | QStringList targets; | 743 | QStringList targets; |
735 | if ( backupRestoreGzip( file, targets ) ) | 744 | if ( backupRestoreGzip( file, targets ) ) |
736 | dtp->sendGzipFile( file, targets, peeraddress, peerport ); | 745 | dtp->sendGzipFile( file, targets, peeraddress, peerport ); |
737 | else dtp->sendFile( file, peeraddress, peerport ); | 746 | else |
747 | dtp->sendFile( file, peeraddress, peerport ); | ||
738 | } | 748 | } |
739 | } | 749 | } |
740 | 750 | ||
741 | void ServerPI::retrieveFile( const QString& file ) | 751 | void ServerPI::retrieveFile( const QString& file ) |
742 | { | 752 | { |
743 | if ( passiv ) { | 753 | if ( passiv ) { |
@@ -755,13 +765,14 @@ void ServerPI::retrieveFile( const QString& file ) | |||
755 | } | 765 | } |
756 | } | 766 | } |
757 | 767 | ||
758 | bool ServerPI::parsePort( const QString& pp ) | 768 | bool ServerPI::parsePort( const QString& pp ) |
759 | { | 769 | { |
760 | QStringList p = QStringList::split( ",", pp ); | 770 | QStringList p = QStringList::split( ",", pp ); |
761 | if ( p.count() != 6 ) return FALSE; | 771 | if ( p.count() != 6 ) |
772 | return FALSE; | ||
762 | 773 | ||
763 | // h1,h2,h3,h4,p1,p2 | 774 | // h1,h2,h3,h4,p1,p2 |
764 | peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + | 775 | peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + |
765 | ( p[2].toInt() << 8 ) + p[3].toInt() ); | 776 | ( p[2].toInt() << 8 ) + p[3].toInt() ); |
766 | peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); | 777 | peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); |
767 | return TRUE; | 778 | return TRUE; |
@@ -807,13 +818,14 @@ bool ServerPI::sendList( const QString& arg ) | |||
807 | QString fn = arg; | 818 | QString fn = arg; |
808 | 819 | ||
809 | if ( fn.isEmpty() ) | 820 | if ( fn.isEmpty() ) |
810 | fn = directory.path(); | 821 | fn = directory.path(); |
811 | 822 | ||
812 | QFileInfo fi( fn ); | 823 | QFileInfo fi( fn ); |
813 | if ( !fi.exists() ) return FALSE; | 824 | if ( !fi.exists() ) |
825 | return FALSE; | ||
814 | 826 | ||
815 | // return file listing | 827 | // return file listing |
816 | if ( fi.isFile() ) { | 828 | if ( fi.isFile() ) { |
817 | ts << fileListing( &fi ) << endl; | 829 | ts << fileListing( &fi ) << endl; |
818 | } | 830 | } |
819 | 831 | ||
@@ -855,13 +867,14 @@ bool ServerPI::sendList( const QString& arg ) | |||
855 | dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); | 867 | dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); |
856 | return TRUE; | 868 | return TRUE; |
857 | } | 869 | } |
858 | 870 | ||
859 | QString ServerPI::fileListing( QFileInfo *info ) | 871 | QString ServerPI::fileListing( QFileInfo *info ) |
860 | { | 872 | { |
861 | if ( !info ) return QString::null; | 873 | if ( !info ) |
874 | return QString::null; | ||
862 | QString s; | 875 | QString s; |
863 | 876 | ||
864 | // type char | 877 | // type char |
865 | if ( info->isDir() ) | 878 | if ( info->isDir() ) |
866 | s += "d"; | 879 | s += "d"; |
867 | else if ( info->isSymLink() ) | 880 | else if ( info->isSymLink() ) |
@@ -905,47 +918,67 @@ QString ServerPI::fileListing( QFileInfo *info ) | |||
905 | 918 | ||
906 | return s; | 919 | return s; |
907 | } | 920 | } |
908 | 921 | ||
909 | QString ServerPI::permissionString( QFileInfo *info ) | 922 | QString ServerPI::permissionString( QFileInfo *info ) |
910 | { | 923 | { |
911 | if ( !info ) return QString( "---------" ); | 924 | if ( !info ) |
925 | return QString( "---------" ); | ||
912 | QString s; | 926 | QString s; |
913 | 927 | ||
914 | // user | 928 | // user |
915 | if ( info->permission( QFileInfo::ReadUser ) ) s += "r"; | 929 | if ( info->permission( QFileInfo::ReadUser ) ) |
916 | else s += "-"; | 930 | s += "r"; |
917 | if ( info->permission( QFileInfo::WriteUser ) ) s += "w"; | 931 | else |
918 | else s += "-"; | 932 | s += "-"; |
919 | if ( info->permission( QFileInfo::ExeUser ) ) s += "x"; | 933 | if ( info->permission( QFileInfo::WriteUser ) ) |
920 | else s += "-"; | 934 | s += "w"; |
935 | else | ||
936 | s += "-"; | ||
937 | if ( info->permission( QFileInfo::ExeUser ) ) | ||
938 | s += "x"; | ||
939 | else | ||
940 | s += "-"; | ||
921 | 941 | ||
922 | // group | 942 | // group |
923 | if ( info->permission( QFileInfo::ReadGroup ) ) s += "r"; | 943 | if ( info->permission( QFileInfo::ReadGroup ) ) |
924 | else s += "-"; | 944 | s += "r"; |
925 | if ( info->permission( QFileInfo::WriteGroup ) )s += "w"; | 945 | else |
926 | else s += "-"; | 946 | s += "-"; |
927 | if ( info->permission( QFileInfo::ExeGroup ) ) s += "x"; | 947 | if ( info->permission( QFileInfo::WriteGroup ) ) |
928 | else s += "-"; | 948 | s += "w"; |
949 | else | ||
950 | s += "-"; | ||
951 | if ( info->permission( QFileInfo::ExeGroup ) ) | ||
952 | s += "x"; | ||
953 | else | ||
954 | s += "-"; | ||
929 | 955 | ||
930 | // exec | 956 | // exec |
931 | if ( info->permission( QFileInfo::ReadOther ) ) s += "r"; | 957 | if ( info->permission( QFileInfo::ReadOther ) ) |
932 | else s += "-"; | 958 | s += "r"; |
933 | if ( info->permission( QFileInfo::WriteOther ) ) s += "w"; | 959 | else |
934 | else s += "-"; | 960 | s += "-"; |
935 | if ( info->permission( QFileInfo::ExeOther ) ) s += "x"; | 961 | if ( info->permission( QFileInfo::WriteOther ) ) |
936 | else s += "-"; | 962 | s += "w"; |
963 | else | ||
964 | s += "-"; | ||
965 | if ( info->permission( QFileInfo::ExeOther ) ) | ||
966 | s += "x"; | ||
967 | else | ||
968 | s += "-"; | ||
937 | 969 | ||
938 | return s; | 970 | return s; |
939 | } | 971 | } |
940 | 972 | ||
941 | void ServerPI::newConnection( int socket ) | 973 | void ServerPI::newConnection( int socket ) |
942 | { | 974 | { |
943 | //qDebug( "New incomming connection" ); | 975 | //qDebug( "New incomming connection" ); |
944 | 976 | ||
945 | if ( !passiv ) return; | 977 | if ( !passiv ) |
978 | return ; | ||
946 | 979 | ||
947 | if ( wait[SendFile] ) { | 980 | if ( wait[SendFile] ) { |
948 | QStringList targets; | 981 | QStringList targets; |
949 | if ( backupRestoreGzip( waitfile, targets ) ) | 982 | if ( backupRestoreGzip( waitfile, targets ) ) |
950 | dtp->sendGzipFile( waitfile, targets ); | 983 | dtp->sendGzipFile( waitfile, targets ); |
951 | else | 984 | else |
@@ -975,13 +1008,14 @@ void ServerPI::newConnection( int socket ) | |||
975 | for( int i = 0; i < 4; i++ ) | 1008 | for( int i = 0; i < 4; i++ ) |
976 | wait[i] = FALSE; | 1009 | wait[i] = FALSE; |
977 | } | 1010 | } |
978 | 1011 | ||
979 | QString ServerPI::absFilePath( const QString& file ) | 1012 | QString ServerPI::absFilePath( const QString& file ) |
980 | { | 1013 | { |
981 | if ( file.isEmpty() ) return file; | 1014 | if ( file.isEmpty() ) |
1015 | return file; | ||
982 | 1016 | ||
983 | QString filepath( file ); | 1017 | QString filepath( file ); |
984 | if ( file[0] != "/" ) | 1018 | if ( file[0] != "/" ) |
985 | filepath = directory.path() + "/" + file; | 1019 | filepath = directory.path() + "/" + file; |
986 | 1020 | ||
987 | return filepath; | 1021 | return filepath; |
@@ -1001,28 +1035,25 @@ retrieveTargzProc( 0 ), gzipProc( 0 ) | |||
1001 | 1035 | ||
1002 | connect( this, SIGNAL( connected() ), SLOT( connected() ) ); | 1036 | connect( this, SIGNAL( connected() ), SLOT( connected() ) ); |
1003 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 1037 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
1004 | connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); | 1038 | connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); |
1005 | connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); | 1039 | connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); |
1006 | 1040 | ||
1007 | gzipProc = new QProcess( this, "gzipProc" ); | 1041 | gzipProc = new OProcess( this, "gzipProc" ); |
1008 | gzipProc->setCommunication( QProcess::Stdin | QProcess::Stdout ); | ||
1009 | 1042 | ||
1010 | createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); | 1043 | createTargzProc = new OProcess( QString("tar"), this, "createTargzProc"); |
1011 | createTargzProc->setCommunication( QProcess::Stdout ); | ||
1012 | createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); | 1044 | createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); |
1013 | connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); | 1045 | connect( createTargzProc, SIGNAL( processExited(OProcess *) ), SLOT( targzDone() ) ); |
1014 | 1046 | ||
1015 | QStringList args = "tar"; | 1047 | QStringList args = "tar"; |
1016 | args += "-xv"; | 1048 | args += "-xv"; |
1017 | retrieveTargzProc = new QProcess( args, this, "retrieveTargzProc" ); | 1049 | retrieveTargzProc = new OProcess( args, this, "retrieveTargzProc" ); |
1018 | retrieveTargzProc->setCommunication( QProcess::Stdin ); | ||
1019 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); | 1050 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); |
1020 | connect( retrieveTargzProc, SIGNAL( processExited() ), | 1051 | connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ), |
1021 | SIGNAL( completed() ) ); | 1052 | SIGNAL( completed() ) ); |
1022 | connect( retrieveTargzProc, SIGNAL( processExited() ), | 1053 | connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ), |
1023 | SLOT( extractTarDone() ) ); | 1054 | SLOT( extractTarDone() ) ); |
1024 | } | 1055 | } |
1025 | 1056 | ||
1026 | ServerDTP::~ServerDTP() | 1057 | ServerDTP::~ServerDTP() |
1027 | { | 1058 | { |
1028 | buf.close(); | 1059 | buf.close(); |
@@ -1031,12 +1062,13 @@ ServerDTP::~ServerDTP() | |||
1031 | } | 1062 | } |
1032 | 1063 | ||
1033 | void ServerDTP::extractTarDone() | 1064 | void ServerDTP::extractTarDone() |
1034 | { | 1065 | { |
1035 | qDebug("extract done"); | 1066 | qDebug("extract done"); |
1036 | #ifndef QT_NO_COP | 1067 | #ifndef QT_NO_COP |
1068 | |||
1037 | QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); | 1069 | QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); |
1038 | e << file.name(); | 1070 | e << file.name(); |
1039 | #endif | 1071 | #endif |
1040 | } | 1072 | } |
1041 | 1073 | ||
1042 | void ServerDTP::connected() | 1074 | void ServerDTP::connected() |
@@ -1055,13 +1087,14 @@ void ServerDTP::connected() | |||
1055 | bytes_written = 0; | 1087 | bytes_written = 0; |
1056 | if ( file.size() == 0 ) { | 1088 | if ( file.size() == 0 ) { |
1057 | //make sure it doesn't hang on empty files | 1089 | //make sure it doesn't hang on empty files |
1058 | file.close(); | 1090 | file.close(); |
1059 | emit completed(); | 1091 | emit completed(); |
1060 | mode = Idle; | 1092 | mode = Idle; |
1061 | } else { | 1093 | } |
1094 | else { | ||
1062 | 1095 | ||
1063 | if( !file.atEnd() ) { | 1096 | if( !file.atEnd() ) { |
1064 | QCString s; | 1097 | QCString s; |
1065 | s.resize( block_size ); | 1098 | s.resize( block_size ); |
1066 | int bytes = file.readBlock( s.data(), block_size ); | 1099 | int bytes = file.readBlock( s.data(), block_size ); |
1067 | writeBlock( s.data(), bytes ); | 1100 | writeBlock( s.data(), bytes ); |
@@ -1074,16 +1107,16 @@ void ServerDTP::connected() | |||
1074 | qWarning("Previous tar --gzip process is still running; killing it..."); | 1107 | qWarning("Previous tar --gzip process is still running; killing it..."); |
1075 | createTargzProc->kill(); | 1108 | createTargzProc->kill(); |
1076 | } | 1109 | } |
1077 | 1110 | ||
1078 | bytes_written = 0; | 1111 | bytes_written = 0; |
1079 | qDebug("==>start send tar process"); | 1112 | qDebug("==>start send tar process"); |
1080 | if ( !createTargzProc->start() ) | 1113 | if ( !createTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdout) ) |
1081 | qWarning("Error starting %s or %s", | 1114 | qWarning("Error starting %s or %s", |
1082 | createTargzProc->arguments().join(" ").latin1(), | 1115 | createTargzProc->args()[0].data(), |
1083 | gzipProc->arguments().join(" ").latin1() ); | 1116 | gzipProc->args()[0].data()); |
1084 | break; | 1117 | break; |
1085 | case SendBuffer: | 1118 | case SendBuffer: |
1086 | if ( !buf.open( IO_ReadOnly) ) { | 1119 | if ( !buf.open( IO_ReadOnly) ) { |
1087 | emit failed(); | 1120 | emit failed(); |
1088 | mode = Idle; | 1121 | mode = Idle; |
1089 | return; | 1122 | return; |
@@ -1209,59 +1242,58 @@ void ServerDTP::readyRead() | |||
1209 | s.resize( bytesAvailable() ); | 1242 | s.resize( bytesAvailable() ); |
1210 | readBlock( s.data(), bytesAvailable() ); | 1243 | readBlock( s.data(), bytesAvailable() ); |
1211 | file.writeBlock( s.data(), s.size() ); | 1244 | file.writeBlock( s.data(), s.size() ); |
1212 | } | 1245 | } |
1213 | else if ( RetrieveGzipFile == mode ) { | 1246 | else if ( RetrieveGzipFile == mode ) { |
1214 | if ( !gzipProc->isRunning() ) | 1247 | if ( !gzipProc->isRunning() ) |
1215 | gzipProc->start(); | 1248 | gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout )); |
1216 | 1249 | ||
1217 | QByteArray s; | 1250 | QByteArray s; |
1218 | s.resize( bytesAvailable() ); | 1251 | s.resize( bytesAvailable() ); |
1219 | readBlock( s.data(), bytesAvailable() ); | 1252 | readBlock( s.data(), bytesAvailable() ); |
1220 | gzipProc->writeToStdin( s ); | 1253 | gzipProc->writeStdin( s.data(), s.size() ); |
1221 | qDebug("wrote %d bytes to ungzip ", s.size() ); | 1254 | qDebug("wrote %d bytes to ungzip ", s.size() ); |
1222 | } | 1255 | } |
1223 | // retrieve buffer mode | 1256 | // retrieve buffer mode |
1224 | else if ( RetrieveBuffer == mode ) { | 1257 | else if ( RetrieveBuffer == mode ) { |
1225 | QCString s; | 1258 | QCString s; |
1226 | s.resize( bytesAvailable() ); | 1259 | s.resize( bytesAvailable() ); |
1227 | readBlock( s.data(), bytesAvailable() ); | 1260 | readBlock( s.data(), bytesAvailable() ); |
1228 | buf.writeBlock( s.data(), s.size() ); | 1261 | buf.writeBlock( s.data(), s.size() ); |
1229 | } | 1262 | } |
1230 | } | 1263 | } |
1231 | 1264 | ||
1232 | void ServerDTP::writeTargzBlock() | 1265 | void ServerDTP::writeTargzBlock(OProcess *, char *buffer, int buflen) |
1233 | { | 1266 | { |
1234 | QByteArray block = gzipProc->readStdout(); | 1267 | writeBlock( buffer, buflen ); |
1235 | writeBlock( block.data(), block.size() ); | 1268 | qDebug("writeTargzBlock %d", buflen); |
1236 | qDebug("writeTargzBlock %d", block.size()); | ||
1237 | if ( !createTargzProc->isRunning() ) { | 1269 | if ( !createTargzProc->isRunning() ) { |
1238 | qDebug("tar and gzip done"); | 1270 | qDebug("tar and gzip done"); |
1239 | emit completed(); | 1271 | emit completed(); |
1240 | mode = Idle; | 1272 | mode = Idle; |
1241 | disconnect( gzipProc, SIGNAL( readyReadStdout() ), | 1273 | disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int ) ), |
1242 | this, SLOT( writeTargzBlock() ) ); | 1274 | this, SLOT( writeTargzBlock(OProcess *, char *, int) ) ); |
1243 | } | 1275 | } |
1244 | } | 1276 | } |
1245 | 1277 | ||
1246 | void ServerDTP::targzDone() | 1278 | void ServerDTP::targzDone() |
1247 | { | 1279 | { |
1248 | //qDebug("targz done"); | 1280 | //qDebug("targz done"); |
1249 | disconnect( createTargzProc, SIGNAL( readyReadStdout() ), | 1281 | disconnect( createTargzProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), |
1250 | this, SLOT( gzipTarBlock() ) ); | 1282 | this, SLOT( gzipTarBlock(OProcess *, char *, int) ) ); |
1251 | gzipProc->closeStdin(); | 1283 | gzipProc->closeStdin(); |
1252 | } | 1284 | } |
1253 | 1285 | ||
1254 | void ServerDTP::gzipTarBlock() | 1286 | void ServerDTP::gzipTarBlock(OProcess *, char *buffer, int buflen) |
1255 | { | 1287 | { |
1256 | //qDebug("gzipTarBlock"); | 1288 | //qDebug("gzipTarBlock"); |
1257 | if ( !gzipProc->isRunning() ) { | 1289 | if ( !gzipProc->isRunning() ) { |
1258 | //qDebug("auto start gzip proc"); | 1290 | //qDebug("auto start gzip proc"); |
1259 | gzipProc->start(); | 1291 | gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout )); |
1260 | } | 1292 | } |
1261 | gzipProc->writeToStdin( createTargzProc->readStdout() ); | 1293 | gzipProc->writeStdin( buffer, buflen ); |
1262 | } | 1294 | } |
1263 | 1295 | ||
1264 | void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) | 1296 | void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) |
1265 | { | 1297 | { |
1266 | file.setName( fn ); | 1298 | file.setName( fn ); |
1267 | mode = SendFile; | 1299 | mode = SendFile; |
@@ -1289,40 +1321,42 @@ void ServerDTP::sendGzipFile( const QString &fn, | |||
1289 | file.setName( fn ); | 1321 | file.setName( fn ); |
1290 | 1322 | ||
1291 | QStringList args = "tar"; | 1323 | QStringList args = "tar"; |
1292 | args += "-cv"; | 1324 | args += "-cv"; |
1293 | args += archiveTargets; | 1325 | args += archiveTargets; |
1294 | qDebug("sendGzipFile %s", args.join(" ").latin1() ); | 1326 | qDebug("sendGzipFile %s", args.join(" ").latin1() ); |
1295 | createTargzProc->setArguments( args ); | 1327 | createTargzProc->clearArguments( ); |
1328 | *createTargzProc << args; | ||
1296 | connect( createTargzProc, | 1329 | connect( createTargzProc, |
1297 | SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) ); | 1330 | SIGNAL( receivedStdout(OProcess *, char *, int) ), SLOT( gzipTarBlock(OProcess *, char *, int) ) ); |
1298 | 1331 | ||
1299 | gzipProc->setArguments( "gzip" ); | 1332 | gzipProc->clearArguments( ); |
1300 | connect( gzipProc, SIGNAL( readyReadStdout() ), | 1333 | *gzipProc << "gzip"; |
1301 | SLOT( writeTargzBlock() ) ); | 1334 | connect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), |
1335 | SLOT( writeTargzBlock(OProcess *, char *, int) ) ); | ||
1302 | } | 1336 | } |
1303 | 1337 | ||
1304 | void ServerDTP::gunzipDone() | 1338 | void ServerDTP::gunzipDone() |
1305 | { | 1339 | { |
1306 | qDebug("gunzipDone"); | 1340 | qDebug("gunzipDone"); |
1307 | disconnect( gzipProc, SIGNAL( processExited() ), | 1341 | disconnect( gzipProc, SIGNAL( processExited() ), |
1308 | this, SLOT( gunzipDone() ) ); | 1342 | this, SLOT( gunzipDone() ) ); |
1309 | retrieveTargzProc->closeStdin(); | 1343 | retrieveTargzProc->closeStdin(); |
1310 | disconnect( gzipProc, SIGNAL( readyReadStdout() ), | 1344 | disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), |
1311 | this, SLOT( tarExtractBlock() ) ); | 1345 | this, SLOT( tarExtractBlock(OProcess *, char *, int) ) ); |
1312 | } | 1346 | } |
1313 | 1347 | ||
1314 | void ServerDTP::tarExtractBlock() | 1348 | void ServerDTP::tarExtractBlock(OProcess *, char *buffer, int buflen) |
1315 | { | 1349 | { |
1316 | qDebug("ungzipTarBlock"); | 1350 | qDebug("tarExtractBlock"); |
1317 | if ( !retrieveTargzProc->isRunning() ) { | 1351 | if ( !retrieveTargzProc->isRunning() ) { |
1318 | qDebug("auto start ungzip proc"); | 1352 | qDebug("auto start ungzip proc"); |
1319 | if ( !retrieveTargzProc->start() ) | 1353 | if ( !retrieveTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdin) ) |
1320 | qWarning(" failed to start tar -x process"); | 1354 | qWarning(" failed to start tar -x process"); |
1321 | } | 1355 | } |
1322 | retrieveTargzProc->writeToStdin( gzipProc->readStdout() ); | 1356 | retrieveTargzProc->writeStdin( buffer, buflen ); |
1323 | } | 1357 | } |
1324 | 1358 | ||
1325 | 1359 | ||
1326 | void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) | 1360 | void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) |
1327 | { | 1361 | { |
1328 | file.setName( fn ); | 1362 | file.setName( fn ); |
@@ -1339,13 +1373,14 @@ void ServerDTP::retrieveFile( const QString fn ) | |||
1339 | void ServerDTP::retrieveGzipFile( const QString &fn ) | 1373 | void ServerDTP::retrieveGzipFile( const QString &fn ) |
1340 | { | 1374 | { |
1341 | qDebug("retrieveGzipFile %s", fn.latin1()); | 1375 | qDebug("retrieveGzipFile %s", fn.latin1()); |
1342 | file.setName( fn ); | 1376 | file.setName( fn ); |
1343 | mode = RetrieveGzipFile; | 1377 | mode = RetrieveGzipFile; |
1344 | 1378 | ||
1345 | gzipProc->setArguments( "gunzip" ); | 1379 | gzipProc->clearArguments(); |
1380 | *gzipProc << "gunzip"; | ||
1346 | connect( gzipProc, SIGNAL( readyReadStdout() ), | 1381 | connect( gzipProc, SIGNAL( readyReadStdout() ), |
1347 | SLOT( tarExtractBlock() ) ); | 1382 | SLOT( tarExtractBlock() ) ); |
1348 | connect( gzipProc, SIGNAL( processExited() ), | 1383 | connect( gzipProc, SIGNAL( processExited() ), |
1349 | SLOT( gunzipDone() ) ); | 1384 | SLOT( gunzipDone() ) ); |
1350 | } | 1385 | } |
1351 | 1386 | ||