summaryrefslogtreecommitdiff
authorzecke <zecke>2002-07-12 13:51:37 (UTC)
committer zecke <zecke>2002-07-12 13:51:37 (UTC)
commit716211b5e06bb25145cfbcf62a11a7c52c79dde5 (patch) (unidiff)
tree595c4c15cb0ca31f2579be42ee029c1c30454b9c
parent7c12000481b535ce54951ef8a53b439814f8fcd6 (diff)
downloadopie-716211b5e06bb25145cfbcf62a11a7c52c79dde5.zip
opie-716211b5e06bb25145cfbcf62a11a7c52c79dde5.tar.gz
opie-716211b5e06bb25145cfbcf62a11a7c52c79dde5.tar.bz2
Security fix by trolltech
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/desktop.cpp4
-rw-r--r--core/launcher/launcher.pro2
-rw-r--r--core/launcher/qcopbridge.cpp424
-rw-r--r--core/launcher/qcopbridge.h7
-rw-r--r--core/launcher/transferserver.cpp213
-rw-r--r--core/launcher/transferserver.h23
6 files changed, 392 insertions, 281 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp
index 24dce73..541b4be 100644
--- a/core/launcher/desktop.cpp
+++ b/core/launcher/desktop.cpp
@@ -185,606 +185,606 @@ enum MemState { Unknown, VeryLow, Low, Normal } memstate=Unknown;
185 185
186#ifdef Q_WS_QWS 186#ifdef Q_WS_QWS
187bool DesktopApplication::qwsEventFilter( QWSEvent *e ) 187bool DesktopApplication::qwsEventFilter( QWSEvent *e )
188{ 188{
189 qpedesktop->checkMemory(); 189 qpedesktop->checkMemory();
190 190
191 if ( e->type == QWSEvent::Key ) { 191 if ( e->type == QWSEvent::Key ) {
192 QWSKeyEvent *ke = (QWSKeyEvent *)e; 192 QWSKeyEvent *ke = (QWSKeyEvent *)e;
193 if ( !loggedin && ke->simpleData.keycode != Key_F34 ) 193 if ( !loggedin && ke->simpleData.keycode != Key_F34 )
194 return TRUE; 194 return TRUE;
195 bool press = ke->simpleData.is_press; 195 bool press = ke->simpleData.is_press;
196 bool autoRepeat= ke->simpleData.is_auto_repeat; 196 bool autoRepeat= ke->simpleData.is_auto_repeat;
197 197
198 /* 198 /*
199 app that registers key/message to be sent back to the app, when it doesn't have focus, 199 app that registers key/message to be sent back to the app, when it doesn't have focus,
200 when user presses key, unless keyboard has been requested from app. 200 when user presses key, unless keyboard has been requested from app.
201 will not send multiple repeats if user holds key 201 will not send multiple repeats if user holds key
202 i.e. one shot 202 i.e. one shot
203 203
204 */ 204 */
205 if (!keyRegisterList.isEmpty()) { 205 if (!keyRegisterList.isEmpty()) {
206 KeyRegisterList::Iterator it; 206 KeyRegisterList::Iterator it;
207 for( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { 207 for( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) {
208 if ((*it).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed()) { 208 if ((*it).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed()) {
209 if(press) qDebug("press"); else qDebug("release"); 209 if(press) qDebug("press"); else qDebug("release");
210 QCopEnvelope((*it).getChannel().utf8(), (*it).getMessage().utf8()); 210 QCopEnvelope((*it).getChannel().utf8(), (*it).getMessage().utf8());
211 } 211 }
212 } 212 }
213 } 213 }
214 214
215 if ( !keyboardGrabbed() ) { 215 if ( !keyboardGrabbed() ) {
216 if ( ke->simpleData.keycode == Key_F9 ) { 216 if ( ke->simpleData.keycode == Key_F9 ) {
217 if ( press ) emit datebook(); 217 if ( press ) emit datebook();
218 return TRUE; 218 return TRUE;
219 } 219 }
220 if ( ke->simpleData.keycode == Key_F10 ) { 220 if ( ke->simpleData.keycode == Key_F10 ) {
221 if ( !press && cardSendTimer ) { 221 if ( !press && cardSendTimer ) {
222 emit contacts(); 222 emit contacts();
223 delete cardSendTimer; 223 delete cardSendTimer;
224 } else if ( press ) { 224 } else if ( press ) {
225 cardSendTimer = new QTimer(); 225 cardSendTimer = new QTimer();
226 cardSendTimer->start( 2000, TRUE ); 226 cardSendTimer->start( 2000, TRUE );
227 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); 227 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) );
228 } 228 }
229 return TRUE; 229 return TRUE;
230 } 230 }
231 /* menu key now opens application menu/toolbar 231 /* menu key now opens application menu/toolbar
232 if ( ke->simpleData.keycode == Key_F11 ) { 232 if ( ke->simpleData.keycode == Key_F11 ) {
233 if ( press ) emit menu(); 233 if ( press ) emit menu();
234 return TRUE; 234 return TRUE;
235 } 235 }
236 */ 236 */
237 if ( ke->simpleData.keycode == Key_F12 ) { 237 if ( ke->simpleData.keycode == Key_F12 ) {
238 while( activePopupWidget() ) 238 while( activePopupWidget() )
239 activePopupWidget()->close(); 239 activePopupWidget()->close();
240 if ( press ) emit launch(); 240 if ( press ) emit launch();
241 return TRUE; 241 return TRUE;
242 } 242 }
243 if ( ke->simpleData.keycode == Key_F13 ) { 243 if ( ke->simpleData.keycode == Key_F13 ) {
244 if ( press ) emit email(); 244 if ( press ) emit email();
245 return TRUE; 245 return TRUE;
246 } 246 }
247 } 247 }
248 248
249 if ( ke->simpleData.keycode == Key_F34 ) { 249 if ( ke->simpleData.keycode == Key_F34 ) {
250 if ( press ) emit power(); 250 if ( press ) emit power();
251 return TRUE; 251 return TRUE;
252 } 252 }
253// This was used for the iPAQ PowerButton 253// This was used for the iPAQ PowerButton
254// See main.cpp for new KeyboardFilter 254// See main.cpp for new KeyboardFilter
255// 255//
256// if ( ke->simpleData.keycode == Key_SysReq ) { 256// if ( ke->simpleData.keycode == Key_SysReq ) {
257// if ( press ) emit power(); 257// if ( press ) emit power();
258// return TRUE; 258// return TRUE;
259// } 259// }
260 if ( ke->simpleData.keycode == Key_F35 ) { 260 if ( ke->simpleData.keycode == Key_F35 ) {
261 if ( press ) emit backlight(); 261 if ( press ) emit backlight();
262 return TRUE; 262 return TRUE;
263 } 263 }
264 if ( ke->simpleData.keycode == Key_F32 ) { 264 if ( ke->simpleData.keycode == Key_F32 ) {
265 if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" ); 265 if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" );
266 return TRUE; 266 return TRUE;
267 } 267 }
268 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { 268 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) {
269 if ( press ) emit symbol(); 269 if ( press ) emit symbol();
270 return TRUE; 270 return TRUE;
271 } 271 }
272 if ( ke->simpleData.keycode == Key_NumLock ) { 272 if ( ke->simpleData.keycode == Key_NumLock ) {
273 if ( press ) emit numLockStateToggle(); 273 if ( press ) emit numLockStateToggle();
274 } 274 }
275 if ( ke->simpleData.keycode == Key_CapsLock ) { 275 if ( ke->simpleData.keycode == Key_CapsLock ) {
276 if ( press ) emit capsLockStateToggle(); 276 if ( press ) emit capsLockStateToggle();
277 } 277 }
278 if (( press && !autoRepeat ) || ( !press && autoRepeat )) 278 if (( press && !autoRepeat ) || ( !press && autoRepeat ))
279 qpedesktop->keyClick(); 279 qpedesktop->keyClick();
280 } else { 280 } else {
281 if ( e->type == QWSEvent::Mouse ) { 281 if ( e->type == QWSEvent::Mouse ) {
282 QWSMouseEvent *me = (QWSMouseEvent *)e; 282 QWSMouseEvent *me = (QWSMouseEvent *)e;
283 static bool up = TRUE; 283 static bool up = TRUE;
284 if ( me->simpleData.state&LeftButton ) { 284 if ( me->simpleData.state&LeftButton ) {
285 if ( up ) { 285 if ( up ) {
286 up = FALSE; 286 up = FALSE;
287 qpedesktop->screenClick(); 287 qpedesktop->screenClick();
288 } 288 }
289 } else { 289 } else {
290 up = TRUE; 290 up = TRUE;
291 } 291 }
292 } 292 }
293 } 293 }
294 294
295 return QPEApplication::qwsEventFilter( e ); 295 return QPEApplication::qwsEventFilter( e );
296} 296}
297#endif 297#endif
298 298
299void DesktopApplication::psTimeout() 299void DesktopApplication::psTimeout()
300{ 300{
301 qpedesktop->checkMemory(); // in case no events are being generated 301 qpedesktop->checkMemory(); // in case no events are being generated
302 302
303 *ps = PowerStatusManager::readStatus(); 303 *ps = PowerStatusManager::readStatus();
304 304
305 if ( (ps->batteryStatus() == PowerStatus::VeryLow ) ) { 305 if ( (ps->batteryStatus() == PowerStatus::VeryLow ) ) {
306 pa->alert( tr( "Battery is running very low." ), 6 ); 306 pa->alert( tr( "Battery is running very low." ), 6 );
307 } 307 }
308 308
309 if ( ps->batteryStatus() == PowerStatus::Critical ) { 309 if ( ps->batteryStatus() == PowerStatus::Critical ) {
310 pa->alert( tr( "Battery level is critical!\n" 310 pa->alert( tr( "Battery level is critical!\n"
311 "Keep power off until power restored!" ), 1 ); 311 "Keep power off until power restored!" ), 1 );
312 } 312 }
313 313
314 if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) { 314 if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) {
315 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 ); 315 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 );
316 } 316 }
317} 317}
318 318
319 319
320void DesktopApplication::sendCard() 320void DesktopApplication::sendCard()
321{ 321{
322 delete cardSendTimer; 322 delete cardSendTimer;
323 cardSendTimer = 0; 323 cardSendTimer = 0;
324 QString card = getenv("HOME"); 324 QString card = getenv("HOME");
325 card += "/Applications/addressbook/businesscard.vcf"; 325 card += "/Applications/addressbook/businesscard.vcf";
326 326
327 if ( QFile::exists( card ) ) { 327 if ( QFile::exists( card ) ) {
328 QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)"); 328 QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)");
329 QString mimetype = "text/x-vCard"; 329 QString mimetype = "text/x-vCard";
330 e << tr("business card") << card << mimetype; 330 e << tr("business card") << card << mimetype;
331 } 331 }
332} 332}
333 333
334#if defined(QPE_HAVE_MEMALERTER) 334#if defined(QPE_HAVE_MEMALERTER)
335QPE_MEMALERTER_IMPL 335QPE_MEMALERTER_IMPL
336#endif 336#endif
337 337
338//=========================================================================== 338//===========================================================================
339 339
340Desktop::Desktop() : 340Desktop::Desktop() :
341 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), 341 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ),
342 qcopBridge( 0 ), 342 qcopBridge( 0 ),
343 transferServer( 0 ), 343 transferServer( 0 ),
344 packageSlave( 0 ) 344 packageSlave( 0 )
345{ 345{
346 qpedesktop = this; 346 qpedesktop = this;
347 347
348// bg = new Info( this ); 348// bg = new Info( this );
349 tb = new TaskBar; 349 tb = new TaskBar;
350 350
351 launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader ); 351 launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader );
352 352
353 connect(launcher, SIGNAL(busy()), tb, SLOT(startWait())); 353 connect(launcher, SIGNAL(busy()), tb, SLOT(startWait()));
354 connect(launcher, SIGNAL(notBusy(const QString&)), tb, SLOT(stopWait(const QString&))); 354 connect(launcher, SIGNAL(notBusy(const QString&)), tb, SLOT(stopWait(const QString&)));
355 355
356 int displayw = qApp->desktop()->width(); 356 int displayw = qApp->desktop()->width();
357 int displayh = qApp->desktop()->height(); 357 int displayh = qApp->desktop()->height();
358 358
359 359
360 QSize sz = tb->sizeHint(); 360 QSize sz = tb->sizeHint();
361 361
362 setGeometry( 0, displayh-sz.height(), displayw, sz.height() ); 362 setGeometry( 0, displayh-sz.height(), displayw, sz.height() );
363 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() ); 363 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() );
364 364
365 tb->show(); 365 tb->show();
366 launcher->showMaximized(); 366 launcher->showMaximized();
367 launcher->show(); 367 launcher->show();
368 launcher->raise(); 368 launcher->raise();
369#if defined(QPE_HAVE_MEMALERTER) 369#if defined(QPE_HAVE_MEMALERTER)
370 initMemalerter(); 370 initMemalerter();
371#endif 371#endif
372 // start services 372 // start services
373 startTransferServer(); 373 startTransferServer();
374 (void) new IrServer( this ); 374 (void) new IrServer( this );
375 rereadVolumes(); 375 rereadVolumes();
376 376
377 packageSlave = new PackageSlave( this ); 377 packageSlave = new PackageSlave( this );
378 connect(qApp, SIGNAL(volumeChanged(bool)), this, SLOT(rereadVolumes())); 378 connect(qApp, SIGNAL(volumeChanged(bool)), this, SLOT(rereadVolumes()));
379 379
380 qApp->installEventFilter( this ); 380 qApp->installEventFilter( this );
381} 381}
382 382
383void Desktop::show() 383void Desktop::show()
384{ 384{
385 login(TRUE); 385 login(TRUE);
386 QWidget::show(); 386 QWidget::show();
387} 387}
388 388
389Desktop::~Desktop() 389Desktop::~Desktop()
390{ 390{
391 delete launcher; 391 delete launcher;
392 delete tb; 392 delete tb;
393 delete qcopBridge; 393 delete qcopBridge;
394 delete transferServer; 394 delete transferServer;
395} 395}
396 396
397bool Desktop::recoverMemory() 397bool Desktop::recoverMemory()
398{ 398{
399 return tb->recoverMemory(); 399 return tb->recoverMemory();
400} 400}
401 401
402void Desktop::checkMemory() 402void Desktop::checkMemory()
403{ 403{
404#if defined(QPE_HAVE_MEMALERTER) 404#if defined(QPE_HAVE_MEMALERTER)
405 static bool ignoreNormal=FALSE; 405 static bool ignoreNormal=FALSE;
406 static bool existingMessage=FALSE; 406 static bool existingMessage=FALSE;
407 407
408 if(existingMessage) 408 if(existingMessage)
409 return; // don't show a second message while still on first 409 return; // don't show a second message while still on first
410 410
411 existingMessage = TRUE; 411 existingMessage = TRUE;
412 switch ( memstate ) { 412 switch ( memstate ) {
413 case Unknown: 413 case Unknown:
414 break; 414 break;
415 case Low: 415 case Low:
416 memstate = Unknown; 416 memstate = Unknown;
417 if ( recoverMemory() ) 417 if ( recoverMemory() )
418 ignoreNormal = TRUE; 418 ignoreNormal = TRUE;
419 else 419 else
420 QMessageBox::warning( 0 , "Memory Status", 420 QMessageBox::warning( 0 , "Memory Status",
421 "The memory smacks of shortage. \n" 421 "The memory smacks of shortage. \n"
422 "Please save data. " ); 422 "Please save data. " );
423 break; 423 break;
424 case Normal: 424 case Normal:
425 memstate = Unknown; 425 memstate = Unknown;
426 if ( ignoreNormal ) 426 if ( ignoreNormal )
427 ignoreNormal = FALSE; 427 ignoreNormal = FALSE;
428 else 428 else
429 QMessageBox::information ( 0 , "Memory Status", 429 QMessageBox::information ( 0 , "Memory Status",
430 "There is enough memory again." ); 430 "There is enough memory again." );
431 break; 431 break;
432 case VeryLow: 432 case VeryLow:
433 memstate = Unknown; 433 memstate = Unknown;
434 QMessageBox::critical( 0 , "Memory Status", 434 QMessageBox::critical( 0 , "Memory Status",
435 "The memory is very low. \n" 435 "The memory is very low. \n"
436 "Please end this application \n" 436 "Please end this application \n"
437 "immediately." ); 437 "immediately." );
438 recoverMemory(); 438 recoverMemory();
439 } 439 }
440 existingMessage = FALSE; 440 existingMessage = FALSE;
441#endif 441#endif
442} 442}
443 443
444static bool isVisibleWindow(int wid) 444static bool isVisibleWindow(int wid)
445{ 445{
446 const QList<QWSWindow> &list = qwsServer->clientWindows(); 446 const QList<QWSWindow> &list = qwsServer->clientWindows();
447 QWSWindow* w; 447 QWSWindow* w;
448 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { 448 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
449 if ( w->winId() == wid ) 449 if ( w->winId() == wid )
450 return !w->isFullyObscured(); 450 return !w->isFullyObscured();
451 } 451 }
452 return FALSE; 452 return FALSE;
453} 453}
454 454
455static bool hasVisibleWindow(const QString& clientname) 455static bool hasVisibleWindow(const QString& clientname)
456{ 456{
457 const QList<QWSWindow> &list = qwsServer->clientWindows(); 457 const QList<QWSWindow> &list = qwsServer->clientWindows();
458 QWSWindow* w; 458 QWSWindow* w;
459 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { 459 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
460 if ( w->client()->identity() == clientname && !w->isFullyObscured() ) 460 if ( w->client()->identity() == clientname && !w->isFullyObscured() )
461 return TRUE; 461 return TRUE;
462 } 462 }
463 return FALSE; 463 return FALSE;
464} 464}
465 465
466void Desktop::raiseLauncher() 466void Desktop::raiseLauncher()
467{ 467{
468 Config cfg("qpe"); //F12 'Home' 468 Config cfg("qpe"); //F12 'Home'
469 cfg.setGroup("AppsKey"); 469 cfg.setGroup("AppsKey");
470 QString tempItem; 470 QString tempItem;
471 tempItem = cfg.readEntry("Middle","Home"); 471 tempItem = cfg.readEntry("Middle","Home");
472 if(tempItem == "Home" || tempItem.isEmpty()) { 472 if(tempItem == "Home" || tempItem.isEmpty()) {
473 if ( isVisibleWindow(launcher->winId()) ) 473 if ( isVisibleWindow(launcher->winId()) )
474 launcher->nextView(); 474 launcher->nextView();
475 else 475 else
476 launcher->raise(); 476 launcher->raise();
477 } else { 477 } else {
478 QCopEnvelope e("QPE/System","execute(QString)"); 478 QCopEnvelope e("QPE/System","execute(QString)");
479 e << tempItem; 479 e << tempItem;
480 } 480 }
481} 481}
482 482
483void Desktop::executeOrModify(const QString& appLnkFile) 483void Desktop::executeOrModify(const QString& appLnkFile)
484{ 484{
485 AppLnk lnk(MimeType::appsFolderName() + "/" + appLnkFile); 485 AppLnk lnk(MimeType::appsFolderName() + "/" + appLnkFile);
486 if ( lnk.isValid() ) { 486 if ( lnk.isValid() ) {
487 QCString app = lnk.exec().utf8(); 487 QCString app = lnk.exec().utf8();
488 Global::terminateBuiltin("calibrate"); 488 Global::terminateBuiltin("calibrate");
489 if ( QCopChannel::isRegistered("QPE/Application/" + app) ) { 489 if ( QCopChannel::isRegistered("QPE/Application/" + app) ) {
490 MRUList::addTask(&lnk); 490 MRUList::addTask(&lnk);
491 if ( hasVisibleWindow(app) ) 491 if ( hasVisibleWindow(app) )
492 QCopChannel::send("QPE/Application/" + app, "nextView()"); 492 QCopChannel::send("QPE/Application/" + app, "nextView()");
493 else 493 else
494 QCopChannel::send("QPE/Application/" + app, "raise()"); 494 QCopChannel::send("QPE/Application/" + app, "raise()");
495 } else { 495 } else {
496 lnk.execute(); 496 lnk.execute();
497 } 497 }
498 } 498 }
499} 499}
500 500
501void Desktop::raiseDatebook() 501void Desktop::raiseDatebook()
502{ 502{
503 Config cfg("qpe"); //F9 'Activity' 503 Config cfg("qpe"); //F9 'Activity'
504 cfg.setGroup("AppsKey"); 504 cfg.setGroup("AppsKey");
505 QString tempItem; 505 QString tempItem;
506 tempItem = cfg.readEntry("LeftEnd","Calender"); 506 tempItem = cfg.readEntry("LeftEnd","Calender");
507 if(tempItem == "Calender" || tempItem.isEmpty()) executeOrModify("Applications/datebook.desktop"); 507 if(tempItem == "Calender" || tempItem.isEmpty()) executeOrModify("Applications/datebook.desktop");
508 else { 508 else {
509 QCopEnvelope e("QPE/System","execute(QString)"); 509 QCopEnvelope e("QPE/System","execute(QString)");
510 e << tempItem; 510 e << tempItem;
511 } 511 }
512} 512}
513 513
514void Desktop::raiseContacts() 514void Desktop::raiseContacts()
515{ 515{
516 Config cfg("qpe"); //F10, 'Contacts' 516 Config cfg("qpe"); //F10, 'Contacts'
517 cfg.setGroup("AppsKey"); 517 cfg.setGroup("AppsKey");
518 QString tempItem; 518 QString tempItem;
519 tempItem = cfg.readEntry("Left2nd","Address Book"); 519 tempItem = cfg.readEntry("Left2nd","Address Book");
520 if(tempItem == "Address Book" || tempItem.isEmpty()) executeOrModify("Applications/addressbook.desktop"); 520 if(tempItem == "Address Book" || tempItem.isEmpty()) executeOrModify("Applications/addressbook.desktop");
521 else { 521 else {
522 QCopEnvelope e("QPE/System","execute(QString)"); 522 QCopEnvelope e("QPE/System","execute(QString)");
523 e << tempItem; 523 e << tempItem;
524 } 524 }
525} 525}
526 526
527void Desktop::raiseMenu() 527void Desktop::raiseMenu()
528{ 528{
529 Config cfg("qpe"); //F11, 'Menu' 529 Config cfg("qpe"); //F11, 'Menu'
530 cfg.setGroup("AppsKey"); 530 cfg.setGroup("AppsKey");
531 QString tempItem; 531 QString tempItem;
532 tempItem = cfg.readEntry("Right2nd","Popup Menu"); 532 tempItem = cfg.readEntry("Right2nd","Popup Menu");
533 if(tempItem == "Popup Menu" || tempItem.isEmpty()) { 533 if(tempItem == "Popup Menu" || tempItem.isEmpty()) {
534 Global::terminateBuiltin("calibrate"); 534 Global::terminateBuiltin("calibrate");
535 tb->startMenu()->launch(); 535 tb->startMenu()->launch();
536 } else { 536 } else {
537 QCopEnvelope e("QPE/System","execute(QString)"); 537 QCopEnvelope e("QPE/System","execute(QString)");
538 e << tempItem; 538 e << tempItem;
539 } 539 }
540} 540}
541 541
542void Desktop::raiseEmail() 542void Desktop::raiseEmail()
543{ 543{
544 Config cfg("qpe"); //F13, 'Mail' 544 Config cfg("qpe"); //F13, 'Mail'
545 cfg.setGroup("AppsKey"); 545 cfg.setGroup("AppsKey");
546 QString tempItem; 546 QString tempItem;
547 tempItem = cfg.readEntry("RightEnd","Mail"); 547 tempItem = cfg.readEntry("RightEnd","Mail");
548 if(tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty()) executeOrModify("Applications/qtmail.desktop"); 548 if(tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty()) executeOrModify("Applications/qtmail.desktop");
549 else { 549 else {
550 QCopEnvelope e("QPE/System","execute(QString)"); 550 QCopEnvelope e("QPE/System","execute(QString)");
551 e << tempItem; 551 e << tempItem;
552 } 552 }
553} 553}
554 554
555// autoStarts apps on resume and start 555// autoStarts apps on resume and start
556void Desktop::execAutoStart() { 556void Desktop::execAutoStart() {
557 QString appName; 557 QString appName;
558 int delay; 558 int delay;
559 QDateTime now = QDateTime::currentDateTime(); 559 QDateTime now = QDateTime::currentDateTime();
560 Config cfg( "autostart" ); 560 Config cfg( "autostart" );
561 cfg.setGroup( "AutoStart" ); 561 cfg.setGroup( "AutoStart" );
562 appName = cfg.readEntry("Apps", ""); 562 appName = cfg.readEntry("Apps", "");
563 delay = (cfg.readEntry("Delay", "0" )).toInt(); 563 delay = (cfg.readEntry("Delay", "0" )).toInt();
564 // If the time between suspend and resume was longer then the 564 // If the time between suspend and resume was longer then the
565 // value saved as delay, start the app 565 // value saved as delay, start the app
566 if ( suspendTime.secsTo(now) >= (delay*60) ) { 566 if ( suspendTime.secsTo(now) >= (delay*60) ) {
567 QCopEnvelope e("QPE/System", "execute(QString)"); 567 QCopEnvelope e("QPE/System", "execute(QString)");
568 e << QString(appName); 568 e << QString(appName);
569 } else { 569 } //else {
570 } 570 //}
571} 571}
572 572
573#if defined(QPE_HAVE_TOGGLELIGHT) 573#if defined(QPE_HAVE_TOGGLELIGHT)
574#include <qpe/config.h> 574#include <qpe/config.h>
575 575
576#include <sys/ioctl.h> 576#include <sys/ioctl.h>
577#include <sys/types.h> 577#include <sys/types.h>
578#include <fcntl.h> 578#include <fcntl.h>
579#include <unistd.h> 579#include <unistd.h>
580#include <errno.h> 580#include <errno.h>
581#include <linux/ioctl.h> 581#include <linux/ioctl.h>
582#include <time.h> 582#include <time.h>
583#endif 583#endif
584 584
585static bool blanked=FALSE; 585static bool blanked=FALSE;
586 586
587static void blankScreen() 587static void blankScreen()
588{ 588{
589 if ( !qt_screen ) return; 589 if ( !qt_screen ) return;
590 /* Should use a big black window instead. 590 /* Should use a big black window instead.
591 QGfx* g = qt_screen->screenGfx(); 591 QGfx* g = qt_screen->screenGfx();
592 g->fillRect(0,0,qt_screen->width(),qt_screen->height()); 592 g->fillRect(0,0,qt_screen->width(),qt_screen->height());
593 delete g; 593 delete g;
594 */ 594 */
595 blanked = TRUE; 595 blanked = TRUE;
596} 596}
597 597
598static void darkScreen() 598static void darkScreen()
599{ 599{
600 extern void qpe_setBacklight(int); 600 extern void qpe_setBacklight(int);
601 qpe_setBacklight(0); // force off 601 qpe_setBacklight(0); // force off
602} 602}
603 603
604 604
605void Desktop::togglePower() 605void Desktop::togglePower()
606{ 606{
607 bool wasloggedin = loggedin; 607 bool wasloggedin = loggedin;
608 loggedin=0; 608 loggedin=0;
609 suspendTime = QDateTime::currentDateTime(); 609 suspendTime = QDateTime::currentDateTime();
610 darkScreen(); 610 darkScreen();
611 if ( wasloggedin ) 611 if ( wasloggedin )
612 blankScreen(); 612 blankScreen();
613 613
614 system("apm --suspend"); 614 system("apm --suspend");
615 615
616 616
617 617
618 QWSServer::screenSaverActivate( FALSE ); 618 QWSServer::screenSaverActivate( FALSE );
619 { 619 {
620 QCopEnvelope("QPE/Card", "mtabChanged()" ); // might have changed while asleep 620 QCopEnvelope("QPE/Card", "mtabChanged()" ); // might have changed while asleep
621 QCopEnvelope e("QPE/System", "setBacklight(int)"); 621 QCopEnvelope e("QPE/System", "setBacklight(int)");
622 e << -3; // Force on 622 e << -3; // Force on
623 } 623 }
624 if ( wasloggedin ) { 624 if ( wasloggedin ) {
625 login(TRUE); 625 login(TRUE);
626 } 626 }
627 sleep(1); 627 sleep(1);
628 execAutoStart(); 628 execAutoStart();
629 //qcopBridge->closeOpenConnections(); 629 //qcopBridge->closeOpenConnections();
630 //qDebug("called togglePower()!!!!!!"); 630 //qDebug("called togglePower()!!!!!!");
631} 631}
632 632
633void Desktop::toggleLight() 633void Desktop::toggleLight()
634{ 634{
635 QCopEnvelope e("QPE/System", "setBacklight(int)"); 635 QCopEnvelope e("QPE/System", "setBacklight(int)");
636 e << -2; // toggle 636 e << -2; // toggle
637} 637}
638 638
639void Desktop::toggleSymbolInput() 639void Desktop::toggleSymbolInput()
640{ 640{
641 tb->toggleSymbolInput(); 641 tb->toggleSymbolInput();
642} 642}
643 643
644void Desktop::toggleNumLockState() 644void Desktop::toggleNumLockState()
645{ 645{
646 tb->toggleNumLockState(); 646 tb->toggleNumLockState();
647} 647}
648 648
649void Desktop::toggleCapsLockState() 649void Desktop::toggleCapsLockState()
650{ 650{
651 tb->toggleCapsLockState(); 651 tb->toggleCapsLockState();
652} 652}
653 653
654void Desktop::styleChange( QStyle &s ) 654void Desktop::styleChange( QStyle &s )
655{ 655{
656 QWidget::styleChange( s ); 656 QWidget::styleChange( s );
657 int displayw = qApp->desktop()->width(); 657 int displayw = qApp->desktop()->width();
658 int displayh = qApp->desktop()->height(); 658 int displayh = qApp->desktop()->height();
659 659
660 QSize sz = tb->sizeHint(); 660 QSize sz = tb->sizeHint();
661 661
662 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() ); 662 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() );
663} 663}
664 664
665void DesktopApplication::shutdown() 665void DesktopApplication::shutdown()
666{ 666{
667 if ( type() != GuiServer ) 667 if ( type() != GuiServer )
668 return; 668 return;
669 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); 669 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose );
670 connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)), 670 connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)),
671 this, SLOT(shutdown(ShutdownImpl::Type)) ); 671 this, SLOT(shutdown(ShutdownImpl::Type)) );
672 sd->showMaximized(); 672 sd->showMaximized();
673} 673}
674 674
675void DesktopApplication::shutdown( ShutdownImpl::Type t ) 675void DesktopApplication::shutdown( ShutdownImpl::Type t )
676{ 676{
677 switch ( t ) { 677 switch ( t ) {
678 case ShutdownImpl::ShutdownSystem: 678 case ShutdownImpl::ShutdownSystem:
679 execlp("shutdown", "shutdown", "-h", "now", (void*)0); 679 execlp("shutdown", "shutdown", "-h", "now", (void*)0);
680 break; 680 break;
681 case ShutdownImpl::RebootSystem: 681 case ShutdownImpl::RebootSystem:
682 execlp("shutdown", "shutdown", "-r", "now", (void*)0); 682 execlp("shutdown", "shutdown", "-r", "now", (void*)0);
683 break; 683 break;
684 case ShutdownImpl::RestartDesktop: 684 case ShutdownImpl::RestartDesktop:
685 restart(); 685 restart();
686 break; 686 break;
687 case ShutdownImpl::TerminateDesktop: 687 case ShutdownImpl::TerminateDesktop:
688 prepareForTermination(FALSE); 688 prepareForTermination(FALSE);
689 quit(); 689 quit();
690 break; 690 break;
691 } 691 }
692} 692}
693 693
694void DesktopApplication::restart() 694void DesktopApplication::restart()
695{ 695{
696 prepareForTermination(TRUE); 696 prepareForTermination(TRUE);
697 697
698#ifdef Q_WS_QWS 698#ifdef Q_WS_QWS
699 for ( int fd = 3; fd < 100; fd++ ) 699 for ( int fd = 3; fd < 100; fd++ )
700 close( fd ); 700 close( fd );
701#if defined(QT_DEMO_SINGLE_FLOPPY) 701#if defined(QT_DEMO_SINGLE_FLOPPY)
702 execl( "/sbin/init", "qpe", 0 ); 702 execl( "/sbin/init", "qpe", 0 );
703#elif defined(QT_QWS_CASSIOPEIA) 703#elif defined(QT_QWS_CASSIOPEIA)
704 execl( "/bin/sh", "sh", 0 ); 704 execl( "/bin/sh", "sh", 0 );
705#else 705#else
706 execl( (qpeDir()+"/bin/qpe").latin1(), "qpe", 0 ); 706 execl( (qpeDir()+"/bin/qpe").latin1(), "qpe", 0 );
707#endif 707#endif
708 exit(1); 708 exit(1);
709#endif 709#endif
710} 710}
711 711
712void Desktop::startTransferServer() 712void Desktop::startTransferServer()
713{ 713{
714 // start qcop bridge server 714 // start qcop bridge server
715 qcopBridge = new QCopBridge( 4243 ); 715 qcopBridge = new QCopBridge( 4243 );
716 if ( !qcopBridge->ok() ) { 716 if ( !qcopBridge->ok() ) {
717 delete qcopBridge; 717 delete qcopBridge;
718 qcopBridge = 0; 718 qcopBridge = 0;
719 } 719 }
720 // start transfer server 720 // start transfer server
721 transferServer = new TransferServer( 4242 ); 721 transferServer = new TransferServer( 4242 );
722 if ( !transferServer->ok() ) { 722 if ( !transferServer->ok() ) {
723 delete transferServer; 723 delete transferServer;
724 transferServer = 0; 724 transferServer = 0;
725 } 725 }
726 if ( !transferServer || !qcopBridge ) 726 if ( !transferServer || !qcopBridge )
727 startTimer( 2000 ); 727 startTimer( 2000 );
728} 728}
729 729
730void Desktop::timerEvent( QTimerEvent *e ) 730void Desktop::timerEvent( QTimerEvent *e )
731{ 731{
732 killTimer( e->timerId() ); 732 killTimer( e->timerId() );
733 startTransferServer(); 733 startTransferServer();
734} 734}
735 735
736void Desktop::terminateServers() 736void Desktop::terminateServers()
737{ 737{
738 delete transferServer; 738 delete transferServer;
739 delete qcopBridge; 739 delete qcopBridge;
740 transferServer = 0; 740 transferServer = 0;
741 qcopBridge = 0; 741 qcopBridge = 0;
742} 742}
743 743
744void Desktop::rereadVolumes() 744void Desktop::rereadVolumes()
745{ 745{
746 Config cfg("qpe"); 746 Config cfg("qpe");
747 cfg.setGroup("Volume"); 747 cfg.setGroup("Volume");
748 touchclick = cfg.readBoolEntry("TouchSound"); 748 touchclick = cfg.readBoolEntry("TouchSound");
749 keyclick = cfg.readBoolEntry("KeySound"); 749 keyclick = cfg.readBoolEntry("KeySound");
750 alarmsound = cfg.readBoolEntry("AlarmSound"); 750 alarmsound = cfg.readBoolEntry("AlarmSound");
751// Config cfg("Sound"); 751// Config cfg("Sound");
752// cfg.setGroup("System"); 752// cfg.setGroup("System");
753// touchclick = cfg.readBoolEntry("Touch"); 753// touchclick = cfg.readBoolEntry("Touch");
754// keyclick = cfg.readBoolEntry("Key"); 754// keyclick = cfg.readBoolEntry("Key");
755} 755}
756 756
757void Desktop::keyClick() 757void Desktop::keyClick()
758{ 758{
759 if ( keyclick ) 759 if ( keyclick )
760 ODevice::inst ( )-> keySound ( ); 760 ODevice::inst ( )-> keySound ( );
761} 761}
762 762
763void Desktop::screenClick() 763void Desktop::screenClick()
764{ 764{
765 if ( touchclick ) 765 if ( touchclick )
766 ODevice::inst ( )-> touchSound ( ); 766 ODevice::inst ( )-> touchSound ( );
767} 767}
768 768
769void Desktop::soundAlarm() 769void Desktop::soundAlarm()
770{ 770{
771 if ( qpedesktop-> alarmsound ) 771 if ( qpedesktop-> alarmsound )
772 ODevice::inst ( )-> alarmSound ( ); 772 ODevice::inst ( )-> alarmSound ( );
773} 773}
774 774
775bool Desktop::eventFilter( QObject *, QEvent *ev ) 775bool Desktop::eventFilter( QObject *, QEvent *ev )
776{ 776{
777 if ( ev-> type ( ) == QEvent::KeyPress ) { 777 if ( ev-> type ( ) == QEvent::KeyPress ) {
778 QKeyEvent *ke = (QKeyEvent *) ev; 778 QKeyEvent *ke = (QKeyEvent *) ev;
779 if ( ke-> key ( ) == Qt::Key_F11 ) { // menu key 779 if ( ke-> key ( ) == Qt::Key_F11 ) { // menu key
780 QWidget *active = qApp-> activeWindow ( ); 780 QWidget *active = qApp-> activeWindow ( );
781 781
782 if ( active && active-> isPopup ( )) 782 if ( active && active-> isPopup ( ))
783 active->close(); 783 active->close();
784 784
785 raiseMenu ( ); 785 raiseMenu ( );
786 return true; 786 return true;
787 } 787 }
788 } 788 }
789 return false; 789 return false;
790} 790}
diff --git a/core/launcher/launcher.pro b/core/launcher/launcher.pro
index ccf8231..169edc1 100644
--- a/core/launcher/launcher.pro
+++ b/core/launcher/launcher.pro
@@ -1,117 +1,117 @@
1 TEMPLATE= app 1 TEMPLATE= app
2 CONFIG = qt warn_on release 2 CONFIG = qt warn_on release
3 DESTDIR = $(OPIEDIR)/bin 3 DESTDIR = $(OPIEDIR)/bin
4 HEADERS = background.h \ 4 HEADERS = background.h \
5 desktop.h \ 5 desktop.h \
6 qprocess.h \ 6 qprocess.h \
7 mediummountgui.h \ 7 mediummountgui.h \
8 info.h \ 8 info.h \
9 appicons.h \ 9 appicons.h \
10 taskbar.h \ 10 taskbar.h \
11 sidething.h \ 11 sidething.h \
12 mrulist.h \ 12 mrulist.h \
13 stabmon.h \ 13 stabmon.h \
14 inputmethods.h \ 14 inputmethods.h \
15 systray.h \ 15 systray.h \
16 wait.h \ 16 wait.h \
17 shutdownimpl.h \ 17 shutdownimpl.h \
18 launcher.h \ 18 launcher.h \
19 launcherview.h \ 19 launcherview.h \
20 $(OPIEDIR)/core/apps/calibrate/calibrate.h \ 20 $(OPIEDIR)/core/apps/calibrate/calibrate.h \
21 startmenu.h \ 21 startmenu.h \
22 transferserver.h \ 22 transferserver.h \
23 qcopbridge.h \ 23 qcopbridge.h \
24 packageslave.h \ 24 packageslave.h \
25 irserver.h \ 25 irserver.h \
26 $(OPIEDIR)/rsync/buf.h \ 26 $(OPIEDIR)/rsync/buf.h \
27 $(OPIEDIR)/rsync/checksum.h \ 27 $(OPIEDIR)/rsync/checksum.h \
28 $(OPIEDIR)/rsync/command.h \ 28 $(OPIEDIR)/rsync/command.h \
29 $(OPIEDIR)/rsync/emit.h \ 29 $(OPIEDIR)/rsync/emit.h \
30 $(OPIEDIR)/rsync/job.h \ 30 $(OPIEDIR)/rsync/job.h \
31 $(OPIEDIR)/rsync/netint.h \ 31 $(OPIEDIR)/rsync/netint.h \
32 $(OPIEDIR)/rsync/protocol.h \ 32 $(OPIEDIR)/rsync/protocol.h \
33 $(OPIEDIR)/rsync/prototab.h \ 33 $(OPIEDIR)/rsync/prototab.h \
34 $(OPIEDIR)/rsync/rsync.h \ 34 $(OPIEDIR)/rsync/rsync.h \
35 $(OPIEDIR)/rsync/search.h \ 35 $(OPIEDIR)/rsync/search.h \
36 $(OPIEDIR)/rsync/stream.h \ 36 $(OPIEDIR)/rsync/stream.h \
37 $(OPIEDIR)/rsync/sumset.h \ 37 $(OPIEDIR)/rsync/sumset.h \
38 $(OPIEDIR)/rsync/trace.h \ 38 $(OPIEDIR)/rsync/trace.h \
39 $(OPIEDIR)/rsync/types.h \ 39 $(OPIEDIR)/rsync/types.h \
40 $(OPIEDIR)/rsync/util.h \ 40 $(OPIEDIR)/rsync/util.h \
41 $(OPIEDIR)/rsync/whole.h \ 41 $(OPIEDIR)/rsync/whole.h \
42 $(OPIEDIR)/rsync/config_rsync.h \ 42 $(OPIEDIR)/rsync/config_rsync.h \
43 $(OPIEDIR)/rsync/qrsync.h 43 $(OPIEDIR)/rsync/qrsync.h
44 # quicklauncher.h \ 44 # quicklauncher.h \
45 SOURCES = background.cpp \ 45 SOURCES = background.cpp \
46 desktop.cpp \ 46 desktop.cpp \
47 mediummountgui.cpp \ 47 mediummountgui.cpp \
48 qprocess.cpp qprocess_unix.cpp \ 48 qprocess.cpp qprocess_unix.cpp \
49 info.cpp \ 49 info.cpp \
50 appicons.cpp \ 50 appicons.cpp \
51 taskbar.cpp \ 51 taskbar.cpp \
52 sidething.cpp \ 52 sidething.cpp \
53 mrulist.cpp \ 53 mrulist.cpp \
54 stabmon.cpp \ 54 stabmon.cpp \
55 inputmethods.cpp \ 55 inputmethods.cpp \
56 systray.cpp \ 56 systray.cpp \
57 wait.cpp \ 57 wait.cpp \
58 shutdownimpl.cpp \ 58 shutdownimpl.cpp \
59 launcher.cpp \ 59 launcher.cpp \
60 launcherview.cpp \ 60 launcherview.cpp \
61 $(OPIEDIR)/core/apps/calibrate/calibrate.cpp \ 61 $(OPIEDIR)/core/apps/calibrate/calibrate.cpp \
62 transferserver.cpp \ 62 transferserver.cpp \
63 packageslave.cpp \ 63 packageslave.cpp \
64 irserver.cpp \ 64 irserver.cpp \
65 qcopbridge.cpp \ 65 qcopbridge.cpp \
66 startmenu.cpp \ 66 startmenu.cpp \
67 main.cpp \ 67 main.cpp \
68 $(OPIEDIR)/rsync/base64.c \ 68 $(OPIEDIR)/rsync/base64.c \
69 $(OPIEDIR)/rsync/buf.c \ 69 $(OPIEDIR)/rsync/buf.c \
70 $(OPIEDIR)/rsync/checksum.c \ 70 $(OPIEDIR)/rsync/checksum.c \
71 $(OPIEDIR)/rsync/command.c \ 71 $(OPIEDIR)/rsync/command.c \
72 $(OPIEDIR)/rsync/delta.c \ 72 $(OPIEDIR)/rsync/delta.c \
73 $(OPIEDIR)/rsync/emit.c \ 73 $(OPIEDIR)/rsync/emit.c \
74 $(OPIEDIR)/rsync/hex.c \ 74 $(OPIEDIR)/rsync/hex.c \
75 $(OPIEDIR)/rsync/job.c \ 75 $(OPIEDIR)/rsync/job.c \
76 $(OPIEDIR)/rsync/mdfour.c \ 76 $(OPIEDIR)/rsync/mdfour.c \
77 $(OPIEDIR)/rsync/mksum.c \ 77 $(OPIEDIR)/rsync/mksum.c \
78 $(OPIEDIR)/rsync/msg.c \ 78 $(OPIEDIR)/rsync/msg.c \
79 $(OPIEDIR)/rsync/netint.c \ 79 $(OPIEDIR)/rsync/netint.c \
80 $(OPIEDIR)/rsync/patch.c \ 80 $(OPIEDIR)/rsync/patch.c \
81 $(OPIEDIR)/rsync/prototab.c \ 81 $(OPIEDIR)/rsync/prototab.c \
82 $(OPIEDIR)/rsync/readsums.c \ 82 $(OPIEDIR)/rsync/readsums.c \
83 $(OPIEDIR)/rsync/scoop.c \ 83 $(OPIEDIR)/rsync/scoop.c \
84 $(OPIEDIR)/rsync/search.c \ 84 $(OPIEDIR)/rsync/search.c \
85 $(OPIEDIR)/rsync/stats.c \ 85 $(OPIEDIR)/rsync/stats.c \
86 $(OPIEDIR)/rsync/stream.c \ 86 $(OPIEDIR)/rsync/stream.c \
87 $(OPIEDIR)/rsync/sumset.c \ 87 $(OPIEDIR)/rsync/sumset.c \
88 $(OPIEDIR)/rsync/trace.c \ 88 $(OPIEDIR)/rsync/trace.c \
89 $(OPIEDIR)/rsync/tube.c \ 89 $(OPIEDIR)/rsync/tube.c \
90 $(OPIEDIR)/rsync/util.c \ 90 $(OPIEDIR)/rsync/util.c \
91 $(OPIEDIR)/rsync/version.c \ 91 $(OPIEDIR)/rsync/version.c \
92 $(OPIEDIR)/rsync/whole.c \ 92 $(OPIEDIR)/rsync/whole.c \
93 $(OPIEDIR)/rsync/qrsync.cpp 93 $(OPIEDIR)/rsync/qrsync.cpp
94 INTERFACES= syncdialog.ui 94 INTERFACES= syncdialog.ui
95INCLUDEPATH += $(OPIEDIR)/include 95INCLUDEPATH += $(OPIEDIR)/include
96 DEPENDPATH+= $(OPIEDIR)/include . 96 DEPENDPATH+= $(OPIEDIR)/include .
97INCLUDEPATH += $(OPIEDIR)/core/apps/calibrate 97INCLUDEPATH += $(OPIEDIR)/core/apps/calibrate
98 DEPENDPATH+= $(OPIEDIR)/core/apps/calibrate 98 DEPENDPATH+= $(OPIEDIR)/core/apps/calibrate
99INCLUDEPATH += $(OPIEDIR)/rsync 99INCLUDEPATH += $(OPIEDIR)/rsync
100 DEPENDPATH+= $(OPIEDIR)/rsync 100 DEPENDPATH+= $(OPIEDIR)/rsync
101 TARGET = qpe 101 TARGET = qpe
102 LIBS += -lqpe -lcrypt -lopie 102 LIBS += -lqpe -lcrypt -lopie -luuid
103 103
104TRANSLATIONS = ../../i18n/de/qpe.ts \ 104TRANSLATIONS = ../../i18n/de/qpe.ts \
105 ../../i18n/en/qpe.ts \ 105 ../../i18n/en/qpe.ts \
106 ../../i18n/es/qpe.ts \ 106 ../../i18n/es/qpe.ts \
107 ../../i18n/fr/qpe.ts \ 107 ../../i18n/fr/qpe.ts \
108 ../../i18n/hu/qpe.ts \ 108 ../../i18n/hu/qpe.ts \
109 ../../i18n/ja/qpe.ts \ 109 ../../i18n/ja/qpe.ts \
110 ../../i18n/ko/qpe.ts \ 110 ../../i18n/ko/qpe.ts \
111 ../../i18n/no/qpe.ts \ 111 ../../i18n/no/qpe.ts \
112 ../../i18n/pl/qpe.ts \ 112 ../../i18n/pl/qpe.ts \
113 ../../i18n/pt/qpe.ts \ 113 ../../i18n/pt/qpe.ts \
114 ../../i18n/pt_BR/qpe.ts \ 114 ../../i18n/pt_BR/qpe.ts \
115 ../../i18n/sl/qpe.ts \ 115 ../../i18n/sl/qpe.ts \
116 ../../i18n/zh_CN/qpe.ts \ 116 ../../i18n/zh_CN/qpe.ts \
117 ../../i18n/zh_TW/qpe.ts 117 ../../i18n/zh_TW/qpe.ts
diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp
index 2d084fc..85993ee 100644
--- a/core/launcher/qcopbridge.cpp
+++ b/core/launcher/qcopbridge.cpp
@@ -1,420 +1,424 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "qcopbridge.h" 21#include "qcopbridge.h"
22#include "transferserver.h" 22#include "transferserver.h"
23 23
24#ifdef QWS
24#include <qpe/qcopenvelope_qws.h> 25#include <qpe/qcopenvelope_qws.h>
26#endif
25#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28#include <qpe/version.h>
26 29
27#include <qdir.h> 30#include <qdir.h>
28#include <qfile.h> 31#include <qfile.h>
29#include <qtextstream.h> 32#include <qtextstream.h>
30#include <qdatastream.h> 33#include <qdatastream.h>
31#include <qstringlist.h> 34#include <qstringlist.h>
32#include <qfileinfo.h> 35#include <qfileinfo.h>
33#include <qregexp.h> 36#include <qregexp.h>
37#ifdef QWS
34#include <qcopchannel_qws.h> 38#include <qcopchannel_qws.h>
39#endif
35 40
36// actually this is wrong, _XOPEN_SOURCE should get defined on the commandline
37// and it should have a proper value assigned. (Simon)
38#if !defined(_XOPEN_SOURCE)
39#define _XOPEN_SOURCE 41#define _XOPEN_SOURCE
40#endif
41#include <pwd.h> 42#include <pwd.h>
42#include <sys/types.h> 43#include <sys/types.h>
43#include <unistd.h> 44#include <unistd.h>
44 45
45#if defined(_OS_LINUX_) 46#if defined(_OS_LINUX_)
46#include <shadow.h> 47#include <shadow.h>
47#endif 48#endif
48 49
49//#define INSECURE 50//#define INSECURE
50 51
51const int block_size = 51200; 52const int block_size = 51200;
52 53
53QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent, 54QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent ,
54 const char* name ) 55 const char* name )
55 : QServerSocket( port, 1, parent, name ), 56 : QServerSocket( port, 1, parent, name ),
56 desktopChannel( 0 ), 57 desktopChannel( 0 ),
57 cardChannel( 0 ) 58 cardChannel( 0 )
58{ 59{
59 if ( !ok() ) 60 if ( !ok() )
60 qWarning( "Failed to bind to port %d", port ); 61 qWarning( "Failed to bind to port %d", port );
61 else { 62 else {
62 desktopChannel = new QCopChannel( "QPE/Desktop", this ); 63#ifndef QT_NO_COP
63 connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)), 64 desktopChannel = new QCopChannel( "QPE/Desktop", this );
64 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 65 connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)),
65 cardChannel = new QCopChannel( "QPE/Card", this ); 66 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
66 connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), 67 cardChannel = new QCopChannel( "QPE/Card", this );
67 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 68 connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)),
69 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
70#endif
68 } 71 }
69 sendSync = FALSE; 72 sendSync = FALSE;
70} 73}
71 74
72QCopBridge::~QCopBridge() 75QCopBridge::~QCopBridge()
73{ 76{
77#ifndef QT_NO_COP
74 delete desktopChannel; 78 delete desktopChannel;
79#endif
75} 80}
76 81
77void QCopBridge::newConnection( int socket ) 82void QCopBridge::newConnection( int socket )
78{ 83{
79 QCopBridgePI *pi = new QCopBridgePI( socket, this ); 84 QCopBridgePI *pi = new QCopBridgePI( socket, this );
80 openConnections.append( pi ); 85 openConnections.append( pi );
81 connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) ); 86 connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) );
87#ifndef QT_NO_COP
82 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; 88 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend;
83 89#endif
90
84 if ( sendSync ) { 91 if ( sendSync ) {
85 pi ->startSync(); 92 pi ->startSync();
86 sendSync = FALSE; 93 sendSync = FALSE;
87 } 94 }
88} 95}
89 96
90void QCopBridge::connectionClosed( QCopBridgePI *pi ) 97void QCopBridge::connectionClosed( QCopBridgePI *pi )
91{ 98{
92 openConnections.remove( pi ); 99 openConnections.remove( pi );
93 if ( openConnections.count() == 0 ) { 100 if ( openConnections.count() == 0 ) {
94 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 101#ifndef QT_NO_COP
102 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
103#endif
95 } 104 }
96} 105}
97 106
98void QCopBridge::closeOpenConnections() 107void QCopBridge::closeOpenConnections()
99{ 108{
100 QCopBridgePI *pi; 109 QCopBridgePI *pi;
101 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) 110 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() )
102 pi->close(); 111 pi->close();
103} 112}
104 113
105 114
106void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args ) 115void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args )
107{ 116{
108 command.stripWhiteSpace(); 117 command.stripWhiteSpace();
109 118
110 int paren = command.find( "(" ); 119 int paren = command.find( "(" );
111 if ( paren <= 0 ) { 120 if ( paren <= 0 ) {
112 qDebug("DesktopMessage: bad qcop syntax"); 121 qDebug("DesktopMessage: bad qcop syntax");
113 return; 122 return;
114 } 123 }
115 124
116 QString params = command.mid( paren + 1 ); 125 QString params = command.mid( paren + 1 );
117 if ( params[params.length()-1] != ')' ) { 126 if ( params[params.length()-1] != ')' ) {
118 qDebug("DesktopMessage: bad qcop syntax"); 127 qDebug("DesktopMessage: bad qcop syntax");
119 return; 128 return;
120 } 129 }
121 130
122 params.truncate( params.length()-1 ); 131 params.truncate( params.length()-1 );
123 132
124 QStringList paramList = QStringList::split( ",", params ); 133 QStringList paramList = QStringList::split( ",", params );
125 QString data; 134 QString data;
126 if ( paramList.count() ) { 135 if ( paramList.count() ) {
127 QDataStream stream( args, IO_ReadOnly ); 136 QDataStream stream( args, IO_ReadOnly );
128 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { 137 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
129 QString str; 138 QString str;
130 if ( *it == "QString" ) { 139 if ( *it == "QString" ) {
131 stream >> str; 140 stream >> str;
132 } else if ( *it == "QCString" ) { 141 } else if ( *it == "QCString" ) {
133 QCString cstr; 142 QCString cstr;
134 stream >> cstr; 143 stream >> cstr;
135 str = QString::fromLocal8Bit( cstr ); 144 str = QString::fromLocal8Bit( cstr );
136 } else if ( *it == "int" ) { 145 } else if ( *it == "int" ) {
137 int i; 146 int i;
138 stream >> i; 147 stream >> i;
139 str = QString::number( i ); 148 str = QString::number( i );
140 } else if ( *it == "bool" ) { 149 } else if ( *it == "bool" ) {
141 int i; 150 int i;
142 stream >> i; 151 stream >> i;
143 str = QString::number( i ); 152 str = QString::number( i );
144 } else { 153 } else {
145 qDebug(" cannot route the argument type %s through the qcop bridge", (*it).latin1() ); 154 qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() );
146 return; 155 return;
147 } 156 }
148 str.replace( QRegExp("&"), "&amp;" ); 157 QString estr;
149 str.replace( QRegExp(" "), "&0x20;" ); 158 for (int i=0; i<(int)str.length(); i++) {
150 str.replace( QRegExp("\n"), "&0x0d;" ); 159 QChar ch = str[i];
151 str.replace( QRegExp("\r"), "&0x0a;" ); 160 if ( ch.row() )
152 data += " " + str; 161 goto quick;
153 } 162 switch (ch.cell()) {
163 case '&':
164 estr.append( "&amp;" );
165 break;
166 case ' ':
167 estr.append( "&0x20;" );
168 break;
169 case '\n':
170 estr.append( "&0x0d;" );
171 break;
172 case '\r':
173 estr.append( "&0x0a;" );
174 break;
175 default: quick:
176 estr.append(ch);
177 }
178 }
179 data += " " + estr;
180 }
154 } 181 }
155 QString sendCommand = QString(command.data()) + data; 182 QString sendCommand = QString(command.data()) + data;
156 // send the command to all open connections 183 // send the command to all open connections
157 if ( command == "startSync()" ) { 184 if ( command == "startSync()" ) {
158 // we need to buffer it a bit 185 // we need to buffer it a bit
159 sendSync = TRUE; 186 sendSync = TRUE;
160 startTimer( 20000 ); 187 startTimer( 20000 );
161 } 188 }
162 189
163 QCopBridgePI *pi; 190 QCopBridgePI *pi;
164 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { 191 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) {
165 pi->sendDesktopMessage( sendCommand ); 192 pi->sendDesktopMessage( sendCommand );
166 } 193 }
167} 194}
168 195
169void QCopBridge::timerEvent( QTimerEvent * ) 196void QCopBridge::timerEvent( QTimerEvent * )
170{ 197{
171 sendSync = FALSE; 198 sendSync = FALSE;
172 killTimers(); 199 killTimers();
173} 200}
174 201
175 202
176QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name ) 203QCopBridgePI::QCopBridgePI( int socket, QObject *parent , const char* name )
177 : QSocket( parent, name ) 204 : QSocket( parent, name )
178{ 205{
179 setSocket( socket ); 206 setSocket( socket );
180 207
181 peerport = peerPort(); 208 peerport = peerPort();
182 peeraddress = peerAddress(); 209 peeraddress = peerAddress();
183 210
184#ifndef INSECURE 211#ifndef INSECURE
185 if ( !accessAuthorized(peeraddress) ) { 212 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
186 state = Forbidden; 213 state = Forbidden;
187 startTimer( 0 ); 214 startTimer( 0 );
188 } else 215 } else
189#endif 216 #endif
190 { 217 {
191 state = Connected; 218 state = Connected;
192 sendSync = FALSE; 219 sendSync = FALSE;
193 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 220 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
194 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 221 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
195 222
196 send( "220 Qtopia QCop bridge ready!" ); 223 QString intro="220 Qtopia ";
197 state = Wait_USER; 224 intro += QPE_VERSION; intro += ";";
198 225 intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";";
199 // idle timer to close connections when not used anymore 226 intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";";
200 startTimer( 60000 ); 227 intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";";
201 connected = TRUE; 228 send( intro );
229 state = Wait_USER;
230
231 // idle timer to close connections when not used anymore
232 startTimer( 60000 );
233 connected = TRUE;
202 } 234 }
203} 235}
204 236
205 237
206QCopBridgePI::~QCopBridgePI() 238QCopBridgePI::~QCopBridgePI()
207{ 239{
208 240
209} 241}
210 242
211void QCopBridgePI::connectionClosed() 243void QCopBridgePI::connectionClosed()
212{ 244{
213 emit connectionClosed( this ); 245 emit connectionClosed( this );
214 // qDebug( "Debug: Connection closed" ); 246 // qDebug( "Debug: Connection closed" );
215 delete this; 247 delete this;
216} 248}
217 249
218void QCopBridgePI::sendDesktopMessage( const QString &msg ) 250void QCopBridgePI::sendDesktopMessage( const QString &msg )
219{ 251{
220 QString str = "CALL QPE/Desktop " + msg; 252 QString str = "CALL QPE/Desktop " + msg;
221 send ( str ); 253 send ( str );
222} 254}
223 255
224 256
225void QCopBridgePI::send( const QString& msg ) 257void QCopBridgePI::send( const QString& msg )
226{ 258{
227 QTextStream os( this ); 259 QTextStream os( this );
228 os << msg << endl; 260 os << msg << endl;
229 //qDebug( "sending qcop message: %s", msg.latin1() ); 261 //qDebug( "sending qcop message: %s", msg.latin1() );
230} 262}
231 263
232void QCopBridgePI::read() 264void QCopBridgePI::read()
233{ 265{
234 while ( canReadLine() ) 266 while ( canReadLine() )
235 process( readLine().stripWhiteSpace() ); 267 process( readLine().stripWhiteSpace() );
236}
237
238bool QCopBridgePI::checkUser( const QString& user )
239{
240 if ( user.isEmpty() ) return FALSE;
241
242 struct passwd *pw;
243 pw = getpwuid( geteuid() );
244 QString euser = QString::fromLocal8Bit( pw->pw_name );
245 return user == euser;
246}
247
248bool QCopBridgePI::checkPassword( const QString& password )
249{
250 // ### HACK for testing on local host
251 return true;
252
253 /*
254 struct passwd *pw = 0;
255 struct spwd *spw = 0;
256
257 pw = getpwuid( geteuid() );
258 spw = getspnam( pw->pw_name );
259
260 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
261 if ( cpwd == "x" && spw )
262 cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
263
264 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
265 return cpwd == cpassword;
266*/
267} 268}
268 269
269void QCopBridgePI::process( const QString& message ) 270void QCopBridgePI::process( const QString& message )
270{ 271{
271 //qDebug( "Command: %s", message.latin1() ); 272 //qDebug( "Command: %s", message.latin1() );
272 273
273 // split message using "," as separator 274 // split message using "," as separator
274 QStringList msg = QStringList::split( " ", message ); 275 QStringList msg = QStringList::split( " ", message );
275 if ( msg.isEmpty() ) return; 276 if ( msg.isEmpty() ) return;
276 277
277 // command token 278 // command token
278 QString cmd = msg[0].upper(); 279 QString cmd = msg[0].upper();
279 280
280 // argument token 281 // argument token
281 QString arg; 282 QString arg;
282 if ( msg.count() >= 2 ) 283 if ( msg.count() >= 2 )
283 arg = msg[1]; 284 arg = msg[1];
284 285
285 // we always respond to QUIT, regardless of state 286 // we always respond to QUIT, regardless of state
286 if ( cmd == "QUIT" ) { 287 if ( cmd == "QUIT" ) {
287 send( "211 Have a nice day!" ); 288 send( "211 Have a nice day!" );
288 delete this; 289 delete this;
289 return; 290 return;
290 } 291 }
291 292
292 // connected to client 293 // connected to client
293 if ( Connected == state ) 294 if ( Connected == state )
294 return; 295 return;
295 296
296 // waiting for user name 297 // waiting for user name
297 if ( Wait_USER == state ) { 298 if ( Wait_USER == state ) {
298 299
299 if ( cmd != "USER" || msg.count() < 2 || !checkUser( arg ) ) { 300 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
300 send( "530 Please login with USER and PASS" ); 301 send( "530 Please login with USER and PASS" );
301 return; 302 return;
302 } 303 }
303 send( "331 User name ok, need password" ); 304 send( "331 User name ok, need password" );
304 state = Wait_PASS; 305 state = Wait_PASS;
305 return; 306 return;
306 } 307 }
307 308
308 // waiting for password 309 // waiting for password
309 if ( Wait_PASS == state ) { 310 if ( Wait_PASS == state ) {
310 311
311 if ( cmd != "PASS" || !checkPassword( arg ) ) { 312 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
312 //if ( cmd != "PASS" || msg.count() < 2 || !checkPassword( arg ) ) { 313 send( "530 Please login with USER and PASS" );
313 send( "530 Please login with USER and PASS" ); 314 return;
314 return; 315 }
315 } 316 send( "230 User logged in, proceed" );
316 send( "230 User logged in, proceed" ); 317 state = Ready;
317 state = Ready; 318 if ( sendSync ) {
318 if ( sendSync ) { 319 sendDesktopMessage( "startSync()" );
319 sendDesktopMessage( "startSync()" ); 320 sendSync = FALSE;
320 sendSync = FALSE; 321 }
321 } 322 return;
322 return;
323 } 323 }
324 324
325 // noop (NOOP) 325 // noop (NOOP)
326 else if ( cmd == "NOOP" ) { 326 else if ( cmd == "NOOP" ) {
327 connected = TRUE; 327 connected = TRUE;
328 send( "200 Command okay" ); 328 send( "200 Command okay" );
329 } 329 }
330 330
331 // call (CALL) 331 // call (CALL)
332 else if ( cmd == "CALL" ) { 332 else if ( cmd == "CALL" ) {
333 333
334 // example: call QPE/System execute(QString) addressbook 334 // example: call QPE/System execute(QString) addressbook
335 335
336 if ( msg.count() < 3 ) { 336 if ( msg.count() < 3 ) {
337 send( "500 Syntax error, command unrecognized" ); 337 send( "500 Syntax error, command unrecognized" );
338 } 338 }
339 else { 339 else {
340 340
341 QString channel = msg[1]; 341 QString channel = msg[1];
342 QString command = msg[2]; 342 QString command = msg[2];
343 343
344 command.stripWhiteSpace(); 344 command.stripWhiteSpace();
345 345
346 int paren = command.find( "(" ); 346 int paren = command.find( "(" );
347 if ( paren <= 0 ) { 347 if ( paren <= 0 ) {
348 send( "500 Syntax error, command unrecognized" ); 348 send( "500 Syntax error, command unrecognized" );
349 return; 349 return;
350 } 350 }
351 351
352 QString params = command.mid( paren + 1 ); 352 QString params = command.mid( paren + 1 );
353 if ( params[params.length()-1] != ')' ) { 353 if ( params[params.length()-1] != ')' ) {
354 send( "500 Syntax error, command unrecognized" ); 354 send( "500 Syntax error, command unrecognized" );
355 return; 355 return;
356 } 356 }
357 357
358 params.truncate( params.length()-1 ); 358 params.truncate( params.length()-1 );
359 QByteArray buffer; 359 QByteArray buffer;
360 QDataStream ds( buffer, IO_WriteOnly ); 360 QDataStream ds( buffer, IO_WriteOnly );
361 361
362 int msgId = 3; 362 int msgId = 3;
363 363
364 QStringList paramList = QStringList::split( ",", params ); 364 QStringList paramList = QStringList::split( ",", params );
365 if ( paramList.count() > msg.count() - 3 ) { 365 if ( paramList.count() > msg.count() - 3 ) {
366 send( "500 Syntax error, command unrecognized" ); 366 send( "500 Syntax error, command unrecognized" );
367 return; 367 return;
368 } 368 }
369 369
370 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { 370 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
371 371
372 QString arg = msg[msgId]; 372 QString arg = msg[msgId];
373 arg.replace( QRegExp("&0x20;"), " " ); 373 arg.replace( QRegExp("&0x20;"), " " );
374 arg.replace( QRegExp("&amp;"), "&" ); 374 arg.replace( QRegExp("&amp;"), "&" );
375 arg.replace( QRegExp("&0x0d;"), "\n" ); 375 arg.replace( QRegExp("&0x0d;"), "\n" );
376 arg.replace( QRegExp("&0x0a;"), "\r" ); 376 arg.replace( QRegExp("&0x0a;"), "\r" );
377 if ( *it == "QString" ) 377 if ( *it == "QString" )
378 ds << arg; 378 ds << arg;
379 else if ( *it == "QCString" ) 379 else if ( *it == "QCString" )
380 ds << arg.local8Bit(); 380 ds << arg.local8Bit();
381 else if ( *it == "int" ) 381 else if ( *it == "int" )
382 ds << arg.toInt(); 382 ds << arg.toInt();
383 else if ( *it == "bool" ) 383 else if ( *it == "bool" )
384 ds << arg.toInt(); 384 ds << arg.toInt();
385 else { 385 else {
386 send( "500 Syntax error, command unrecognized" ); 386 send( "500 Syntax error, command unrecognized" );
387 return; 387 return;
388 } 388 }
389 msgId++; 389 msgId++;
390 } 390 }
391 391
392 if ( !QCopChannel::isRegistered( channel.latin1() ) ) { 392#ifndef QT_NO_COP
393 // send message back about it 393 if ( !QCopChannel::isRegistered( channel.latin1() ) ) {
394 QString answer = "599 ChannelNotRegistered " + channel; 394 // send message back about it
395 send( answer ); 395 QString answer = "599 ChannelNotRegistered " + channel;
396 return; 396 send( answer );
397 } 397 return;
398 398 }
399 if ( paramList.count() ) 399#endif
400 QCopChannel::send( channel.latin1(), command.latin1(), buffer ); 400
401 else 401#ifndef QT_NO_COP
402 QCopChannel::send( channel.latin1(), command.latin1() ); 402 if ( paramList.count() )
403 403 QCopChannel::send( channel.latin1(), command.latin1(), buffer );
404 send( "200 Command okay" ); 404 else
405 } 405 QCopChannel::send( channel.latin1(), command.latin1() );
406
407 send( "200 Command okay" );
408#endif
409 }
406 } 410 }
407 // not implemented 411 // not implemented
408 else 412 else
409 send( "502 Command not implemented" ); 413 send( "502 Command not implemented" );
410} 414}
411 415
412 416
413 417
414void QCopBridgePI::timerEvent( QTimerEvent * ) 418void QCopBridgePI::timerEvent( QTimerEvent * )
415{ 419{
416 if ( connected ) 420 if ( connected )
417 connected = FALSE; 421 connected = FALSE;
418 else 422 else
419 connectionClosed(); 423 connectionClosed();
420} 424}
diff --git a/core/launcher/qcopbridge.h b/core/launcher/qcopbridge.h
index 114b3ee..408d10d 100644
--- a/core/launcher/qcopbridge.h
+++ b/core/launcher/qcopbridge.h
@@ -1,95 +1,92 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef __qcopbridge_h__ 20#ifndef __qcopbridge_h__
21#define __qcopbridge_h__ 21#define __qcopbridge_h__
22 22
23#include <qserversocket.h> 23#include <qserversocket.h>
24#include <qsocket.h> 24#include <qsocket.h>
25#include <qdir.h> 25#include <qdir.h>
26#include <qfile.h> 26#include <qfile.h>
27#include <qbuffer.h> 27#include <qbuffer.h>
28 28
29class QFileInfo; 29class QFileInfo;
30class QCopBridgePI; 30class QCopBridgePI;
31class QCopChannel; 31class QCopChannel;
32 32
33class QCopBridge : public QServerSocket 33class QCopBridge : public QServerSocket
34{ 34{
35 Q_OBJECT 35 Q_OBJECT
36 36
37public: 37public:
38 QCopBridge( Q_UINT16 port, QObject *parent = 0, const char* name = 0 ); 38 QCopBridge( Q_UINT16 port, QObject *parent = 0, const char* name = 0 );
39 virtual ~QCopBridge(); 39 virtual ~QCopBridge();
40 40
41 void newConnection( int socket ); 41 void newConnection( int socket );
42 void closeOpenConnections(); 42 void closeOpenConnections();
43 43
44public slots: 44public slots:
45 void connectionClosed( QCopBridgePI *pi ); 45 void connectionClosed( QCopBridgePI *pi );
46 void desktopMessage( const QCString &call, const QByteArray & ); 46 void desktopMessage( const QCString &call, const QByteArray & );
47 47
48protected: 48protected:
49 void timerEvent( QTimerEvent * ); 49 void timerEvent( QTimerEvent * );
50 50
51private: 51private:
52 QCopChannel *desktopChannel; 52 QCopChannel *desktopChannel;
53 QCopChannel *cardChannel; 53 QCopChannel *cardChannel;
54 QList<QCopBridgePI> openConnections; 54 QList<QCopBridgePI> openConnections;
55 bool sendSync; 55 bool sendSync;
56}; 56};
57 57
58 58
59class QCopBridgePI : public QSocket 59class QCopBridgePI : public QSocket
60{ 60{
61 Q_OBJECT 61 Q_OBJECT
62 62
63 enum State { Connected, Wait_USER, Wait_PASS, Ready, Forbidden }; 63 enum State { Connected, Wait_USER, Wait_PASS, Ready, Forbidden };
64 64
65public: 65public:
66 QCopBridgePI( int socket, QObject *parent = 0, const char* name = 0 ); 66 QCopBridgePI( int socket, QObject *parent = 0, const char* name = 0 );
67 virtual ~QCopBridgePI(); 67 virtual ~QCopBridgePI();
68 68
69 void sendDesktopMessage( const QString &msg ); 69 void sendDesktopMessage( const QString &msg );
70 void startSync() { sendSync = TRUE; } 70 void startSync() { sendSync = TRUE; }
71 71
72signals: 72signals:
73 void connectionClosed( QCopBridgePI *); 73 void connectionClosed( QCopBridgePI *);
74 74
75protected slots: 75protected slots:
76 void read(); 76 void read();
77 void send( const QString& msg ); 77 void send( const QString& msg );
78 void process( const QString& command ); 78 void process( const QString& command );
79 void connectionClosed(); 79 void connectionClosed();
80 80
81protected: 81protected:
82 bool checkUser( const QString& user );
83 bool checkPassword( const QString& pw );
84
85 void timerEvent( QTimerEvent *e ); 82 void timerEvent( QTimerEvent *e );
86 83
87private: 84private:
88 State state; 85 State state;
89 Q_UINT16 peerport; 86 Q_UINT16 peerport;
90 QHostAddress peeraddress; 87 QHostAddress peeraddress;
91 bool connected; 88 bool connected;
92 bool sendSync; 89 bool sendSync;
93}; 90};
94 91
95#endif 92#endif
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index 7294f9c..a6dab07 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -1,1245 +1,1344 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#define _XOPEN_SOURCE 20#define _XOPEN_SOURCE
21#include <pwd.h> 21#include <pwd.h>
22#include <sys/types.h> 22#include <sys/types.h>
23#include <unistd.h> 23#include <unistd.h>
24#include <stdlib.h> 24#include <stdlib.h>
25#include <time.h>
26#include <shadow.h>
27
28extern "C" {
29#include <uuid/uuid.h>
30#define UUID_H_INCLUDED
31}
25 32
26#if defined(_OS_LINUX_) 33#if defined(_OS_LINUX_)
27#include <shadow.h> 34#include <shadow.h>
28#endif 35#endif
29 36
30#include <qdir.h> 37#include <qdir.h>
31#include <qfile.h> 38#include <qfile.h>
32#include <qtextstream.h> 39#include <qtextstream.h>
33#include <qdatastream.h> 40#include <qdatastream.h>
34#include <qmessagebox.h> 41#include <qmessagebox.h>
35#include <qstringlist.h> 42#include <qstringlist.h>
36#include <qfileinfo.h> 43#include <qfileinfo.h>
37#include <qregexp.h> 44#include <qregexp.h>
38//#include <qpe/qcopchannel_qws.h> 45//#include <qpe/qcopchannel_qws.h>
39#include <qpe/process.h> 46#include <qpe/process.h>
47#include <qpe/global.h>
40#include <qpe/config.h> 48#include <qpe/config.h>
49#include <qpe/contact.h>
50#include <qpe/quuid.h>
51#include <qpe/version.h>
52#ifdef QWS
41#include <qpe/qcopenvelope_qws.h> 53#include <qpe/qcopenvelope_qws.h>
54#endif
42 55
43#include "transferserver.h" 56#include "transferserver.h"
44#include "qprocess.h" 57#include "qprocess.h"
45 58
46const int block_size = 51200; 59const int block_size = 51200;
47 60
48TransferServer::TransferServer( Q_UINT16 port, QObject *parent, 61TransferServer::TransferServer( Q_UINT16 port, QObject *parent ,
49 const char* name ) 62 const char* name )
50 : QServerSocket( port, 1, parent, name ) 63 : QServerSocket( port, 1, parent, name )
51{ 64{
52 if ( !ok() ) 65 if ( !ok() )
53 qWarning( "Failed to bind to port %d", port ); 66 qWarning( "Failed to bind to port %d", port );
54} 67}
55 68
56TransferServer::~TransferServer() 69TransferServer::~TransferServer()
57{ 70{
58 71
59} 72}
60 73
61void TransferServer::newConnection( int socket ) 74void TransferServer::newConnection( int socket )
62{ 75{
63 (void) new ServerPI( socket, this ); 76 (void) new ServerPI( socket, this );
64} 77}
65 78
66bool accessAuthorized(QHostAddress peeraddress) 79QString SyncAuthentication::serverId()
67{ 80{
68 Config cfg("Security"); 81 Config cfg("Security");
69 cfg.setGroup("Sync"); 82 cfg.setGroup("Sync");
70 uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100); 83 QString r=cfg.readEntry("serverid");
84 if ( r.isEmpty() ) {
85 uuid_t uuid;
86 uuid_generate( uuid );
87 cfg.writeEntry("serverid",(r = QUuid( uuid ).toString()));
88 }
89 return r;
90}
91
92QString SyncAuthentication::ownerName()
93{
94 QString vfilename = Global::applicationFileName("addressbook",
95 "businesscard.vcf");
96 if (QFile::exists(vfilename)) {
97 Contact c;
98 c = Contact::readVCard( vfilename )[0];
99 return c.fullName();
100 }
101
102 return "";
103}
104
105QString SyncAuthentication::loginName()
106{
107 struct passwd *pw;
108 pw = getpwuid( geteuid() );
109 return QString::fromLocal8Bit( pw->pw_name );
110}
111
112int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
113{
114 Config cfg("Security");
115 cfg.setGroup("Sync");
116 QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
117 QHostAddress allowed;
118 allowed.setAddress(allowedstr);
119 uint auth_peer = allowed.ip4Addr();
71 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); 120 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24);
72 bool ok = (peeraddress.ip4Addr() & (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits))) 121 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined
73 == auth_peer; 122 ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits));
74 /* Allows denial-of-service attack. 123 return (peeraddress.ip4Addr() & mask) == auth_peer;
75 if ( !ok ) { 124}
76 QMessageBox::warning(0,tr("Security"), 125
77 tr("<p>An attempt to access this device from %1 has been denied.") 126bool SyncAuthentication::checkUser( const QString& user )
78 .arg(peeraddress.toString())); 127{
79 } 128 if ( user.isEmpty() ) return FALSE;
80 */ 129 QString euser = loginName();
81 return ok; 130 return user == euser;
82} 131}
83 132
84ServerPI::ServerPI( int socket, QObject *parent, const char* name ) 133bool SyncAuthentication::checkPassword( const QString& password )
134{
135#ifdef ALLOW_UNIX_USER_FTP
136 // First, check system password...
137
138 struct passwd *pw = 0;
139 struct spwd *spw = 0;
140
141 pw = getpwuid( geteuid() );
142 spw = getspnam( pw->pw_name );
143
144 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
145 if ( cpwd == "x" && spw )
146 cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
147
148 // Note: some systems use more than crypt for passwords.
149 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
150 if ( cpwd == cpassword )
151 return TRUE;
152#endif
153
154 static int lastdenial=0;
155 static int denials=0;
156 int now = time(0);
157
158 // Detect old Qtopia Desktop (no password)
159 if ( password.isEmpty() ) {
160 if ( denials < 1 || now > lastdenial+600 ) {
161 QMessageBox::warning( 0,tr("Sync Connection"),
162 tr("<p>An unauthorized system is requesting access to this device."
163 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, "
164 "please upgrade."),
165 tr("Deny") );
166 denials++;
167 lastdenial=now;
168 }
169 return FALSE;
170 }
171
172 // Second, check sync password...
173 if ( password.left(6) == "Qtopia" ) {
174 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) );
175 Config cfg("Security");
176 cfg.setGroup("Sync");
177 QString pwds = cfg.readEntry("Passwords");
178 if ( QStringList::split(QChar(' '),pwds).contains(cpassword) )
179 return TRUE;
180
181 // Unrecognized system. Be careful...
182
183 if ( (denials > 2 && now < lastdenial+600)
184 || QMessageBox::warning(0,tr("Sync Connection"),
185 tr("<p>An unrecognized system is requesting access to this device."
186 "<p>If you have just initiated a Sync for the first time, this is normal."),
187 tr("Allow"),tr("Deny"))==1 )
188 {
189 denials++;
190 lastdenial=now;
191 return FALSE;
192 } else {
193 denials=0;
194 cfg.writeEntry("Passwords",pwds+" "+cpassword);
195 return TRUE;
196 }
197 }
198
199 return FALSE;
200}
201
202
203ServerPI::ServerPI( int socket, QObject *parent , const char* name )
85 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) 204 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 )
86{ 205{
87 state = Connected; 206 state = Connected;
88 207
89 setSocket( socket ); 208 setSocket( socket );
90 209
91 peerport = peerPort(); 210 peerport = peerPort();
92 peeraddress = peerAddress(); 211 peeraddress = peerAddress();
93 212
94#ifndef INSECURE 213#ifndef INSECURE
95 if ( !accessAuthorized(peeraddress) ) { 214 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
96 state = Forbidden; 215 state = Forbidden;
97 startTimer( 0 ); 216 startTimer( 0 );
98 } else 217 } else
99 #endif 218 #endif
100 { 219 {
101 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 220 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
102 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 221 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
103 222
104 passiv = FALSE; 223 passiv = FALSE;
105 for( int i = 0; i < 4; i++ ) 224 for( int i = 0; i < 4; i++ )
106 wait[i] = FALSE; 225 wait[i] = FALSE;
107 226
108 send( "220 Qtopia transfer service ready!" ); 227 send( "220 Qtopia " QPE_VERSION " FTP Server" );
109 state = Wait_USER; 228 state = Wait_USER;
110 229
111 dtp = new ServerDTP( this ); 230 dtp = new ServerDTP( this );
112 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); 231 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) );
113 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); 232 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) );
114 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); 233 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) );
115 234
116 235
117 directory = QDir::currentDirPath(); 236 directory = QDir::currentDirPath();
118 237
119 static int p = 1024; 238 static int p = 1024;
120 239
121 while ( !serversocket || !serversocket->ok() ) { 240 while ( !serversocket || !serversocket->ok() ) {
122 delete serversocket; 241 delete serversocket;
123 serversocket = new ServerSocket( ++p, this ); 242 serversocket = new ServerSocket( ++p, this );
124 } 243 }
125 connect( serversocket, SIGNAL( newIncomming( int ) ), 244 connect( serversocket, SIGNAL( newIncomming( int ) ),
126 SLOT( newConnection( int ) ) ); 245 SLOT( newConnection( int ) ) );
127 } 246 }
128} 247}
129 248
130ServerPI::~ServerPI() 249ServerPI::~ServerPI()
131{ 250{
132 251
133} 252}
134 253
135void ServerPI::connectionClosed() 254void ServerPI::connectionClosed()
136{ 255{
137 // qDebug( "Debug: Connection closed" ); 256 // qDebug( "Debug: Connection closed" );
138 delete this; 257 delete this;
139} 258}
140 259
141void ServerPI::send( const QString& msg ) 260void ServerPI::send( const QString& msg )
142{ 261{
143 QTextStream os( this ); 262 QTextStream os( this );
144 os << msg << endl; 263 os << msg << endl;
145 //qDebug( "Reply: %s", msg.latin1() ); 264 //qDebug( "Reply: %s", msg.latin1() );
146} 265}
147 266
148void ServerPI::read() 267void ServerPI::read()
149{ 268{
150 while ( canReadLine() ) 269 while ( canReadLine() )
151 process( readLine().stripWhiteSpace() ); 270 process( readLine().stripWhiteSpace() );
152} 271}
153 272
154bool ServerPI::checkUser( const QString& user )
155{
156 if ( user.isEmpty() ) return FALSE;
157
158 struct passwd *pw;
159 pw = getpwuid( geteuid() );
160 QString euser = QString::fromLocal8Bit( pw->pw_name );
161 return user == euser;
162}
163
164bool ServerPI::checkPassword( const QString& /* password */ )
165{
166 // ### HACK for testing on local host
167 return true;
168
169 /*
170 struct passwd *pw = 0;
171 struct spwd *spw = 0;
172
173 pw = getpwuid( geteuid() );
174 spw = getspnam( pw->pw_name );
175
176 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
177 if ( cpwd == "x" && spw )
178 cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
179
180 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
181 return cpwd == cpassword;
182*/
183}
184
185bool ServerPI::checkReadFile( const QString& file ) 273bool ServerPI::checkReadFile( const QString& file )
186{ 274{
187 QString filename; 275 QString filename;
188 276
189 if ( file[0] != "/" ) 277 if ( file[0] != "/" )
190 filename = directory.path() + "/" + file; 278 filename = directory.path() + "/" + file;
191 else 279 else
192 filename = file; 280 filename = file;
193 281
194 QFileInfo fi( filename ); 282 QFileInfo fi( filename );
195 return ( fi.exists() && fi.isReadable() ); 283 return ( fi.exists() && fi.isReadable() );
196} 284}
197 285
198bool ServerPI::checkWriteFile( const QString& file ) 286bool ServerPI::checkWriteFile( const QString& file )
199{ 287{
200 QString filename; 288 QString filename;
201 289
202 if ( file[0] != "/" ) 290 if ( file[0] != "/" )
203 filename = directory.path() + "/" + file; 291 filename = directory.path() + "/" + file;
204 else 292 else
205 filename = file; 293 filename = file;
206 294
207 QFileInfo fi( filename ); 295 QFileInfo fi( filename );
208 296
209 if ( fi.exists() ) 297 if ( fi.exists() )
210 if ( !QFile( filename ).remove() ) 298 if ( !QFile( filename ).remove() )
211 return FALSE; 299 return FALSE;
212 return TRUE; 300 return TRUE;
213} 301}
214 302
215void ServerPI::process( const QString& message ) 303void ServerPI::process( const QString& message )
216{ 304{
217 //qDebug( "Command: %s", message.latin1() ); 305 //qDebug( "Command: %s", message.latin1() );
218 306
219 // split message using "," as separator 307 // split message using "," as separator
220 QStringList msg = QStringList::split( " ", message ); 308 QStringList msg = QStringList::split( " ", message );
221 if ( msg.isEmpty() ) return; 309 if ( msg.isEmpty() ) return;
222 310
223 // command token 311 // command token
224 QString cmd = msg[0].upper(); 312 QString cmd = msg[0].upper();
225 313
226 // argument token 314 // argument token
227 QString arg; 315 QString arg;
228 if ( msg.count() >= 2 ) 316 if ( msg.count() >= 2 )
229 arg = msg[1]; 317 arg = msg[1];
230 318
231 // full argument string 319 // full argument string
232 QString args; 320 QString args;
233 if ( msg.count() >= 2 ) { 321 if ( msg.count() >= 2 ) {
234 QStringList copy( msg ); 322 QStringList copy( msg );
235 // FIXME: for Qt3 323 // FIXME: for Qt3
236 // copy.pop_front() 324 // copy.pop_front()
237 copy.remove( copy.begin() ); 325 copy.remove( copy.begin() );
238 args = copy.join( " " ); 326 args = copy.join( " " );
239 } 327 }
240 328
241 //qDebug( "args: %s", args.latin1() ); 329 //qDebug( "args: %s", args.latin1() );
242 330
243 // we always respond to QUIT, regardless of state 331 // we always respond to QUIT, regardless of state
244 if ( cmd == "QUIT" ) { 332 if ( cmd == "QUIT" ) {
245 send( "211 Good bye!" ); 333 send( "211 Good bye!" );
246 delete this; 334 delete this;
247 return; 335 return;
248 } 336 }
249 337
250 // connected to client 338 // connected to client
251 if ( Connected == state ) 339 if ( Connected == state )
252 return; 340 return;
253 341
254 // waiting for user name 342 // waiting for user name
255 if ( Wait_USER == state ) { 343 if ( Wait_USER == state ) {
256 344
257 if ( cmd != "USER" || msg.count() < 2 || !checkUser( arg ) ) { 345 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
258 send( "530 Please login with USER and PASS" ); 346 send( "530 Please login with USER and PASS" );
259 return; 347 return;
260 } 348 }
261 send( "331 User name ok, need password" ); 349 send( "331 User name ok, need password" );
262 state = Wait_PASS; 350 state = Wait_PASS;
263 return; 351 return;
264 } 352 }
265 353
266 // waiting for password 354 // waiting for password
267 if ( Wait_PASS == state ) { 355 if ( Wait_PASS == state ) {
268 356
269 if ( cmd != "PASS" || !checkPassword( arg ) ) { 357 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
270 //if ( cmd != "PASS" || msg.count() < 2 || !checkPassword( arg ) ) {
271 send( "530 Please login with USER and PASS" ); 358 send( "530 Please login with USER and PASS" );
272 return; 359 return;
273 } 360 }
274 send( "230 User logged in, proceed" ); 361 send( "230 User logged in, proceed" );
275 state = Ready; 362 state = Ready;
276 return; 363 return;
277 } 364 }
278 365
279 // ACCESS CONTROL COMMANDS 366 // ACCESS CONTROL COMMANDS
280 367
281 368
282 // account (ACCT) 369 // account (ACCT)
283 if ( cmd == "ACCT" ) { 370 if ( cmd == "ACCT" ) {
284 // even wu-ftp does not support it 371 // even wu-ftp does not support it
285 send( "502 Command not implemented" ); 372 send( "502 Command not implemented" );
286 } 373 }
287 374
288 // change working directory (CWD) 375 // change working directory (CWD)
289 else if ( cmd == "CWD" ) { 376 else if ( cmd == "CWD" ) {
290 377
291 if ( !args.isEmpty() ) { 378 if ( !args.isEmpty() ) {
292 if ( directory.cd( args, TRUE ) ) 379 if ( directory.cd( args, TRUE ) )
293 send( "250 Requested file action okay, completed" ); 380 send( "250 Requested file action okay, completed" );
294 else 381 else
295 send( "550 Requested action not taken" ); 382 send( "550 Requested action not taken" );
296 } 383 }
297 else 384 else
298 send( "500 Syntax error, command unrecognized" ); 385 send( "500 Syntax error, command unrecognized" );
299 } 386 }
300 387
301 // change to parent directory (CDUP) 388 // change to parent directory (CDUP)
302 else if ( cmd == "CDUP" ) { 389 else if ( cmd == "CDUP" ) {
303 if ( directory.cdUp() ) 390 if ( directory.cdUp() )
304 send( "250 Requested file action okay, completed" ); 391 send( "250 Requested file action okay, completed" );
305 else 392 else
306 send( "550 Requested action not taken" ); 393 send( "550 Requested action not taken" );
307 } 394 }
308 395
309 // structure mount (SMNT) 396 // structure mount (SMNT)
310 else if ( cmd == "SMNT" ) { 397 else if ( cmd == "SMNT" ) {
311 // even wu-ftp does not support it 398 // even wu-ftp does not support it
312 send( "502 Command not implemented" ); 399 send( "502 Command not implemented" );
313 } 400 }
314 401
315 // reinitialize (REIN) 402 // reinitialize (REIN)
316 else if ( cmd == "REIN" ) { 403 else if ( cmd == "REIN" ) {
317 // even wu-ftp does not support it 404 // even wu-ftp does not support it
318 send( "502 Command not implemented" ); 405 send( "502 Command not implemented" );
319 } 406 }
320 407
321 408
322 // TRANSFER PARAMETER COMMANDS 409 // TRANSFER PARAMETER COMMANDS
323 410
324 411
325 // data port (PORT) 412 // data port (PORT)
326 else if ( cmd == "PORT" ) { 413 else if ( cmd == "PORT" ) {
327 if ( parsePort( arg ) ) 414 if ( parsePort( arg ) )
328 send( "200 Command okay" ); 415 send( "200 Command okay" );
329 else 416 else
330 send( "500 Syntax error, command unrecognized" ); 417 send( "500 Syntax error, command unrecognized" );
331 } 418 }
332 419
333 // passive (PASV) 420 // passive (PASV)
334 else if ( cmd == "PASV" ) { 421 else if ( cmd == "PASV" ) {
335 passiv = TRUE; 422 passiv = TRUE;
336 send( "227 Entering Passive Mode (" 423 send( "227 Entering Passive Mode ("
337 + address().toString().replace( QRegExp( "\\." ), "," ) + "," 424 + address().toString().replace( QRegExp( "\\." ), "," ) + ","
338 + QString::number( ( serversocket->port() ) >> 8 ) + "," 425 + QString::number( ( serversocket->port() ) >> 8 ) + ","
339 + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); 426 + QString::number( ( serversocket->port() ) & 0xFF ) +")" );
340 } 427 }
341 428
342 // representation type (TYPE) 429 // representation type (TYPE)
343 else if ( cmd == "TYPE" ) { 430 else if ( cmd == "TYPE" ) {
344 if ( arg.upper() == "A" || arg.upper() == "I" ) 431 if ( arg.upper() == "A" || arg.upper() == "I" )
345 send( "200 Command okay" ); 432 send( "200 Command okay" );
346 else 433 else
347 send( "504 Command not implemented for that parameter" ); 434 send( "504 Command not implemented for that parameter" );
348 } 435 }
349 436
350 // file structure (STRU) 437 // file structure (STRU)
351 else if ( cmd == "STRU" ) { 438 else if ( cmd == "STRU" ) {
352 if ( arg.upper() == "F" ) 439 if ( arg.upper() == "F" )
353 send( "200 Command okay" ); 440 send( "200 Command okay" );
354 else 441 else
355 send( "504 Command not implemented for that parameter" ); 442 send( "504 Command not implemented for that parameter" );
356 } 443 }
357 444
358 // transfer mode (MODE) 445 // transfer mode (MODE)
359 else if ( cmd == "MODE" ) { 446 else if ( cmd == "MODE" ) {
360 if ( arg.upper() == "S" ) 447 if ( arg.upper() == "S" )
361 send( "200 Command okay" ); 448 send( "200 Command okay" );
362 else 449 else
363 send( "504 Command not implemented for that parameter" ); 450 send( "504 Command not implemented for that parameter" );
364 } 451 }
365 452
366 453
367 // FTP SERVICE COMMANDS 454 // FTP SERVICE COMMANDS
368 455
369 456
370 // retrieve (RETR) 457 // retrieve (RETR)
371 else if ( cmd == "RETR" ) 458 else if ( cmd == "RETR" )
372 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) 459 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) )
373 || backupRestoreGzip( absFilePath( args ) ) ) { 460 || backupRestoreGzip( absFilePath( args ) ) ) {
374 send( "150 File status okay" ); 461 send( "150 File status okay" );
375 sendFile( absFilePath( args ) ); 462 sendFile( absFilePath( args ) );
376 } 463 }
377 else { 464 else {
378 qDebug("550 Requested action not taken"); 465 qDebug("550 Requested action not taken");
379 send( "550 Requested action not taken" ); 466 send( "550 Requested action not taken" );
380 } 467 }
381 468
382 // store (STOR) 469 // store (STOR)
383 else if ( cmd == "STOR" ) 470 else if ( cmd == "STOR" )
384 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { 471 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) {
385 send( "150 File status okay" ); 472 send( "150 File status okay" );
386 retrieveFile( absFilePath( args ) ); 473 retrieveFile( absFilePath( args ) );
387 } 474 }
388 else 475 else
389 send( "550 Requested action not taken" ); 476 send( "550 Requested action not taken" );
390 477
391 // store unique (STOU) 478 // store unique (STOU)
392 else if ( cmd == "STOU" ) { 479 else if ( cmd == "STOU" ) {
393 send( "502 Command not implemented" ); 480 send( "502 Command not implemented" );
394 } 481 }
395 482
396 // append (APPE) 483 // append (APPE)
397 else if ( cmd == "APPE" ) { 484 else if ( cmd == "APPE" ) {
398 send( "502 Command not implemented" ); 485 send( "502 Command not implemented" );
399 } 486 }
400 487
401 // allocate (ALLO) 488 // allocate (ALLO)
402 else if ( cmd == "ALLO" ) { 489 else if ( cmd == "ALLO" ) {
403 send( "200 Command okay" ); 490 send( "200 Command okay" );
404 } 491 }
405 492
406 // restart (REST) 493 // restart (REST)
407 else if ( cmd == "REST" ) { 494 else if ( cmd == "REST" ) {
408 send( "502 Command not implemented" ); 495 send( "502 Command not implemented" );
409 } 496 }
410 497
411 // rename from (RNFR) 498 // rename from (RNFR)
412 else if ( cmd == "RNFR" ) { 499 else if ( cmd == "RNFR" ) {
413 renameFrom = QString::null; 500 renameFrom = QString::null;
414 if ( args.isEmpty() ) 501 if ( args.isEmpty() )
415 send( "500 Syntax error, command unrecognized" ); 502 send( "500 Syntax error, command unrecognized" );
416 else { 503 else {
417 QFile file( absFilePath( args ) ); 504 QFile file( absFilePath( args ) );
418 if ( file.exists() ) { 505 if ( file.exists() ) {
419 send( "350 File exists, ready for destination name" ); 506 send( "350 File exists, ready for destination name" );
420 renameFrom = absFilePath( args ); 507 renameFrom = absFilePath( args );
421 } 508 }
422 else 509 else
423 send( "550 Requested action not taken" ); 510 send( "550 Requested action not taken" );
424 } 511 }
425 } 512 }
426 513
427 // rename to (RNTO) 514 // rename to (RNTO)
428 else if ( cmd == "RNTO" ) { 515 else if ( cmd == "RNTO" ) {
429 if ( lastCommand != "RNFR" ) 516 if ( lastCommand != "RNFR" )
430 send( "503 Bad sequence of commands" ); 517 send( "503 Bad sequence of commands" );
431 else if ( args.isEmpty() ) 518 else if ( args.isEmpty() )
432 send( "500 Syntax error, command unrecognized" ); 519 send( "500 Syntax error, command unrecognized" );
433 else { 520 else {
434 QDir dir( absFilePath( args ) ); 521 QDir dir( absFilePath( args ) );
435 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) 522 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) )
436 send( "250 Requested file action okay, completed." ); 523 send( "250 Requested file action okay, completed." );
437 else 524 else
438 send( "550 Requested action not taken" ); 525 send( "550 Requested action not taken" );
439 } 526 }
440 } 527 }
441 528
442 // abort (ABOR) 529 // abort (ABOR)
443 else if ( cmd.contains( "ABOR" ) ) { 530 else if ( cmd.contains( "ABOR" ) ) {
444 dtp->close(); 531 dtp->close();
445 if ( dtp->dtpMode() != ServerDTP::Idle ) 532 if ( dtp->dtpMode() != ServerDTP::Idle )
446 send( "426 Connection closed; transfer aborted" ); 533 send( "426 Connection closed; transfer aborted" );
447 else 534 else
448 send( "226 Closing data connection" ); 535 send( "226 Closing data connection" );
449 } 536 }
450 537
451 // delete (DELE) 538 // delete (DELE)
452 else if ( cmd == "DELE" ) { 539 else if ( cmd == "DELE" ) {
453 if ( args.isEmpty() ) 540 if ( args.isEmpty() )
454 send( "500 Syntax error, command unrecognized" ); 541 send( "500 Syntax error, command unrecognized" );
455 else { 542 else {
456 QFile file( absFilePath( args ) ) ; 543 QFile file( absFilePath( args ) ) ;
457 if ( file.remove() ) 544 if ( file.remove() ) {
458 send( "250 Requested file action okay, completed" ); 545 send( "250 Requested file action okay, completed" );
459 else 546 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
547 e << file.name();
548 } else {
460 send( "550 Requested action not taken" ); 549 send( "550 Requested action not taken" );
550 }
461 } 551 }
462 } 552 }
463 553
464 // remove directory (RMD) 554 // remove directory (RMD)
465 else if ( cmd == "RMD" ) { 555 else if ( cmd == "RMD" ) {
466 if ( args.isEmpty() ) 556 if ( args.isEmpty() )
467 send( "500 Syntax error, command unrecognized" ); 557 send( "500 Syntax error, command unrecognized" );
468 else { 558 else {
469 QDir dir; 559 QDir dir;
470 if ( dir.rmdir( absFilePath( args ), TRUE ) ) 560 if ( dir.rmdir( absFilePath( args ), TRUE ) )
471 send( "250 Requested file action okay, completed" ); 561 send( "250 Requested file action okay, completed" );
472 else 562 else
473 send( "550 Requested action not taken" ); 563 send( "550 Requested action not taken" );
474 } 564 }
475 } 565 }
476 566
477 // make directory (MKD) 567 // make directory (MKD)
478 else if ( cmd == "MKD" ) { 568 else if ( cmd == "MKD" ) {
479 if ( args.isEmpty() ) { 569 if ( args.isEmpty() ) {
480 qDebug(" Error: no arg"); 570 qDebug(" Error: no arg");
481 send( "500 Syntax error, command unrecognized" ); 571 send( "500 Syntax error, command unrecognized" );
482 } 572 }
483 else { 573 else {
484 QDir dir; 574 QDir dir;
485 if ( dir.mkdir( absFilePath( args ), TRUE ) ) 575 if ( dir.mkdir( absFilePath( args ), TRUE ) )
486 send( "250 Requested file action okay, completed." ); 576 send( "250 Requested file action okay, completed." );
487 else 577 else
488 send( "550 Requested action not taken" ); 578 send( "550 Requested action not taken" );
489 } 579 }
490 } 580 }
491 581
492 // print working directory (PWD) 582 // print working directory (PWD)
493 else if ( cmd == "PWD" ) { 583 else if ( cmd == "PWD" ) {
494 send( "257 \"" + directory.path() +"\"" ); 584 send( "257 \"" + directory.path() +"\"" );
495 } 585 }
496 586
497 // list (LIST) 587 // list (LIST)
498 else if ( cmd == "LIST" ) { 588 else if ( cmd == "LIST" ) {
499 if ( sendList( absFilePath( args ) ) ) 589 if ( sendList( absFilePath( args ) ) )
500 send( "150 File status okay" ); 590 send( "150 File status okay" );
501 else 591 else
502 send( "500 Syntax error, command unrecognized" ); 592 send( "500 Syntax error, command unrecognized" );
503 } 593 }
504 594
505 // size (SIZE) 595 // size (SIZE)
506 else if ( cmd == "SIZE" ) { 596 else if ( cmd == "SIZE" ) {
507 QString filePath = absFilePath( args ); 597 QString filePath = absFilePath( args );
508 QFileInfo fi( filePath ); 598 QFileInfo fi( filePath );
509 bool gzipfile = backupRestoreGzip( filePath ); 599 bool gzipfile = backupRestoreGzip( filePath );
510 if ( !fi.exists() && !gzipfile ) 600 if ( !fi.exists() && !gzipfile )
511 send( "500 Syntax error, command unrecognized" ); 601 send( "500 Syntax error, command unrecognized" );
512 else { 602 else {
513 if ( !gzipfile ) 603 if ( !gzipfile )
514 send( "213 " + QString::number( fi.size() ) ); 604 send( "213 " + QString::number( fi.size() ) );
515 else { 605 else {
516 Process duproc( QString("du") ); 606 Process duproc( QString("du") );
517 duproc.addArgument("-s"); 607 duproc.addArgument("-s");
518 QString in, out; 608 QString in, out;
519 if ( !duproc.exec(in, out) ) { 609 if ( !duproc.exec(in, out) ) {
520 qDebug("du process failed; just sending back 1K"); 610 qDebug("du process failed; just sending back 1K");
521 send( "213 1024"); 611 send( "213 1024");
522 } 612 }
523 else { 613 else {
524 QString size = out.left( out.find("\t") ); 614 QString size = out.left( out.find("\t") );
525 int guess = size.toInt()/5; 615 int guess = size.toInt()/5;
526 if ( filePath.contains("doc") ) 616 if ( filePath.contains("doc") )
527 guess *= 1000; 617 guess *= 1000;
528 qDebug("sending back gzip guess of %d", guess); 618 qDebug("sending back gzip guess of %d", guess);
529 send( "213 " + QString::number(guess) ); 619 send( "213 " + QString::number(guess) );
530 } 620 }
531 } 621 }
532 } 622 }
533 } 623 }
534 // name list (NLST) 624 // name list (NLST)
535 else if ( cmd == "NLST" ) { 625 else if ( cmd == "NLST" ) {
536 send( "502 Command not implemented" ); 626 send( "502 Command not implemented" );
537 } 627 }
538 628
539 // site parameters (SITE) 629 // site parameters (SITE)
540 else if ( cmd == "SITE" ) { 630 else if ( cmd == "SITE" ) {
541 send( "502 Command not implemented" ); 631 send( "502 Command not implemented" );
542 } 632 }
543 633
544 // system (SYST) 634 // system (SYST)
545 else if ( cmd == "SYST" ) { 635 else if ( cmd == "SYST" ) {
546 send( "215 UNIX Type: L8" ); 636 send( "215 UNIX Type: L8" );
547 } 637 }
548 638
549 // status (STAT) 639 // status (STAT)
550 else if ( cmd == "STAT" ) { 640 else if ( cmd == "STAT" ) {
551 send( "502 Command not implemented" ); 641 send( "502 Command not implemented" );
552 } 642 }
553 643
554 // help (HELP ) 644 // help (HELP )
555 else if ( cmd == "HELP" ) { 645 else if ( cmd == "HELP" ) {
556 send( "502 Command not implemented" ); 646 send( "502 Command not implemented" );
557 } 647 }
558 648
559 // noop (NOOP) 649 // noop (NOOP)
560 else if ( cmd == "NOOP" ) { 650 else if ( cmd == "NOOP" ) {
561 send( "200 Command okay" ); 651 send( "200 Command okay" );
562 } 652 }
563 653
564 // not implemented 654 // not implemented
565 else 655 else
566 send( "502 Command not implemented" ); 656 send( "502 Command not implemented" );
567 657
568 lastCommand = cmd; 658 lastCommand = cmd;
569} 659}
570 660
571bool ServerPI::backupRestoreGzip( const QString &file ) 661bool ServerPI::backupRestoreGzip( const QString &file )
572{ 662{
573 return (file.find( "backup" ) != -1 && 663 return (file.find( "backup" ) != -1 &&
574 file.findRev( ".tgz" ) == (int)file.length()-4 ); 664 file.findRev( ".tgz" ) == (int)file.length()-4 );
575} 665}
576 666
577bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) 667bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets )
578{ 668{
579 if ( file.find( "backup" ) != -1 && 669 if ( file.find( "backup" ) != -1 &&
580 file.findRev( ".tgz" ) == (int)file.length()-4 ) { 670 file.findRev( ".tgz" ) == (int)file.length()-4 ) {
581 QFileInfo info( file ); 671 QFileInfo info( file );
582 targets = info.dirPath( TRUE ); 672 targets = info.dirPath( TRUE );
583 qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), 673 qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(),
584 targets.join(" ").latin1() ); 674 targets.join(" ").latin1() );
585 return true; 675 return true;
586 } 676 }
587 return false; 677 return false;
588} 678}
589 679
590void ServerPI::sendFile( const QString& file ) 680void ServerPI::sendFile( const QString& file )
591{ 681{
592 if ( passiv ) { 682 if ( passiv ) {
593 wait[SendFile] = TRUE; 683 wait[SendFile] = TRUE;
594 waitfile = file; 684 waitfile = file;
595 if ( waitsocket ) 685 if ( waitsocket )
596 newConnection( waitsocket ); 686 newConnection( waitsocket );
597 } 687 }
598 else { 688 else {
599 QStringList targets; 689 QStringList targets;
600 if ( backupRestoreGzip( file, targets ) ) 690 if ( backupRestoreGzip( file, targets ) )
601 dtp->sendGzipFile( file, targets, peeraddress, peerport ); 691 dtp->sendGzipFile( file, targets, peeraddress, peerport );
602 else dtp->sendFile( file, peeraddress, peerport ); 692 else dtp->sendFile( file, peeraddress, peerport );
603 } 693 }
604} 694}
605 695
606void ServerPI::retrieveFile( const QString& file ) 696void ServerPI::retrieveFile( const QString& file )
607{ 697{
608 if ( passiv ) { 698 if ( passiv ) {
609 wait[RetrieveFile] = TRUE; 699 wait[RetrieveFile] = TRUE;
610 waitfile = file; 700 waitfile = file;
611 if ( waitsocket ) 701 if ( waitsocket )
612 newConnection( waitsocket ); 702 newConnection( waitsocket );
613 } 703 }
614 else { 704 else {
615 QStringList targets; 705 QStringList targets;
616 if ( backupRestoreGzip( file, targets ) ) 706 if ( backupRestoreGzip( file, targets ) )
617 dtp->retrieveGzipFile( file, peeraddress, peerport ); 707 dtp->retrieveGzipFile( file, peeraddress, peerport );
618 else 708 else
619 dtp->retrieveFile( file, peeraddress, peerport ); 709 dtp->retrieveFile( file, peeraddress, peerport );
620 } 710 }
621} 711}
622 712
623bool ServerPI::parsePort( const QString& pp ) 713bool ServerPI::parsePort( const QString& pp )
624{ 714{
625 QStringList p = QStringList::split( ",", pp ); 715 QStringList p = QStringList::split( ",", pp );
626 if ( p.count() != 6 ) return FALSE; 716 if ( p.count() != 6 ) return FALSE;
627 717
628 // h1,h2,h3,h4,p1,p2 718 // h1,h2,h3,h4,p1,p2
629 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + 719 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) +
630 ( p[2].toInt() << 8 ) + p[3].toInt() ); 720 ( p[2].toInt() << 8 ) + p[3].toInt() );
631 peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); 721 peerport = ( p[4].toInt() << 8 ) + p[5].toInt();
632 return TRUE; 722 return TRUE;
633} 723}
634 724
635void ServerPI::dtpCompleted() 725void ServerPI::dtpCompleted()
636{ 726{
637 dtp->close();
638 waitsocket = 0;
639 send( "226 Closing data connection, file transfer successful" ); 727 send( "226 Closing data connection, file transfer successful" );
728 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) {
729 QString fn = dtp->fileName();
730 if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) {
731 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
732 e << fn;
733 }
734 }
735 waitsocket = 0;
736 dtp->close();
640} 737}
641 738
642void ServerPI::dtpFailed() 739void ServerPI::dtpFailed()
643{ 740{
644 dtp->close(); 741 dtp->close();
645 waitsocket = 0; 742 waitsocket = 0;
646 send( "451 Requested action aborted: local error in processing" ); 743 send( "451 Requested action aborted: local error in processing" );
647} 744}
648 745
649void ServerPI::dtpError( int ) 746void ServerPI::dtpError( int )
650{ 747{
651 dtp->close(); 748 dtp->close();
652 waitsocket = 0; 749 waitsocket = 0;
653 send( "451 Requested action aborted: local error in processing" ); 750 send( "451 Requested action aborted: local error in processing" );
654} 751}
655 752
656bool ServerPI::sendList( const QString& arg ) 753bool ServerPI::sendList( const QString& arg )
657{ 754{
658 QByteArray listing; 755 QByteArray listing;
659 QBuffer buffer( listing ); 756 QBuffer buffer( listing );
660 757
661 if ( !buffer.open( IO_WriteOnly ) ) 758 if ( !buffer.open( IO_WriteOnly ) )
662 return FALSE; 759 return FALSE;
663 760
664 QTextStream ts( &buffer ); 761 QTextStream ts( &buffer );
665 QString fn = arg; 762 QString fn = arg;
666 763
667 if ( fn.isEmpty() ) 764 if ( fn.isEmpty() )
668 fn = directory.path(); 765 fn = directory.path();
669 766
670 QFileInfo fi( fn ); 767 QFileInfo fi( fn );
671 if ( !fi.exists() ) return FALSE; 768 if ( !fi.exists() ) return FALSE;
672 769
673 // return file listing 770 // return file listing
674 if ( fi.isFile() ) { 771 if ( fi.isFile() ) {
675 ts << fileListing( &fi ) << endl; 772 ts << fileListing( &fi ) << endl;
676 } 773 }
677 774
678 // return directory listing 775 // return directory listing
679 else if ( fi.isDir() ) { 776 else if ( fi.isDir() ) {
680 QDir dir( fn ); 777 QDir dir( fn );
681 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); 778 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden );
682 779
683 QFileInfoListIterator it( *list ); 780 QFileInfoListIterator it( *list );
684 QFileInfo *info; 781 QFileInfo *info;
685 782
686 unsigned long total = 0; 783 unsigned long total = 0;
687 while ( ( info = it.current() ) ) { 784 while ( ( info = it.current() ) ) {
688 if ( info->fileName() != "." && info->fileName() != ".." ) 785 if ( info->fileName() != "." && info->fileName() != ".." )
689 total += info->size(); 786 total += info->size();
690 ++it; 787 ++it;
691 } 788 }
692 789
693 ts << "total " << QString::number( total / 1024 ) << endl; 790 ts << "total " << QString::number( total / 1024 ) << endl;
694 791
695 it.toFirst(); 792 it.toFirst();
696 while ( ( info = it.current() ) ) { 793 while ( ( info = it.current() ) ) {
697 if ( info->fileName() == "." || info->fileName() == ".." ) { 794 if ( info->fileName() == "." || info->fileName() == ".." ) {
698 ++it; 795 ++it;
699 continue; 796 continue;
700 } 797 }
701 ts << fileListing( info ) << endl; 798 ts << fileListing( info ) << endl;
702 ++it; 799 ++it;
703 } 800 }
704 } 801 }
705 802
706 if ( passiv ) { 803 if ( passiv ) {
707 waitarray = buffer.buffer(); 804 waitarray = buffer.buffer();
708 wait[SendByteArray] = TRUE; 805 wait[SendByteArray] = TRUE;
709 if ( waitsocket ) 806 if ( waitsocket )
710 newConnection( waitsocket ); 807 newConnection( waitsocket );
711 } 808 }
712 else 809 else
713 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); 810 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport );
714 return TRUE; 811 return TRUE;
715} 812}
716 813
717QString ServerPI::fileListing( QFileInfo *info ) 814QString ServerPI::fileListing( QFileInfo *info )
718{ 815{
719 if ( !info ) return QString::null; 816 if ( !info ) return QString::null;
720 QString s; 817 QString s;
721 818
722 // type char 819 // type char
723 if ( info->isDir() ) 820 if ( info->isDir() )
724 s += "d"; 821 s += "d";
725 else if ( info->isSymLink() ) 822 else if ( info->isSymLink() )
726 s += "l"; 823 s += "l";
727 else 824 else
728 s += "-"; 825 s += "-";
729 826
730 // permisson string 827 // permisson string
731 s += permissionString( info ) + " "; 828 s += permissionString( info ) + " ";
732 829
733 // number of hardlinks 830 // number of hardlinks
734 int subdirs = 1; 831 int subdirs = 1;
735 832
736 if ( info->isDir() ) 833 if ( info->isDir() )
737 subdirs = 2; 834 subdirs = 2;
738 // FIXME : this is to slow 835 // FIXME : this is to slow
739 //if ( info->isDir() ) 836 //if ( info->isDir() )
740 //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); 837 //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count();
741 838
742 s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; 839 s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " ";
743 840
744 // owner 841 // owner
745 s += info->owner().leftJustify( 8, ' ', TRUE ) + " "; 842 s += info->owner().leftJustify( 8, ' ', TRUE ) + " ";
746 843
747 // group 844 // group
748 s += info->group().leftJustify( 8, ' ', TRUE ) + " "; 845 s += info->group().leftJustify( 8, ' ', TRUE ) + " ";
749 846
750 // file size in bytes 847 // file size in bytes
751 s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; 848 s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " ";
752 849
753 // last modified date 850 // last modified date
754 QDate date = info->lastModified().date(); 851 QDate date = info->lastModified().date();
755 QTime time = info->lastModified().time(); 852 QTime time = info->lastModified().time();
756 s += date.monthName( date.month() ) + " " 853 s += date.monthName( date.month() ) + " "
757 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " 854 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " "
758 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" 855 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":"
759 + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; 856 + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " ";
760 857
761 // file name 858 // file name
762 s += info->fileName(); 859 s += info->fileName();
763 860
764 return s; 861 return s;
765} 862}
766 863
767QString ServerPI::permissionString( QFileInfo *info ) 864QString ServerPI::permissionString( QFileInfo *info )
768{ 865{
769 if ( !info ) return QString( "---------" ); 866 if ( !info ) return QString( "---------" );
770 QString s; 867 QString s;
771 868
772 // user 869 // user
773 if ( info->permission( QFileInfo::ReadUser ) ) s += "r"; 870 if ( info->permission( QFileInfo::ReadUser ) ) s += "r";
774 else s += "-"; 871 else s += "-";
775 if ( info->permission( QFileInfo::WriteUser ) ) s += "w"; 872 if ( info->permission( QFileInfo::WriteUser ) ) s += "w";
776 else s += "-"; 873 else s += "-";
777 if ( info->permission( QFileInfo::ExeUser ) ) s += "x"; 874 if ( info->permission( QFileInfo::ExeUser ) ) s += "x";
778 else s += "-"; 875 else s += "-";
779 876
780 // group 877 // group
781 if ( info->permission( QFileInfo::ReadGroup ) ) s += "r"; 878 if ( info->permission( QFileInfo::ReadGroup ) ) s += "r";
782 else s += "-"; 879 else s += "-";
783 if ( info->permission( QFileInfo::WriteGroup ) )s += "w"; 880 if ( info->permission( QFileInfo::WriteGroup ) )s += "w";
784 else s += "-"; 881 else s += "-";
785 if ( info->permission( QFileInfo::ExeGroup ) ) s += "x"; 882 if ( info->permission( QFileInfo::ExeGroup ) ) s += "x";
786 else s += "-"; 883 else s += "-";
787 884
788 // exec 885 // exec
789 if ( info->permission( QFileInfo::ReadOther ) ) s += "r"; 886 if ( info->permission( QFileInfo::ReadOther ) ) s += "r";
790 else s += "-"; 887 else s += "-";
791 if ( info->permission( QFileInfo::WriteOther ) ) s += "w"; 888 if ( info->permission( QFileInfo::WriteOther ) ) s += "w";
792 else s += "-"; 889 else s += "-";
793 if ( info->permission( QFileInfo::ExeOther ) ) s += "x"; 890 if ( info->permission( QFileInfo::ExeOther ) ) s += "x";
794 else s += "-"; 891 else s += "-";
795 892
796 return s; 893 return s;
797} 894}
798 895
799void ServerPI::newConnection( int socket ) 896void ServerPI::newConnection( int socket )
800{ 897{
801 //qDebug( "New incomming connection" ); 898 //qDebug( "New incomming connection" );
802 899
803 if ( !passiv ) return; 900 if ( !passiv ) return;
804 901
805 if ( wait[SendFile] ) { 902 if ( wait[SendFile] ) {
806 QStringList targets; 903 QStringList targets;
807 if ( backupRestoreGzip( waitfile, targets ) ) 904 if ( backupRestoreGzip( waitfile, targets ) )
808 dtp->sendGzipFile( waitfile, targets ); 905 dtp->sendGzipFile( waitfile, targets );
809 else 906 else
810 dtp->sendFile( waitfile ); 907 dtp->sendFile( waitfile );
811 dtp->setSocket( socket ); 908 dtp->setSocket( socket );
812 } 909 }
813 else if ( wait[RetrieveFile] ) { 910 else if ( wait[RetrieveFile] ) {
814 qDebug("check retrieve file"); 911 qDebug("check retrieve file");
815 if ( backupRestoreGzip( waitfile ) ) 912 if ( backupRestoreGzip( waitfile ) )
816 dtp->retrieveGzipFile( waitfile ); 913 dtp->retrieveGzipFile( waitfile );
817 else 914 else
818 dtp->retrieveFile( waitfile ); 915 dtp->retrieveFile( waitfile );
819 dtp->setSocket( socket ); 916 dtp->setSocket( socket );
820 } 917 }
821 else if ( wait[SendByteArray] ) { 918 else if ( wait[SendByteArray] ) {
822 dtp->sendByteArray( waitarray ); 919 dtp->sendByteArray( waitarray );
823 dtp->setSocket( socket ); 920 dtp->setSocket( socket );
824 } 921 }
825 else if ( wait[RetrieveByteArray] ) { 922 else if ( wait[RetrieveByteArray] ) {
826 qDebug("retrieve byte array"); 923 qDebug("retrieve byte array");
827 dtp->retrieveByteArray(); 924 dtp->retrieveByteArray();
828 dtp->setSocket( socket ); 925 dtp->setSocket( socket );
829 } 926 }
830 else 927 else
831 waitsocket = socket; 928 waitsocket = socket;
832 929
833 for( int i = 0; i < 4; i++ ) 930 for( int i = 0; i < 4; i++ )
834 wait[i] = FALSE; 931 wait[i] = FALSE;
835} 932}
836 933
837QString ServerPI::absFilePath( const QString& file ) 934QString ServerPI::absFilePath( const QString& file )
838{ 935{
839 if ( file.isEmpty() ) return file; 936 if ( file.isEmpty() ) return file;
840 937
841 QString filepath( file ); 938 QString filepath( file );
842 if ( file[0] != "/" ) 939 if ( file[0] != "/" )
843 filepath = directory.path() + "/" + file; 940 filepath = directory.path() + "/" + file;
844 941
845 return filepath; 942 return filepath;
846} 943}
847 944
848 945
849void ServerPI::timerEvent( QTimerEvent * ) 946void ServerPI::timerEvent( QTimerEvent * )
850{ 947{
851 connectionClosed(); 948 connectionClosed();
852} 949}
853 950
854 951
855ServerDTP::ServerDTP( QObject *parent, const char* name ) 952ServerDTP::ServerDTP( QObject *parent = 0, const char* name = 0)
856 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), 953 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ),
857retrieveTargzProc( 0 ), gzipProc( 0 ) 954retrieveTargzProc( 0 ), gzipProc( 0 )
858{ 955{
859 956
860 connect( this, SIGNAL( connected() ), SLOT( connected() ) ); 957 connect( this, SIGNAL( connected() ), SLOT( connected() ) );
861 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 958 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
862 connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); 959 connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) );
863 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); 960 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) );
864 961
865 gzipProc = new QProcess( this, "gzipProc" ); 962 gzipProc = new QProcess( this, "gzipProc" );
866 gzipProc->setCommunication( QProcess::Stdin | QProcess::Stdout ); 963 gzipProc->setCommunication( QProcess::Stdin | QProcess::Stdout );
867 964
868 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); 965 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc");
869 createTargzProc->setCommunication( QProcess::Stdout ); 966 createTargzProc->setCommunication( QProcess::Stdout );
870 createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 967 createTargzProc->setWorkingDirectory( QDir::rootDirPath() );
871 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); 968 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) );
872 969
873 QStringList args = "tar"; 970 QStringList args = "tar";
874 args += "-xv"; 971 args += "-xv";
875 retrieveTargzProc = new QProcess( args, this, "retrieveTargzProc" ); 972 retrieveTargzProc = new QProcess( args, this, "retrieveTargzProc" );
876 retrieveTargzProc->setCommunication( QProcess::Stdin ); 973 retrieveTargzProc->setCommunication( QProcess::Stdin );
877 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 974 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() );
878 connect( retrieveTargzProc, SIGNAL( processExited() ), 975 connect( retrieveTargzProc, SIGNAL( processExited() ),
879 SIGNAL( completed() ) ); 976 SIGNAL( completed() ) );
880 connect( retrieveTargzProc, SIGNAL( processExited() ), 977 connect( retrieveTargzProc, SIGNAL( processExited() ),
881 SLOT( extractTarDone() ) ); 978 SLOT( extractTarDone() ) );
882} 979}
883 980
884ServerDTP::~ServerDTP() 981ServerDTP::~ServerDTP()
885{ 982{
886 buf.close(); 983 buf.close();
887 file.close(); 984 file.close();
888 createTargzProc->kill(); 985 createTargzProc->kill();
889} 986}
890 987
891void ServerDTP::extractTarDone() 988void ServerDTP::extractTarDone()
892{ 989{
893 qDebug("extract done"); 990 qDebug("extract done");
991#ifndef QT_NO_COP
894 QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); 992 QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" );
895 e << file.name(); 993 e << file.name();
994#endif
896} 995}
897 996
898void ServerDTP::connected() 997void ServerDTP::connected()
899{ 998{
900 // send file mode 999 // send file mode
901 switch ( mode ) { 1000 switch ( mode ) {
902 case SendFile : 1001 case SendFile :
903 if ( !file.exists() || !file.open( IO_ReadOnly) ) { 1002 if ( !file.exists() || !file.open( IO_ReadOnly) ) {
904 emit failed(); 1003 emit failed();
905 mode = Idle; 1004 mode = Idle;
906 return; 1005 return;
907 } 1006 }
908 1007
909 //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); 1008 //qDebug( "Debug: Sending file '%s'", file.name().latin1() );
910 1009
911 bytes_written = 0; 1010 bytes_written = 0;
912 if ( file.size() == 0 ) { 1011 if ( file.size() == 0 ) {
913 //make sure it doesn't hang on empty files 1012 //make sure it doesn't hang on empty files
914 file.close(); 1013 file.close();
915 emit completed(); 1014 emit completed();
916 mode = Idle; 1015 mode = Idle;
917 } else { 1016 } else {
918 1017
919 if( !file.atEnd() ) { 1018 if( !file.atEnd() ) {
920 QCString s; 1019 QCString s;
921 s.resize( block_size ); 1020 s.resize( block_size );
922 int bytes = file.readBlock( s.data(), block_size ); 1021 int bytes = file.readBlock( s.data(), block_size );
923 writeBlock( s.data(), bytes ); 1022 writeBlock( s.data(), bytes );
924 } 1023 }
925 } 1024 }
926 break; 1025 break;
927 case SendGzipFile: 1026 case SendGzipFile:
928 if ( createTargzProc->isRunning() ) { 1027 if ( createTargzProc->isRunning() ) {
929 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY 1028 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY
930 qWarning("Previous tar --gzip process is still running; killing it..."); 1029 qWarning("Previous tar --gzip process is still running; killing it...");
931 createTargzProc->kill(); 1030 createTargzProc->kill();
932 } 1031 }
933 1032
934 bytes_written = 0; 1033 bytes_written = 0;
935 qDebug("==>start send tar process"); 1034 qDebug("==>start send tar process");
936 if ( !createTargzProc->start() ) 1035 if ( !createTargzProc->start() )
937 qWarning("Error starting %s or %s", 1036 qWarning("Error starting %s or %s",
938 createTargzProc->arguments().join(" ").latin1(), 1037 createTargzProc->arguments().join(" ").latin1(),
939 gzipProc->arguments().join(" ").latin1() ); 1038 gzipProc->arguments().join(" ").latin1() );
940 break; 1039 break;
941 case SendBuffer: 1040 case SendBuffer:
942 if ( !buf.open( IO_ReadOnly) ) { 1041 if ( !buf.open( IO_ReadOnly) ) {
943 emit failed(); 1042 emit failed();
944 mode = Idle; 1043 mode = Idle;
945 return; 1044 return;
946 } 1045 }
947 1046
948 // qDebug( "Debug: Sending byte array" ); 1047 // qDebug( "Debug: Sending byte array" );
949 bytes_written = 0; 1048 bytes_written = 0;
950 while( !buf.atEnd() ) 1049 while( !buf.atEnd() )
951 putch( buf.getch() ); 1050 putch( buf.getch() );
952 buf.close(); 1051 buf.close();
953 break; 1052 break;
954 case RetrieveFile: 1053 case RetrieveFile:
955 // retrieve file mode 1054 // retrieve file mode
956 if ( file.exists() && !file.remove() ) { 1055 if ( file.exists() && !file.remove() ) {
957 emit failed(); 1056 emit failed();
958 mode = Idle; 1057 mode = Idle;
959 return; 1058 return;
960 } 1059 }
961 1060
962 if ( !file.open( IO_WriteOnly) ) { 1061 if ( !file.open( IO_WriteOnly) ) {
963 emit failed(); 1062 emit failed();
964 mode = Idle; 1063 mode = Idle;
965 return; 1064 return;
966 } 1065 }
967 // qDebug( "Debug: Retrieving file %s", file.name().latin1() ); 1066 // qDebug( "Debug: Retrieving file %s", file.name().latin1() );
968 break; 1067 break;
969 case RetrieveGzipFile: 1068 case RetrieveGzipFile:
970 qDebug("=-> starting tar process to receive .tgz file"); 1069 qDebug("=-> starting tar process to receive .tgz file");
971 break; 1070 break;
972 case RetrieveBuffer: 1071 case RetrieveBuffer:
973 // retrieve buffer mode 1072 // retrieve buffer mode
974 if ( !buf.open( IO_WriteOnly) ) { 1073 if ( !buf.open( IO_WriteOnly) ) {
975 emit failed(); 1074 emit failed();
976 mode = Idle; 1075 mode = Idle;
977 return; 1076 return;
978 } 1077 }
979 // qDebug( "Debug: Retrieving byte array" ); 1078 // qDebug( "Debug: Retrieving byte array" );
980 break; 1079 break;
981 case Idle: 1080 case Idle:
982 qDebug("connection established but mode set to Idle; BUG!"); 1081 qDebug("connection established but mode set to Idle; BUG!");
983 break; 1082 break;
984 } 1083 }
985} 1084}
986 1085
987void ServerDTP::connectionClosed() 1086void ServerDTP::connectionClosed()
988{ 1087{
989 //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written ); 1088 //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written );
990 1089
991 // send file mode 1090 // send file mode
992 if ( SendFile == mode ) { 1091 if ( SendFile == mode ) {
993 if ( bytes_written == file.size() ) 1092 if ( bytes_written == file.size() )
994 emit completed(); 1093 emit completed();
995 else 1094 else
996 emit failed(); 1095 emit failed();
997 } 1096 }
998 1097
999 // send buffer mode 1098 // send buffer mode
1000 else if ( SendBuffer == mode ) { 1099 else if ( SendBuffer == mode ) {
1001 if ( bytes_written == buf.size() ) 1100 if ( bytes_written == buf.size() )
1002 emit completed(); 1101 emit completed();
1003 else 1102 else
1004 emit failed(); 1103 emit failed();
1005 } 1104 }
1006 1105
1007 // retrieve file mode 1106 // retrieve file mode
1008 else if ( RetrieveFile == mode ) { 1107 else if ( RetrieveFile == mode ) {
1009 file.close(); 1108 file.close();
1010 emit completed(); 1109 emit completed();
1011 } 1110 }
1012 1111
1013 else if ( RetrieveGzipFile == mode ) { 1112 else if ( RetrieveGzipFile == mode ) {
1014 qDebug("Done writing ungzip file; closing input"); 1113 qDebug("Done writing ungzip file; closing input");
1015 gzipProc->flushStdin(); 1114 gzipProc->flushStdin();
1016 gzipProc->closeStdin(); 1115 gzipProc->closeStdin();
1017 } 1116 }
1018 1117
1019 // retrieve buffer mode 1118 // retrieve buffer mode
1020 else if ( RetrieveBuffer == mode ) { 1119 else if ( RetrieveBuffer == mode ) {
1021 buf.close(); 1120 buf.close();
1022 emit completed(); 1121 emit completed();
1023 } 1122 }
1024 1123
1025 mode = Idle; 1124 mode = Idle;
1026} 1125}
1027 1126
1028void ServerDTP::bytesWritten( int bytes ) 1127void ServerDTP::bytesWritten( int bytes )
1029{ 1128{
1030 bytes_written += bytes; 1129 bytes_written += bytes;
1031 1130
1032 // send file mode 1131 // send file mode
1033 if ( SendFile == mode ) { 1132 if ( SendFile == mode ) {
1034 1133
1035 if ( bytes_written == file.size() ) { 1134 if ( bytes_written == file.size() ) {
1036 // qDebug( "Debug: Sending complete: %d bytes", file.size() ); 1135 // qDebug( "Debug: Sending complete: %d bytes", file.size() );
1037 file.close(); 1136 file.close();
1038 emit completed(); 1137 emit completed();
1039 mode = Idle; 1138 mode = Idle;
1040 } 1139 }
1041 else if( !file.atEnd() ) { 1140 else if( !file.atEnd() ) {
1042 QCString s; 1141 QCString s;
1043 s.resize( block_size ); 1142 s.resize( block_size );
1044 int bytes = file.readBlock( s.data(), block_size ); 1143 int bytes = file.readBlock( s.data(), block_size );
1045 writeBlock( s.data(), bytes ); 1144 writeBlock( s.data(), bytes );
1046 } 1145 }
1047 } 1146 }
1048 1147
1049 // send buffer mode 1148 // send buffer mode
1050 if ( SendBuffer == mode ) { 1149 if ( SendBuffer == mode ) {
1051 1150
1052 if ( bytes_written == buf.size() ) { 1151 if ( bytes_written == buf.size() ) {
1053 // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); 1152 // qDebug( "Debug: Sending complete: %d bytes", buf.size() );
1054 emit completed(); 1153 emit completed();
1055 mode = Idle; 1154 mode = Idle;
1056 } 1155 }
1057 } 1156 }
1058} 1157}
1059 1158
1060void ServerDTP::readyRead() 1159void ServerDTP::readyRead()
1061{ 1160{
1062 // retrieve file mode 1161 // retrieve file mode
1063 if ( RetrieveFile == mode ) { 1162 if ( RetrieveFile == mode ) {
1064 QCString s; 1163 QCString s;
1065 s.resize( bytesAvailable() ); 1164 s.resize( bytesAvailable() );
1066 readBlock( s.data(), bytesAvailable() ); 1165 readBlock( s.data(), bytesAvailable() );
1067 file.writeBlock( s.data(), s.size() ); 1166 file.writeBlock( s.data(), s.size() );
1068 } 1167 }
1069 else if ( RetrieveGzipFile == mode ) { 1168 else if ( RetrieveGzipFile == mode ) {
1070 if ( !gzipProc->isRunning() ) 1169 if ( !gzipProc->isRunning() )
1071 gzipProc->start(); 1170 gzipProc->start();
1072 1171
1073 QByteArray s; 1172 QByteArray s;
1074 s.resize( bytesAvailable() ); 1173 s.resize( bytesAvailable() );
1075 readBlock( s.data(), bytesAvailable() ); 1174 readBlock( s.data(), bytesAvailable() );
1076 gzipProc->writeToStdin( s ); 1175 gzipProc->writeToStdin( s );
1077 qDebug("wrote %d bytes to ungzip ", s.size() ); 1176 qDebug("wrote %d bytes to ungzip ", s.size() );
1078 } 1177 }
1079 // retrieve buffer mode 1178 // retrieve buffer mode
1080 else if ( RetrieveBuffer == mode ) { 1179 else if ( RetrieveBuffer == mode ) {
1081 QCString s; 1180 QCString s;
1082 s.resize( bytesAvailable() ); 1181 s.resize( bytesAvailable() );
1083 readBlock( s.data(), bytesAvailable() ); 1182 readBlock( s.data(), bytesAvailable() );
1084 buf.writeBlock( s.data(), s.size() ); 1183 buf.writeBlock( s.data(), s.size() );
1085 } 1184 }
1086} 1185}
1087 1186
1088void ServerDTP::writeTargzBlock() 1187void ServerDTP::writeTargzBlock()
1089{ 1188{
1090 QByteArray block = gzipProc->readStdout(); 1189 QByteArray block = gzipProc->readStdout();
1091 writeBlock( block.data(), block.size() ); 1190 writeBlock( block.data(), block.size() );
1092 qDebug("writeTargzBlock %d", block.size()); 1191 qDebug("writeTargzBlock %d", block.size());
1093 if ( !createTargzProc->isRunning() ) { 1192 if ( !createTargzProc->isRunning() ) {
1094 qDebug("tar and gzip done"); 1193 qDebug("tar and gzip done");
1095 emit completed(); 1194 emit completed();
1096 mode = Idle; 1195 mode = Idle;
1097 disconnect( gzipProc, SIGNAL( readyReadStdout() ), 1196 disconnect( gzipProc, SIGNAL( readyReadStdout() ),
1098 this, SLOT( writeTargzBlock() ) ); 1197 this, SLOT( writeTargzBlock() ) );
1099 } 1198 }
1100} 1199}
1101 1200
1102void ServerDTP::targzDone() 1201void ServerDTP::targzDone()
1103{ 1202{
1104 //qDebug("targz done"); 1203 //qDebug("targz done");
1105 disconnect( createTargzProc, SIGNAL( readyReadStdout() ), 1204 disconnect( createTargzProc, SIGNAL( readyReadStdout() ),
1106 this, SLOT( gzipTarBlock() ) ); 1205 this, SLOT( gzipTarBlock() ) );
1107 gzipProc->closeStdin(); 1206 gzipProc->closeStdin();
1108} 1207}
1109 1208
1110void ServerDTP::gzipTarBlock() 1209void ServerDTP::gzipTarBlock()
1111{ 1210{
1112 //qDebug("gzipTarBlock"); 1211 //qDebug("gzipTarBlock");
1113 if ( !gzipProc->isRunning() ) { 1212 if ( !gzipProc->isRunning() ) {
1114 //qDebug("auto start gzip proc"); 1213 //qDebug("auto start gzip proc");
1115 gzipProc->start(); 1214 gzipProc->start();
1116 } 1215 }
1117 gzipProc->writeToStdin( createTargzProc->readStdout() ); 1216 gzipProc->writeToStdin( createTargzProc->readStdout() );
1118} 1217}
1119 1218
1120void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) 1219void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port )
1121{ 1220{
1122 file.setName( fn ); 1221 file.setName( fn );
1123 mode = SendFile; 1222 mode = SendFile;
1124 connectToHost( host.toString(), port ); 1223 connectToHost( host.toString(), port );
1125} 1224}
1126 1225
1127void ServerDTP::sendFile( const QString fn ) 1226void ServerDTP::sendFile( const QString fn )
1128{ 1227{
1129 file.setName( fn ); 1228 file.setName( fn );
1130 mode = SendFile; 1229 mode = SendFile;
1131} 1230}
1132 1231
1133void ServerDTP::sendGzipFile( const QString &fn, 1232void ServerDTP::sendGzipFile( const QString &fn,
1134 const QStringList &archiveTargets, 1233 const QStringList &archiveTargets,
1135 const QHostAddress& host, Q_UINT16 port ) 1234 const QHostAddress& host, Q_UINT16 port )
1136{ 1235{
1137 sendGzipFile( fn, archiveTargets ); 1236 sendGzipFile( fn, archiveTargets );
1138 connectToHost( host.toString(), port ); 1237 connectToHost( host.toString(), port );
1139} 1238}
1140 1239
1141void ServerDTP::sendGzipFile( const QString &fn, 1240void ServerDTP::sendGzipFile( const QString &fn,
1142 const QStringList &archiveTargets ) 1241 const QStringList &archiveTargets )
1143{ 1242{
1144 mode = SendGzipFile; 1243 mode = SendGzipFile;
1145 file.setName( fn ); 1244 file.setName( fn );
1146 1245
1147 QStringList args = "tar"; 1246 QStringList args = "tar";
1148 args += "-cv"; 1247 args += "-cv";
1149 args += archiveTargets; 1248 args += archiveTargets;
1150 qDebug("sendGzipFile %s", args.join(" ").latin1() ); 1249 qDebug("sendGzipFile %s", args.join(" ").latin1() );
1151 createTargzProc->setArguments( args ); 1250 createTargzProc->setArguments( args );
1152 connect( createTargzProc, 1251 connect( createTargzProc,
1153 SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) ); 1252 SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) );
1154 1253
1155 gzipProc->setArguments( "gzip" ); 1254 gzipProc->setArguments( "gzip" );
1156 connect( gzipProc, SIGNAL( readyReadStdout() ), 1255 connect( gzipProc, SIGNAL( readyReadStdout() ),
1157 SLOT( writeTargzBlock() ) ); 1256 SLOT( writeTargzBlock() ) );
1158} 1257}
1159 1258
1160void ServerDTP::gunzipDone() 1259void ServerDTP::gunzipDone()
1161{ 1260{
1162 qDebug("gunzipDone"); 1261 qDebug("gunzipDone");
1163 disconnect( gzipProc, SIGNAL( processExited() ), 1262 disconnect( gzipProc, SIGNAL( processExited() ),
1164 this, SLOT( gunzipDone() ) ); 1263 this, SLOT( gunzipDone() ) );
1165 retrieveTargzProc->closeStdin(); 1264 retrieveTargzProc->closeStdin();
1166 disconnect( gzipProc, SIGNAL( readyReadStdout() ), 1265 disconnect( gzipProc, SIGNAL( readyReadStdout() ),
1167 this, SLOT( tarExtractBlock() ) ); 1266 this, SLOT( tarExtractBlock() ) );
1168} 1267}
1169 1268
1170void ServerDTP::tarExtractBlock() 1269void ServerDTP::tarExtractBlock()
1171{ 1270{
1172 qDebug("ungzipTarBlock"); 1271 qDebug("ungzipTarBlock");
1173 if ( !retrieveTargzProc->isRunning() ) { 1272 if ( !retrieveTargzProc->isRunning() ) {
1174 qDebug("auto start ungzip proc"); 1273 qDebug("auto start ungzip proc");
1175 if ( !retrieveTargzProc->start() ) 1274 if ( !retrieveTargzProc->start() )
1176 qWarning(" failed to start tar -x process"); 1275 qWarning(" failed to start tar -x process");
1177 } 1276 }
1178 retrieveTargzProc->writeToStdin( gzipProc->readStdout() ); 1277 retrieveTargzProc->writeToStdin( gzipProc->readStdout() );
1179} 1278}
1180 1279
1181 1280
1182void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) 1281void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port )
1183{ 1282{
1184 file.setName( fn ); 1283 file.setName( fn );
1185 mode = RetrieveFile; 1284 mode = RetrieveFile;
1186 connectToHost( host.toString(), port ); 1285 connectToHost( host.toString(), port );
1187} 1286}
1188 1287
1189void ServerDTP::retrieveFile( const QString fn ) 1288void ServerDTP::retrieveFile( const QString fn )
1190{ 1289{
1191 file.setName( fn ); 1290 file.setName( fn );
1192 mode = RetrieveFile; 1291 mode = RetrieveFile;
1193} 1292}
1194 1293
1195void ServerDTP::retrieveGzipFile( const QString &fn ) 1294void ServerDTP::retrieveGzipFile( const QString &fn )
1196{ 1295{
1197 qDebug("retrieveGzipFile %s", fn.latin1()); 1296 qDebug("retrieveGzipFile %s", fn.latin1());
1198 file.setName( fn ); 1297 file.setName( fn );
1199 mode = RetrieveGzipFile; 1298 mode = RetrieveGzipFile;
1200 1299
1201 gzipProc->setArguments( "gunzip" ); 1300 gzipProc->setArguments( "gunzip" );
1202 connect( gzipProc, SIGNAL( readyReadStdout() ), 1301 connect( gzipProc, SIGNAL( readyReadStdout() ),
1203 SLOT( tarExtractBlock() ) ); 1302 SLOT( tarExtractBlock() ) );
1204 connect( gzipProc, SIGNAL( processExited() ), 1303 connect( gzipProc, SIGNAL( processExited() ),
1205 SLOT( gunzipDone() ) ); 1304 SLOT( gunzipDone() ) );
1206} 1305}
1207 1306
1208void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) 1307void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port )
1209{ 1308{
1210 retrieveGzipFile( fn ); 1309 retrieveGzipFile( fn );
1211 connectToHost( host.toString(), port ); 1310 connectToHost( host.toString(), port );
1212} 1311}
1213 1312
1214void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ) 1313void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port )
1215{ 1314{
1216 buf.setBuffer( array ); 1315 buf.setBuffer( array );
1217 mode = SendBuffer; 1316 mode = SendBuffer;
1218 connectToHost( host.toString(), port ); 1317 connectToHost( host.toString(), port );
1219} 1318}
1220 1319
1221void ServerDTP::sendByteArray( const QByteArray& array ) 1320void ServerDTP::sendByteArray( const QByteArray& array )
1222{ 1321{
1223 buf.setBuffer( array ); 1322 buf.setBuffer( array );
1224 mode = SendBuffer; 1323 mode = SendBuffer;
1225} 1324}
1226 1325
1227void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port ) 1326void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port )
1228{ 1327{
1229 buf.setBuffer( QByteArray() ); 1328 buf.setBuffer( QByteArray() );
1230 mode = RetrieveBuffer; 1329 mode = RetrieveBuffer;
1231 connectToHost( host.toString(), port ); 1330 connectToHost( host.toString(), port );
1232} 1331}
1233 1332
1234void ServerDTP::retrieveByteArray() 1333void ServerDTP::retrieveByteArray()
1235{ 1334{
1236 buf.setBuffer( QByteArray() ); 1335 buf.setBuffer( QByteArray() );
1237 mode = RetrieveBuffer; 1336 mode = RetrieveBuffer;
1238} 1337}
1239 1338
1240void ServerDTP::setSocket( int socket ) 1339void ServerDTP::setSocket( int socket )
1241{ 1340{
1242 QSocket::setSocket( socket ); 1341 QSocket::setSocket( socket );
1243 connected(); 1342 connected();
1244} 1343}
1245 1344
diff --git a/core/launcher/transferserver.h b/core/launcher/transferserver.h
index 076e460..a3bb060 100644
--- a/core/launcher/transferserver.h
+++ b/core/launcher/transferserver.h
@@ -1,168 +1,179 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qserversocket.h> 20#include <qserversocket.h>
21#include <qsocket.h> 21#include <qsocket.h>
22#include <qdir.h> 22#include <qdir.h>
23#include <qfile.h> 23#include <qfile.h>
24#include <qbuffer.h> 24#include <qbuffer.h>
25 25
26class QFileInfo; 26class QFileInfo;
27class QProcess; 27class QProcess;
28class TransferServer : public QServerSocket 28class TransferServer : public QServerSocket
29{ 29{
30 Q_OBJECT 30 Q_OBJECT
31 31
32public: 32public:
33 TransferServer( Q_UINT16 port, QObject *parent = 0, const char* name = 0 ); 33 TransferServer( Q_UINT16 port, QObject *parent = 0, const char* name = 0 );
34 virtual ~TransferServer(); 34 virtual ~TransferServer();
35 35
36 void newConnection( int socket ); 36 void newConnection( int socket );
37}; 37};
38 38
39class SyncAuthentication : QObject
40{
41 Q_OBJECT
42
43public:
44 static int isAuthorized(QHostAddress peeraddress);
45 static bool checkPassword(const QString& pw);
46 static bool checkUser(const QString& user);
47
48 static QString serverId();
49 static QString loginName();
50 static QString ownerName();
51};
52
39 53
40class ServerDTP : public QSocket 54class ServerDTP : public QSocket
41{ 55{
42 Q_OBJECT 56 Q_OBJECT
43 57
44public: 58public:
45 ServerDTP( QObject *parent = 0, const char* name = 0 ); 59 ServerDTP( QObject *parent = 0, const char* name = 0 );
46 ~ServerDTP(); 60 ~ServerDTP();
47 61
48 enum Mode{ Idle = 0, SendFile, SendGzipFile, SendBuffer, 62 enum Mode{ Idle = 0, SendFile, SendGzipFile, SendBuffer,
49 RetrieveFile, RetrieveGzipFile, RetrieveBuffer }; 63 RetrieveFile, RetrieveGzipFile, RetrieveBuffer };
50 64
51 void sendFile( const QString fn ); 65 void sendFile( const QString fn );
52 void sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ); 66 void sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port );
53 void sendGzipFile( const QString &fn, const QStringList &archiveTargets ); 67 void sendGzipFile( const QString &fn, const QStringList &archiveTargets );
54 void sendGzipFile( const QString &fn, const QStringList &archiveTargets, 68 void sendGzipFile( const QString &fn, const QStringList &archiveTargets,
55 const QHostAddress& host, Q_UINT16 port ); 69 const QHostAddress& host, Q_UINT16 port );
56 void sendByteArray( const QByteArray& array ); 70 void sendByteArray( const QByteArray& array );
57 void sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ); 71 void sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port );
58 72
59 void retrieveFile( const QString fn ); 73 void retrieveFile( const QString fn );
60 void retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ); 74 void retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port );
61 void retrieveGzipFile( const QString &fn ); 75 void retrieveGzipFile( const QString &fn );
62 void retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ); 76 void retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port );
63 void retrieveByteArray(); 77 void retrieveByteArray();
64 void retrieveByteArray( const QHostAddress& host, Q_UINT16 port ); 78 void retrieveByteArray( const QHostAddress& host, Q_UINT16 port );
65 79
66 Mode dtpMode() { return mode; } 80 Mode dtpMode() { return mode; }
67 QByteArray buffer() { return buf.buffer(); } 81 QByteArray buffer() { return buf.buffer(); }
82 QString fileName() const { return file.name(); }
68 83
69 void setSocket( int socket ); 84 void setSocket( int socket );
70 85
71signals: 86signals:
72 void completed(); 87 void completed();
73 void failed(); 88 void failed();
74 89
75private slots: 90private slots:
76 void connectionClosed(); 91 void connectionClosed();
77 void connected(); 92 void connected();
78 void bytesWritten( int bytes ); 93 void bytesWritten( int bytes );
79 void readyRead(); 94 void readyRead();
80 void writeTargzBlock(); 95 void writeTargzBlock();
81 void targzDone(); 96 void targzDone();
82 97
83 void gzipTarBlock(); 98 void gzipTarBlock();
84 void tarExtractBlock(); 99 void tarExtractBlock();
85 void gunzipDone(); 100 void gunzipDone();
86 void extractTarDone(); 101 void extractTarDone();
87 102
88private: 103private:
89 104
90 unsigned long bytes_written; 105 unsigned long bytes_written;
91 Mode mode; 106 Mode mode;
92 QFile file; 107 QFile file;
93 QBuffer buf; 108 QBuffer buf;
94 QProcess *createTargzProc; 109 QProcess *createTargzProc;
95 QProcess *retrieveTargzProc; 110 QProcess *retrieveTargzProc;
96 QProcess *gzipProc; 111 QProcess *gzipProc;
97}; 112};
98 113
99class ServerSocket : public QServerSocket 114class ServerSocket : public QServerSocket
100{ 115{
101 Q_OBJECT 116 Q_OBJECT
102 117
103public: 118public:
104 ServerSocket( Q_UINT16 port, QObject *parent = 0, const char* name = 0 ) 119 ServerSocket( Q_UINT16 port, QObject *parent = 0, const char* name = 0 )
105 : QServerSocket( port, 1, parent, name ) {} 120 : QServerSocket( port, 1, parent, name ) {}
106 121
107 void newConnection( int socket ) { emit newIncomming( socket ); } 122 void newConnection( int socket ) { emit newIncomming( socket ); }
108signals: 123signals:
109 void newIncomming( int socket ); 124 void newIncomming( int socket );
110}; 125};
111 126
112class ServerPI : public QSocket 127class ServerPI : public QSocket
113{ 128{
114 Q_OBJECT 129 Q_OBJECT
115 130
116 enum State { Connected, Wait_USER, Wait_PASS, Ready, Forbidden }; 131 enum State { Connected, Wait_USER, Wait_PASS, Ready, Forbidden };
117 enum Transfer { SendFile = 0, RetrieveFile = 1, SendByteArray = 2, RetrieveByteArray = 3 }; 132 enum Transfer { SendFile = 0, RetrieveFile = 1, SendByteArray = 2, RetrieveByteArray = 3 };
118 133
119public: 134public:
120 ServerPI( int socket, QObject *parent = 0, const char* name = 0 ); 135 ServerPI( int socket, QObject *parent = 0, const char* name = 0 );
121 virtual ~ServerPI(); 136 virtual ~ServerPI();
122 137
123protected slots: 138protected slots:
124 void read(); 139 void read();
125 void send( const QString& msg ); 140 void send( const QString& msg );
126 void process( const QString& command ); 141 void process( const QString& command );
127 void connectionClosed(); 142 void connectionClosed();
128 void dtpCompleted(); 143 void dtpCompleted();
129 void dtpFailed(); 144 void dtpFailed();
130 void dtpError( int ); 145 void dtpError( int );
131 void newConnection( int socket ); 146 void newConnection( int socket );
132 147
133protected: 148protected:
134 bool checkUser( const QString& user );
135 bool checkPassword( const QString& pw );
136 bool checkReadFile( const QString& file ); 149 bool checkReadFile( const QString& file );
137 bool checkWriteFile( const QString& file ); 150 bool checkWriteFile( const QString& file );
138 bool parsePort( const QString& pw ); 151 bool parsePort( const QString& pw );
139 bool backupRestoreGzip( const QString &file, QStringList &targets ); 152 bool backupRestoreGzip( const QString &file, QStringList &targets );
140 bool backupRestoreGzip( const QString &file ); 153 bool backupRestoreGzip( const QString &file );
141 154
142 bool sendList( const QString& arg ); 155 bool sendList( const QString& arg );
143 void sendFile( const QString& file ); 156 void sendFile( const QString& file );
144 void retrieveFile( const QString& file ); 157 void retrieveFile( const QString& file );
145 158
146 QString permissionString( QFileInfo *info ); 159 QString permissionString( QFileInfo *info );
147 QString fileListing( QFileInfo *info ); 160 QString fileListing( QFileInfo *info );
148 QString absFilePath( const QString& file ); 161 QString absFilePath( const QString& file );
149 162
150 void timerEvent( QTimerEvent *e ); 163 void timerEvent( QTimerEvent *e );
151 164
152private: 165private:
153 State state; 166 State state;
154 Q_UINT16 peerport; 167 Q_UINT16 peerport;
155 QHostAddress peeraddress; 168 QHostAddress peeraddress;
156 bool passiv; 169 bool passiv;
157 bool wait[4]; 170 bool wait[4];
158 ServerDTP *dtp; 171 ServerDTP *dtp;
159 ServerSocket *serversocket; 172 ServerSocket *serversocket;
160 QString waitfile; 173 QString waitfile;
161 QDir directory; 174 QDir directory;
162 QByteArray waitarray; 175 QByteArray waitarray;
163 QString renameFrom; 176 QString renameFrom;
164 QString lastCommand; 177 QString lastCommand;
165 int waitsocket; 178 int waitsocket;
166}; 179};
167
168bool accessAuthorized(QHostAddress peeraddress);