summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/qws/qcopbridge.cpp18
-rw-r--r--core/qws/transferserver.cpp82
2 files changed, 54 insertions, 46 deletions
diff --git a/core/qws/qcopbridge.cpp b/core/qws/qcopbridge.cpp
index 4fd0807..822efb7 100644
--- a/core/qws/qcopbridge.cpp
+++ b/core/qws/qcopbridge.cpp
@@ -16,25 +16,29 @@
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/* OPIE */
24#include <qpe/qcopenvelope_qws.h> 25#include <qpe/qcopenvelope_qws.h>
25#include <qpe/qpeapplication.h> 26#include <qpe/qpeapplication.h>
26#include <qpe/version.h> 27#include <qpe/version.h>
28#include <opie2/odebug.h>
27 29
30/* QT */
28#include <qtextstream.h> 31#include <qtextstream.h>
29#ifdef QWS 32#ifdef QWS
30#include <qcopchannel_qws.h> 33#include <qcopchannel_qws.h>
31#endif 34#endif
32 35
36/* STD */
33#define _XOPEN_SOURCE 37#define _XOPEN_SOURCE
34#include <pwd.h> 38#include <pwd.h>
35#include <sys/types.h> 39#include <sys/types.h>
36#include <unistd.h> 40#include <unistd.h>
37 41
38#if defined(_OS_LINUX_) 42#if defined(_OS_LINUX_)
39#include <shadow.h> 43#include <shadow.h>
40#endif 44#endif
@@ -45,17 +49,17 @@ const int block_size = 51200;
45 49
46QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent , 50QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent ,
47 const char* name ) 51 const char* name )
48 : QServerSocket( port, 1, parent, name ), 52 : QServerSocket( port, 1, parent, name ),
49 desktopChannel( 0 ), 53 desktopChannel( 0 ),
50 cardChannel( 0 ) 54 cardChannel( 0 )
51{ 55{
52 if ( !ok() ) 56 if ( !ok() )
53 qWarning( "Failed to bind to port %d", port ); 57 owarn << "Failed to bind to port " << port << "" << oendl;
54 else { 58 else {
55#ifndef QT_NO_COP 59#ifndef QT_NO_COP
56 desktopChannel = new QCopChannel( "QPE/Desktop", this ); 60 desktopChannel = new QCopChannel( "QPE/Desktop", this );
57 connect( desktopChannel, SIGNAL(received(const QCString&,const QByteArray&)), 61 connect( desktopChannel, SIGNAL(received(const QCString&,const QByteArray&)),
58 this, SLOT(desktopMessage(const QCString&,const QByteArray&)) ); 62 this, SLOT(desktopMessage(const QCString&,const QByteArray&)) );
59 cardChannel = new QCopChannel( "QPE/Card", this ); 63 cardChannel = new QCopChannel( "QPE/Card", this );
60 connect( cardChannel, SIGNAL(received(const QCString&,const QByteArray&)), 64 connect( cardChannel, SIGNAL(received(const QCString&,const QByteArray&)),
61 this, SLOT(desktopMessage(const QCString&,const QByteArray&)) ); 65 this, SLOT(desktopMessage(const QCString&,const QByteArray&)) );
@@ -105,23 +109,23 @@ void QCopBridge::closeOpenConnections()
105 109
106 110
107void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args ) 111void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args )
108{ 112{
109 command.stripWhiteSpace(); 113 command.stripWhiteSpace();
110 114
111 int paren = command.find( "(" ); 115 int paren = command.find( "(" );
112 if ( paren <= 0 ) { 116 if ( paren <= 0 ) {
113 qDebug("DesktopMessage: bad qcop syntax"); 117 odebug << "DesktopMessage: bad qcop syntax" << oendl;
114 return; 118 return;
115 } 119 }
116 120
117 QString params = command.mid( paren + 1 ); 121 QString params = command.mid( paren + 1 );
118 if ( params[params.length()-1] != ')' ) { 122 if ( params[params.length()-1] != ')' ) {
119 qDebug("DesktopMessage: bad qcop syntax"); 123 odebug << "DesktopMessage: bad qcop syntax" << oendl;
120 return; 124 return;
121 } 125 }
122 126
123 params.truncate( params.length()-1 ); 127 params.truncate( params.length()-1 );
124 128
125 QStringList paramList = QStringList::split( ",", params ); 129 QStringList paramList = QStringList::split( ",", params );
126 QString data; 130 QString data;
127 if ( paramList.count() ) { 131 if ( paramList.count() ) {
@@ -138,17 +142,17 @@ void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args
138 int i; 142 int i;
139 stream >> i; 143 stream >> i;
140 str = QString::number( i ); 144 str = QString::number( i );
141 } else if ( *it == "bool" ) { 145 } else if ( *it == "bool" ) {
142 int i; 146 int i;
143 stream >> i; 147 stream >> i;
144 str = QString::number( i ); 148 str = QString::number( i );
145 } else { 149 } else {
146 qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() ); 150 odebug << " cannot route the argument type " << (*it) << " throught the qcop bridge" << oendl;
147 return; 151 return;
148 } 152 }
149 QString estr; 153 QString estr;
150 for (int i=0; i<(int)str.length(); i++) { 154 for (int i=0; i<(int)str.length(); i++) {
151 QChar ch = str[i]; 155 QChar ch = str[i];
152 if ( ch.row() ) 156 if ( ch.row() )
153 goto quick; 157 goto quick;
154 switch (ch.cell()) { 158 switch (ch.cell()) {
@@ -230,43 +234,43 @@ QCopBridgePI::QCopBridgePI( int socket, QObject *parent , const char* name )
230QCopBridgePI::~QCopBridgePI() 234QCopBridgePI::~QCopBridgePI()
231{ 235{
232 236
233} 237}
234 238
235void QCopBridgePI::connectionClosed() 239void QCopBridgePI::connectionClosed()
236{ 240{
237 emit connectionClosed( this ); 241 emit connectionClosed( this );
238 // qDebug( "Debug: Connection closed" ); 242 // odebug << "Debug: Connection closed" << oendl;
239 delete this; 243 delete this;
240} 244}
241 245
242void QCopBridgePI::sendDesktopMessage( const QString &msg ) 246void QCopBridgePI::sendDesktopMessage( const QString &msg )
243{ 247{
244 QString str = "CALL QPE/Desktop " + msg; 248 QString str = "CALL QPE/Desktop " + msg;
245 send ( str ); 249 send ( str );
246} 250}
247 251
248 252
249void QCopBridgePI::send( const QString& msg ) 253void QCopBridgePI::send( const QString& msg )
250{ 254{
251 QTextStream os( this ); 255 QTextStream os( this );
252 os << msg << endl; 256 os << msg << endl;
253 //qDebug( "sending qcop message: %s", msg.latin1() ); 257 //odebug << "sending qcop message: " << msg << "" << oendl;
254} 258}
255 259
256void QCopBridgePI::read() 260void QCopBridgePI::read()
257{ 261{
258 while ( canReadLine() ) 262 while ( canReadLine() )
259 process( readLine().stripWhiteSpace() ); 263 process( readLine().stripWhiteSpace() );
260} 264}
261 265
262void QCopBridgePI::process( const QString& message ) 266void QCopBridgePI::process( const QString& message )
263{ 267{
264 //qDebug( "Command: %s", message.latin1() ); 268 //odebug << "Command: " << message << "" << oendl;
265 269
266 // split message using "," as separator 270 // split message using "," as separator
267 QStringList msg = QStringList::split( " ", message ); 271 QStringList msg = QStringList::split( " ", message );
268 if ( msg.isEmpty() ) return; 272 if ( msg.isEmpty() ) return;
269 273
270 // command token 274 // command token
271 QString cmd = msg[0].upper(); 275 QString cmd = msg[0].upper();
272 276
diff --git a/core/qws/transferserver.cpp b/core/qws/transferserver.cpp
index d0fec89..777c384 100644
--- a/core/qws/transferserver.cpp
+++ b/core/qws/transferserver.cpp
@@ -12,16 +12,20 @@
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
21/* OPIE */
22#include <opie2/odebug.h>
23
20#define _XOPEN_SOURCE 24#define _XOPEN_SOURCE
21#include <pwd.h> 25#include <pwd.h>
22#include <sys/types.h> 26#include <sys/types.h>
23#include <unistd.h> 27#include <unistd.h>
24#include <stdlib.h> 28#include <stdlib.h>
25#include <time.h> 29#include <time.h>
26 30
27#ifndef Q_OS_MACX 31#ifndef Q_OS_MACX
@@ -69,17 +73,17 @@ using namespace Opie::Core;
69 73
70const int block_size = 51200; 74const int block_size = 51200;
71 75
72TransferServer::TransferServer( Q_UINT16 port, QObject *parent , 76TransferServer::TransferServer( Q_UINT16 port, QObject *parent ,
73 const char* name ) 77 const char* name )
74 : QServerSocket( port, 1, parent, name ) 78 : QServerSocket( port, 1, parent, name )
75{ 79{
76 if ( !ok() ) 80 if ( !ok() )
77 qWarning( "Failed to bind to port %d", port ); 81 owarn << "Failed to bind to port " << port << "" << oendl;
78} 82}
79 83
80TransferServer::~TransferServer() 84TransferServer::~TransferServer()
81{ 85{
82} 86}
83 87
84void TransferServer::newConnection( int socket ) 88void TransferServer::newConnection( int socket )
85{ 89{
@@ -312,25 +316,25 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name )
312} 316}
313 317
314ServerPI::~ServerPI() 318ServerPI::~ServerPI()
315{ 319{
316} 320}
317 321
318void ServerPI::connectionClosed() 322void ServerPI::connectionClosed()
319{ 323{
320 // qDebug( "Debug: Connection closed" ); 324 // odebug << "Debug: Connection closed" << oendl;
321 delete this; 325 delete this;
322} 326}
323 327
324void ServerPI::send( const QString& msg ) 328void ServerPI::send( const QString& msg )
325{ 329{
326 QTextStream os( this ); 330 QTextStream os( this );
327 os << msg << endl; 331 os << msg << endl;
328 //qDebug( "Reply: %s", msg.latin1() ); 332 //odebug << "Reply: " << msg << "" << oendl;
329} 333}
330 334
331void ServerPI::read() 335void ServerPI::read()
332{ 336{
333 while ( canReadLine() ) 337 while ( canReadLine() )
334 process( readLine().stripWhiteSpace() ); 338 process( readLine().stripWhiteSpace() );
335} 339}
336 340
@@ -361,17 +365,17 @@ bool ServerPI::checkWriteFile( const QString& file )
361 if ( fi.exists() ) 365 if ( fi.exists() )
362 if ( !QFile( filename ).remove() ) 366 if ( !QFile( filename ).remove() )
363 return FALSE; 367 return FALSE;
364 return TRUE; 368 return TRUE;
365} 369}
366 370
367void ServerPI::process( const QString& message ) 371void ServerPI::process( const QString& message )
368{ 372{
369 //qDebug( "Command: %s", message.latin1() ); 373 //odebug << "Command: " << message << "" << oendl;
370 374
371 // split message using "," as separator 375 // split message using "," as separator
372 QStringList msg = QStringList::split( " ", message ); 376 QStringList msg = QStringList::split( " ", message );
373 if ( msg.isEmpty() ) 377 if ( msg.isEmpty() )
374 return ; 378 return ;
375 379
376 // command token 380 // command token
377 QString cmd = msg[0].upper(); 381 QString cmd = msg[0].upper();
@@ -386,17 +390,17 @@ void ServerPI::process( const QString& message )
386 if ( msg.count() >= 2 ) { 390 if ( msg.count() >= 2 ) {
387 QStringList copy( msg ); 391 QStringList copy( msg );
388 // FIXME: for Qt3 392 // FIXME: for Qt3
389 // copy.pop_front() 393 // copy.pop_front()
390 copy.remove( copy.begin() ); 394 copy.remove( copy.begin() );
391 args = copy.join( " " ); 395 args = copy.join( " " );
392 } 396 }
393 397
394 //qDebug( "args: %s", args.latin1() ); 398 //odebug << "args: " << args << "" << oendl;
395 399
396 // we always respond to QUIT, regardless of state 400 // we always respond to QUIT, regardless of state
397 if ( cmd == "QUIT" ) { 401 if ( cmd == "QUIT" ) {
398 send( "211 Good bye!" ); 402 send( "211 Good bye!" );
399 delete this; 403 delete this;
400 return ; 404 return ;
401 } 405 }
402 406
@@ -522,17 +526,17 @@ void ServerPI::process( const QString& message )
522 // retrieve (RETR) 526 // retrieve (RETR)
523 else if ( cmd == "RETR" ) 527 else if ( cmd == "RETR" )
524 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) 528 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) )
525 || backupRestoreGzip( absFilePath( args ) ) ) { 529 || backupRestoreGzip( absFilePath( args ) ) ) {
526 send( "150 File status okay" ); 530 send( "150 File status okay" );
527 sendFile( absFilePath( args ) ); 531 sendFile( absFilePath( args ) );
528 } 532 }
529 else { 533 else {
530 qDebug("550 Requested action not taken"); 534 odebug << "550 Requested action not taken" << oendl;
531 send( "550 Requested action not taken" ); 535 send( "550 Requested action not taken" );
532 } 536 }
533 537
534 // store (STOR) 538 // store (STOR)
535 else if ( cmd == "STOR" ) 539 else if ( cmd == "STOR" )
536 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { 540 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) {
537 send( "150 File status okay" ); 541 send( "150 File status okay" );
538 retrieveFile( absFilePath( args ) ); 542 retrieveFile( absFilePath( args ) );
@@ -628,17 +632,17 @@ void ServerPI::process( const QString& message )
628 else 632 else
629 send( "550 Requested action not taken" ); 633 send( "550 Requested action not taken" );
630 } 634 }
631 } 635 }
632 636
633 // make directory (MKD) 637 // make directory (MKD)
634 else if ( cmd == "MKD" ) { 638 else if ( cmd == "MKD" ) {
635 if ( args.isEmpty() ) { 639 if ( args.isEmpty() ) {
636 qDebug(" Error: no arg"); 640 odebug << " Error: no arg" << oendl;
637 send( "500 Syntax error, command unrecognized" ); 641 send( "500 Syntax error, command unrecognized" );
638 } 642 }
639 else { 643 else {
640 QDir dir; 644 QDir dir;
641 if ( dir.mkdir( absFilePath( args ), TRUE ) ) 645 if ( dir.mkdir( absFilePath( args ), TRUE ) )
642 send( "250 Requested file action okay, completed." ); 646 send( "250 Requested file action okay, completed." );
643 else 647 else
644 send( "550 Requested action not taken" ); 648 send( "550 Requested action not taken" );
@@ -668,25 +672,25 @@ void ServerPI::process( const QString& message )
668 else { 672 else {
669 if ( !gzipfile ) 673 if ( !gzipfile )
670 send( "213 " + QString::number( fi.size() ) ); 674 send( "213 " + QString::number( fi.size() ) );
671 else { 675 else {
672 Process duproc( QString("du") ); 676 Process duproc( QString("du") );
673 duproc.addArgument("-s"); 677 duproc.addArgument("-s");
674 QString in, out; 678 QString in, out;
675 if ( !duproc.exec(in, out) ) { 679 if ( !duproc.exec(in, out) ) {
676 qDebug("du process failed; just sending back 1K"); 680 odebug << "du process failed; just sending back 1K" << oendl;
677 send( "213 1024"); 681 send( "213 1024");
678 } 682 }
679 else { 683 else {
680 QString size = out.left( out.find("\t") ); 684 QString size = out.left( out.find("\t") );
681 int guess = size.toInt() / 5; 685 int guess = size.toInt() / 5;
682 if ( filePath.contains("doc") ) 686 if ( filePath.contains("doc") )
683 guess *= 1000; 687 guess *= 1000;
684 qDebug("sending back gzip guess of %d", guess); 688 odebug << "sending back gzip guess of " << guess << "" << oendl;
685 send( "213 " + QString::number(guess) ); 689 send( "213 " + QString::number(guess) );
686 } 690 }
687 } 691 }
688 } 692 }
689 } 693 }
690 // name list (NLST) 694 // name list (NLST)
691 else if ( cmd == "NLST" ) { 695 else if ( cmd == "NLST" ) {
692 send( "502 Command not implemented" ); 696 send( "502 Command not implemented" );
@@ -731,18 +735,18 @@ bool ServerPI::backupRestoreGzip( const QString &file )
731} 735}
732 736
733bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) 737bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets )
734{ 738{
735 if ( file.find( "backup" ) != -1 && 739 if ( file.find( "backup" ) != -1 &&
736 file.findRev( ".tgz" ) == (int)file.length() - 4 ) { 740 file.findRev( ".tgz" ) == (int)file.length() - 4 ) {
737 QFileInfo info( file ); 741 QFileInfo info( file );
738 targets = info.dirPath( TRUE ); 742 targets = info.dirPath( TRUE );
739 qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), 743 odebug << "ServerPI::backupRestoreGzip for " << file.latin1() << " = "
740 targets.join(" ").latin1() ); 744 << targets.join(" ").latin1() << oendl;
741 return true; 745 return true;
742 } 746 }
743 return false; 747 return false;
744} 748}
745 749
746void ServerPI::sendFile( const QString& file ) 750void ServerPI::sendFile( const QString& file )
747{ 751{
748 if ( passiv ) { 752 if ( passiv ) {
@@ -979,43 +983,43 @@ QString ServerPI::permissionString( QFileInfo *info )
979 else 983 else
980 s += "-"; 984 s += "-";
981 985
982 return s; 986 return s;
983} 987}
984 988
985void ServerPI::newConnection( int socket ) 989void ServerPI::newConnection( int socket )
986{ 990{
987 //qDebug( "New incomming connection" ); 991 //odebug << "New incomming connection" << oendl;
988 992
989 if ( !passiv ) 993 if ( !passiv )
990 return ; 994 return ;
991 995
992 if ( wait[SendFile] ) { 996 if ( wait[SendFile] ) {
993 QStringList targets; 997 QStringList targets;
994 if ( backupRestoreGzip( waitfile, targets ) ) 998 if ( backupRestoreGzip( waitfile, targets ) )
995 dtp->sendGzipFile( waitfile, targets ); 999 dtp->sendGzipFile( waitfile, targets );
996 else 1000 else
997 dtp->sendFile( waitfile ); 1001 dtp->sendFile( waitfile );
998 dtp->setSocket( socket ); 1002 dtp->setSocket( socket );
999 } 1003 }
1000 else if ( wait[RetrieveFile] ) { 1004 else if ( wait[RetrieveFile] ) {
1001 qDebug("check retrieve file"); 1005 odebug << "check retrieve file" << oendl;
1002 if ( backupRestoreGzip( waitfile ) ) 1006 if ( backupRestoreGzip( waitfile ) )
1003 dtp->retrieveGzipFile( waitfile ); 1007 dtp->retrieveGzipFile( waitfile );
1004 else 1008 else
1005 dtp->retrieveFile( waitfile ); 1009 dtp->retrieveFile( waitfile );
1006 dtp->setSocket( socket ); 1010 dtp->setSocket( socket );
1007 } 1011 }
1008 else if ( wait[SendByteArray] ) { 1012 else if ( wait[SendByteArray] ) {
1009 dtp->sendByteArray( waitarray ); 1013 dtp->sendByteArray( waitarray );
1010 dtp->setSocket( socket ); 1014 dtp->setSocket( socket );
1011 } 1015 }
1012 else if ( wait[RetrieveByteArray] ) { 1016 else if ( wait[RetrieveByteArray] ) {
1013 qDebug("retrieve byte array"); 1017 odebug << "retrieve byte array" << oendl;
1014 dtp->retrieveByteArray(); 1018 dtp->retrieveByteArray();
1015 dtp->setSocket( socket ); 1019 dtp->setSocket( socket );
1016 } 1020 }
1017 else 1021 else
1018 waitsocket = socket; 1022 waitsocket = socket;
1019 1023
1020 for ( int i = 0; i < 4; i++ ) 1024 for ( int i = 0; i < 4; i++ )
1021 wait[i] = FALSE; 1025 wait[i] = FALSE;
@@ -1070,17 +1074,17 @@ ServerDTP::~ServerDTP()
1070{ 1074{
1071 buf.close(); 1075 buf.close();
1072 file.close(); 1076 file.close();
1073 createTargzProc->kill(); 1077 createTargzProc->kill();
1074} 1078}
1075 1079
1076void ServerDTP::extractTarDone() 1080void ServerDTP::extractTarDone()
1077{ 1081{
1078 qDebug("extract done"); 1082 odebug << "extract done" << oendl;
1079#ifndef QT_NO_COP 1083#ifndef QT_NO_COP
1080 1084
1081 QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); 1085 QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" );
1082 e << file.name(); 1086 e << file.name();
1083#endif 1087#endif
1084} 1088}
1085 1089
1086void ServerDTP::connected() 1090void ServerDTP::connected()
@@ -1089,17 +1093,17 @@ void ServerDTP::connected()
1089 switch ( mode ) { 1093 switch ( mode ) {
1090 case SendFile : 1094 case SendFile :
1091 if ( !file.exists() || !file.open( IO_ReadOnly) ) { 1095 if ( !file.exists() || !file.open( IO_ReadOnly) ) {
1092 emit failed(); 1096 emit failed();
1093 mode = Idle; 1097 mode = Idle;
1094 return ; 1098 return ;
1095 } 1099 }
1096 1100
1097 //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); 1101 //odebug << "Debug: Sending file '" << file.name() << "'" << oendl;
1098 1102
1099 bytes_written = 0; 1103 bytes_written = 0;
1100 if ( file.size() == 0 ) { 1104 if ( file.size() == 0 ) {
1101 //make sure it doesn't hang on empty files 1105 //make sure it doesn't hang on empty files
1102 file.close(); 1106 file.close();
1103 emit completed(); 1107 emit completed();
1104 mode = Idle; 1108 mode = Idle;
1105 } 1109 }
@@ -1111,35 +1115,35 @@ void ServerDTP::connected()
1111 int bytes = file.readBlock( s.data(), block_size ); 1115 int bytes = file.readBlock( s.data(), block_size );
1112 writeBlock( s.data(), bytes ); 1116 writeBlock( s.data(), bytes );
1113 } 1117 }
1114 } 1118 }
1115 break; 1119 break;
1116 case SendGzipFile: 1120 case SendGzipFile:
1117 if ( createTargzProc->isRunning() ) { 1121 if ( createTargzProc->isRunning() ) {
1118 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY 1122 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY
1119 qWarning("Previous tar --gzip process is still running; killing it..."); 1123 owarn << "Previous tar --gzip process is still running; killing it..." << oendl;
1120 createTargzProc->kill(); 1124 createTargzProc->kill();
1121 } 1125 }
1122 1126
1123 bytes_written = 0; 1127 bytes_written = 0;
1124 qDebug("==>start send tar process"); 1128 odebug << "==>start send tar process" << oendl;
1125 if ( !createTargzProc->start(Opie::Core::OProcess::NotifyOnExit, Opie::Core::OProcess::Stdout) ) 1129 if ( !createTargzProc->start(Opie::Core::OProcess::NotifyOnExit, Opie::Core::OProcess::Stdout) )
1126 qWarning("Error starting %s or %s", 1130 qWarning("Error starting %s or %s",
1127 createTargzProc->args()[0].data(), 1131 createTargzProc->args()[0].data(),
1128 gzipProc->args()[0].data()); 1132 gzipProc->args()[0].data());
1129 break; 1133 break;
1130 case SendBuffer: 1134 case SendBuffer:
1131 if ( !buf.open( IO_ReadOnly) ) { 1135 if ( !buf.open( IO_ReadOnly) ) {
1132 emit failed(); 1136 emit failed();
1133 mode = Idle; 1137 mode = Idle;
1134 return ; 1138 return ;
1135 } 1139 }
1136 1140
1137 // qDebug( "Debug: Sending byte array" ); 1141 // odebug << "Debug: Sending byte array" << oendl;
1138 bytes_written = 0; 1142 bytes_written = 0;
1139 while ( !buf.atEnd() ) 1143 while ( !buf.atEnd() )
1140 putch( buf.getch() ); 1144 putch( buf.getch() );
1141 buf.close(); 1145 buf.close();
1142 break; 1146 break;
1143 case RetrieveFile: 1147 case RetrieveFile:
1144 // retrieve file mode 1148 // retrieve file mode
1145 if ( file.exists() && !file.remove() ) { 1149 if ( file.exists() && !file.remove() ) {
@@ -1148,39 +1152,39 @@ void ServerDTP::connected()
1148 return ; 1152 return ;
1149 } 1153 }
1150 1154
1151 if ( !file.open( IO_WriteOnly) ) { 1155 if ( !file.open( IO_WriteOnly) ) {
1152 emit failed(); 1156 emit failed();
1153 mode = Idle; 1157 mode = Idle;
1154 return ; 1158 return ;
1155 } 1159 }
1156 // qDebug( "Debug: Retrieving file %s", file.name().latin1() ); 1160 // odebug << "Debug: Retrieving file " << file.name() << "" << oendl;
1157 break; 1161 break;
1158 case RetrieveGzipFile: 1162 case RetrieveGzipFile:
1159 qDebug("=-> starting tar process to receive .tgz file"); 1163 odebug << "=-> starting tar process to receive .tgz file" << oendl;
1160 break; 1164 break;
1161 case RetrieveBuffer: 1165 case RetrieveBuffer:
1162 // retrieve buffer mode 1166 // retrieve buffer mode
1163 if ( !buf.open( IO_WriteOnly) ) { 1167 if ( !buf.open( IO_WriteOnly) ) {
1164 emit failed(); 1168 emit failed();
1165 mode = Idle; 1169 mode = Idle;
1166 return ; 1170 return ;
1167 } 1171 }
1168 // qDebug( "Debug: Retrieving byte array" ); 1172 // odebug << "Debug: Retrieving byte array" << oendl;
1169 break; 1173 break;
1170 case Idle: 1174 case Idle:
1171 qDebug("connection established but mode set to Idle; BUG!"); 1175 odebug << "connection established but mode set to Idle; BUG!" << oendl;
1172 break; 1176 break;
1173 } 1177 }
1174} 1178}
1175 1179
1176void ServerDTP::connectionClosed() 1180void ServerDTP::connectionClosed()
1177{ 1181{
1178 //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written ); 1182 //odebug << "Debug: Data connection closed " << bytes_written << " bytes written" << oendl;
1179 1183
1180 // send file mode 1184 // send file mode
1181 if ( SendFile == mode ) { 1185 if ( SendFile == mode ) {
1182 if ( bytes_written == file.size() ) 1186 if ( bytes_written == file.size() )
1183 emit completed(); 1187 emit completed();
1184 else 1188 else
1185 emit failed(); 1189 emit failed();
1186 } 1190 }
@@ -1195,17 +1199,17 @@ void ServerDTP::connectionClosed()
1195 1199
1196 // retrieve file mode 1200 // retrieve file mode
1197 else if ( RetrieveFile == mode ) { 1201 else if ( RetrieveFile == mode ) {
1198 file.close(); 1202 file.close();
1199 emit completed(); 1203 emit completed();
1200 } 1204 }
1201 1205
1202 else if ( RetrieveGzipFile == mode ) { 1206 else if ( RetrieveGzipFile == mode ) {
1203 qDebug("Done writing ungzip file; closing input"); 1207 odebug << "Done writing ungzip file; closing input" << oendl;
1204 gzipProc->flushStdin(); 1208 gzipProc->flushStdin();
1205 gzipProc->closeStdin(); 1209 gzipProc->closeStdin();
1206 } 1210 }
1207 1211
1208 // retrieve buffer mode 1212 // retrieve buffer mode
1209 else if ( RetrieveBuffer == mode ) { 1213 else if ( RetrieveBuffer == mode ) {
1210 buf.close(); 1214 buf.close();
1211 emit completed(); 1215 emit completed();
@@ -1217,34 +1221,34 @@ void ServerDTP::connectionClosed()
1217void ServerDTP::bytesWritten( int bytes ) 1221void ServerDTP::bytesWritten( int bytes )
1218{ 1222{
1219 bytes_written += bytes; 1223 bytes_written += bytes;
1220 1224
1221 // send file mode 1225 // send file mode
1222 if ( SendFile == mode ) { 1226 if ( SendFile == mode ) {
1223 1227
1224 if ( bytes_written == file.size() ) { 1228 if ( bytes_written == file.size() ) {
1225 // qDebug( "Debug: Sending complete: %d bytes", file.size() ); 1229 // odebug << "Debug: Sending complete: " << file.size() << " bytes" << oendl;
1226 file.close(); 1230 file.close();
1227 emit completed(); 1231 emit completed();
1228 mode = Idle; 1232 mode = Idle;
1229 } 1233 }
1230 else if ( !file.atEnd() ) { 1234 else if ( !file.atEnd() ) {
1231 QCString s; 1235 QCString s;
1232 s.resize( block_size ); 1236 s.resize( block_size );
1233 int bytes = file.readBlock( s.data(), block_size ); 1237 int bytes = file.readBlock( s.data(), block_size );
1234 writeBlock( s.data(), bytes ); 1238 writeBlock( s.data(), bytes );
1235 } 1239 }
1236 } 1240 }
1237 1241
1238 // send buffer mode 1242 // send buffer mode
1239 if ( SendBuffer == mode ) { 1243 if ( SendBuffer == mode ) {
1240 1244
1241 if ( bytes_written == buf.size() ) { 1245 if ( bytes_written == buf.size() ) {
1242 // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); 1246 // odebug << "Debug: Sending complete: " << buf.size() << " bytes" << oendl;
1243 emit completed(); 1247 emit completed();
1244 mode = Idle; 1248 mode = Idle;
1245 } 1249 }
1246 } 1250 }
1247} 1251}
1248 1252
1249void ServerDTP::readyRead() 1253void ServerDTP::readyRead()
1250{ 1254{
@@ -1258,53 +1262,53 @@ void ServerDTP::readyRead()
1258 else if ( RetrieveGzipFile == mode ) { 1262 else if ( RetrieveGzipFile == mode ) {
1259 if ( !gzipProc->isRunning() ) 1263 if ( !gzipProc->isRunning() )
1260 gzipProc->start(Opie::Core::OProcess::NotifyOnExit, (Opie::Core::OProcess::Communication) ( Opie::Core::OProcess::Stdin | Opie::Core::OProcess::Stdout )); 1264 gzipProc->start(Opie::Core::OProcess::NotifyOnExit, (Opie::Core::OProcess::Communication) ( Opie::Core::OProcess::Stdin | Opie::Core::OProcess::Stdout ));
1261 1265
1262 QByteArray s; 1266 QByteArray s;
1263 s.resize( bytesAvailable() ); 1267 s.resize( bytesAvailable() );
1264 readBlock( s.data(), bytesAvailable() ); 1268 readBlock( s.data(), bytesAvailable() );
1265 gzipProc->writeStdin( s.data(), s.size() ); 1269 gzipProc->writeStdin( s.data(), s.size() );
1266 qDebug("wrote %d bytes to ungzip ", s.size() ); 1270 odebug << "wrote " << s.size() << " bytes to ungzip " << oendl;
1267 } 1271 }
1268 // retrieve buffer mode 1272 // retrieve buffer mode
1269 else if ( RetrieveBuffer == mode ) { 1273 else if ( RetrieveBuffer == mode ) {
1270 QCString s; 1274 QCString s;
1271 s.resize( bytesAvailable() ); 1275 s.resize( bytesAvailable() );
1272 readBlock( s.data(), bytesAvailable() ); 1276 readBlock( s.data(), bytesAvailable() );
1273 buf.writeBlock( s.data(), s.size() ); 1277 buf.writeBlock( s.data(), s.size() );
1274 } 1278 }
1275} 1279}
1276 1280
1277void ServerDTP::writeTargzBlock(Opie::Core::OProcess *, char *buffer, int buflen) 1281void ServerDTP::writeTargzBlock(Opie::Core::OProcess *, char *buffer, int buflen)
1278{ 1282{
1279 writeBlock( buffer, buflen ); 1283 writeBlock( buffer, buflen );
1280 qDebug("writeTargzBlock %d", buflen); 1284 odebug << "writeTargzBlock " << buflen << "" << oendl;
1281 if ( !createTargzProc->isRunning() ) { 1285 if ( !createTargzProc->isRunning() ) {
1282 qDebug("tar and gzip done"); 1286 odebug << "tar and gzip done" << oendl;
1283 emit completed(); 1287 emit completed();
1284 mode = Idle; 1288 mode = Idle;
1285 disconnect( gzipProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ), 1289 disconnect( gzipProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ),
1286 this, SLOT( writeTargzBlock(Opie::Core::OProcess*,char*,int) ) ); 1290 this, SLOT( writeTargzBlock(Opie::Core::OProcess*,char*,int) ) );
1287 } 1291 }
1288} 1292}
1289 1293
1290void ServerDTP::targzDone() 1294void ServerDTP::targzDone()
1291{ 1295{
1292 //qDebug("targz done"); 1296 //odebug << "targz done" << oendl;
1293 disconnect( createTargzProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ), 1297 disconnect( createTargzProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ),
1294 this, SLOT( gzipTarBlock(Opie::Core::OProcess*,char*,int) ) ); 1298 this, SLOT( gzipTarBlock(Opie::Core::OProcess*,char*,int) ) );
1295 gzipProc->closeStdin(); 1299 gzipProc->closeStdin();
1296} 1300}
1297 1301
1298void ServerDTP::gzipTarBlock(Opie::Core::OProcess *, char *buffer, int buflen) 1302void ServerDTP::gzipTarBlock(Opie::Core::OProcess *, char *buffer, int buflen)
1299{ 1303{
1300 //qDebug("gzipTarBlock"); 1304 //odebug << "gzipTarBlock" << oendl;
1301 if ( !gzipProc->isRunning() ) { 1305 if ( !gzipProc->isRunning() ) {
1302 //qDebug("auto start gzip proc"); 1306 //odebug << "auto start gzip proc" << oendl;
1303 gzipProc->start(Opie::Core::OProcess::NotifyOnExit, (Opie::Core::OProcess::Communication) ( Opie::Core::OProcess::Stdin | Opie::Core::OProcess::Stdout )); 1307 gzipProc->start(Opie::Core::OProcess::NotifyOnExit, (Opie::Core::OProcess::Communication) ( Opie::Core::OProcess::Stdin | Opie::Core::OProcess::Stdout ));
1304 } 1308 }
1305 gzipProc->writeStdin( buffer, buflen ); 1309 gzipProc->writeStdin( buffer, buflen );
1306} 1310}
1307 1311
1308void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) 1312void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port )
1309{ 1313{
1310 file.setName( fn ); 1314 file.setName( fn );
@@ -1330,45 +1334,45 @@ void ServerDTP::sendGzipFile( const QString &fn,
1330 const QStringList &archiveTargets ) 1334 const QStringList &archiveTargets )
1331{ 1335{
1332 mode = SendGzipFile; 1336 mode = SendGzipFile;
1333 file.setName( fn ); 1337 file.setName( fn );
1334 1338
1335 QStringList args = "tar"; 1339 QStringList args = "tar";
1336 args += "-cv"; 1340 args += "-cv";
1337 args += archiveTargets; 1341 args += archiveTargets;
1338 qDebug("sendGzipFile %s", args.join(" ").latin1() ); 1342 odebug << "sendGzipFile " << args.join(" ") << "" << oendl;
1339 createTargzProc->clearArguments( ); 1343 createTargzProc->clearArguments( );
1340 *createTargzProc << args; 1344 *createTargzProc << args;
1341 connect( createTargzProc, 1345 connect( createTargzProc,
1342 SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ), SLOT( gzipTarBlock(Opie::Core::OProcess*,char*,int) ) ); 1346 SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ), SLOT( gzipTarBlock(Opie::Core::OProcess*,char*,int) ) );
1343 1347
1344 gzipProc->clearArguments( ); 1348 gzipProc->clearArguments( );
1345 *gzipProc << "gzip"; 1349 *gzipProc << "gzip";
1346 connect( gzipProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ), 1350 connect( gzipProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ),
1347 SLOT( writeTargzBlock(Opie::Core::OProcess*,char*,int) ) ); 1351 SLOT( writeTargzBlock(Opie::Core::OProcess*,char*,int) ) );
1348} 1352}
1349 1353
1350void ServerDTP::gunzipDone() 1354void ServerDTP::gunzipDone()
1351{ 1355{
1352 qDebug("gunzipDone"); 1356 odebug << "gunzipDone" << oendl;
1353 disconnect( gzipProc, SIGNAL( processExited() ), 1357 disconnect( gzipProc, SIGNAL( processExited() ),
1354 this, SLOT( gunzipDone() ) ); 1358 this, SLOT( gunzipDone() ) );
1355 retrieveTargzProc->closeStdin(); 1359 retrieveTargzProc->closeStdin();
1356 disconnect( gzipProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ), 1360 disconnect( gzipProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ),
1357 this, SLOT( tarExtractBlock(Opie::Core::OProcess*,char*,int) ) ); 1361 this, SLOT( tarExtractBlock(Opie::Core::OProcess*,char*,int) ) );
1358} 1362}
1359 1363
1360void ServerDTP::tarExtractBlock(Opie::Core::OProcess *, char *buffer, int buflen) 1364void ServerDTP::tarExtractBlock(Opie::Core::OProcess *, char *buffer, int buflen)
1361{ 1365{
1362 qDebug("tarExtractBlock"); 1366 odebug << "tarExtractBlock" << oendl;
1363 if ( !retrieveTargzProc->isRunning() ) { 1367 if ( !retrieveTargzProc->isRunning() ) {
1364 qDebug("auto start ungzip proc"); 1368 odebug << "auto start ungzip proc" << oendl;
1365 if ( !retrieveTargzProc->start(Opie::Core::OProcess::NotifyOnExit, Opie::Core::OProcess::Stdin) ) 1369 if ( !retrieveTargzProc->start(Opie::Core::OProcess::NotifyOnExit, Opie::Core::OProcess::Stdin) )
1366 qWarning(" failed to start tar -x process"); 1370 owarn << " failed to start tar -x process" << oendl;
1367 } 1371 }
1368 retrieveTargzProc->writeStdin( buffer, buflen ); 1372 retrieveTargzProc->writeStdin( buffer, buflen );
1369} 1373}
1370 1374
1371 1375
1372void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) 1376void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port )
1373{ 1377{
1374 file.setName( fn ); 1378 file.setName( fn );
@@ -1379,17 +1383,17 @@ void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT
1379void ServerDTP::retrieveFile( const QString fn ) 1383void ServerDTP::retrieveFile( const QString fn )
1380{ 1384{
1381 file.setName( fn ); 1385 file.setName( fn );
1382 mode = RetrieveFile; 1386 mode = RetrieveFile;
1383} 1387}
1384 1388
1385void ServerDTP::retrieveGzipFile( const QString &fn ) 1389void ServerDTP::retrieveGzipFile( const QString &fn )
1386{ 1390{
1387 qDebug("retrieveGzipFile %s", fn.latin1()); 1391 odebug << "retrieveGzipFile " << fn << "" << oendl;
1388 file.setName( fn ); 1392 file.setName( fn );
1389 mode = RetrieveGzipFile; 1393 mode = RetrieveGzipFile;
1390 1394
1391 gzipProc->clearArguments(); 1395 gzipProc->clearArguments();
1392 *gzipProc << "gunzip"; 1396 *gzipProc << "gunzip";
1393 connect( gzipProc, SIGNAL( readyReadStdout() ), 1397 connect( gzipProc, SIGNAL( readyReadStdout() ),
1394 SLOT( tarExtractBlock() ) ); 1398 SLOT( tarExtractBlock() ) );
1395 connect( gzipProc, SIGNAL( processExited() ), 1399 connect( gzipProc, SIGNAL( processExited() ),