summaryrefslogtreecommitdiff
authorzecke <zecke>2004-02-21 13:09:17 (UTC)
committer zecke <zecke>2004-02-21 13:09:17 (UTC)
commit4024cfd1e32a43d82361d6ba9977fe64db88e3ce (patch) (unidiff)
tree1d2e0592a3df330a17d9a07cd2f29615ce5be595
parentaa11789fc4d735a04fac09063851753d8a57027b (diff)
downloadopie-4024cfd1e32a43d82361d6ba9977fe64db88e3ce.zip
opie-4024cfd1e32a43d82361d6ba9977fe64db88e3ce.tar.gz
opie-4024cfd1e32a43d82361d6ba9977fe64db88e3ce.tar.bz2
Fix up syncing mode
InetlliSync,Opie1.0,QtopiaNEW
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/qcopbridge.cpp2
-rw-r--r--core/launcher/qcopbridge.h3
-rw-r--r--core/launcher/transferserver.cpp36
3 files changed, 30 insertions, 11 deletions
diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp
index b45f0cc..9bca360 100644
--- a/core/launcher/qcopbridge.cpp
+++ b/core/launcher/qcopbridge.cpp
@@ -1,498 +1,498 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "qcopbridge.h" 21#include "qcopbridge.h"
22#include "transferserver.h" 22#include "transferserver.h"
23 23
24#include <opie2/oglobal.h> 24#include <opie2/oglobal.h>
25 25
26#ifdef Q_WS_QWS 26#ifdef Q_WS_QWS
27#include <qtopia/qcopenvelope_qws.h> 27#include <qtopia/qcopenvelope_qws.h>
28#endif 28#endif
29#include <qtopia/qpeapplication.h> 29#include <qtopia/qpeapplication.h>
30 30
31#include <qtopia/version.h> 31#include <qtopia/version.h>
32#include <qtopia/config.h> 32#include <qtopia/config.h>
33 33
34#include <qdir.h> 34#include <qdir.h>
35#include <qfile.h> 35#include <qfile.h>
36#include <qtextstream.h> 36#include <qtextstream.h>
37#include <qdatastream.h> 37#include <qdatastream.h>
38#include <qcstring.h> 38#include <qcstring.h>
39#include <qstringlist.h> 39#include <qstringlist.h>
40#include <qfileinfo.h> 40#include <qfileinfo.h>
41#include <qregexp.h> 41#include <qregexp.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#ifdef Q_WS_QWS 43#ifdef Q_WS_QWS
44#include <qcopchannel_qws.h> 44#include <qcopchannel_qws.h>
45#endif 45#endif
46 46
47#ifndef _XOPEN_SOURCE 47#ifndef _XOPEN_SOURCE
48#define _XOPEN_SOURCE 48#define _XOPEN_SOURCE
49#endif 49#endif
50#ifndef Q_OS_WIN32 50#ifndef Q_OS_WIN32
51#include <pwd.h> 51#include <pwd.h>
52#include <unistd.h> 52#include <unistd.h>
53#include <sys/types.h> 53#include <sys/types.h>
54#endif 54#endif
55 55
56#if defined(_OS_LINUX_) 56#if defined(_OS_LINUX_)
57#include <shadow.h> 57#include <shadow.h>
58#endif 58#endif
59 59
60 60
61//#define INSECURE 61//#define INSECURE
62 62
63const int block_size = 51200; 63const int block_size = 51200;
64 64
65QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent, 65QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent,
66 const char* name ) 66 const char* name )
67 : QServerSocket( port, 1, parent, name ), 67 : QServerSocket( port, 1, parent, name ),
68 desktopChannel( 0 ), 68 desktopChannel( 0 ),
69 cardChannel( 0 ) 69 cardChannel( 0 )
70{ 70{
71 if ( !ok() ) 71 if ( !ok() )
72 qWarning( "Failed to bind to port %d", port ); 72 qWarning( "Failed to bind to port %d", port );
73 else { 73 else {
74#ifndef QT_NO_COP 74#ifndef QT_NO_COP
75 desktopChannel = new QCopChannel( "QPE/Desktop", this ); 75 desktopChannel = new QCopChannel( "QPE/Desktop", this );
76 connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)), 76 connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)),
77 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 77 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
78 cardChannel = new QCopChannel( "QPE/Card", this ); 78 cardChannel = new QCopChannel( "QPE/Card", this );
79 connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), 79 connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)),
80 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 80 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
81#endif 81#endif
82 } 82 }
83 sendSync = FALSE; 83 sendSync = FALSE;
84 openConnections.setAutoDelete( TRUE ); 84 openConnections.setAutoDelete( TRUE );
85 authorizeConnections(); 85 authorizeConnections();
86} 86}
87 87
88QCopBridge::~QCopBridge() 88QCopBridge::~QCopBridge()
89{ 89{
90#ifndef QT_NO_COP 90#ifndef QT_NO_COP
91 delete desktopChannel; 91 delete desktopChannel;
92#endif 92#endif
93} 93}
94 94
95void QCopBridge::authorizeConnections() 95void QCopBridge::authorizeConnections()
96{ 96{
97 Config cfg("Security"); 97 Config cfg("Security");
98 cfg.setGroup("SyncMode"); 98 cfg.setGroup("SyncMode");
99 m_mode = Mode(cfg.readNumEntry("Mode", Sharp )); 99 m_mode = Mode(cfg.readNumEntry("Mode", Sharp ));
100 QListIterator<QCopBridgePI> it(openConnections); 100 QListIterator<QCopBridgePI> it(openConnections);
101 while ( it.current() ) { 101 while ( it.current() ) {
102 if ( !it.current()->verifyAuthorised() ) { 102 if ( !it.current()->verifyAuthorised() ) {
103 disconnect ( it.current(), SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) ); 103 disconnect ( it.current(), SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) );
104 openConnections.removeRef( it.current() ); 104 openConnections.removeRef( it.current() );
105 } else 105 } else
106 ++it; 106 ++it;
107 } 107 }
108} 108}
109 109
110void QCopBridge::newConnection( int socket ) 110void QCopBridge::newConnection( int socket )
111{ 111{
112 QCopBridgePI *pi = new QCopBridgePI( socket, this ); 112 QCopBridgePI *pi = new QCopBridgePI( socket, this );
113 openConnections.append( pi ); 113 openConnections.append( pi );
114 connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) ); 114 connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) );
115 115
116 /* ### libqtopia merge FIXME */ 116 /* ### libqtopia merge FIXME */
117#if 0 117#if 0
118 QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend ); 118 QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend );
119#endif 119#endif
120#ifndef QT_NO_COP 120#ifndef QT_NO_COP
121 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; 121 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend;
122#endif 122#endif
123 123
124 if ( sendSync ) { 124 if ( sendSync ) {
125 pi ->startSync(); 125 pi ->startSync();
126 sendSync = FALSE; 126 sendSync = FALSE;
127 } 127 }
128} 128}
129 129
130void QCopBridge::closed( QCopBridgePI *pi ) 130void QCopBridge::closed( QCopBridgePI *pi )
131{ 131{
132 emit connectionClosed( pi->peerAddress() ); 132 emit connectionClosed( pi->peerAddress() );
133 openConnections.removeRef( pi ); 133 openConnections.removeRef( pi );
134 if ( openConnections.count() == 0 ) { 134 if ( openConnections.count() == 0 ) {
135 /* ### FIXME libqtopia merge */ 135 /* ### FIXME libqtopia merge */
136#if 0 136#if 0
137 QPEApplication::setTempScreenSaverMode( QPEApplication::Enable ); 137 QPEApplication::setTempScreenSaverMode( QPEApplication::Enable );
138#endif 138#endif
139#ifndef QT_NO_COP 139#ifndef QT_NO_COP
140 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 140 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
141#endif 141#endif
142 } 142 }
143} 143}
144 144
145void QCopBridge::closeOpenConnections() 145void QCopBridge::closeOpenConnections()
146{ 146{
147 QCopBridgePI *pi; 147 QCopBridgePI *pi;
148 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) 148 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() )
149 pi->close(); 149 pi->close();
150} 150}
151 151
152 152
153void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data ) 153void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data )
154{ 154{
155 if ( command == "startSync()" ) { 155 if ( command == "startSync()" ) {
156 // we need to buffer it a bit 156 // we need to buffer it a bit
157 sendSync = TRUE; 157 sendSync = TRUE;
158 startTimer( 20000 ); 158 startTimer( 20000 );
159 } 159 }
160 160
161 if ( m_mode & Qtopia1_7 ) { 161 if ( m_mode & Qtopia1_7 ) {
162 // send the command to all open connections 162 // send the command to all open connections
163 QCopBridgePI *pi; 163 QCopBridgePI *pi;
164 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { 164 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) {
165 pi->sendDesktopMessage( command, data ); 165 pi->sendDesktopMessage( command, data );
166 } 166 }
167 } 167 }
168 if ( m_mode & Sharp ) 168 if ( ( m_mode & Sharp ) || (m_mode & IntelliSync) )
169 sendDesktopMessageOld( command, data ); 169 sendDesktopMessageOld( command, data );
170} 170}
171 171
172#ifndef OPIE_NO_OLD_SYNC_CODE 172#ifndef OPIE_NO_OLD_SYNC_CODE
173/* 173/*
174 * Old compat mode 174 * Old compat mode
175 */ 175 */
176void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) { 176void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) {
177 command.stripWhiteSpace(); 177 command.stripWhiteSpace();
178 178
179 int paren = command.find( "(" ); 179 int paren = command.find( "(" );
180 if ( paren <= 0 ) { 180 if ( paren <= 0 ) {
181 qDebug("DesktopMessage: bad qcop syntax"); 181 qDebug("DesktopMessage: bad qcop syntax");
182 return; 182 return;
183 } 183 }
184 184
185 QString params = command.mid( paren + 1 ); 185 QString params = command.mid( paren + 1 );
186 if ( params[params.length()-1] != ')' ) { 186 if ( params[params.length()-1] != ')' ) {
187 qDebug("DesktopMessage: bad qcop syntax"); 187 qDebug("DesktopMessage: bad qcop syntax");
188 return; 188 return;
189 } 189 }
190 190
191 params.truncate( params.length()-1 ); 191 params.truncate( params.length()-1 );
192 192
193 QStringList paramList = QStringList::split( ",", params ); 193 QStringList paramList = QStringList::split( ",", params );
194 QString data; 194 QString data;
195 if ( paramList.count() ) { 195 if ( paramList.count() ) {
196 QDataStream stream( args, IO_ReadOnly ); 196 QDataStream stream( args, IO_ReadOnly );
197 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { 197 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
198 QString str; 198 QString str;
199 if ( *it == "QString" ) { 199 if ( *it == "QString" ) {
200 stream >> str; 200 stream >> str;
201 } else if ( *it == "QCString" ) { 201 } else if ( *it == "QCString" ) {
202 QCString cstr; 202 QCString cstr;
203 stream >> cstr; 203 stream >> cstr;
204 str = QString::fromLocal8Bit( cstr ); 204 str = QString::fromLocal8Bit( cstr );
205 } else if ( *it == "int" ) { 205 } else if ( *it == "int" ) {
206 int i; 206 int i;
207 stream >> i; 207 stream >> i;
208 str = QString::number( i ); 208 str = QString::number( i );
209 } else if ( *it == "bool" ) { 209 } else if ( *it == "bool" ) {
210 int i; 210 int i;
211 stream >> i; 211 stream >> i;
212 str = QString::number( i ); 212 str = QString::number( i );
213 } else { 213 } else {
214 qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() ); 214 qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() );
215 return; 215 return;
216 } 216 }
217 QString estr; 217 QString estr;
218 for (int i=0; i<(int)str.length(); i++) { 218 for (int i=0; i<(int)str.length(); i++) {
219 QChar ch = str[i]; 219 QChar ch = str[i];
220 if ( ch.row() ) 220 if ( ch.row() )
221 goto quick; 221 goto quick;
222 switch (ch.cell()) { 222 switch (ch.cell()) {
223 case '&': 223 case '&':
224 estr.append( "&amp;" ); 224 estr.append( "&amp;" );
225 break; 225 break;
226 case ' ': 226 case ' ':
227 estr.append( "&0x20;" ); 227 estr.append( "&0x20;" );
228 break; 228 break;
229 case '\n': 229 case '\n':
230 estr.append( "&0x0d;" ); 230 estr.append( "&0x0d;" );
231 break; 231 break;
232 case '\r': 232 case '\r':
233 estr.append( "&0x0a;" ); 233 estr.append( "&0x0a;" );
234 break; 234 break;
235 default: quick: 235 default: quick:
236 estr.append(ch); 236 estr.append(ch);
237 } 237 }
238 } 238 }
239 data += " " + estr; 239 data += " " + estr;
240 } 240 }
241 } 241 }
242 QString sendCommand = QString(command.data()) + data; 242 QString sendCommand = QString(command.data()) + data;
243 243
244 244
245 // send the command to all open connections 245 // send the command to all open connections
246 QCopBridgePI *pi; 246 QCopBridgePI *pi;
247 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) 247 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() )
248 pi->sendDesktopMessage( sendCommand ); 248 pi->sendDesktopMessage( sendCommand );
249 249
250} 250}
251#endif 251#endif
252 252
253 253
254void QCopBridge::timerEvent( QTimerEvent * ) 254void QCopBridge::timerEvent( QTimerEvent * )
255{ 255{
256 sendSync = FALSE; 256 sendSync = FALSE;
257 killTimers(); 257 killTimers();
258} 258}
259 259
260 260
261QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name ) 261QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name )
262 : QSocket( parent, name ) 262 : QSocket( parent, name )
263{ 263{
264 setSocket( socket ); 264 setSocket( socket );
265 265
266 peerport = peerPort(); 266 peerport = peerPort();
267 peeraddress = peerAddress(); 267 peeraddress = peerAddress();
268 268
269#ifndef INSECURE 269#ifndef INSECURE
270 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 270 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
271 state = Forbidden; 271 state = Forbidden;
272 close(); 272 close();
273 } else 273 } else
274#endif 274#endif
275 { 275 {
276 state = Connected; 276 state = Connected;
277 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 277 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
278 QString intro="220 Qtopia "; 278 QString intro="220 Qtopia ";
279 intro += QPE_VERSION; intro += ";"; 279 intro += QPE_VERSION; intro += ";";
280 intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";"; // No tr 280 intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";"; // No tr
281 intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";"; 281 intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";";
282 intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";"; 282 intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";";
283 send( intro ); 283 send( intro );
284 state = Wait_USER; 284 state = Wait_USER;
285 } 285 }
286 sendSync = FALSE; 286 sendSync = FALSE;
287 connect( this, SIGNAL( connectionClosed() ), SLOT( myConnectionClosed() ) ); 287 connect( this, SIGNAL( connectionClosed() ), SLOT( myConnectionClosed() ) );
288 288
289 // idle timer to close connections when not used anymore 289 // idle timer to close connections when not used anymore
290 timer = new QTimer(this); 290 timer = new QTimer(this);
291 connect( timer, SIGNAL(timeout()), this, SLOT(myConnectionClosed()) ); 291 connect( timer, SIGNAL(timeout()), this, SLOT(myConnectionClosed()) );
292 timer->start( 300000, TRUE ); 292 timer->start( 300000, TRUE );
293} 293}
294 294
295 295
296QCopBridgePI::~QCopBridgePI() 296QCopBridgePI::~QCopBridgePI()
297{ 297{
298} 298}
299 299
300bool QCopBridgePI::verifyAuthorised() 300bool QCopBridgePI::verifyAuthorised()
301{ 301{
302 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { 302 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) {
303 state = Forbidden; 303 state = Forbidden;
304 return FALSE; 304 return FALSE;
305 } 305 }
306 return TRUE; 306 return TRUE;
307} 307}
308 308
309void QCopBridgePI::myConnectionClosed() 309void QCopBridgePI::myConnectionClosed()
310{ 310{
311 emit connectionClosed( this ); 311 emit connectionClosed( this );
312} 312}
313 313
314void QCopBridgePI::sendDesktopMessage( const QString &msg ) 314void QCopBridgePI::sendDesktopMessage( const QString &msg )
315{ 315{
316 QString str = "CALL QPE/Desktop " + msg; // No tr 316 QString str = "CALL QPE/Desktop " + msg; // No tr
317 send ( str ); 317 send ( str );
318} 318}
319 319
320void QCopBridgePI::sendDesktopMessage( const QCString &msg, const QByteArray& data ) 320void QCopBridgePI::sendDesktopMessage( const QCString &msg, const QByteArray& data )
321{ 321{
322 if ( !isOpen() ) // eg. Forbidden 322 if ( !isOpen() ) // eg. Forbidden
323 return; 323 return;
324 324
325 const char hdr[]="CALLB QPE/Desktop "; 325 const char hdr[]="CALLB QPE/Desktop ";
326 writeBlock(hdr,sizeof(hdr)-1); 326 writeBlock(hdr,sizeof(hdr)-1);
327 writeBlock(msg,msg.length()); 327 writeBlock(msg,msg.length());
328 writeBlock(" ",1); 328 writeBlock(" ",1);
329 QByteArray b64 = OGlobal::encodeBase64(data); 329 QByteArray b64 = OGlobal::encodeBase64(data);
330 writeBlock(b64.data(),b64.size()); 330 writeBlock(b64.data(),b64.size());
331 writeBlock("\r\n",2); 331 writeBlock("\r\n",2);
332 332
333} 333}
334 334
335 335
336void QCopBridgePI::send( const QString& msg ) 336void QCopBridgePI::send( const QString& msg )
337{ 337{
338 if ( !isOpen() ) // eg. Forbidden 338 if ( !isOpen() ) // eg. Forbidden
339 return; 339 return;
340 QTextStream os( this ); 340 QTextStream os( this );
341 os << msg << endl; 341 os << msg << endl;
342 //qDebug( "sending qcop message: %s", msg.latin1() ); 342 //qDebug( "sending qcop message: %s", msg.latin1() );
343} 343}
344 344
345void QCopBridgePI::read() 345void QCopBridgePI::read()
346{ 346{
347 while ( canReadLine() ) { 347 while ( canReadLine() ) {
348 timer->start( 300000, TRUE ); 348 timer->start( 300000, TRUE );
349 process( readLine().stripWhiteSpace() ); 349 process( readLine().stripWhiteSpace() );
350 } 350 }
351} 351}
352 352
353void QCopBridgePI::process( const QString& message ) 353void QCopBridgePI::process( const QString& message )
354{ 354{
355 //qDebug( "Command: %s", message.latin1() ); 355 //qDebug( "Command: %s", message.latin1() );
356 356
357 // split message using "," as separator 357 // split message using "," as separator
358 QStringList msg = QStringList::split( " ", message ); 358 QStringList msg = QStringList::split( " ", message );
359 if ( msg.isEmpty() ) return; 359 if ( msg.isEmpty() ) return;
360 360
361 // command token 361 // command token
362 QString cmd = msg[0].upper(); 362 QString cmd = msg[0].upper();
363 363
364 // argument token 364 // argument token
365 QString arg; 365 QString arg;
366 if ( msg.count() >= 2 ) 366 if ( msg.count() >= 2 )
367 arg = msg[1]; 367 arg = msg[1];
368 368
369 // we always respond to QUIT, regardless of state 369 // we always respond to QUIT, regardless of state
370 if ( cmd == "QUIT" ) { 370 if ( cmd == "QUIT" ) {
371 send( "211 Have a nice day!" ); // No tr 371 send( "211 Have a nice day!" ); // No tr
372 close(); 372 close();
373 return; 373 return;
374 } 374 }
375 375
376 // connected to client 376 // connected to client
377 if ( Connected == state ) 377 if ( Connected == state )
378 return; 378 return;
379 379
380 // waiting for user name 380 // waiting for user name
381 if ( Wait_USER == state ) { 381 if ( Wait_USER == state ) {
382 382
383 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { 383 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
384 send( "530 Please login with USER and PASS" ); // No tr 384 send( "530 Please login with USER and PASS" ); // No tr
385 return; 385 return;
386 } 386 }
387 send( "331 User name ok, need password" ); // No tr 387 send( "331 User name ok, need password" ); // No tr
388 state = Wait_PASS; 388 state = Wait_PASS;
389 return; 389 return;
390 } 390 }
391 391
392 // waiting for password 392 // waiting for password
393 if ( Wait_PASS == state ) { 393 if ( Wait_PASS == state ) {
394 394
395 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { 395 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
396 send( "530 Please login with USER and PASS" ); // No tr 396 send( "530 Please login with USER and PASS" ); // No tr
397 return; 397 return;
398 } 398 }
399 send( "230 User logged in, proceed" ); // No tr 399 send( "230 User logged in, proceed" ); // No tr
400 state = Ready; 400 state = Ready;
401 if ( sendSync ) { 401 if ( sendSync ) {
402 sendDesktopMessage( "startSync()" ); 402 sendDesktopMessage( "startSync()" );
403 sendSync = FALSE; 403 sendSync = FALSE;
404 } 404 }
405 return; 405 return;
406 } 406 }
407 407
408 // noop (NOOP) 408 // noop (NOOP)
409 else if ( cmd == "NOOP" ) { 409 else if ( cmd == "NOOP" ) {
410 send( "200 Command okay" ); // No tr 410 send( "200 Command okay" ); // No tr
411 } 411 }
412 412
413 // call (CALL) 413 // call (CALL)
414 else if ( cmd == "CALL" ) { 414 else if ( cmd == "CALL" ) {
415 415
416 // example: call QPE/System execute(QString) addressbook 416 // example: call QPE/System execute(QString) addressbook
417 417
418 if ( msg.count() < 3 ) { 418 if ( msg.count() < 3 ) {
419 send( "500 Syntax error, command unrecognized" ); // No tr 419 send( "500 Syntax error, command unrecognized" ); // No tr
420 } 420 }
421 else { 421 else {
422 422
423 QString channel = msg[1]; 423 QString channel = msg[1];
424 QString command = msg[2]; 424 QString command = msg[2];
425 425
426 command.stripWhiteSpace(); 426 command.stripWhiteSpace();
427 427
428 int paren = command.find( "(" ); 428 int paren = command.find( "(" );
429 if ( paren <= 0 ) { 429 if ( paren <= 0 ) {
430 send( "500 Syntax error, command unrecognized" ); // No tr 430 send( "500 Syntax error, command unrecognized" ); // No tr
431 return; 431 return;
432 } 432 }
433 433
434 QString params = command.mid( paren + 1 ); 434 QString params = command.mid( paren + 1 );
435 if ( params[(int)params.length()-1] != ')' ) { 435 if ( params[(int)params.length()-1] != ')' ) {
436 send( "500 Syntax error, command unrecognized" ); // No tr 436 send( "500 Syntax error, command unrecognized" ); // No tr
437 return; 437 return;
438 } 438 }
439 439
440 params.truncate( params.length()-1 ); 440 params.truncate( params.length()-1 );
441 QByteArray buffer; 441 QByteArray buffer;
442 QDataStream ds( buffer, IO_WriteOnly ); 442 QDataStream ds( buffer, IO_WriteOnly );
443 443
444 int msgId = 3; 444 int msgId = 3;
445 445
446 QStringList paramList = QStringList::split( ",", params ); 446 QStringList paramList = QStringList::split( ",", params );
447 if ( paramList.count() > msg.count() - 3 ) { 447 if ( paramList.count() > msg.count() - 3 ) {
448 send( "500 Syntax error, command unrecognized" ); // No tr 448 send( "500 Syntax error, command unrecognized" ); // No tr
449 return; 449 return;
450 } 450 }
451 451
452 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { 452 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
453 453
454 QString arg = msg[msgId]; 454 QString arg = msg[msgId];
455 arg.replace( QRegExp("&0x20;"), " " ); 455 arg.replace( QRegExp("&0x20;"), " " );
456 arg.replace( QRegExp("&amp;"), "&" ); 456 arg.replace( QRegExp("&amp;"), "&" );
457 arg.replace( QRegExp("&0x0d;"), "\n" ); 457 arg.replace( QRegExp("&0x0d;"), "\n" );
458 arg.replace( QRegExp("&0x0a;"), "\r" ); 458 arg.replace( QRegExp("&0x0a;"), "\r" );
459 if ( *it == "QString" ) 459 if ( *it == "QString" )
460 ds << arg; 460 ds << arg;
461 else if ( *it == "QCString" ) 461 else if ( *it == "QCString" )
462 ds << arg.local8Bit(); 462 ds << arg.local8Bit();
463 else if ( *it == "int" ) 463 else if ( *it == "int" )
464 ds << arg.toInt(); 464 ds << arg.toInt();
465 else if ( *it == "bool" ) 465 else if ( *it == "bool" )
466 ds << arg.toInt(); 466 ds << arg.toInt();
467 else { 467 else {
468 send( "500 Syntax error, command unrecognized" ); // No tr 468 send( "500 Syntax error, command unrecognized" ); // No tr
469 return; 469 return;
470 } 470 }
471 msgId++; 471 msgId++;
472 } 472 }
473 473
474#ifndef QT_NO_COP 474#ifndef QT_NO_COP
475 if ( !QCopChannel::isRegistered( channel.latin1() ) ) { 475 if ( !QCopChannel::isRegistered( channel.latin1() ) ) {
476 // send message back about it 476 // send message back about it
477 QString answer = "599 ChannelNotRegistered " + channel; 477 QString answer = "599 ChannelNotRegistered " + channel;
478 send( answer ); 478 send( answer );
479 return; 479 return;
480 } 480 }
481#endif 481#endif
482 482
483#ifndef QT_NO_COP 483#ifndef QT_NO_COP
484 if ( paramList.count() ) 484 if ( paramList.count() )
485 QCopChannel::send( channel.latin1(), command.latin1(), buffer ); 485 QCopChannel::send( channel.latin1(), command.latin1(), buffer );
486 else 486 else
487 QCopChannel::send( channel.latin1(), command.latin1() ); 487 QCopChannel::send( channel.latin1(), command.latin1() );
488 488
489 send( "200 Command okay" ); // No tr 489 send( "200 Command okay" ); // No tr
490#endif 490#endif
491 } 491 }
492 } 492 }
493 // not implemented 493 // not implemented
494 else 494 else
495 send( "502 Command not implemented" ); // No tr 495 send( "502 Command not implemented" ); // No tr
496} 496}
497 497
498 498
diff --git a/core/launcher/qcopbridge.h b/core/launcher/qcopbridge.h
index 9483d9d..d5988cd 100644
--- a/core/launcher/qcopbridge.h
+++ b/core/launcher/qcopbridge.h
@@ -1,100 +1,101 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef __qcopbridge_h__ 20#ifndef __qcopbridge_h__
21#define __qcopbridge_h__ 21#define __qcopbridge_h__
22 22
23#include <qtopia/global.h> 23#include <qtopia/global.h>
24#include <qserversocket.h> 24#include <qserversocket.h>
25#include <qsocket.h> 25#include <qsocket.h>
26#include <qdir.h> 26#include <qdir.h>
27#include <qfile.h> 27#include <qfile.h>
28#include <qbuffer.h> 28#include <qbuffer.h>
29 29
30class QFileInfo; 30class QFileInfo;
31class QCopBridgePI; 31class QCopBridgePI;
32class QCopChannel; 32class QCopChannel;
33class QTimer; 33class QTimer;
34 34
35class QCopBridge : public QServerSocket 35class QCopBridge : public QServerSocket
36{ 36{
37 Q_OBJECT 37 Q_OBJECT
38 38
39public: 39public:
40 enum Mode { Qtopia1_7= 0x01, Sharp = 0x02, Both = Qtopia1_7 | Sharp }; 40 /* can not or anymore :) */
41 enum Mode { Qtopia1_7= 0x01, Sharp = 0x02, IntelliSync = 0x04 };
41 QCopBridge( Q_UINT16 port, QObject *parent = 0, const char* name = 0 ); 42 QCopBridge( Q_UINT16 port, QObject *parent = 0, const char* name = 0 );
42 virtual ~QCopBridge(); 43 virtual ~QCopBridge();
43 44
44 void newConnection( int socket ); 45 void newConnection( int socket );
45 void closeOpenConnections(); 46 void closeOpenConnections();
46 void authorizeConnections(); 47 void authorizeConnections();
47 48
48public slots: 49public slots:
49 void closed( QCopBridgePI *pi ); 50 void closed( QCopBridgePI *pi );
50 void desktopMessage( const QCString &call, const QByteArray & ); 51 void desktopMessage( const QCString &call, const QByteArray & );
51 52
52signals: 53signals:
53 void connectionClosed( const QHostAddress & ); 54 void connectionClosed( const QHostAddress & );
54 55
55protected: 56protected:
56 void timerEvent( QTimerEvent * ); 57 void timerEvent( QTimerEvent * );
57 void sendDesktopMessageOld( const QCString&, const QByteArray& ); 58 void sendDesktopMessageOld( const QCString&, const QByteArray& );
58 59
59private: 60private:
60 QCopChannel *desktopChannel; 61 QCopChannel *desktopChannel;
61 QCopChannel *cardChannel; 62 QCopChannel *cardChannel;
62 QList<QCopBridgePI> openConnections; 63 QList<QCopBridgePI> openConnections;
63 bool sendSync; 64 bool sendSync;
64 Mode m_mode; 65 Mode m_mode;
65}; 66};
66 67
67 68
68class QCopBridgePI : public QSocket 69class QCopBridgePI : public QSocket
69{ 70{
70 Q_OBJECT 71 Q_OBJECT
71 72
72 enum State { Connected, Wait_USER, Wait_PASS, Ready, Forbidden }; 73 enum State { Connected, Wait_USER, Wait_PASS, Ready, Forbidden };
73 74
74public: 75public:
75 QCopBridgePI( int socket, QObject *parent = 0, const char* name = 0 ); 76 QCopBridgePI( int socket, QObject *parent = 0, const char* name = 0 );
76 virtual ~QCopBridgePI(); 77 virtual ~QCopBridgePI();
77 78
78 void sendDesktopMessage( const QString &msg ); 79 void sendDesktopMessage( const QString &msg );
79 void sendDesktopMessage( const QCString &msg, const QByteArray& ); 80 void sendDesktopMessage( const QCString &msg, const QByteArray& );
80 void startSync() { sendSync = TRUE; } 81 void startSync() { sendSync = TRUE; }
81 bool verifyAuthorised(); 82 bool verifyAuthorised();
82 83
83signals: 84signals:
84 void connectionClosed( QCopBridgePI *); 85 void connectionClosed( QCopBridgePI *);
85 86
86protected slots: 87protected slots:
87 void read(); 88 void read();
88 void send( const QString& msg ); 89 void send( const QString& msg );
89 void process( const QString& command ); 90 void process( const QString& command );
90 void myConnectionClosed(); 91 void myConnectionClosed();
91 92
92private: 93private:
93 State state; 94 State state;
94 Q_UINT16 peerport; 95 Q_UINT16 peerport;
95 QHostAddress peeraddress; 96 QHostAddress peeraddress;
96 bool sendSync; 97 bool sendSync;
97 QTimer *timer; 98 QTimer *timer;
98}; 99};
99 100
100#endif 101#endif
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index 9cb9d7a..8367a62 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -1,1433 +1,1451 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20//#define _XOPEN_SOURCE 20//#define _XOPEN_SOURCE
21 21
22#include <opie2/oglobal.h> 22#include <opie2/oglobal.h>
23#include <qtopia/qpeapplication.h> 23#include <qtopia/qpeapplication.h>
24 24
25#ifndef Q_OS_WIN32 25#ifndef Q_OS_WIN32
26#include <pwd.h> 26#include <pwd.h>
27#include <sys/types.h> 27#include <sys/types.h>
28#include <unistd.h> 28#include <unistd.h>
29#include <stdlib.h> 29#include <stdlib.h>
30#include <time.h> 30#include <time.h>
31 31
32#ifndef Q_OS_MACX 32#ifndef Q_OS_MACX
33#include <shadow.h> 33#include <shadow.h>
34#include <crypt.h> 34#include <crypt.h>
35#endif /* Q_OS_MACX */ 35#endif /* Q_OS_MACX */
36 36
37#else 37#else
38#include <stdlib.h> 38#include <stdlib.h>
39#include <time.h> 39#include <time.h>
40#endif 40#endif
41 41
42 42
43#if defined(_OS_LINUX_) 43#if defined(_OS_LINUX_)
44#include <shadow.h> 44#include <shadow.h>
45#endif 45#endif
46 46
47#include <qdir.h> 47#include <qdir.h>
48#include <qfile.h> 48#include <qfile.h>
49#include <qtextstream.h> 49#include <qtextstream.h>
50#include <qdatastream.h> 50#include <qdatastream.h>
51#include <qmessagebox.h> 51#include <qmessagebox.h>
52#include <qstringlist.h> 52#include <qstringlist.h>
53#include <qfileinfo.h> 53#include <qfileinfo.h>
54#include <qregexp.h> 54#include <qregexp.h>
55//#include <qtopia/qcopchannel_qws.h> 55//#include <qtopia/qcopchannel_qws.h>
56#include <qtopia/process.h> 56#include <qtopia/process.h>
57#include <qtopia/global.h> 57#include <qtopia/global.h>
58#include <qtopia/config.h> 58#include <qtopia/config.h>
59#include <qtopia/private/contact.h> 59#include <qtopia/private/contact.h>
60#include <qtopia/quuid.h> 60#include <qtopia/quuid.h>
61#include <qtopia/version.h> 61#include <qtopia/version.h>
62#ifdef Q_WS_QWS 62#ifdef Q_WS_QWS
63#include <qtopia/qcopenvelope_qws.h> 63#include <qtopia/qcopenvelope_qws.h>
64#endif 64#endif
65 65
66 66
67#include "transferserver.h" 67#include "transferserver.h"
68#include <qtopia/qprocess.h> 68#include <qtopia/qprocess.h>
69 69
70const int block_size = 51200; 70const int block_size = 51200;
71 71
72TransferServer::TransferServer( Q_UINT16 port, QObject *parent, 72TransferServer::TransferServer( Q_UINT16 port, QObject *parent,
73 const char* name) 73 const char* name)
74 : QServerSocket( port, 1, parent, name ) 74 : QServerSocket( port, 1, parent, name )
75{ 75{
76 connections.setAutoDelete( TRUE ); 76 connections.setAutoDelete( TRUE );
77 if ( !ok() ) 77 if ( !ok() )
78 qWarning( "Failed to bind to port %d", port ); 78 qWarning( "Failed to bind to port %d", port );
79} 79}
80 80
81void TransferServer::authorizeConnections() 81void TransferServer::authorizeConnections()
82{ 82{
83 QListIterator<ServerPI> it(connections); 83 QListIterator<ServerPI> it(connections);
84 while ( it.current() ) { 84 while ( it.current() ) {
85 if ( !it.current()->verifyAuthorised() ) { 85 if ( !it.current()->verifyAuthorised() ) {
86 disconnect( it.current(), SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) ); 86 disconnect( it.current(), SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) );
87 connections.removeRef( it.current() ); 87 connections.removeRef( it.current() );
88 } else 88 } else
89 ++it; 89 ++it;
90 } 90 }
91} 91}
92 92
93void TransferServer::closed(ServerPI *item) 93void TransferServer::closed(ServerPI *item)
94{ 94{
95 connections.removeRef(item); 95 connections.removeRef(item);
96} 96}
97 97
98TransferServer::~TransferServer() 98TransferServer::~TransferServer()
99{ 99{
100} 100}
101 101
102void TransferServer::newConnection( int socket ) 102void TransferServer::newConnection( int socket )
103{ 103{
104 ServerPI *ptr = new ServerPI( socket, this ); 104 ServerPI *ptr = new ServerPI( socket, this );
105 connect( ptr, SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) ); 105 connect( ptr, SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) );
106 connections.append( ptr ); 106 connections.append( ptr );
107} 107}
108 108
109QString SyncAuthentication::serverId() 109QString SyncAuthentication::serverId()
110{ 110{
111 Config cfg("Security"); 111 Config cfg("Security");
112 cfg.setGroup("Sync"); 112 cfg.setGroup("Sync");
113 QString r = cfg.readEntry("serverid"); 113 QString r = cfg.readEntry("serverid");
114 114
115 if ( r.isEmpty() ) { 115 if ( r.isEmpty() ) {
116 r = OGlobal::generateUuid(); 116 r = OGlobal::generateUuid();
117 cfg.writeEntry("serverid", r ); 117 cfg.writeEntry("serverid", r );
118 } 118 }
119 return r; 119 return r;
120} 120}
121 121
122QString SyncAuthentication::ownerName() 122QString SyncAuthentication::ownerName()
123{ 123{
124 QString vfilename = Global::applicationFileName("addressbook", 124 QString vfilename = Global::applicationFileName("addressbook",
125 "businesscard.vcf"); 125 "businesscard.vcf");
126 if (QFile::exists(vfilename)) { 126 if (QFile::exists(vfilename)) {
127 Contact c; 127 Contact c;
128 c = Contact::readVCard( vfilename )[0]; 128 c = Contact::readVCard( vfilename )[0];
129 return c.fullName(); 129 return c.fullName();
130 } 130 }
131 131
132 return QString::null; 132 return QString::null;
133} 133}
134 134
135QString SyncAuthentication::loginName() 135QString SyncAuthentication::loginName()
136{ 136{
137 struct passwd *pw = 0L; 137 struct passwd *pw = 0L;
138#ifndef Q_OS_WIN32 138#ifndef Q_OS_WIN32
139 pw = getpwuid( geteuid() ); 139 pw = getpwuid( geteuid() );
140 return QString::fromLocal8Bit( pw->pw_name ); 140 return QString::fromLocal8Bit( pw->pw_name );
141#else 141#else
142 //### revise 142 //### revise
143 return QString(); 143 return QString();
144#endif 144#endif
145} 145}
146 146
147int SyncAuthentication::isAuthorized(QHostAddress peeraddress) 147int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
148{ 148{
149 Config cfg("Security"); 149 Config cfg("Security");
150 cfg.setGroup("Sync"); 150 cfg.setGroup("Sync");
151 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); 151 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
152 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); 152 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100);
153 153
154 // QHostAddress allowed; 154 // QHostAddress allowed;
155 // allowed.setAddress(allowedstr); 155 // allowed.setAddress(allowedstr);
156 // uint auth_peer = allowed.ip4Addr(); 156 // uint auth_peer = allowed.ip4Addr();
157 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); 157 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24);
158 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined 158 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined
159 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); 159 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits));
160 160
161 return (peeraddress.ip4Addr() & mask) == auth_peer; 161 return (peeraddress.ip4Addr() & mask) == auth_peer;
162} 162}
163 163
164bool SyncAuthentication::checkUser( const QString& user ) 164bool SyncAuthentication::checkUser( const QString& user )
165{ 165{
166 if ( user.isEmpty() ) return FALSE; 166 if ( user.isEmpty() ) return FALSE;
167 QString euser = loginName(); 167 QString euser = loginName();
168 return user == euser; 168 return user == euser;
169} 169}
170 170
171bool SyncAuthentication::checkPassword( const QString& password ) 171bool SyncAuthentication::checkPassword( const QString& password )
172{ 172{
173#ifdef ALLOW_UNIX_USER_FTP 173#ifdef ALLOW_UNIX_USER_FTP
174 // First, check system password... 174 // First, check system password...
175 175
176 struct passwd *pw = 0; 176 struct passwd *pw = 0;
177 struct spwd *spw = 0; 177 struct spwd *spw = 0;
178 178
179 pw = getpwuid( geteuid() ); 179 pw = getpwuid( geteuid() );
180 spw = getspnam( pw->pw_name ); 180 spw = getspnam( pw->pw_name );
181 181
182 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); 182 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
183 if ( cpwd == "x" && spw ) 183 if ( cpwd == "x" && spw )
184 cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); 184 cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
185 185
186 // Note: some systems use more than crypt for passwords. 186 // Note: some systems use more than crypt for passwords.
187 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); 187 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
188 if ( cpwd == cpassword ) 188 if ( cpwd == cpassword )
189 return TRUE; 189 return TRUE;
190#endif 190#endif
191 191
192 static int lastdenial=0; 192 static int lastdenial=0;
193 static int denials=0; 193 static int denials=0;
194 int now = time(0); 194 int now = time(0);
195 195
196 Config cfg("Security"); 196 Config cfg("Security");
197 cfg.setGroup("Sync"); 197 cfg.setGroup("SyncMode");
198 QString syncapp = cfg.readEntry("syncapp","Qtopia"); 198 int mode = cfg.readNumEntry("Mode", 0x02 );
199 199
200 //No password needed if the user really wants it 200 //No pass word needed if the user really needs it
201 if (syncapp == "IntelliSync") { 201 if (mode & 0x04) {
202 return TRUE; 202 QMessageBox unauth(
203 } 203 tr("Sync Connection"),
204 204 tr("<qt><p>An unauthorized system is requesting access to this device."
205 // Detect old Qtopia Desktop (no password) 205 "<p>You chose IntelliSync so you may I allow or deny this connection.</qt>" ),
206 QMessageBox::Warning,
207 QMessageBox::Ok, QMessageBox::Cancel|QMessageBox::Default, QMessageBox::NoButton,
208 0, QString::null, TRUE, WStyle_StaysOnTop);
209 unauth.setButtonText(QMessageBox::Ok, tr("Allow" ) );
210 unauth.setButtonText(QMessageBox::Cancel, tr("Deny"));
211 switch( unauth.exec() ) {
212 case QMessageBox::Ok:
213 return TRUE;
214 break;
215 case QMessageBox::Cancel:
216 default:
217 denials++;
218 lastdenial=now;
219 return FALSE;
220 }
221 }
222
223 // Detect old Qtopia Desktop (no password) and fail
206 if ( password.isEmpty() ) { 224 if ( password.isEmpty() ) {
207 if ( denials < 3 || now > lastdenial+600 ) { 225 if ( denials < 3 || now > lastdenial+600 ) {
208 QMessageBox unauth( 226 QMessageBox unauth(
209 tr("Sync Connection"), 227 tr("Sync Connection"),
210 tr("<p>An unauthorized system is requesting access to this device." 228 tr("<p>An unauthorized system is requesting access to this device."
211 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " 229 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, "
212 "please upgrade or change the security setting to use IntelliSync." ), 230 "please upgrade or change the security setting to use IntelliSync." ),
213 QMessageBox::Warning, 231 QMessageBox::Warning,
214 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, 232 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton,
215 0, QString::null, TRUE, WStyle_StaysOnTop); 233 0, QString::null, TRUE, WStyle_StaysOnTop);
216 unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); 234 unauth.setButtonText(QMessageBox::Cancel, tr("Deny"));
217 unauth.exec(); 235 unauth.exec();
218 236
219 denials++; 237 denials++;
220 lastdenial=now; 238 lastdenial=now;
221 } 239 }
222 return FALSE; 240 return FALSE;
223 241
224 } 242 }
225 243
226 // Second, check sync password... 244 // Second, check sync password...
227 245
228 static int lock=0; 246 static int lock=0;
229 if ( lock ) return FALSE; 247 if ( lock ) return FALSE;
230 248
231 ++lock; 249 ++lock;
232 250
233 /* 251 /*
234 * we need to support old Sync software and QtopiaDesktop 252 * we need to support old Sync software and QtopiaDesktop
235 */ 253 */
236 if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) { 254 if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) {
237 Config cfg( "Security" ); 255 Config cfg( "Security" );
238 cfg.setGroup("Sync"); 256 cfg.setGroup("Sync");
239 QStringList pwds = cfg.readListEntry("Passwords",' '); 257 QStringList pwds = cfg.readListEntry("Passwords",' ');
240 for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) { 258 for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) {
241#ifndef Q_OS_WIN32 259#ifndef Q_OS_WIN32
242 QString cpassword = QString::fromLocal8Bit( 260 QString cpassword = QString::fromLocal8Bit(
243 crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) ); 261 crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) );
244#else 262#else
245 // ### revise 263 // ### revise
246 QString cpassword(""); 264 QString cpassword("");
247#endif 265#endif
248 if ( *it == cpassword ) { 266 if ( *it == cpassword ) {
249 lock--; 267 lock--;
250 return TRUE; 268 return TRUE;
251 } 269 }
252 } 270 }
253 271
254 // Unrecognized system. Be careful... 272 // Unrecognized system. Be careful...
255 QMessageBox unrecbox( 273 QMessageBox unrecbox(
256 tr("Sync Connection"), 274 tr("Sync Connection"),
257 tr("<p>An unrecognized system is requesting access to this device." 275 tr("<p>An unrecognized system is requesting access to this device."
258 "<p>If you have just initiated a Sync for the first time, this is normal."), 276 "<p>If you have just initiated a Sync for the first time, this is normal."),
259 QMessageBox::Warning, 277 QMessageBox::Warning,
260 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, 278 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton,
261 0, QString::null, TRUE, WStyle_StaysOnTop); 279 0, QString::null, TRUE, WStyle_StaysOnTop);
262 unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny")); 280 unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny"));
263 unrecbox.setButtonText(QMessageBox::Yes, tr("Allow")); 281 unrecbox.setButtonText(QMessageBox::Yes, tr("Allow"));
264 282
265 if ( (denials > 2 && now < lastdenial+600) 283 if ( (denials > 2 && now < lastdenial+600)
266 || unrecbox.exec() != QMessageBox::Yes) 284 || unrecbox.exec() != QMessageBox::Yes)
267 { 285 {
268 denials++; 286 denials++;
269 lastdenial=now; 287 lastdenial=now;
270 lock--; 288 lock--;
271 return FALSE; 289 return FALSE;
272 } else { 290 } else {
273 const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."; 291 const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/.";
274 char salt[2]; 292 char salt[2];
275 salt[0]= salty[rand() % (sizeof(salty)-1)]; 293 salt[0]= salty[rand() % (sizeof(salty)-1)];
276 salt[1]= salty[rand() % (sizeof(salty)-1)]; 294 salt[1]= salty[rand() % (sizeof(salty)-1)];
277#ifndef Q_OS_WIN32 295#ifndef Q_OS_WIN32
278 QString cpassword = QString::fromLocal8Bit( 296 QString cpassword = QString::fromLocal8Bit(
279 crypt( password.mid(8).local8Bit(), salt ) ); 297 crypt( password.mid(8).local8Bit(), salt ) );
280#else 298#else
281 //### revise 299 //### revise
282 QString cpassword(""); 300 QString cpassword("");
283#endif 301#endif
284 denials=0; 302 denials=0;
285 pwds.prepend(cpassword); 303 pwds.prepend(cpassword);
286 cfg.writeEntry("Passwords",pwds,' '); 304 cfg.writeEntry("Passwords",pwds,' ');
287 lock--; 305 lock--;
288 return TRUE; 306 return TRUE;
289 } 307 }
290 } 308 }
291 lock--; 309 lock--;
292 310
293 return FALSE; 311 return FALSE;
294} 312}
295 313
296 314
297ServerPI::ServerPI( int socket, QObject *parent, const char* name ) 315ServerPI::ServerPI( int socket, QObject *parent, const char* name )
298 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ), 316 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ),
299 storFileSize(-1) 317 storFileSize(-1)
300{ 318{
301 state = Connected; 319 state = Connected;
302 320
303 setSocket( socket ); 321 setSocket( socket );
304 322
305 peerport = peerPort(); 323 peerport = peerPort();
306 peeraddress = peerAddress(); 324 peeraddress = peerAddress();
307 325
308#ifndef INSECURE 326#ifndef INSECURE
309 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 327 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
310 state = Forbidden; 328 state = Forbidden;
311 startTimer( 0 ); 329 startTimer( 0 );
312 } else 330 } else
313#endif 331#endif
314 { 332 {
315 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 333 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
316 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 334 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
317 335
318 passiv = FALSE; 336 passiv = FALSE;
319 for( int i = 0; i < 4; i++ ) 337 for( int i = 0; i < 4; i++ )
320 wait[i] = FALSE; 338 wait[i] = FALSE;
321 339
322 send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr 340 send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr
323 state = Wait_USER; 341 state = Wait_USER;
324 342
325 dtp = new ServerDTP( this ); 343 dtp = new ServerDTP( this );
326 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); 344 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) );
327 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); 345 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) );
328 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); 346 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) );
329 347
330 348
331 directory = QDir::currentDirPath(); 349 directory = QDir::currentDirPath();
332 350
333 static int p = 1024; 351 static int p = 1024;
334 352
335 while ( !serversocket || !serversocket->ok() ) { 353 while ( !serversocket || !serversocket->ok() ) {
336 delete serversocket; 354 delete serversocket;
337 serversocket = new ServerSocket( ++p, this ); 355 serversocket = new ServerSocket( ++p, this );
338 } 356 }
339 connect( serversocket, SIGNAL( newIncomming( int ) ), 357 connect( serversocket, SIGNAL( newIncomming( int ) ),
340 SLOT( newConnection( int ) ) ); 358 SLOT( newConnection( int ) ) );
341 } 359 }
342} 360}
343 361
344ServerPI::~ServerPI() 362ServerPI::~ServerPI()
345{ 363{
346 close(); 364 close();
347 365
348 if ( dtp ) 366 if ( dtp )
349 dtp->close(); 367 dtp->close();
350 delete dtp; 368 delete dtp;
351 delete serversocket; 369 delete serversocket;
352} 370}
353 371
354bool ServerPI::verifyAuthorised() 372bool ServerPI::verifyAuthorised()
355{ 373{
356 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { 374 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) {
357 state = Forbidden; 375 state = Forbidden;
358 return FALSE; 376 return FALSE;
359 } 377 }
360 return TRUE; 378 return TRUE;
361} 379}
362 380
363void ServerPI::connectionClosed() 381void ServerPI::connectionClosed()
364{ 382{
365 // qDebug( "Debug: Connection closed" ); 383 // qDebug( "Debug: Connection closed" );
366 emit connectionClosed(this); 384 emit connectionClosed(this);
367} 385}
368 386
369void ServerPI::send( const QString& msg ) 387void ServerPI::send( const QString& msg )
370{ 388{
371 QTextStream os( this ); 389 QTextStream os( this );
372 os << msg << endl; 390 os << msg << endl;
373 //qDebug( "Reply: %s", msg.latin1() ); 391 //qDebug( "Reply: %s", msg.latin1() );
374} 392}
375 393
376void ServerPI::read() 394void ServerPI::read()
377{ 395{
378 while ( canReadLine() ) 396 while ( canReadLine() )
379 process( readLine().stripWhiteSpace() ); 397 process( readLine().stripWhiteSpace() );
380} 398}
381 399
382bool ServerPI::checkReadFile( const QString& file ) 400bool ServerPI::checkReadFile( const QString& file )
383{ 401{
384 QString filename; 402 QString filename;
385 403
386 if ( file[0] != "/" ) 404 if ( file[0] != "/" )
387 filename = directory.path() + "/" + file; 405 filename = directory.path() + "/" + file;
388 else 406 else
389 filename = file; 407 filename = file;
390 408
391 QFileInfo fi( filename ); 409 QFileInfo fi( filename );
392 return ( fi.exists() && fi.isReadable() ); 410 return ( fi.exists() && fi.isReadable() );
393} 411}
394 412
395bool ServerPI::checkWriteFile( const QString& file ) 413bool ServerPI::checkWriteFile( const QString& file )
396{ 414{
397 QString filename; 415 QString filename;
398 416
399 if ( file[0] != "/" ) 417 if ( file[0] != "/" )
400 filename = directory.path() + "/" + file; 418 filename = directory.path() + "/" + file;
401 else 419 else
402 filename = file; 420 filename = file;
403 421
404 QFileInfo fi( filename ); 422 QFileInfo fi( filename );
405 423
406 if ( fi.exists() ) 424 if ( fi.exists() )
407 if ( !QFile( filename ).remove() ) 425 if ( !QFile( filename ).remove() )
408 return FALSE; 426 return FALSE;
409 return TRUE; 427 return TRUE;
410} 428}
411 429
412void ServerPI::process( const QString& message ) 430void ServerPI::process( const QString& message )
413{ 431{
414 //qDebug( "Command: %s", message.latin1() ); 432 //qDebug( "Command: %s", message.latin1() );
415 433
416 // split message using "," as separator 434 // split message using "," as separator
417 QStringList msg = QStringList::split( " ", message ); 435 QStringList msg = QStringList::split( " ", message );
418 if ( msg.isEmpty() ) return; 436 if ( msg.isEmpty() ) return;
419 437
420 // command token 438 // command token
421 QString cmd = msg[0].upper(); 439 QString cmd = msg[0].upper();
422 440
423 // argument token 441 // argument token
424 QString arg; 442 QString arg;
425 if ( msg.count() >= 2 ) 443 if ( msg.count() >= 2 )
426 arg = msg[1]; 444 arg = msg[1];
427 445
428 // full argument string 446 // full argument string
429 QString args; 447 QString args;
430 if ( msg.count() >= 2 ) { 448 if ( msg.count() >= 2 ) {
431 QStringList copy( msg ); 449 QStringList copy( msg );
432 // FIXME: for Qt3 450 // FIXME: for Qt3
433 // copy.pop_front() 451 // copy.pop_front()
434 copy.remove( copy.begin() ); 452 copy.remove( copy.begin() );
435 args = copy.join( " " ); 453 args = copy.join( " " );
436 } 454 }
437 455
438 //qDebug( "args: %s", args.latin1() ); 456 //qDebug( "args: %s", args.latin1() );
439 457
440 // we always respond to QUIT, regardless of state 458 // we always respond to QUIT, regardless of state
441 if ( cmd == "QUIT" ) { 459 if ( cmd == "QUIT" ) {
442 send( "211 Good bye!" ); // No tr 460 send( "211 Good bye!" ); // No tr
443 close(); 461 close();
444 return; 462 return;
445 } 463 }
446 464
447 // connected to client 465 // connected to client
448 if ( Connected == state ) 466 if ( Connected == state )
449 return; 467 return;
450 468
451 // waiting for user name 469 // waiting for user name
452 if ( Wait_USER == state ) { 470 if ( Wait_USER == state ) {
453 471
454 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { 472 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
455 send( "530 Please login with USER and PASS" ); // No tr 473 send( "530 Please login with USER and PASS" ); // No tr
456 return; 474 return;
457 } 475 }
458 send( "331 User name ok, need password" ); // No tr 476 send( "331 User name ok, need password" ); // No tr
459 state = Wait_PASS; 477 state = Wait_PASS;
460 return; 478 return;
461 } 479 }
462 480
463 // waiting for password 481 // waiting for password
464 if ( Wait_PASS == state ) { 482 if ( Wait_PASS == state ) {
465 483
466 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { 484 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
467 send( "530 Please login with USER and PASS" ); // No tr 485 send( "530 Please login with USER and PASS" ); // No tr
468 return; 486 return;
469 } 487 }
470 send( "230 User logged in, proceed" ); // No tr 488 send( "230 User logged in, proceed" ); // No tr
471 state = Ready; 489 state = Ready;
472 return; 490 return;
473 } 491 }
474 492
475 // ACCESS CONTROL COMMANDS 493 // ACCESS CONTROL COMMANDS
476 494
477 // Only an ALLO sent immediately before STOR is valid. 495 // Only an ALLO sent immediately before STOR is valid.
478 if ( cmd != "STOR" ) 496 if ( cmd != "STOR" )
479 storFileSize = -1; 497 storFileSize = -1;
480 498
481 // account (ACCT) 499 // account (ACCT)
482 if ( cmd == "ACCT" ) { 500 if ( cmd == "ACCT" ) {
483 // even wu-ftp does not support it 501 // even wu-ftp does not support it
484 send( "502 Command not implemented" ); // No tr 502 send( "502 Command not implemented" ); // No tr
485 } 503 }
486 504
487 // change working directory (CWD) 505 // change working directory (CWD)
488 else if ( cmd == "CWD" ) { 506 else if ( cmd == "CWD" ) {
489 507
490 if ( !args.isEmpty() ) { 508 if ( !args.isEmpty() ) {
491 if ( directory.cd( args, TRUE ) ) 509 if ( directory.cd( args, TRUE ) )
492 send( "250 Requested file action okay, completed" ); // No tr 510 send( "250 Requested file action okay, completed" ); // No tr
493 else 511 else
494 send( "550 Requested action not taken" ); // No tr 512 send( "550 Requested action not taken" ); // No tr
495 } 513 }
496 else 514 else
497 send( "500 Syntax error, command unrecognized" ); // No tr 515 send( "500 Syntax error, command unrecognized" ); // No tr
498 } 516 }
499 517
500 // change to parent directory (CDUP) 518 // change to parent directory (CDUP)
501 else if ( cmd == "CDUP" ) { 519 else if ( cmd == "CDUP" ) {
502 if ( directory.cdUp() ) 520 if ( directory.cdUp() )
503 send( "250 Requested file action okay, completed" ); // No tr 521 send( "250 Requested file action okay, completed" ); // No tr
504 else 522 else
505 send( "550 Requested action not taken" ); // No tr 523 send( "550 Requested action not taken" ); // No tr
506 } 524 }
507 525
508 // structure mount (SMNT) 526 // structure mount (SMNT)
509 else if ( cmd == "SMNT" ) { 527 else if ( cmd == "SMNT" ) {
510 // even wu-ftp does not support it 528 // even wu-ftp does not support it
511 send( "502 Command not implemented" ); // No tr 529 send( "502 Command not implemented" ); // No tr
512 } 530 }
513 531
514 // reinitialize (REIN) 532 // reinitialize (REIN)
515 else if ( cmd == "REIN" ) { 533 else if ( cmd == "REIN" ) {
516 // even wu-ftp does not support it 534 // even wu-ftp does not support it
517 send( "502 Command not implemented" ); // No tr 535 send( "502 Command not implemented" ); // No tr
518 } 536 }
519 537
520 538
521 // TRANSFER PARAMETER COMMANDS 539 // TRANSFER PARAMETER COMMANDS
522 540
523 541
524 // data port (PORT) 542 // data port (PORT)
525 else if ( cmd == "PORT" ) { 543 else if ( cmd == "PORT" ) {
526 if ( parsePort( arg ) ) 544 if ( parsePort( arg ) )
527 send( "200 Command okay" ); // No tr 545 send( "200 Command okay" ); // No tr
528 else 546 else
529 send( "500 Syntax error, command unrecognized" ); // No tr 547 send( "500 Syntax error, command unrecognized" ); // No tr
530 } 548 }
531 549
532 // passive (PASV) 550 // passive (PASV)
533 else if ( cmd == "PASV" ) { 551 else if ( cmd == "PASV" ) {
534 passiv = TRUE; 552 passiv = TRUE;
535 send( "227 Entering Passive Mode (" // No tr 553 send( "227 Entering Passive Mode (" // No tr
536 + address().toString().replace( QRegExp( "\\." ), "," ) + "," 554 + address().toString().replace( QRegExp( "\\." ), "," ) + ","
537 + QString::number( ( serversocket->port() ) >> 8 ) + "," 555 + QString::number( ( serversocket->port() ) >> 8 ) + ","
538 + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); 556 + QString::number( ( serversocket->port() ) & 0xFF ) +")" );
539 } 557 }
540 558
541 // representation type (TYPE) 559 // representation type (TYPE)
542 else if ( cmd == "TYPE" ) { 560 else if ( cmd == "TYPE" ) {
543 if ( arg.upper() == "A" || arg.upper() == "I" ) 561 if ( arg.upper() == "A" || arg.upper() == "I" )
544 send( "200 Command okay" ); // No tr 562 send( "200 Command okay" ); // No tr
545 else 563 else
546 send( "504 Command not implemented for that parameter" ); // No tr 564 send( "504 Command not implemented for that parameter" ); // No tr
547 } 565 }
548 566
549 // file structure (STRU) 567 // file structure (STRU)
550 else if ( cmd == "STRU" ) { 568 else if ( cmd == "STRU" ) {
551 if ( arg.upper() == "F" ) 569 if ( arg.upper() == "F" )
552 send( "200 Command okay" ); // No tr 570 send( "200 Command okay" ); // No tr
553 else 571 else
554 send( "504 Command not implemented for that parameter" ); // No tr 572 send( "504 Command not implemented for that parameter" ); // No tr
555 } 573 }
556 574
557 // transfer mode (MODE) 575 // transfer mode (MODE)
558 else if ( cmd == "MODE" ) { 576 else if ( cmd == "MODE" ) {
559 if ( arg.upper() == "S" ) 577 if ( arg.upper() == "S" )
560 send( "200 Command okay" ); // No tr 578 send( "200 Command okay" ); // No tr
561 else 579 else
562 send( "504 Command not implemented for that parameter" ); // No tr 580 send( "504 Command not implemented for that parameter" ); // No tr
563 } 581 }
564 582
565 583
566 // FTP SERVICE COMMANDS 584 // FTP SERVICE COMMANDS
567 585
568 586
569 // retrieve (RETR) 587 // retrieve (RETR)
570 else if ( cmd == "RETR" ) 588 else if ( cmd == "RETR" )
571 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) 589 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) )
572 || backupRestoreGzip( absFilePath( args ) ) ) { 590 || backupRestoreGzip( absFilePath( args ) ) ) {
573 send( "150 File status okay" ); // No tr 591 send( "150 File status okay" ); // No tr
574 sendFile( absFilePath( args ) ); 592 sendFile( absFilePath( args ) );
575 } 593 }
576 else { 594 else {
577 qDebug("550 Requested action not taken"); 595 qDebug("550 Requested action not taken");
578 send( "550 Requested action not taken" ); // No tr 596 send( "550 Requested action not taken" ); // No tr
579 } 597 }
580 598
581 // store (STOR) 599 // store (STOR)
582 else if ( cmd == "STOR" ) 600 else if ( cmd == "STOR" )
583 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { 601 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) {
584 send( "150 File status okay" ); // No tr 602 send( "150 File status okay" ); // No tr
585 retrieveFile( absFilePath( args ) ); 603 retrieveFile( absFilePath( args ) );
586 } 604 }
587 else 605 else
588 send( "550 Requested action not taken" ); // No tr 606 send( "550 Requested action not taken" ); // No tr
589 607
590 // store unique (STOU) 608 // store unique (STOU)
591 else if ( cmd == "STOU" ) { 609 else if ( cmd == "STOU" ) {
592 send( "502 Command not implemented" ); // No tr 610 send( "502 Command not implemented" ); // No tr
593 } 611 }
594 612
595 // append (APPE) 613 // append (APPE)
596 else if ( cmd == "APPE" ) { 614 else if ( cmd == "APPE" ) {
597 send( "502 Command not implemented" ); // No tr 615 send( "502 Command not implemented" ); // No tr
598 } 616 }
599 617
600 // allocate (ALLO) 618 // allocate (ALLO)
601 else if ( cmd == "ALLO" ) { 619 else if ( cmd == "ALLO" ) {
602 storFileSize = args.toInt(); 620 storFileSize = args.toInt();
603 send( "200 Command okay" ); // No tr 621 send( "200 Command okay" ); // No tr
604 } 622 }
605 623
606 // restart (REST) 624 // restart (REST)
607 else if ( cmd == "REST" ) { 625 else if ( cmd == "REST" ) {
608 send( "502 Command not implemented" ); // No tr 626 send( "502 Command not implemented" ); // No tr
609 } 627 }
610 628
611 // rename from (RNFR) 629 // rename from (RNFR)
612 else if ( cmd == "RNFR" ) { 630 else if ( cmd == "RNFR" ) {
613 renameFrom = QString::null; 631 renameFrom = QString::null;
614 if ( args.isEmpty() ) 632 if ( args.isEmpty() )
615 send( "500 Syntax error, command unrecognized" ); // No tr 633 send( "500 Syntax error, command unrecognized" ); // No tr
616 else { 634 else {
617 QFile file( absFilePath( args ) ); 635 QFile file( absFilePath( args ) );
618 if ( file.exists() ) { 636 if ( file.exists() ) {
619 send( "350 File exists, ready for destination name" ); // No tr 637 send( "350 File exists, ready for destination name" ); // No tr
620 renameFrom = absFilePath( args ); 638 renameFrom = absFilePath( args );
621 } 639 }
622 else 640 else
623 send( "550 Requested action not taken" ); // No tr 641 send( "550 Requested action not taken" ); // No tr
624 } 642 }
625 } 643 }
626 644
627 // rename to (RNTO) 645 // rename to (RNTO)
628 else if ( cmd == "RNTO" ) { 646 else if ( cmd == "RNTO" ) {
629 if ( lastCommand != "RNFR" ) 647 if ( lastCommand != "RNFR" )
630 send( "503 Bad sequence of commands" ); // No tr 648 send( "503 Bad sequence of commands" ); // No tr
631 else if ( args.isEmpty() ) 649 else if ( args.isEmpty() )
632 send( "500 Syntax error, command unrecognized" ); // No tr 650 send( "500 Syntax error, command unrecognized" ); // No tr
633 else { 651 else {
634 QDir dir( absFilePath( args ) ); 652 QDir dir( absFilePath( args ) );
635 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) 653 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) )
636 send( "250 Requested file action okay, completed." ); // No tr 654 send( "250 Requested file action okay, completed." ); // No tr
637 else 655 else
638 send( "550 Requested action not taken" ); // No tr 656 send( "550 Requested action not taken" ); // No tr
639 } 657 }
640 } 658 }
641 659
642 // abort (ABOR) 660 // abort (ABOR)
643 else if ( cmd.contains( "ABOR" ) ) { 661 else if ( cmd.contains( "ABOR" ) ) {
644 dtp->close(); 662 dtp->close();
645 if ( dtp->dtpMode() != ServerDTP::Idle ) 663 if ( dtp->dtpMode() != ServerDTP::Idle )
646 send( "426 Connection closed; transfer aborted" ); // No tr 664 send( "426 Connection closed; transfer aborted" ); // No tr
647 else 665 else
648 send( "226 Closing data connection" ); // No tr 666 send( "226 Closing data connection" ); // No tr
649 } 667 }
650 668
651 // delete (DELE) 669 // delete (DELE)
652 else if ( cmd == "DELE" ) { 670 else if ( cmd == "DELE" ) {
653 if ( args.isEmpty() ) 671 if ( args.isEmpty() )
654 send( "500 Syntax error, command unrecognized" ); // No tr 672 send( "500 Syntax error, command unrecognized" ); // No tr
655 else { 673 else {
656 QFile file( absFilePath( args ) ) ; 674 QFile file( absFilePath( args ) ) ;
657 if ( file.remove() ) { 675 if ( file.remove() ) {
658 send( "250 Requested file action okay, completed" ); // No tr 676 send( "250 Requested file action okay, completed" ); // No tr
659 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 677 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
660 e << file.name(); 678 e << file.name();
661 } else { 679 } else {
662 send( "550 Requested action not taken" ); // No tr 680 send( "550 Requested action not taken" ); // No tr
663 } 681 }
664 } 682 }
665 } 683 }
666 684
667 // remove directory (RMD) 685 // remove directory (RMD)
668 else if ( cmd == "RMD" ) { 686 else if ( cmd == "RMD" ) {
669 if ( args.isEmpty() ) 687 if ( args.isEmpty() )
670 send( "500 Syntax error, command unrecognized" ); // No tr 688 send( "500 Syntax error, command unrecognized" ); // No tr
671 else { 689 else {
672 QDir dir; 690 QDir dir;
673 if ( dir.rmdir( absFilePath( args ), TRUE ) ) 691 if ( dir.rmdir( absFilePath( args ), TRUE ) )
674 send( "250 Requested file action okay, completed" ); // No tr 692 send( "250 Requested file action okay, completed" ); // No tr
675 else 693 else
676 send( "550 Requested action not taken" ); // No tr 694 send( "550 Requested action not taken" ); // No tr
677 } 695 }
678 } 696 }
679 697
680 // make directory (MKD) 698 // make directory (MKD)
681 else if ( cmd == "MKD" ) { 699 else if ( cmd == "MKD" ) {
682 if ( args.isEmpty() ) { 700 if ( args.isEmpty() ) {
683 qDebug(" Error: no arg"); 701 qDebug(" Error: no arg");
684 send( "500 Syntax error, command unrecognized" ); // No tr 702 send( "500 Syntax error, command unrecognized" ); // No tr
685 } 703 }
686 else { 704 else {
687 QDir dir; 705 QDir dir;
688 if ( dir.mkdir( absFilePath( args ), TRUE ) ) 706 if ( dir.mkdir( absFilePath( args ), TRUE ) )
689 send( "250 Requested file action okay, completed." ); // No tr 707 send( "250 Requested file action okay, completed." ); // No tr
690 else 708 else
691 send( "550 Requested action not taken" ); // No tr 709 send( "550 Requested action not taken" ); // No tr
692 } 710 }
693 } 711 }
694 712
695 // print working directory (PWD) 713 // print working directory (PWD)
696 else if ( cmd == "PWD" ) { 714 else if ( cmd == "PWD" ) {
697 send( "257 \"" + directory.path() +"\"" ); 715 send( "257 \"" + directory.path() +"\"" );
698 } 716 }
699 717
700 // list (LIST) 718 // list (LIST)
701 else if ( cmd == "LIST" ) { 719 else if ( cmd == "LIST" ) {
702 if ( sendList( absFilePath( args ) ) ) 720 if ( sendList( absFilePath( args ) ) )
703 send( "150 File status okay" ); // No tr 721 send( "150 File status okay" ); // No tr
704 else 722 else
705 send( "500 Syntax error, command unrecognized" ); // No tr 723 send( "500 Syntax error, command unrecognized" ); // No tr
706 } 724 }
707 725
708 // size (SIZE) 726 // size (SIZE)
709 else if ( cmd == "SIZE" ) { 727 else if ( cmd == "SIZE" ) {
710 QString filePath = absFilePath( args ); 728 QString filePath = absFilePath( args );
711 QFileInfo fi( filePath ); 729 QFileInfo fi( filePath );
712 bool gzipfile = backupRestoreGzip( filePath ); 730 bool gzipfile = backupRestoreGzip( filePath );
713 if ( !fi.exists() && !gzipfile ) 731 if ( !fi.exists() && !gzipfile )
714 send( "500 Syntax error, command unrecognized" ); // No tr 732 send( "500 Syntax error, command unrecognized" ); // No tr
715 else { 733 else {
716 if ( !gzipfile ) 734 if ( !gzipfile )
717 send( "213 " + QString::number( fi.size() ) ); 735 send( "213 " + QString::number( fi.size() ) );
718 else { 736 else {
719 Process duproc( QString("du") ); 737 Process duproc( QString("du") );
720 duproc.addArgument("-s"); 738 duproc.addArgument("-s");
721 QString in, out; 739 QString in, out;
722 if ( !duproc.exec(in, out) ) { 740 if ( !duproc.exec(in, out) ) {
723 qDebug("du process failed; just sending back 1K"); 741 qDebug("du process failed; just sending back 1K");
724 send( "213 1024"); 742 send( "213 1024");
725 } 743 }
726 else { 744 else {
727 QString size = out.left( out.find("\t") ); 745 QString size = out.left( out.find("\t") );
728 int guess = size.toInt()/5; 746 int guess = size.toInt()/5;
729 if ( filePath.contains("doc") ) // No tr 747 if ( filePath.contains("doc") ) // No tr
730 guess *= 1000; 748 guess *= 1000;
731 qDebug("sending back gzip guess of %d", guess); 749 qDebug("sending back gzip guess of %d", guess);
732 send( "213 " + QString::number(guess) ); 750 send( "213 " + QString::number(guess) );
733 } 751 }
734 } 752 }
735 } 753 }
736 } 754 }
737 // name list (NLST) 755 // name list (NLST)
738 else if ( cmd == "NLST" ) { 756 else if ( cmd == "NLST" ) {
739 send( "502 Command not implemented" ); // No tr 757 send( "502 Command not implemented" ); // No tr
740 } 758 }
741 759
742 // site parameters (SITE) 760 // site parameters (SITE)
743 else if ( cmd == "SITE" ) { 761 else if ( cmd == "SITE" ) {
744 send( "502 Command not implemented" ); // No tr 762 send( "502 Command not implemented" ); // No tr
745 } 763 }
746 764
747 // system (SYST) 765 // system (SYST)
748 else if ( cmd == "SYST" ) { 766 else if ( cmd == "SYST" ) {
749 send( "215 UNIX Type: L8" ); // No tr 767 send( "215 UNIX Type: L8" ); // No tr
750 } 768 }
751 769
752 // status (STAT) 770 // status (STAT)
753 else if ( cmd == "STAT" ) { 771 else if ( cmd == "STAT" ) {
754 send( "502 Command not implemented" ); // No tr 772 send( "502 Command not implemented" ); // No tr
755 } 773 }
756 774
757 // help (HELP ) 775 // help (HELP )
758 else if ( cmd == "HELP" ) { 776 else if ( cmd == "HELP" ) {
759 send( "502 Command not implemented" ); // No tr 777 send( "502 Command not implemented" ); // No tr
760 } 778 }
761 779
762 // noop (NOOP) 780 // noop (NOOP)
763 else if ( cmd == "NOOP" ) { 781 else if ( cmd == "NOOP" ) {
764 send( "200 Command okay" ); // No tr 782 send( "200 Command okay" ); // No tr
765 } 783 }
766 784
767 // not implemented 785 // not implemented
768 else 786 else
769 send( "502 Command not implemented" ); // No tr 787 send( "502 Command not implemented" ); // No tr
770 788
771 lastCommand = cmd; 789 lastCommand = cmd;
772} 790}
773 791
774bool ServerPI::backupRestoreGzip( const QString &file ) 792bool ServerPI::backupRestoreGzip( const QString &file )
775{ 793{
776 return (file.find( "backup" ) != -1 && // No tr 794 return (file.find( "backup" ) != -1 && // No tr
777 file.findRev( ".tgz" ) == (int)file.length()-4 ); 795 file.findRev( ".tgz" ) == (int)file.length()-4 );
778} 796}
779 797
780bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) 798bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets )
781{ 799{
782 if ( file.find( "backup" ) != -1 && // No tr 800 if ( file.find( "backup" ) != -1 && // No tr
783 file.findRev( ".tgz" ) == (int)file.length()-4 ) { 801 file.findRev( ".tgz" ) == (int)file.length()-4 ) {
784 QFileInfo info( file ); 802 QFileInfo info( file );
785 targets = info.dirPath( TRUE ); 803 targets = info.dirPath( TRUE );
786 qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), 804 qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(),
787 targets.join(" ").latin1() ); 805 targets.join(" ").latin1() );
788 return true; 806 return true;
789 } 807 }
790 return false; 808 return false;
791} 809}
792 810
793void ServerPI::sendFile( const QString& file ) 811void ServerPI::sendFile( const QString& file )
794{ 812{
795 if ( passiv ) { 813 if ( passiv ) {
796 wait[SendFile] = TRUE; 814 wait[SendFile] = TRUE;
797 waitfile = file; 815 waitfile = file;
798 if ( waitsocket ) 816 if ( waitsocket )
799 newConnection( waitsocket ); 817 newConnection( waitsocket );
800 } 818 }
801 else { 819 else {
802 QStringList targets; 820 QStringList targets;
803 if ( backupRestoreGzip( file, targets ) ) 821 if ( backupRestoreGzip( file, targets ) )
804 dtp->sendGzipFile( file, targets, peeraddress, peerport ); 822 dtp->sendGzipFile( file, targets, peeraddress, peerport );
805 else dtp->sendFile( file, peeraddress, peerport ); 823 else dtp->sendFile( file, peeraddress, peerport );
806 } 824 }
807} 825}
808 826
809void ServerPI::retrieveFile( const QString& file ) 827void ServerPI::retrieveFile( const QString& file )
810{ 828{
811 if ( passiv ) { 829 if ( passiv ) {
812 wait[RetrieveFile] = TRUE; 830 wait[RetrieveFile] = TRUE;
813 waitfile = file; 831 waitfile = file;
814 if ( waitsocket ) 832 if ( waitsocket )
815 newConnection( waitsocket ); 833 newConnection( waitsocket );
816 } 834 }
817 else { 835 else {
818 QStringList targets; 836 QStringList targets;
819 if ( backupRestoreGzip( file, targets ) ) 837 if ( backupRestoreGzip( file, targets ) )
820 dtp->retrieveGzipFile( file, peeraddress, peerport ); 838 dtp->retrieveGzipFile( file, peeraddress, peerport );
821 else 839 else
822 dtp->retrieveFile( file, peeraddress, peerport, storFileSize ); 840 dtp->retrieveFile( file, peeraddress, peerport, storFileSize );
823 } 841 }
824} 842}
825 843
826bool ServerPI::parsePort( const QString& pp ) 844bool ServerPI::parsePort( const QString& pp )
827{ 845{
828 QStringList p = QStringList::split( ",", pp ); 846 QStringList p = QStringList::split( ",", pp );
829 if ( p.count() != 6 ) return FALSE; 847 if ( p.count() != 6 ) return FALSE;
830 848
831 // h1,h2,h3,h4,p1,p2 849 // h1,h2,h3,h4,p1,p2
832 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + 850 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) +
833 ( p[2].toInt() << 8 ) + p[3].toInt() ); 851 ( p[2].toInt() << 8 ) + p[3].toInt() );
834 peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); 852 peerport = ( p[4].toInt() << 8 ) + p[5].toInt();
835 return TRUE; 853 return TRUE;
836} 854}
837 855
838void ServerPI::dtpCompleted() 856void ServerPI::dtpCompleted()
839{ 857{
840 send( "226 Closing data connection, file transfer successful" ); // No tr 858 send( "226 Closing data connection, file transfer successful" ); // No tr
841 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { 859 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) {
842 QString fn = dtp->fileName(); 860 QString fn = dtp->fileName();
843 if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) { 861 if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) {
844 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 862 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
845 e << fn; 863 e << fn;
846 } 864 }
847 } 865 }
848 waitsocket = 0; 866 waitsocket = 0;
849 dtp->close(); 867 dtp->close();
850 storFileSize = -1; 868 storFileSize = -1;
851} 869}
852 870
853void ServerPI::dtpFailed() 871void ServerPI::dtpFailed()
854{ 872{
855 dtp->close(); 873 dtp->close();
856 waitsocket = 0; 874 waitsocket = 0;
857 send( "451 Requested action aborted: local error in processing" ); // No tr 875 send( "451 Requested action aborted: local error in processing" ); // No tr
858 storFileSize = -1; 876 storFileSize = -1;
859} 877}
860 878
861void ServerPI::dtpError( int ) 879void ServerPI::dtpError( int )
862{ 880{
863 dtp->close(); 881 dtp->close();
864 waitsocket = 0; 882 waitsocket = 0;
865 send( "451 Requested action aborted: local error in processing" ); // No tr 883 send( "451 Requested action aborted: local error in processing" ); // No tr
866 storFileSize = -1; 884 storFileSize = -1;
867} 885}
868 886
869bool ServerPI::sendList( const QString& arg ) 887bool ServerPI::sendList( const QString& arg )
870{ 888{
871 QByteArray listing; 889 QByteArray listing;
872 QBuffer buffer( listing ); 890 QBuffer buffer( listing );
873 891
874 if ( !buffer.open( IO_WriteOnly ) ) 892 if ( !buffer.open( IO_WriteOnly ) )
875 return FALSE; 893 return FALSE;
876 894
877 QTextStream ts( &buffer ); 895 QTextStream ts( &buffer );
878 QString fn = arg; 896 QString fn = arg;
879 897
880 if ( fn.isEmpty() ) 898 if ( fn.isEmpty() )
881 fn = directory.path(); 899 fn = directory.path();
882 900
883 QFileInfo fi( fn ); 901 QFileInfo fi( fn );
884 if ( !fi.exists() ) return FALSE; 902 if ( !fi.exists() ) return FALSE;
885 903
886 // return file listing 904 // return file listing
887 if ( fi.isFile() ) { 905 if ( fi.isFile() ) {
888 ts << fileListing( &fi ) << endl; 906 ts << fileListing( &fi ) << endl;
889 } 907 }
890 908
891 // return directory listing 909 // return directory listing
892 else if ( fi.isDir() ) { 910 else if ( fi.isDir() ) {
893 QDir dir( fn ); 911 QDir dir( fn );
894 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); 912 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden );
895 913
896 QFileInfoListIterator it( *list ); 914 QFileInfoListIterator it( *list );
897 QFileInfo *info; 915 QFileInfo *info;
898 916
899 unsigned long total = 0; 917 unsigned long total = 0;
900 while ( ( info = it.current() ) ) { 918 while ( ( info = it.current() ) ) {
901 if ( info->fileName() != "." && info->fileName() != ".." ) 919 if ( info->fileName() != "." && info->fileName() != ".." )
902 total += info->size(); 920 total += info->size();
903 ++it; 921 ++it;
904 } 922 }
905 923
906 ts << "total " << QString::number( total / 1024 ) << endl; // No tr 924 ts << "total " << QString::number( total / 1024 ) << endl; // No tr
907 925
908 it.toFirst(); 926 it.toFirst();
909 while ( ( info = it.current() ) ) { 927 while ( ( info = it.current() ) ) {
910 if ( info->fileName() == "." || info->fileName() == ".." ) { 928 if ( info->fileName() == "." || info->fileName() == ".." ) {
911 ++it; 929 ++it;
912 continue; 930 continue;
913 } 931 }
914 ts << fileListing( info ) << endl; 932 ts << fileListing( info ) << endl;
915 ++it; 933 ++it;
916 } 934 }
917 } 935 }
918 936
919 if ( passiv ) { 937 if ( passiv ) {
920 waitarray = buffer.buffer(); 938 waitarray = buffer.buffer();
921 wait[SendByteArray] = TRUE; 939 wait[SendByteArray] = TRUE;
922 if ( waitsocket ) 940 if ( waitsocket )
923 newConnection( waitsocket ); 941 newConnection( waitsocket );
924 } 942 }
925 else 943 else
926 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); 944 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport );
927 return TRUE; 945 return TRUE;
928} 946}
929 947
930QString ServerPI::fileListing( QFileInfo *info ) 948QString ServerPI::fileListing( QFileInfo *info )
931{ 949{
932 if ( !info ) return QString::null; 950 if ( !info ) return QString::null;
933 QString s; 951 QString s;
934 952
935 // type char 953 // type char
936 if ( info->isDir() ) 954 if ( info->isDir() )
937 s += "d"; 955 s += "d";
938 else if ( info->isSymLink() ) 956 else if ( info->isSymLink() )
939 s += "l"; 957 s += "l";
940 else 958 else
941 s += "-"; 959 s += "-";
942 960
943 // permisson string 961 // permisson string
944 s += permissionString( info ) + " "; 962 s += permissionString( info ) + " ";
945 963
946 // number of hardlinks 964 // number of hardlinks
947 int subdirs = 1; 965 int subdirs = 1;
948 966
949 if ( info->isDir() ) 967 if ( info->isDir() )
950 subdirs = 2; 968 subdirs = 2;
951 // FIXME : this is to slow 969 // FIXME : this is to slow
952 //if ( info->isDir() ) 970 //if ( info->isDir() )
953 //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); 971 //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count();
954 972
955 s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; 973 s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " ";
956 974
957 // owner 975 // owner
958 QString o = info->owner(); 976 QString o = info->owner();
959 if ( o.isEmpty() ) 977 if ( o.isEmpty() )
960 o = QString::number(info->ownerId()); 978 o = QString::number(info->ownerId());
961 s += o.leftJustify( 8, ' ', TRUE ) + " "; 979 s += o.leftJustify( 8, ' ', TRUE ) + " ";
962 980
963 // group 981 // group
964 QString g = info->group(); 982 QString g = info->group();
965 if ( g.isEmpty() ) 983 if ( g.isEmpty() )
966 g = QString::number(info->groupId()); 984 g = QString::number(info->groupId());
967 s += g.leftJustify( 8, ' ', TRUE ) + " "; 985 s += g.leftJustify( 8, ' ', TRUE ) + " ";
968 986
969 // file size in bytes 987 // file size in bytes
970 s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; 988 s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " ";
971 989
972 // last modified date 990 // last modified date
973 QDate date = info->lastModified().date(); 991 QDate date = info->lastModified().date();
974 QTime time = info->lastModified().time(); 992 QTime time = info->lastModified().time();
975 s += date.monthName( date.month() ) + " " 993 s += date.monthName( date.month() ) + " "
976 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " 994 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " "
977 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" 995 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":"
978 + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; 996 + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " ";
979 997
980 // file name 998 // file name
981 s += info->fileName(); 999 s += info->fileName();
982 1000
983 return s; 1001 return s;
984} 1002}
985 1003
986QString ServerPI::permissionString( QFileInfo *info ) 1004QString ServerPI::permissionString( QFileInfo *info )
987{ 1005{
988 if ( !info ) return QString( "---------" ); 1006 if ( !info ) return QString( "---------" );
989 QString s; 1007 QString s;
990 1008
991 // user 1009 // user
992 if ( info->permission( QFileInfo::ReadUser ) ) s += "r"; 1010 if ( info->permission( QFileInfo::ReadUser ) ) s += "r";
993 else s += "-"; 1011 else s += "-";
994 if ( info->permission( QFileInfo::WriteUser ) ) s += "w"; 1012 if ( info->permission( QFileInfo::WriteUser ) ) s += "w";
995 else s += "-"; 1013 else s += "-";
996 if ( info->permission( QFileInfo::ExeUser ) ) s += "x"; 1014 if ( info->permission( QFileInfo::ExeUser ) ) s += "x";
997 else s += "-"; 1015 else s += "-";
998 1016
999 // group 1017 // group
1000 if ( info->permission( QFileInfo::ReadGroup ) ) s += "r"; 1018 if ( info->permission( QFileInfo::ReadGroup ) ) s += "r";
1001 else s += "-"; 1019 else s += "-";
1002 if ( info->permission( QFileInfo::WriteGroup ) )s += "w"; 1020 if ( info->permission( QFileInfo::WriteGroup ) )s += "w";
1003 else s += "-"; 1021 else s += "-";
1004 if ( info->permission( QFileInfo::ExeGroup ) ) s += "x"; 1022 if ( info->permission( QFileInfo::ExeGroup ) ) s += "x";
1005 else s += "-"; 1023 else s += "-";
1006 1024
1007 // exec 1025 // exec
1008 if ( info->permission( QFileInfo::ReadOther ) ) s += "r"; 1026 if ( info->permission( QFileInfo::ReadOther ) ) s += "r";
1009 else s += "-"; 1027 else s += "-";
1010 if ( info->permission( QFileInfo::WriteOther ) ) s += "w"; 1028 if ( info->permission( QFileInfo::WriteOther ) ) s += "w";
1011 else s += "-"; 1029 else s += "-";
1012 if ( info->permission( QFileInfo::ExeOther ) ) s += "x"; 1030 if ( info->permission( QFileInfo::ExeOther ) ) s += "x";
1013 else s += "-"; 1031 else s += "-";
1014 1032
1015 return s; 1033 return s;
1016} 1034}
1017 1035
1018void ServerPI::newConnection( int socket ) 1036void ServerPI::newConnection( int socket )
1019{ 1037{
1020 //qDebug( "New incomming connection" ); 1038 //qDebug( "New incomming connection" );
1021 1039
1022 if ( !passiv ) return; 1040 if ( !passiv ) return;
1023 1041
1024 if ( wait[SendFile] ) { 1042 if ( wait[SendFile] ) {
1025 QStringList targets; 1043 QStringList targets;
1026 if ( backupRestoreGzip( waitfile, targets ) ) 1044 if ( backupRestoreGzip( waitfile, targets ) )
1027 dtp->sendGzipFile( waitfile, targets ); 1045 dtp->sendGzipFile( waitfile, targets );
1028 else 1046 else
1029 dtp->sendFile( waitfile ); 1047 dtp->sendFile( waitfile );
1030 dtp->setSocket( socket ); 1048 dtp->setSocket( socket );
1031 } 1049 }
1032 else if ( wait[RetrieveFile] ) { 1050 else if ( wait[RetrieveFile] ) {
1033 qDebug("check retrieve file"); 1051 qDebug("check retrieve file");
1034 if ( backupRestoreGzip( waitfile ) ) 1052 if ( backupRestoreGzip( waitfile ) )
1035 dtp->retrieveGzipFile( waitfile ); 1053 dtp->retrieveGzipFile( waitfile );
1036 else 1054 else
1037 dtp->retrieveFile( waitfile, storFileSize ); 1055 dtp->retrieveFile( waitfile, storFileSize );
1038 dtp->setSocket( socket ); 1056 dtp->setSocket( socket );
1039 } 1057 }
1040 else if ( wait[SendByteArray] ) { 1058 else if ( wait[SendByteArray] ) {
1041 dtp->sendByteArray( waitarray ); 1059 dtp->sendByteArray( waitarray );
1042 dtp->setSocket( socket ); 1060 dtp->setSocket( socket );
1043 } 1061 }
1044 else if ( wait[RetrieveByteArray] ) { 1062 else if ( wait[RetrieveByteArray] ) {
1045 qDebug("retrieve byte array"); 1063 qDebug("retrieve byte array");
1046 dtp->retrieveByteArray(); 1064 dtp->retrieveByteArray();
1047 dtp->setSocket( socket ); 1065 dtp->setSocket( socket );
1048 } 1066 }
1049 else 1067 else
1050 waitsocket = socket; 1068 waitsocket = socket;
1051 1069
1052 for( int i = 0; i < 4; i++ ) 1070 for( int i = 0; i < 4; i++ )
1053 wait[i] = FALSE; 1071 wait[i] = FALSE;
1054} 1072}
1055 1073
1056QString ServerPI::absFilePath( const QString& file ) 1074QString ServerPI::absFilePath( const QString& file )
1057{ 1075{
1058 if ( file.isEmpty() ) return file; 1076 if ( file.isEmpty() ) return file;
1059 1077
1060 QString filepath( file ); 1078 QString filepath( file );
1061 if ( file[0] != "/" ) 1079 if ( file[0] != "/" )
1062 filepath = directory.path() + "/" + file; 1080 filepath = directory.path() + "/" + file;
1063 1081
1064 return filepath; 1082 return filepath;
1065} 1083}
1066 1084
1067 1085
1068void ServerPI::timerEvent( QTimerEvent * ) 1086void ServerPI::timerEvent( QTimerEvent * )
1069{ 1087{
1070 connectionClosed(); 1088 connectionClosed();
1071} 1089}
1072 1090
1073 1091
1074ServerDTP::ServerDTP( QObject *parent, const char* name) 1092ServerDTP::ServerDTP( QObject *parent, const char* name)
1075 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), 1093 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ),
1076 retrieveTargzProc( 0 ) 1094 retrieveTargzProc( 0 )
1077{ 1095{
1078 1096
1079 connect( this, SIGNAL( connected() ), SLOT( connected() ) ); 1097 connect( this, SIGNAL( connected() ), SLOT( connected() ) );
1080 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 1098 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
1081 connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); 1099 connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) );
1082 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); 1100 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) );
1083 1101
1084 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); // No tr 1102 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); // No tr
1085 createTargzProc->setCommunication( QProcess::Stdout ); 1103 createTargzProc->setCommunication( QProcess::Stdout );
1086 createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1104 createTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1087 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); 1105 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) );
1088 1106
1089 retrieveTargzProc = new QProcess( this, "retrieveTargzProc" ); 1107 retrieveTargzProc = new QProcess( this, "retrieveTargzProc" );
1090 retrieveTargzProc->setCommunication( QProcess::Stdin ); 1108 retrieveTargzProc->setCommunication( QProcess::Stdin );
1091 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1109 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1092 connect( retrieveTargzProc, SIGNAL( processExited() ), 1110 connect( retrieveTargzProc, SIGNAL( processExited() ),
1093 SIGNAL( completed() ) ); 1111 SIGNAL( completed() ) );
1094 connect( retrieveTargzProc, SIGNAL( processExited() ), 1112 connect( retrieveTargzProc, SIGNAL( processExited() ),
1095 SLOT( extractTarDone() ) ); 1113 SLOT( extractTarDone() ) );
1096} 1114}
1097 1115
1098ServerDTP::~ServerDTP() 1116ServerDTP::~ServerDTP()
1099{ 1117{
1100 buf.close(); 1118 buf.close();
1101 if ( RetrieveFile == mode && file.isOpen() ) { 1119 if ( RetrieveFile == mode && file.isOpen() ) {
1102 // We're being shutdown before the client closed. 1120 // We're being shutdown before the client closed.
1103 file.close(); 1121 file.close();
1104 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { 1122 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) {
1105 qDebug( "STOR incomplete" ); 1123 qDebug( "STOR incomplete" );
1106 file.remove(); 1124 file.remove();
1107 } 1125 }
1108 } else { 1126 } else {
1109 file.close(); 1127 file.close();
1110 } 1128 }
1111 createTargzProc->kill(); 1129 createTargzProc->kill();
1112} 1130}
1113 1131
1114void ServerDTP::extractTarDone() 1132void ServerDTP::extractTarDone()
1115{ 1133{
1116 qDebug("extract done"); 1134 qDebug("extract done");
1117#ifndef QT_NO_COP 1135#ifndef QT_NO_COP
1118 QCopEnvelope e( "QPE/System", "restoreDone(QString)" ); 1136 QCopEnvelope e( "QPE/System", "restoreDone(QString)" );
1119 e << file.name(); 1137 e << file.name();
1120#endif 1138#endif
1121} 1139}
1122 1140
1123void ServerDTP::connected() 1141void ServerDTP::connected()
1124{ 1142{
1125 // send file mode 1143 // send file mode
1126 switch ( mode ) { 1144 switch ( mode ) {
1127 case SendFile : 1145 case SendFile :
1128 if ( !file.exists() || !file.open( IO_ReadOnly) ) { 1146 if ( !file.exists() || !file.open( IO_ReadOnly) ) {
1129 emit failed(); 1147 emit failed();
1130 mode = Idle; 1148 mode = Idle;
1131 return; 1149 return;
1132 } 1150 }
1133 1151
1134 //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); 1152 //qDebug( "Debug: Sending file '%s'", file.name().latin1() );
1135 1153
1136 bytes_written = 0; 1154 bytes_written = 0;
1137 if ( file.size() == 0 ) { 1155 if ( file.size() == 0 ) {
1138 //make sure it doesn't hang on empty files 1156 //make sure it doesn't hang on empty files
1139 file.close(); 1157 file.close();
1140 emit completed(); 1158 emit completed();
1141 mode = Idle; 1159 mode = Idle;
1142 } else { 1160 } else {
1143 // Don't write more if there is plenty buffered already. 1161 // Don't write more if there is plenty buffered already.
1144 if ( bytesToWrite() <= block_size && !file.atEnd() ) { 1162 if ( bytesToWrite() <= block_size && !file.atEnd() ) {
1145 QCString s; 1163 QCString s;
1146 s.resize( block_size ); 1164 s.resize( block_size );
1147 int bytes = file.readBlock( s.data(), block_size ); 1165 int bytes = file.readBlock( s.data(), block_size );
1148 writeBlock( s.data(), bytes ); 1166 writeBlock( s.data(), bytes );
1149 } 1167 }
1150 } 1168 }
1151 break; 1169 break;
1152 case SendGzipFile: 1170 case SendGzipFile:
1153 if ( createTargzProc->isRunning() ) { 1171 if ( createTargzProc->isRunning() ) {
1154 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY 1172 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY
1155 qWarning("Previous tar --gzip process is still running; killing it..."); 1173 qWarning("Previous tar --gzip process is still running; killing it...");
1156 createTargzProc->kill(); 1174 createTargzProc->kill();
1157 } 1175 }
1158 1176
1159 bytes_written = 0; 1177 bytes_written = 0;
1160 qDebug("==>start send tar process"); 1178 qDebug("==>start send tar process");
1161 if ( !createTargzProc->start() ) 1179 if ( !createTargzProc->start() )
1162 qWarning("Error starting %s", 1180 qWarning("Error starting %s",
1163 createTargzProc->arguments().join(" ").latin1()); 1181 createTargzProc->arguments().join(" ").latin1());
1164 break; 1182 break;
1165 case SendBuffer: 1183 case SendBuffer:
1166 if ( !buf.open( IO_ReadOnly) ) { 1184 if ( !buf.open( IO_ReadOnly) ) {
1167 emit failed(); 1185 emit failed();
1168 mode = Idle; 1186 mode = Idle;
1169 return; 1187 return;
1170 } 1188 }
1171 1189
1172 // qDebug( "Debug: Sending byte array" ); 1190 // qDebug( "Debug: Sending byte array" );
1173 bytes_written = 0; 1191 bytes_written = 0;
1174 while( !buf.atEnd() ) 1192 while( !buf.atEnd() )
1175 putch( buf.getch() ); 1193 putch( buf.getch() );
1176 buf.close(); 1194 buf.close();
1177 break; 1195 break;
1178 case RetrieveFile: 1196 case RetrieveFile:
1179 // retrieve file mode 1197 // retrieve file mode
1180 if ( file.exists() && !file.remove() ) { 1198 if ( file.exists() && !file.remove() ) {
1181 emit failed(); 1199 emit failed();
1182 mode = Idle; 1200 mode = Idle;
1183 return; 1201 return;
1184 } 1202 }
1185 1203
1186 if ( !file.open( IO_WriteOnly) ) { 1204 if ( !file.open( IO_WriteOnly) ) {
1187 emit failed(); 1205 emit failed();
1188 mode = Idle; 1206 mode = Idle;
1189 return; 1207 return;
1190 } 1208 }
1191 // qDebug( "Debug: Retrieving file %s", file.name().latin1() ); 1209 // qDebug( "Debug: Retrieving file %s", file.name().latin1() );
1192 break; 1210 break;
1193 case RetrieveGzipFile: 1211 case RetrieveGzipFile:
1194 qDebug("=-> starting tar process to receive .tgz file"); 1212 qDebug("=-> starting tar process to receive .tgz file");
1195 break; 1213 break;
1196 case RetrieveBuffer: 1214 case RetrieveBuffer:
1197 // retrieve buffer mode 1215 // retrieve buffer mode
1198 if ( !buf.open( IO_WriteOnly) ) { 1216 if ( !buf.open( IO_WriteOnly) ) {
1199 emit failed(); 1217 emit failed();
1200 mode = Idle; 1218 mode = Idle;
1201 return; 1219 return;
1202 } 1220 }
1203 // qDebug( "Debug: Retrieving byte array" ); 1221 // qDebug( "Debug: Retrieving byte array" );
1204 break; 1222 break;
1205 case Idle: 1223 case Idle:
1206 qDebug("connection established but mode set to Idle; BUG!"); 1224 qDebug("connection established but mode set to Idle; BUG!");
1207 break; 1225 break;
1208 } 1226 }
1209} 1227}
1210 1228
1211void ServerDTP::connectionClosed() 1229void ServerDTP::connectionClosed()
1212{ 1230{
1213 //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written ); 1231 //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written );
1214 1232
1215 // send file mode 1233 // send file mode
1216 if ( SendFile == mode ) { 1234 if ( SendFile == mode ) {
1217 if ( bytes_written == file.size() ) 1235 if ( bytes_written == file.size() )
1218 emit completed(); 1236 emit completed();
1219 else 1237 else
1220 emit failed(); 1238 emit failed();
1221 } 1239 }
1222 1240
1223 // send buffer mode 1241 // send buffer mode
1224 else if ( SendBuffer == mode ) { 1242 else if ( SendBuffer == mode ) {
1225 if ( bytes_written == buf.size() ) 1243 if ( bytes_written == buf.size() )
1226 emit completed(); 1244 emit completed();
1227 else 1245 else
1228 emit failed(); 1246 emit failed();
1229 } 1247 }
1230 1248
1231 // retrieve file mode 1249 // retrieve file mode
1232 else if ( RetrieveFile == mode ) { 1250 else if ( RetrieveFile == mode ) {
1233 file.close(); 1251 file.close();
1234 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { 1252 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) {
1235 qDebug( "STOR incomplete" ); 1253 qDebug( "STOR incomplete" );
1236 file.remove(); 1254 file.remove();
1237 emit failed(); 1255 emit failed();
1238 } else { 1256 } else {
1239 emit completed(); 1257 emit completed();
1240 } 1258 }
1241 } 1259 }
1242 1260
1243 else if ( RetrieveGzipFile == mode ) { 1261 else if ( RetrieveGzipFile == mode ) {
1244 qDebug("Done writing ungzip file; closing input"); 1262 qDebug("Done writing ungzip file; closing input");
1245 retrieveTargzProc->flushStdin(); 1263 retrieveTargzProc->flushStdin();
1246 retrieveTargzProc->closeStdin(); 1264 retrieveTargzProc->closeStdin();
1247 } 1265 }
1248 1266
1249 // retrieve buffer mode 1267 // retrieve buffer mode
1250 else if ( RetrieveBuffer == mode ) { 1268 else if ( RetrieveBuffer == mode ) {
1251 buf.close(); 1269 buf.close();
1252 emit completed(); 1270 emit completed();
1253 } 1271 }
1254 1272
1255 mode = Idle; 1273 mode = Idle;
1256} 1274}
1257 1275
1258void ServerDTP::bytesWritten( int bytes ) 1276void ServerDTP::bytesWritten( int bytes )
1259{ 1277{
1260 bytes_written += bytes; 1278 bytes_written += bytes;
1261 1279
1262 // send file mode 1280 // send file mode
1263 if ( SendFile == mode ) { 1281 if ( SendFile == mode ) {
1264 1282
1265 if ( bytes_written == file.size() ) { 1283 if ( bytes_written == file.size() ) {
1266 // qDebug( "Debug: Sending complete: %d bytes", file.size() ); 1284 // qDebug( "Debug: Sending complete: %d bytes", file.size() );
1267 file.close(); 1285 file.close();
1268 emit completed(); 1286 emit completed();
1269 mode = Idle; 1287 mode = Idle;
1270 } 1288 }
1271 else if( !file.atEnd() ) { 1289 else if( !file.atEnd() ) {
1272 QCString s; 1290 QCString s;
1273 s.resize( block_size ); 1291 s.resize( block_size );
1274 int bytes = file.readBlock( s.data(), block_size ); 1292 int bytes = file.readBlock( s.data(), block_size );
1275 writeBlock( s.data(), bytes ); 1293 writeBlock( s.data(), bytes );
1276 } 1294 }
1277 } 1295 }
1278 1296
1279 // send buffer mode 1297 // send buffer mode
1280 if ( SendBuffer == mode ) { 1298 if ( SendBuffer == mode ) {
1281 1299
1282 if ( bytes_written == buf.size() ) { 1300 if ( bytes_written == buf.size() ) {
1283 // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); 1301 // qDebug( "Debug: Sending complete: %d bytes", buf.size() );
1284 emit completed(); 1302 emit completed();
1285 mode = Idle; 1303 mode = Idle;
1286 } 1304 }
1287 } 1305 }
1288} 1306}
1289 1307
1290void ServerDTP::readyRead() 1308void ServerDTP::readyRead()
1291{ 1309{
1292 // retrieve file mode 1310 // retrieve file mode
1293 if ( RetrieveFile == mode ) { 1311 if ( RetrieveFile == mode ) {
1294 QCString s; 1312 QCString s;
1295 s.resize( bytesAvailable() ); 1313 s.resize( bytesAvailable() );
1296 readBlock( s.data(), bytesAvailable() ); 1314 readBlock( s.data(), bytesAvailable() );
1297 file.writeBlock( s.data(), s.size() ); 1315 file.writeBlock( s.data(), s.size() );
1298 } 1316 }
1299 else if ( RetrieveGzipFile == mode ) { 1317 else if ( RetrieveGzipFile == mode ) {
1300 if ( !retrieveTargzProc->isRunning() ) 1318 if ( !retrieveTargzProc->isRunning() )
1301 retrieveTargzProc->start(); 1319 retrieveTargzProc->start();
1302 1320
1303 QByteArray s; 1321 QByteArray s;
1304 s.resize( bytesAvailable() ); 1322 s.resize( bytesAvailable() );
1305 readBlock( s.data(), bytesAvailable() ); 1323 readBlock( s.data(), bytesAvailable() );
1306 retrieveTargzProc->writeToStdin( s ); 1324 retrieveTargzProc->writeToStdin( s );
1307 qDebug("wrote %d bytes to ungzip ", s.size() ); 1325 qDebug("wrote %d bytes to ungzip ", s.size() );
1308 } 1326 }
1309 // retrieve buffer mode 1327 // retrieve buffer mode
1310 else if ( RetrieveBuffer == mode ) { 1328 else if ( RetrieveBuffer == mode ) {
1311 QCString s; 1329 QCString s;
1312 s.resize( bytesAvailable() ); 1330 s.resize( bytesAvailable() );
1313 readBlock( s.data(), bytesAvailable() ); 1331 readBlock( s.data(), bytesAvailable() );
1314 buf.writeBlock( s.data(), s.size() ); 1332 buf.writeBlock( s.data(), s.size() );
1315 } 1333 }
1316} 1334}
1317 1335
1318void ServerDTP::writeTargzBlock() 1336void ServerDTP::writeTargzBlock()
1319{ 1337{
1320 QByteArray block = createTargzProc->readStdout(); 1338 QByteArray block = createTargzProc->readStdout();
1321 writeBlock( block.data(), block.size() ); 1339 writeBlock( block.data(), block.size() );
1322 qDebug("writeTargzBlock %d", block.size()); 1340 qDebug("writeTargzBlock %d", block.size());
1323} 1341}
1324 1342
1325void ServerDTP::targzDone() 1343void ServerDTP::targzDone()
1326{ 1344{
1327 qDebug("tar and gzip done"); 1345 qDebug("tar and gzip done");
1328 emit completed(); 1346 emit completed();
1329 mode = Idle; 1347 mode = Idle;
1330 disconnect( createTargzProc, SIGNAL( readyReadStdout() ), 1348 disconnect( createTargzProc, SIGNAL( readyReadStdout() ),
1331 this, SLOT( writeTargzBlock() ) ); 1349 this, SLOT( writeTargzBlock() ) );
1332} 1350}
1333 1351
1334void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) 1352void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port )
1335{ 1353{
1336 file.setName( fn ); 1354 file.setName( fn );
1337 mode = SendFile; 1355 mode = SendFile;
1338 connectToHost( host.toString(), port ); 1356 connectToHost( host.toString(), port );
1339} 1357}
1340 1358
1341void ServerDTP::sendFile( const QString fn ) 1359void ServerDTP::sendFile( const QString fn )
1342{ 1360{
1343 file.setName( fn ); 1361 file.setName( fn );
1344 mode = SendFile; 1362 mode = SendFile;
1345} 1363}
1346 1364
1347void ServerDTP::sendGzipFile( const QString &fn, 1365void ServerDTP::sendGzipFile( const QString &fn,
1348 const QStringList &archiveTargets, 1366 const QStringList &archiveTargets,
1349 const QHostAddress& host, Q_UINT16 port ) 1367 const QHostAddress& host, Q_UINT16 port )
1350{ 1368{
1351 sendGzipFile( fn, archiveTargets ); 1369 sendGzipFile( fn, archiveTargets );
1352 connectToHost( host.toString(), port ); 1370 connectToHost( host.toString(), port );
1353} 1371}
1354 1372
1355void ServerDTP::sendGzipFile( const QString &fn, 1373void ServerDTP::sendGzipFile( const QString &fn,
1356 const QStringList &archiveTargets ) 1374 const QStringList &archiveTargets )
1357{ 1375{
1358 mode = SendGzipFile; 1376 mode = SendGzipFile;
1359 file.setName( fn ); 1377 file.setName( fn );
1360 1378
1361 QStringList args = "targzip"; 1379 QStringList args = "targzip";
1362 //args += "-cv"; 1380 //args += "-cv";
1363 args += archiveTargets; 1381 args += archiveTargets;
1364 qDebug("sendGzipFile %s", args.join(" ").latin1() ); 1382 qDebug("sendGzipFile %s", args.join(" ").latin1() );
1365 createTargzProc->setArguments( args ); 1383 createTargzProc->setArguments( args );
1366 connect( createTargzProc, 1384 connect( createTargzProc,
1367 SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); 1385 SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) );
1368} 1386}
1369 1387
1370void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize ) 1388void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize )
1371{ 1389{
1372 recvFileSize = fileSize; 1390 recvFileSize = fileSize;
1373 file.setName( fn ); 1391 file.setName( fn );
1374 mode = RetrieveFile; 1392 mode = RetrieveFile;
1375 connectToHost( host.toString(), port ); 1393 connectToHost( host.toString(), port );
1376} 1394}
1377 1395
1378void ServerDTP::retrieveFile( const QString fn, int fileSize ) 1396void ServerDTP::retrieveFile( const QString fn, int fileSize )
1379{ 1397{
1380 recvFileSize = fileSize; 1398 recvFileSize = fileSize;
1381 file.setName( fn ); 1399 file.setName( fn );
1382 mode = RetrieveFile; 1400 mode = RetrieveFile;
1383} 1401}
1384 1402
1385void ServerDTP::retrieveGzipFile( const QString &fn ) 1403void ServerDTP::retrieveGzipFile( const QString &fn )
1386{ 1404{
1387 qDebug("retrieveGzipFile %s", fn.latin1()); 1405 qDebug("retrieveGzipFile %s", fn.latin1());
1388 file.setName( fn ); 1406 file.setName( fn );
1389 mode = RetrieveGzipFile; 1407 mode = RetrieveGzipFile;
1390 1408
1391 retrieveTargzProc->setArguments( "targunzip" ); 1409 retrieveTargzProc->setArguments( "targunzip" );
1392 connect( retrieveTargzProc, SIGNAL( processExited() ), 1410 connect( retrieveTargzProc, SIGNAL( processExited() ),
1393 SLOT( extractTarDone() ) ); 1411 SLOT( extractTarDone() ) );
1394} 1412}
1395 1413
1396void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) 1414void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port )
1397{ 1415{
1398 retrieveGzipFile( fn ); 1416 retrieveGzipFile( fn );
1399 connectToHost( host.toString(), port ); 1417 connectToHost( host.toString(), port );
1400} 1418}
1401 1419
1402void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ) 1420void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port )
1403{ 1421{
1404 buf.setBuffer( array ); 1422 buf.setBuffer( array );
1405 mode = SendBuffer; 1423 mode = SendBuffer;
1406 connectToHost( host.toString(), port ); 1424 connectToHost( host.toString(), port );
1407} 1425}
1408 1426
1409void ServerDTP::sendByteArray( const QByteArray& array ) 1427void ServerDTP::sendByteArray( const QByteArray& array )
1410{ 1428{
1411 buf.setBuffer( array ); 1429 buf.setBuffer( array );
1412 mode = SendBuffer; 1430 mode = SendBuffer;
1413} 1431}
1414 1432
1415void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port ) 1433void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port )
1416{ 1434{
1417 buf.setBuffer( QByteArray() ); 1435 buf.setBuffer( QByteArray() );
1418 mode = RetrieveBuffer; 1436 mode = RetrieveBuffer;
1419 connectToHost( host.toString(), port ); 1437 connectToHost( host.toString(), port );
1420} 1438}
1421 1439
1422void ServerDTP::retrieveByteArray() 1440void ServerDTP::retrieveByteArray()
1423{ 1441{
1424 buf.setBuffer( QByteArray() ); 1442 buf.setBuffer( QByteArray() );
1425 mode = RetrieveBuffer; 1443 mode = RetrieveBuffer;
1426} 1444}
1427 1445
1428void ServerDTP::setSocket( int socket ) 1446void ServerDTP::setSocket( int socket )
1429{ 1447{
1430 QSocket::setSocket( socket ); 1448 QSocket::setSocket( socket );
1431 connected(); 1449 connected();
1432} 1450}
1433 1451