author | ar <ar> | 2004-05-02 17:11:49 (UTC) |
---|---|---|
committer | ar <ar> | 2004-05-02 17:11:49 (UTC) |
commit | 18759e9156c96795831120408a9da0d3b4ec71a4 (patch) (unidiff) | |
tree | bfc1a5560340b77a1918855e9915d133898ec189 /core/qws/qcopbridge.cpp | |
parent | 4d3379027557e251201b531896974a69ae4c665a (diff) | |
download | opie-18759e9156c96795831120408a9da0d3b4ec71a4.zip opie-18759e9156c96795831120408a9da0d3b4ec71a4.tar.gz opie-18759e9156c96795831120408a9da0d3b4ec71a4.tar.bz2 |
- convert qDebug to odebug
-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 | |||
@@ -22,8 +22,11 @@ | |||
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 |
@@ -31,4 +34,5 @@ | |||
31 | #endif | 34 | #endif |
32 | 35 | ||
36 | /* STD */ | ||
33 | #define _XOPEN_SOURCE | 37 | #define _XOPEN_SOURCE |
34 | #include <pwd.h> | 38 | #include <pwd.h> |
@@ -51,13 +55,13 @@ QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent , | |||
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 | } |
@@ -82,6 +86,6 @@ void QCopBridge::newConnection( int socket ) | |||
82 | 86 | ||
83 | if ( sendSync ) { | 87 | if ( sendSync ) { |
84 | pi ->startSync(); | 88 | pi ->startSync(); |
85 | sendSync = FALSE; | 89 | sendSync = FALSE; |
86 | } | 90 | } |
87 | } | 91 | } |
@@ -92,5 +96,5 @@ void QCopBridge::connectionClosed( QCopBridgePI *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 | } |
@@ -101,5 +105,5 @@ void QCopBridge::closeOpenConnections() | |||
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 | ||
@@ -111,12 +115,12 @@ void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args | |||
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 | ||
@@ -126,61 +130,61 @@ void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args | |||
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 | } |
@@ -203,25 +207,25 @@ QCopBridgePI::QCopBridgePI( int socket, QObject *parent , const char* name ) | |||
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 | } |
@@ -236,5 +240,5 @@ 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 | } |
@@ -251,5 +255,5 @@ void QCopBridgePI::send( const QString& msg ) | |||
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 | ||
@@ -257,10 +261,10 @@ 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 |
@@ -274,27 +278,27 @@ void QCopBridgePI::process( const QString& message ) | |||
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 | ||
@@ -302,21 +306,21 @@ void QCopBridgePI::process( const QString& message ) | |||
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 | ||
@@ -324,84 +328,84 @@ void QCopBridgePI::process( const QString& message ) | |||
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 | ||
@@ -411,6 +415,6 @@ 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 | } |