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