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.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp
index 24f471d..53efba4 100644
--- a/core/launcher/qcopbridge.cpp
+++ b/core/launcher/qcopbridge.cpp
@@ -1,202 +1,202 @@
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#include <opie2/oglobal.h> 24#include <opie2/oglobal.h>
25 25
26#ifdef Q_WS_QWS 26#ifdef Q_WS_QWS
27#include <qtopia/qcopenvelope_qws.h> 27#include <qtopia/qcopenvelope_qws.h>
28#endif 28#endif
29#include <qtopia/qpeapplication.h> 29#include <qtopia/qpeapplication.h>
30 30
31#include <qtopia/version.h> 31#include <qtopia/version.h>
32 32
33#include <qtextstream.h> 33#include <qtextstream.h>
34#include <qtimer.h> 34#include <qtimer.h>
35#ifdef Q_WS_QWS 35#ifdef Q_WS_QWS
36#include <qcopchannel_qws.h> 36#include <qcopchannel_qws.h>
37#endif 37#endif
38 38
39#ifndef _XOPEN_SOURCE 39#ifndef _XOPEN_SOURCE
40#define _XOPEN_SOURCE 40#define _XOPEN_SOURCE
41#endif 41#endif
42#ifndef Q_OS_WIN32 42#ifndef Q_OS_WIN32
43#include <pwd.h> 43#include <pwd.h>
44#include <unistd.h> 44#include <unistd.h>
45#include <sys/types.h> 45#include <sys/types.h>
46#endif 46#endif
47 47
48#if defined(_OS_LINUX_) 48#if defined(_OS_LINUX_)
49#include <shadow.h> 49#include <shadow.h>
50#endif 50#endif
51 51
52 52
53//#define INSECURE 53//#define INSECURE
54 54
55const int block_size = 51200; 55const int block_size = 51200;
56 56
57QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent, 57QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent,
58 const char* name ) 58 const char* name )
59 : QServerSocket( port, 1, parent, name ), 59 : QServerSocket( port, 1, parent, name ),
60 desktopChannel( 0 ), 60 desktopChannel( 0 ),
61 cardChannel( 0 ) 61 cardChannel( 0 )
62{ 62{
63 if ( !ok() ) 63 if ( !ok() )
64 qWarning( "Failed to bind to port %d", port ); 64 qWarning( "Failed to bind to port %d", port );
65 else { 65 else {
66#ifndef QT_NO_COP 66#ifndef QT_NO_COP
67 desktopChannel = new QCopChannel( "QPE/Desktop", this ); 67 desktopChannel = new QCopChannel( "QPE/Desktop", this );
68 connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)), 68 connect( desktopChannel, SIGNAL(received(const QCString&,const QByteArray&)),
69 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 69 this, SLOT(desktopMessage(const QCString&,const QByteArray&)) );
70 cardChannel = new QCopChannel( "QPE/Card", this ); 70 cardChannel = new QCopChannel( "QPE/Card", this );
71 connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), 71 connect( cardChannel, SIGNAL(received(const QCString&,const QByteArray&)),
72 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 72 this, SLOT(desktopMessage(const QCString&,const QByteArray&)) );
73#endif 73#endif
74 } 74 }
75 sendSync = FALSE; 75 sendSync = FALSE;
76 openConnections.setAutoDelete( TRUE ); 76 openConnections.setAutoDelete( TRUE );
77 authorizeConnections(); 77 authorizeConnections();
78} 78}
79 79
80QCopBridge::~QCopBridge() 80QCopBridge::~QCopBridge()
81{ 81{
82#ifndef QT_NO_COP 82#ifndef QT_NO_COP
83 delete desktopChannel; 83 delete desktopChannel;
84#endif 84#endif
85} 85}
86 86
87void QCopBridge::authorizeConnections() 87void QCopBridge::authorizeConnections()
88{ 88{
89 Config cfg("Security"); 89 Config cfg("Security");
90 cfg.setGroup("SyncMode"); 90 cfg.setGroup("SyncMode");
91 m_mode = Mode(cfg.readNumEntry("Mode", Sharp )); 91 m_mode = Mode(cfg.readNumEntry("Mode", Sharp ));
92 QListIterator<QCopBridgePI> it(openConnections); 92 QListIterator<QCopBridgePI> it(openConnections);
93 while ( it.current() ) { 93 while ( it.current() ) {
94 if ( !it.current()->verifyAuthorised() ) { 94 if ( !it.current()->verifyAuthorised() ) {
95 disconnect ( it.current(), SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) ); 95 disconnect ( it.current(), SIGNAL( connectionClosed(QCopBridgePI*) ), this, SLOT( closed(QCopBridgePI*) ) );
96 openConnections.removeRef( it.current() ); 96 openConnections.removeRef( it.current() );
97 } else 97 } else
98 ++it; 98 ++it;
99 } 99 }
100} 100}
101 101
102void QCopBridge::newConnection( int socket ) 102void QCopBridge::newConnection( int socket )
103{ 103{
104 QCopBridgePI *pi = new QCopBridgePI( socket, this ); 104 QCopBridgePI *pi = new QCopBridgePI( socket, this );
105 openConnections.append( pi ); 105 openConnections.append( pi );
106 connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) ); 106 connect ( pi, SIGNAL( connectionClosed(QCopBridgePI*) ), this, SLOT( closed(QCopBridgePI*) ) );
107 107
108 /* ### libqtopia merge FIXME */ 108 /* ### libqtopia merge FIXME */
109#if 0 109#if 0
110 QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend ); 110 QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend );
111#endif 111#endif
112#ifndef QT_NO_COP 112#ifndef QT_NO_COP
113 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; 113 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend;
114#endif 114#endif
115 115
116 if ( sendSync ) { 116 if ( sendSync ) {
117 pi ->startSync(); 117 pi ->startSync();
118 sendSync = FALSE; 118 sendSync = FALSE;
119 } 119 }
120} 120}
121 121
122void QCopBridge::closed( QCopBridgePI *pi ) 122void QCopBridge::closed( QCopBridgePI *pi )
123{ 123{
124 emit connectionClosed( pi->peerAddress() ); 124 emit connectionClosed( pi->peerAddress() );
125 openConnections.removeRef( pi ); 125 openConnections.removeRef( pi );
126 if ( openConnections.count() == 0 ) { 126 if ( openConnections.count() == 0 ) {
127 /* ### FIXME libqtopia merge */ 127 /* ### FIXME libqtopia merge */
128#if 0 128#if 0
129 QPEApplication::setTempScreenSaverMode( QPEApplication::Enable ); 129 QPEApplication::setTempScreenSaverMode( QPEApplication::Enable );
130#endif 130#endif
131#ifndef QT_NO_COP 131#ifndef QT_NO_COP
132 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 132 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
133#endif 133#endif
134 } 134 }
135} 135}
136 136
137void QCopBridge::closeOpenConnections() 137void QCopBridge::closeOpenConnections()
138{ 138{
139 QCopBridgePI *pi; 139 QCopBridgePI *pi;
140 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) 140 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() )
141 pi->close(); 141 pi->close();
142} 142}
143 143
144 144
145void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data ) 145void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data )
146{ 146{
147 if ( command == "startSync()" ) { 147 if ( command == "startSync()" ) {
148 // we need to buffer it a bit 148 // we need to buffer it a bit
149 sendSync = TRUE; 149 sendSync = TRUE;
150 startTimer( 20000 ); 150 startTimer( 20000 );
151 } 151 }
152 152
153 if ( m_mode & Qtopia1_7 ) { 153 if ( m_mode & Qtopia1_7 ) {
154 // send the command to all open connections 154 // send the command to all open connections
155 QCopBridgePI *pi; 155 QCopBridgePI *pi;
156 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { 156 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) {
157 pi->sendDesktopMessage( command, data ); 157 pi->sendDesktopMessage( command, data );
158 } 158 }
159 } 159 }
160 if ( ( m_mode & Sharp ) || (m_mode & IntelliSync) ) 160 if ( ( m_mode & Sharp ) || (m_mode & IntelliSync) )
161 sendDesktopMessageOld( command, data ); 161 sendDesktopMessageOld( command, data );
162} 162}
163 163
164#ifndef OPIE_NO_OLD_SYNC_CODE 164#ifndef OPIE_NO_OLD_SYNC_CODE
165/* 165/*
166 * Old compat mode 166 * Old compat mode
167 */ 167 */
168void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) { 168void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) {
169 command.stripWhiteSpace(); 169 command.stripWhiteSpace();
170 170
171 int paren = command.find( "(" ); 171 int paren = command.find( "(" );
172 if ( paren <= 0 ) { 172 if ( paren <= 0 ) {
173 qDebug("DesktopMessage: bad qcop syntax"); 173 qDebug("DesktopMessage: bad qcop syntax");
174 return; 174 return;
175 } 175 }
176 176
177 QString params = command.mid( paren + 1 ); 177 QString params = command.mid( paren + 1 );
178 if ( params[params.length()-1] != ')' ) { 178 if ( params[params.length()-1] != ')' ) {
179 qDebug("DesktopMessage: bad qcop syntax"); 179 qDebug("DesktopMessage: bad qcop syntax");
180 return; 180 return;
181 } 181 }
182 182
183 params.truncate( params.length()-1 ); 183 params.truncate( params.length()-1 );
184 184
185 QStringList paramList = QStringList::split( ",", params ); 185 QStringList paramList = QStringList::split( ",", params );
186 QString data; 186 QString data;
187 if ( paramList.count() ) { 187 if ( paramList.count() ) {
188 QDataStream stream( args, IO_ReadOnly ); 188 QDataStream stream( args, IO_ReadOnly );
189 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { 189 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
190 QString str; 190 QString str;
191 if ( *it == "QString" ) { 191 if ( *it == "QString" ) {
192 stream >> str; 192 stream >> str;
193 } else if ( *it == "QCString" ) { 193 } else if ( *it == "QCString" ) {
194 QCString cstr; 194 QCString cstr;
195 stream >> cstr; 195 stream >> cstr;
196 str = QString::fromLocal8Bit( cstr ); 196 str = QString::fromLocal8Bit( cstr );
197 } else if ( *it == "int" ) { 197 } else if ( *it == "int" ) {
198 int i; 198 int i;
199 stream >> i; 199 stream >> i;
200 str = QString::number( i ); 200 str = QString::number( i );
201 } else if ( *it == "bool" ) { 201 } else if ( *it == "bool" ) {
202 int i; 202 int i;