summaryrefslogtreecommitdiff
path: root/core/launcher/qcopbridge.cpp
Unidiff
Diffstat (limited to 'core/launcher/qcopbridge.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/qcopbridge.cpp23
1 files changed, 11 insertions, 12 deletions
diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp
index 33df6c4..e339dc7 100644
--- a/core/launcher/qcopbridge.cpp
+++ b/core/launcher/qcopbridge.cpp
@@ -1,89 +1,88 @@
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/* OPIE */
25#include <opie2/odebug.h>
24#include <opie2/oglobal.h> 26#include <opie2/oglobal.h>
25
26#ifdef Q_WS_QWS 27#ifdef Q_WS_QWS
27#include <qtopia/qcopenvelope_qws.h> 28#include <qtopia/qcopenvelope_qws.h>
28#endif 29#endif
29#include <qtopia/qpeapplication.h> 30#include <qtopia/qpeapplication.h>
30
31#include <qtopia/version.h> 31#include <qtopia/version.h>
32using namespace Opie::Core;
32 33
34/* QT */
33#include <qtextstream.h> 35#include <qtextstream.h>
34#include <qtimer.h> 36#include <qtimer.h>
35#ifdef Q_WS_QWS 37#ifdef Q_WS_QWS
36#include <qcopchannel_qws.h> 38#include <qcopchannel_qws.h>
37#endif 39#endif
38 40
41/* STD */
39#ifndef _XOPEN_SOURCE 42#ifndef _XOPEN_SOURCE
40#define _XOPEN_SOURCE 43#define _XOPEN_SOURCE
41#endif 44#endif
42#ifndef Q_OS_WIN32 45#ifndef Q_OS_WIN32
43#include <pwd.h> 46#include <pwd.h>
44#include <unistd.h> 47#include <unistd.h>
45#include <sys/types.h> 48#include <sys/types.h>
46#endif 49#endif
47 50
48#if defined(_OS_LINUX_) 51#if defined(_OS_LINUX_)
49#include <shadow.h> 52#include <shadow.h>
50#endif 53#endif
51 54
52
53//#define INSECURE
54
55const int block_size = 51200; 55const int block_size = 51200;
56 56
57using namespace Opie::Core;
58QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent, 57QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent,
59 const char* name ) 58 const char* name )
60 : QServerSocket( port, 1, parent, name ), 59 : QServerSocket( port, 1, parent, name ),
61 desktopChannel( 0 ), 60 desktopChannel( 0 ),
62 cardChannel( 0 ) 61 cardChannel( 0 )
63{ 62{
64 if ( !ok() ) 63 if ( !ok() )
65 qWarning( "Failed to bind to port %d", port ); 64 owarn << "Failed to bind to port " << port << "" << oendl;
66 else { 65 else {
67#ifndef QT_NO_COP 66#ifndef QT_NO_COP
68 desktopChannel = new QCopChannel( "QPE/Desktop", this ); 67 desktopChannel = new QCopChannel( "QPE/Desktop", this );
69 connect( desktopChannel, SIGNAL(received(const QCString&,const QByteArray&)), 68 connect( desktopChannel, SIGNAL(received(const QCString&,const QByteArray&)),
70 this, SLOT(desktopMessage(const QCString&,const QByteArray&)) ); 69 this, SLOT(desktopMessage(const QCString&,const QByteArray&)) );
71 cardChannel = new QCopChannel( "QPE/Card", this ); 70 cardChannel = new QCopChannel( "QPE/Card", this );
72 connect( cardChannel, SIGNAL(received(const QCString&,const QByteArray&)), 71 connect( cardChannel, SIGNAL(received(const QCString&,const QByteArray&)),
73 this, SLOT(desktopMessage(const QCString&,const QByteArray&)) ); 72 this, SLOT(desktopMessage(const QCString&,const QByteArray&)) );
74#endif 73#endif
75 } 74 }
76 sendSync = FALSE; 75 sendSync = FALSE;
77 openConnections.setAutoDelete( TRUE ); 76 openConnections.setAutoDelete( TRUE );
78 authorizeConnections(); 77 authorizeConnections();
79} 78}
80 79
81QCopBridge::~QCopBridge() 80QCopBridge::~QCopBridge()
82{ 81{
83#ifndef QT_NO_COP 82#ifndef QT_NO_COP
84 delete desktopChannel; 83 delete desktopChannel;
85#endif 84#endif
86} 85}
87 86
88void QCopBridge::authorizeConnections() 87void QCopBridge::authorizeConnections()
89{ 88{
@@ -150,82 +149,82 @@ void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data
150 sendSync = TRUE; 149 sendSync = TRUE;
151 startTimer( 20000 ); 150 startTimer( 20000 );
152 } 151 }
153 152
154 if ( m_mode & Qtopia1_7 ) { 153 if ( m_mode & Qtopia1_7 ) {
155 // send the command to all open connections 154 // send the command to all open connections
156 QCopBridgePI *pi; 155 QCopBridgePI *pi;
157 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { 156 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) {
158 pi->sendDesktopMessage( command, data ); 157 pi->sendDesktopMessage( command, data );
159 } 158 }
160 } 159 }
161 if ( ( m_mode & Sharp ) || (m_mode & IntelliSync) ) 160 if ( ( m_mode & Sharp ) || (m_mode & IntelliSync) )
162 sendDesktopMessageOld( command, data ); 161 sendDesktopMessageOld( command, data );
163} 162}
164 163
165#ifndef OPIE_NO_OLD_SYNC_CODE 164#ifndef OPIE_NO_OLD_SYNC_CODE
166/* 165/*
167 * Old compat mode 166 * Old compat mode
168 */ 167 */
169void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) { 168void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) {
170 command.stripWhiteSpace(); 169 command.stripWhiteSpace();
171 170
172 int paren = command.find( "(" ); 171 int paren = command.find( "(" );
173 if ( paren <= 0 ) { 172 if ( paren <= 0 ) {
174 qDebug("DesktopMessage: bad qcop syntax"); 173 odebug << "DesktopMessage: bad qcop syntax" << oendl;
175 return; 174 return;
176 } 175 }
177 176
178 QString params = command.mid( paren + 1 ); 177 QString params = command.mid( paren + 1 );
179 if ( params[params.length()-1] != ')' ) { 178 if ( params[params.length()-1] != ')' ) {
180 qDebug("DesktopMessage: bad qcop syntax"); 179 odebug << "DesktopMessage: bad qcop syntax" << oendl;
181 return; 180 return;
182 } 181 }
183 182
184 params.truncate( params.length()-1 ); 183 params.truncate( params.length()-1 );
185 184
186 QStringList paramList = QStringList::split( ",", params ); 185 QStringList paramList = QStringList::split( ",", params );
187 QString data; 186 QString data;
188 if ( paramList.count() ) { 187 if ( paramList.count() ) {
189 QDataStream stream( args, IO_ReadOnly ); 188 QDataStream stream( args, IO_ReadOnly );
190 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { 189 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
191 QString str; 190 QString str;
192 if ( *it == "QString" ) { 191 if ( *it == "QString" ) {
193 stream >> str; 192 stream >> str;
194 } else if ( *it == "QCString" ) { 193 } else if ( *it == "QCString" ) {
195 QCString cstr; 194 QCString cstr;
196 stream >> cstr; 195 stream >> cstr;
197 str = QString::fromLocal8Bit( cstr ); 196 str = QString::fromLocal8Bit( cstr );
198 } else if ( *it == "int" ) { 197 } else if ( *it == "int" ) {
199 int i; 198 int i;
200 stream >> i; 199 stream >> i;
201 str = QString::number( i ); 200 str = QString::number( i );
202 } else if ( *it == "bool" ) { 201 } else if ( *it == "bool" ) {
203 int i; 202 int i;
204 stream >> i; 203 stream >> i;
205 str = QString::number( i ); 204 str = QString::number( i );
206 } else { 205 } else {
207 qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() ); 206 odebug << " cannot route the argument type " << (*it) << " throught the qcop bridge" << oendl;
208 return; 207 return;
209 } 208 }
210 QString estr; 209 QString estr;
211 for (int i=0; i<(int)str.length(); i++) { 210 for (int i=0; i<(int)str.length(); i++) {
212 QChar ch = str[i]; 211 QChar ch = str[i];
213 if ( ch.row() ) 212 if ( ch.row() )
214 goto quick; 213 goto quick;
215 switch (ch.cell()) { 214 switch (ch.cell()) {
216 case '&': 215 case '&':
217 estr.append( "&amp;" ); 216 estr.append( "&amp;" );
218 break; 217 break;
219 case ' ': 218 case ' ':
220 estr.append( "&0x20;" ); 219 estr.append( "&0x20;" );
221 break; 220 break;
222 case '\n': 221 case '\n':
223 estr.append( "&0x0d;" ); 222 estr.append( "&0x0d;" );
224 break; 223 break;
225 case '\r': 224 case '\r':
226 estr.append( "&0x0a;" ); 225 estr.append( "&0x0a;" );
227 break; 226 break;
228 default: quick: 227 default: quick:
229 estr.append(ch); 228 estr.append(ch);
230 } 229 }
231 } 230 }
@@ -311,62 +310,62 @@ void QCopBridgePI::sendDesktopMessage( const QString &msg )
311} 310}
312 311
313void QCopBridgePI::sendDesktopMessage( const QCString &msg, const QByteArray& data ) 312void QCopBridgePI::sendDesktopMessage( const QCString &msg, const QByteArray& data )
314{ 313{
315 if ( !isOpen() ) // eg. Forbidden 314 if ( !isOpen() ) // eg. Forbidden
316 return; 315 return;
317 316
318 const char hdr[]="CALLB QPE/Desktop "; 317 const char hdr[]="CALLB QPE/Desktop ";
319 writeBlock(hdr,sizeof(hdr)-1); 318 writeBlock(hdr,sizeof(hdr)-1);
320 writeBlock(msg,msg.length()); 319 writeBlock(msg,msg.length());
321 writeBlock(" ",1); 320 writeBlock(" ",1);
322 QByteArray b64 = OGlobal::encodeBase64(data); 321 QByteArray b64 = OGlobal::encodeBase64(data);
323 writeBlock(b64.data(),b64.size()); 322 writeBlock(b64.data(),b64.size());
324 writeBlock("\r\n",2); 323 writeBlock("\r\n",2);
325 324
326} 325}
327 326
328 327
329void QCopBridgePI::send( const QString& msg ) 328void QCopBridgePI::send( const QString& msg )
330{ 329{
331 if ( !isOpen() ) // eg. Forbidden 330 if ( !isOpen() ) // eg. Forbidden
332 return; 331 return;
333 QTextStream os( this ); 332 QTextStream os( this );
334 os << msg << endl; 333 os << msg << endl;
335 //qDebug( "sending qcop message: %s", msg.latin1() ); 334 //odebug << "sending qcop message: " << msg << "" << oendl;
336} 335}
337 336
338void QCopBridgePI::read() 337void QCopBridgePI::read()
339{ 338{
340 while ( canReadLine() ) { 339 while ( canReadLine() ) {
341 timer->start( 300000, TRUE ); 340 timer->start( 300000, TRUE );
342 process( readLine().stripWhiteSpace() ); 341 process( readLine().stripWhiteSpace() );
343 } 342 }
344} 343}
345 344
346void QCopBridgePI::process( const QString& message ) 345void QCopBridgePI::process( const QString& message )
347{ 346{
348 //qDebug( "Command: %s", message.latin1() ); 347 //odebug << "Command: " << message << "" << oendl;
349 348
350 // split message using "," as separator 349 // split message using "," as separator
351 QStringList msg = QStringList::split( " ", message ); 350 QStringList msg = QStringList::split( " ", message );
352 if ( msg.isEmpty() ) return; 351 if ( msg.isEmpty() ) return;
353 352
354 // command token 353 // command token
355 QString cmd = msg[0].upper(); 354 QString cmd = msg[0].upper();
356 355
357 // argument token 356 // argument token
358 QString arg; 357 QString arg;
359 if ( msg.count() >= 2 ) 358 if ( msg.count() >= 2 )
360 arg = msg[1]; 359 arg = msg[1];
361 360
362 // we always respond to QUIT, regardless of state 361 // we always respond to QUIT, regardless of state
363 if ( cmd == "QUIT" ) { 362 if ( cmd == "QUIT" ) {
364 send( "211 Have a nice day!" ); // No tr 363 send( "211 Have a nice day!" ); // No tr
365 close(); 364 close();
366 return; 365 return;
367 } 366 }
368 367
369 // connected to client 368 // connected to client
370 if ( Connected == state ) 369 if ( Connected == state )
371 return; 370 return;
372 371