-rw-r--r-- | core/qws/qcopbridge.cpp | 10 | ||||
-rw-r--r-- | core/qws/transferserver.cpp | 32 |
2 files changed, 21 insertions, 21 deletions
diff --git a/core/qws/qcopbridge.cpp b/core/qws/qcopbridge.cpp index c0c52e8..4fd0807 100644 --- a/core/qws/qcopbridge.cpp +++ b/core/qws/qcopbridge.cpp | |||
@@ -9,118 +9,118 @@ | |||
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 | 20 | ||
21 | #include "qcopbridge.h" | 21 | #include "qcopbridge.h" |
22 | #include "transferserver.h" | 22 | #include "transferserver.h" |
23 | 23 | ||
24 | #include <qpe/qcopenvelope_qws.h> | 24 | #include <qpe/qcopenvelope_qws.h> |
25 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
26 | #include <qpe/version.h> | 26 | #include <qpe/version.h> |
27 | 27 | ||
28 | #include <qtextstream.h> | 28 | #include <qtextstream.h> |
29 | #ifdef QWS | 29 | #ifdef QWS |
30 | #include <qcopchannel_qws.h> | 30 | #include <qcopchannel_qws.h> |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | #define _XOPEN_SOURCE | 33 | #define _XOPEN_SOURCE |
34 | #include <pwd.h> | 34 | #include <pwd.h> |
35 | #include <sys/types.h> | 35 | #include <sys/types.h> |
36 | #include <unistd.h> | 36 | #include <unistd.h> |
37 | 37 | ||
38 | #if defined(_OS_LINUX_) | 38 | #if defined(_OS_LINUX_) |
39 | #include <shadow.h> | 39 | #include <shadow.h> |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | //#define INSECURE | 42 | //#define INSECURE |
43 | 43 | ||
44 | const int block_size = 51200; | 44 | const int block_size = 51200; |
45 | 45 | ||
46 | QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent , | 46 | QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent , |
47 | const char* name ) | 47 | const char* name ) |
48 | : QServerSocket( port, 1, parent, name ), | 48 | : QServerSocket( port, 1, parent, name ), |
49 | desktopChannel( 0 ), | 49 | desktopChannel( 0 ), |
50 | cardChannel( 0 ) | 50 | cardChannel( 0 ) |
51 | { | 51 | { |
52 | if ( !ok() ) | 52 | if ( !ok() ) |
53 | qWarning( "Failed to bind to port %d", port ); | 53 | qWarning( "Failed to bind to port %d", port ); |
54 | else { | 54 | else { |
55 | #ifndef QT_NO_COP | 55 | #ifndef QT_NO_COP |
56 | desktopChannel = new QCopChannel( "QPE/Desktop", this ); | 56 | desktopChannel = new QCopChannel( "QPE/Desktop", this ); |
57 | connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)), | 57 | connect( desktopChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
58 | this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); | 58 | this, SLOT(desktopMessage(const QCString&,const QByteArray&)) ); |
59 | cardChannel = new QCopChannel( "QPE/Card", this ); | 59 | cardChannel = new QCopChannel( "QPE/Card", this ); |
60 | connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), | 60 | connect( cardChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
61 | this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); | 61 | this, SLOT(desktopMessage(const QCString&,const QByteArray&)) ); |
62 | #endif | 62 | #endif |
63 | } | 63 | } |
64 | sendSync = FALSE; | 64 | sendSync = FALSE; |
65 | } | 65 | } |
66 | 66 | ||
67 | QCopBridge::~QCopBridge() | 67 | QCopBridge::~QCopBridge() |
68 | { | 68 | { |
69 | #ifndef QT_NO_COP | 69 | #ifndef QT_NO_COP |
70 | delete desktopChannel; | 70 | delete desktopChannel; |
71 | #endif | 71 | #endif |
72 | } | 72 | } |
73 | 73 | ||
74 | void QCopBridge::newConnection( int socket ) | 74 | void QCopBridge::newConnection( int socket ) |
75 | { | 75 | { |
76 | QCopBridgePI *pi = new QCopBridgePI( socket, this ); | 76 | QCopBridgePI *pi = new QCopBridgePI( socket, this ); |
77 | openConnections.append( pi ); | 77 | openConnections.append( pi ); |
78 | connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) ); | 78 | connect ( pi, SIGNAL( connectionClosed(QCopBridgePI*) ), this, SLOT( connectionClosed(QCopBridgePI*) ) ); |
79 | #ifndef QT_NO_COP | 79 | #ifndef QT_NO_COP |
80 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; | 80 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; |
81 | #endif | 81 | #endif |
82 | 82 | ||
83 | if ( sendSync ) { | 83 | if ( sendSync ) { |
84 | pi ->startSync(); | 84 | pi ->startSync(); |
85 | sendSync = FALSE; | 85 | sendSync = FALSE; |
86 | } | 86 | } |
87 | } | 87 | } |
88 | 88 | ||
89 | void QCopBridge::connectionClosed( QCopBridgePI *pi ) | 89 | void QCopBridge::connectionClosed( QCopBridgePI *pi ) |
90 | { | 90 | { |
91 | openConnections.remove( pi ); | 91 | openConnections.remove( pi ); |
92 | if ( openConnections.count() == 0 ) { | 92 | if ( openConnections.count() == 0 ) { |
93 | #ifndef QT_NO_COP | 93 | #ifndef QT_NO_COP |
94 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | 94 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; |
95 | #endif | 95 | #endif |
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 | ||
99 | void QCopBridge::closeOpenConnections() | 99 | void QCopBridge::closeOpenConnections() |
100 | { | 100 | { |
101 | QCopBridgePI *pi; | 101 | QCopBridgePI *pi; |
102 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) | 102 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) |
103 | pi->close(); | 103 | pi->close(); |
104 | } | 104 | } |
105 | 105 | ||
106 | 106 | ||
107 | void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args ) | 107 | void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args ) |
108 | { | 108 | { |
109 | command.stripWhiteSpace(); | 109 | command.stripWhiteSpace(); |
110 | 110 | ||
111 | int paren = command.find( "(" ); | 111 | int paren = command.find( "(" ); |
112 | if ( paren <= 0 ) { | 112 | if ( paren <= 0 ) { |
113 | qDebug("DesktopMessage: bad qcop syntax"); | 113 | qDebug("DesktopMessage: bad qcop syntax"); |
114 | return; | 114 | return; |
115 | } | 115 | } |
116 | 116 | ||
117 | QString params = command.mid( paren + 1 ); | 117 | QString params = command.mid( paren + 1 ); |
118 | if ( params[params.length()-1] != ')' ) { | 118 | if ( params[params.length()-1] != ')' ) { |
119 | qDebug("DesktopMessage: bad qcop syntax"); | 119 | qDebug("DesktopMessage: bad qcop syntax"); |
120 | return; | 120 | return; |
121 | } | 121 | } |
122 | 122 | ||
123 | params.truncate( params.length()-1 ); | 123 | params.truncate( params.length()-1 ); |
124 | 124 | ||
125 | QStringList paramList = QStringList::split( ",", params ); | 125 | QStringList paramList = QStringList::split( ",", params ); |
126 | QString data; | 126 | QString data; |
diff --git a/core/qws/transferserver.cpp b/core/qws/transferserver.cpp index 30bf438..daf63ec 100644 --- a/core/qws/transferserver.cpp +++ b/core/qws/transferserver.cpp | |||
@@ -249,109 +249,109 @@ bool SyncAuthentication::checkPassword( const QString& password ) | |||
249 | "<p>If you have just initiated a Sync for the first time, this is normal."), | 249 | "<p>If you have just initiated a Sync for the first time, this is normal."), |
250 | tr("Allow"), tr("Deny"), 0, 1, 1 ) == 1 ) { | 250 | tr("Allow"), tr("Deny"), 0, 1, 1 ) == 1 ) { |
251 | denials++; | 251 | denials++; |
252 | lastdenial = now; | 252 | lastdenial = now; |
253 | return FALSE; | 253 | return FALSE; |
254 | } | 254 | } |
255 | else { | 255 | else { |
256 | denials = 0; | 256 | denials = 0; |
257 | cfg.writeEntry("Passwords", pwds + " " + cpassword); | 257 | cfg.writeEntry("Passwords", pwds + " " + cpassword); |
258 | return TRUE; | 258 | return TRUE; |
259 | } | 259 | } |
260 | } | 260 | } |
261 | 261 | ||
262 | return FALSE; | 262 | return FALSE; |
263 | } | 263 | } |
264 | 264 | ||
265 | ServerPI::ServerPI( int socket, QObject *parent , const char* name ) | 265 | ServerPI::ServerPI( int socket, QObject *parent , const char* name ) |
266 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) | 266 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) |
267 | { | 267 | { |
268 | state = Connected; | 268 | state = Connected; |
269 | 269 | ||
270 | setSocket( socket ); | 270 | setSocket( socket ); |
271 | 271 | ||
272 | peerport = peerPort(); | 272 | peerport = peerPort(); |
273 | peeraddress = peerAddress(); | 273 | peeraddress = peerAddress(); |
274 | 274 | ||
275 | #ifndef INSECURE | 275 | #ifndef INSECURE |
276 | 276 | ||
277 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { | 277 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { |
278 | state = Forbidden; | 278 | state = Forbidden; |
279 | startTimer( 0 ); | 279 | startTimer( 0 ); |
280 | } | 280 | } |
281 | else | 281 | else |
282 | #endif | 282 | #endif |
283 | { | 283 | { |
284 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); | 284 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); |
285 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 285 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
286 | 286 | ||
287 | passiv = FALSE; | 287 | passiv = FALSE; |
288 | for ( int i = 0; i < 4; i++ ) | 288 | for ( int i = 0; i < 4; i++ ) |
289 | wait[i] = FALSE; | 289 | wait[i] = FALSE; |
290 | 290 | ||
291 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); | 291 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); |
292 | state = Wait_USER; | 292 | state = Wait_USER; |
293 | 293 | ||
294 | dtp = new ServerDTP( this ); | 294 | dtp = new ServerDTP( this ); |
295 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); | 295 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); |
296 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); | 296 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); |
297 | connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); | 297 | connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) ); |
298 | 298 | ||
299 | 299 | ||
300 | directory = QDir::currentDirPath(); | 300 | directory = QDir::currentDirPath(); |
301 | 301 | ||
302 | static int p = 1024; | 302 | static int p = 1024; |
303 | 303 | ||
304 | while ( !serversocket || !serversocket->ok() ) { | 304 | while ( !serversocket || !serversocket->ok() ) { |
305 | delete serversocket; | 305 | delete serversocket; |
306 | serversocket = new ServerSocket( ++p, this ); | 306 | serversocket = new ServerSocket( ++p, this ); |
307 | } | 307 | } |
308 | connect( serversocket, SIGNAL( newIncomming( int ) ), | 308 | connect( serversocket, SIGNAL( newIncomming(int) ), |
309 | SLOT( newConnection( int ) ) ); | 309 | SLOT( newConnection(int) ) ); |
310 | } | 310 | } |
311 | } | 311 | } |
312 | 312 | ||
313 | ServerPI::~ServerPI() | 313 | ServerPI::~ServerPI() |
314 | { | 314 | { |
315 | } | 315 | } |
316 | 316 | ||
317 | void ServerPI::connectionClosed() | 317 | void ServerPI::connectionClosed() |
318 | { | 318 | { |
319 | // qDebug( "Debug: Connection closed" ); | 319 | // qDebug( "Debug: Connection closed" ); |
320 | delete this; | 320 | delete this; |
321 | } | 321 | } |
322 | 322 | ||
323 | void ServerPI::send( const QString& msg ) | 323 | void ServerPI::send( const QString& msg ) |
324 | { | 324 | { |
325 | QTextStream os( this ); | 325 | QTextStream os( this ); |
326 | os << msg << endl; | 326 | os << msg << endl; |
327 | //qDebug( "Reply: %s", msg.latin1() ); | 327 | //qDebug( "Reply: %s", msg.latin1() ); |
328 | } | 328 | } |
329 | 329 | ||
330 | void ServerPI::read() | 330 | void ServerPI::read() |
331 | { | 331 | { |
332 | while ( canReadLine() ) | 332 | while ( canReadLine() ) |
333 | process( readLine().stripWhiteSpace() ); | 333 | process( readLine().stripWhiteSpace() ); |
334 | } | 334 | } |
335 | 335 | ||
336 | bool ServerPI::checkReadFile( const QString& file ) | 336 | bool ServerPI::checkReadFile( const QString& file ) |
337 | { | 337 | { |
338 | QString filename; | 338 | QString filename; |
339 | 339 | ||
340 | if ( file[0] != "/" ) | 340 | if ( file[0] != "/" ) |
341 | filename = directory.path() + "/" + file; | 341 | filename = directory.path() + "/" + file; |
342 | else | 342 | else |
343 | filename = file; | 343 | filename = file; |
344 | 344 | ||
345 | QFileInfo fi( filename ); | 345 | QFileInfo fi( filename ); |
346 | return ( fi.exists() && fi.isReadable() ); | 346 | return ( fi.exists() && fi.isReadable() ); |
347 | } | 347 | } |
348 | 348 | ||
349 | bool ServerPI::checkWriteFile( const QString& file ) | 349 | bool ServerPI::checkWriteFile( const QString& file ) |
350 | { | 350 | { |
351 | QString filename; | 351 | QString filename; |
352 | 352 | ||
353 | if ( file[0] != "/" ) | 353 | if ( file[0] != "/" ) |
354 | filename = directory.path() + "/" + file; | 354 | filename = directory.path() + "/" + file; |
355 | else | 355 | else |
356 | filename = file; | 356 | filename = file; |
357 | 357 | ||
@@ -1001,112 +1001,112 @@ void ServerPI::newConnection( int socket ) | |||
1001 | if ( backupRestoreGzip( waitfile ) ) | 1001 | if ( backupRestoreGzip( waitfile ) ) |
1002 | dtp->retrieveGzipFile( waitfile ); | 1002 | dtp->retrieveGzipFile( waitfile ); |
1003 | else | 1003 | else |
1004 | dtp->retrieveFile( waitfile ); | 1004 | dtp->retrieveFile( waitfile ); |
1005 | dtp->setSocket( socket ); | 1005 | dtp->setSocket( socket ); |
1006 | } | 1006 | } |
1007 | else if ( wait[SendByteArray] ) { | 1007 | else if ( wait[SendByteArray] ) { |
1008 | dtp->sendByteArray( waitarray ); | 1008 | dtp->sendByteArray( waitarray ); |
1009 | dtp->setSocket( socket ); | 1009 | dtp->setSocket( socket ); |
1010 | } | 1010 | } |
1011 | else if ( wait[RetrieveByteArray] ) { | 1011 | else if ( wait[RetrieveByteArray] ) { |
1012 | qDebug("retrieve byte array"); | 1012 | qDebug("retrieve byte array"); |
1013 | dtp->retrieveByteArray(); | 1013 | dtp->retrieveByteArray(); |
1014 | dtp->setSocket( socket ); | 1014 | dtp->setSocket( socket ); |
1015 | } | 1015 | } |
1016 | else | 1016 | else |
1017 | waitsocket = socket; | 1017 | waitsocket = socket; |
1018 | 1018 | ||
1019 | for ( int i = 0; i < 4; i++ ) | 1019 | for ( int i = 0; i < 4; i++ ) |
1020 | wait[i] = FALSE; | 1020 | wait[i] = FALSE; |
1021 | } | 1021 | } |
1022 | 1022 | ||
1023 | QString ServerPI::absFilePath( const QString& file ) | 1023 | QString ServerPI::absFilePath( const QString& file ) |
1024 | { | 1024 | { |
1025 | if ( file.isEmpty() ) | 1025 | if ( file.isEmpty() ) |
1026 | return file; | 1026 | return file; |
1027 | 1027 | ||
1028 | QString filepath( file ); | 1028 | QString filepath( file ); |
1029 | if ( file[0] != "/" ) | 1029 | if ( file[0] != "/" ) |
1030 | filepath = directory.path() + "/" + file; | 1030 | filepath = directory.path() + "/" + file; |
1031 | 1031 | ||
1032 | return filepath; | 1032 | return filepath; |
1033 | } | 1033 | } |
1034 | 1034 | ||
1035 | 1035 | ||
1036 | void ServerPI::timerEvent( QTimerEvent * ) | 1036 | void ServerPI::timerEvent( QTimerEvent * ) |
1037 | { | 1037 | { |
1038 | connectionClosed(); | 1038 | connectionClosed(); |
1039 | } | 1039 | } |
1040 | 1040 | ||
1041 | 1041 | ||
1042 | ServerDTP::ServerDTP( QObject *parent, const char* name) | 1042 | ServerDTP::ServerDTP( QObject *parent, const char* name) |
1043 | : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), | 1043 | : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), |
1044 | retrieveTargzProc( 0 ), gzipProc( 0 ) | 1044 | retrieveTargzProc( 0 ), gzipProc( 0 ) |
1045 | { | 1045 | { |
1046 | 1046 | ||
1047 | connect( this, SIGNAL( connected() ), SLOT( connected() ) ); | 1047 | connect( this, SIGNAL( connected() ), SLOT( connected() ) ); |
1048 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 1048 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
1049 | connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); | 1049 | connect( this, SIGNAL( bytesWritten(int) ), SLOT( bytesWritten(int) ) ); |
1050 | connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); | 1050 | connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); |
1051 | 1051 | ||
1052 | gzipProc = new OProcess( this, "gzipProc" ); | 1052 | gzipProc = new OProcess( this, "gzipProc" ); |
1053 | 1053 | ||
1054 | createTargzProc = new OProcess( QString("tar"), this, "createTargzProc"); | 1054 | createTargzProc = new OProcess( QString("tar"), this, "createTargzProc"); |
1055 | createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); | 1055 | createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); |
1056 | connect( createTargzProc, SIGNAL( processExited(OProcess *) ), SLOT( targzDone() ) ); | 1056 | connect( createTargzProc, SIGNAL( processExited(OProcess*) ), SLOT( targzDone() ) ); |
1057 | 1057 | ||
1058 | QStringList args = "tar"; | 1058 | QStringList args = "tar"; |
1059 | args += "-xv"; | 1059 | args += "-xv"; |
1060 | retrieveTargzProc = new OProcess( args, this, "retrieveTargzProc" ); | 1060 | retrieveTargzProc = new OProcess( args, this, "retrieveTargzProc" ); |
1061 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); | 1061 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); |
1062 | connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ), | 1062 | connect( retrieveTargzProc, SIGNAL( processExited(OProcess*) ), |
1063 | SIGNAL( completed() ) ); | 1063 | SIGNAL( completed() ) ); |
1064 | connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ), | 1064 | connect( retrieveTargzProc, SIGNAL( processExited(OProcess*) ), |
1065 | SLOT( extractTarDone() ) ); | 1065 | SLOT( extractTarDone() ) ); |
1066 | } | 1066 | } |
1067 | 1067 | ||
1068 | ServerDTP::~ServerDTP() | 1068 | ServerDTP::~ServerDTP() |
1069 | { | 1069 | { |
1070 | buf.close(); | 1070 | buf.close(); |
1071 | file.close(); | 1071 | file.close(); |
1072 | createTargzProc->kill(); | 1072 | createTargzProc->kill(); |
1073 | } | 1073 | } |
1074 | 1074 | ||
1075 | void ServerDTP::extractTarDone() | 1075 | void ServerDTP::extractTarDone() |
1076 | { | 1076 | { |
1077 | qDebug("extract done"); | 1077 | qDebug("extract done"); |
1078 | #ifndef QT_NO_COP | 1078 | #ifndef QT_NO_COP |
1079 | 1079 | ||
1080 | QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); | 1080 | QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); |
1081 | e << file.name(); | 1081 | e << file.name(); |
1082 | #endif | 1082 | #endif |
1083 | } | 1083 | } |
1084 | 1084 | ||
1085 | void ServerDTP::connected() | 1085 | void ServerDTP::connected() |
1086 | { | 1086 | { |
1087 | // send file mode | 1087 | // send file mode |
1088 | switch ( mode ) { | 1088 | switch ( mode ) { |
1089 | case SendFile : | 1089 | case SendFile : |
1090 | if ( !file.exists() || !file.open( IO_ReadOnly) ) { | 1090 | if ( !file.exists() || !file.open( IO_ReadOnly) ) { |
1091 | emit failed(); | 1091 | emit failed(); |
1092 | mode = Idle; | 1092 | mode = Idle; |
1093 | return ; | 1093 | return ; |
1094 | } | 1094 | } |
1095 | 1095 | ||
1096 | //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); | 1096 | //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); |
1097 | 1097 | ||
1098 | bytes_written = 0; | 1098 | bytes_written = 0; |
1099 | if ( file.size() == 0 ) { | 1099 | if ( file.size() == 0 ) { |
1100 | //make sure it doesn't hang on empty files | 1100 | //make sure it doesn't hang on empty files |
1101 | file.close(); | 1101 | file.close(); |
1102 | emit completed(); | 1102 | emit completed(); |
1103 | mode = Idle; | 1103 | mode = Idle; |
1104 | } | 1104 | } |
1105 | else { | 1105 | else { |
1106 | 1106 | ||
1107 | if ( !file.atEnd() ) { | 1107 | if ( !file.atEnd() ) { |
1108 | QCString s; | 1108 | QCString s; |
1109 | s.resize( block_size ); | 1109 | s.resize( block_size ); |
1110 | int bytes = file.readBlock( s.data(), block_size ); | 1110 | int bytes = file.readBlock( s.data(), block_size ); |
1111 | writeBlock( s.data(), bytes ); | 1111 | writeBlock( s.data(), bytes ); |
1112 | } | 1112 | } |
@@ -1236,169 +1236,169 @@ void ServerDTP::bytesWritten( int bytes ) | |||
1236 | 1236 | ||
1237 | // send buffer mode | 1237 | // send buffer mode |
1238 | if ( SendBuffer == mode ) { | 1238 | if ( SendBuffer == mode ) { |
1239 | 1239 | ||
1240 | if ( bytes_written == buf.size() ) { | 1240 | if ( bytes_written == buf.size() ) { |
1241 | // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); | 1241 | // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); |
1242 | emit completed(); | 1242 | emit completed(); |
1243 | mode = Idle; | 1243 | mode = Idle; |
1244 | } | 1244 | } |
1245 | } | 1245 | } |
1246 | } | 1246 | } |
1247 | 1247 | ||
1248 | void ServerDTP::readyRead() | 1248 | void ServerDTP::readyRead() |
1249 | { | 1249 | { |
1250 | // retrieve file mode | 1250 | // retrieve file mode |
1251 | if ( RetrieveFile == mode ) { | 1251 | if ( RetrieveFile == mode ) { |
1252 | QCString s; | 1252 | QCString s; |
1253 | s.resize( bytesAvailable() ); | 1253 | s.resize( bytesAvailable() ); |
1254 | readBlock( s.data(), bytesAvailable() ); | 1254 | readBlock( s.data(), bytesAvailable() ); |
1255 | file.writeBlock( s.data(), s.size() ); | 1255 | file.writeBlock( s.data(), s.size() ); |
1256 | } | 1256 | } |
1257 | else if ( RetrieveGzipFile == mode ) { | 1257 | else if ( RetrieveGzipFile == mode ) { |
1258 | if ( !gzipProc->isRunning() ) | 1258 | if ( !gzipProc->isRunning() ) |
1259 | gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout )); | 1259 | gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout )); |
1260 | 1260 | ||
1261 | QByteArray s; | 1261 | QByteArray s; |
1262 | s.resize( bytesAvailable() ); | 1262 | s.resize( bytesAvailable() ); |
1263 | readBlock( s.data(), bytesAvailable() ); | 1263 | readBlock( s.data(), bytesAvailable() ); |
1264 | gzipProc->writeStdin( s.data(), s.size() ); | 1264 | gzipProc->writeStdin( s.data(), s.size() ); |
1265 | qDebug("wrote %d bytes to ungzip ", s.size() ); | 1265 | qDebug("wrote %d bytes to ungzip ", s.size() ); |
1266 | } | 1266 | } |
1267 | // retrieve buffer mode | 1267 | // retrieve buffer mode |
1268 | else if ( RetrieveBuffer == mode ) { | 1268 | else if ( RetrieveBuffer == mode ) { |
1269 | QCString s; | 1269 | QCString s; |
1270 | s.resize( bytesAvailable() ); | 1270 | s.resize( bytesAvailable() ); |
1271 | readBlock( s.data(), bytesAvailable() ); | 1271 | readBlock( s.data(), bytesAvailable() ); |
1272 | buf.writeBlock( s.data(), s.size() ); | 1272 | buf.writeBlock( s.data(), s.size() ); |
1273 | } | 1273 | } |
1274 | } | 1274 | } |
1275 | 1275 | ||
1276 | void ServerDTP::writeTargzBlock(OProcess *, char *buffer, int buflen) | 1276 | void ServerDTP::writeTargzBlock(OProcess *, char *buffer, int buflen) |
1277 | { | 1277 | { |
1278 | writeBlock( buffer, buflen ); | 1278 | writeBlock( buffer, buflen ); |
1279 | qDebug("writeTargzBlock %d", buflen); | 1279 | qDebug("writeTargzBlock %d", buflen); |
1280 | if ( !createTargzProc->isRunning() ) { | 1280 | if ( !createTargzProc->isRunning() ) { |
1281 | qDebug("tar and gzip done"); | 1281 | qDebug("tar and gzip done"); |
1282 | emit completed(); | 1282 | emit completed(); |
1283 | mode = Idle; | 1283 | mode = Idle; |
1284 | disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int ) ), | 1284 | disconnect( gzipProc, SIGNAL( receivedStdout(OProcess*,char*,int) ), |
1285 | this, SLOT( writeTargzBlock(OProcess *, char *, int) ) ); | 1285 | this, SLOT( writeTargzBlock(OProcess*,char*,int) ) ); |
1286 | } | 1286 | } |
1287 | } | 1287 | } |
1288 | 1288 | ||
1289 | void ServerDTP::targzDone() | 1289 | void ServerDTP::targzDone() |
1290 | { | 1290 | { |
1291 | //qDebug("targz done"); | 1291 | //qDebug("targz done"); |
1292 | disconnect( createTargzProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), | 1292 | disconnect( createTargzProc, SIGNAL( receivedStdout(OProcess*,char*,int) ), |
1293 | this, SLOT( gzipTarBlock(OProcess *, char *, int) ) ); | 1293 | this, SLOT( gzipTarBlock(OProcess*,char*,int) ) ); |
1294 | gzipProc->closeStdin(); | 1294 | gzipProc->closeStdin(); |
1295 | } | 1295 | } |
1296 | 1296 | ||
1297 | void ServerDTP::gzipTarBlock(OProcess *, char *buffer, int buflen) | 1297 | void ServerDTP::gzipTarBlock(OProcess *, char *buffer, int buflen) |
1298 | { | 1298 | { |
1299 | //qDebug("gzipTarBlock"); | 1299 | //qDebug("gzipTarBlock"); |
1300 | if ( !gzipProc->isRunning() ) { | 1300 | if ( !gzipProc->isRunning() ) { |
1301 | //qDebug("auto start gzip proc"); | 1301 | //qDebug("auto start gzip proc"); |
1302 | gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout )); | 1302 | gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout )); |
1303 | } | 1303 | } |
1304 | gzipProc->writeStdin( buffer, buflen ); | 1304 | gzipProc->writeStdin( buffer, buflen ); |
1305 | } | 1305 | } |
1306 | 1306 | ||
1307 | void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) | 1307 | void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) |
1308 | { | 1308 | { |
1309 | file.setName( fn ); | 1309 | file.setName( fn ); |
1310 | mode = SendFile; | 1310 | mode = SendFile; |
1311 | connectToHost( host.toString(), port ); | 1311 | connectToHost( host.toString(), port ); |
1312 | } | 1312 | } |
1313 | 1313 | ||
1314 | void ServerDTP::sendFile( const QString fn ) | 1314 | void ServerDTP::sendFile( const QString fn ) |
1315 | { | 1315 | { |
1316 | file.setName( fn ); | 1316 | file.setName( fn ); |
1317 | mode = SendFile; | 1317 | mode = SendFile; |
1318 | } | 1318 | } |
1319 | 1319 | ||
1320 | void ServerDTP::sendGzipFile( const QString &fn, | 1320 | void ServerDTP::sendGzipFile( const QString &fn, |
1321 | const QStringList &archiveTargets, | 1321 | const QStringList &archiveTargets, |
1322 | const QHostAddress& host, Q_UINT16 port ) | 1322 | const QHostAddress& host, Q_UINT16 port ) |
1323 | { | 1323 | { |
1324 | sendGzipFile( fn, archiveTargets ); | 1324 | sendGzipFile( fn, archiveTargets ); |
1325 | connectToHost( host.toString(), port ); | 1325 | connectToHost( host.toString(), port ); |
1326 | } | 1326 | } |
1327 | 1327 | ||
1328 | void ServerDTP::sendGzipFile( const QString &fn, | 1328 | void ServerDTP::sendGzipFile( const QString &fn, |
1329 | const QStringList &archiveTargets ) | 1329 | const QStringList &archiveTargets ) |
1330 | { | 1330 | { |
1331 | mode = SendGzipFile; | 1331 | mode = SendGzipFile; |
1332 | file.setName( fn ); | 1332 | file.setName( fn ); |
1333 | 1333 | ||
1334 | QStringList args = "tar"; | 1334 | QStringList args = "tar"; |
1335 | args += "-cv"; | 1335 | args += "-cv"; |
1336 | args += archiveTargets; | 1336 | args += archiveTargets; |
1337 | qDebug("sendGzipFile %s", args.join(" ").latin1() ); | 1337 | qDebug("sendGzipFile %s", args.join(" ").latin1() ); |
1338 | createTargzProc->clearArguments( ); | 1338 | createTargzProc->clearArguments( ); |
1339 | *createTargzProc << args; | 1339 | *createTargzProc << args; |
1340 | connect( createTargzProc, | 1340 | connect( createTargzProc, |
1341 | SIGNAL( receivedStdout(OProcess *, char *, int) ), SLOT( gzipTarBlock(OProcess *, char *, int) ) ); | 1341 | SIGNAL( receivedStdout(OProcess*,char*,int) ), SLOT( gzipTarBlock(OProcess*,char*,int) ) ); |
1342 | 1342 | ||
1343 | gzipProc->clearArguments( ); | 1343 | gzipProc->clearArguments( ); |
1344 | *gzipProc << "gzip"; | 1344 | *gzipProc << "gzip"; |
1345 | connect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), | 1345 | connect( gzipProc, SIGNAL( receivedStdout(OProcess*,char*,int) ), |
1346 | SLOT( writeTargzBlock(OProcess *, char *, int) ) ); | 1346 | SLOT( writeTargzBlock(OProcess*,char*,int) ) ); |
1347 | } | 1347 | } |
1348 | 1348 | ||
1349 | void ServerDTP::gunzipDone() | 1349 | void ServerDTP::gunzipDone() |
1350 | { | 1350 | { |
1351 | qDebug("gunzipDone"); | 1351 | qDebug("gunzipDone"); |
1352 | disconnect( gzipProc, SIGNAL( processExited() ), | 1352 | disconnect( gzipProc, SIGNAL( processExited() ), |
1353 | this, SLOT( gunzipDone() ) ); | 1353 | this, SLOT( gunzipDone() ) ); |
1354 | retrieveTargzProc->closeStdin(); | 1354 | retrieveTargzProc->closeStdin(); |
1355 | disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), | 1355 | disconnect( gzipProc, SIGNAL( receivedStdout(OProcess*,char*,int) ), |
1356 | this, SLOT( tarExtractBlock(OProcess *, char *, int) ) ); | 1356 | this, SLOT( tarExtractBlock(OProcess*,char*,int) ) ); |
1357 | } | 1357 | } |
1358 | 1358 | ||
1359 | void ServerDTP::tarExtractBlock(OProcess *, char *buffer, int buflen) | 1359 | void ServerDTP::tarExtractBlock(OProcess *, char *buffer, int buflen) |
1360 | { | 1360 | { |
1361 | qDebug("tarExtractBlock"); | 1361 | qDebug("tarExtractBlock"); |
1362 | if ( !retrieveTargzProc->isRunning() ) { | 1362 | if ( !retrieveTargzProc->isRunning() ) { |
1363 | qDebug("auto start ungzip proc"); | 1363 | qDebug("auto start ungzip proc"); |
1364 | if ( !retrieveTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdin) ) | 1364 | if ( !retrieveTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdin) ) |
1365 | qWarning(" failed to start tar -x process"); | 1365 | qWarning(" failed to start tar -x process"); |
1366 | } | 1366 | } |
1367 | retrieveTargzProc->writeStdin( buffer, buflen ); | 1367 | retrieveTargzProc->writeStdin( buffer, buflen ); |
1368 | } | 1368 | } |
1369 | 1369 | ||
1370 | 1370 | ||
1371 | void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) | 1371 | void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) |
1372 | { | 1372 | { |
1373 | file.setName( fn ); | 1373 | file.setName( fn ); |
1374 | mode = RetrieveFile; | 1374 | mode = RetrieveFile; |
1375 | connectToHost( host.toString(), port ); | 1375 | connectToHost( host.toString(), port ); |
1376 | } | 1376 | } |
1377 | 1377 | ||
1378 | void ServerDTP::retrieveFile( const QString fn ) | 1378 | void ServerDTP::retrieveFile( const QString fn ) |
1379 | { | 1379 | { |
1380 | file.setName( fn ); | 1380 | file.setName( fn ); |
1381 | mode = RetrieveFile; | 1381 | mode = RetrieveFile; |
1382 | } | 1382 | } |
1383 | 1383 | ||
1384 | void ServerDTP::retrieveGzipFile( const QString &fn ) | 1384 | void ServerDTP::retrieveGzipFile( const QString &fn ) |
1385 | { | 1385 | { |
1386 | qDebug("retrieveGzipFile %s", fn.latin1()); | 1386 | qDebug("retrieveGzipFile %s", fn.latin1()); |
1387 | file.setName( fn ); | 1387 | file.setName( fn ); |
1388 | mode = RetrieveGzipFile; | 1388 | mode = RetrieveGzipFile; |
1389 | 1389 | ||
1390 | gzipProc->clearArguments(); | 1390 | gzipProc->clearArguments(); |
1391 | *gzipProc << "gunzip"; | 1391 | *gzipProc << "gunzip"; |
1392 | connect( gzipProc, SIGNAL( readyReadStdout() ), | 1392 | connect( gzipProc, SIGNAL( readyReadStdout() ), |
1393 | SLOT( tarExtractBlock() ) ); | 1393 | SLOT( tarExtractBlock() ) ); |
1394 | connect( gzipProc, SIGNAL( processExited() ), | 1394 | connect( gzipProc, SIGNAL( processExited() ), |
1395 | SLOT( gunzipDone() ) ); | 1395 | SLOT( gunzipDone() ) ); |
1396 | } | 1396 | } |
1397 | 1397 | ||
1398 | void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) | 1398 | void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) |
1399 | { | 1399 | { |
1400 | retrieveGzipFile( fn ); | 1400 | retrieveGzipFile( fn ); |
1401 | connectToHost( host.toString(), port ); | 1401 | connectToHost( host.toString(), port ); |
1402 | } | 1402 | } |
1403 | 1403 | ||
1404 | void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ) | 1404 | void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ) |