-rw-r--r-- | core/launcher/qcopbridge.cpp | 99 | ||||
-rw-r--r-- | core/launcher/qcopbridge.h | 3 |
2 files changed, 99 insertions, 3 deletions
diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp index f780235..9cb56ce 100644 --- a/core/launcher/qcopbridge.cpp +++ b/core/launcher/qcopbridge.cpp | |||
@@ -1,302 +1,395 @@ | |||
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 | #ifdef Q_WS_QWS | 24 | #ifdef Q_WS_QWS |
25 | #include <qtopia/qcopenvelope_qws.h> | 25 | #include <qtopia/qcopenvelope_qws.h> |
26 | #endif | 26 | #endif |
27 | #include <qtopia/qpeapplication.h> | 27 | #include <qtopia/qpeapplication.h> |
28 | #include <qtopia/global.h> | 28 | #include <qtopia/global.h> |
29 | #include <qtopia/version.h> | 29 | #include <qtopia/version.h> |
30 | #include <qtopia/config.h> | ||
30 | 31 | ||
31 | #include <qdir.h> | 32 | #include <qdir.h> |
32 | #include <qfile.h> | 33 | #include <qfile.h> |
33 | #include <qtextstream.h> | 34 | #include <qtextstream.h> |
34 | #include <qdatastream.h> | 35 | #include <qdatastream.h> |
35 | #include <qcstring.h> | 36 | #include <qcstring.h> |
36 | #include <qstringlist.h> | 37 | #include <qstringlist.h> |
37 | #include <qfileinfo.h> | 38 | #include <qfileinfo.h> |
38 | #include <qregexp.h> | 39 | #include <qregexp.h> |
39 | #include <qtimer.h> | 40 | #include <qtimer.h> |
40 | #ifdef Q_WS_QWS | 41 | #ifdef Q_WS_QWS |
41 | #include <qcopchannel_qws.h> | 42 | #include <qcopchannel_qws.h> |
42 | #endif | 43 | #endif |
43 | 44 | ||
44 | #ifndef _XOPEN_SOURCE | 45 | #ifndef _XOPEN_SOURCE |
45 | #define _XOPEN_SOURCE | 46 | #define _XOPEN_SOURCE |
46 | #endif | 47 | #endif |
47 | #ifndef Q_OS_WIN32 | 48 | #ifndef Q_OS_WIN32 |
48 | #include <pwd.h> | 49 | #include <pwd.h> |
49 | #include <unistd.h> | 50 | #include <unistd.h> |
50 | #include <sys/types.h> | 51 | #include <sys/types.h> |
51 | #endif | 52 | #endif |
52 | 53 | ||
53 | #if defined(_OS_LINUX_) | 54 | #if defined(_OS_LINUX_) |
54 | #include <shadow.h> | 55 | #include <shadow.h> |
55 | #endif | 56 | #endif |
56 | 57 | ||
57 | #include "launcherglobal.h" | 58 | #include "launcherglobal.h" |
58 | 59 | ||
59 | //#define INSECURE | 60 | //#define INSECURE |
60 | 61 | ||
61 | const int block_size = 51200; | 62 | const int block_size = 51200; |
62 | 63 | ||
63 | QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent, | 64 | QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent, |
64 | const char* name ) | 65 | const char* name ) |
65 | : QServerSocket( port, 1, parent, name ), | 66 | : QServerSocket( port, 1, parent, name ), |
66 | desktopChannel( 0 ), | 67 | desktopChannel( 0 ), |
67 | cardChannel( 0 ) | 68 | cardChannel( 0 ) |
68 | { | 69 | { |
69 | if ( !ok() ) | 70 | if ( !ok() ) |
70 | qWarning( "Failed to bind to port %d", port ); | 71 | qWarning( "Failed to bind to port %d", port ); |
71 | else { | 72 | else { |
72 | #ifndef QT_NO_COP | 73 | #ifndef QT_NO_COP |
73 | desktopChannel = new QCopChannel( "QPE/Desktop", this ); | 74 | desktopChannel = new QCopChannel( "QPE/Desktop", this ); |
74 | connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)), | 75 | connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)), |
75 | this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); | 76 | this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); |
76 | cardChannel = new QCopChannel( "QPE/Card", this ); | 77 | cardChannel = new QCopChannel( "QPE/Card", this ); |
77 | connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), | 78 | connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), |
78 | this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); | 79 | this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); |
79 | #endif | 80 | #endif |
80 | } | 81 | } |
81 | sendSync = FALSE; | 82 | sendSync = FALSE; |
82 | openConnections.setAutoDelete( TRUE ); | 83 | openConnections.setAutoDelete( TRUE ); |
84 | authorizeConnections(); | ||
83 | } | 85 | } |
84 | 86 | ||
85 | QCopBridge::~QCopBridge() | 87 | QCopBridge::~QCopBridge() |
86 | { | 88 | { |
87 | #ifndef QT_NO_COP | 89 | #ifndef QT_NO_COP |
88 | delete desktopChannel; | 90 | delete desktopChannel; |
89 | #endif | 91 | #endif |
90 | } | 92 | } |
91 | 93 | ||
92 | void QCopBridge::authorizeConnections() | 94 | void QCopBridge::authorizeConnections() |
93 | { | 95 | { |
96 | Config cfg("Security"); | ||
97 | cfg.setGroup("SyncMode"); | ||
98 | m_mode = Mode(cfg.readNumEntry("Mode", Sharp )); | ||
94 | QListIterator<QCopBridgePI> it(openConnections); | 99 | QListIterator<QCopBridgePI> it(openConnections); |
95 | while ( it.current() ) { | 100 | while ( it.current() ) { |
96 | if ( !it.current()->verifyAuthorised() ) { | 101 | if ( !it.current()->verifyAuthorised() ) { |
97 | disconnect ( it.current(), SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) ); | 102 | disconnect ( it.current(), SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) ); |
98 | openConnections.removeRef( it.current() ); | 103 | openConnections.removeRef( it.current() ); |
99 | } else | 104 | } else |
100 | ++it; | 105 | ++it; |
101 | } | 106 | } |
102 | } | 107 | } |
103 | 108 | ||
104 | void QCopBridge::newConnection( int socket ) | 109 | void QCopBridge::newConnection( int socket ) |
105 | { | 110 | { |
106 | QCopBridgePI *pi = new QCopBridgePI( socket, this ); | 111 | QCopBridgePI *pi = new QCopBridgePI( socket, this ); |
107 | openConnections.append( pi ); | 112 | openConnections.append( pi ); |
108 | connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) ); | 113 | connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) ); |
109 | 114 | ||
110 | /* ### libqtopia merge FIXME */ | 115 | /* ### libqtopia merge FIXME */ |
111 | #if 0 | 116 | #if 0 |
112 | QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend ); | 117 | QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend ); |
113 | #endif | 118 | #endif |
114 | #ifndef QT_NO_COP | 119 | #ifndef QT_NO_COP |
115 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; | 120 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; |
116 | #endif | 121 | #endif |
117 | 122 | ||
118 | if ( sendSync ) { | 123 | if ( sendSync ) { |
119 | pi ->startSync(); | 124 | pi ->startSync(); |
120 | sendSync = FALSE; | 125 | sendSync = FALSE; |
121 | } | 126 | } |
122 | } | 127 | } |
123 | 128 | ||
124 | void QCopBridge::closed( QCopBridgePI *pi ) | 129 | void QCopBridge::closed( QCopBridgePI *pi ) |
125 | { | 130 | { |
126 | emit connectionClosed( pi->peerAddress() ); | 131 | emit connectionClosed( pi->peerAddress() ); |
127 | openConnections.removeRef( pi ); | 132 | openConnections.removeRef( pi ); |
128 | if ( openConnections.count() == 0 ) { | 133 | if ( openConnections.count() == 0 ) { |
129 | /* ### FIXME libqtopia merge */ | 134 | /* ### FIXME libqtopia merge */ |
130 | #if 0 | 135 | #if 0 |
131 | QPEApplication::setTempScreenSaverMode( QPEApplication::Enable ); | 136 | QPEApplication::setTempScreenSaverMode( QPEApplication::Enable ); |
132 | #endif | 137 | #endif |
133 | #ifndef QT_NO_COP | 138 | #ifndef QT_NO_COP |
134 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | 139 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; |
135 | #endif | 140 | #endif |
136 | } | 141 | } |
137 | } | 142 | } |
138 | 143 | ||
139 | void QCopBridge::closeOpenConnections() | 144 | void QCopBridge::closeOpenConnections() |
140 | { | 145 | { |
141 | QCopBridgePI *pi; | 146 | QCopBridgePI *pi; |
142 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) | 147 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) |
143 | pi->close(); | 148 | pi->close(); |
144 | } | 149 | } |
145 | 150 | ||
146 | 151 | ||
147 | void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data ) | 152 | void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data ) |
148 | { | 153 | { |
149 | if ( command == "startSync()" ) { | 154 | if ( command == "startSync()" ) { |
150 | // we need to buffer it a bit | 155 | // we need to buffer it a bit |
151 | sendSync = TRUE; | 156 | sendSync = TRUE; |
152 | startTimer( 20000 ); | 157 | startTimer( 20000 ); |
153 | } | 158 | } |
154 | 159 | ||
160 | if ( m_mode & Qtopia1_7 ) { | ||
161 | // send the command to all open connections | ||
162 | QCopBridgePI *pi; | ||
163 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { | ||
164 | pi->sendDesktopMessage( command, data ); | ||
165 | } | ||
166 | } | ||
167 | if ( m_mode & Sharp ) | ||
168 | sendDesktopMessageOld( command, data ); | ||
169 | } | ||
170 | |||
171 | #ifndef OPIE_NO_OLD_SYNC_CODE | ||
172 | /* | ||
173 | * Old compat mode | ||
174 | */ | ||
175 | void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) { | ||
176 | command.stripWhiteSpace(); | ||
177 | |||
178 | int paren = command.find( "(" ); | ||
179 | if ( paren <= 0 ) { | ||
180 | qDebug("DesktopMessage: bad qcop syntax"); | ||
181 | return; | ||
182 | } | ||
183 | |||
184 | QString params = command.mid( paren + 1 ); | ||
185 | if ( params[params.length()-1] != ')' ) { | ||
186 | qDebug("DesktopMessage: bad qcop syntax"); | ||
187 | return; | ||
188 | } | ||
189 | |||
190 | params.truncate( params.length()-1 ); | ||
191 | |||
192 | QStringList paramList = QStringList::split( ",", params ); | ||
193 | QString data; | ||
194 | if ( paramList.count() ) { | ||
195 | QDataStream stream( args, IO_ReadOnly ); | ||
196 | for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { | ||
197 | QString str; | ||
198 | if ( *it == "QString" ) { | ||
199 | stream >> str; | ||
200 | } else if ( *it == "QCString" ) { | ||
201 | QCString cstr; | ||
202 | stream >> cstr; | ||
203 | str = QString::fromLocal8Bit( cstr ); | ||
204 | } else if ( *it == "int" ) { | ||
205 | int i; | ||
206 | stream >> i; | ||
207 | str = QString::number( i ); | ||
208 | } else if ( *it == "bool" ) { | ||
209 | int i; | ||
210 | stream >> i; | ||
211 | str = QString::number( i ); | ||
212 | } else { | ||
213 | qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() ); | ||
214 | return; | ||
215 | } | ||
216 | QString estr; | ||
217 | for (int i=0; i<(int)str.length(); i++) { | ||
218 | QChar ch = str[i]; | ||
219 | if ( ch.row() ) | ||
220 | goto quick; | ||
221 | switch (ch.cell()) { | ||
222 | case '&': | ||
223 | estr.append( "&" ); | ||
224 | break; | ||
225 | case ' ': | ||
226 | estr.append( "&0x20;" ); | ||
227 | break; | ||
228 | case '\n': | ||
229 | estr.append( "&0x0d;" ); | ||
230 | break; | ||
231 | case '\r': | ||
232 | estr.append( "&0x0a;" ); | ||
233 | break; | ||
234 | default: quick: | ||
235 | estr.append(ch); | ||
236 | } | ||
237 | } | ||
238 | data += " " + estr; | ||
239 | } | ||
240 | } | ||
241 | QString sendCommand = QString(command.data()) + data; | ||
242 | |||
243 | |||
155 | // send the command to all open connections | 244 | // send the command to all open connections |
156 | QCopBridgePI *pi; | 245 | QCopBridgePI *pi; |
157 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { | 246 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) |
158 | pi->sendDesktopMessage( command, data ); | 247 | pi->sendDesktopMessage( sendCommand ); |
159 | } | 248 | |
160 | } | 249 | } |
250 | #endif | ||
251 | |||
161 | 252 | ||
162 | void QCopBridge::timerEvent( QTimerEvent * ) | 253 | void QCopBridge::timerEvent( QTimerEvent * ) |
163 | { | 254 | { |
164 | sendSync = FALSE; | 255 | sendSync = FALSE; |
165 | killTimers(); | 256 | killTimers(); |
166 | } | 257 | } |
167 | 258 | ||
168 | 259 | ||
169 | QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name ) | 260 | QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name ) |
170 | : QSocket( parent, name ) | 261 | : QSocket( parent, name ) |
171 | { | 262 | { |
172 | setSocket( socket ); | 263 | setSocket( socket ); |
173 | 264 | ||
174 | peerport = peerPort(); | 265 | peerport = peerPort(); |
175 | peeraddress = peerAddress(); | 266 | peeraddress = peerAddress(); |
176 | 267 | ||
177 | #ifndef INSECURE | 268 | #ifndef INSECURE |
178 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { | 269 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { |
179 | state = Forbidden; | 270 | state = Forbidden; |
180 | close(); | 271 | close(); |
181 | } else | 272 | } else |
182 | #endif | 273 | #endif |
183 | { | 274 | { |
184 | state = Connected; | 275 | state = Connected; |
185 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); | 276 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); |
186 | QString intro="220 Qtopia "; | 277 | QString intro="220 Qtopia "; |
187 | intro += QPE_VERSION; intro += ";"; | 278 | intro += QPE_VERSION; intro += ";"; |
188 | intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";"; // No tr | 279 | intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";"; // No tr |
189 | intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";"; | 280 | intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";"; |
190 | intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";"; | 281 | intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";"; |
191 | send( intro ); | 282 | send( intro ); |
192 | state = Wait_USER; | 283 | state = Wait_USER; |
193 | } | 284 | } |
194 | sendSync = FALSE; | 285 | sendSync = FALSE; |
195 | connect( this, SIGNAL( connectionClosed() ), SLOT( myConnectionClosed() ) ); | 286 | connect( this, SIGNAL( connectionClosed() ), SLOT( myConnectionClosed() ) ); |
196 | 287 | ||
197 | // idle timer to close connections when not used anymore | 288 | // idle timer to close connections when not used anymore |
198 | timer = new QTimer(this); | 289 | timer = new QTimer(this); |
199 | connect( timer, SIGNAL(timeout()), this, SLOT(myConnectionClosed()) ); | 290 | connect( timer, SIGNAL(timeout()), this, SLOT(myConnectionClosed()) ); |
200 | timer->start( 300000, TRUE ); | 291 | timer->start( 300000, TRUE ); |
201 | } | 292 | } |
202 | 293 | ||
203 | 294 | ||
204 | QCopBridgePI::~QCopBridgePI() | 295 | QCopBridgePI::~QCopBridgePI() |
205 | { | 296 | { |
206 | } | 297 | } |
207 | 298 | ||
208 | bool QCopBridgePI::verifyAuthorised() | 299 | bool QCopBridgePI::verifyAuthorised() |
209 | { | 300 | { |
210 | if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { | 301 | if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { |
211 | state = Forbidden; | 302 | state = Forbidden; |
212 | return FALSE; | 303 | return FALSE; |
213 | } | 304 | } |
214 | return TRUE; | 305 | return TRUE; |
215 | } | 306 | } |
216 | 307 | ||
217 | void QCopBridgePI::myConnectionClosed() | 308 | void QCopBridgePI::myConnectionClosed() |
218 | { | 309 | { |
219 | emit connectionClosed( this ); | 310 | emit connectionClosed( this ); |
220 | } | 311 | } |
221 | 312 | ||
222 | void QCopBridgePI::sendDesktopMessage( const QString &msg ) | 313 | void QCopBridgePI::sendDesktopMessage( const QString &msg ) |
223 | { | 314 | { |
224 | QString str = "CALL QPE/Desktop " + msg; // No tr | 315 | QString str = "CALL QPE/Desktop " + msg; // No tr |
225 | send ( str ); | 316 | send ( str ); |
226 | } | 317 | } |
227 | 318 | ||
228 | void QCopBridgePI::sendDesktopMessage( const QCString &msg, const QByteArray& data ) | 319 | void QCopBridgePI::sendDesktopMessage( const QCString &msg, const QByteArray& data ) |
229 | { | 320 | { |
230 | if ( !isOpen() ) // eg. Forbidden | 321 | if ( !isOpen() ) // eg. Forbidden |
231 | return; | 322 | return; |
323 | |||
232 | const char hdr[]="CALLB QPE/Desktop "; | 324 | const char hdr[]="CALLB QPE/Desktop "; |
233 | writeBlock(hdr,sizeof(hdr)-1); | 325 | writeBlock(hdr,sizeof(hdr)-1); |
234 | writeBlock(msg,msg.length()); | 326 | writeBlock(msg,msg.length()); |
235 | writeBlock(" ",1); | 327 | writeBlock(" ",1); |
236 | QByteArray b64 = Opie::Global::encodeBase64(data); | 328 | QByteArray b64 = Opie::Global::encodeBase64(data); |
237 | writeBlock(b64.data(),b64.size()); | 329 | writeBlock(b64.data(),b64.size()); |
238 | writeBlock("\r\n",2); | 330 | writeBlock("\r\n",2); |
331 | |||
239 | } | 332 | } |
240 | 333 | ||
241 | 334 | ||
242 | void QCopBridgePI::send( const QString& msg ) | 335 | void QCopBridgePI::send( const QString& msg ) |
243 | { | 336 | { |
244 | if ( !isOpen() ) // eg. Forbidden | 337 | if ( !isOpen() ) // eg. Forbidden |
245 | return; | 338 | return; |
246 | QTextStream os( this ); | 339 | QTextStream os( this ); |
247 | os << msg << endl; | 340 | os << msg << endl; |
248 | //qDebug( "sending qcop message: %s", msg.latin1() ); | 341 | //qDebug( "sending qcop message: %s", msg.latin1() ); |
249 | } | 342 | } |
250 | 343 | ||
251 | void QCopBridgePI::read() | 344 | void QCopBridgePI::read() |
252 | { | 345 | { |
253 | while ( canReadLine() ) { | 346 | while ( canReadLine() ) { |
254 | timer->start( 300000, TRUE ); | 347 | timer->start( 300000, TRUE ); |
255 | process( readLine().stripWhiteSpace() ); | 348 | process( readLine().stripWhiteSpace() ); |
256 | } | 349 | } |
257 | } | 350 | } |
258 | 351 | ||
259 | void QCopBridgePI::process( const QString& message ) | 352 | void QCopBridgePI::process( const QString& message ) |
260 | { | 353 | { |
261 | //qDebug( "Command: %s", message.latin1() ); | 354 | //qDebug( "Command: %s", message.latin1() ); |
262 | 355 | ||
263 | // split message using "," as separator | 356 | // split message using "," as separator |
264 | QStringList msg = QStringList::split( " ", message ); | 357 | QStringList msg = QStringList::split( " ", message ); |
265 | if ( msg.isEmpty() ) return; | 358 | if ( msg.isEmpty() ) return; |
266 | 359 | ||
267 | // command token | 360 | // command token |
268 | QString cmd = msg[0].upper(); | 361 | QString cmd = msg[0].upper(); |
269 | 362 | ||
270 | // argument token | 363 | // argument token |
271 | QString arg; | 364 | QString arg; |
272 | if ( msg.count() >= 2 ) | 365 | if ( msg.count() >= 2 ) |
273 | arg = msg[1]; | 366 | arg = msg[1]; |
274 | 367 | ||
275 | // we always respond to QUIT, regardless of state | 368 | // we always respond to QUIT, regardless of state |
276 | if ( cmd == "QUIT" ) { | 369 | if ( cmd == "QUIT" ) { |
277 | send( "211 Have a nice day!" ); // No tr | 370 | send( "211 Have a nice day!" ); // No tr |
278 | close(); | 371 | close(); |
279 | return; | 372 | return; |
280 | } | 373 | } |
281 | 374 | ||
282 | // connected to client | 375 | // connected to client |
283 | if ( Connected == state ) | 376 | if ( Connected == state ) |
284 | return; | 377 | return; |
285 | 378 | ||
286 | // waiting for user name | 379 | // waiting for user name |
287 | if ( Wait_USER == state ) { | 380 | if ( Wait_USER == state ) { |
288 | 381 | ||
289 | if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { | 382 | if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { |
290 | send( "530 Please login with USER and PASS" ); // No tr | 383 | send( "530 Please login with USER and PASS" ); // No tr |
291 | return; | 384 | return; |
292 | } | 385 | } |
293 | send( "331 User name ok, need password" ); // No tr | 386 | send( "331 User name ok, need password" ); // No tr |
294 | state = Wait_PASS; | 387 | state = Wait_PASS; |
295 | return; | 388 | return; |
296 | } | 389 | } |
297 | 390 | ||
298 | // waiting for password | 391 | // waiting for password |
299 | if ( Wait_PASS == state ) { | 392 | if ( Wait_PASS == state ) { |
300 | 393 | ||
301 | if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { | 394 | if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { |
302 | send( "530 Please login with USER and PASS" ); // No tr | 395 | send( "530 Please login with USER and PASS" ); // No tr |
diff --git a/core/launcher/qcopbridge.h b/core/launcher/qcopbridge.h index bae3f88..9483d9d 100644 --- a/core/launcher/qcopbridge.h +++ b/core/launcher/qcopbridge.h | |||
@@ -1,97 +1,100 @@ | |||
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 | ||
30 | class QFileInfo; | 30 | class QFileInfo; |
31 | class QCopBridgePI; | 31 | class QCopBridgePI; |
32 | class QCopChannel; | 32 | class QCopChannel; |
33 | class QTimer; | 33 | class QTimer; |
34 | 34 | ||
35 | class QCopBridge : public QServerSocket | 35 | class QCopBridge : public QServerSocket |
36 | { | 36 | { |
37 | Q_OBJECT | 37 | Q_OBJECT |
38 | 38 | ||
39 | public: | 39 | public: |
40 | enum Mode { Qtopia1_7= 0x01, Sharp = 0x02, Both = Qtopia1_7 | Sharp }; | ||
40 | QCopBridge( Q_UINT16 port, QObject *parent = 0, const char* name = 0 ); | 41 | QCopBridge( Q_UINT16 port, QObject *parent = 0, const char* name = 0 ); |
41 | virtual ~QCopBridge(); | 42 | virtual ~QCopBridge(); |
42 | 43 | ||
43 | void newConnection( int socket ); | 44 | void newConnection( int socket ); |
44 | void closeOpenConnections(); | 45 | void closeOpenConnections(); |
45 | void authorizeConnections(); | 46 | void authorizeConnections(); |
46 | 47 | ||
47 | public slots: | 48 | public slots: |
48 | void closed( QCopBridgePI *pi ); | 49 | void closed( QCopBridgePI *pi ); |
49 | void desktopMessage( const QCString &call, const QByteArray & ); | 50 | void desktopMessage( const QCString &call, const QByteArray & ); |
50 | 51 | ||
51 | signals: | 52 | signals: |
52 | void connectionClosed( const QHostAddress & ); | 53 | void connectionClosed( const QHostAddress & ); |
53 | 54 | ||
54 | protected: | 55 | protected: |
55 | void timerEvent( QTimerEvent * ); | 56 | void timerEvent( QTimerEvent * ); |
57 | void sendDesktopMessageOld( const QCString&, const QByteArray& ); | ||
56 | 58 | ||
57 | private: | 59 | private: |
58 | QCopChannel *desktopChannel; | 60 | QCopChannel *desktopChannel; |
59 | QCopChannel *cardChannel; | 61 | QCopChannel *cardChannel; |
60 | QList<QCopBridgePI> openConnections; | 62 | QList<QCopBridgePI> openConnections; |
61 | bool sendSync; | 63 | bool sendSync; |
64 | Mode m_mode; | ||
62 | }; | 65 | }; |
63 | 66 | ||
64 | 67 | ||
65 | class QCopBridgePI : public QSocket | 68 | class QCopBridgePI : public QSocket |
66 | { | 69 | { |
67 | Q_OBJECT | 70 | Q_OBJECT |
68 | 71 | ||
69 | enum State { Connected, Wait_USER, Wait_PASS, Ready, Forbidden }; | 72 | enum State { Connected, Wait_USER, Wait_PASS, Ready, Forbidden }; |
70 | 73 | ||
71 | public: | 74 | public: |
72 | QCopBridgePI( int socket, QObject *parent = 0, const char* name = 0 ); | 75 | QCopBridgePI( int socket, QObject *parent = 0, const char* name = 0 ); |
73 | virtual ~QCopBridgePI(); | 76 | virtual ~QCopBridgePI(); |
74 | 77 | ||
75 | void sendDesktopMessage( const QString &msg ); | 78 | void sendDesktopMessage( const QString &msg ); |
76 | void sendDesktopMessage( const QCString &msg, const QByteArray& ); | 79 | void sendDesktopMessage( const QCString &msg, const QByteArray& ); |
77 | void startSync() { sendSync = TRUE; } | 80 | void startSync() { sendSync = TRUE; } |
78 | bool verifyAuthorised(); | 81 | bool verifyAuthorised(); |
79 | 82 | ||
80 | signals: | 83 | signals: |
81 | void connectionClosed( QCopBridgePI *); | 84 | void connectionClosed( QCopBridgePI *); |
82 | 85 | ||
83 | protected slots: | 86 | protected slots: |
84 | void read(); | 87 | void read(); |
85 | void send( const QString& msg ); | 88 | void send( const QString& msg ); |
86 | void process( const QString& command ); | 89 | void process( const QString& command ); |
87 | void myConnectionClosed(); | 90 | void myConnectionClosed(); |
88 | 91 | ||
89 | private: | 92 | private: |
90 | State state; | 93 | State state; |
91 | Q_UINT16 peerport; | 94 | Q_UINT16 peerport; |
92 | QHostAddress peeraddress; | 95 | QHostAddress peeraddress; |
93 | bool sendSync; | 96 | bool sendSync; |
94 | QTimer *timer; | 97 | QTimer *timer; |
95 | }; | 98 | }; |
96 | 99 | ||
97 | #endif | 100 | #endif |