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