summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-09-06 17:46:33 (UTC)
committer llornkcor <llornkcor>2002-09-06 17:46:33 (UTC)
commit4acfa3f53762b6c786e421444d23c49c279e556f (patch) (unidiff)
treeff4522ecadcbdcd0410f91e9b88aa2205948b692
parentd4257a0388d3444b5318436449423d27cdd85acf (diff)
downloadopie-4acfa3f53762b6c786e421444d23c49c279e556f.zip
opie-4acfa3f53762b6c786e421444d23c49c279e556f.tar.gz
opie-4acfa3f53762b6c786e421444d23c49c279e556f.tar.bz2
TT gave us the wrong sync password! ^#$^@&^
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/transferserver.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index ed3e2c6..28b7b49 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -1,1199 +1,1201 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#define _XOPEN_SOURCE 20#define _XOPEN_SOURCE
21#include <pwd.h> 21#include <pwd.h>
22#include <sys/types.h> 22#include <sys/types.h>
23#include <unistd.h> 23#include <unistd.h>
24#include <stdlib.h> 24#include <stdlib.h>
25#include <time.h> 25#include <time.h>
26#include <shadow.h> 26#include <shadow.h>
27 27
28extern "C" { 28extern "C" {
29#include <uuid/uuid.h> 29#include <uuid/uuid.h>
30#define UUID_H_INCLUDED 30#define UUID_H_INCLUDED
31} 31}
32 32
33#if defined(_OS_LINUX_) 33#if defined(_OS_LINUX_)
34#include <shadow.h> 34#include <shadow.h>
35#endif 35#endif
36 36
37#include <qdir.h> 37#include <qdir.h>
38#include <qfile.h> 38#include <qfile.h>
39#include <qtextstream.h> 39#include <qtextstream.h>
40#include <qdatastream.h> 40#include <qdatastream.h>
41#include <qmessagebox.h> 41#include <qmessagebox.h>
42#include <qstringlist.h> 42#include <qstringlist.h>
43#include <qfileinfo.h> 43#include <qfileinfo.h>
44#include <qregexp.h> 44#include <qregexp.h>
45//#include <qpe/qcopchannel_qws.h> 45//#include <qpe/qcopchannel_qws.h>
46#include <qpe/process.h> 46#include <qpe/process.h>
47#include <qpe/global.h> 47#include <qpe/global.h>
48#include <qpe/config.h> 48#include <qpe/config.h>
49#include <qpe/contact.h> 49#include <qpe/contact.h>
50#include <qpe/quuid.h> 50#include <qpe/quuid.h>
51#include <qpe/version.h> 51#include <qpe/version.h>
52#ifdef QWS 52#ifdef QWS
53#include <qpe/qcopenvelope_qws.h> 53#include <qpe/qcopenvelope_qws.h>
54#endif 54#endif
55 55
56#include "transferserver.h" 56#include "transferserver.h"
57#include "qprocess.h" 57#include "qprocess.h"
58 58
59const int block_size = 51200; 59const int block_size = 51200;
60 60
61TransferServer::TransferServer( Q_UINT16 port, QObject *parent , 61TransferServer::TransferServer( Q_UINT16 port, QObject *parent ,
62 const char* name ) 62 const char* name )
63 : QServerSocket( port, 1, parent, name ) 63 : QServerSocket( port, 1, parent, name )
64{ 64{
65 if ( !ok() ) 65 if ( !ok() )
66 qWarning( "Failed to bind to port %d", port ); 66 qWarning( "Failed to bind to port %d", port );
67} 67}
68 68
69TransferServer::~TransferServer() 69TransferServer::~TransferServer()
70{ 70{
71 71
72} 72}
73 73
74void TransferServer::newConnection( int socket ) 74void TransferServer::newConnection( int socket )
75{ 75{
76 (void) new ServerPI( socket, this ); 76 (void) new ServerPI( socket, this );
77} 77}
78 78
79QString SyncAuthentication::serverId() 79QString SyncAuthentication::serverId()
80{ 80{
81 Config cfg("Security"); 81 Config cfg("Security");
82 cfg.setGroup("Sync"); 82 cfg.setGroup("Sync");
83 QString r=cfg.readEntry("serverid"); 83 QString r=cfg.readEntry("serverid");
84 if ( r.isEmpty() ) { 84 if ( r.isEmpty() ) {
85 uuid_t uuid; 85 uuid_t uuid;
86 uuid_generate( uuid ); 86 uuid_generate( uuid );
87 cfg.writeEntry("serverid",(r = QUuid( uuid ).toString())); 87 cfg.writeEntry("serverid",(r = QUuid( uuid ).toString()));
88 } 88 }
89 return r; 89 return r;
90} 90}
91 91
92QString SyncAuthentication::ownerName() 92QString SyncAuthentication::ownerName()
93{ 93{
94 QString vfilename = Global::applicationFileName("addressbook", 94 QString vfilename = Global::applicationFileName("addressbook",
95 "businesscard.vcf"); 95 "businesscard.vcf");
96 if (QFile::exists(vfilename)) { 96 if (QFile::exists(vfilename)) {
97 Contact c; 97 Contact c;
98 c = Contact::readVCard( vfilename )[0]; 98 c = Contact::readVCard( vfilename )[0];
99 return c.fullName(); 99 return c.fullName();
100 } 100 }
101 101
102 return ""; 102 return "";
103} 103}
104 104
105QString SyncAuthentication::loginName() 105QString SyncAuthentication::loginName()
106{ 106{
107 struct passwd *pw; 107 struct passwd *pw;
108 pw = getpwuid( geteuid() ); 108 pw = getpwuid( geteuid() );
109 return QString::fromLocal8Bit( pw->pw_name ); 109 return QString::fromLocal8Bit( pw->pw_name );
110} 110}
111 111
112int SyncAuthentication::isAuthorized(QHostAddress peeraddress) 112int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
113{ 113{
114 Config cfg("Security"); 114 Config cfg("Security");
115 cfg.setGroup("Sync"); 115 cfg.setGroup("Sync");
116// QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); 116// QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
117 uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100); 117 uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100);
118 118
119// QHostAddress allowed; 119// QHostAddress allowed;
120// allowed.setAddress(allowedstr); 120// allowed.setAddress(allowedstr);
121// uint auth_peer = allowed.ip4Addr(); 121// uint auth_peer = allowed.ip4Addr();
122 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); 122 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24);
123 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined 123 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined
124 ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits)); 124 ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits));
125 return (peeraddress.ip4Addr() & mask) == auth_peer; 125 return (peeraddress.ip4Addr() & mask) == auth_peer;
126} 126}
127 127
128bool SyncAuthentication::checkUser( const QString& user ) 128bool SyncAuthentication::checkUser( const QString& user )
129{ 129{
130 if ( user.isEmpty() ) return FALSE; 130 if ( user.isEmpty() ) return FALSE;
131 QString euser = loginName(); 131 QString euser = loginName();
132 return user == euser; 132 return user == euser;
133} 133}
134 134
135bool SyncAuthentication::checkPassword( const QString& password ) 135bool SyncAuthentication::checkPassword( const QString& password )
136{ 136{
137#ifdef ALLOW_UNIX_USER_FTP 137#ifdef ALLOW_UNIX_USER_FTP
138 // First, check system password... 138 // First, check system password...
139 139
140 struct passwd *pw = 0; 140 struct passwd *pw = 0;
141 struct spwd *spw = 0; 141 struct spwd *spw = 0;
142 142
143 pw = getpwuid( geteuid() ); 143 pw = getpwuid( geteuid() );
144 spw = getspnam( pw->pw_name ); 144 spw = getspnam( pw->pw_name );
145 145
146 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); 146 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
147 if ( cpwd == "x" && spw ) 147 if ( cpwd == "x" && spw )
148 cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); 148 cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
149 149
150 // Note: some systems use more than crypt for passwords. 150 // Note: some systems use more than crypt for passwords.
151 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); 151 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
152 if ( cpwd == cpassword ) 152 if ( cpwd == cpassword )
153 return TRUE; 153 return TRUE;
154#endif 154#endif
155 155
156 static int lastdenial=0; 156 static int lastdenial=0;
157 static int denials=0; 157 static int denials=0;
158 int now = time(0); 158 int now = time(0);
159 159
160 // Detect old Qtopia Desktop (no password) 160 // Detect old Qtopia Desktop (no password)
161 if ( password.isEmpty() ) { 161 if ( password.isEmpty() ) {
162 if ( denials < 1 || now > lastdenial+600 ) { 162 if ( denials < 1 || now > lastdenial+600 ) {
163 QMessageBox::warning( 0,tr("Sync Connection"), 163 QMessageBox::warning( 0,tr("Sync Connection"),
164 tr("<p>An unauthorized system is requesting access to this device." 164 tr("<p>An unauthorized system is requesting access to this device."
165 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " 165 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, "
166 "please upgrade."), 166 "please upgrade."),
167 tr("Deny") ); 167 tr("Deny") );
168 denials++; 168 denials++;
169 lastdenial=now; 169 lastdenial=now;
170 } 170 }
171 return FALSE; 171 return FALSE;
172 } 172 }
173 173
174 // Second, check sync password... 174 // Second, check sync password...
175 if ( password.left(6) == "Qtopia" ) { 175 if ( password.left(6) == "rootme" ) {
176 // fuckin TT gave us the wrong sync password.
177 // what a dumbassed password is rootme anyway.
176 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); 178 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) );
177 Config cfg("Security"); 179 Config cfg("Security");
178 cfg.setGroup("Sync"); 180 cfg.setGroup("Sync");
179 QString pwds = cfg.readEntry("Passwords"); 181 QString pwds = cfg.readEntry("Passwords");
180 if ( QStringList::split(QChar(' '),pwds).contains(cpassword) ) 182 if ( QStringList::split(QChar(' '),pwds).contains(cpassword) )
181 return TRUE; 183 return TRUE;
182 184
183 // Unrecognized system. Be careful... 185 // Unrecognized system. Be careful...
184 186
185 if ( (denials > 2 && now < lastdenial+600) 187 if ( (denials > 2 && now < lastdenial+600)
186 || QMessageBox::warning(0,tr("Sync Connection"), 188 || QMessageBox::warning(0,tr("Sync Connection"),
187 tr("<p>An unrecognized system is requesting access to this device." 189 tr("<p>An unrecognized system is requesting access to this device."
188 "<p>If you have just initiated a Sync for the first time, this is normal."), 190 "<p>If you have just initiated a Sync for the first time, this is normal."),
189 tr("Allow"),tr("Deny"))==1 ) 191 tr("Allow"),tr("Deny"))==1 )
190 { 192 {
191 denials++; 193 denials++;
192 lastdenial=now; 194 lastdenial=now;
193 return FALSE; 195 return FALSE;
194 } else { 196 } else {
195 denials=0; 197 denials=0;
196 cfg.writeEntry("Passwords",pwds+" "+cpassword); 198 cfg.writeEntry("Passwords",pwds+" "+cpassword);
197 return TRUE; 199 return TRUE;
198 } 200 }
199 } 201 }
200 202
201 return FALSE; 203 return FALSE;
202} 204}
203 205
204ServerPI::ServerPI( int socket, QObject *parent , const char* name ) 206ServerPI::ServerPI( int socket, QObject *parent , const char* name )
205 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) 207 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 )
206{ 208{
207 state = Connected; 209 state = Connected;
208 210
209 setSocket( socket ); 211 setSocket( socket );
210 212
211 peerport = peerPort(); 213 peerport = peerPort();
212 peeraddress = peerAddress(); 214 peeraddress = peerAddress();
213 215
214#ifndef INSECURE 216#ifndef INSECURE
215 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 217 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
216 state = Forbidden; 218 state = Forbidden;
217 startTimer( 0 ); 219 startTimer( 0 );
218 } else 220 } else
219#endif 221#endif
220 { 222 {
221 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 223 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
222 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 224 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
223 225
224 passiv = FALSE; 226 passiv = FALSE;
225 for( int i = 0; i < 4; i++ ) 227 for( int i = 0; i < 4; i++ )
226 wait[i] = FALSE; 228 wait[i] = FALSE;
227 229
228 send( "220 Qtopia " QPE_VERSION " FTP Server" ); 230 send( "220 Qtopia " QPE_VERSION " FTP Server" );
229 state = Wait_USER; 231 state = Wait_USER;
230 232
231 dtp = new ServerDTP( this ); 233 dtp = new ServerDTP( this );
232 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); 234 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) );
233 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); 235 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) );
234 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); 236 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) );
235 237
236 238
237 directory = QDir::currentDirPath(); 239 directory = QDir::currentDirPath();
238 240
239 static int p = 1024; 241 static int p = 1024;
240 242
241 while ( !serversocket || !serversocket->ok() ) { 243 while ( !serversocket || !serversocket->ok() ) {
242 delete serversocket; 244 delete serversocket;
243 serversocket = new ServerSocket( ++p, this ); 245 serversocket = new ServerSocket( ++p, this );
244 } 246 }
245 connect( serversocket, SIGNAL( newIncomming( int ) ), 247 connect( serversocket, SIGNAL( newIncomming( int ) ),
246 SLOT( newConnection( int ) ) ); 248 SLOT( newConnection( int ) ) );
247 } 249 }
248} 250}
249 251
250ServerPI::~ServerPI() 252ServerPI::~ServerPI()
251{ 253{
252 254
253} 255}
254 256
255void ServerPI::connectionClosed() 257void ServerPI::connectionClosed()
256{ 258{
257 // qDebug( "Debug: Connection closed" ); 259 // qDebug( "Debug: Connection closed" );
258 delete this; 260 delete this;
259} 261}
260 262
261void ServerPI::send( const QString& msg ) 263void ServerPI::send( const QString& msg )
262{ 264{
263 QTextStream os( this ); 265 QTextStream os( this );
264 os << msg << endl; 266 os << msg << endl;
265 //qDebug( "Reply: %s", msg.latin1() ); 267 //qDebug( "Reply: %s", msg.latin1() );
266} 268}
267 269
268void ServerPI::read() 270void ServerPI::read()
269{ 271{
270 while ( canReadLine() ) 272 while ( canReadLine() )
271 process( readLine().stripWhiteSpace() ); 273 process( readLine().stripWhiteSpace() );
272} 274}
273 275
274bool ServerPI::checkReadFile( const QString& file ) 276bool ServerPI::checkReadFile( const QString& file )
275{ 277{
276 QString filename; 278 QString filename;
277 279
278 if ( file[0] != "/" ) 280 if ( file[0] != "/" )
279 filename = directory.path() + "/" + file; 281 filename = directory.path() + "/" + file;
280 else 282 else
281 filename = file; 283 filename = file;
282 284
283 QFileInfo fi( filename ); 285 QFileInfo fi( filename );
284 return ( fi.exists() && fi.isReadable() ); 286 return ( fi.exists() && fi.isReadable() );
285} 287}
286 288
287bool ServerPI::checkWriteFile( const QString& file ) 289bool ServerPI::checkWriteFile( const QString& file )
288{ 290{
289 QString filename; 291 QString filename;
290 292
291 if ( file[0] != "/" ) 293 if ( file[0] != "/" )
292 filename = directory.path() + "/" + file; 294 filename = directory.path() + "/" + file;
293 else 295 else
294 filename = file; 296 filename = file;
295 297
296 QFileInfo fi( filename ); 298 QFileInfo fi( filename );
297 299
298 if ( fi.exists() ) 300 if ( fi.exists() )
299 if ( !QFile( filename ).remove() ) 301 if ( !QFile( filename ).remove() )
300 return FALSE; 302 return FALSE;
301 return TRUE; 303 return TRUE;
302} 304}
303 305
304void ServerPI::process( const QString& message ) 306void ServerPI::process( const QString& message )
305{ 307{
306 //qDebug( "Command: %s", message.latin1() ); 308 //qDebug( "Command: %s", message.latin1() );
307 309
308 // split message using "," as separator 310 // split message using "," as separator
309 QStringList msg = QStringList::split( " ", message ); 311 QStringList msg = QStringList::split( " ", message );
310 if ( msg.isEmpty() ) return; 312 if ( msg.isEmpty() ) return;
311 313
312 // command token 314 // command token
313 QString cmd = msg[0].upper(); 315 QString cmd = msg[0].upper();
314 316
315 // argument token 317 // argument token
316 QString arg; 318 QString arg;
317 if ( msg.count() >= 2 ) 319 if ( msg.count() >= 2 )
318 arg = msg[1]; 320 arg = msg[1];
319 321
320 // full argument string 322 // full argument string
321 QString args; 323 QString args;
322 if ( msg.count() >= 2 ) { 324 if ( msg.count() >= 2 ) {
323 QStringList copy( msg ); 325 QStringList copy( msg );
324 // FIXME: for Qt3 326 // FIXME: for Qt3
325 // copy.pop_front() 327 // copy.pop_front()
326 copy.remove( copy.begin() ); 328 copy.remove( copy.begin() );
327 args = copy.join( " " ); 329 args = copy.join( " " );
328 } 330 }
329 331
330 //qDebug( "args: %s", args.latin1() ); 332 //qDebug( "args: %s", args.latin1() );
331 333
332 // we always respond to QUIT, regardless of state 334 // we always respond to QUIT, regardless of state
333 if ( cmd == "QUIT" ) { 335 if ( cmd == "QUIT" ) {
334 send( "211 Good bye!" ); 336 send( "211 Good bye!" );
335 delete this; 337 delete this;
336 return; 338 return;
337 } 339 }
338 340
339 // connected to client 341 // connected to client
340 if ( Connected == state ) 342 if ( Connected == state )
341 return; 343 return;
342 344
343 // waiting for user name 345 // waiting for user name
344 if ( Wait_USER == state ) { 346 if ( Wait_USER == state ) {
345 347
346 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { 348 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
347 send( "530 Please login with USER and PASS" ); 349 send( "530 Please login with USER and PASS" );
348 return; 350 return;
349 } 351 }
350 send( "331 User name ok, need password" ); 352 send( "331 User name ok, need password" );
351 state = Wait_PASS; 353 state = Wait_PASS;
352 return; 354 return;
353 } 355 }
354 356
355 // waiting for password 357 // waiting for password
356 if ( Wait_PASS == state ) { 358 if ( Wait_PASS == state ) {
357 359
358 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { 360 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
359 send( "530 Please login with USER and PASS" ); 361 send( "530 Please login with USER and PASS" );
360 return; 362 return;
361 } 363 }
362 send( "230 User logged in, proceed" ); 364 send( "230 User logged in, proceed" );
363 state = Ready; 365 state = Ready;
364 return; 366 return;
365 } 367 }
366 368
367 // ACCESS CONTROL COMMANDS 369 // ACCESS CONTROL COMMANDS
368 370
369 371
370 // account (ACCT) 372 // account (ACCT)
371 if ( cmd == "ACCT" ) { 373 if ( cmd == "ACCT" ) {
372 // even wu-ftp does not support it 374 // even wu-ftp does not support it
373 send( "502 Command not implemented" ); 375 send( "502 Command not implemented" );
374 } 376 }
375 377
376 // change working directory (CWD) 378 // change working directory (CWD)
377 else if ( cmd == "CWD" ) { 379 else if ( cmd == "CWD" ) {
378 380
379 if ( !args.isEmpty() ) { 381 if ( !args.isEmpty() ) {
380 if ( directory.cd( args, TRUE ) ) 382 if ( directory.cd( args, TRUE ) )
381 send( "250 Requested file action okay, completed" ); 383 send( "250 Requested file action okay, completed" );
382 else 384 else
383 send( "550 Requested action not taken" ); 385 send( "550 Requested action not taken" );
384 } 386 }
385 else 387 else
386 send( "500 Syntax error, command unrecognized" ); 388 send( "500 Syntax error, command unrecognized" );
387 } 389 }
388 390
389 // change to parent directory (CDUP) 391 // change to parent directory (CDUP)
390 else if ( cmd == "CDUP" ) { 392 else if ( cmd == "CDUP" ) {
391 if ( directory.cdUp() ) 393 if ( directory.cdUp() )
392 send( "250 Requested file action okay, completed" ); 394 send( "250 Requested file action okay, completed" );
393 else 395 else
394 send( "550 Requested action not taken" ); 396 send( "550 Requested action not taken" );
395 } 397 }
396 398
397 // structure mount (SMNT) 399 // structure mount (SMNT)
398 else if ( cmd == "SMNT" ) { 400 else if ( cmd == "SMNT" ) {
399 // even wu-ftp does not support it 401 // even wu-ftp does not support it
400 send( "502 Command not implemented" ); 402 send( "502 Command not implemented" );
401 } 403 }
402 404
403 // reinitialize (REIN) 405 // reinitialize (REIN)
404 else if ( cmd == "REIN" ) { 406 else if ( cmd == "REIN" ) {
405 // even wu-ftp does not support it 407 // even wu-ftp does not support it
406 send( "502 Command not implemented" ); 408 send( "502 Command not implemented" );
407 } 409 }
408 410
409 411
410 // TRANSFER PARAMETER COMMANDS 412 // TRANSFER PARAMETER COMMANDS
411 413
412 414
413 // data port (PORT) 415 // data port (PORT)
414 else if ( cmd == "PORT" ) { 416 else if ( cmd == "PORT" ) {
415 if ( parsePort( arg ) ) 417 if ( parsePort( arg ) )
416 send( "200 Command okay" ); 418 send( "200 Command okay" );
417 else 419 else
418 send( "500 Syntax error, command unrecognized" ); 420 send( "500 Syntax error, command unrecognized" );
419 } 421 }
420 422
421 // passive (PASV) 423 // passive (PASV)
422 else if ( cmd == "PASV" ) { 424 else if ( cmd == "PASV" ) {
423 passiv = TRUE; 425 passiv = TRUE;
424 send( "227 Entering Passive Mode (" 426 send( "227 Entering Passive Mode ("
425 + address().toString().replace( QRegExp( "\\." ), "," ) + "," 427 + address().toString().replace( QRegExp( "\\." ), "," ) + ","
426 + QString::number( ( serversocket->port() ) >> 8 ) + "," 428 + QString::number( ( serversocket->port() ) >> 8 ) + ","
427 + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); 429 + QString::number( ( serversocket->port() ) & 0xFF ) +")" );
428 } 430 }
429 431
430 // representation type (TYPE) 432 // representation type (TYPE)
431 else if ( cmd == "TYPE" ) { 433 else if ( cmd == "TYPE" ) {
432 if ( arg.upper() == "A" || arg.upper() == "I" ) 434 if ( arg.upper() == "A" || arg.upper() == "I" )
433 send( "200 Command okay" ); 435 send( "200 Command okay" );
434 else 436 else
435 send( "504 Command not implemented for that parameter" ); 437 send( "504 Command not implemented for that parameter" );
436 } 438 }
437 439
438 // file structure (STRU) 440 // file structure (STRU)
439 else if ( cmd == "STRU" ) { 441 else if ( cmd == "STRU" ) {
440 if ( arg.upper() == "F" ) 442 if ( arg.upper() == "F" )
441 send( "200 Command okay" ); 443 send( "200 Command okay" );
442 else 444 else
443 send( "504 Command not implemented for that parameter" ); 445 send( "504 Command not implemented for that parameter" );
444 } 446 }
445 447
446 // transfer mode (MODE) 448 // transfer mode (MODE)
447 else if ( cmd == "MODE" ) { 449 else if ( cmd == "MODE" ) {
448 if ( arg.upper() == "S" ) 450 if ( arg.upper() == "S" )
449 send( "200 Command okay" ); 451 send( "200 Command okay" );
450 else 452 else
451 send( "504 Command not implemented for that parameter" ); 453 send( "504 Command not implemented for that parameter" );
452 } 454 }
453 455
454 456
455 // FTP SERVICE COMMANDS 457 // FTP SERVICE COMMANDS
456 458
457 459
458 // retrieve (RETR) 460 // retrieve (RETR)
459 else if ( cmd == "RETR" ) 461 else if ( cmd == "RETR" )
460 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) 462 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) )
461 || backupRestoreGzip( absFilePath( args ) ) ) { 463 || backupRestoreGzip( absFilePath( args ) ) ) {
462 send( "150 File status okay" ); 464 send( "150 File status okay" );
463 sendFile( absFilePath( args ) ); 465 sendFile( absFilePath( args ) );
464 } 466 }
465 else { 467 else {
466 qDebug("550 Requested action not taken"); 468 qDebug("550 Requested action not taken");
467 send( "550 Requested action not taken" ); 469 send( "550 Requested action not taken" );
468 } 470 }
469 471
470 // store (STOR) 472 // store (STOR)
471 else if ( cmd == "STOR" ) 473 else if ( cmd == "STOR" )
472 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { 474 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) {
473 send( "150 File status okay" ); 475 send( "150 File status okay" );
474 retrieveFile( absFilePath( args ) ); 476 retrieveFile( absFilePath( args ) );
475 } 477 }
476 else 478 else
477 send( "550 Requested action not taken" ); 479 send( "550 Requested action not taken" );
478 480
479 // store unique (STOU) 481 // store unique (STOU)
480 else if ( cmd == "STOU" ) { 482 else if ( cmd == "STOU" ) {
481 send( "502 Command not implemented" ); 483 send( "502 Command not implemented" );
482 } 484 }
483 485
484 // append (APPE) 486 // append (APPE)
485 else if ( cmd == "APPE" ) { 487 else if ( cmd == "APPE" ) {
486 send( "502 Command not implemented" ); 488 send( "502 Command not implemented" );
487 } 489 }
488 490
489 // allocate (ALLO) 491 // allocate (ALLO)
490 else if ( cmd == "ALLO" ) { 492 else if ( cmd == "ALLO" ) {
491 send( "200 Command okay" ); 493 send( "200 Command okay" );
492 } 494 }
493 495
494 // restart (REST) 496 // restart (REST)
495 else if ( cmd == "REST" ) { 497 else if ( cmd == "REST" ) {
496 send( "502 Command not implemented" ); 498 send( "502 Command not implemented" );
497 } 499 }
498 500
499 // rename from (RNFR) 501 // rename from (RNFR)
500 else if ( cmd == "RNFR" ) { 502 else if ( cmd == "RNFR" ) {
501 renameFrom = QString::null; 503 renameFrom = QString::null;
502 if ( args.isEmpty() ) 504 if ( args.isEmpty() )
503 send( "500 Syntax error, command unrecognized" ); 505 send( "500 Syntax error, command unrecognized" );
504 else { 506 else {
505 QFile file( absFilePath( args ) ); 507 QFile file( absFilePath( args ) );
506 if ( file.exists() ) { 508 if ( file.exists() ) {
507 send( "350 File exists, ready for destination name" ); 509 send( "350 File exists, ready for destination name" );
508 renameFrom = absFilePath( args ); 510 renameFrom = absFilePath( args );
509 } 511 }
510 else 512 else
511 send( "550 Requested action not taken" ); 513 send( "550 Requested action not taken" );
512 } 514 }
513 } 515 }
514 516
515 // rename to (RNTO) 517 // rename to (RNTO)
516 else if ( cmd == "RNTO" ) { 518 else if ( cmd == "RNTO" ) {
517 if ( lastCommand != "RNFR" ) 519 if ( lastCommand != "RNFR" )
518 send( "503 Bad sequence of commands" ); 520 send( "503 Bad sequence of commands" );
519 else if ( args.isEmpty() ) 521 else if ( args.isEmpty() )
520 send( "500 Syntax error, command unrecognized" ); 522 send( "500 Syntax error, command unrecognized" );
521 else { 523 else {
522 QDir dir( absFilePath( args ) ); 524 QDir dir( absFilePath( args ) );
523 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) 525 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) )
524 send( "250 Requested file action okay, completed." ); 526 send( "250 Requested file action okay, completed." );
525 else 527 else
526 send( "550 Requested action not taken" ); 528 send( "550 Requested action not taken" );
527 } 529 }
528 } 530 }
529 531
530 // abort (ABOR) 532 // abort (ABOR)
531 else if ( cmd.contains( "ABOR" ) ) { 533 else if ( cmd.contains( "ABOR" ) ) {
532 dtp->close(); 534 dtp->close();
533 if ( dtp->dtpMode() != ServerDTP::Idle ) 535 if ( dtp->dtpMode() != ServerDTP::Idle )
534 send( "426 Connection closed; transfer aborted" ); 536 send( "426 Connection closed; transfer aborted" );
535 else 537 else
536 send( "226 Closing data connection" ); 538 send( "226 Closing data connection" );
537 } 539 }
538 540
539 // delete (DELE) 541 // delete (DELE)
540 else if ( cmd == "DELE" ) { 542 else if ( cmd == "DELE" ) {
541 if ( args.isEmpty() ) 543 if ( args.isEmpty() )
542 send( "500 Syntax error, command unrecognized" ); 544 send( "500 Syntax error, command unrecognized" );
543 else { 545 else {
544 QFile file( absFilePath( args ) ) ; 546 QFile file( absFilePath( args ) ) ;
545 if ( file.remove() ) { 547 if ( file.remove() ) {
546 send( "250 Requested file action okay, completed" ); 548 send( "250 Requested file action okay, completed" );
547 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 549 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
548 e << file.name(); 550 e << file.name();
549 } else { 551 } else {
550 send( "550 Requested action not taken" ); 552 send( "550 Requested action not taken" );
551 } 553 }
552 } 554 }
553 } 555 }
554 556
555 // remove directory (RMD) 557 // remove directory (RMD)
556 else if ( cmd == "RMD" ) { 558 else if ( cmd == "RMD" ) {
557 if ( args.isEmpty() ) 559 if ( args.isEmpty() )
558 send( "500 Syntax error, command unrecognized" ); 560 send( "500 Syntax error, command unrecognized" );
559 else { 561 else {
560 QDir dir; 562 QDir dir;
561 if ( dir.rmdir( absFilePath( args ), TRUE ) ) 563 if ( dir.rmdir( absFilePath( args ), TRUE ) )
562 send( "250 Requested file action okay, completed" ); 564 send( "250 Requested file action okay, completed" );
563 else 565 else
564 send( "550 Requested action not taken" ); 566 send( "550 Requested action not taken" );
565 } 567 }
566 } 568 }
567 569
568 // make directory (MKD) 570 // make directory (MKD)
569 else if ( cmd == "MKD" ) { 571 else if ( cmd == "MKD" ) {
570 if ( args.isEmpty() ) { 572 if ( args.isEmpty() ) {
571 qDebug(" Error: no arg"); 573 qDebug(" Error: no arg");
572 send( "500 Syntax error, command unrecognized" ); 574 send( "500 Syntax error, command unrecognized" );
573 } 575 }
574 else { 576 else {
575 QDir dir; 577 QDir dir;
576 if ( dir.mkdir( absFilePath( args ), TRUE ) ) 578 if ( dir.mkdir( absFilePath( args ), TRUE ) )
577 send( "250 Requested file action okay, completed." ); 579 send( "250 Requested file action okay, completed." );
578 else 580 else
579 send( "550 Requested action not taken" ); 581 send( "550 Requested action not taken" );
580 } 582 }
581 } 583 }
582 584
583 // print working directory (PWD) 585 // print working directory (PWD)
584 else if ( cmd == "PWD" ) { 586 else if ( cmd == "PWD" ) {
585 send( "257 \"" + directory.path() +"\"" ); 587 send( "257 \"" + directory.path() +"\"" );
586 } 588 }
587 589
588 // list (LIST) 590 // list (LIST)
589 else if ( cmd == "LIST" ) { 591 else if ( cmd == "LIST" ) {
590 if ( sendList( absFilePath( args ) ) ) 592 if ( sendList( absFilePath( args ) ) )
591 send( "150 File status okay" ); 593 send( "150 File status okay" );
592 else 594 else
593 send( "500 Syntax error, command unrecognized" ); 595 send( "500 Syntax error, command unrecognized" );
594 } 596 }
595 597
596 // size (SIZE) 598 // size (SIZE)
597 else if ( cmd == "SIZE" ) { 599 else if ( cmd == "SIZE" ) {
598 QString filePath = absFilePath( args ); 600 QString filePath = absFilePath( args );
599 QFileInfo fi( filePath ); 601 QFileInfo fi( filePath );
600 bool gzipfile = backupRestoreGzip( filePath ); 602 bool gzipfile = backupRestoreGzip( filePath );
601 if ( !fi.exists() && !gzipfile ) 603 if ( !fi.exists() && !gzipfile )
602 send( "500 Syntax error, command unrecognized" ); 604 send( "500 Syntax error, command unrecognized" );
603 else { 605 else {
604 if ( !gzipfile ) 606 if ( !gzipfile )
605 send( "213 " + QString::number( fi.size() ) ); 607 send( "213 " + QString::number( fi.size() ) );
606 else { 608 else {
607 Process duproc( QString("du") ); 609 Process duproc( QString("du") );
608 duproc.addArgument("-s"); 610 duproc.addArgument("-s");
609 QString in, out; 611 QString in, out;
610 if ( !duproc.exec(in, out) ) { 612 if ( !duproc.exec(in, out) ) {
611 qDebug("du process failed; just sending back 1K"); 613 qDebug("du process failed; just sending back 1K");
612 send( "213 1024"); 614 send( "213 1024");
613 } 615 }
614 else { 616 else {
615 QString size = out.left( out.find("\t") ); 617 QString size = out.left( out.find("\t") );
616 int guess = size.toInt()/5; 618 int guess = size.toInt()/5;
617 if ( filePath.contains("doc") ) 619 if ( filePath.contains("doc") )
618 guess *= 1000; 620 guess *= 1000;
619 qDebug("sending back gzip guess of %d", guess); 621 qDebug("sending back gzip guess of %d", guess);
620 send( "213 " + QString::number(guess) ); 622 send( "213 " + QString::number(guess) );
621 } 623 }
622 } 624 }
623 } 625 }
624 } 626 }
625 // name list (NLST) 627 // name list (NLST)
626 else if ( cmd == "NLST" ) { 628 else if ( cmd == "NLST" ) {
627 send( "502 Command not implemented" ); 629 send( "502 Command not implemented" );
628 } 630 }
629 631
630 // site parameters (SITE) 632 // site parameters (SITE)
631 else if ( cmd == "SITE" ) { 633 else if ( cmd == "SITE" ) {
632 send( "502 Command not implemented" ); 634 send( "502 Command not implemented" );
633 } 635 }
634 636
635 // system (SYST) 637 // system (SYST)
636 else if ( cmd == "SYST" ) { 638 else if ( cmd == "SYST" ) {
637 send( "215 UNIX Type: L8" ); 639 send( "215 UNIX Type: L8" );
638 } 640 }
639 641
640 // status (STAT) 642 // status (STAT)
641 else if ( cmd == "STAT" ) { 643 else if ( cmd == "STAT" ) {
642 send( "502 Command not implemented" ); 644 send( "502 Command not implemented" );
643 } 645 }
644 646
645 // help (HELP ) 647 // help (HELP )
646 else if ( cmd == "HELP" ) { 648 else if ( cmd == "HELP" ) {
647 send( "502 Command not implemented" ); 649 send( "502 Command not implemented" );
648 } 650 }
649 651
650 // noop (NOOP) 652 // noop (NOOP)
651 else if ( cmd == "NOOP" ) { 653 else if ( cmd == "NOOP" ) {
652 send( "200 Command okay" ); 654 send( "200 Command okay" );
653 } 655 }
654 656
655 // not implemented 657 // not implemented
656 else 658 else
657 send( "502 Command not implemented" ); 659 send( "502 Command not implemented" );
658 660
659 lastCommand = cmd; 661 lastCommand = cmd;
660} 662}
661 663
662bool ServerPI::backupRestoreGzip( const QString &file ) 664bool ServerPI::backupRestoreGzip( const QString &file )
663{ 665{
664 return (file.find( "backup" ) != -1 && 666 return (file.find( "backup" ) != -1 &&
665 file.findRev( ".tgz" ) == (int)file.length()-4 ); 667 file.findRev( ".tgz" ) == (int)file.length()-4 );
666} 668}
667 669
668bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) 670bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets )
669{ 671{
670 if ( file.find( "backup" ) != -1 && 672 if ( file.find( "backup" ) != -1 &&
671 file.findRev( ".tgz" ) == (int)file.length()-4 ) { 673 file.findRev( ".tgz" ) == (int)file.length()-4 ) {
672 QFileInfo info( file ); 674 QFileInfo info( file );
673 targets = info.dirPath( TRUE ); 675 targets = info.dirPath( TRUE );
674 qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), 676 qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(),
675 targets.join(" ").latin1() ); 677 targets.join(" ").latin1() );
676 return true; 678 return true;
677 } 679 }
678 return false; 680 return false;
679} 681}
680 682
681void ServerPI::sendFile( const QString& file ) 683void ServerPI::sendFile( const QString& file )
682{ 684{
683 if ( passiv ) { 685 if ( passiv ) {
684 wait[SendFile] = TRUE; 686 wait[SendFile] = TRUE;
685 waitfile = file; 687 waitfile = file;
686 if ( waitsocket ) 688 if ( waitsocket )
687 newConnection( waitsocket ); 689 newConnection( waitsocket );
688 } 690 }
689 else { 691 else {
690 QStringList targets; 692 QStringList targets;
691 if ( backupRestoreGzip( file, targets ) ) 693 if ( backupRestoreGzip( file, targets ) )
692 dtp->sendGzipFile( file, targets, peeraddress, peerport ); 694 dtp->sendGzipFile( file, targets, peeraddress, peerport );
693 else dtp->sendFile( file, peeraddress, peerport ); 695 else dtp->sendFile( file, peeraddress, peerport );
694 } 696 }
695} 697}
696 698
697void ServerPI::retrieveFile( const QString& file ) 699void ServerPI::retrieveFile( const QString& file )
698{ 700{
699 if ( passiv ) { 701 if ( passiv ) {
700 wait[RetrieveFile] = TRUE; 702 wait[RetrieveFile] = TRUE;
701 waitfile = file; 703 waitfile = file;
702 if ( waitsocket ) 704 if ( waitsocket )
703 newConnection( waitsocket ); 705 newConnection( waitsocket );
704 } 706 }
705 else { 707 else {
706 QStringList targets; 708 QStringList targets;
707 if ( backupRestoreGzip( file, targets ) ) 709 if ( backupRestoreGzip( file, targets ) )
708 dtp->retrieveGzipFile( file, peeraddress, peerport ); 710 dtp->retrieveGzipFile( file, peeraddress, peerport );
709 else 711 else
710 dtp->retrieveFile( file, peeraddress, peerport ); 712 dtp->retrieveFile( file, peeraddress, peerport );
711 } 713 }
712} 714}
713 715
714bool ServerPI::parsePort( const QString& pp ) 716bool ServerPI::parsePort( const QString& pp )
715{ 717{
716 QStringList p = QStringList::split( ",", pp ); 718 QStringList p = QStringList::split( ",", pp );
717 if ( p.count() != 6 ) return FALSE; 719 if ( p.count() != 6 ) return FALSE;
718 720
719 // h1,h2,h3,h4,p1,p2 721 // h1,h2,h3,h4,p1,p2
720 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + 722 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) +
721 ( p[2].toInt() << 8 ) + p[3].toInt() ); 723 ( p[2].toInt() << 8 ) + p[3].toInt() );
722 peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); 724 peerport = ( p[4].toInt() << 8 ) + p[5].toInt();
723 return TRUE; 725 return TRUE;
724} 726}
725 727
726void ServerPI::dtpCompleted() 728void ServerPI::dtpCompleted()
727{ 729{
728 send( "226 Closing data connection, file transfer successful" ); 730 send( "226 Closing data connection, file transfer successful" );
729 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { 731 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) {
730 QString fn = dtp->fileName(); 732 QString fn = dtp->fileName();
731 if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) { 733 if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) {
732 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 734 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
733 e << fn; 735 e << fn;
734 } 736 }
735 } 737 }
736 waitsocket = 0; 738 waitsocket = 0;
737 dtp->close(); 739 dtp->close();
738} 740}
739 741
740void ServerPI::dtpFailed() 742void ServerPI::dtpFailed()
741{ 743{
742 dtp->close(); 744 dtp->close();
743 waitsocket = 0; 745 waitsocket = 0;
744 send( "451 Requested action aborted: local error in processing" ); 746 send( "451 Requested action aborted: local error in processing" );
745} 747}
746 748
747void ServerPI::dtpError( int ) 749void ServerPI::dtpError( int )
748{ 750{
749 dtp->close(); 751 dtp->close();
750 waitsocket = 0; 752 waitsocket = 0;
751 send( "451 Requested action aborted: local error in processing" ); 753 send( "451 Requested action aborted: local error in processing" );
752} 754}
753 755
754bool ServerPI::sendList( const QString& arg ) 756bool ServerPI::sendList( const QString& arg )
755{ 757{
756 QByteArray listing; 758 QByteArray listing;
757 QBuffer buffer( listing ); 759 QBuffer buffer( listing );
758 760
759 if ( !buffer.open( IO_WriteOnly ) ) 761 if ( !buffer.open( IO_WriteOnly ) )
760 return FALSE; 762 return FALSE;
761 763
762 QTextStream ts( &buffer ); 764 QTextStream ts( &buffer );
763 QString fn = arg; 765 QString fn = arg;
764 766
765 if ( fn.isEmpty() ) 767 if ( fn.isEmpty() )
766 fn = directory.path(); 768 fn = directory.path();
767 769
768 QFileInfo fi( fn ); 770 QFileInfo fi( fn );
769 if ( !fi.exists() ) return FALSE; 771 if ( !fi.exists() ) return FALSE;
770 772
771 // return file listing 773 // return file listing
772 if ( fi.isFile() ) { 774 if ( fi.isFile() ) {
773 ts << fileListing( &fi ) << endl; 775 ts << fileListing( &fi ) << endl;
774 } 776 }
775 777
776 // return directory listing 778 // return directory listing
777 else if ( fi.isDir() ) { 779 else if ( fi.isDir() ) {
778 QDir dir( fn ); 780 QDir dir( fn );
779 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); 781 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden );
780 782
781 QFileInfoListIterator it( *list ); 783 QFileInfoListIterator it( *list );
782 QFileInfo *info; 784 QFileInfo *info;
783 785
784 unsigned long total = 0; 786 unsigned long total = 0;
785 while ( ( info = it.current() ) ) { 787 while ( ( info = it.current() ) ) {
786 if ( info->fileName() != "." && info->fileName() != ".." ) 788 if ( info->fileName() != "." && info->fileName() != ".." )
787 total += info->size(); 789 total += info->size();
788 ++it; 790 ++it;
789 } 791 }
790 792
791 ts << "total " << QString::number( total / 1024 ) << endl; 793 ts << "total " << QString::number( total / 1024 ) << endl;
792 794
793 it.toFirst(); 795 it.toFirst();
794 while ( ( info = it.current() ) ) { 796 while ( ( info = it.current() ) ) {
795 if ( info->fileName() == "." || info->fileName() == ".." ) { 797 if ( info->fileName() == "." || info->fileName() == ".." ) {
796 ++it; 798 ++it;
797 continue; 799 continue;
798 } 800 }
799 ts << fileListing( info ) << endl; 801 ts << fileListing( info ) << endl;
800 ++it; 802 ++it;
801 } 803 }
802 } 804 }
803 805
804 if ( passiv ) { 806 if ( passiv ) {
805 waitarray = buffer.buffer(); 807 waitarray = buffer.buffer();
806 wait[SendByteArray] = TRUE; 808 wait[SendByteArray] = TRUE;
807 if ( waitsocket ) 809 if ( waitsocket )
808 newConnection( waitsocket ); 810 newConnection( waitsocket );
809 } 811 }
810 else 812 else
811 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); 813 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport );
812 return TRUE; 814 return TRUE;
813} 815}
814 816
815QString ServerPI::fileListing( QFileInfo *info ) 817QString ServerPI::fileListing( QFileInfo *info )
816{ 818{
817 if ( !info ) return QString::null; 819 if ( !info ) return QString::null;
818 QString s; 820 QString s;
819 821
820 // type char 822 // type char
821 if ( info->isDir() ) 823 if ( info->isDir() )
822 s += "d"; 824 s += "d";
823 else if ( info->isSymLink() ) 825 else if ( info->isSymLink() )
824 s += "l"; 826 s += "l";
825 else 827 else
826 s += "-"; 828 s += "-";
827 829
828 // permisson string 830 // permisson string
829 s += permissionString( info ) + " "; 831 s += permissionString( info ) + " ";
830 832
831 // number of hardlinks 833 // number of hardlinks
832 int subdirs = 1; 834 int subdirs = 1;
833 835
834 if ( info->isDir() ) 836 if ( info->isDir() )
835 subdirs = 2; 837 subdirs = 2;
836 // FIXME : this is to slow 838 // FIXME : this is to slow
837 //if ( info->isDir() ) 839 //if ( info->isDir() )
838 //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); 840 //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count();
839 841
840 s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; 842 s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " ";
841 843
842 // owner 844 // owner
843 s += info->owner().leftJustify( 8, ' ', TRUE ) + " "; 845 s += info->owner().leftJustify( 8, ' ', TRUE ) + " ";
844 846
845 // group 847 // group
846 s += info->group().leftJustify( 8, ' ', TRUE ) + " "; 848 s += info->group().leftJustify( 8, ' ', TRUE ) + " ";
847 849
848 // file size in bytes 850 // file size in bytes
849 s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; 851 s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " ";
850 852
851 // last modified date 853 // last modified date
852 QDate date = info->lastModified().date(); 854 QDate date = info->lastModified().date();
853 QTime time = info->lastModified().time(); 855 QTime time = info->lastModified().time();
854 s += date.monthName( date.month() ) + " " 856 s += date.monthName( date.month() ) + " "
855 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " 857 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " "
856 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" 858 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":"
857 + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; 859 + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " ";
858 860
859 // file name 861 // file name
860 s += info->fileName(); 862 s += info->fileName();
861 863
862 return s; 864 return s;
863} 865}
864 866
865QString ServerPI::permissionString( QFileInfo *info ) 867QString ServerPI::permissionString( QFileInfo *info )
866{ 868{
867 if ( !info ) return QString( "---------" ); 869 if ( !info ) return QString( "---------" );
868 QString s; 870 QString s;
869 871
870 // user 872 // user
871 if ( info->permission( QFileInfo::ReadUser ) ) s += "r"; 873 if ( info->permission( QFileInfo::ReadUser ) ) s += "r";
872 else s += "-"; 874 else s += "-";
873 if ( info->permission( QFileInfo::WriteUser ) ) s += "w"; 875 if ( info->permission( QFileInfo::WriteUser ) ) s += "w";
874 else s += "-"; 876 else s += "-";
875 if ( info->permission( QFileInfo::ExeUser ) ) s += "x"; 877 if ( info->permission( QFileInfo::ExeUser ) ) s += "x";
876 else s += "-"; 878 else s += "-";
877 879
878 // group 880 // group
879 if ( info->permission( QFileInfo::ReadGroup ) ) s += "r"; 881 if ( info->permission( QFileInfo::ReadGroup ) ) s += "r";
880 else s += "-"; 882 else s += "-";
881 if ( info->permission( QFileInfo::WriteGroup ) )s += "w"; 883 if ( info->permission( QFileInfo::WriteGroup ) )s += "w";
882 else s += "-"; 884 else s += "-";
883 if ( info->permission( QFileInfo::ExeGroup ) ) s += "x"; 885 if ( info->permission( QFileInfo::ExeGroup ) ) s += "x";
884 else s += "-"; 886 else s += "-";
885 887
886 // exec 888 // exec
887 if ( info->permission( QFileInfo::ReadOther ) ) s += "r"; 889 if ( info->permission( QFileInfo::ReadOther ) ) s += "r";
888 else s += "-"; 890 else s += "-";
889 if ( info->permission( QFileInfo::WriteOther ) ) s += "w"; 891 if ( info->permission( QFileInfo::WriteOther ) ) s += "w";
890 else s += "-"; 892 else s += "-";
891 if ( info->permission( QFileInfo::ExeOther ) ) s += "x"; 893 if ( info->permission( QFileInfo::ExeOther ) ) s += "x";
892 else s += "-"; 894 else s += "-";
893 895
894 return s; 896 return s;
895} 897}
896 898
897void ServerPI::newConnection( int socket ) 899void ServerPI::newConnection( int socket )
898{ 900{
899 //qDebug( "New incomming connection" ); 901 //qDebug( "New incomming connection" );
900 902
901 if ( !passiv ) return; 903 if ( !passiv ) return;
902 904
903 if ( wait[SendFile] ) { 905 if ( wait[SendFile] ) {
904 QStringList targets; 906 QStringList targets;
905 if ( backupRestoreGzip( waitfile, targets ) ) 907 if ( backupRestoreGzip( waitfile, targets ) )
906 dtp->sendGzipFile( waitfile, targets ); 908 dtp->sendGzipFile( waitfile, targets );
907 else 909 else
908 dtp->sendFile( waitfile ); 910 dtp->sendFile( waitfile );
909 dtp->setSocket( socket ); 911 dtp->setSocket( socket );
910 } 912 }
911 else if ( wait[RetrieveFile] ) { 913 else if ( wait[RetrieveFile] ) {
912 qDebug("check retrieve file"); 914 qDebug("check retrieve file");
913 if ( backupRestoreGzip( waitfile ) ) 915 if ( backupRestoreGzip( waitfile ) )
914 dtp->retrieveGzipFile( waitfile ); 916 dtp->retrieveGzipFile( waitfile );
915 else 917 else
916 dtp->retrieveFile( waitfile ); 918 dtp->retrieveFile( waitfile );
917 dtp->setSocket( socket ); 919 dtp->setSocket( socket );
918 } 920 }
919 else if ( wait[SendByteArray] ) { 921 else if ( wait[SendByteArray] ) {
920 dtp->sendByteArray( waitarray ); 922 dtp->sendByteArray( waitarray );
921 dtp->setSocket( socket ); 923 dtp->setSocket( socket );
922 } 924 }
923 else if ( wait[RetrieveByteArray] ) { 925 else if ( wait[RetrieveByteArray] ) {
924 qDebug("retrieve byte array"); 926 qDebug("retrieve byte array");
925 dtp->retrieveByteArray(); 927 dtp->retrieveByteArray();
926 dtp->setSocket( socket ); 928 dtp->setSocket( socket );
927 } 929 }
928 else 930 else
929 waitsocket = socket; 931 waitsocket = socket;
930 932
931 for( int i = 0; i < 4; i++ ) 933 for( int i = 0; i < 4; i++ )
932 wait[i] = FALSE; 934 wait[i] = FALSE;
933} 935}
934 936
935QString ServerPI::absFilePath( const QString& file ) 937QString ServerPI::absFilePath( const QString& file )
936{ 938{
937 if ( file.isEmpty() ) return file; 939 if ( file.isEmpty() ) return file;
938 940
939 QString filepath( file ); 941 QString filepath( file );
940 if ( file[0] != "/" ) 942 if ( file[0] != "/" )
941 filepath = directory.path() + "/" + file; 943 filepath = directory.path() + "/" + file;
942 944
943 return filepath; 945 return filepath;
944} 946}
945 947
946 948
947void ServerPI::timerEvent( QTimerEvent * ) 949void ServerPI::timerEvent( QTimerEvent * )
948{ 950{
949 connectionClosed(); 951 connectionClosed();
950} 952}
951 953
952 954
953ServerDTP::ServerDTP( QObject *parent = 0, const char* name = 0) 955ServerDTP::ServerDTP( QObject *parent = 0, const char* name = 0)
954 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), 956 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ),
955retrieveTargzProc( 0 ), gzipProc( 0 ) 957retrieveTargzProc( 0 ), gzipProc( 0 )
956{ 958{
957 959
958 connect( this, SIGNAL( connected() ), SLOT( connected() ) ); 960 connect( this, SIGNAL( connected() ), SLOT( connected() ) );
959 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 961 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
960 connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); 962 connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) );
961 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); 963 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) );
962 964
963 gzipProc = new QProcess( this, "gzipProc" ); 965 gzipProc = new QProcess( this, "gzipProc" );
964 gzipProc->setCommunication( QProcess::Stdin | QProcess::Stdout ); 966 gzipProc->setCommunication( QProcess::Stdin | QProcess::Stdout );
965 967
966 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); 968 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc");
967 createTargzProc->setCommunication( QProcess::Stdout ); 969 createTargzProc->setCommunication( QProcess::Stdout );
968 createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 970 createTargzProc->setWorkingDirectory( QDir::rootDirPath() );
969 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); 971 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) );
970 972
971 QStringList args = "tar"; 973 QStringList args = "tar";
972 args += "-xv"; 974 args += "-xv";
973 retrieveTargzProc = new QProcess( args, this, "retrieveTargzProc" ); 975 retrieveTargzProc = new QProcess( args, this, "retrieveTargzProc" );
974 retrieveTargzProc->setCommunication( QProcess::Stdin ); 976 retrieveTargzProc->setCommunication( QProcess::Stdin );
975 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 977 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() );
976 connect( retrieveTargzProc, SIGNAL( processExited() ), 978 connect( retrieveTargzProc, SIGNAL( processExited() ),
977 SIGNAL( completed() ) ); 979 SIGNAL( completed() ) );
978 connect( retrieveTargzProc, SIGNAL( processExited() ), 980 connect( retrieveTargzProc, SIGNAL( processExited() ),
979 SLOT( extractTarDone() ) ); 981 SLOT( extractTarDone() ) );
980} 982}
981 983
982ServerDTP::~ServerDTP() 984ServerDTP::~ServerDTP()
983{ 985{
984 buf.close(); 986 buf.close();
985 file.close(); 987 file.close();
986 createTargzProc->kill(); 988 createTargzProc->kill();
987} 989}
988 990
989void ServerDTP::extractTarDone() 991void ServerDTP::extractTarDone()
990{ 992{
991 qDebug("extract done"); 993 qDebug("extract done");
992#ifndef QT_NO_COP 994#ifndef QT_NO_COP
993 QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); 995 QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" );
994 e << file.name(); 996 e << file.name();
995#endif 997#endif
996} 998}
997 999
998void ServerDTP::connected() 1000void ServerDTP::connected()
999{ 1001{
1000 // send file mode 1002 // send file mode
1001 switch ( mode ) { 1003 switch ( mode ) {
1002 case SendFile : 1004 case SendFile :
1003 if ( !file.exists() || !file.open( IO_ReadOnly) ) { 1005 if ( !file.exists() || !file.open( IO_ReadOnly) ) {
1004 emit failed(); 1006 emit failed();
1005 mode = Idle; 1007 mode = Idle;
1006 return; 1008 return;
1007 } 1009 }
1008 1010
1009 //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); 1011 //qDebug( "Debug: Sending file '%s'", file.name().latin1() );
1010 1012
1011 bytes_written = 0; 1013 bytes_written = 0;
1012 if ( file.size() == 0 ) { 1014 if ( file.size() == 0 ) {
1013 //make sure it doesn't hang on empty files 1015 //make sure it doesn't hang on empty files
1014 file.close(); 1016 file.close();
1015 emit completed(); 1017 emit completed();
1016 mode = Idle; 1018 mode = Idle;
1017 } else { 1019 } else {
1018 1020
1019 if( !file.atEnd() ) { 1021 if( !file.atEnd() ) {
1020 QCString s; 1022 QCString s;
1021 s.resize( block_size ); 1023 s.resize( block_size );
1022 int bytes = file.readBlock( s.data(), block_size ); 1024 int bytes = file.readBlock( s.data(), block_size );
1023 writeBlock( s.data(), bytes ); 1025 writeBlock( s.data(), bytes );
1024 } 1026 }
1025 } 1027 }
1026 break; 1028 break;
1027 case SendGzipFile: 1029 case SendGzipFile:
1028 if ( createTargzProc->isRunning() ) { 1030 if ( createTargzProc->isRunning() ) {
1029 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY 1031 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY
1030 qWarning("Previous tar --gzip process is still running; killing it..."); 1032 qWarning("Previous tar --gzip process is still running; killing it...");
1031 createTargzProc->kill(); 1033 createTargzProc->kill();
1032 } 1034 }
1033 1035
1034 bytes_written = 0; 1036 bytes_written = 0;
1035 qDebug("==>start send tar process"); 1037 qDebug("==>start send tar process");
1036 if ( !createTargzProc->start() ) 1038 if ( !createTargzProc->start() )
1037 qWarning("Error starting %s or %s", 1039 qWarning("Error starting %s or %s",
1038 createTargzProc->arguments().join(" ").latin1(), 1040 createTargzProc->arguments().join(" ").latin1(),
1039 gzipProc->arguments().join(" ").latin1() ); 1041 gzipProc->arguments().join(" ").latin1() );
1040 break; 1042 break;
1041 case SendBuffer: 1043 case SendBuffer:
1042 if ( !buf.open( IO_ReadOnly) ) { 1044 if ( !buf.open( IO_ReadOnly) ) {
1043 emit failed(); 1045 emit failed();
1044 mode = Idle; 1046 mode = Idle;
1045 return; 1047 return;
1046 } 1048 }
1047 1049
1048 // qDebug( "Debug: Sending byte array" ); 1050 // qDebug( "Debug: Sending byte array" );
1049 bytes_written = 0; 1051 bytes_written = 0;
1050 while( !buf.atEnd() ) 1052 while( !buf.atEnd() )
1051 putch( buf.getch() ); 1053 putch( buf.getch() );
1052 buf.close(); 1054 buf.close();
1053 break; 1055 break;
1054 case RetrieveFile: 1056 case RetrieveFile:
1055 // retrieve file mode 1057 // retrieve file mode
1056 if ( file.exists() && !file.remove() ) { 1058 if ( file.exists() && !file.remove() ) {
1057 emit failed(); 1059 emit failed();
1058 mode = Idle; 1060 mode = Idle;
1059 return; 1061 return;
1060 } 1062 }
1061 1063
1062 if ( !file.open( IO_WriteOnly) ) { 1064 if ( !file.open( IO_WriteOnly) ) {
1063 emit failed(); 1065 emit failed();
1064 mode = Idle; 1066 mode = Idle;
1065 return; 1067 return;
1066 } 1068 }
1067 // qDebug( "Debug: Retrieving file %s", file.name().latin1() ); 1069 // qDebug( "Debug: Retrieving file %s", file.name().latin1() );
1068 break; 1070 break;
1069 case RetrieveGzipFile: 1071 case RetrieveGzipFile:
1070 qDebug("=-> starting tar process to receive .tgz file"); 1072 qDebug("=-> starting tar process to receive .tgz file");
1071 break; 1073 break;
1072 case RetrieveBuffer: 1074 case RetrieveBuffer:
1073 // retrieve buffer mode 1075 // retrieve buffer mode
1074 if ( !buf.open( IO_WriteOnly) ) { 1076 if ( !buf.open( IO_WriteOnly) ) {
1075 emit failed(); 1077 emit failed();
1076 mode = Idle; 1078 mode = Idle;
1077 return; 1079 return;
1078 } 1080 }
1079 // qDebug( "Debug: Retrieving byte array" ); 1081 // qDebug( "Debug: Retrieving byte array" );
1080 break; 1082 break;
1081 case Idle: 1083 case Idle:
1082 qDebug("connection established but mode set to Idle; BUG!"); 1084 qDebug("connection established but mode set to Idle; BUG!");
1083 break; 1085 break;
1084 } 1086 }
1085} 1087}
1086 1088
1087void ServerDTP::connectionClosed() 1089void ServerDTP::connectionClosed()
1088{ 1090{
1089 //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written ); 1091 //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written );
1090 1092
1091 // send file mode 1093 // send file mode
1092 if ( SendFile == mode ) { 1094 if ( SendFile == mode ) {
1093 if ( bytes_written == file.size() ) 1095 if ( bytes_written == file.size() )
1094 emit completed(); 1096 emit completed();
1095 else 1097 else
1096 emit failed(); 1098 emit failed();
1097 } 1099 }
1098 1100
1099 // send buffer mode 1101 // send buffer mode
1100 else if ( SendBuffer == mode ) { 1102 else if ( SendBuffer == mode ) {
1101 if ( bytes_written == buf.size() ) 1103 if ( bytes_written == buf.size() )
1102 emit completed(); 1104 emit completed();
1103 else 1105 else
1104 emit failed(); 1106 emit failed();
1105 } 1107 }
1106 1108
1107 // retrieve file mode 1109 // retrieve file mode
1108 else if ( RetrieveFile == mode ) { 1110 else if ( RetrieveFile == mode ) {
1109 file.close(); 1111 file.close();
1110 emit completed(); 1112 emit completed();
1111 } 1113 }
1112 1114
1113 else if ( RetrieveGzipFile == mode ) { 1115 else if ( RetrieveGzipFile == mode ) {
1114 qDebug("Done writing ungzip file; closing input"); 1116 qDebug("Done writing ungzip file; closing input");
1115 gzipProc->flushStdin(); 1117 gzipProc->flushStdin();
1116 gzipProc->closeStdin(); 1118 gzipProc->closeStdin();
1117 } 1119 }
1118 1120
1119 // retrieve buffer mode 1121 // retrieve buffer mode
1120 else if ( RetrieveBuffer == mode ) { 1122 else if ( RetrieveBuffer == mode ) {
1121 buf.close(); 1123 buf.close();
1122 emit completed(); 1124 emit completed();
1123 } 1125 }
1124 1126
1125 mode = Idle; 1127 mode = Idle;
1126} 1128}
1127 1129
1128void ServerDTP::bytesWritten( int bytes ) 1130void ServerDTP::bytesWritten( int bytes )
1129{ 1131{
1130 bytes_written += bytes; 1132 bytes_written += bytes;
1131 1133
1132 // send file mode 1134 // send file mode
1133 if ( SendFile == mode ) { 1135 if ( SendFile == mode ) {
1134 1136
1135 if ( bytes_written == file.size() ) { 1137 if ( bytes_written == file.size() ) {
1136 // qDebug( "Debug: Sending complete: %d bytes", file.size() ); 1138 // qDebug( "Debug: Sending complete: %d bytes", file.size() );
1137 file.close(); 1139 file.close();
1138 emit completed(); 1140 emit completed();
1139 mode = Idle; 1141 mode = Idle;
1140 } 1142 }
1141 else if( !file.atEnd() ) { 1143 else if( !file.atEnd() ) {
1142 QCString s; 1144 QCString s;
1143 s.resize( block_size ); 1145 s.resize( block_size );
1144 int bytes = file.readBlock( s.data(), block_size ); 1146 int bytes = file.readBlock( s.data(), block_size );
1145 writeBlock( s.data(), bytes ); 1147 writeBlock( s.data(), bytes );
1146 } 1148 }
1147 } 1149 }
1148 1150
1149 // send buffer mode 1151 // send buffer mode
1150 if ( SendBuffer == mode ) { 1152 if ( SendBuffer == mode ) {
1151 1153
1152 if ( bytes_written == buf.size() ) { 1154 if ( bytes_written == buf.size() ) {
1153 // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); 1155 // qDebug( "Debug: Sending complete: %d bytes", buf.size() );
1154 emit completed(); 1156 emit completed();
1155 mode = Idle; 1157 mode = Idle;
1156 } 1158 }
1157 } 1159 }
1158} 1160}
1159 1161
1160void ServerDTP::readyRead() 1162void ServerDTP::readyRead()
1161{ 1163{
1162 // retrieve file mode 1164 // retrieve file mode
1163 if ( RetrieveFile == mode ) { 1165 if ( RetrieveFile == mode ) {
1164 QCString s; 1166 QCString s;
1165 s.resize( bytesAvailable() ); 1167 s.resize( bytesAvailable() );
1166 readBlock( s.data(), bytesAvailable() ); 1168 readBlock( s.data(), bytesAvailable() );
1167 file.writeBlock( s.data(), s.size() ); 1169 file.writeBlock( s.data(), s.size() );
1168 } 1170 }
1169 else if ( RetrieveGzipFile == mode ) { 1171 else if ( RetrieveGzipFile == mode ) {
1170 if ( !gzipProc->isRunning() ) 1172 if ( !gzipProc->isRunning() )
1171 gzipProc->start(); 1173 gzipProc->start();
1172 1174
1173 QByteArray s; 1175 QByteArray s;
1174 s.resize( bytesAvailable() ); 1176 s.resize( bytesAvailable() );
1175 readBlock( s.data(), bytesAvailable() ); 1177 readBlock( s.data(), bytesAvailable() );
1176 gzipProc->writeToStdin( s ); 1178 gzipProc->writeToStdin( s );
1177 qDebug("wrote %d bytes to ungzip ", s.size() ); 1179 qDebug("wrote %d bytes to ungzip ", s.size() );
1178 } 1180 }
1179 // retrieve buffer mode 1181 // retrieve buffer mode
1180 else if ( RetrieveBuffer == mode ) { 1182 else if ( RetrieveBuffer == mode ) {
1181 QCString s; 1183 QCString s;
1182 s.resize( bytesAvailable() ); 1184 s.resize( bytesAvailable() );
1183 readBlock( s.data(), bytesAvailable() ); 1185 readBlock( s.data(), bytesAvailable() );
1184 buf.writeBlock( s.data(), s.size() ); 1186 buf.writeBlock( s.data(), s.size() );
1185 } 1187 }
1186} 1188}
1187 1189
1188void ServerDTP::writeTargzBlock() 1190void ServerDTP::writeTargzBlock()
1189{ 1191{
1190 QByteArray block = gzipProc->readStdout(); 1192 QByteArray block = gzipProc->readStdout();
1191 writeBlock( block.data(), block.size() ); 1193 writeBlock( block.data(), block.size() );
1192 qDebug("writeTargzBlock %d", block.size()); 1194 qDebug("writeTargzBlock %d", block.size());
1193 if ( !createTargzProc->isRunning() ) { 1195 if ( !createTargzProc->isRunning() ) {
1194 qDebug("tar and gzip done"); 1196 qDebug("tar and gzip done");
1195 emit completed(); 1197 emit completed();
1196 mode = Idle; 1198 mode = Idle;
1197 disconnect( gzipProc, SIGNAL( readyReadStdout() ), 1199 disconnect( gzipProc, SIGNAL( readyReadStdout() ),
1198 this, SLOT( writeTargzBlock() ) ); 1200 this, SLOT( writeTargzBlock() ) );
1199 } 1201 }