summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/documentlist.cpp8
-rw-r--r--core/launcher/qprocess_unix.cpp646
-rw-r--r--core/launcher/screensaver.cpp386
-rw-r--r--core/launcher/server.cpp434
-rw-r--r--core/launcher/transferserver.cpp851
5 files changed, 1164 insertions, 1161 deletions
diff --git a/core/launcher/documentlist.cpp b/core/launcher/documentlist.cpp
index 19ceb0f..44ceb0c 100644
--- a/core/launcher/documentlist.cpp
+++ b/core/launcher/documentlist.cpp
@@ -384,13 +384,13 @@ void DocumentList::DiffAppLnks()
384 while ( (i=it1.current()) ){ 384 while ( (i=it1.current()) ){
385 if (strcmp(i->name().ascii(),j->name().ascii()) == 0) 385 if (strcmp(i->name().ascii(),j->name().ascii()) == 0)
386 found = true; 386 found = true;
387 ++it1; 387 ++it1;
388 } 388 }
389 if (!found) { 389 if (!found) {
390 qDebug("Item %s needs to be added",j->name().ascii() ); 390 odebug << "Item " << j->name().ascii() << " needs to be added" << oendl;
391 d->serverGui->applicationAdded( j->type(), *j ); 391 d->serverGui->applicationAdded( j->type(), *j );
392 } 392 }
393 ++it2; 393 ++it2;
394 } 394 }
395 395
396 it1 = appLnkSet->children(); 396 it1 = appLnkSet->children();
@@ -400,13 +400,13 @@ void DocumentList::DiffAppLnks()
400 while ( (j=it2.current()) ){ 400 while ( (j=it2.current()) ){
401 if (strcmp(i->name().ascii(),j->name().ascii()) == 0) 401 if (strcmp(i->name().ascii(),j->name().ascii()) == 0)
402 found = true; 402 found = true;
403 ++it2; 403 ++it2;
404 } 404 }
405 if (!found) { 405 if (!found) {
406 qDebug("Item %s needs to be removed",i->name().ascii() ); 406 odebug << "Item " << i->name().ascii() << " needs to be removed" << oendl;
407 d->serverGui->applicationRemoved( i->type(), *i ); 407 d->serverGui->applicationRemoved( i->type(), *i );
408 } 408 }
409 409
410 ++it1; 410 ++it1;
411 } 411 }
412 412
@@ -419,16 +419,16 @@ void DocumentList::storageChanged()
419 QTime t; 419 QTime t;
420 // ### can implement better 420 // ### can implement better
421 421
422 t.start(); 422 t.start();
423 DiffAppLnks(); 423 DiffAppLnks();
424// reloadAppLnks(); 424// reloadAppLnks();
425 qDebug("Reload App links took %i ms",t.elapsed() ); 425 odebug << "Reload App links took " << t.elapsed() << " ms" << oendl;
426 reloadDocLnks(); 426 reloadDocLnks();
427// odebug << "Reload links took " << t.elapsed() << " ms " << oendl; 427// odebug << "Reload links took " << t.elapsed() << " ms " << oendl;
428 qDebug("Reload All links took %i ms",t.elapsed() ); 428 odebug << "Reload All links took " << t.elapsed() << " ms" << oendl;
429// ### Optimization opportunity 429// ### Optimization opportunity
430 // Could be a bit more intelligent and somehow work out which 430 // Could be a bit more intelligent and somehow work out which
431 // mtab entry has changed and then only scan that and add and remove 431 // mtab entry has changed and then only scan that and add and remove
432 // links appropriately. 432 // links appropriately.
433// rescan(); 433// rescan();
434} 434}
diff --git a/core/launcher/qprocess_unix.cpp b/core/launcher/qprocess_unix.cpp
index 56e1b1d..97c0460 100644
--- a/core/launcher/qprocess_unix.cpp
+++ b/core/launcher/qprocess_unix.cpp
@@ -130,38 +130,38 @@ class QProc
130public: 130public:
131 QProc( pid_t p, QProcess *proc=0 ) : pid(p), process(proc) 131 QProc( pid_t p, QProcess *proc=0 ) : pid(p), process(proc)
132 { 132 {
133#if defined(QT_QPROCESS_DEBUG) 133#if defined(QT_QPROCESS_DEBUG)
134 odebug << "QProc: Constructor for pid " << pid << " and QProcess " << process << "" << oendl; 134 odebug << "QProc: Constructor for pid " << pid << " and QProcess " << process << "" << oendl;
135#endif 135#endif
136 socketStdin = 0; 136 socketStdin = 0;
137 socketStdout = 0; 137 socketStdout = 0;
138 socketStderr = 0; 138 socketStderr = 0;
139 } 139 }
140 ~QProc() 140 ~QProc()
141 { 141 {
142#if defined(QT_QPROCESS_DEBUG) 142#if defined(QT_QPROCESS_DEBUG)
143 odebug << "QProc: Destructor for pid " << pid << " and QProcess " << process << "" << oendl; 143 odebug << "QProc: Destructor for pid " << pid << " and QProcess " << process << "" << oendl;
144#endif 144#endif
145 if ( process != 0 ) { 145 if ( process != 0 ) {
146 if ( process->d->notifierStdin ) 146 if ( process->d->notifierStdin )
147 process->d->notifierStdin->setEnabled( FALSE ); 147 process->d->notifierStdin->setEnabled( FALSE );
148 if ( process->d->notifierStdout ) 148 if ( process->d->notifierStdout )
149 process->d->notifierStdout->setEnabled( FALSE ); 149 process->d->notifierStdout->setEnabled( FALSE );
150 if ( process->d->notifierStderr ) 150 if ( process->d->notifierStderr )
151 process->d->notifierStderr->setEnabled( FALSE ); 151 process->d->notifierStderr->setEnabled( FALSE );
152 process->d->proc = 0; 152 process->d->proc = 0;
153 } 153 }
154 if( socketStdin != 0 ) 154 if( socketStdin != 0 )
155 ::close( socketStdin ); 155 ::close( socketStdin );
156 // ### close these sockets even on parent exit or is it better only on 156 // ### close these sockets even on parent exit or is it better only on
157 // sigchld (but what do I have to do with them on exit then)? 157 // sigchld (but what do I have to do with them on exit then)?
158 if( socketStdout != 0 ) 158 if( socketStdout != 0 )
159 ::close( socketStdout ); 159 ::close( socketStdout );
160 if( socketStderr != 0 ) 160 if( socketStderr != 0 )
161 ::close( socketStderr ); 161 ::close( socketStderr );
162 } 162 }
163 163
164 pid_t pid; 164 pid_t pid;
165 int socketStdin; 165 int socketStdin;
166 int socketStdout; 166 int socketStdout;
167 int socketStderr; 167 int socketStderr;
@@ -205,23 +205,23 @@ QProcessManager::QProcessManager()
205 procList->setAutoDelete( TRUE ); 205 procList->setAutoDelete( TRUE );
206 206
207 // The SIGCHLD handler writes to a socket to tell the manager that 207 // The SIGCHLD handler writes to a socket to tell the manager that
208 // something happened. This is done to get the processing in sync with the 208 // something happened. This is done to get the processing in sync with the
209 // event reporting. 209 // event reporting.
210 if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, sigchldFd ) ) { 210 if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, sigchldFd ) ) {
211 sigchldFd[0] = 0; 211 sigchldFd[0] = 0;
212 sigchldFd[1] = 0; 212 sigchldFd[1] = 0;
213 } else { 213 } else {
214#if defined(QT_QPROCESS_DEBUG) 214#if defined(QT_QPROCESS_DEBUG)
215 odebug << "QProcessManager: install socket notifier (" << sigchldFd[1] << ")" << oendl; 215 odebug << "QProcessManager: install socket notifier (" << sigchldFd[1] << ")" << oendl;
216#endif 216#endif
217 QSocketNotifier *sn = new QSocketNotifier( sigchldFd[1], 217 QSocketNotifier *sn = new QSocketNotifier( sigchldFd[1],
218 QSocketNotifier::Read, this ); 218 QSocketNotifier::Read, this );
219 connect( sn, SIGNAL(activated(int)), 219 connect( sn, SIGNAL(activated(int)),
220 this, SLOT(sigchldHnd(int)) ); 220 this, SLOT(sigchldHnd(int)) );
221 sn->setEnabled( TRUE ); 221 sn->setEnabled( TRUE );
222 } 222 }
223 223
224 // install a SIGCHLD handler and ignore SIGPIPE 224 // install a SIGCHLD handler and ignore SIGPIPE
225 struct sigaction act; 225 struct sigaction act;
226 226
227#if defined(QT_QPROCESS_DEBUG) 227#if defined(QT_QPROCESS_DEBUG)
@@ -238,16 +238,16 @@ QProcessManager::QProcessManager()
238 owarn << "Error installing SIGCHLD handler" << oendl; 238 owarn << "Error installing SIGCHLD handler" << oendl;
239 239
240#if defined(QT_QPROCESS_DEBUG) 240#if defined(QT_QPROCESS_DEBUG)
241 odebug << "QProcessManager: install a SIGPIPE handler (SIG_IGN)" << oendl; 241 odebug << "QProcessManager: install a SIGPIPE handler (SIG_IGN)" << oendl;
242#endif 242#endif
243 /* 243 /*
244 Using qt_C_sigpipeHnd rather than SIG_IGN is a workaround 244 Using qt_C_sigpipeHnd rather than SIG_IGN is a workaround
245 for a strange problem where GNU tar (called by backuprestore) 245 for a strange problem where GNU tar (called by backuprestore)
246 would hang on filesystem-full. Strangely, the qt_C_sigpipeHnd 246 would hang on filesystem-full. Strangely, the qt_C_sigpipeHnd
247 is never even called, yet this avoids the hang. 247 is never even called, yet this avoids the hang.
248 */ 248 */
249 act.sa_handler = qt_C_sigpipeHnd; 249 act.sa_handler = qt_C_sigpipeHnd;
250 sigemptyset( &(act.sa_mask) ); 250 sigemptyset( &(act.sa_mask) );
251 sigaddset( &(act.sa_mask), SIGPIPE ); 251 sigaddset( &(act.sa_mask), SIGPIPE );
252 act.sa_flags = 0; 252 act.sa_flags = 0;
253 if ( sigaction( SIGPIPE, &act, &oldactPipe ) != 0 ) 253 if ( sigaction( SIGPIPE, &act, &oldactPipe ) != 0 )
@@ -256,15 +256,15 @@ QProcessManager::QProcessManager()
256 256
257QProcessManager::~QProcessManager() 257QProcessManager::~QProcessManager()
258{ 258{
259 delete procList; 259 delete procList;
260 260
261 if ( sigchldFd[0] != 0 ) 261 if ( sigchldFd[0] != 0 )
262 ::close( sigchldFd[0] ); 262 ::close( sigchldFd[0] );
263 if ( sigchldFd[1] != 0 ) 263 if ( sigchldFd[1] != 0 )
264 ::close( sigchldFd[1] ); 264 ::close( sigchldFd[1] );
265 265
266 // restore SIGCHLD handler 266 // restore SIGCHLD handler
267#if defined(QT_QPROCESS_DEBUG) 267#if defined(QT_QPROCESS_DEBUG)
268 odebug << "QProcessManager: restore old sigchild handler" << oendl; 268 odebug << "QProcessManager: restore old sigchild handler" << oendl;
269#endif 269#endif
270 if ( sigaction( SIGCHLD, &oldactChld, 0 ) != 0 ) 270 if ( sigaction( SIGCHLD, &oldactChld, 0 ) != 0 )
@@ -294,22 +294,22 @@ void QProcessManager::remove( QProc *p )
294 cleanup(); 294 cleanup();
295} 295}
296 296
297void QProcessManager::cleanup() 297void QProcessManager::cleanup()
298{ 298{
299 if ( procList->count() == 0 ) { 299 if ( procList->count() == 0 ) {
300 QTimer::singleShot( 0, this, SLOT(removeMe()) ); 300 QTimer::singleShot( 0, this, SLOT(removeMe()) );
301 } 301 }
302} 302}
303 303
304void QProcessManager::removeMe() 304void QProcessManager::removeMe()
305{ 305{
306 if ( procList->count() == 0 ) { 306 if ( procList->count() == 0 ) {
307 qprocess_cleanup_procmanager.remove( &QProcessPrivate::procManager ); 307 qprocess_cleanup_procmanager.remove( &QProcessPrivate::procManager );
308 QProcessPrivate::procManager = 0; 308 QProcessPrivate::procManager = 0;
309 delete this; 309 delete this;
310 } 310 }
311} 311}
312 312
313void QProcessManager::sigchldHnd( int fd ) 313void QProcessManager::sigchldHnd( int fd )
314{ 314{
315 char tmp; 315 char tmp;
@@ -319,59 +319,59 @@ void QProcessManager::sigchldHnd( int fd )
319#endif 319#endif
320 QProc *proc; 320 QProc *proc;
321 QProcess *process; 321 QProcess *process;
322 bool removeProc; 322 bool removeProc;
323 proc = procList->first(); 323 proc = procList->first();
324 while ( proc != 0 ) { 324 while ( proc != 0 ) {
325 removeProc = FALSE; 325 removeProc = FALSE;
326 process = proc->process; 326 process = proc->process;
327 QProcess *process_exit_notify=0; 327 QProcess *process_exit_notify=0;
328 if ( process != 0 ) { 328 if ( process != 0 ) {
329 if ( !process->isRunning() ) { 329 if ( !process->isRunning() ) {
330#if defined(QT_QPROCESS_DEBUG) 330#if defined(QT_QPROCESS_DEBUG)
331 odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): process exited (QProcess available)" << oendl; 331 odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): process exited (QProcess available)" << oendl;
332#endif 332#endif
333 // read pending data 333 // read pending data
334 int nbytes = 0; 334 int nbytes = 0;
335 if ( ::ioctl(proc->socketStdout, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) { 335 if ( ::ioctl(proc->socketStdout, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) {
336#if defined(QT_QPROCESS_DEBUG) 336#if defined(QT_QPROCESS_DEBUG)
337 odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): reading " << nbytes << " bytes of pending data on stdout" << oendl; 337 odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): reading " << nbytes << " bytes of pending data on stdout" << oendl;
338#endif 338#endif
339 process->socketRead( proc->socketStdout ); 339 process->socketRead( proc->socketStdout );
340 } 340 }
341 nbytes = 0; 341 nbytes = 0;
342 if ( ::ioctl(proc->socketStderr, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) { 342 if ( ::ioctl(proc->socketStderr, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) {
343#if defined(QT_QPROCESS_DEBUG) 343#if defined(QT_QPROCESS_DEBUG)
344 odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): reading " << nbytes << " bytes of pending data on stderr" << oendl; 344 odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): reading " << nbytes << " bytes of pending data on stderr" << oendl;
345#endif 345#endif
346 process->socketRead( proc->socketStderr ); 346 process->socketRead( proc->socketStderr );
347 } 347 }
348 348
349 if ( process->notifyOnExit ) 349 if ( process->notifyOnExit )
350 process_exit_notify = process; 350 process_exit_notify = process;
351 351
352 removeProc = TRUE; 352 removeProc = TRUE;
353 } 353 }
354 } else { 354 } else {
355 int status; 355 int status;
356 if ( ::waitpid( proc->pid, &status, WNOHANG ) == proc->pid ) { 356 if ( ::waitpid( proc->pid, &status, WNOHANG ) == proc->pid ) {
357#if defined(QT_QPROCESS_DEBUG) 357#if defined(QT_QPROCESS_DEBUG)
358 odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): process exited (QProcess not available)" << oendl; 358 odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): process exited (QProcess not available)" << oendl;
359#endif 359#endif
360 removeProc = TRUE; 360 removeProc = TRUE;
361 } 361 }
362 } 362 }
363 if ( removeProc ) { 363 if ( removeProc ) {
364 QProc *oldproc = proc; 364 QProc *oldproc = proc;
365 proc = procList->next(); 365 proc = procList->next();
366 remove( oldproc ); 366 remove( oldproc );
367 } else { 367 } else {
368 proc = procList->next(); 368 proc = procList->next();
369 } 369 }
370 if ( process_exit_notify ) 370 if ( process_exit_notify )
371 emit process_exit_notify->processExited(); 371 emit process_exit_notify->processExited();
372 } 372 }
373} 373}
374 374
375#include "qprocess_unix.moc" 375#include "qprocess_unix.moc"
376 376
377 377
@@ -403,21 +403,21 @@ QProcessPrivate::~QProcessPrivate()
403{ 403{
404#if defined(QT_QPROCESS_DEBUG) 404#if defined(QT_QPROCESS_DEBUG)
405 odebug << "QProcessPrivate: Destructor" << oendl; 405 odebug << "QProcessPrivate: Destructor" << oendl;
406#endif 406#endif
407 407
408 if ( proc != 0 ) { 408 if ( proc != 0 ) {
409 if ( proc->socketStdin != 0 ) { 409 if ( proc->socketStdin != 0 ) {
410 ::close( proc->socketStdin ); 410 ::close( proc->socketStdin );
411 proc->socketStdin = 0; 411 proc->socketStdin = 0;
412 } 412 }
413 proc->process = 0; 413 proc->process = 0;
414 } 414 }
415 415
416 while ( !stdinBuf.isEmpty() ) { 416 while ( !stdinBuf.isEmpty() ) {
417 delete stdinBuf.dequeue(); 417 delete stdinBuf.dequeue();
418 } 418 }
419 delete notifierStdin; 419 delete notifierStdin;
420 delete notifierStdout; 420 delete notifierStdout;
421 delete notifierStderr; 421 delete notifierStderr;
422} 422}
423 423
@@ -426,33 +426,33 @@ QProcessPrivate::~QProcessPrivate()
426 process. Otherwise one child may have an open socket on standard input, etc. 426 process. Otherwise one child may have an open socket on standard input, etc.
427 of another child. 427 of another child.
428*/ 428*/
429void QProcessPrivate::closeOpenSocketsForChild() 429void QProcessPrivate::closeOpenSocketsForChild()
430{ 430{
431 if ( procManager != 0 ) { 431 if ( procManager != 0 ) {
432 if ( procManager->sigchldFd[0] != 0 ) 432 if ( procManager->sigchldFd[0] != 0 )
433 ::close( procManager->sigchldFd[0] ); 433 ::close( procManager->sigchldFd[0] );
434 if ( procManager->sigchldFd[1] != 0 ) 434 if ( procManager->sigchldFd[1] != 0 )
435 ::close( procManager->sigchldFd[1] ); 435 ::close( procManager->sigchldFd[1] );
436 436
437 // close also the sockets from other QProcess instances 437 // close also the sockets from other QProcess instances
438 QProc *proc; 438 QProc *proc;
439 for ( proc=procManager->procList->first(); proc!=0; proc=procManager->procList->next() ) { 439 for ( proc=procManager->procList->first(); proc!=0; proc=procManager->procList->next() ) {
440 ::close( proc->socketStdin ); 440 ::close( proc->socketStdin );
441 ::close( proc->socketStdout ); 441 ::close( proc->socketStdout );
442 ::close( proc->socketStderr ); 442 ::close( proc->socketStderr );
443 } 443 }
444 } 444 }
445} 445}
446 446
447void QProcessPrivate::newProc( pid_t pid, QProcess *process ) 447void QProcessPrivate::newProc( pid_t pid, QProcess *process )
448{ 448{
449 proc = new QProc( pid, process ); 449 proc = new QProc( pid, process );
450 if ( procManager == 0 ) { 450 if ( procManager == 0 ) {
451 procManager = new QProcessManager; 451 procManager = new QProcessManager;
452 qprocess_cleanup_procmanager.add( &procManager ); 452 qprocess_cleanup_procmanager.add( &procManager );
453 } 453 }
454 // the QProcessManager takes care of deleting the QProc instances 454 // the QProcessManager takes care of deleting the QProc instances
455 procManager->append( proc ); 455 procManager->append( proc );
456} 456}
457 457
458/*********************************************************************** 458/***********************************************************************
@@ -460,15 +460,15 @@ void QProcessPrivate::newProc( pid_t pid, QProcess *process )
460 * sigchld handler callback 460 * sigchld handler callback
461 * 461 *
462 **********************************************************************/ 462 **********************************************************************/
463QT_SIGNAL_RETTYPE qt_C_sigchldHnd( QT_SIGNAL_ARGS ) 463QT_SIGNAL_RETTYPE qt_C_sigchldHnd( QT_SIGNAL_ARGS )
464{ 464{
465 if ( QProcessPrivate::procManager == 0 ) 465 if ( QProcessPrivate::procManager == 0 )
466 return; 466 return;
467 if ( QProcessPrivate::procManager->sigchldFd[0] == 0 ) 467 if ( QProcessPrivate::procManager->sigchldFd[0] == 0 )
468 return; 468 return;
469 469
470 char a = 1; 470 char a = 1;
471 ::write( QProcessPrivate::procManager->sigchldFd[0], &a, sizeof(a) ); 471 ::write( QProcessPrivate::procManager->sigchldFd[0], &a, sizeof(a) );
472} 472}
473QT_SIGNAL_RETTYPE qt_C_sigpipeHnd( QT_SIGNAL_ARGS ) 473QT_SIGNAL_RETTYPE qt_C_sigpipeHnd( QT_SIGNAL_ARGS )
474{ 474{
@@ -505,50 +505,50 @@ void QProcess::reset()
505 d->bufStderr.resize( 0 ); 505 d->bufStderr.resize( 0 );
506} 506}
507 507
508QByteArray* QProcess::bufStdout() 508QByteArray* QProcess::bufStdout()
509{ 509{
510 if ( d->proc && d->proc->socketStdout ) { 510 if ( d->proc && d->proc->socketStdout ) {
511 // ### can this cause a blocking behaviour (maybe do a ioctl() to see 511 // ### can this cause a blocking behaviour (maybe do a ioctl() to see
512 // if data is available)? 512 // if data is available)?
513 socketRead( d->proc->socketStdout ); 513 socketRead( d->proc->socketStdout );
514 } 514 }
515 return &d->bufStdout; 515 return &d->bufStdout;
516} 516}
517 517
518QByteArray* QProcess::bufStderr() 518QByteArray* QProcess::bufStderr()
519{ 519{
520 if ( d->proc && d->proc->socketStderr ) { 520 if ( d->proc && d->proc->socketStderr ) {
521 // ### can this cause a blocking behaviour (maybe do a ioctl() to see 521 // ### can this cause a blocking behaviour (maybe do a ioctl() to see
522 // if data is available)? 522 // if data is available)?
523 socketRead( d->proc->socketStderr ); 523 socketRead( d->proc->socketStderr );
524 } 524 }
525 return &d->bufStderr; 525 return &d->bufStderr;
526} 526}
527 527
528void QProcess::consumeBufStdout( int consume ) 528void QProcess::consumeBufStdout( int consume )
529{ 529{
530 uint n = d->bufStdout.size(); 530 uint n = d->bufStdout.size();
531 if ( consume==-1 || (uint)consume >= n ) { 531 if ( consume==-1 || (uint)consume >= n ) {
532 d->bufStdout.resize( 0 ); 532 d->bufStdout.resize( 0 );
533 } else { 533 } else {
534 QByteArray tmp( n - consume ); 534 QByteArray tmp( n - consume );
535 memcpy( tmp.data(), d->bufStdout.data()+consume, n-consume ); 535 memcpy( tmp.data(), d->bufStdout.data()+consume, n-consume );
536 d->bufStdout = tmp; 536 d->bufStdout = tmp;
537 } 537 }
538} 538}
539 539
540void QProcess::consumeBufStderr( int consume ) 540void QProcess::consumeBufStderr( int consume )
541{ 541{
542 uint n = d->bufStderr.size(); 542 uint n = d->bufStderr.size();
543 if ( consume==-1 || (uint)consume >= n ) { 543 if ( consume==-1 || (uint)consume >= n ) {
544 d->bufStderr.resize( 0 ); 544 d->bufStderr.resize( 0 );
545 } else { 545 } else {
546 QByteArray tmp( n - consume ); 546 QByteArray tmp( n - consume );
547 memcpy( tmp.data(), d->bufStderr.data()+consume, n-consume ); 547 memcpy( tmp.data(), d->bufStderr.data()+consume, n-consume );
548 d->bufStderr = tmp; 548 d->bufStderr = tmp;
549 } 549 }
550} 550}
551 551
552/*! 552/*!
553 Destroys the class. 553 Destroys the class.
554 554
@@ -605,217 +605,217 @@ bool QProcess::start( QStringList *env )
605 int sStdin[2]; 605 int sStdin[2];
606 int sStdout[2]; 606 int sStdout[2];
607 int sStderr[2]; 607 int sStderr[2];
608 608
609 // open sockets for piping 609 // open sockets for piping
610 if ( (comms & Stdin) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStdin ) == -1 ) { 610 if ( (comms & Stdin) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStdin ) == -1 ) {
611 return FALSE; 611 return FALSE;
612 } 612 }
613 if ( (comms & Stderr) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStderr ) == -1 ) { 613 if ( (comms & Stderr) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStderr ) == -1 ) {
614 return FALSE; 614 return FALSE;
615 } 615 }
616 if ( (comms & Stdout) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStdout ) == -1 ) { 616 if ( (comms & Stdout) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStdout ) == -1 ) {
617 return FALSE; 617 return FALSE;
618 } 618 }
619 619
620 // the following pipe is only used to determine if the process could be 620 // the following pipe is only used to determine if the process could be
621 // started 621 // started
622 int fd[2]; 622 int fd[2];
623 if ( pipe( fd ) < 0 ) { 623 if ( pipe( fd ) < 0 ) {
624 // non critical error, go on 624 // non critical error, go on
625 fd[0] = 0; 625 fd[0] = 0;
626 fd[1] = 0; 626 fd[1] = 0;
627 } 627 }
628 628
629 // construct the arguments for exec 629 // construct the arguments for exec
630 QCString *arglistQ = new QCString[ _arguments.count() + 1 ]; 630 QCString *arglistQ = new QCString[ _arguments.count() + 1 ];
631 const char** arglist = new const char*[ _arguments.count() + 1 ]; 631 const char** arglist = new const char*[ _arguments.count() + 1 ];
632 int i = 0; 632 int i = 0;
633 for ( QStringList::Iterator it = _arguments.begin(); it != _arguments.end(); ++it ) { 633 for ( QStringList::Iterator it = _arguments.begin(); it != _arguments.end(); ++it ) {
634 arglistQ[i] = (*it).local8Bit(); 634 arglistQ[i] = (*it).local8Bit();
635 arglist[i] = arglistQ[i]; 635 arglist[i] = arglistQ[i];
636#if defined(QT_QPROCESS_DEBUG) 636#if defined(QT_QPROCESS_DEBUG)
637 odebug << "QProcess::start(): arg " << i << " = " << arglist[i] << "" << oendl; 637 odebug << "QProcess::start(): arg " << i << " = " << arglist[i] << "" << oendl;
638#endif 638#endif
639 i++; 639 i++;
640 } 640 }
641 arglist[i] = 0; 641 arglist[i] = 0;
642 642
643 // Must make sure signal handlers are installed before exec'ing 643 // Must make sure signal handlers are installed before exec'ing
644 // in case the process exits quickly. 644 // in case the process exits quickly.
645 if ( d->procManager == 0 ) { 645 if ( d->procManager == 0 ) {
646 d->procManager = new QProcessManager; 646 d->procManager = new QProcessManager;
647 qprocess_cleanup_procmanager.add( &d->procManager ); 647 qprocess_cleanup_procmanager.add( &d->procManager );
648 } 648 }
649 649
650 // fork and exec 650 // fork and exec
651 QApplication::flushX(); 651 QApplication::flushX();
652 pid_t pid = fork(); 652 pid_t pid = fork();
653 if ( pid == 0 ) { 653 if ( pid == 0 ) {
654 // child 654 // child
655 d->closeOpenSocketsForChild(); 655 d->closeOpenSocketsForChild();
656 if ( comms & Stdin ) { 656 if ( comms & Stdin ) {
657 ::close( sStdin[1] ); 657 ::close( sStdin[1] );
658 ::dup2( sStdin[0], STDIN_FILENO ); 658 ::dup2( sStdin[0], STDIN_FILENO );
659 } 659 }
660 if ( comms & Stdout ) { 660 if ( comms & Stdout ) {
661 ::close( sStdout[0] ); 661 ::close( sStdout[0] );
662 ::dup2( sStdout[1], STDOUT_FILENO ); 662 ::dup2( sStdout[1], STDOUT_FILENO );
663 } 663 }
664 if ( comms & Stderr ) { 664 if ( comms & Stderr ) {
665 ::close( sStderr[0] ); 665 ::close( sStderr[0] );
666 ::dup2( sStderr[1], STDERR_FILENO ); 666 ::dup2( sStderr[1], STDERR_FILENO );
667 } 667 }
668 if ( comms & DupStderr ) { 668 if ( comms & DupStderr ) {
669 ::dup2( STDOUT_FILENO, STDERR_FILENO ); 669 ::dup2( STDOUT_FILENO, STDERR_FILENO );
670 } 670 }
671#ifndef QT_NO_DIR 671#ifndef QT_NO_DIR
672 ::chdir( workingDir.absPath().latin1() ); 672 ::chdir( workingDir.absPath().latin1() );
673#endif 673#endif
674 if ( fd[0] ) 674 if ( fd[0] )
675 ::close( fd[0] ); 675 ::close( fd[0] );
676 if ( fd[1] ) 676 if ( fd[1] )
677 ::fcntl( fd[1], F_SETFD, FD_CLOEXEC ); // close on exec shows sucess 677 ::fcntl( fd[1], F_SETFD, FD_CLOEXEC ); // close on exec shows sucess
678 678
679 if ( env == 0 ) { // inherit environment and start process 679 if ( env == 0 ) { // inherit environment and start process
680 ::execvp( arglist[0], (char*const*)arglist ); // ### cast not nice 680 ::execvp( arglist[0], (char*const*)arglist ); // ### cast not nice
681 } else { // start process with environment settins as specified in env 681 } else { // start process with environment settins as specified in env
682 // construct the environment for exec 682 // construct the environment for exec
683 int numEntries = env->count(); 683 int numEntries = env->count();
684 bool setLibraryPath = 684 bool setLibraryPath =
685 env->grep( QRegExp( "^LD_LIBRARY_PATH=" ) ).isEmpty() && 685 env->grep( QRegExp( "^LD_LIBRARY_PATH=" ) ).isEmpty() &&
686 getenv( "LD_LIBRARY_PATH" ) != 0; 686 getenv( "LD_LIBRARY_PATH" ) != 0;
687 if ( setLibraryPath ) 687 if ( setLibraryPath )
688 numEntries++; 688 numEntries++;
689 QCString *envlistQ = new QCString[ numEntries + 1 ]; 689 QCString *envlistQ = new QCString[ numEntries + 1 ];
690 const char** envlist = new const char*[ numEntries + 1 ]; 690 const char** envlist = new const char*[ numEntries + 1 ];
691 int i = 0; 691 int i = 0;
692 if ( setLibraryPath ) { 692 if ( setLibraryPath ) {
693 envlistQ[i] = QString( "LD_LIBRARY_PATH=%1" ).arg( getenv( "LD_LIBRARY_PATH" ) ).local8Bit(); 693 envlistQ[i] = QString( "LD_LIBRARY_PATH=%1" ).arg( getenv( "LD_LIBRARY_PATH" ) ).local8Bit();
694 envlist[i] = envlistQ[i]; 694 envlist[i] = envlistQ[i];
695 i++; 695 i++;
696 } 696 }
697 for ( QStringList::Iterator it = env->begin(); it != env->end(); ++it ) { 697 for ( QStringList::Iterator it = env->begin(); it != env->end(); ++it ) {
698 envlistQ[i] = (*it).local8Bit(); 698 envlistQ[i] = (*it).local8Bit();
699 envlist[i] = envlistQ[i]; 699 envlist[i] = envlistQ[i];
700 i++; 700 i++;
701 } 701 }
702 envlist[i] = 0; 702 envlist[i] = 0;
703 703
704 // look for the executable in the search path 704 // look for the executable in the search path
705 if ( _arguments.count()>0 && getenv("PATH")!=0 ) { 705 if ( _arguments.count()>0 && getenv("PATH")!=0 ) {
706 QString command = _arguments[0]; 706 QString command = _arguments[0];
707 if ( !command.contains( '/' ) ) { 707 if ( !command.contains( '/' ) ) {
708 QStringList pathList = QStringList::split( ':', getenv( "PATH" ) ); 708 QStringList pathList = QStringList::split( ':', getenv( "PATH" ) );
709 for (QStringList::Iterator it = pathList.begin(); it != pathList.end(); ++it ) { 709 for (QStringList::Iterator it = pathList.begin(); it != pathList.end(); ++it ) {
710 QString dir = *it; 710 QString dir = *it;
711#ifdef Q_OS_MACX 711#ifdef Q_OS_MACX
712 if(QFile::exists(dir + "/" + command + ".app")) //look in a bundle 712 if(QFile::exists(dir + "/" + command + ".app")) //look in a bundle
713 dir += "/" + command + ".app/Contents/MacOS"; 713 dir += "/" + command + ".app/Contents/MacOS";
714#endif 714#endif
715#ifndef QT_NO_DIR 715#ifndef QT_NO_DIR
716 QFileInfo fileInfo( dir, command ); 716 QFileInfo fileInfo( dir, command );
717#else 717#else
718 QFileInfo fileInfo( dir + "/" + command ); 718 QFileInfo fileInfo( dir + "/" + command );
719#endif 719#endif
720 if ( fileInfo.isExecutable() ) { 720 if ( fileInfo.isExecutable() ) {
721 arglistQ[0] = fileInfo.filePath().local8Bit(); 721 arglistQ[0] = fileInfo.filePath().local8Bit();
722 arglist[0] = arglistQ[0]; 722 arglist[0] = arglistQ[0];
723 break; 723 break;
724 } 724 }
725 } 725 }
726 } 726 }
727 } 727 }
728 ::execve( arglist[0], (char*const*)arglist, (char*const*)envlist ); // ### casts not nice 728 ::execve( arglist[0], (char*const*)arglist, (char*const*)envlist ); // ### casts not nice
729 } 729 }
730 if ( fd[1] ) { 730 if ( fd[1] ) {
731 char buf = 0; 731 char buf = 0;
732 ::write( fd[1], &buf, 1 ); 732 ::write( fd[1], &buf, 1 );
733 ::close( fd[1] ); 733 ::close( fd[1] );
734 } 734 }
735 ::exit( -1 ); 735 ::exit( -1 );
736 } else if ( pid == -1 ) { 736 } else if ( pid == -1 ) {
737 // error forking 737 // error forking
738 goto error; 738 goto error;
739 } 739 }
740 740
741 // test if exec was successful 741 // test if exec was successful
742 if ( fd[1] ) 742 if ( fd[1] )
743 ::close( fd[1] ); 743 ::close( fd[1] );
744 if ( fd[0] ) { 744 if ( fd[0] ) {
745 char buf; 745 char buf;
746 for ( ;; ) { 746 for ( ;; ) {
747 int n = ::read( fd[0], &buf, 1 ); 747 int n = ::read( fd[0], &buf, 1 );
748 if ( n==1 ) { 748 if ( n==1 ) {
749 // socket was not closed => error 749 // socket was not closed => error
750 d->proc = 0; 750 d->proc = 0;
751 goto error; 751 goto error;
752 } else if ( n==-1 ) { 752 } else if ( n==-1 ) {
753 if ( errno==EAGAIN || errno==EINTR ) 753 if ( errno==EAGAIN || errno==EINTR )
754 // try it again 754 // try it again
755 continue; 755 continue;
756 } 756 }
757 break; 757 break;
758 } 758 }
759 ::close( fd[0] ); 759 ::close( fd[0] );
760 } 760 }
761 761
762 d->newProc( pid, this ); 762 d->newProc( pid, this );
763 763
764 if ( comms & Stdin ) { 764 if ( comms & Stdin ) {
765 ::close( sStdin[0] ); 765 ::close( sStdin[0] );
766 d->proc->socketStdin = sStdin[1]; 766 d->proc->socketStdin = sStdin[1];
767 d->notifierStdin = new QSocketNotifier( sStdin[1], QSocketNotifier::Write ); 767 d->notifierStdin = new QSocketNotifier( sStdin[1], QSocketNotifier::Write );
768 connect( d->notifierStdin, SIGNAL(activated(int)), 768 connect( d->notifierStdin, SIGNAL(activated(int)),
769 this, SLOT(socketWrite(int)) ); 769 this, SLOT(socketWrite(int)) );
770 // setup notifiers for the sockets 770 // setup notifiers for the sockets
771 if ( !d->stdinBuf.isEmpty() ) { 771 if ( !d->stdinBuf.isEmpty() ) {
772 d->notifierStdin->setEnabled( TRUE ); 772 d->notifierStdin->setEnabled( TRUE );
773 } 773 }
774 } 774 }
775 if ( comms & Stdout ) { 775 if ( comms & Stdout ) {
776 ::close( sStdout[1] ); 776 ::close( sStdout[1] );
777 d->proc->socketStdout = sStdout[0]; 777 d->proc->socketStdout = sStdout[0];
778 d->notifierStdout = new QSocketNotifier( sStdout[0], QSocketNotifier::Read ); 778 d->notifierStdout = new QSocketNotifier( sStdout[0], QSocketNotifier::Read );
779 connect( d->notifierStdout, SIGNAL(activated(int)), 779 connect( d->notifierStdout, SIGNAL(activated(int)),
780 this, SLOT(socketRead(int)) ); 780 this, SLOT(socketRead(int)) );
781 if ( ioRedirection ) 781 if ( ioRedirection )
782 d->notifierStdout->setEnabled( TRUE ); 782 d->notifierStdout->setEnabled( TRUE );
783 } 783 }
784 if ( comms & Stderr ) { 784 if ( comms & Stderr ) {
785 ::close( sStderr[1] ); 785 ::close( sStderr[1] );
786 d->proc->socketStderr = sStderr[0]; 786 d->proc->socketStderr = sStderr[0];
787 d->notifierStderr = new QSocketNotifier( sStderr[0], QSocketNotifier::Read ); 787 d->notifierStderr = new QSocketNotifier( sStderr[0], QSocketNotifier::Read );
788 connect( d->notifierStderr, SIGNAL(activated(int)), 788 connect( d->notifierStderr, SIGNAL(activated(int)),
789 this, SLOT(socketRead(int)) ); 789 this, SLOT(socketRead(int)) );
790 if ( ioRedirection ) 790 if ( ioRedirection )
791 d->notifierStderr->setEnabled( TRUE ); 791 d->notifierStderr->setEnabled( TRUE );
792 } 792 }
793 793
794 // cleanup and return 794 // cleanup and return
795 delete[] arglistQ; 795 delete[] arglistQ;
796 delete[] arglist; 796 delete[] arglist;
797 return TRUE; 797 return TRUE;
798 798
799error: 799error:
800#if defined(QT_QPROCESS_DEBUG) 800#if defined(QT_QPROCESS_DEBUG)
801 odebug << "QProcess::start(): error starting process" << oendl; 801 odebug << "QProcess::start(): error starting process" << oendl;
802#endif 802#endif
803 if ( d->procManager ) 803 if ( d->procManager )
804 d->procManager->cleanup(); 804 d->procManager->cleanup();
805 if ( comms & Stdin ) { 805 if ( comms & Stdin ) {
806 ::close( sStdin[1] ); 806 ::close( sStdin[1] );
807 ::close( sStdin[0] ); 807 ::close( sStdin[0] );
808 } 808 }
809 if ( comms & Stdout ) { 809 if ( comms & Stdout ) {
810 ::close( sStdout[0] ); 810 ::close( sStdout[0] );
811 ::close( sStdout[1] ); 811 ::close( sStdout[1] );
812 } 812 }
813 if ( comms & Stderr ) { 813 if ( comms & Stderr ) {
814 ::close( sStderr[0] ); 814 ::close( sStderr[0] );
815 ::close( sStderr[1] ); 815 ::close( sStderr[1] );
816 } 816 }
817 ::close( fd[0] ); 817 ::close( fd[0] );
818 ::close( fd[1] ); 818 ::close( fd[1] );
819 delete[] arglistQ; 819 delete[] arglistQ;
820 delete[] arglist; 820 delete[] arglist;
821 return FALSE; 821 return FALSE;
@@ -832,13 +832,13 @@ error:
832 832
833 \sa kill() processExited() 833 \sa kill() processExited()
834*/ 834*/
835void QProcess::tryTerminate() const 835void QProcess::tryTerminate() const
836{ 836{
837 if ( d->proc != 0 ) 837 if ( d->proc != 0 )
838 ::kill( d->proc->pid, SIGTERM ); 838 ::kill( d->proc->pid, SIGTERM );
839} 839}
840 840
841/*! 841/*!
842 Terminates the process. This is not a safe way to end a process since the 842 Terminates the process. This is not a safe way to end a process since the
843 process will not be able to do cleanup. tryTerminate() is a safer way to do 843 process will not be able to do cleanup. tryTerminate() is a safer way to do
844 it, but processes might ignore a tryTerminate(). 844 it, but processes might ignore a tryTerminate().
@@ -862,13 +862,13 @@ void QProcess::tryTerminate() const
862 862
863 \sa tryTerminate() processExited() 863 \sa tryTerminate() processExited()
864*/ 864*/
865void QProcess::kill() const 865void QProcess::kill() const
866{ 866{
867 if ( d->proc != 0 ) 867 if ( d->proc != 0 )
868 ::kill( d->proc->pid, SIGKILL ); 868 ::kill( d->proc->pid, SIGKILL );
869} 869}
870 870
871/*! 871/*!
872 Returns TRUE if the process is running, otherwise FALSE. 872 Returns TRUE if the process is running, otherwise FALSE.
873 873
874 \sa normalExit() exitStatus() processExited() 874 \sa normalExit() exitStatus() processExited()
@@ -876,30 +876,30 @@ void QProcess::kill() const
876bool QProcess::isRunning() const 876bool QProcess::isRunning() const
877{ 877{
878 if ( d->exitValuesCalculated ) { 878 if ( d->exitValuesCalculated ) {
879#if defined(QT_QPROCESS_DEBUG) 879#if defined(QT_QPROCESS_DEBUG)
880 odebug << "QProcess::isRunning(): FALSE (already computed)" << oendl; 880 odebug << "QProcess::isRunning(): FALSE (already computed)" << oendl;
881#endif 881#endif
882 return FALSE; 882 return FALSE;
883 } 883 }
884 if ( d->proc == 0 ) 884 if ( d->proc == 0 )
885 return FALSE; 885 return FALSE;
886 int status; 886 int status;
887 if ( ::waitpid( d->proc->pid, &status, WNOHANG ) == d->proc->pid ) 887 if ( ::waitpid( d->proc->pid, &status, WNOHANG ) == d->proc->pid )
888 { 888 {
889 // compute the exit values 889 // compute the exit values
890 QProcess *that = (QProcess*)this; // mutable 890 QProcess *that = (QProcess*)this; // mutable
891 that->exitNormal = WIFEXITED( status ) != 0; 891 that->exitNormal = WIFEXITED( status ) != 0;
892 if ( exitNormal ) { 892 if ( exitNormal ) {
893 that->exitStat = (char)WEXITSTATUS( status ); 893 that->exitStat = (char)WEXITSTATUS( status );
894 } 894 }
895 d->exitValuesCalculated = TRUE; 895 d->exitValuesCalculated = TRUE;
896#if defined(QT_QPROCESS_DEBUG) 896#if defined(QT_QPROCESS_DEBUG)
897 odebug << "QProcess::isRunning() (PID: " << d->proc->pid << "): FALSE" << oendl; 897 odebug << "QProcess::isRunning() (PID: " << d->proc->pid << "): FALSE" << oendl;
898#endif 898#endif
899 return FALSE; 899 return FALSE;
900 } 900 }
901#if defined(QT_QPROCESS_DEBUG) 901#if defined(QT_QPROCESS_DEBUG)
902 odebug << "QProcess::isRunning() (PID: " << d->proc->pid << "): TRUE" << oendl; 902 odebug << "QProcess::isRunning() (PID: " << d->proc->pid << "): TRUE" << oendl;
903#endif 903#endif
904 return TRUE; 904 return TRUE;
905} 905}
@@ -920,13 +920,13 @@ void QProcess::writeToStdin( const QByteArray& buf )
920{ 920{
921#if defined(QT_QPROCESS_DEBUG) 921#if defined(QT_QPROCESS_DEBUG)
922// odebug << "QProcess::writeToStdin(): write to stdin (" << d->socketStdin << ")" << oendl; 922// odebug << "QProcess::writeToStdin(): write to stdin (" << d->socketStdin << ")" << oendl;
923#endif 923#endif
924 d->stdinBuf.enqueue( new QByteArray(buf) ); 924 d->stdinBuf.enqueue( new QByteArray(buf) );
925 if ( d->notifierStdin != 0 ) 925 if ( d->notifierStdin != 0 )
926 d->notifierStdin->setEnabled( TRUE ); 926 d->notifierStdin->setEnabled( TRUE );
927} 927}
928 928
929 929
930/*! 930/*!
931 Closes standard input of the process. 931 Closes standard input of the process.
932 932
@@ -935,147 +935,147 @@ void QProcess::writeToStdin( const QByteArray& buf )
935 935
936 \sa wroteToStdin() 936 \sa wroteToStdin()
937*/ 937*/
938void QProcess::closeStdin() 938void QProcess::closeStdin()
939{ 939{
940 if ( d->proc == 0 ) 940 if ( d->proc == 0 )
941 return; 941 return;
942 if ( d->proc->socketStdin !=0 ) { 942 if ( d->proc->socketStdin !=0 ) {
943 while ( !d->stdinBuf.isEmpty() ) { 943 while ( !d->stdinBuf.isEmpty() ) {
944 delete d->stdinBuf.dequeue(); 944 delete d->stdinBuf.dequeue();
945 } 945 }
946 delete d->notifierStdin; 946 delete d->notifierStdin;
947 d->notifierStdin = 0; 947 d->notifierStdin = 0;
948 if ( ::close( d->proc->socketStdin ) != 0 ) { 948 if ( ::close( d->proc->socketStdin ) != 0 ) {
949 owarn << "Could not close stdin of child process" << oendl; 949 owarn << "Could not close stdin of child process" << oendl;
950 } 950 }
951#if defined(QT_QPROCESS_DEBUG) 951#if defined(QT_QPROCESS_DEBUG)
952 odebug << "QProcess::closeStdin(): stdin (" << d->proc->socketStdin << ") closed" << oendl; 952 odebug << "QProcess::closeStdin(): stdin (" << d->proc->socketStdin << ") closed" << oendl;
953#endif 953#endif
954 d->proc->socketStdin = 0; 954 d->proc->socketStdin = 0;
955 } 955 }
956} 956}
957 957
958 958
959/* 959/*
960 This private slot is called when the process has outputted data to either 960 This private slot is called when the process has outputted data to either
961 standard output or standard error. 961 standard output or standard error.
962*/ 962*/
963void QProcess::socketRead( int fd ) 963void QProcess::socketRead( int fd )
964{ 964{
965 if ( d->socketReadCalled ) { 965 if ( d->socketReadCalled ) {
966 // the slots that are connected to the readyRead...() signals might 966 // the slots that are connected to the readyRead...() signals might
967 // trigger a recursive call of socketRead(). Avoid this since you get a 967 // trigger a recursive call of socketRead(). Avoid this since you get a
968 // blocking read otherwise. 968 // blocking read otherwise.
969 return; 969 return;
970 } 970 }
971#if defined(QT_QPROCESS_DEBUG) 971#if defined(QT_QPROCESS_DEBUG)
972 odebug << "QProcess::socketRead(): " << fd << "" << oendl; 972 odebug << "QProcess::socketRead(): " << fd << "" << oendl;
973#endif 973#endif
974 if ( fd == 0 ) 974 if ( fd == 0 )
975 return; 975 return;
976 const int bufsize = 4096; 976 const int bufsize = 4096;
977 QByteArray *buffer = 0; 977 QByteArray *buffer = 0;
978 uint oldSize; 978 uint oldSize;
979 int n; 979 int n;
980 if ( fd == d->proc->socketStdout ) { 980 if ( fd == d->proc->socketStdout ) {
981 buffer = &d->bufStdout; 981 buffer = &d->bufStdout;
982 } else if ( fd == d->proc->socketStderr ) { 982 } else if ( fd == d->proc->socketStderr ) {
983 buffer = &d->bufStderr; 983 buffer = &d->bufStderr;
984 } else { 984 } else {
985 // this case should never happen, but just to be safe 985 // this case should never happen, but just to be safe
986 return; 986 return;
987 } 987 }
988 988
989 // read data 989 // read data
990 oldSize = buffer->size(); 990 oldSize = buffer->size();
991 buffer->resize( oldSize + bufsize ); 991 buffer->resize( oldSize + bufsize );
992 n = ::read( fd, buffer->data()+oldSize, bufsize ); 992 n = ::read( fd, buffer->data()+oldSize, bufsize );
993 if ( n > 0 ) 993 if ( n > 0 )
994 buffer->resize( oldSize + n ); 994 buffer->resize( oldSize + n );
995 else 995 else
996 buffer->resize( oldSize ); 996 buffer->resize( oldSize );
997 // eof or error? 997 // eof or error?
998 if ( n == 0 || n == -1 ) { 998 if ( n == 0 || n == -1 ) {
999 if ( fd == d->proc->socketStdout ) { 999 if ( fd == d->proc->socketStdout ) {
1000#if defined(QT_QPROCESS_DEBUG) 1000#if defined(QT_QPROCESS_DEBUG)
1001 odebug << "QProcess::socketRead(): stdout (" << fd << ") closed" << oendl; 1001 odebug << "QProcess::socketRead(): stdout (" << fd << ") closed" << oendl;
1002#endif 1002#endif
1003 d->notifierStdout->setEnabled( FALSE ); 1003 d->notifierStdout->setEnabled( FALSE );
1004 delete d->notifierStdout; 1004 delete d->notifierStdout;
1005 d->notifierStdout = 0; 1005 d->notifierStdout = 0;
1006 ::close( d->proc->socketStdout ); 1006 ::close( d->proc->socketStdout );
1007 d->proc->socketStdout = 0; 1007 d->proc->socketStdout = 0;
1008 return; 1008 return;
1009 } else if ( fd == d->proc->socketStderr ) { 1009 } else if ( fd == d->proc->socketStderr ) {
1010#if defined(QT_QPROCESS_DEBUG) 1010#if defined(QT_QPROCESS_DEBUG)
1011 odebug << "QProcess::socketRead(): stderr (" << fd << ") closed" << oendl; 1011 odebug << "QProcess::socketRead(): stderr (" << fd << ") closed" << oendl;
1012#endif 1012#endif
1013 d->notifierStderr->setEnabled( FALSE ); 1013 d->notifierStderr->setEnabled( FALSE );
1014 delete d->notifierStderr; 1014 delete d->notifierStderr;
1015 d->notifierStderr = 0; 1015 d->notifierStderr = 0;
1016 ::close( d->proc->socketStderr ); 1016 ::close( d->proc->socketStderr );
1017 d->proc->socketStderr = 0; 1017 d->proc->socketStderr = 0;
1018 return; 1018 return;
1019 } 1019 }
1020 } 1020 }
1021 // read all data that is available 1021 // read all data that is available
1022 while ( n == bufsize ) { 1022 while ( n == bufsize ) {
1023 oldSize = buffer->size(); 1023 oldSize = buffer->size();
1024 buffer->resize( oldSize + bufsize ); 1024 buffer->resize( oldSize + bufsize );
1025 n = ::read( fd, buffer->data()+oldSize, bufsize ); 1025 n = ::read( fd, buffer->data()+oldSize, bufsize );
1026 if ( n > 0 ) 1026 if ( n > 0 )
1027 buffer->resize( oldSize + n ); 1027 buffer->resize( oldSize + n );
1028 else 1028 else
1029 buffer->resize( oldSize ); 1029 buffer->resize( oldSize );
1030 } 1030 }
1031 1031
1032 d->socketReadCalled = TRUE; 1032 d->socketReadCalled = TRUE;
1033 if ( fd == d->proc->socketStdout ) { 1033 if ( fd == d->proc->socketStdout ) {
1034#if defined(QT_QPROCESS_DEBUG) 1034#if defined(QT_QPROCESS_DEBUG)
1035 qDebug( "QProcess::socketRead(): %d bytes read from stdout (%d)", 1035 odebug << "QProcess::socketRead(): " << buffer->size()-oldSize << "bytes read from stdout ("
1036 buffer->size()-oldSize, fd ); 1036 << fd << ")" << oendl;
1037#endif 1037#endif
1038 emit readyReadStdout(); 1038 emit readyReadStdout();
1039 } else if ( fd == d->proc->socketStderr ) { 1039 } else if ( fd == d->proc->socketStderr ) {
1040#if defined(QT_QPROCESS_DEBUG) 1040#if defined(QT_QPROCESS_DEBUG)
1041 qDebug( "QProcess::socketRead(): %d bytes read from stderr (%d)", 1041 odebug << "QProcess::socketRead(): " << buffer->size()-oldSize << " bytes read from stderr ("
1042 buffer->size()-oldSize, fd ); 1042 << fd << ")" << oendl;
1043#endif 1043#endif
1044 emit readyReadStderr(); 1044 emit readyReadStderr();
1045 } 1045 }
1046 d->socketReadCalled = FALSE; 1046 d->socketReadCalled = FALSE;
1047} 1047}
1048 1048
1049 1049
1050/* 1050/*
1051 This private slot is called when the process tries to read data from standard 1051 This private slot is called when the process tries to read data from standard
1052 input. 1052 input.
1053*/ 1053*/
1054void QProcess::socketWrite( int fd ) 1054void QProcess::socketWrite( int fd )
1055{ 1055{
1056 if ( fd != d->proc->socketStdin || d->proc->socketStdin == 0 ) 1056 if ( fd != d->proc->socketStdin || d->proc->socketStdin == 0 )
1057 return; 1057 return;
1058 if ( d->stdinBuf.isEmpty() ) { 1058 if ( d->stdinBuf.isEmpty() ) {
1059 d->notifierStdin->setEnabled( FALSE ); 1059 d->notifierStdin->setEnabled( FALSE );
1060 return; 1060 return;
1061 } 1061 }
1062#if defined(QT_QPROCESS_DEBUG) 1062#if defined(QT_QPROCESS_DEBUG)
1063 odebug << "QProcess::socketWrite(): write to stdin (" << fd << ")" << oendl; 1063 odebug << "QProcess::socketWrite(): write to stdin (" << fd << ")" << oendl;
1064#endif 1064#endif
1065 ssize_t ret = ::write( fd, 1065 ssize_t ret = ::write( fd,
1066 d->stdinBuf.head()->data() + d->stdinBufRead, 1066 d->stdinBuf.head()->data() + d->stdinBufRead,
1067 d->stdinBuf.head()->size() - d->stdinBufRead ); 1067 d->stdinBuf.head()->size() - d->stdinBufRead );
1068 if ( ret > 0 ) 1068 if ( ret > 0 )
1069 d->stdinBufRead += ret; 1069 d->stdinBufRead += ret;
1070 if ( d->stdinBufRead == (ssize_t)d->stdinBuf.head()->size() ) { 1070 if ( d->stdinBufRead == (ssize_t)d->stdinBuf.head()->size() ) {
1071 d->stdinBufRead = 0; 1071 d->stdinBufRead = 0;
1072 delete d->stdinBuf.dequeue(); 1072 delete d->stdinBuf.dequeue();
1073 if ( wroteToStdinConnected && d->stdinBuf.isEmpty() ) 1073 if ( wroteToStdinConnected && d->stdinBuf.isEmpty() )
1074 emit wroteToStdin(); 1074 emit wroteToStdin();
1075 socketWrite( fd ); 1075 socketWrite( fd );
1076 } 1076 }
1077} 1077}
1078 1078
1079/*! 1079/*!
1080 \internal 1080 \internal
1081 Flushes standard input. This is useful if you want to use QProcess in a 1081 Flushes standard input. This is useful if you want to use QProcess in a
@@ -1102,21 +1102,21 @@ void QProcess::timeout()
1102 change the value of ioRedirection (and related behaviour) 1102 change the value of ioRedirection (and related behaviour)
1103*/ 1103*/
1104void QProcess::setIoRedirection( bool value ) 1104void QProcess::setIoRedirection( bool value )
1105{ 1105{
1106 ioRedirection = value; 1106 ioRedirection = value;
1107 if ( ioRedirection ) { 1107 if ( ioRedirection ) {
1108 if ( d->notifierStdout ) 1108 if ( d->notifierStdout )
1109 d->notifierStdout->setEnabled( TRUE ); 1109 d->notifierStdout->setEnabled( TRUE );
1110 if ( d->notifierStderr ) 1110 if ( d->notifierStderr )
1111 d->notifierStderr->setEnabled( TRUE ); 1111 d->notifierStderr->setEnabled( TRUE );
1112 } else { 1112 } else {
1113 if ( d->notifierStdout ) 1113 if ( d->notifierStdout )
1114 d->notifierStdout->setEnabled( FALSE ); 1114 d->notifierStdout->setEnabled( FALSE );
1115 if ( d->notifierStderr ) 1115 if ( d->notifierStderr )
1116 d->notifierStderr->setEnabled( FALSE ); 1116 d->notifierStderr->setEnabled( FALSE );
1117 } 1117 }
1118} 1118}
1119 1119
1120/* 1120/*
1121 This private function is used by connectNotify() and 1121 This private function is used by connectNotify() and
1122 disconnectNotify() to change the value of notifyOnExit (and related 1122 disconnectNotify() to change the value of notifyOnExit (and related
@@ -1149,25 +1149,25 @@ void QProcess::setWroteStdinConnected( bool value )
1149 Under Windows it is a pointer to the \c PROCESS_INFORMATION struct, or 0 if 1149 Under Windows it is a pointer to the \c PROCESS_INFORMATION struct, or 0 if
1150 no process is belonging to this object. 1150 no process is belonging to this object.
1151*/ 1151*/
1152QProcess::PID QProcess::processIdentifier() 1152QProcess::PID QProcess::processIdentifier()
1153{ 1153{
1154 if ( d->proc == 0 ) 1154 if ( d->proc == 0 )
1155 return -1; 1155 return -1;
1156 return d->proc->pid; 1156 return d->proc->pid;
1157} 1157}
1158 1158
1159int QProcess::priority() const 1159int QProcess::priority() const
1160{ 1160{
1161 if ( d->proc ) 1161 if ( d->proc )
1162 return getpriority(PRIO_PROCESS,d->proc->pid); 1162 return getpriority(PRIO_PROCESS,d->proc->pid);
1163 return 0; 1163 return 0;
1164} 1164}
1165 1165
1166void QProcess::setPriority(int p) 1166void QProcess::setPriority(int p)
1167{ 1167{
1168 if ( d->proc ) 1168 if ( d->proc )
1169 setpriority(PRIO_PROCESS,d->proc->pid,p); 1169 setpriority(PRIO_PROCESS,d->proc->pid,p);
1170} 1170}
1171 1171
1172 1172
1173#endif // QT_NO_PROCESS 1173#endif // QT_NO_PROCESS
diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp
index a7d23c4..f818d62 100644
--- a/core/launcher/screensaver.cpp
+++ b/core/launcher/screensaver.cpp
@@ -2,123 +2,124 @@
2#include "screensaver.h" 2#include "screensaver.h"
3 3
4#include <qpe/config.h> 4#include <qpe/config.h>
5#include <qpe/network.h> 5#include <qpe/network.h>
6 6
7#include <opie2/odevice.h> 7#include <opie2/odevice.h>
8#include <opie2/odebug.h>
8 9
9 10
10using namespace Opie::Core; 11using namespace Opie::Core;
11 12
12 13
13 14
14OpieScreenSaver::OpieScreenSaver ( ) 15OpieScreenSaver::OpieScreenSaver ( )
15 : QObject ( 0, "screensaver" ), QWSScreenSaver ( ) 16 : QObject ( 0, "screensaver" ), QWSScreenSaver ( )
16{ 17{
17 m_disable_suspend = 100; 18 m_disable_suspend = 100;
18 m_enable_dim = false; 19 m_enable_dim = false;
19 m_enable_lightoff = false; 20 m_enable_lightoff = false;
20 m_enable_suspend = false; 21 m_enable_suspend = false;
21 m_onlylcdoff = false; 22 m_onlylcdoff = false;
22 23
23 m_enable_dim_ac = false; 24 m_enable_dim_ac = false;
24 m_enable_lightoff_ac = false; 25 m_enable_lightoff_ac = false;
25 m_enable_suspend_ac = false; 26 m_enable_suspend_ac = false;
26 m_onlylcdoff_ac = false; 27 m_onlylcdoff_ac = false;
27 28
28 m_use_light_sensor = false; 29 m_use_light_sensor = false;
29 m_backlight_sensor = -1; 30 m_backlight_sensor = -1;
30 ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] )); 31 ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] ));
31 32
32 m_lcd_status = true; 33 m_lcd_status = true;
33 34
34 m_backlight_normal = -1; 35 m_backlight_normal = -1;
35 m_backlight_current = -1; 36 m_backlight_current = -1;
36 m_backlight_forcedoff = false; 37 m_backlight_forcedoff = false;
37 38
38 m_on_ac = false; 39 m_on_ac = false;
39 40
40 m_level = -1; 41 m_level = -1;
41 42
42 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) 43 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
43 ODevice::inst ( )-> setDisplayStatus ( true ); 44 ODevice::inst ( )-> setDisplayStatus ( true );
44 setBacklight ( -1 ); 45 setBacklight ( -1 );
45} 46}
46 47
47 48
48/** 49/**
49 * Stops the screen saver 50 * Stops the screen saver
50 */ 51 */
51void OpieScreenSaver::restore() 52void OpieScreenSaver::restore()
52{ 53{
53 m_level = -1; 54 m_level = -1;
54 55
55 if ( !m_lcd_status ) { // We must have turned it off 56 if ( !m_lcd_status ) { // We must have turned it off
56 ODevice::inst ( ) -> setDisplayStatus ( true ); 57 ODevice::inst ( ) -> setDisplayStatus ( true );
57 m_lcd_status = true; 58 m_lcd_status = true;
58 } 59 }
59 60
60 setBacklightInternal ( -1 ); 61 setBacklightInternal ( -1 );
61} 62}
62 63
63 64
64/** 65/**
65 * Starts the screen saver 66 * Starts the screen saver
66 * 67 *
67 * @param level what level of screen saving should happen (0=lowest non-off, 1=off, 68 * @param level what level of screen saving should happen (0=lowest non-off, 1=off,
68 * 2=suspend whole machine) 69 * 2=suspend whole machine)
69 * @returns true on success 70 * @returns true on success
70 */ 71 */
71bool OpieScreenSaver::save( int level ) 72bool OpieScreenSaver::save( int level )
72{ 73{
73 m_level = level; 74 m_level = level;
74 75
75 switch ( level ) { 76 switch ( level ) {
76 case 0: 77 case 0:
77 if (( m_on_ac && m_enable_dim_ac ) || 78 if (( m_on_ac && m_enable_dim_ac ) ||
78 ( !m_on_ac && m_enable_dim )) { 79 ( !m_on_ac && m_enable_dim )) {
79 if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor ) 80 if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor )
80 setBacklightInternal ( 1 ); // lowest non-off 81 setBacklightInternal ( 1 ); // lowest non-off
81 } 82 }
82 return true; 83 return true;
83 break; 84 break;
84 85
85 case 1: 86 case 1:
86 if (( m_on_ac && m_enable_lightoff_ac ) || 87 if (( m_on_ac && m_enable_lightoff_ac ) ||
87 ( !m_on_ac && m_enable_lightoff )) { 88 ( !m_on_ac && m_enable_lightoff )) {
88 if ( m_disable_suspend > 1 ) 89 if ( m_disable_suspend > 1 )
89 setBacklightInternal ( 0 ); // off 90 setBacklightInternal ( 0 ); // off
90 } 91 }
91 return true; 92 return true;
92 break; 93 break;
93 94
94 case 2: 95 case 2:
95 if (( m_on_ac && !m_enable_suspend_ac ) || 96 if (( m_on_ac && !m_enable_suspend_ac ) ||
96 ( !m_on_ac && !m_enable_suspend )) { 97 ( !m_on_ac && !m_enable_suspend )) {
97 return true; 98 return true;
98 } 99 }
99 100
100 if (( m_on_ac && m_onlylcdoff_ac ) || 101 if (( m_on_ac && m_onlylcdoff_ac ) ||
101 ( !m_on_ac && m_onlylcdoff )) { 102 ( !m_on_ac && m_onlylcdoff )) {
102 ODevice::inst ( ) -> setDisplayStatus ( false ); 103 ODevice::inst ( ) -> setDisplayStatus ( false );
103 m_lcd_status = false; 104 m_lcd_status = false;
104 return true; 105 return true;
105 } 106 }
106 107
107 // We're going to suspend the whole machine 108 // We're going to suspend the whole machine
108 109
109 if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { 110 if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) {
110 // TODO: why is this key F34 hard coded? -- schurig 111 // TODO: why is this key F34 hard coded? -- schurig
111 // Does this now only work an devices with a ODevice::filter? 112 // Does this now only work an devices with a ODevice::filter?
112 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 113 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
113 return true; 114 return true;
114 } 115 }
115 116
116 break; 117 break;
117 } 118 }
118 return false; 119 return false;
119} 120}
120 121
121 122
122/** 123/**
123 * Set intervals in seconds for automatic dimming, light off and suspend 124 * Set intervals in seconds for automatic dimming, light off and suspend
124 * 125 *
@@ -131,67 +132,67 @@ bool OpieScreenSaver::save( int level )
131 * read value from config file, 0 to disable 132 * read value from config file, 0 to disable
132 * @param suspend time in seconds to do an APM suspend, -1 to 133 * @param suspend time in seconds to do an APM suspend, -1 to
133 * read value from config file, 0 to disable 134 * read value from config file, 0 to disable
134 */ 135 */
135void OpieScreenSaver::setIntervals ( int dim, int lightoff, int suspend ) 136void OpieScreenSaver::setIntervals ( int dim, int lightoff, int suspend )
136{ 137{
137 Config config ( "apm" ); 138 Config config ( "apm" );
138 config. setGroup ( m_on_ac ? "AC" : "Battery" ); 139 config. setGroup ( m_on_ac ? "AC" : "Battery" );
139 140
140 int v[ 4 ]; 141 int v[ 4 ];
141 if ( dim < 0 ) 142 if ( dim < 0 )
142 dim = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); 143 dim = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 );
143 if ( lightoff < 0 ) 144 if ( lightoff < 0 )
144 lightoff = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); 145 lightoff = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 );
145 if ( suspend < 0 ) 146 if ( suspend < 0 )
146 suspend = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); 147 suspend = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 );
147 148
148 if ( m_on_ac ) { 149 if ( m_on_ac ) {
149 m_enable_dim_ac = ( dim > 0 ); 150 m_enable_dim_ac = ( dim > 0 );
150 m_enable_lightoff_ac = ( lightoff > 0 ); 151 m_enable_lightoff_ac = ( lightoff > 0 );
151 m_enable_suspend_ac = ( suspend > 0 ); 152 m_enable_suspend_ac = ( suspend > 0 );
152 m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); 153 m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false );
153 } 154 }
154 else { 155 else {
155 m_enable_dim = ( dim > 0 ); 156 m_enable_dim = ( dim > 0 );
156 m_enable_lightoff = ( lightoff > 0 ); 157 m_enable_lightoff = ( lightoff > 0 );
157 m_enable_suspend = ( suspend > 0 ); 158 m_enable_suspend = ( suspend > 0 );
158 m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); 159 m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false );
159 } 160 }
160 161
161 //odebug << "screen saver intervals: " << dim << " " << lightoff << " " << suspend << "" << oendl; 162 //odebug << "screen saver intervals: " << dim << " " << lightoff << " " << suspend << "" << oendl;
162 163
163 v [ 0 ] = QMAX( 1000 * dim, 100 ); 164 v [ 0 ] = QMAX( 1000 * dim, 100 );
164 v [ 1 ] = QMAX( 1000 * lightoff, 100 ); 165 v [ 1 ] = QMAX( 1000 * lightoff, 100 );
165 v [ 2 ] = QMAX( 1000 * suspend, 100 ); 166 v [ 2 ] = QMAX( 1000 * suspend, 100 );
166 v [ 3 ] = 0; 167 v [ 3 ] = 0;
167 168
168 if ( !dim && !lightoff && !suspend ) 169 if ( !dim && !lightoff && !suspend )
169 QWSServer::setScreenSaverInterval( 0 ); 170 QWSServer::setScreenSaverInterval( 0 );
170 else 171 else
171 QWSServer::setScreenSaverIntervals( v ); 172 QWSServer::setScreenSaverIntervals( v );
172} 173}
173 174
174 175
175/** 176/**
176 * Set suspend time. Will read the dim and lcd-off times from the config file. 177 * Set suspend time. Will read the dim and lcd-off times from the config file.
177 * 178 *
178 * @param suspend time in seconds to go into APM suspend, -1 to 179 * @param suspend time in seconds to go into APM suspend, -1 to
179 * read value from config file, 0 to disable 180 * read value from config file, 0 to disable
180 */ 181 */
181void OpieScreenSaver::setInterval ( int interval ) 182void OpieScreenSaver::setInterval ( int interval )
182{ 183{
183 setIntervals ( -1, -1, interval ); 184 setIntervals ( -1, -1, interval );
184} 185}
185 186
186 187
187void OpieScreenSaver::setMode ( int mode ) 188void OpieScreenSaver::setMode ( int mode )
188{ 189{
189 if ( mode > m_disable_suspend ) 190 if ( mode > m_disable_suspend )
190 setInterval ( -1 ); 191 setInterval ( -1 );
191 m_disable_suspend = mode; 192 m_disable_suspend = mode;
192} 193}
193 194
194 195
195/** 196/**
196 * Set display brightness 197 * Set display brightness
197 * 198 *
@@ -200,45 +201,46 @@ void OpieScreenSaver::setMode ( int mode )
200 * @param bright desired brighness (-1 to use automatic sensor data or value 201 * @param bright desired brighness (-1 to use automatic sensor data or value
201 * from config file, -2 to toggle backlight on and off, -3 to 202 * from config file, -2 to toggle backlight on and off, -3 to
202 * force backlight off) 203 * force backlight off)
203 */ 204 */
204void OpieScreenSaver::setBacklight ( int bright ) 205void OpieScreenSaver::setBacklight ( int bright )
205{ 206{
206 // Read from config 207 // Read from config
207 Config config ( "apm" ); 208 Config config ( "apm" );
208 config. setGroup ( m_on_ac ? "AC" : "Battery" ); 209 config. setGroup ( m_on_ac ? "AC" : "Battery" );
209 m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); 210 m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 );
210 int contrast = config. readNumEntry ( "Contrast", 127); 211 int contrast = config. readNumEntry ( "Contrast", 127);
211 m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); 212 m_use_light_sensor = config. readBoolEntry ( "LightSensor", false );
212 213
213 //qDebug ( "setBacklight: %d (norm: %d) (ls: %d)", bright, m_backlight_normal, m_use_light_sensor ? 1 : 0 ); 214 //odebug << "setBacklight: " << bright << " (norm: " << m_backlight_normal << ") (ls: "
214 215 // << ( m_use_light_sensor ? 1 : 0 ) << ")" << oendl;
215 killTimers ( ); 216
216 if (( bright < 0 ) && m_use_light_sensor ) { 217 killTimers ( );
217 QStringList sl = config. readListEntry ( "LightSensorData", ';' ); 218 if (( bright < 0 ) && m_use_light_sensor ) {
218 219 QStringList sl = config. readListEntry ( "LightSensorData", ';' );
219 m_sensordata [LS_SensorMin] = 40; 220
220 m_sensordata [LS_SensorMax] = 215; 221 m_sensordata [LS_SensorMin] = 40;
221 m_sensordata [LS_LightMin] = 1; 222 m_sensordata [LS_SensorMax] = 215;
222 m_sensordata [LS_LightMax] = 255; 223 m_sensordata [LS_LightMin] = 1;
223 m_sensordata [LS_Steps] = 12; 224 m_sensordata [LS_LightMax] = 255;
224 m_sensordata [LS_Interval] = 2000; 225 m_sensordata [LS_Steps] = 12;
225 226 m_sensordata [LS_Interval] = 2000;
226 for ( uint i = 0; i < LS_Count; i++ ) { 227
227 if ( i < sl. count ( )) 228 for ( uint i = 0; i < LS_Count; i++ ) {
228 m_sensordata [i] = sl [i]. toInt ( ); 229 if ( i < sl. count ( ))
229 } 230 m_sensordata [i] = sl [i]. toInt ( );
230 if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE 231 }
231 m_sensordata [LS_Steps] = 2; 232 if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE
232 233 m_sensordata [LS_Steps] = 2;
233 timerEvent ( 0 ); 234
234 startTimer ( m_sensordata [LS_Interval] ); 235 timerEvent ( 0 );
235 } 236 startTimer ( m_sensordata [LS_Interval] );
236 237 }
237 setBacklightInternal ( bright ); 238
238 ODevice::inst ( )-> setDisplayContrast(contrast); 239 setBacklightInternal ( bright );
240 ODevice::inst ( )-> setDisplayContrast(contrast);
239} 241}
240 242
241 243
242/** 244/**
243 * Internal brightness setting method 245 * Internal brightness setting method
244 * 246 *
@@ -247,82 +249,84 @@ void OpieScreenSaver::setBacklight ( int bright )
247 * @param bright desired brighness (-1 to use automatic sensor data or value 249 * @param bright desired brighness (-1 to use automatic sensor data or value
248 * from config file, -2 to toggle backlight on and off, -3 to 250 * from config file, -2 to toggle backlight on and off, -3 to
249 * force backlight off) 251 * force backlight off)
250 */ 252 */
251void OpieScreenSaver::setBacklightInternal ( int bright ) 253void OpieScreenSaver::setBacklightInternal ( int bright )
252{ 254{
253 if ( bright == -3 ) { 255 if ( bright == -3 ) {
254 // Forced on 256 // Forced on
255 m_backlight_forcedoff = false; 257 m_backlight_forcedoff = false;
256 bright = -1; 258 bright = -1;
257 } 259 }
258 if ( m_backlight_forcedoff && bright != -2 ) 260 if ( m_backlight_forcedoff && bright != -2 )
259 return ; 261 return ;
260 if ( bright == -2 ) { 262 if ( bright == -2 ) {
261 // Toggle between off and on 263 // Toggle between off and on
262 bright = m_backlight_current ? 0 : -1; 264 bright = m_backlight_current ? 0 : -1;
263 m_backlight_forcedoff = !bright; 265 m_backlight_forcedoff = !bright;
264 } 266 }
265 if ( bright == -1 ) 267 if ( bright == -1 )
266 bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; 268 bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal;
267 269
268 if ( bright != m_backlight_current ) { 270 if ( bright != m_backlight_current ) {
269 ODevice::inst ( )-> setDisplayBrightness ( bright ); 271 ODevice::inst ( )-> setDisplayBrightness ( bright );
270 m_backlight_current = bright; 272 m_backlight_current = bright;
271 } 273 }
272} 274}
273 275
274 276
275/** 277/**
276 * Timer event used for automatic setting the backlight according to a light sensor 278 * Timer event used for automatic setting the backlight according to a light sensor
277 * and to set the default brightness 279 * and to set the default brightness
278 */ 280 */
279void OpieScreenSaver::timerEvent ( QTimerEvent * ) 281void OpieScreenSaver::timerEvent ( QTimerEvent * )
280{ 282{
281 int s = ODevice::inst ( )-> readLightSensor ( ) * 256 / ODevice::inst ( )-> lightSensorResolution ( ); 283 int s = ODevice::inst ( )-> readLightSensor ( ) * 256 / ODevice::inst ( )-> lightSensorResolution ( );
282 284
283 if ( s < m_sensordata [LS_SensorMin] ) 285 if ( s < m_sensordata [LS_SensorMin] )
284 m_backlight_sensor = m_sensordata [LS_LightMax]; 286 m_backlight_sensor = m_sensordata [LS_LightMax];
285 else if ( s >= m_sensordata [LS_SensorMax] ) 287 else if ( s >= m_sensordata [LS_SensorMax] )
286 m_backlight_sensor = m_sensordata [LS_LightMin]; 288 m_backlight_sensor = m_sensordata [LS_LightMin];
287 else { 289 else {
288 int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; 290 int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin];
289 int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; 291 int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin];
290 292
291 int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0 293 int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0
292 294
293 m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); 295 m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 );
294 } 296 }
295 297
296 //qDebug ( "f(%d) = %d [%d - %d] -> [%d - %d] / %d", s, m_backlight_sensor, m_sensordata [LS_SensorMin], m_sensordata [LS_SensorMax], m_sensordata [LS_LightMin], m_sensordata [LS_LightMax], m_sensordata [LS_Steps] ); 298 odebug << "f(" << s << ") = " << m_backlight_sensor << " [" << m_sensordata [LS_SensorMin]
299 << " - " << m_sensordata [LS_SensorMax] << " ] -> [" << m_sensordata [LS_LightMin]
300 << " - " << m_sensordata [LS_LightMax] << "] / " << m_sensordata [LS_Steps] << oendl;
297 301
298 if ( m_level <= 0 ) 302 if ( m_level <= 0 )
299 setBacklightInternal ( -1 ); 303 setBacklightInternal ( -1 );
300} 304}
301 305
302 306
303/** 307/**
304 * Like ODevice::setDisplayStatus(), but keep current state in m_lcd_status. 308 * Like ODevice::setDisplayStatus(), but keep current state in m_lcd_status.
305 */ 309 */
306void OpieScreenSaver::setDisplayState ( bool on ) 310void OpieScreenSaver::setDisplayState ( bool on )
307{ 311{
308 if ( m_lcd_status != on ) { 312 if ( m_lcd_status != on ) {
309 ODevice::inst ( ) -> setDisplayStatus ( on ); 313 ODevice::inst ( ) -> setDisplayStatus ( on );
310 m_lcd_status = on; 314 m_lcd_status = on;
311 } 315 }
312} 316}
313 317
314 318
315/** 319/**
316 * Set display to default ac/battery settings when power status changed. 320 * Set display to default ac/battery settings when power status changed.
317 */ 321 */
318void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) 322void OpieScreenSaver::powerStatusChanged ( PowerStatus ps )
319{ 323{
320 bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); 324 bool newonac = ( ps. acStatus ( ) == PowerStatus::Online );
321 325
322 if ( newonac != m_on_ac ) { 326 if ( newonac != m_on_ac ) {
323 m_on_ac = newonac; 327 m_on_ac = newonac;
324 setInterval ( -1 ); 328 setInterval ( -1 );
325 setBacklight ( -1 ); 329 setBacklight ( -1 );
326 restore ( ); 330 restore ( );
327 } 331 }
328} 332}
diff --git a/core/launcher/server.cpp b/core/launcher/server.cpp
index b9fa1e5..950032d 100644
--- a/core/launcher/server.cpp
+++ b/core/launcher/server.cpp
@@ -75,22 +75,22 @@ static QWidget *calibrate(bool)
75 return 0; 75 return 0;
76#endif 76#endif
77} 77}
78 78
79#define FACTORY(T) \ 79#define FACTORY(T) \
80 static QWidget *new##T( bool maximized ) { \ 80 static QWidget *new##T( bool maximized ) { \
81 QWidget *w = new T( 0, 0, QWidget::WDestructiveClose | QWidget::WGroupLeader ); \ 81 QWidget *w = new T( 0, 0, QWidget::WDestructiveClose | QWidget::WGroupLeader ); \
82 if ( maximized ) { \ 82 if ( maximized ) { \
83 if ( qApp->desktop()->width() <= 350 ) { \ 83 if ( qApp->desktop()->width() <= 350 ) { \
84 w->showMaximized(); \ 84 w->showMaximized(); \
85 } else { \ 85 } else { \
86 w->resize( QSize( 300, 300 ) ); \ 86 w->resize( QSize( 300, 300 ) ); \
87 } \ 87 } \
88 } \ 88 } \
89 w->show(); \ 89 w->show(); \
90 return w; \ 90 return w; \
91 } 91 }
92 92
93 93
94#ifdef SINGLE_APP 94#ifdef SINGLE_APP
95#define APP(a,b,c,d) FACTORY(b) 95#define APP(a,b,c,d) FACTORY(b)
96#include "apps.h" 96#include "apps.h"
@@ -104,20 +104,20 @@ static Global::Command builtins[] = {
104#include "apps.h" 104#include "apps.h"
105#undef APP 105#undef APP
106#endif 106#endif
107 107
108 /* FIXME defines need to be defined*/ 108 /* FIXME defines need to be defined*/
109#if !defined(OPIE_NO_BUILTIN_CALIBRATE) 109#if !defined(OPIE_NO_BUILTIN_CALIBRATE)
110 { "calibrate", calibrate, 1, 0 }, // No tr 110 { "calibrate", calibrate, 1, 0 }, // No tr
111#endif 111#endif
112#if !defined(OPIE_NO_BUILTIN_SHUTDOWN) 112#if !defined(OPIE_NO_BUILTIN_SHUTDOWN)
113 { "shutdown", Global::shutdown, 1, 0 }, // No tr 113 { "shutdown", Global::shutdown, 1, 0 }, // No tr
114 // { "run", run, 1, 0 }, // No tr 114// { "run", run, 1, 0 }, // No tr
115#endif 115#endif
116 116
117 { 0, calibrate,0, 0 }, 117 { 0, calibrate, 0, 0 },
118}; 118};
119 119
120 120
121//--------------------------------------------------------------------------- 121//---------------------------------------------------------------------------
122 122
123 123
@@ -163,17 +163,17 @@ Server::Server() :
163 this,SLOT(activate(const Opie::Core::ODeviceButton*,bool))); 163 this,SLOT(activate(const Opie::Core::ODeviceButton*,bool)));
164 164
165 setGeometry( -10, -10, 9, 9 ); 165 setGeometry( -10, -10, 9, 9 );
166 166
167 QCopChannel *channel = new QCopChannel("QPE/System", this); 167 QCopChannel *channel = new QCopChannel("QPE/System", this);
168 connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), 168 connect(channel, SIGNAL(received(const QCString&,const QByteArray&)),
169 this, SLOT(systemMsg(const QCString&,const QByteArray&)) ); 169 this, SLOT(systemMsg(const QCString&,const QByteArray&)) );
170 170
171 QCopChannel *tbChannel = new QCopChannel( "QPE/TaskBar", this ); 171 QCopChannel *tbChannel = new QCopChannel( "QPE/TaskBar", this );
172 connect( tbChannel, SIGNAL(received(const QCString&,const QByteArray&)), 172 connect( tbChannel, SIGNAL(received(const QCString&,const QByteArray&)),
173 this, SLOT(receiveTaskBar(const QCString&,const QByteArray&)) ); 173 this, SLOT(receiveTaskBar(const QCString&,const QByteArray&)) );
174 174
175 connect( qApp, SIGNAL(prepareForRestart()), this, SLOT(terminateServers()) ); 175 connect( qApp, SIGNAL(prepareForRestart()), this, SLOT(terminateServers()) );
176 connect( qApp, SIGNAL(timeChanged()), this, SLOT(pokeTimeMonitors()) ); 176 connect( qApp, SIGNAL(timeChanged()), this, SLOT(pokeTimeMonitors()) );
177 177
178 preloadApps(); 178 preloadApps();
179} 179}
@@ -199,59 +199,59 @@ Server::~Server()
199static bool hasVisibleWindow(const QString& clientname, bool partial) 199static bool hasVisibleWindow(const QString& clientname, bool partial)
200{ 200{
201#ifdef QWS 201#ifdef QWS
202 const QList<QWSWindow> &list = qwsServer->clientWindows(); 202 const QList<QWSWindow> &list = qwsServer->clientWindows();
203 QWSWindow* w; 203 QWSWindow* w;
204 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { 204 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
205 if ( w->client()->identity() == clientname ) { 205 if ( w->client()->identity() == clientname ) {
206 if ( partial && !w->isFullyObscured() ) 206 if ( partial && !w->isFullyObscured() )
207 return TRUE; 207 return TRUE;
208 if ( !partial && !w->isFullyObscured() && !w->isPartiallyObscured() ) { 208 if ( !partial && !w->isFullyObscured() && !w->isPartiallyObscured() ) {
209# if QT_VERSION < 0x030000 209# if QT_VERSION < 0x030000
210 QRect mwr = qt_screen->mapToDevice(qt_maxWindowRect, 210 QRect mwr = qt_screen->mapToDevice(qt_maxWindowRect,
211 QSize(qt_screen->width(),qt_screen->height()) ); 211 QSize(qt_screen->width(),qt_screen->height()) );
212# else 212# else
213 QRect mwr = qt_maxWindowRect; 213 QRect mwr = qt_maxWindowRect;
214# endif 214# endif
215 if ( mwr.contains(w->requested().boundingRect()) ) 215 if ( mwr.contains(w->requested().boundingRect()) )
216 return TRUE; 216 return TRUE;
217 } 217 }
218 } 218 }
219 } 219 }
220#endif 220#endif
221 return FALSE; 221 return FALSE;
222} 222}
223 223
224void Server::activate(const ODeviceButton* button, bool held) 224void Server::activate(const ODeviceButton* button, bool held)
225{ 225{
226 Global::terminateBuiltin("calibrate"); // No tr 226 Global::terminateBuiltin("calibrate"); // No tr
227 OQCopMessage om; 227 OQCopMessage om;
228 if ( held ) { 228 if ( held ) {
229 om = button->heldAction(); 229 om = button->heldAction();
230 } else { 230 } else {
231 om = button->pressedAction(); 231 om = button->pressedAction();
232 } 232 }
233 233
234 if ( om.channel() != "ignore" ) 234 if ( om.channel() != "ignore" )
235 om.send(); 235 om.send();
236 236
237 // A button with no action defined, will return a null ServiceRequest. Don't attempt 237 // A button with no action defined, will return a null ServiceRequest. Don't attempt
238 // to send/do anything with this as it will crash 238 // to send/do anything with this as it will crash
239 /* ### FIXME */ 239 /* ### FIXME */
240#if 0 240#if 0
241 if ( !sr.isNull() ) { 241 if ( !sr.isNull() ) {
242 QString app = sr.app(); 242 QString app = sr.app();
243 bool vis = hasVisibleWindow(app, app != "qpe"); 243 bool vis = hasVisibleWindow(app, app != "qpe");
244 if ( sr.message() == "raise()" && vis ) { 244 if ( sr.message() == "raise()" && vis ) {
245 sr.setMessage("nextView()"); 245 sr.setMessage("nextView()");
246 } else { 246 } else {
247 // "back door" 247 // "back door"
248 sr << (int)vis; 248 sr << (int)vis;
249 } 249 }
250 250
251 sr.send(); 251 sr.send();
252 } 252 }
253#endif 253#endif
254} 254}
255 255
256 256
257#ifdef Q_WS_QWS 257#ifdef Q_WS_QWS
@@ -289,20 +289,20 @@ static const KeyOverride jp109keys[] = {
289bool Server::setKeyboardLayout( const QString &kb ) 289bool Server::setKeyboardLayout( const QString &kb )
290{ 290{
291 //quick demo version that can be extended 291 //quick demo version that can be extended
292 292
293 QIntDict<QWSServer::KeyMap> *om = 0; 293 QIntDict<QWSServer::KeyMap> *om = 0;
294 if ( kb == "us101" ) { // No tr 294 if ( kb == "us101" ) { // No tr
295 om = 0; 295 om = 0;
296 } else if ( kb == "jp109" ) { 296 } else if ( kb == "jp109" ) {
297 om = new QIntDict<QWSServer::KeyMap>(37); 297 om = new QIntDict<QWSServer::KeyMap>(37);
298 const KeyOverride *k = jp109keys; 298 const KeyOverride *k = jp109keys;
299 while ( k->scan_code ) { 299 while ( k->scan_code ) {
300 om->insert( k->scan_code, &k->map ); 300 om->insert( k->scan_code, &k->map );
301 k++; 301 k++;
302 } 302 }
303 } 303 }
304 QWSServer::setOverrideKeys( om ); 304 QWSServer::setOverrideKeys( om );
305 305
306 return TRUE; 306 return TRUE;
307} 307}
308 308
@@ -310,176 +310,176 @@ bool Server::setKeyboardLayout( const QString &kb )
310 310
311void Server::systemMsg(const QCString &msg, const QByteArray &data) 311void Server::systemMsg(const QCString &msg, const QByteArray &data)
312{ 312{
313 QDataStream stream( data, IO_ReadOnly ); 313 QDataStream stream( data, IO_ReadOnly );
314 314
315 if ( msg == "securityChanged()" ) { 315 if ( msg == "securityChanged()" ) {
316 if ( transferServer ) 316 if ( transferServer )
317 transferServer->authorizeConnections(); 317 transferServer->authorizeConnections();
318 if ( qcopBridge ) 318 if ( qcopBridge )
319 qcopBridge->authorizeConnections(); 319 qcopBridge->authorizeConnections();
320 } 320 }
321 /* ### FIXME support TempScreenSaverMode */ 321 /* ### FIXME support TempScreenSaverMode */
322#if 0 322#if 0
323 else if ( msg == "setTempScreenSaverMode(int,int)" ) { 323 else if ( msg == "setTempScreenSaverMode(int,int)" ) {
324 int mode, pid; 324 int mode, pid;
325 stream >> mode >> pid; 325 stream >> mode >> pid;
326 tsmMonitor->setTempMode(mode, pid); 326 tsmMonitor->setTempMode(mode, pid);
327 } 327 }
328#endif 328#endif
329 else if ( msg == "linkChanged(QString)" ) { 329 else if ( msg == "linkChanged(QString)" ) {
330 QString link; 330 QString link;
331 stream >> link; 331 stream >> link;
332 odebug << "desktop.cpp systemMsg -> linkchanged( " << link << " )" << oendl; 332 odebug << "desktop.cpp systemMsg -> linkchanged( " << link << " )" << oendl;
333 docList->linkChanged(link); 333 docList->linkChanged(link);
334 } else if ( msg == "serviceChanged(QString)" ) { 334 } else if ( msg == "serviceChanged(QString)" ) {
335 MimeType::updateApplications(); 335 MimeType::updateApplications();
336 } else if ( msg == "mkdir(QString)" ) { 336 } else if ( msg == "mkdir(QString)" ) {
337 QString dir; 337 QString dir;
338 stream >> dir; 338 stream >> dir;
339 if ( !dir.isEmpty() ) 339 if ( !dir.isEmpty() )
340 mkdir( dir ); 340 mkdir( dir );
341 } else if ( msg == "rdiffGenSig(QString,QString)" ) { 341 } else if ( msg == "rdiffGenSig(QString,QString)" ) {
342 QString baseFile, sigFile; 342 QString baseFile, sigFile;
343 stream >> baseFile >> sigFile; 343 stream >> baseFile >> sigFile;
344 QRsync::generateSignature( baseFile, sigFile ); 344 QRsync::generateSignature( baseFile, sigFile );
345 } else if ( msg == "rdiffGenDiff(QString,QString,QString)" ) { 345 } else if ( msg == "rdiffGenDiff(QString,QString,QString)" ) {
346 QString baseFile, sigFile, deltaFile; 346 QString baseFile, sigFile, deltaFile;
347 stream >> baseFile >> sigFile >> deltaFile; 347 stream >> baseFile >> sigFile >> deltaFile;
348 QRsync::generateDiff( baseFile, sigFile, deltaFile ); 348 QRsync::generateDiff( baseFile, sigFile, deltaFile );
349 } else if ( msg == "rdiffApplyPatch(QString,QString)" ) { 349 } else if ( msg == "rdiffApplyPatch(QString,QString)" ) {
350 QString baseFile, deltaFile; 350 QString baseFile, deltaFile;
351 stream >> baseFile >> deltaFile; 351 stream >> baseFile >> deltaFile;
352 if ( !QFile::exists( baseFile ) ) { 352 if ( !QFile::exists( baseFile ) ) {
353 QFile f( baseFile ); 353 QFile f( baseFile );
354 f.open( IO_WriteOnly ); 354 f.open( IO_WriteOnly );
355 f.close(); 355 f.close();
356 } 356 }
357 QRsync::applyDiff( baseFile, deltaFile ); 357 QRsync::applyDiff( baseFile, deltaFile );
358#ifndef QT_NO_COP 358#ifndef QT_NO_COP
359 QCopEnvelope e( "QPE/Desktop", "patchApplied(QString)" ); 359 QCopEnvelope e( "QPE/Desktop", "patchApplied(QString)" );
360 e << baseFile; 360 e << baseFile;
361#endif 361#endif
362 } else if ( msg == "rdiffCleanup()" ) { 362 } else if ( msg == "rdiffCleanup()" ) {
363 mkdir( "/tmp/rdiff" ); 363 mkdir( "/tmp/rdiff" );
364 QDir dir; 364 QDir dir;
365 dir.setPath( "/tmp/rdiff" ); 365 dir.setPath( "/tmp/rdiff" );
366 QStringList entries = dir.entryList(); 366 QStringList entries = dir.entryList();
367 for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it ) 367 for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it )
368 dir.remove( *it ); 368 dir.remove( *it );
369 } else if ( msg == "sendHandshakeInfo()" ) { 369 } else if ( msg == "sendHandshakeInfo()" ) {
370 QString home = getenv( "HOME" ); 370 QString home = getenv( "HOME" );
371#ifndef QT_NO_COP 371#ifndef QT_NO_COP
372 QCopEnvelope e( "QPE/Desktop", "handshakeInfo(QString,bool)" ); 372 QCopEnvelope e( "QPE/Desktop", "handshakeInfo(QString,bool)" );
373 e << home; 373 e << home;
374 int locked = (int) ServerApplication::screenLocked(); 374 int locked = (int) ServerApplication::screenLocked();
375 e << locked; 375 e << locked;
376#endif 376#endif
377 377
378 } 378 }
379 /* 379 /*
380 * QtopiaDesktop relies on the major number 380 * QtopiaDesktop relies on the major number
381 * to start with 1. We're at 0.9 381 * to start with 1. We're at 0.9
382 * so wee need to fake at least 1.4 to be able 382 * so wee need to fake at least 1.4 to be able
383 * to sync with QtopiaDesktop1.6 383 * to sync with QtopiaDesktop1.6
384 */ 384 */
385 else if ( msg == "sendVersionInfo()" ) { 385 else if ( msg == "sendVersionInfo()" ) {
386 QCopEnvelope e( "QPE/Desktop", "versionInfo(QString,QString)" ); 386 QCopEnvelope e( "QPE/Desktop", "versionInfo(QString,QString)" );
387 /* ### FIXME Architecture ### */ 387 /* ### FIXME Architecture ### */
388 e << QString::fromLatin1("1.7") << "Uncustomized Device"; 388 e << QString::fromLatin1("1.7") << "Uncustomized Device";
389 } else if ( msg == "sendCardInfo()" ) { 389 } else if ( msg == "sendCardInfo()" ) {
390#ifndef QT_NO_COP 390#ifndef QT_NO_COP
391 QCopEnvelope e( "QPE/Desktop", "cardInfo(QString)" ); 391 QCopEnvelope e( "QPE/Desktop", "cardInfo(QString)" );
392#endif 392#endif
393 storage->update(); 393 storage->update();
394 const QList<FileSystem> &fs = storage->fileSystems(); 394 const QList<FileSystem> &fs = storage->fileSystems();
395 QListIterator<FileSystem> it ( fs ); 395 QListIterator<FileSystem> it ( fs );
396 QString s; 396 QString s;
397 QString homeDir = getenv("HOME"); 397 QString homeDir = getenv("HOME");
398 QString homeFs, homeFsPath; 398 QString homeFs, homeFsPath;
399 for ( ; it.current(); ++it ) { 399 for ( ; it.current(); ++it ) {
400 int k4 = (*it)->blockSize()/256; 400 int k4 = (*it)->blockSize()/256;
401 if ( (*it)->isRemovable() ) { 401 if ( (*it)->isRemovable() ) {
402 s += (*it)->name() + "=" + (*it)->path() + "/Documents " // No tr 402 s += (*it)->name() + "=" + (*it)->path() + "/Documents " // No tr
403 + QString::number( (*it)->availBlocks() * k4/4 ) 403 + QString::number( (*it)->availBlocks() * k4/4 )
404 + "K " + (*it)->options() + ";"; 404 + "K " + (*it)->options() + ";";
405 } else if ( homeDir.contains( (*it)->path() ) && 405 } else if ( homeDir.contains( (*it)->path() ) &&
406 (*it)->path().length() > homeFsPath.length() ) { 406 (*it)->path().length() > homeFsPath.length() ) {
407 homeFsPath = (*it)->path(); 407 homeFsPath = (*it)->path();
408 homeFs = 408 homeFs =
409 (*it)->name() + "=" + homeDir + "/Documents " // No tr 409 (*it)->name() + "=" + homeDir + "/Documents " // No tr
410 + QString::number( (*it)->availBlocks() * k4/4 ) 410 + QString::number( (*it)->availBlocks() * k4/4 )
411 + "K " + (*it)->options() + ";"; 411 + "K " + (*it)->options() + ";";
412 } 412 }
413 } 413 }
414 if ( !homeFs.isEmpty() ) 414 if ( !homeFs.isEmpty() )
415 s += homeFs; 415 s += homeFs;
416 416
417#ifndef QT_NO_COP 417#ifndef QT_NO_COP
418 e << s; 418 e << s;
419#endif 419#endif
420 } else if ( msg == "sendSyncDate(QString)" ) { 420 } else if ( msg == "sendSyncDate(QString)" ) {
421 QString app; 421 QString app;
422 stream >> app; 422 stream >> app;
423 Config cfg( "qpe" ); 423 Config cfg( "qpe" );
424 cfg.setGroup("SyncDate"); 424 cfg.setGroup("SyncDate");
425#ifndef QT_NO_COP 425#ifndef QT_NO_COP
426 QCopEnvelope e( "QPE/Desktop", "syncDate(QString,QString)" ); 426 QCopEnvelope e( "QPE/Desktop", "syncDate(QString,QString)" );
427 e << app << cfg.readEntry( app ); 427 e << app << cfg.readEntry( app );
428#endif 428#endif
429 //qDebug("QPE/System sendSyncDate for %s: response %s", app.latin1(), 429 //odebug << "QPE/System sendSyncDate for " << app.latin1() << ": response "
430 //cfg.readEntry( app ).latin1() ); 430 // << cfg.readEntry( app ).latin1() << oendl;
431 } else if ( msg == "setSyncDate(QString,QString)" ) { 431 } else if ( msg == "setSyncDate(QString,QString)" ) {
432 QString app, date; 432 QString app, date;
433 stream >> app >> date; 433 stream >> app >> date;
434 Config cfg( "qpe" ); 434 Config cfg( "qpe" );
435 cfg.setGroup("SyncDate"); 435 cfg.setGroup("SyncDate");
436 cfg.writeEntry( app, date ); 436 cfg.writeEntry( app, date );
437 //odebug << "setSyncDate(QString,QString) " << app << " " << date << "" << oendl; 437 //odebug << "setSyncDate(QString,QString) " << app << " " << date << "" << oendl;
438 } else if ( msg == "startSync(QString)" ) { 438 } else if ( msg == "startSync(QString)" ) {
439 QString what; 439 QString what;
440 stream >> what; 440 stream >> what;
441 delete syncDialog; 441 delete syncDialog;
442 syncDialog = new SyncDialog( this, what ); 442 syncDialog = new SyncDialog( this, what );
443 syncDialog->show(); 443 syncDialog->show();
444 connect( syncDialog, SIGNAL(cancel()), SLOT(cancelSync()) ); 444 connect( syncDialog, SIGNAL(cancel()), SLOT(cancelSync()) );
445 } else if ( msg == "stopSync()") { 445 } else if ( msg == "stopSync()") {
446 delete syncDialog; 446 delete syncDialog;
447 syncDialog = 0; 447 syncDialog = 0;
448 } else if (msg == "restoreDone(QString)") { 448 } else if (msg == "restoreDone(QString)") {
449 docList->restoreDone(); 449 docList->restoreDone();
450 } else if ( msg == "getAllDocLinks()" ) { 450 } else if ( msg == "getAllDocLinks()" ) {
451 docList->sendAllDocLinks(); 451 docList->sendAllDocLinks();
452 } 452 }
453#ifdef Q_WS_QWS 453#ifdef Q_WS_QWS
454 else if ( msg == "setMouseProto(QString)" ) { 454 else if ( msg == "setMouseProto(QString)" ) {
455 QString mice; 455 QString mice;
456 stream >> mice; 456 stream >> mice;
457 setenv("QWS_MOUSE_PROTO",mice.latin1(),1); 457 setenv("QWS_MOUSE_PROTO",mice.latin1(),1);
458 qwsServer->openMouse(); 458 qwsServer->openMouse();
459 } else if ( msg == "setKeyboard(QString)" ) { 459 } else if ( msg == "setKeyboard(QString)" ) {
460 QString kb; 460 QString kb;
461 stream >> kb; 461 stream >> kb;
462 setenv("QWS_KEYBOARD",kb.latin1(),1); 462 setenv("QWS_KEYBOARD",kb.latin1(),1);
463 qwsServer->openKeyboard(); 463 qwsServer->openKeyboard();
464 464
465 } else if ( msg == "setKeyboardAutoRepeat(int,int)" ) { 465 } else if ( msg == "setKeyboardAutoRepeat(int,int)" ) {
466 int delay, period; 466 int delay, period;
467 stream >> delay >> period; 467 stream >> delay >> period;
468 qwsSetKeyboardAutoRepeat( delay, period ); 468 qwsSetKeyboardAutoRepeat( delay, period );
469 Config cfg( "qpe" ); 469 Config cfg( "qpe" );
470 cfg.setGroup("Keyboard"); 470 cfg.setGroup("Keyboard");
471 cfg.writeEntry( "RepeatDelay", delay ); 471 cfg.writeEntry( "RepeatDelay", delay );
472 cfg.writeEntry( "RepeatPeriod", period ); 472 cfg.writeEntry( "RepeatPeriod", period );
473 } else if ( msg == "setKeyboardLayout(QString)" ) { 473 } else if ( msg == "setKeyboardLayout(QString)" ) {
474 QString kb; 474 QString kb;
475 stream >> kb; 475 stream >> kb;
476 setKeyboardLayout( kb ); 476 setKeyboardLayout( kb );
477 Config cfg( "qpe" ); 477 Config cfg( "qpe" );
478 cfg.setGroup("Keyboard"); 478 cfg.setGroup("Keyboard");
479 cfg.writeEntry( "Layout", kb ); 479 cfg.writeEntry( "Layout", kb );
480 } else if ( msg == "autoStart(QString)" ) { 480 } else if ( msg == "autoStart(QString)" ) {
481 QString appName; 481 QString appName;
482 stream >> appName; 482 stream >> appName;
483 Config cfg( "autostart" ); 483 Config cfg( "autostart" );
484 cfg.setGroup( "AutoStart" ); 484 cfg.setGroup( "AutoStart" );
485 if ( appName.compare("clear") == 0){ 485 if ( appName.compare("clear") == 0){
@@ -526,22 +526,22 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
526 526
527void Server::receiveTaskBar(const QCString &msg, const QByteArray &data) 527void Server::receiveTaskBar(const QCString &msg, const QByteArray &data)
528{ 528{
529 QDataStream stream( data, IO_ReadOnly ); 529 QDataStream stream( data, IO_ReadOnly );
530 530
531 if ( msg == "reloadApps()" ) { 531 if ( msg == "reloadApps()" ) {
532 docList->reloadAppLnks(); 532 docList->reloadAppLnks();
533 } else if ( msg == "soundAlarm()" ) { 533 } else if ( msg == "soundAlarm()" ) {
534 ServerApplication::soundAlarm(); 534 ServerApplication::soundAlarm();
535 } 535 }
536 else if ( msg == "setLed(int,bool)" ) { 536 else if ( msg == "setLed(int,bool)" ) {
537 int led, status; 537 int led, status;
538 stream >> led >> status; 538 stream >> led >> status;
539 539
540 QValueList <OLed> ll = ODevice::inst ( )-> ledList ( ); 540 QValueList <OLed> ll = ODevice::inst ( )-> ledList ( );
541 if ( ll. count ( )){ 541 if ( ll. count ( )) {
542 OLed l = ll. contains ( Led_Mail ) ? Led_Mail : ll [0]; 542 OLed l = ll. contains ( Led_Mail ) ? Led_Mail : ll [0];
543 bool canblink = ODevice::inst ( )-> ledStateList ( l ). contains ( Led_BlinkSlow ); 543 bool canblink = ODevice::inst ( )-> ledStateList ( l ). contains ( Led_BlinkSlow );
544 544
545 ODevice::inst ( )-> setLedState ( l, status ? ( canblink ? Led_BlinkSlow : Led_On ) : Led_Off ); 545 ODevice::inst ( )-> setLedState ( l, status ? ( canblink ? Led_BlinkSlow : Led_On ) : Led_Off );
546 } 546 }
547 } 547 }
@@ -557,48 +557,48 @@ void Server::cancelSync()
557} 557}
558 558
559bool Server::mkdir(const QString &localPath) 559bool Server::mkdir(const QString &localPath)
560{ 560{
561 QDir fullDir(localPath); 561 QDir fullDir(localPath);
562 if (fullDir.exists()) 562 if (fullDir.exists())
563 return true; 563 return true;
564 564
565 // at this point the directory doesn't exist 565 // at this point the directory doesn't exist
566 // go through the directory tree and start creating the direcotories 566 // go through the directory tree and start creating the direcotories
567 // that don't exist; if we can't create the directories, return false 567 // that don't exist; if we can't create the directories, return false
568 568
569 QString dirSeps = "/"; 569 QString dirSeps = "/";
570 int dirIndex = localPath.find(dirSeps); 570 int dirIndex = localPath.find(dirSeps);
571 QString checkedPath; 571 QString checkedPath;
572 572
573 // didn't find any seps; weird, use the cur dir instead 573 // didn't find any seps; weird, use the cur dir instead
574 if (dirIndex == -1) { 574 if (dirIndex == -1) {
575 //odebug << "No seperators found in path " << localPath << "" << oendl; 575 //odebug << "No seperators found in path " << localPath << "" << oendl;
576 checkedPath = QDir::currentDirPath(); 576 checkedPath = QDir::currentDirPath();
577 } 577 }
578 578
579 while (checkedPath != localPath) { 579 while (checkedPath != localPath) {
580 // no more seperators found, use the local path 580 // no more seperators found, use the local path
581 if (dirIndex == -1) 581 if (dirIndex == -1)
582 checkedPath = localPath; 582 checkedPath = localPath;
583 else { 583 else {
584 // the next directory to check 584 // the next directory to check
585 checkedPath = localPath.left(dirIndex) + "/"; 585 checkedPath = localPath.left(dirIndex) + "/";
586 // advance the iterator; the next dir seperator 586 // advance the iterator; the next dir seperator
587 dirIndex = localPath.find(dirSeps, dirIndex+1); 587 dirIndex = localPath.find(dirSeps, dirIndex+1);
588 } 588 }
589 589
590 QDir checkDir(checkedPath); 590 QDir checkDir(checkedPath);
591 if (!checkDir.exists()) { 591 if (!checkDir.exists()) {
592 //odebug << "mkdir making dir " << checkedPath << "" << oendl; 592 //odebug << "mkdir making dir " << checkedPath << "" << oendl;
593 593
594 if (!checkDir.mkdir(checkedPath)) { 594 if (!checkDir.mkdir(checkedPath)) {
595 odebug << "Unable to make directory " << checkedPath << "" << oendl; 595 odebug << "Unable to make directory " << checkedPath << "" << oendl;
596 return FALSE; 596 return FALSE;
597 } 597 }
598 } 598 }
599 599
600 } 600 }
601 return TRUE; 601 return TRUE;
602} 602}
603 603
604void Server::styleChange( QStyle &s ) 604void Server::styleChange( QStyle &s )
@@ -606,59 +606,59 @@ void Server::styleChange( QStyle &s )
606 QWidget::styleChange( s ); 606 QWidget::styleChange( s );
607} 607}
608 608
609void Server::startTransferServer() 609void Server::startTransferServer()
610{ 610{
611 if ( !qcopBridge ) { 611 if ( !qcopBridge ) {
612 // start qcop bridge server 612 // start qcop bridge server
613 qcopBridge = new QCopBridge( 4243 ); 613 qcopBridge = new QCopBridge( 4243 );
614 if ( qcopBridge->ok() ) { 614 if ( qcopBridge->ok() ) {
615 // ... OK 615 // ... OK
616 connect( qcopBridge, SIGNAL(connectionClosed(const QHostAddress&)), 616 connect( qcopBridge, SIGNAL(connectionClosed(const QHostAddress&)),
617 this, SLOT(syncConnectionClosed(const QHostAddress&)) ); 617 this, SLOT(syncConnectionClosed(const QHostAddress&)) );
618 } else { 618 } else {
619 delete qcopBridge; 619 delete qcopBridge;
620 qcopBridge = 0; 620 qcopBridge = 0;
621 } 621 }
622 } 622 }
623 if ( !transferServer ) { 623 if ( !transferServer ) {
624 // start transfer server 624 // start transfer server
625 transferServer = new TransferServer( 4242 ); 625 transferServer = new TransferServer( 4242 );
626 if ( transferServer->ok() ) { 626 if ( transferServer->ok() ) {
627 // ... OK 627 // ... OK
628 } else { 628 } else {
629 delete transferServer; 629 delete transferServer;
630 transferServer = 0; 630 transferServer = 0;
631 } 631 }
632 } 632 }
633 if ( !transferServer || !qcopBridge ) 633 if ( !transferServer || !qcopBridge )
634 tid_xfer = startTimer( 2000 ); 634 tid_xfer = startTimer( 2000 );
635} 635}
636 636
637void Server::timerEvent( QTimerEvent *e ) 637void Server::timerEvent( QTimerEvent *e )
638{ 638{
639 if ( e->timerId() == tid_xfer ) { 639 if ( e->timerId() == tid_xfer ) {
640 killTimer( tid_xfer ); 640 killTimer( tid_xfer );
641 tid_xfer = 0; 641 tid_xfer = 0;
642 startTransferServer(); 642 startTransferServer();
643 } 643 }
644 /* ### FIXME today startin */ 644 /* ### FIXME today startin */
645#if 0 645#if 0
646 else if ( e->timerId() == tid_today ) { 646 else if ( e->timerId() == tid_today ) {
647 QDate today = QDate::currentDate(); 647 QDate today = QDate::currentDate();
648 if ( today != last_today_show ) { 648 if ( today != last_today_show ) {
649 last_today_show = today; 649 last_today_show = today;
650 Config cfg("today"); 650 Config cfg("today");
651 cfg.setGroup("Start"); 651 cfg.setGroup("Start");
652#ifndef QPE_DEFAULT_TODAY_MODE 652#ifndef QPE_DEFAULT_TODAY_MODE
653#define QPE_DEFAULT_TODAY_MODE "Never" 653#define QPE_DEFAULT_TODAY_MODE "Never"
654#endif 654#endif
655 if ( cfg.readEntry("Mode",QPE_DEFAULT_TODAY_MODE) == "Daily" ) { 655 if ( cfg.readEntry("Mode",QPE_DEFAULT_TODAY_MODE) == "Daily" ) {
656 QCopEnvelope env(Service::channel("today"),"raise()"); 656 QCopEnvelope env(Service::channel("today"),"raise()");
657 } 657 }
658 } 658 }
659 } 659 }
660#endif 660#endif
661} 661}
662 662
663void Server::terminateServers() 663void Server::terminateServers()
664{ 664{
@@ -678,15 +678,15 @@ void Server::syncConnectionClosed( const QHostAddress & )
678void Server::pokeTimeMonitors() 678void Server::pokeTimeMonitors()
679{ 679{
680#if 0 680#if 0
681 // inform all TimeMonitors 681 // inform all TimeMonitors
682 QStrList tms = Service::channels("TimeMonitor"); 682 QStrList tms = Service::channels("TimeMonitor");
683 for (const char* ch = tms.first(); ch; ch=tms.next()) { 683 for (const char* ch = tms.first(); ch; ch=tms.next()) {
684 QString t = getenv("TZ"); 684 QString t = getenv("TZ");
685 QCopEnvelope e(ch, "timeChange(QString)"); 685 QCopEnvelope e(ch, "timeChange(QString)");
686 e << t; 686 e << t;
687 } 687 }
688#endif 688#endif
689} 689}
690 690
691void Server::applicationLaunched(int, const QString &app) 691void Server::applicationLaunched(int, const QString &app)
692{ 692{
@@ -719,11 +719,11 @@ void Server::preloadApps()
719{ 719{
720 Config cfg("Launcher"); 720 Config cfg("Launcher");
721 cfg.setGroup("Preload"); 721 cfg.setGroup("Preload");
722 QStringList apps = cfg.readListEntry("Apps",','); 722 QStringList apps = cfg.readListEntry("Apps",',');
723 for (QStringList::ConstIterator it=apps.begin(); it!=apps.end(); ++it) { 723 for (QStringList::ConstIterator it=apps.begin(); it!=apps.end(); ++it) {
724#ifndef QT_NO_COP 724#ifndef QT_NO_COP
725 QCopEnvelope e("QPE/Application/"+(*it).local8Bit(), "enablePreload()"); 725 QCopEnvelope e("QPE/Application/"+(*it).local8Bit(), "enablePreload()");
726#endif 726#endif
727 } 727 }
728} 728}
729 729
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index 4b764e3..c3f936e 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -59,17 +59,17 @@ TransferServer::TransferServer( Q_UINT16 port, QObject *parent,
59} 59}
60 60
61void TransferServer::authorizeConnections() 61void TransferServer::authorizeConnections()
62{ 62{
63 QListIterator<ServerPI> it(connections); 63 QListIterator<ServerPI> it(connections);
64 while ( it.current() ) { 64 while ( it.current() ) {
65 if ( !it.current()->verifyAuthorised() ) { 65 if ( !it.current()->verifyAuthorised() ) {
66 disconnect( it.current(), SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) ); 66 disconnect( it.current(), SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) );
67 connections.removeRef( it.current() ); 67 connections.removeRef( it.current() );
68 } else 68 } else
69 ++it; 69 ++it;
70 } 70 }
71} 71}
72 72
73void TransferServer::closed(ServerPI *item) 73void TransferServer::closed(ServerPI *item)
74{ 74{
75 connections.removeRef(item); 75 connections.removeRef(item);
@@ -101,15 +101,15 @@ QString SyncAuthentication::serverId()
101 101
102QString SyncAuthentication::ownerName() 102QString SyncAuthentication::ownerName()
103{ 103{
104 QString vfilename = Global::applicationFileName("addressbook", 104 QString vfilename = Global::applicationFileName("addressbook",
105 "businesscard.vcf"); 105 "businesscard.vcf");
106 if (QFile::exists(vfilename)) { 106 if (QFile::exists(vfilename)) {
107 Contact c; 107 Contact c;
108 c = Contact::readVCard( vfilename )[0]; 108 c = Contact::readVCard( vfilename )[0];
109 return c.fullName(); 109 return c.fullName();
110 } 110 }
111 111
112 return QString::null; 112 return QString::null;
113} 113}
114 114
115QString SyncAuthentication::loginName() 115QString SyncAuthentication::loginName()
@@ -124,24 +124,24 @@ QString SyncAuthentication::loginName()
124#endif 124#endif
125} 125}
126 126
127int SyncAuthentication::isAuthorized(QHostAddress peeraddress) 127int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
128{ 128{
129 Config cfg("Security"); 129 Config cfg("Security");
130 cfg.setGroup("Sync"); 130 cfg.setGroup("Sync");
131 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); 131 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
132 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); 132 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100);
133 133
134 // QHostAddress allowed; 134 // QHostAddress allowed;
135 // allowed.setAddress(allowedstr); 135 // allowed.setAddress(allowedstr);
136 // uint auth_peer = allowed.ip4Addr(); 136 // uint auth_peer = allowed.ip4Addr();
137 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); 137 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24);
138 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined 138 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined
139 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); 139 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits));
140 140
141 return (peeraddress.ip4Addr() & mask) == auth_peer; 141 return (peeraddress.ip4Addr() & mask) == auth_peer;
142} 142}
143 143
144bool SyncAuthentication::checkUser( const QString& user ) 144bool SyncAuthentication::checkUser( const QString& user )
145{ 145{
146 if ( user.isEmpty() ) return FALSE; 146 if ( user.isEmpty() ) return FALSE;
147 QString euser = loginName(); 147 QString euser = loginName();
@@ -158,18 +158,18 @@ bool SyncAuthentication::checkPassword( const QString& password )
158 158
159 pw = getpwuid( geteuid() ); 159 pw = getpwuid( geteuid() );
160 spw = getspnam( pw->pw_name ); 160 spw = getspnam( pw->pw_name );
161 161
162 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); 162 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
163 if ( cpwd == "x" && spw ) 163 if ( cpwd == "x" && spw )
164 cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); 164 cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
165 165
166 // Note: some systems use more than crypt for passwords. 166 // Note: some systems use more than crypt for passwords.
167 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); 167 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
168 if ( cpwd == cpassword ) 168 if ( cpwd == cpassword )
169 return TRUE; 169 return TRUE;
170#endif 170#endif
171 171
172 static int lastdenial=0; 172 static int lastdenial=0;
173 static int denials=0; 173 static int denials=0;
174 int now = time(0); 174 int now = time(0);
175 175
@@ -199,28 +199,28 @@ bool SyncAuthentication::checkPassword( const QString& password )
199 return FALSE; 199 return FALSE;
200 } 200 }
201 } 201 }
202 202
203 // Detect old Qtopia Desktop (no password) and fail 203 // Detect old Qtopia Desktop (no password) and fail
204 if ( password.isEmpty() ) { 204 if ( password.isEmpty() ) {
205 if ( denials < 3 || now > lastdenial+600 ) { 205 if ( denials < 3 || now > lastdenial+600 ) {
206 QMessageBox unauth( 206 QMessageBox unauth(
207 tr("Sync Connection"), 207 tr("Sync Connection"),
208 tr("<p>An unauthorized system is requesting access to this device." 208 tr("<p>An unauthorized system is requesting access to this device."
209 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " 209 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, "
210 "please upgrade or change the security setting to use IntelliSync." ), 210 "please upgrade or change the security setting to use IntelliSync." ),
211 QMessageBox::Warning, 211 QMessageBox::Warning,
212 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, 212 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton,
213 0, QString::null, TRUE, WStyle_StaysOnTop); 213 0, QString::null, TRUE, WStyle_StaysOnTop);
214 unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); 214 unauth.setButtonText(QMessageBox::Cancel, tr("Deny"));
215 unauth.exec(); 215 unauth.exec();
216 216
217 denials++; 217 denials++;
218 lastdenial=now; 218 lastdenial=now;
219 } 219 }
220 return FALSE; 220 return FALSE;
221 221
222 } 222 }
223 223
224 // Second, check sync password... 224 // Second, check sync password...
225 225
226 static int lock=0; 226 static int lock=0;
@@ -229,65 +229,65 @@ bool SyncAuthentication::checkPassword( const QString& password )
229 ++lock; 229 ++lock;
230 230
231 /* 231 /*
232 * we need to support old Sync software and QtopiaDesktop 232 * we need to support old Sync software and QtopiaDesktop
233 */ 233 */
234 if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) { 234 if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) {
235 Config cfg( "Security" ); 235 Config cfg( "Security" );
236 cfg.setGroup("Sync"); 236 cfg.setGroup("Sync");
237 QStringList pwds = cfg.readListEntry("Passwords",' '); 237 QStringList pwds = cfg.readListEntry("Passwords",' ');
238 for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) { 238 for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) {
239#ifndef Q_OS_WIN32 239#ifndef Q_OS_WIN32
240 QString cpassword = QString::fromLocal8Bit( 240 QString cpassword = QString::fromLocal8Bit(
241 crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) ); 241 crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) );
242#else 242#else
243 // ### revise 243 // ### revise
244 QString cpassword(""); 244 QString cpassword("");
245#endif 245#endif
246 if ( *it == cpassword ) { 246 if ( *it == cpassword ) {
247 lock--; 247 lock--;
248 return TRUE; 248 return TRUE;
249 } 249 }
250 } 250 }
251 251
252 // Unrecognized system. Be careful... 252 // Unrecognized system. Be careful...
253 QMessageBox unrecbox( 253 QMessageBox unrecbox(
254 tr("Sync Connection"), 254 tr("Sync Connection"),
255 tr("<p>An unrecognized system is requesting access to this device." 255 tr( "<p>An unrecognized system is requesting access to this device."
256 "<p>If you have just initiated a Sync for the first time, this is normal."), 256 "<p>If you have just initiated a Sync for the first time, this is normal."),
257 QMessageBox::Warning, 257 QMessageBox::Warning,
258 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, 258 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton,
259 0, QString::null, TRUE, WStyle_StaysOnTop); 259 0, QString::null, TRUE, WStyle_StaysOnTop);
260 unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny")); 260 unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny"));
261 unrecbox.setButtonText(QMessageBox::Yes, tr("Allow")); 261 unrecbox.setButtonText(QMessageBox::Yes, tr("Allow"));
262 262
263 if ( (denials > 2 && now < lastdenial+600) 263 if ( (denials > 2 && now < lastdenial+600)
264 || unrecbox.exec() != QMessageBox::Yes) 264 || unrecbox.exec() != QMessageBox::Yes)
265 { 265 {
266 denials++; 266 denials++;
267 lastdenial=now; 267 lastdenial=now;
268 lock--; 268 lock--;
269 return FALSE; 269 return FALSE;
270 } else { 270 } else {
271 const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."; 271 const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/.";
272 char salt[2]; 272 char salt[2];
273 salt[0]= salty[rand() % (sizeof(salty)-1)]; 273 salt[0]= salty[rand() % (sizeof(salty)-1)];
274 salt[1]= salty[rand() % (sizeof(salty)-1)]; 274 salt[1]= salty[rand() % (sizeof(salty)-1)];
275#ifndef Q_OS_WIN32 275#ifndef Q_OS_WIN32
276 QString cpassword = QString::fromLocal8Bit( 276 QString cpassword = QString::fromLocal8Bit(
277 crypt( password.mid(8).local8Bit(), salt ) ); 277 crypt( password.mid(8).local8Bit(), salt ) );
278#else 278#else
279 //### revise 279 //### revise
280 QString cpassword(""); 280 QString cpassword("");
281#endif 281#endif
282 denials=0; 282 denials=0;
283 pwds.prepend(cpassword); 283 pwds.prepend(cpassword);
284 cfg.writeEntry("Passwords",pwds,' '); 284 cfg.writeEntry("Passwords",pwds,' ');
285 lock--; 285 lock--;
286 return TRUE; 286 return TRUE;
287 } 287 }
288 } 288 }
289 lock--; 289 lock--;
290 290
291 return FALSE; 291 return FALSE;
292} 292}
293 293
@@ -302,43 +302,43 @@ ServerPI::ServerPI( int socket, QObject *parent, const char* name )
302 302
303 peerport = peerPort(); 303 peerport = peerPort();
304 peeraddress = peerAddress(); 304 peeraddress = peerAddress();
305 305
306#ifndef INSECURE 306#ifndef INSECURE
307 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 307 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
308 state = Forbidden; 308 state = Forbidden;
309 startTimer( 0 ); 309 startTimer( 0 );
310 } else 310 } else
311#endif 311#endif
312 { 312 {
313 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 313 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
314 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 314 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
315 315
316 passiv = FALSE; 316 passiv = FALSE;
317 for( int i = 0; i < 4; i++ ) 317 for( int i = 0; i < 4; i++ )
318 wait[i] = FALSE; 318 wait[i] = FALSE;
319 319
320 send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr 320 send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr
321 state = Wait_USER; 321 state = Wait_USER;
322 322
323 dtp = new ServerDTP( this ); 323 dtp = new ServerDTP( this );
324 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); 324 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) );
325 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); 325 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) );
326 connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) ); 326 connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) );
327 327
328 328
329 directory = QDir::currentDirPath(); 329 directory = QDir::currentDirPath();
330 330
331 static int p = 1024; 331 static int p = 1024;
332 332
333 while ( !serversocket || !serversocket->ok() ) { 333 while ( !serversocket || !serversocket->ok() ) {
334 delete serversocket; 334 delete serversocket;
335 serversocket = new ServerSocket( ++p, this ); 335 serversocket = new ServerSocket( ++p, this );
336 } 336 }
337 connect( serversocket, SIGNAL( newIncomming(int) ), 337 connect( serversocket, SIGNAL( newIncomming(int) ),
338 SLOT( newConnection(int) ) ); 338 SLOT( newConnection(int) ) );
339 } 339 }
340} 340}
341 341
342ServerPI::~ServerPI() 342ServerPI::~ServerPI()
343{ 343{
344 close(); 344 close();
@@ -349,14 +349,14 @@ ServerPI::~ServerPI()
349 delete serversocket; 349 delete serversocket;
350} 350}
351 351
352bool ServerPI::verifyAuthorised() 352bool ServerPI::verifyAuthorised()
353{ 353{
354 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { 354 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) {
355 state = Forbidden; 355 state = Forbidden;
356 return FALSE; 356 return FALSE;
357 } 357 }
358 return TRUE; 358 return TRUE;
359} 359}
360 360
361void ServerPI::connectionClosed() 361void ServerPI::connectionClosed()
362{ 362{
@@ -371,42 +371,42 @@ void ServerPI::send( const QString& msg )
371 //odebug << "Reply: " << msg << "" << oendl; 371 //odebug << "Reply: " << msg << "" << oendl;
372} 372}
373 373
374void ServerPI::read() 374void ServerPI::read()
375{ 375{
376 while ( canReadLine() ) 376 while ( canReadLine() )
377 process( readLine().stripWhiteSpace() ); 377 process( readLine().stripWhiteSpace() );
378} 378}
379 379
380bool ServerPI::checkReadFile( const QString& file ) 380bool ServerPI::checkReadFile( const QString& file )
381{ 381{
382 QString filename; 382 QString filename;
383 383
384 if ( file[0] != "/" ) 384 if ( file[0] != "/" )
385 filename = directory.path() + "/" + file; 385 filename = directory.path() + "/" + file;
386 else 386 else
387 filename = file; 387 filename = file;
388 388
389 QFileInfo fi( filename ); 389 QFileInfo fi( filename );
390 return ( fi.exists() && fi.isReadable() ); 390 return ( fi.exists() && fi.isReadable() );
391} 391}
392 392
393bool ServerPI::checkWriteFile( const QString& file ) 393bool ServerPI::checkWriteFile( const QString& file )
394{ 394{
395 QString filename; 395 QString filename;
396 396
397 if ( file[0] != "/" ) 397 if ( file[0] != "/" )
398 filename = directory.path() + "/" + file; 398 filename = directory.path() + "/" + file;
399 else 399 else
400 filename = file; 400 filename = file;
401 401
402 QFileInfo fi( filename ); 402 QFileInfo fi( filename );
403 403
404 if ( fi.exists() ) 404 if ( fi.exists() )
405 if ( !QFile( filename ).remove() ) 405 if ( !QFile( filename ).remove() )
406 return FALSE; 406 return FALSE;
407 return TRUE; 407 return TRUE;
408} 408}
409 409
410void ServerPI::process( const QString& message ) 410void ServerPI::process( const QString& message )
411{ 411{
412 //odebug << "Command: " << message << "" << oendl; 412 //odebug << "Command: " << message << "" << oendl;
@@ -418,13 +418,13 @@ void ServerPI::process( const QString& message )
418 // command token 418 // command token
419 QString cmd = msg[0].upper(); 419 QString cmd = msg[0].upper();
420 420
421 // argument token 421 // argument token
422 QString arg; 422 QString arg;
423 if ( msg.count() >= 2 ) 423 if ( msg.count() >= 2 )
424 arg = msg[1]; 424 arg = msg[1];
425 425
426 // full argument string 426 // full argument string
427 QString args; 427 QString args;
428 if ( msg.count() >= 2 ) { 428 if ( msg.count() >= 2 ) {
429 QStringList copy( msg ); 429 QStringList copy( msg );
430 // FIXME: for Qt3 430 // FIXME: for Qt3
@@ -434,417 +434,416 @@ void ServerPI::process( const QString& message )
434 } 434 }
435 435
436 //odebug << "args: " << args << "" << oendl; 436 //odebug << "args: " << args << "" << oendl;
437 437
438 // we always respond to QUIT, regardless of state 438 // we always respond to QUIT, regardless of state
439 if ( cmd == "QUIT" ) { 439 if ( cmd == "QUIT" ) {
440 send( "211 Good bye!" ); // No tr 440 send( "211 Good bye!" ); // No tr
441 close(); 441 close();
442 return; 442 return;
443 } 443 }
444 444
445 // connected to client 445 // connected to client
446 if ( Connected == state ) 446 if ( Connected == state )
447 return; 447 return;
448 448
449 // waiting for user name 449 // waiting for user name
450 if ( Wait_USER == state ) { 450 if ( Wait_USER == state ) {
451 451
452 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { 452 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
453 send( "530 Please login with USER and PASS" ); // No tr 453 send( "530 Please login with USER and PASS" ); // No tr
454 return; 454 return;
455 } 455 }
456 send( "331 User name ok, need password" ); // No tr 456 send( "331 User name ok, need password" ); // No tr
457 state = Wait_PASS; 457 state = Wait_PASS;
458 return; 458 return;
459 } 459 }
460 460
461 // waiting for password 461 // waiting for password
462 if ( Wait_PASS == state ) { 462 if ( Wait_PASS == state ) {
463 463
464 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { 464 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
465 send( "530 Please login with USER and PASS" ); // No tr 465 send( "530 Please login with USER and PASS" ); // No tr
466 return; 466 return;
467 } 467 }
468 send( "230 User logged in, proceed" ); // No tr 468 send( "230 User logged in, proceed" ); // No tr
469 state = Ready; 469 state = Ready;
470 return; 470 return;
471 } 471 }
472 472
473 // ACCESS CONTROL COMMANDS 473 // ACCESS CONTROL COMMANDS
474 474
475 // Only an ALLO sent immediately before STOR is valid. 475 // Only an ALLO sent immediately before STOR is valid.
476 if ( cmd != "STOR" ) 476 if ( cmd != "STOR" )
477 storFileSize = -1; 477 storFileSize = -1;
478 478
479 // account (ACCT) 479 // account (ACCT)
480 if ( cmd == "ACCT" ) { 480 if ( cmd == "ACCT" ) {
481 // even wu-ftp does not support it 481 // even wu-ftp does not support it
482 send( "502 Command not implemented" ); // No tr 482 send( "502 Command not implemented" ); // No tr
483 } 483 }
484 484
485 // change working directory (CWD) 485 // change working directory (CWD)
486 else if ( cmd == "CWD" ) { 486 else if ( cmd == "CWD" ) {
487 487
488 if ( !args.isEmpty() ) { 488 if ( !args.isEmpty() ) {
489 if ( directory.cd( args, TRUE ) ) 489 if ( directory.cd( args, TRUE ) )
490 send( "250 Requested file action okay, completed" ); // No tr 490 send( "250 Requested file action okay, completed" ); // No tr
491 else 491 else
492 send( "550 Requested action not taken" ); // No tr 492 send( "550 Requested action not taken" ); // No tr
493 } 493 }
494 else 494 else
495 send( "500 Syntax error, command unrecognized" ); // No tr 495 send( "500 Syntax error, command unrecognized" ); // No tr
496 } 496 }
497 497
498 // change to parent directory (CDUP) 498 // change to parent directory (CDUP)
499 else if ( cmd == "CDUP" ) { 499 else if ( cmd == "CDUP" ) {
500 if ( directory.cdUp() ) 500 if ( directory.cdUp() )
501 send( "250 Requested file action okay, completed" ); // No tr 501 send( "250 Requested file action okay, completed" ); // No tr
502 else 502 else
503 send( "550 Requested action not taken" ); // No tr 503 send( "550 Requested action not taken" ); // No tr
504 } 504 }
505 505
506 // structure mount (SMNT) 506 // structure mount (SMNT)
507 else if ( cmd == "SMNT" ) { 507 else if ( cmd == "SMNT" ) {
508 // even wu-ftp does not support it 508 // even wu-ftp does not support it
509 send( "502 Command not implemented" ); // No tr 509 send( "502 Command not implemented" ); // No tr
510 } 510 }
511 511
512 // reinitialize (REIN) 512 // reinitialize (REIN)
513 else if ( cmd == "REIN" ) { 513 else if ( cmd == "REIN" ) {
514 // even wu-ftp does not support it 514 // even wu-ftp does not support it
515 send( "502 Command not implemented" ); // No tr 515 send( "502 Command not implemented" ); // No tr
516 } 516 }
517 517
518 518
519 // TRANSFER PARAMETER COMMANDS 519 // TRANSFER PARAMETER COMMANDS
520 520
521 521
522 // data port (PORT) 522 // data port (PORT)
523 else if ( cmd == "PORT" ) { 523 else if ( cmd == "PORT" ) {
524 if ( parsePort( arg ) ) 524 if ( parsePort( arg ) )
525 send( "200 Command okay" ); // No tr 525 send( "200 Command okay" ); // No tr
526 else 526 else
527 send( "500 Syntax error, command unrecognized" ); // No tr 527 send( "500 Syntax error, command unrecognized" ); // No tr
528 } 528 }
529 529
530 // passive (PASV) 530 // passive (PASV)
531 else if ( cmd == "PASV" ) { 531 else if ( cmd == "PASV" ) {
532 passiv = TRUE; 532 passiv = TRUE;
533 send( "227 Entering Passive Mode (" // No tr 533 send( "227 Entering Passive Mode (" // No tr
534 + address().toString().replace( QRegExp( "\\." ), "," ) + "," 534 + address().toString().replace( QRegExp( "\\." ), "," ) + ","
535 + QString::number( ( serversocket->port() ) >> 8 ) + "," 535 + QString::number( ( serversocket->port() ) >> 8 ) + ","
536 + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); 536 + QString::number( ( serversocket->port() ) & 0xFF ) +")" );
537 } 537 }
538 538
539 // representation type (TYPE) 539 // representation type (TYPE)
540 else if ( cmd == "TYPE" ) { 540 else if ( cmd == "TYPE" ) {
541 if ( arg.upper() == "A" || arg.upper() == "I" ) 541 if ( arg.upper() == "A" || arg.upper() == "I" )
542 send( "200 Command okay" ); // No tr 542 send( "200 Command okay" ); // No tr
543 else 543 else
544 send( "504 Command not implemented for that parameter" ); // No tr 544 send( "504 Command not implemented for that parameter" ); // No tr
545 } 545 }
546 546
547 // file structure (STRU) 547 // file structure (STRU)
548 else if ( cmd == "STRU" ) { 548 else if ( cmd == "STRU" ) {
549 if ( arg.upper() == "F" ) 549 if ( arg.upper() == "F" )
550 send( "200 Command okay" ); // No tr 550 send( "200 Command okay" ); // No tr
551 else 551 else
552 send( "504 Command not implemented for that parameter" ); // No tr 552 send( "504 Command not implemented for that parameter" ); // No tr
553 } 553 }
554 554
555 // transfer mode (MODE) 555 // transfer mode (MODE)
556 else if ( cmd == "MODE" ) { 556 else if ( cmd == "MODE" ) {
557 if ( arg.upper() == "S" ) 557 if ( arg.upper() == "S" )
558 send( "200 Command okay" ); // No tr 558 send( "200 Command okay" ); // No tr
559 else 559 else
560 send( "504 Command not implemented for that parameter" ); // No tr 560 send( "504 Command not implemented for that parameter" ); // No tr
561 } 561 }
562 562
563 563
564 // FTP SERVICE COMMANDS 564 // FTP SERVICE COMMANDS
565 565
566 566
567 // retrieve (RETR) 567 // retrieve (RETR)
568 else if ( cmd == "RETR" ) 568 else if ( cmd == "RETR" )
569 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) 569 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) )
570 || backupRestoreGzip( absFilePath( args ) ) ) { 570 || backupRestoreGzip( absFilePath( args ) ) ) {
571 send( "150 File status okay" ); // No tr 571 send( "150 File status okay" ); // No tr
572 sendFile( absFilePath( args ) ); 572 sendFile( absFilePath( args ) );
573 } 573 }
574 else { 574 else {
575 odebug << "550 Requested action not taken" << oendl; 575 odebug << "550 Requested action not taken" << oendl;
576 send( "550 Requested action not taken" ); // No tr 576 send( "550 Requested action not taken" ); // No tr
577 } 577 }
578 578
579 // store (STOR) 579 // store (STOR)
580 else if ( cmd == "STOR" ) 580 else if ( cmd == "STOR" )
581 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { 581 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) {
582 send( "150 File status okay" ); // No tr 582 send( "150 File status okay" ); // No tr
583 retrieveFile( absFilePath( args ) ); 583 retrieveFile( absFilePath( args ) );
584 } 584 }
585 else 585 else
586 send( "550 Requested action not taken" ); // No tr 586 send( "550 Requested action not taken" ); // No tr
587 587
588 // store unique (STOU) 588 // store unique (STOU)
589 else if ( cmd == "STOU" ) { 589 else if ( cmd == "STOU" ) {
590 send( "502 Command not implemented" ); // No tr 590 send( "502 Command not implemented" ); // No tr
591 } 591 }
592 592
593 // append (APPE) 593 // append (APPE)
594 else if ( cmd == "APPE" ) { 594 else if ( cmd == "APPE" ) {
595 send( "502 Command not implemented" ); // No tr 595 send( "502 Command not implemented" ); // No tr
596 } 596 }
597 597
598 // allocate (ALLO) 598 // allocate (ALLO)
599 else if ( cmd == "ALLO" ) { 599 else if ( cmd == "ALLO" ) {
600 storFileSize = args.toInt(); 600 storFileSize = args.toInt();
601 send( "200 Command okay" ); // No tr 601 send( "200 Command okay" ); // No tr
602 } 602 }
603 603
604 // restart (REST) 604 // restart (REST)
605 else if ( cmd == "REST" ) { 605 else if ( cmd == "REST" ) {
606 send( "502 Command not implemented" ); // No tr 606 send( "502 Command not implemented" ); // No tr
607 } 607 }
608 608
609 // rename from (RNFR) 609 // rename from (RNFR)
610 else if ( cmd == "RNFR" ) { 610 else if ( cmd == "RNFR" ) {
611 renameFrom = QString::null; 611 renameFrom = QString::null;
612 if ( args.isEmpty() ) 612 if ( args.isEmpty() )
613 send( "500 Syntax error, command unrecognized" ); // No tr 613 send( "500 Syntax error, command unrecognized" ); // No tr
614 else { 614 else {
615 QFile file( absFilePath( args ) ); 615 QFile file( absFilePath( args ) );
616 if ( file.exists() ) { 616 if ( file.exists() ) {
617 send( "350 File exists, ready for destination name" ); // No tr 617 send( "350 File exists, ready for destination name" ); // No tr
618 renameFrom = absFilePath( args ); 618 renameFrom = absFilePath( args );
619 } 619 }
620 else 620 else
621 send( "550 Requested action not taken" ); // No tr 621 send( "550 Requested action not taken" ); // No tr
622 } 622 }
623 } 623 }
624 624
625 // rename to (RNTO) 625 // rename to (RNTO)
626 else if ( cmd == "RNTO" ) { 626 else if ( cmd == "RNTO" ) {
627 if ( lastCommand != "RNFR" ) 627 if ( lastCommand != "RNFR" )
628 send( "503 Bad sequence of commands" ); // No tr 628 send( "503 Bad sequence of commands" ); // No tr
629 else if ( args.isEmpty() ) 629 else if ( args.isEmpty() )
630 send( "500 Syntax error, command unrecognized" ); // No tr 630 send( "500 Syntax error, command unrecognized" ); // No tr
631 else { 631 else {
632 QDir dir( absFilePath( args ) ); 632 QDir dir( absFilePath( args ) );
633 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) 633 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) )
634 send( "250 Requested file action okay, completed." ); // No tr 634 send( "250 Requested file action okay, completed." ); // No tr
635 else 635 else
636 send( "550 Requested action not taken" ); // No tr 636 send( "550 Requested action not taken" ); // No tr
637 } 637 }
638 } 638 }
639 639
640 // abort (ABOR) 640 // abort (ABOR)
641 else if ( cmd.contains( "ABOR" ) ) { 641 else if ( cmd.contains( "ABOR" ) ) {
642 dtp->close(); 642 dtp->close();
643 if ( dtp->dtpMode() != ServerDTP::Idle ) 643 if ( dtp->dtpMode() != ServerDTP::Idle )
644 send( "426 Connection closed; transfer aborted" ); // No tr 644 send( "426 Connection closed; transfer aborted" ); // No tr
645 else 645 else
646 send( "226 Closing data connection" ); // No tr 646 send( "226 Closing data connection" ); // No tr
647 } 647 }
648 648
649 // delete (DELE) 649 // delete (DELE)
650 else if ( cmd == "DELE" ) { 650 else if ( cmd == "DELE" ) {
651 if ( args.isEmpty() ) 651 if ( args.isEmpty() )
652 send( "500 Syntax error, command unrecognized" ); // No tr 652 send( "500 Syntax error, command unrecognized" ); // No tr
653 else { 653 else {
654 QFile file( absFilePath( args ) ) ; 654 QFile file( absFilePath( args ) ) ;
655 if ( file.remove() ) { 655 if ( file.remove() ) {
656 send( "250 Requested file action okay, completed" ); // No tr 656 send( "250 Requested file action okay, completed" ); // No tr
657 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 657 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
658 e << file.name(); 658 e << file.name();
659 } else { 659 } else {
660 send( "550 Requested action not taken" ); // No tr 660 send( "550 Requested action not taken" ); // No tr
661 } 661 }
662 } 662 }
663 } 663 }
664 664
665 // remove directory (RMD) 665 // remove directory (RMD)
666 else if ( cmd == "RMD" ) { 666 else if ( cmd == "RMD" ) {
667 if ( args.isEmpty() ) 667 if ( args.isEmpty() )
668 send( "500 Syntax error, command unrecognized" ); // No tr 668 send( "500 Syntax error, command unrecognized" ); // No tr
669 else { 669 else {
670 QDir dir; 670 QDir dir;
671 if ( dir.rmdir( absFilePath( args ), TRUE ) ) 671 if ( dir.rmdir( absFilePath( args ), TRUE ) )
672 send( "250 Requested file action okay, completed" ); // No tr 672 send( "250 Requested file action okay, completed" ); // No tr
673 else 673 else
674 send( "550 Requested action not taken" ); // No tr 674 send( "550 Requested action not taken" ); // No tr
675 } 675 }
676 } 676 }
677 677
678 // make directory (MKD) 678 // make directory (MKD)
679 else if ( cmd == "MKD" ) { 679 else if ( cmd == "MKD" ) {
680 if ( args.isEmpty() ) { 680 if ( args.isEmpty() ) {
681 odebug << " Error: no arg" << oendl; 681 odebug << " Error: no arg" << oendl;
682 send( "500 Syntax error, command unrecognized" ); // No tr 682 send( "500 Syntax error, command unrecognized" ); // No tr
683 } 683 }
684 else { 684 else {
685 QDir dir; 685 QDir dir;
686 if ( dir.mkdir( absFilePath( args ), TRUE ) ) 686 if ( dir.mkdir( absFilePath( args ), TRUE ) )
687 send( "250 Requested file action okay, completed." ); // No tr 687 send( "250 Requested file action okay, completed." ); // No tr
688 else 688 else
689 send( "550 Requested action not taken" ); // No tr 689 send( "550 Requested action not taken" ); // No tr
690 } 690 }
691 } 691 }
692 692
693 // print working directory (PWD) 693 // print working directory (PWD)
694 else if ( cmd == "PWD" ) { 694 else if ( cmd == "PWD" ) {
695 send( "257 \"" + directory.path() +"\"" ); 695 send( "257 \"" + directory.path() +"\"" );
696 } 696 }
697 697
698 // list (LIST) 698 // list (LIST)
699 else if ( cmd == "LIST" ) { 699 else if ( cmd == "LIST" ) {
700 if ( sendList( absFilePath( args ) ) ) 700 if ( sendList( absFilePath( args ) ) )
701 send( "150 File status okay" ); // No tr 701 send( "150 File status okay" ); // No tr
702 else 702 else
703 send( "500 Syntax error, command unrecognized" ); // No tr 703 send( "500 Syntax error, command unrecognized" ); // No tr
704 } 704 }
705 705
706 // size (SIZE) 706 // size (SIZE)
707 else if ( cmd == "SIZE" ) { 707 else if ( cmd == "SIZE" ) {
708 QString filePath = absFilePath( args ); 708 QString filePath = absFilePath( args );
709 QFileInfo fi( filePath ); 709 QFileInfo fi( filePath );
710 bool gzipfile = backupRestoreGzip( filePath ); 710 bool gzipfile = backupRestoreGzip( filePath );
711 if ( !fi.exists() && !gzipfile ) 711 if ( !fi.exists() && !gzipfile )
712 send( "500 Syntax error, command unrecognized" ); // No tr 712 send( "500 Syntax error, command unrecognized" ); // No tr
713 else { 713 else {
714 if ( !gzipfile ) 714 if ( !gzipfile )
715 send( "213 " + QString::number( fi.size() ) ); 715 send( "213 " + QString::number( fi.size() ) );
716 else { 716 else {
717 Process duproc( QString("du") ); 717 Process duproc( QString("du") );
718 duproc.addArgument("-s"); 718 duproc.addArgument("-s");
719 QString in, out; 719 QString in, out;
720 if ( !duproc.exec(in, out) ) { 720 if ( !duproc.exec(in, out) ) {
721 odebug << "du process failed; just sending back 1K" << oendl; 721 odebug << "du process failed; just sending back 1K" << oendl;
722 send( "213 1024"); 722 send( "213 1024");
723 } 723 }
724 else { 724 else {
725 QString size = out.left( out.find("\t") ); 725 QString size = out.left( out.find("\t") );
726 int guess = size.toInt()/5; 726 int guess = size.toInt()/5;
727 if ( filePath.contains("doc") ) // No tr 727 if ( filePath.contains("doc") ) // No tr
728 guess *= 1000; 728 guess *= 1000;
729 odebug << "sending back gzip guess of " << guess << "" << oendl; 729 odebug << "sending back gzip guess of " << guess << "" << oendl;
730 send( "213 " + QString::number(guess) ); 730 send( "213 " + QString::number(guess) );
731 } 731 }
732 } 732 }
733 } 733 }
734 } 734 }
735 // name list (NLST) 735 // name list (NLST)
736 else if ( cmd == "NLST" ) { 736 else if ( cmd == "NLST" ) {
737 send( "502 Command not implemented" ); // No tr 737 send( "502 Command not implemented" ); // No tr
738 } 738 }
739 739
740 // site parameters (SITE) 740 // site parameters (SITE)
741 else if ( cmd == "SITE" ) { 741 else if ( cmd == "SITE" ) {
742 send( "502 Command not implemented" ); // No tr 742 send( "502 Command not implemented" ); // No tr
743 } 743 }
744 744
745 // system (SYST) 745 // system (SYST)
746 else if ( cmd == "SYST" ) { 746 else if ( cmd == "SYST" ) {
747 send( "215 UNIX Type: L8" ); // No tr 747 send( "215 UNIX Type: L8" ); // No tr
748 } 748 }
749 749
750 // status (STAT) 750 // status (STAT)
751 else if ( cmd == "STAT" ) { 751 else if ( cmd == "STAT" ) {
752 send( "502 Command not implemented" ); // No tr 752 send( "502 Command not implemented" ); // No tr
753 } 753 }
754 754
755 // help (HELP ) 755 // help (HELP )
756 else if ( cmd == "HELP" ) { 756 else if ( cmd == "HELP" ) {
757 send( "502 Command not implemented" ); // No tr 757 send( "502 Command not implemented" ); // No tr
758 } 758 }
759 759
760 // noop (NOOP) 760 // noop (NOOP)
761 else if ( cmd == "NOOP" ) { 761 else if ( cmd == "NOOP" ) {
762 send( "200 Command okay" ); // No tr 762 send( "200 Command okay" ); // No tr
763 } 763 }
764 764
765 // not implemented 765 // not implemented
766 else 766 else
767 send( "502 Command not implemented" ); // No tr 767 send( "502 Command not implemented" ); // No tr
768 768
769 lastCommand = cmd; 769 lastCommand = cmd;
770} 770}
771 771
772bool ServerPI::backupRestoreGzip( const QString &file ) 772bool ServerPI::backupRestoreGzip( const QString &file )
773{ 773{
774 return (file.find( "backup" ) != -1 && // No tr 774 return (file.find( "backup" ) != -1 && // No tr
775 file.findRev( ".tgz" ) == (int)file.length()-4 ); 775 file.findRev( ".tgz" ) == (int)file.length()-4 );
776} 776}
777 777
778bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) 778bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets )
779{ 779{
780 if ( file.find( "backup" ) != -1 && // No tr 780 if ( file.find( "backup" ) != -1 && // No tr
781 file.findRev( ".tgz" ) == (int)file.length()-4 ) { 781 file.findRev( ".tgz" ) == (int)file.length()-4 ) {
782 QFileInfo info( file ); 782 QFileInfo info( file );
783 targets = info.dirPath( TRUE ); 783 targets = info.dirPath( TRUE );
784 qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), 784 odebug << "ServerPI::backupRestoreGzip for " << file.latin1() << " = " << targets.join(" ").latin1() << oendl;
785 targets.join(" ").latin1() );
786 return true; 785 return true;
787 } 786 }
788 return false; 787 return false;
789} 788}
790 789
791void ServerPI::sendFile( const QString& file ) 790void ServerPI::sendFile( const QString& file )
792{ 791{
793 if ( passiv ) { 792 if ( passiv ) {
794 wait[SendFile] = TRUE; 793 wait[SendFile] = TRUE;
795 waitfile = file; 794 waitfile = file;
796 if ( waitsocket ) 795 if ( waitsocket )
797 newConnection( waitsocket ); 796 newConnection( waitsocket );
798 } 797 }
799 else { 798 else {
800 QStringList targets; 799 QStringList targets;
801 if ( backupRestoreGzip( file, targets ) ) 800 if ( backupRestoreGzip( file, targets ) )
802 dtp->sendGzipFile( file, targets, peeraddress, peerport ); 801 dtp->sendGzipFile( file, targets, peeraddress, peerport );
803 else dtp->sendFile( file, peeraddress, peerport ); 802 else dtp->sendFile( file, peeraddress, peerport );
804 } 803 }
805} 804}
806 805
807void ServerPI::retrieveFile( const QString& file ) 806void ServerPI::retrieveFile( const QString& file )
808{ 807{
809 if ( passiv ) { 808 if ( passiv ) {
810 wait[RetrieveFile] = TRUE; 809 wait[RetrieveFile] = TRUE;
811 waitfile = file; 810 waitfile = file;
812 if ( waitsocket ) 811 if ( waitsocket )
813 newConnection( waitsocket ); 812 newConnection( waitsocket );
814 } 813 }
815 else { 814 else {
816 QStringList targets; 815 QStringList targets;
817 if ( backupRestoreGzip( file, targets ) ) 816 if ( backupRestoreGzip( file, targets ) )
818 dtp->retrieveGzipFile( file, peeraddress, peerport ); 817 dtp->retrieveGzipFile( file, peeraddress, peerport );
819 else 818 else
820 dtp->retrieveFile( file, peeraddress, peerport, storFileSize ); 819 dtp->retrieveFile( file, peeraddress, peerport, storFileSize );
821 } 820 }
822} 821}
823 822
824bool ServerPI::parsePort( const QString& pp ) 823bool ServerPI::parsePort( const QString& pp )
825{ 824{
826 QStringList p = QStringList::split( ",", pp ); 825 QStringList p = QStringList::split( ",", pp );
827 if ( p.count() != 6 ) return FALSE; 826 if ( p.count() != 6 ) return FALSE;
828 827
829 // h1,h2,h3,h4,p1,p2 828 // h1,h2,h3,h4,p1,p2
830 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + 829 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) +
831 ( p[2].toInt() << 8 ) + p[3].toInt() ); 830 ( p[2].toInt() << 8 ) + p[3].toInt() );
832 peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); 831 peerport = ( p[4].toInt() << 8 ) + p[5].toInt();
833 return TRUE; 832 return TRUE;
834} 833}
835 834
836void ServerPI::dtpCompleted() 835void ServerPI::dtpCompleted()
837{ 836{
838 send( "226 Closing data connection, file transfer successful" ); // No tr 837 send( "226 Closing data connection, file transfer successful" ); // No tr
839 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { 838 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) {
840 QString fn = dtp->fileName(); 839 QString fn = dtp->fileName();
841 if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) { 840 if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) {
842 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 841 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
843 e << fn; 842 e << fn;
844 } 843 }
845 } 844 }
846 waitsocket = 0; 845 waitsocket = 0;
847 dtp->close(); 846 dtp->close();
848 storFileSize = -1; 847 storFileSize = -1;
849} 848}
850 849
@@ -867,116 +866,116 @@ void ServerPI::dtpError( int )
867bool ServerPI::sendList( const QString& arg ) 866bool ServerPI::sendList( const QString& arg )
868{ 867{
869 QByteArray listing; 868 QByteArray listing;
870 QBuffer buffer( listing ); 869 QBuffer buffer( listing );
871 870
872 if ( !buffer.open( IO_WriteOnly ) ) 871 if ( !buffer.open( IO_WriteOnly ) )
873 return FALSE; 872 return FALSE;
874 873
875 QTextStream ts( &buffer ); 874 QTextStream ts( &buffer );
876 QString fn = arg; 875 QString fn = arg;
877 876
878 if ( fn.isEmpty() ) 877 if ( fn.isEmpty() )
879 fn = directory.path(); 878 fn = directory.path();
880 879
881 QFileInfo fi( fn ); 880 QFileInfo fi( fn );
882 if ( !fi.exists() ) return FALSE; 881 if ( !fi.exists() ) return FALSE;
883 882
884 // return file listing 883 // return file listing
885 if ( fi.isFile() ) { 884 if ( fi.isFile() ) {
886 ts << fileListing( &fi ) << endl; 885 ts << fileListing( &fi ) << endl;
887 } 886 }
888 887
889 // return directory listing 888 // return directory listing
890 else if ( fi.isDir() ) { 889 else if ( fi.isDir() ) {
891 QDir dir( fn ); 890 QDir dir( fn );
892 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); 891 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden );
893 892
894 QFileInfoListIterator it( *list ); 893 QFileInfoListIterator it( *list );
895 QFileInfo *info; 894 QFileInfo *info;
896 895
897 unsigned long total = 0; 896 unsigned long total = 0;
898 while ( ( info = it.current() ) ) { 897 while ( ( info = it.current() ) ) {
899 if ( info->fileName() != "." && info->fileName() != ".." ) 898 if ( info->fileName() != "." && info->fileName() != ".." )
900 total += info->size(); 899 total += info->size();
901 ++it; 900 ++it;
902 } 901 }
903 902
904 ts << "total " << QString::number( total / 1024 ) << endl; // No tr 903 ts << "total " << QString::number( total / 1024 ) << endl; // No tr
905 904
906 it.toFirst(); 905 it.toFirst();
907 while ( ( info = it.current() ) ) { 906 while ( ( info = it.current() ) ) {
908 if ( info->fileName() == "." || info->fileName() == ".." ) { 907 if ( info->fileName() == "." || info->fileName() == ".." ) {
909 ++it; 908 ++it;
910 continue; 909 continue;
911 } 910 }
912 ts << fileListing( info ) << endl; 911 ts << fileListing( info ) << endl;
913 ++it; 912 ++it;
914 } 913 }
915 } 914 }
916 915
917 if ( passiv ) { 916 if ( passiv ) {
918 waitarray = buffer.buffer(); 917 waitarray = buffer.buffer();
919 wait[SendByteArray] = TRUE; 918 wait[SendByteArray] = TRUE;
920 if ( waitsocket ) 919 if ( waitsocket )
921 newConnection( waitsocket ); 920 newConnection( waitsocket );
922 } 921 }
923 else 922 else
924 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); 923 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport );
925 return TRUE; 924 return TRUE;
926} 925}
927 926
928QString ServerPI::fileListing( QFileInfo *info ) 927QString ServerPI::fileListing( QFileInfo *info )
929{ 928{
930 if ( !info ) return QString::null; 929 if ( !info ) return QString::null;
931 QString s; 930 QString s;
932 931
933 // type char 932 // type char
934 if ( info->isDir() ) 933 if ( info->isDir() )
935 s += "d"; 934 s += "d";
936 else if ( info->isSymLink() ) 935 else if ( info->isSymLink() )
937 s += "l"; 936 s += "l";
938 else 937 else
939 s += "-"; 938 s += "-";
940 939
941 // permisson string 940 // permisson string
942 s += permissionString( info ) + " "; 941 s += permissionString( info ) + " ";
943 942
944 // number of hardlinks 943 // number of hardlinks
945 int subdirs = 1; 944 int subdirs = 1;
946 945
947 if ( info->isDir() ) 946 if ( info->isDir() )
948 subdirs = 2; 947 subdirs = 2;
949 // FIXME : this is to slow 948 // FIXME : this is to slow
950 //if ( info->isDir() ) 949 //if ( info->isDir() )
951 //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); 950 //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count();
952 951
953 s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; 952 s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " ";
954 953
955 // owner 954 // owner
956 QString o = info->owner(); 955 QString o = info->owner();
957 if ( o.isEmpty() ) 956 if ( o.isEmpty() )
958 o = QString::number(info->ownerId()); 957 o = QString::number(info->ownerId());
959 s += o.leftJustify( 8, ' ', TRUE ) + " "; 958 s += o.leftJustify( 8, ' ', TRUE ) + " ";
960 959
961 // group 960 // group
962 QString g = info->group(); 961 QString g = info->group();
963 if ( g.isEmpty() ) 962 if ( g.isEmpty() )
964 g = QString::number(info->groupId()); 963 g = QString::number(info->groupId());
965 s += g.leftJustify( 8, ' ', TRUE ) + " "; 964 s += g.leftJustify( 8, ' ', TRUE ) + " ";
966 965
967 // file size in bytes 966 // file size in bytes
968 s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; 967 s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " ";
969 968
970 // last modified date 969 // last modified date
971 QDate date = info->lastModified().date(); 970 QDate date = info->lastModified().date();
972 QTime time = info->lastModified().time(); 971 QTime time = info->lastModified().time();
973 s += date.monthName( date.month() ) + " " 972 s += date.monthName( date.month() ) + " "
974 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " 973 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " "
975 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" 974 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":"
976 + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; 975 + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " ";
977 976
978 // file name 977 // file name
979 s += info->fileName(); 978 s += info->fileName();
980 979
981 return s; 980 return s;
982} 981}
@@ -1017,50 +1016,50 @@ void ServerPI::newConnection( int socket )
1017{ 1016{
1018 //odebug << "New incomming connection" << oendl; 1017 //odebug << "New incomming connection" << oendl;
1019 1018
1020 if ( !passiv ) return; 1019 if ( !passiv ) return;
1021 1020
1022 if ( wait[SendFile] ) { 1021 if ( wait[SendFile] ) {
1023 QStringList targets; 1022 QStringList targets;
1024 if ( backupRestoreGzip( waitfile, targets ) ) 1023 if ( backupRestoreGzip( waitfile, targets ) )
1025 dtp->sendGzipFile( waitfile, targets ); 1024 dtp->sendGzipFile( waitfile, targets );
1026 else 1025 else
1027 dtp->sendFile( waitfile ); 1026 dtp->sendFile( waitfile );
1028 dtp->setSocket( socket ); 1027 dtp->setSocket( socket );
1029 } 1028 }
1030 else if ( wait[RetrieveFile] ) { 1029 else if ( wait[RetrieveFile] ) {
1031 odebug << "check retrieve file" << oendl; 1030 odebug << "check retrieve file" << oendl;
1032 if ( backupRestoreGzip( waitfile ) ) 1031 if ( backupRestoreGzip( waitfile ) )
1033 dtp->retrieveGzipFile( waitfile ); 1032 dtp->retrieveGzipFile( waitfile );
1034 else 1033 else
1035 dtp->retrieveFile( waitfile, storFileSize ); 1034 dtp->retrieveFile( waitfile, storFileSize );
1036 dtp->setSocket( socket ); 1035 dtp->setSocket( socket );
1037 } 1036 }
1038 else if ( wait[SendByteArray] ) { 1037 else if ( wait[SendByteArray] ) {
1039 dtp->sendByteArray( waitarray ); 1038 dtp->sendByteArray( waitarray );
1040 dtp->setSocket( socket ); 1039 dtp->setSocket( socket );
1041 } 1040 }
1042 else if ( wait[RetrieveByteArray] ) { 1041 else if ( wait[RetrieveByteArray] ) {
1043 odebug << "retrieve byte array" << oendl; 1042 odebug << "retrieve byte array" << oendl;
1044 dtp->retrieveByteArray(); 1043 dtp->retrieveByteArray();
1045 dtp->setSocket( socket ); 1044 dtp->setSocket( socket );
1046 } 1045 }
1047 else 1046 else
1048 waitsocket = socket; 1047 waitsocket = socket;
1049 1048
1050 for( int i = 0; i < 4; i++ ) 1049 for( int i = 0; i < 4; i++ )
1051 wait[i] = FALSE; 1050 wait[i] = FALSE;
1052} 1051}
1053 1052
1054QString ServerPI::absFilePath( const QString& file ) 1053QString ServerPI::absFilePath( const QString& file )
1055{ 1054{
1056 if ( file.isEmpty() ) return file; 1055 if ( file.isEmpty() ) return file;
1057 1056
1058 QString filepath( file ); 1057 QString filepath( file );
1059 if ( file[0] != "/" ) 1058 if ( file[0] != "/" )
1060 filepath = directory.path() + "/" + file; 1059 filepath = directory.path() + "/" + file;
1061 1060
1062 return filepath; 1061 return filepath;
1063} 1062}
1064 1063
1065 1064
1066void ServerPI::timerEvent( QTimerEvent * ) 1065void ServerPI::timerEvent( QTimerEvent * )
@@ -1085,29 +1084,29 @@ ServerDTP::ServerDTP( QObject *parent, const char* name)
1085 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); 1084 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) );
1086 1085
1087 retrieveTargzProc = new QProcess( this, "retrieveTargzProc" ); 1086 retrieveTargzProc = new QProcess( this, "retrieveTargzProc" );
1088 retrieveTargzProc->setCommunication( QProcess::Stdin ); 1087 retrieveTargzProc->setCommunication( QProcess::Stdin );
1089 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1088 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1090 connect( retrieveTargzProc, SIGNAL( processExited() ), 1089 connect( retrieveTargzProc, SIGNAL( processExited() ),
1091 SIGNAL( completed() ) ); 1090 SIGNAL( completed() ) );
1092 connect( retrieveTargzProc, SIGNAL( processExited() ), 1091 connect( retrieveTargzProc, SIGNAL( processExited() ),
1093 SLOT( extractTarDone() ) ); 1092 SLOT( extractTarDone() ) );
1094} 1093}
1095 1094
1096ServerDTP::~ServerDTP() 1095ServerDTP::~ServerDTP()
1097{ 1096{
1098 buf.close(); 1097 buf.close();
1099 if ( RetrieveFile == mode && file.isOpen() ) { 1098 if ( RetrieveFile == mode && file.isOpen() ) {
1100 // We're being shutdown before the client closed. 1099 // We're being shutdown before the client closed.
1101 file.close(); 1100 file.close();
1102 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { 1101 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) {
1103 odebug << "STOR incomplete" << oendl; 1102 odebug << "STOR incomplete" << oendl;
1104 file.remove(); 1103 file.remove();
1105 } 1104 }
1106 } else { 1105 } else {
1107 file.close(); 1106 file.close();
1108 } 1107 }
1109 createTargzProc->kill(); 1108 createTargzProc->kill();
1110} 1109}
1111 1110
1112void ServerDTP::extractTarDone() 1111void ServerDTP::extractTarDone()
1113{ 1112{
@@ -1137,16 +1136,16 @@ void ServerDTP::connected()
1137 file.close(); 1136 file.close();
1138 emit completed(); 1137 emit completed();
1139 mode = Idle; 1138 mode = Idle;
1140 } else { 1139 } else {
1141 // Don't write more if there is plenty buffered already. 1140 // Don't write more if there is plenty buffered already.
1142 if ( bytesToWrite() <= block_size && !file.atEnd() ) { 1141 if ( bytesToWrite() <= block_size && !file.atEnd() ) {
1143 QCString s; 1142 QCString s;
1144 s.resize( block_size ); 1143 s.resize( block_size );
1145 int bytes = file.readBlock( s.data(), block_size ); 1144 int bytes = file.readBlock( s.data(), block_size );
1146 writeBlock( s.data(), bytes ); 1145 writeBlock( s.data(), bytes );
1147 } 1146 }
1148 } 1147 }
1149 break; 1148 break;
1150 case SendGzipFile: 1149 case SendGzipFile:
1151 if ( createTargzProc->isRunning() ) { 1150 if ( createTargzProc->isRunning() ) {
1152 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY 1151 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY
@@ -1155,13 +1154,13 @@ void ServerDTP::connected()
1155 } 1154 }
1156 1155
1157 bytes_written = 0; 1156 bytes_written = 0;
1158 odebug << "==>start send tar process" << oendl; 1157 odebug << "==>start send tar process" << oendl;
1159 if ( !createTargzProc->start() ) 1158 if ( !createTargzProc->start() )
1160 qWarning("Error starting %s", 1159 qWarning("Error starting %s",
1161 createTargzProc->arguments().join(" ").latin1()); 1160 createTargzProc->arguments().join(" ").latin1());
1162 break; 1161 break;
1163 case SendBuffer: 1162 case SendBuffer:
1164 if ( !buf.open( IO_ReadOnly) ) { 1163 if ( !buf.open( IO_ReadOnly) ) {
1165 emit failed(); 1164 emit failed();
1166 mode = Idle; 1165 mode = Idle;
1167 return; 1166 return;
@@ -1209,110 +1208,110 @@ void ServerDTP::connected()
1209void ServerDTP::connectionClosed() 1208void ServerDTP::connectionClosed()
1210{ 1209{
1211 //odebug << "Debug: Data connection closed " << bytes_written << " bytes written" << oendl; 1210 //odebug << "Debug: Data connection closed " << bytes_written << " bytes written" << oendl;
1212 1211
1213 // send file mode 1212 // send file mode
1214 if ( SendFile == mode ) { 1213 if ( SendFile == mode ) {
1215 if ( bytes_written == file.size() ) 1214 if ( bytes_written == file.size() )
1216 emit completed(); 1215 emit completed();
1217 else 1216 else
1218 emit failed(); 1217 emit failed();
1219 } 1218 }
1220 1219
1221 // send buffer mode 1220 // send buffer mode
1222 else if ( SendBuffer == mode ) { 1221 else if ( SendBuffer == mode ) {
1223 if ( bytes_written == buf.size() ) 1222 if ( bytes_written == buf.size() )
1224 emit completed(); 1223 emit completed();
1225 else 1224 else
1226 emit failed(); 1225 emit failed();
1227 } 1226 }
1228 1227
1229 // retrieve file mode 1228 // retrieve file mode
1230 else if ( RetrieveFile == mode ) { 1229 else if ( RetrieveFile == mode ) {
1231 file.close(); 1230 file.close();
1232 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { 1231 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) {
1233 odebug << "STOR incomplete" << oendl; 1232 odebug << "STOR incomplete" << oendl;
1234 file.remove(); 1233 file.remove();
1235 emit failed(); 1234 emit failed();
1236 } else { 1235 } else {
1237 emit completed(); 1236 emit completed();
1238 } 1237 }
1239 } 1238 }
1240 1239
1241 else if ( RetrieveGzipFile == mode ) { 1240 else if ( RetrieveGzipFile == mode ) {
1242 odebug << "Done writing ungzip file; closing input" << oendl; 1241 odebug << "Done writing ungzip file; closing input" << oendl;
1243 retrieveTargzProc->flushStdin(); 1242 retrieveTargzProc->flushStdin();
1244 retrieveTargzProc->closeStdin(); 1243 retrieveTargzProc->closeStdin();
1245 } 1244 }
1246 1245
1247 // retrieve buffer mode 1246 // retrieve buffer mode
1248 else if ( RetrieveBuffer == mode ) { 1247 else if ( RetrieveBuffer == mode ) {
1249 buf.close(); 1248 buf.close();
1250 emit completed(); 1249 emit completed();
1251 } 1250 }
1252 1251
1253 mode = Idle; 1252 mode = Idle;
1254} 1253}
1255 1254
1256void ServerDTP::bytesWritten( int bytes ) 1255void ServerDTP::bytesWritten( int bytes )
1257{ 1256{
1258 bytes_written += bytes; 1257 bytes_written += bytes;
1259 1258
1260 // send file mode 1259 // send file mode
1261 if ( SendFile == mode ) { 1260 if ( SendFile == mode ) {
1262 1261
1263 if ( bytes_written == file.size() ) { 1262 if ( bytes_written == file.size() ) {
1264 // odebug << "Debug: Sending complete: " << file.size() << " bytes" << oendl; 1263 // odebug << "Debug: Sending complete: " << file.size() << " bytes" << oendl;
1265 file.close(); 1264 file.close();
1266 emit completed(); 1265 emit completed();
1267 mode = Idle; 1266 mode = Idle;
1268 } 1267 }
1269 else if( !file.atEnd() ) { 1268 else if( !file.atEnd() ) {
1270 QCString s; 1269 QCString s;
1271 s.resize( block_size ); 1270 s.resize( block_size );
1272 int bytes = file.readBlock( s.data(), block_size ); 1271 int bytes = file.readBlock( s.data(), block_size );
1273 writeBlock( s.data(), bytes ); 1272 writeBlock( s.data(), bytes );
1274 } 1273 }
1275 } 1274 }
1276 1275
1277 // send buffer mode 1276 // send buffer mode
1278 if ( SendBuffer == mode ) { 1277 if ( SendBuffer == mode ) {
1279 1278
1280 if ( bytes_written == buf.size() ) { 1279 if ( bytes_written == buf.size() ) {
1281 // odebug << "Debug: Sending complete: " << buf.size() << " bytes" << oendl; 1280 // odebug << "Debug: Sending complete: " << buf.size() << " bytes" << oendl;
1282 emit completed(); 1281 emit completed();
1283 mode = Idle; 1282 mode = Idle;
1284 } 1283 }
1285 } 1284 }
1286} 1285}
1287 1286
1288void ServerDTP::readyRead() 1287void ServerDTP::readyRead()
1289{ 1288{
1290 // retrieve file mode 1289 // retrieve file mode
1291 if ( RetrieveFile == mode ) { 1290 if ( RetrieveFile == mode ) {
1292 QCString s; 1291 QCString s;
1293 s.resize( bytesAvailable() ); 1292 s.resize( bytesAvailable() );
1294 readBlock( s.data(), bytesAvailable() ); 1293 readBlock( s.data(), bytesAvailable() );
1295 file.writeBlock( s.data(), s.size() ); 1294 file.writeBlock( s.data(), s.size() );
1296 } 1295 }
1297 else if ( RetrieveGzipFile == mode ) { 1296 else if ( RetrieveGzipFile == mode ) {
1298 if ( !retrieveTargzProc->isRunning() ) 1297 if ( !retrieveTargzProc->isRunning() )
1299 retrieveTargzProc->start(); 1298 retrieveTargzProc->start();
1300 1299
1301 QByteArray s; 1300 QByteArray s;
1302 s.resize( bytesAvailable() ); 1301 s.resize( bytesAvailable() );
1303 readBlock( s.data(), bytesAvailable() ); 1302 readBlock( s.data(), bytesAvailable() );
1304 retrieveTargzProc->writeToStdin( s ); 1303 retrieveTargzProc->writeToStdin( s );
1305 odebug << "wrote " << s.size() << " bytes to ungzip " << oendl; 1304 odebug << "wrote " << s.size() << " bytes to ungzip " << oendl;
1306 } 1305 }
1307 // retrieve buffer mode 1306 // retrieve buffer mode
1308 else if ( RetrieveBuffer == mode ) { 1307 else if ( RetrieveBuffer == mode ) {
1309 QCString s; 1308 QCString s;
1310 s.resize( bytesAvailable() ); 1309 s.resize( bytesAvailable() );
1311 readBlock( s.data(), bytesAvailable() ); 1310 readBlock( s.data(), bytesAvailable() );
1312 buf.writeBlock( s.data(), s.size() ); 1311 buf.writeBlock( s.data(), s.size() );
1313 } 1312 }
1314} 1313}
1315 1314
1316void ServerDTP::writeTargzBlock() 1315void ServerDTP::writeTargzBlock()
1317{ 1316{
1318 QByteArray block = createTargzProc->readStdout(); 1317 QByteArray block = createTargzProc->readStdout();
@@ -1323,13 +1322,13 @@ void ServerDTP::writeTargzBlock()
1323void ServerDTP::targzDone() 1322void ServerDTP::targzDone()
1324{ 1323{
1325 odebug << "tar and gzip done" << oendl; 1324 odebug << "tar and gzip done" << oendl;
1326 emit completed(); 1325 emit completed();
1327 mode = Idle; 1326 mode = Idle;
1328 disconnect( createTargzProc, SIGNAL( readyReadStdout() ), 1327 disconnect( createTargzProc, SIGNAL( readyReadStdout() ),
1329 this, SLOT( writeTargzBlock() ) ); 1328 this, SLOT( writeTargzBlock() ) );
1330} 1329}
1331 1330
1332void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) 1331void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port )
1333{ 1332{
1334 file.setName( fn ); 1333 file.setName( fn );
1335 mode = SendFile; 1334 mode = SendFile;
@@ -1340,32 +1339,32 @@ void ServerDTP::sendFile( const QString fn )
1340{ 1339{
1341 file.setName( fn ); 1340 file.setName( fn );
1342 mode = SendFile; 1341 mode = SendFile;
1343} 1342}
1344 1343
1345void ServerDTP::sendGzipFile( const QString &fn, 1344void ServerDTP::sendGzipFile( const QString &fn,
1346 const QStringList &archiveTargets, 1345 const QStringList &archiveTargets,
1347 const QHostAddress& host, Q_UINT16 port ) 1346 const QHostAddress& host, Q_UINT16 port )
1348{ 1347{
1349 sendGzipFile( fn, archiveTargets ); 1348 sendGzipFile( fn, archiveTargets );
1350 connectToHost( host.toString(), port ); 1349 connectToHost( host.toString(), port );
1351} 1350}
1352 1351
1353void ServerDTP::sendGzipFile( const QString &fn, 1352void ServerDTP::sendGzipFile( const QString &fn,
1354 const QStringList &archiveTargets ) 1353 const QStringList &archiveTargets )
1355{ 1354{
1356 mode = SendGzipFile; 1355 mode = SendGzipFile;
1357 file.setName( fn ); 1356 file.setName( fn );
1358 1357
1359 QStringList args = "targzip"; 1358 QStringList args = "targzip";
1360 //args += "-cv"; 1359 //args += "-cv";
1361 args += archiveTargets; 1360 args += archiveTargets;
1362 odebug << "sendGzipFile " << args.join(" ") << "" << oendl; 1361 odebug << "sendGzipFile " << args.join(" ") << "" << oendl;
1363 createTargzProc->setArguments( args ); 1362 createTargzProc->setArguments( args );
1364 connect( createTargzProc, 1363 connect( createTargzProc,
1365 SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); 1364 SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) );
1366} 1365}
1367 1366
1368void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize ) 1367void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize )
1369{ 1368{
1370 recvFileSize = fileSize; 1369 recvFileSize = fileSize;
1371 file.setName( fn ); 1370 file.setName( fn );
@@ -1385,13 +1384,13 @@ void ServerDTP::retrieveGzipFile( const QString &fn )
1385 odebug << "retrieveGzipFile " << fn << "" << oendl; 1384 odebug << "retrieveGzipFile " << fn << "" << oendl;
1386 file.setName( fn ); 1385 file.setName( fn );
1387 mode = RetrieveGzipFile; 1386 mode = RetrieveGzipFile;
1388 1387
1389 retrieveTargzProc->setArguments( "targunzip" ); 1388 retrieveTargzProc->setArguments( "targunzip" );
1390 connect( retrieveTargzProc, SIGNAL( processExited() ), 1389 connect( retrieveTargzProc, SIGNAL( processExited() ),
1391 SLOT( extractTarDone() ) ); 1390 SLOT( extractTarDone() ) );
1392} 1391}
1393 1392
1394void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) 1393void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port )
1395{ 1394{
1396 retrieveGzipFile( fn ); 1395 retrieveGzipFile( fn );
1397 connectToHost( host.toString(), port ); 1396 connectToHost( host.toString(), port );