summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/desktop.cpp4
-rw-r--r--core/launcher/qcopbridge.cpp10
-rw-r--r--core/launcher/transferserver.cpp10
3 files changed, 14 insertions, 10 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp
index 43006f1..d5c16b3 100644
--- a/core/launcher/desktop.cpp
+++ b/core/launcher/desktop.cpp
@@ -91,98 +91,98 @@ bool Desktop::screenLocked()
91 91
92/* 92/*
93 Priority is number of alerts that are needed to pop up 93 Priority is number of alerts that are needed to pop up
94 alert. 94 alert.
95 */ 95 */
96class DesktopPowerAlerter : public QMessageBox 96class DesktopPowerAlerter : public QMessageBox
97{ 97{
98public: 98public:
99 DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) 99 DesktopPowerAlerter( QWidget *parent, const char *name = 0 )
100 : QMessageBox( tr("Battery Status"), "Low Battery", 100 : QMessageBox( tr("Battery Status"), "Low Battery",
101 QMessageBox::Critical, 101 QMessageBox::Critical,
102 QMessageBox::Ok | QMessageBox::Default, 102 QMessageBox::Ok | QMessageBox::Default,
103 QMessageBox::NoButton, QMessageBox::NoButton, 103 QMessageBox::NoButton, QMessageBox::NoButton,
104 parent, name, FALSE ) 104 parent, name, FALSE )
105 { 105 {
106 currentPriority = INT_MAX; 106 currentPriority = INT_MAX;
107 alertCount = 0; 107 alertCount = 0;
108 } 108 }
109 109
110 void alert( const QString &text, int priority ); 110 void alert( const QString &text, int priority );
111 void hideEvent( QHideEvent * ); 111 void hideEvent( QHideEvent * );
112private: 112private:
113 int currentPriority; 113 int currentPriority;
114 int alertCount; 114 int alertCount;
115}; 115};
116 116
117void DesktopPowerAlerter::alert( const QString &text, int priority ) 117void DesktopPowerAlerter::alert( const QString &text, int priority )
118{ 118{
119 alertCount++; 119 alertCount++;
120 if ( alertCount < priority ) 120 if ( alertCount < priority )
121 return; 121 return;
122 if ( priority > currentPriority ) 122 if ( priority > currentPriority )
123 return; 123 return;
124 currentPriority = priority; 124 currentPriority = priority;
125 setText( text ); 125 setText( text );
126 show(); 126 show();
127} 127}
128 128
129 129
130void DesktopPowerAlerter::hideEvent( QHideEvent *e ) 130void DesktopPowerAlerter::hideEvent( QHideEvent *e )
131{ 131{
132 QMessageBox::hideEvent( e ); 132 QMessageBox::hideEvent( e );
133 alertCount = 0; 133 alertCount = 0;
134 currentPriority = INT_MAX; 134 currentPriority = INT_MAX;
135} 135}
136 136
137 137
138 138
139DesktopApplication::DesktopApplication( int& argc, char **argv, Type t ) 139DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType )
140 : QPEApplication( argc, argv, t ) 140 : QPEApplication( argc, argv, appType )
141{ 141{
142 142
143 QTimer *t = new QTimer( this ); 143 QTimer *t = new QTimer( this );
144 connect( t, SIGNAL(timeout()), this, SLOT(psTimeout()) ); 144 connect( t, SIGNAL(timeout()), this, SLOT(psTimeout()) );
145 t->start( 10000 ); 145 t->start( 10000 );
146 ps = new PowerStatus; 146 ps = new PowerStatus;
147 pa = new DesktopPowerAlerter( 0 ); 147 pa = new DesktopPowerAlerter( 0 );
148 148
149 channel = new QCopChannel( "QPE/Desktop", this ); 149 channel = new QCopChannel( "QPE/Desktop", this );
150 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 150 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
151 this, SLOT(receive(const QCString&, const QByteArray&)) ); 151 this, SLOT(receive(const QCString&, const QByteArray&)) );
152} 152}
153 153
154 154
155DesktopApplication::~DesktopApplication() 155DesktopApplication::~DesktopApplication()
156{ 156{
157 delete ps; 157 delete ps;
158 delete pa; 158 delete pa;
159} 159}
160 160
161void DesktopApplication::receive( const QCString &msg, const QByteArray &data ) 161void DesktopApplication::receive( const QCString &msg, const QByteArray &data )
162{ 162{
163 QDataStream stream( data, IO_ReadOnly ); 163 QDataStream stream( data, IO_ReadOnly );
164 if (msg == "keyRegister(int key, QString channel, QString message)") 164 if (msg == "keyRegister(int key, QString channel, QString message)")
165 { 165 {
166 int k; 166 int k;
167 QString c, m; 167 QString c, m;
168 168
169 stream >> k; 169 stream >> k;
170 stream >> c; 170 stream >> c;
171 stream >> m; 171 stream >> m;
172 172
173 qWarning("KeyRegisterRecieved: %i, %s, %s", k, (const char*)c, (const char *)m); 173 qWarning("KeyRegisterRecieved: %i, %s, %s", k, (const char*)c, (const char *)m);
174 keyRegisterList.append(QCopKeyRegister(k,c,m)); 174 keyRegisterList.append(QCopKeyRegister(k,c,m));
175 } 175 }
176 else if (msg == "suspend()"){ 176 else if (msg == "suspend()"){
177 emit power(); 177 emit power();
178 } 178 }
179 179
180} 180}
181 181
182enum MemState { Unknown, VeryLow, Low, Normal } memstate=Unknown; 182enum MemState { Unknown, VeryLow, Low, Normal } memstate=Unknown;
183 183
184#ifdef Q_WS_QWS 184#ifdef Q_WS_QWS
185bool DesktopApplication::qwsEventFilter( QWSEvent *e ) 185bool DesktopApplication::qwsEventFilter( QWSEvent *e )
186{ 186{
187 qpedesktop->checkMemory(); 187 qpedesktop->checkMemory();
188 188
diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp
index c8af919..2d084fc 100644
--- a/core/launcher/qcopbridge.cpp
+++ b/core/launcher/qcopbridge.cpp
@@ -1,98 +1,102 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "qcopbridge.h" 21#include "qcopbridge.h"
22#include "transferserver.h" 22#include "transferserver.h"
23 23
24#include <qpe/qcopenvelope_qws.h> 24#include <qpe/qcopenvelope_qws.h>
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26 26
27#include <qdir.h> 27#include <qdir.h>
28#include <qfile.h> 28#include <qfile.h>
29#include <qtextstream.h> 29#include <qtextstream.h>
30#include <qdatastream.h> 30#include <qdatastream.h>
31#include <qstringlist.h> 31#include <qstringlist.h>
32#include <qfileinfo.h> 32#include <qfileinfo.h>
33#include <qregexp.h> 33#include <qregexp.h>
34#include <qcopchannel_qws.h> 34#include <qcopchannel_qws.h>
35 35
36// actually this is wrong, _XOPEN_SOURCE should get defined on the commandline
37// and it should have a proper value assigned. (Simon)
38#if !defined(_XOPEN_SOURCE)
36#define _XOPEN_SOURCE 39#define _XOPEN_SOURCE
40#endif
37#include <pwd.h> 41#include <pwd.h>
38#include <sys/types.h> 42#include <sys/types.h>
39#include <unistd.h> 43#include <unistd.h>
40 44
41#if defined(_OS_LINUX_) 45#if defined(_OS_LINUX_)
42#include <shadow.h> 46#include <shadow.h>
43#endif 47#endif
44 48
45//#define INSECURE 49//#define INSECURE
46 50
47const int block_size = 51200; 51const int block_size = 51200;
48 52
49QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent = 0, 53QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent,
50 const char* name = 0) 54 const char* name )
51 : QServerSocket( port, 1, parent, name ), 55 : QServerSocket( port, 1, parent, name ),
52 desktopChannel( 0 ), 56 desktopChannel( 0 ),
53 cardChannel( 0 ) 57 cardChannel( 0 )
54{ 58{
55 if ( !ok() ) 59 if ( !ok() )
56 qWarning( "Failed to bind to port %d", port ); 60 qWarning( "Failed to bind to port %d", port );
57 else { 61 else {
58 desktopChannel = new QCopChannel( "QPE/Desktop", this ); 62 desktopChannel = new QCopChannel( "QPE/Desktop", this );
59 connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)), 63 connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)),
60 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 64 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
61 cardChannel = new QCopChannel( "QPE/Card", this ); 65 cardChannel = new QCopChannel( "QPE/Card", this );
62 connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), 66 connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)),
63 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 67 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
64 } 68 }
65 sendSync = FALSE; 69 sendSync = FALSE;
66} 70}
67 71
68QCopBridge::~QCopBridge() 72QCopBridge::~QCopBridge()
69{ 73{
70 delete desktopChannel; 74 delete desktopChannel;
71} 75}
72 76
73void QCopBridge::newConnection( int socket ) 77void QCopBridge::newConnection( int socket )
74{ 78{
75 QCopBridgePI *pi = new QCopBridgePI( socket, this ); 79 QCopBridgePI *pi = new QCopBridgePI( socket, this );
76 openConnections.append( pi ); 80 openConnections.append( pi );
77 connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) ); 81 connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) );
78 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; 82 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend;
79 83
80 if ( sendSync ) { 84 if ( sendSync ) {
81 pi ->startSync(); 85 pi ->startSync();
82 sendSync = FALSE; 86 sendSync = FALSE;
83 } 87 }
84} 88}
85 89
86void QCopBridge::connectionClosed( QCopBridgePI *pi ) 90void QCopBridge::connectionClosed( QCopBridgePI *pi )
87{ 91{
88 openConnections.remove( pi ); 92 openConnections.remove( pi );
89 if ( openConnections.count() == 0 ) { 93 if ( openConnections.count() == 0 ) {
90 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 94 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
91 } 95 }
92} 96}
93 97
94void QCopBridge::closeOpenConnections() 98void QCopBridge::closeOpenConnections()
95{ 99{
96 QCopBridgePI *pi; 100 QCopBridgePI *pi;
97 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) 101 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() )
98 pi->close(); 102 pi->close();
@@ -124,97 +128,97 @@ void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args
124 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { 128 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
125 QString str; 129 QString str;
126 if ( *it == "QString" ) { 130 if ( *it == "QString" ) {
127 stream >> str; 131 stream >> str;
128 } else if ( *it == "QCString" ) { 132 } else if ( *it == "QCString" ) {
129 QCString cstr; 133 QCString cstr;
130 stream >> cstr; 134 stream >> cstr;
131 str = QString::fromLocal8Bit( cstr ); 135 str = QString::fromLocal8Bit( cstr );
132 } else if ( *it == "int" ) { 136 } else if ( *it == "int" ) {
133 int i; 137 int i;
134 stream >> i; 138 stream >> i;
135 str = QString::number( i ); 139 str = QString::number( i );
136 } else if ( *it == "bool" ) { 140 } else if ( *it == "bool" ) {
137 int i; 141 int i;
138 stream >> i; 142 stream >> i;
139 str = QString::number( i ); 143 str = QString::number( i );
140 } else { 144 } else {
141 qDebug(" cannot route the argument type %s through the qcop bridge", (*it).latin1() ); 145 qDebug(" cannot route the argument type %s through the qcop bridge", (*it).latin1() );
142 return; 146 return;
143 } 147 }
144 str.replace( QRegExp("&"), "&amp;" ); 148 str.replace( QRegExp("&"), "&amp;" );
145 str.replace( QRegExp(" "), "&0x20;" ); 149 str.replace( QRegExp(" "), "&0x20;" );
146 str.replace( QRegExp("\n"), "&0x0d;" ); 150 str.replace( QRegExp("\n"), "&0x0d;" );
147 str.replace( QRegExp("\r"), "&0x0a;" ); 151 str.replace( QRegExp("\r"), "&0x0a;" );
148 data += " " + str; 152 data += " " + str;
149 } 153 }
150 } 154 }
151 QString sendCommand = QString(command.data()) + data; 155 QString sendCommand = QString(command.data()) + data;
152 // send the command to all open connections 156 // send the command to all open connections
153 if ( command == "startSync()" ) { 157 if ( command == "startSync()" ) {
154 // we need to buffer it a bit 158 // we need to buffer it a bit
155 sendSync = TRUE; 159 sendSync = TRUE;
156 startTimer( 20000 ); 160 startTimer( 20000 );
157 } 161 }
158 162
159 QCopBridgePI *pi; 163 QCopBridgePI *pi;
160 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { 164 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) {
161 pi->sendDesktopMessage( sendCommand ); 165 pi->sendDesktopMessage( sendCommand );
162 } 166 }
163} 167}
164 168
165void QCopBridge::timerEvent( QTimerEvent * ) 169void QCopBridge::timerEvent( QTimerEvent * )
166{ 170{
167 sendSync = FALSE; 171 sendSync = FALSE;
168 killTimers(); 172 killTimers();
169} 173}
170 174
171 175
172QCopBridgePI::QCopBridgePI( int socket, QObject *parent = 0, const char* name = 0 ) 176QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name )
173 : QSocket( parent, name ) 177 : QSocket( parent, name )
174{ 178{
175 setSocket( socket ); 179 setSocket( socket );
176 180
177 peerport = peerPort(); 181 peerport = peerPort();
178 peeraddress = peerAddress(); 182 peeraddress = peerAddress();
179 183
180#ifndef INSECURE 184#ifndef INSECURE
181 if ( !accessAuthorized(peeraddress) ) { 185 if ( !accessAuthorized(peeraddress) ) {
182 state = Forbidden; 186 state = Forbidden;
183 startTimer( 0 ); 187 startTimer( 0 );
184 } else 188 } else
185#endif 189#endif
186 { 190 {
187 state = Connected; 191 state = Connected;
188 sendSync = FALSE; 192 sendSync = FALSE;
189 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 193 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
190 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 194 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
191 195
192 send( "220 Qtopia QCop bridge ready!" ); 196 send( "220 Qtopia QCop bridge ready!" );
193 state = Wait_USER; 197 state = Wait_USER;
194 198
195 // idle timer to close connections when not used anymore 199 // idle timer to close connections when not used anymore
196 startTimer( 60000 ); 200 startTimer( 60000 );
197 connected = TRUE; 201 connected = TRUE;
198 } 202 }
199} 203}
200 204
201 205
202QCopBridgePI::~QCopBridgePI() 206QCopBridgePI::~QCopBridgePI()
203{ 207{
204 208
205} 209}
206 210
207void QCopBridgePI::connectionClosed() 211void QCopBridgePI::connectionClosed()
208{ 212{
209 emit connectionClosed( this ); 213 emit connectionClosed( this );
210 // qDebug( "Debug: Connection closed" ); 214 // qDebug( "Debug: Connection closed" );
211 delete this; 215 delete this;
212} 216}
213 217
214void QCopBridgePI::sendDesktopMessage( const QString &msg ) 218void QCopBridgePI::sendDesktopMessage( const QString &msg )
215{ 219{
216 QString str = "CALL QPE/Desktop " + msg; 220 QString str = "CALL QPE/Desktop " + msg;
217 send ( str ); 221 send ( str );
218} 222}
219 223
220 224
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index 87a49eb..7294f9c 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -1,132 +1,132 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#define _XOPEN_SOURCE 20#define _XOPEN_SOURCE
21#include <pwd.h> 21#include <pwd.h>
22#include <sys/types.h> 22#include <sys/types.h>
23#include <unistd.h> 23#include <unistd.h>
24#include <stdlib.h> 24#include <stdlib.h>
25 25
26#if defined(_OS_LINUX_) 26#if defined(_OS_LINUX_)
27#include <shadow.h> 27#include <shadow.h>
28#endif 28#endif
29 29
30#include <qdir.h> 30#include <qdir.h>
31#include <qfile.h> 31#include <qfile.h>
32#include <qtextstream.h> 32#include <qtextstream.h>
33#include <qdatastream.h> 33#include <qdatastream.h>
34#include <qmessagebox.h> 34#include <qmessagebox.h>
35#include <qstringlist.h> 35#include <qstringlist.h>
36#include <qfileinfo.h> 36#include <qfileinfo.h>
37#include <qregexp.h> 37#include <qregexp.h>
38//#include <qpe/qcopchannel_qws.h> 38//#include <qpe/qcopchannel_qws.h>
39#include <qpe/qprocess.h>
40#include <qpe/process.h> 39#include <qpe/process.h>
41#include <qpe/config.h> 40#include <qpe/config.h>
42#include <qpe/qcopenvelope_qws.h> 41#include <qpe/qcopenvelope_qws.h>
43 42
44#include "transferserver.h" 43#include "transferserver.h"
44#include "qprocess.h"
45 45
46const int block_size = 51200; 46const int block_size = 51200;
47 47
48TransferServer::TransferServer( Q_UINT16 port, QObject *parent = 0, 48TransferServer::TransferServer( Q_UINT16 port, QObject *parent,
49 const char* name = 0) 49 const char* name )
50 : QServerSocket( port, 1, parent, name ) 50 : QServerSocket( port, 1, parent, name )
51{ 51{
52 if ( !ok() ) 52 if ( !ok() )
53 qWarning( "Failed to bind to port %d", port ); 53 qWarning( "Failed to bind to port %d", port );
54} 54}
55 55
56TransferServer::~TransferServer() 56TransferServer::~TransferServer()
57{ 57{
58 58
59} 59}
60 60
61void TransferServer::newConnection( int socket ) 61void TransferServer::newConnection( int socket )
62{ 62{
63 (void) new ServerPI( socket, this ); 63 (void) new ServerPI( socket, this );
64} 64}
65 65
66bool accessAuthorized(QHostAddress peeraddress) 66bool accessAuthorized(QHostAddress peeraddress)
67{ 67{
68 Config cfg("Security"); 68 Config cfg("Security");
69 cfg.setGroup("Sync"); 69 cfg.setGroup("Sync");
70 uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100); 70 uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100);
71 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); 71 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24);
72 bool ok = (peeraddress.ip4Addr() & (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits))) 72 bool ok = (peeraddress.ip4Addr() & (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits)))
73 == auth_peer; 73 == auth_peer;
74 /* Allows denial-of-service attack. 74 /* Allows denial-of-service attack.
75 if ( !ok ) { 75 if ( !ok ) {
76 QMessageBox::warning(0,tr("Security"), 76 QMessageBox::warning(0,tr("Security"),
77 tr("<p>An attempt to access this device from %1 has been denied.") 77 tr("<p>An attempt to access this device from %1 has been denied.")
78 .arg(peeraddress.toString())); 78 .arg(peeraddress.toString()));
79 } 79 }
80 */ 80 */
81 return ok; 81 return ok;
82} 82}
83 83
84ServerPI::ServerPI( int socket, QObject *parent = 0, const char* name = 0 ) 84ServerPI::ServerPI( int socket, QObject *parent, const char* name )
85 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) 85 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 )
86{ 86{
87 state = Connected; 87 state = Connected;
88 88
89 setSocket( socket ); 89 setSocket( socket );
90 90
91 peerport = peerPort(); 91 peerport = peerPort();
92 peeraddress = peerAddress(); 92 peeraddress = peerAddress();
93 93
94#ifndef INSECURE 94#ifndef INSECURE
95 if ( !accessAuthorized(peeraddress) ) { 95 if ( !accessAuthorized(peeraddress) ) {
96 state = Forbidden; 96 state = Forbidden;
97 startTimer( 0 ); 97 startTimer( 0 );
98 } else 98 } else
99 #endif 99 #endif
100 { 100 {
101 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 101 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
102 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 102 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
103 103
104 passiv = FALSE; 104 passiv = FALSE;
105 for( int i = 0; i < 4; i++ ) 105 for( int i = 0; i < 4; i++ )
106 wait[i] = FALSE; 106 wait[i] = FALSE;
107 107
108 send( "220 Qtopia transfer service ready!" ); 108 send( "220 Qtopia transfer service ready!" );
109 state = Wait_USER; 109 state = Wait_USER;
110 110
111 dtp = new ServerDTP( this ); 111 dtp = new ServerDTP( this );
112 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); 112 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) );
113 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); 113 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) );
114 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); 114 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) );
115 115
116 116
117 directory = QDir::currentDirPath(); 117 directory = QDir::currentDirPath();
118 118
119 static int p = 1024; 119 static int p = 1024;
120 120
121 while ( !serversocket || !serversocket->ok() ) { 121 while ( !serversocket || !serversocket->ok() ) {
122 delete serversocket; 122 delete serversocket;
123 serversocket = new ServerSocket( ++p, this ); 123 serversocket = new ServerSocket( ++p, this );
124 } 124 }
125 connect( serversocket, SIGNAL( newIncomming( int ) ), 125 connect( serversocket, SIGNAL( newIncomming( int ) ),
126 SLOT( newConnection( int ) ) ); 126 SLOT( newConnection( int ) ) );
127 } 127 }
128} 128}
129 129
130ServerPI::~ServerPI() 130ServerPI::~ServerPI()
131{ 131{
132 132
@@ -807,97 +807,97 @@ void ServerPI::newConnection( int socket )
807 if ( backupRestoreGzip( waitfile, targets ) ) 807 if ( backupRestoreGzip( waitfile, targets ) )
808 dtp->sendGzipFile( waitfile, targets ); 808 dtp->sendGzipFile( waitfile, targets );
809 else 809 else
810 dtp->sendFile( waitfile ); 810 dtp->sendFile( waitfile );
811 dtp->setSocket( socket ); 811 dtp->setSocket( socket );
812 } 812 }
813 else if ( wait[RetrieveFile] ) { 813 else if ( wait[RetrieveFile] ) {
814 qDebug("check retrieve file"); 814 qDebug("check retrieve file");
815 if ( backupRestoreGzip( waitfile ) ) 815 if ( backupRestoreGzip( waitfile ) )
816 dtp->retrieveGzipFile( waitfile ); 816 dtp->retrieveGzipFile( waitfile );
817 else 817 else
818 dtp->retrieveFile( waitfile ); 818 dtp->retrieveFile( waitfile );
819 dtp->setSocket( socket ); 819 dtp->setSocket( socket );
820 } 820 }
821 else if ( wait[SendByteArray] ) { 821 else if ( wait[SendByteArray] ) {
822 dtp->sendByteArray( waitarray ); 822 dtp->sendByteArray( waitarray );
823 dtp->setSocket( socket ); 823 dtp->setSocket( socket );
824 } 824 }
825 else if ( wait[RetrieveByteArray] ) { 825 else if ( wait[RetrieveByteArray] ) {
826 qDebug("retrieve byte array"); 826 qDebug("retrieve byte array");
827 dtp->retrieveByteArray(); 827 dtp->retrieveByteArray();
828 dtp->setSocket( socket ); 828 dtp->setSocket( socket );
829 } 829 }
830 else 830 else
831 waitsocket = socket; 831 waitsocket = socket;
832 832
833 for( int i = 0; i < 4; i++ ) 833 for( int i = 0; i < 4; i++ )
834 wait[i] = FALSE; 834 wait[i] = FALSE;
835} 835}
836 836
837QString ServerPI::absFilePath( const QString& file ) 837QString ServerPI::absFilePath( const QString& file )
838{ 838{
839 if ( file.isEmpty() ) return file; 839 if ( file.isEmpty() ) return file;
840 840
841 QString filepath( file ); 841 QString filepath( file );
842 if ( file[0] != "/" ) 842 if ( file[0] != "/" )
843 filepath = directory.path() + "/" + file; 843 filepath = directory.path() + "/" + file;
844 844
845 return filepath; 845 return filepath;
846} 846}
847 847
848 848
849void ServerPI::timerEvent( QTimerEvent * ) 849void ServerPI::timerEvent( QTimerEvent * )
850{ 850{
851 connectionClosed(); 851 connectionClosed();
852} 852}
853 853
854 854
855ServerDTP::ServerDTP( QObject *parent = 0, const char* name = 0) 855ServerDTP::ServerDTP( QObject *parent, const char* name )
856 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), 856 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ),
857retrieveTargzProc( 0 ), gzipProc( 0 ) 857retrieveTargzProc( 0 ), gzipProc( 0 )
858{ 858{
859 859
860 connect( this, SIGNAL( connected() ), SLOT( connected() ) ); 860 connect( this, SIGNAL( connected() ), SLOT( connected() ) );
861 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 861 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
862 connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); 862 connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) );
863 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); 863 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) );
864 864
865 gzipProc = new QProcess( this, "gzipProc" ); 865 gzipProc = new QProcess( this, "gzipProc" );
866 gzipProc->setCommunication( QProcess::Stdin | QProcess::Stdout ); 866 gzipProc->setCommunication( QProcess::Stdin | QProcess::Stdout );
867 867
868 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); 868 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc");
869 createTargzProc->setCommunication( QProcess::Stdout ); 869 createTargzProc->setCommunication( QProcess::Stdout );
870 createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 870 createTargzProc->setWorkingDirectory( QDir::rootDirPath() );
871 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); 871 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) );
872 872
873 QStringList args = "tar"; 873 QStringList args = "tar";
874 args += "-xv"; 874 args += "-xv";
875 retrieveTargzProc = new QProcess( args, this, "retrieveTargzProc" ); 875 retrieveTargzProc = new QProcess( args, this, "retrieveTargzProc" );
876 retrieveTargzProc->setCommunication( QProcess::Stdin ); 876 retrieveTargzProc->setCommunication( QProcess::Stdin );
877 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 877 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() );
878 connect( retrieveTargzProc, SIGNAL( processExited() ), 878 connect( retrieveTargzProc, SIGNAL( processExited() ),
879 SIGNAL( completed() ) ); 879 SIGNAL( completed() ) );
880 connect( retrieveTargzProc, SIGNAL( processExited() ), 880 connect( retrieveTargzProc, SIGNAL( processExited() ),
881 SLOT( extractTarDone() ) ); 881 SLOT( extractTarDone() ) );
882} 882}
883 883
884ServerDTP::~ServerDTP() 884ServerDTP::~ServerDTP()
885{ 885{
886 buf.close(); 886 buf.close();
887 file.close(); 887 file.close();
888 createTargzProc->kill(); 888 createTargzProc->kill();
889} 889}
890 890
891void ServerDTP::extractTarDone() 891void ServerDTP::extractTarDone()
892{ 892{
893 qDebug("extract done"); 893 qDebug("extract done");
894 QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); 894 QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" );
895 e << file.name(); 895 e << file.name();
896} 896}
897 897
898void ServerDTP::connected() 898void ServerDTP::connected()
899{ 899{
900 // send file mode 900 // send file mode
901 switch ( mode ) { 901 switch ( mode ) {
902 case SendFile : 902 case SendFile :
903 if ( !file.exists() || !file.open( IO_ReadOnly) ) { 903 if ( !file.exists() || !file.open( IO_ReadOnly) ) {