summaryrefslogtreecommitdiff
path: root/core/launcher/qcopbridge.cpp
authorzecke <zecke>2003-08-28 14:40:33 (UTC)
committer zecke <zecke>2003-08-28 14:40:33 (UTC)
commitfcc9c16cbd679ebc459ff0ec6228bbdedbfdfe1d (patch) (side-by-side diff)
tree3a304196f52e12761cab01420a189be4369a9522 /core/launcher/qcopbridge.cpp
parent8aff9d2f2d079e4500b6bbbd9f410c16cee3f6a1 (diff)
downloadopie-fcc9c16cbd679ebc459ff0ec6228bbdedbfdfe1d.zip
opie-fcc9c16cbd679ebc459ff0ec6228bbdedbfdfe1d.tar.gz
opie-fcc9c16cbd679ebc459ff0ec6228bbdedbfdfe1d.tar.bz2
Compile fixes
Diffstat (limited to 'core/launcher/qcopbridge.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/qcopbridge.cpp222
1 files changed, 102 insertions, 120 deletions
diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp
index 6177a7c..f780235 100644
--- a/core/launcher/qcopbridge.cpp
+++ b/core/launcher/qcopbridge.cpp
@@ -21,35 +21,46 @@
#include "qcopbridge.h"
#include "transferserver.h"
-#include <qpe/qcopenvelope_qws.h>
-#include <qpe/qpeapplication.h>
-#include <qpe/version.h>
+#ifdef Q_WS_QWS
+#include <qtopia/qcopenvelope_qws.h>
+#endif
+#include <qtopia/qpeapplication.h>
+#include <qtopia/global.h>
+#include <qtopia/version.h>
#include <qdir.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qdatastream.h>
+#include <qcstring.h>
#include <qstringlist.h>
#include <qfileinfo.h>
#include <qregexp.h>
-#ifdef QWS
+#include <qtimer.h>
+#ifdef Q_WS_QWS
#include <qcopchannel_qws.h>
#endif
+#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE
+#endif
+#ifndef Q_OS_WIN32
#include <pwd.h>
-#include <sys/types.h>
#include <unistd.h>
+#include <sys/types.h>
+#endif
#if defined(_OS_LINUX_)
#include <shadow.h>
#endif
+#include "launcherglobal.h"
+
//#define INSECURE
const int block_size = 51200;
-QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent ,
+QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent,
const char* name )
: QServerSocket( port, 1, parent, name ),
desktopChannel( 0 ),
@@ -68,6 +79,7 @@ QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent ,
#endif
}
sendSync = FALSE;
+ openConnections.setAutoDelete( TRUE );
}
QCopBridge::~QCopBridge()
@@ -77,11 +89,28 @@ QCopBridge::~QCopBridge()
#endif
}
+void QCopBridge::authorizeConnections()
+{
+ QListIterator<QCopBridgePI> it(openConnections);
+ while ( it.current() ) {
+ if ( !it.current()->verifyAuthorised() ) {
+ disconnect ( it.current(), SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) );
+ openConnections.removeRef( it.current() );
+ } else
+ ++it;
+ }
+}
+
void QCopBridge::newConnection( int socket )
{
QCopBridgePI *pi = new QCopBridgePI( socket, this );
openConnections.append( pi );
- connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) );
+ connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) );
+
+ /* ### libqtopia merge FIXME */
+#if 0
+ QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend );
+#endif
#ifndef QT_NO_COP
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend;
#endif
@@ -92,12 +121,17 @@ void QCopBridge::newConnection( int socket )
}
}
-void QCopBridge::connectionClosed( QCopBridgePI *pi )
+void QCopBridge::closed( QCopBridgePI *pi )
{
- openConnections.remove( pi );
+ emit connectionClosed( pi->peerAddress() );
+ openConnections.removeRef( pi );
if ( openConnections.count() == 0 ) {
+ /* ### FIXME libqtopia merge */
+#if 0
+ QPEApplication::setTempScreenSaverMode( QPEApplication::Enable );
+#endif
#ifndef QT_NO_COP
- QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
+ QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
#endif
}
}
@@ -110,84 +144,18 @@ void QCopBridge::closeOpenConnections()
}
-void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args )
+void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data )
{
- command.stripWhiteSpace();
-
- int paren = command.find( "(" );
- if ( paren <= 0 ) {
- qDebug("DesktopMessage: bad qcop syntax");
- return;
- }
-
- QString params = command.mid( paren + 1 );
- if ( params[params.length()-1] != ')' ) {
- qDebug("DesktopMessage: bad qcop syntax");
- return;
- }
-
- params.truncate( params.length()-1 );
-
- QStringList paramList = QStringList::split( ",", params );
- QString data;
- if ( paramList.count() ) {
- QDataStream stream( args, IO_ReadOnly );
- for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
- QString str;
- if ( *it == "QString" ) {
- stream >> str;
- } else if ( *it == "QCString" ) {
- QCString cstr;
- stream >> cstr;
- str = QString::fromLocal8Bit( cstr );
- } else if ( *it == "int" ) {
- int i;
- stream >> i;
- str = QString::number( i );
- } else if ( *it == "bool" ) {
- int i;
- stream >> i;
- str = QString::number( i );
- } else {
- qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() );
- return;
- }
- QString estr;
- for (int i=0; i<(int)str.length(); i++) {
- QChar ch = str[i];
- if ( ch.row() )
- goto quick;
- switch (ch.cell()) {
- case '&':
- estr.append( "&amp;" );
- break;
- case ' ':
- estr.append( "&0x20;" );
- break;
- case '\n':
- estr.append( "&0x0d;" );
- break;
- case '\r':
- estr.append( "&0x0a;" );
- break;
- default: quick:
- estr.append(ch);
- }
- }
- data += " " + estr;
- }
- }
- QString sendCommand = QString(command.data()) + data;
- // send the command to all open connections
if ( command == "startSync()" ) {
// we need to buffer it a bit
sendSync = TRUE;
startTimer( 20000 );
}
+ // send the command to all open connections
QCopBridgePI *pi;
for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) {
- pi->sendDesktopMessage( sendCommand );
+ pi->sendDesktopMessage( command, data );
}
}
@@ -198,7 +166,7 @@ void QCopBridge::timerEvent( QTimerEvent * )
}
-QCopBridgePI::QCopBridgePI( int socket, QObject *parent , const char* name )
+QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name )
: QSocket( parent, name )
{
setSocket( socket );
@@ -209,51 +177,72 @@ QCopBridgePI::QCopBridgePI( int socket, QObject *parent , const char* name )
#ifndef INSECURE
if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
state = Forbidden;
- startTimer( 0 );
+ close();
} else
-#endif
+#endif
{
state = Connected;
- sendSync = FALSE;
connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
- connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
-
QString intro="220 Qtopia ";
intro += QPE_VERSION; intro += ";";
- intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";";
+ intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";"; // No tr
intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";";
intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";";
send( intro );
state = Wait_USER;
-
- // idle timer to close connections when not used anymore
- startTimer( 60000 );
- connected = TRUE;
}
+ sendSync = FALSE;
+ connect( this, SIGNAL( connectionClosed() ), SLOT( myConnectionClosed() ) );
+
+ // idle timer to close connections when not used anymore
+ timer = new QTimer(this);
+ connect( timer, SIGNAL(timeout()), this, SLOT(myConnectionClosed()) );
+ timer->start( 300000, TRUE );
}
QCopBridgePI::~QCopBridgePI()
{
+}
+bool QCopBridgePI::verifyAuthorised()
+{
+ if ( !SyncAuthentication::isAuthorized(peerAddress()) ) {
+ state = Forbidden;
+ return FALSE;
+ }
+ return TRUE;
}
-void QCopBridgePI::connectionClosed()
+void QCopBridgePI::myConnectionClosed()
{
emit connectionClosed( this );
- // qDebug( "Debug: Connection closed" );
- delete this;
}
void QCopBridgePI::sendDesktopMessage( const QString &msg )
{
- QString str = "CALL QPE/Desktop " + msg;
+ QString str = "CALL QPE/Desktop " + msg; // No tr
send ( str );
}
+void QCopBridgePI::sendDesktopMessage( const QCString &msg, const QByteArray& data )
+{
+ if ( !isOpen() ) // eg. Forbidden
+ return;
+ const char hdr[]="CALLB QPE/Desktop ";
+ writeBlock(hdr,sizeof(hdr)-1);
+ writeBlock(msg,msg.length());
+ writeBlock(" ",1);
+ QByteArray b64 = Opie::Global::encodeBase64(data);
+ writeBlock(b64.data(),b64.size());
+ writeBlock("\r\n",2);
+}
+
void QCopBridgePI::send( const QString& msg )
{
+ if ( !isOpen() ) // eg. Forbidden
+ return;
QTextStream os( this );
os << msg << endl;
//qDebug( "sending qcop message: %s", msg.latin1() );
@@ -261,8 +250,10 @@ void QCopBridgePI::send( const QString& msg )
void QCopBridgePI::read()
{
- while ( canReadLine() )
+ while ( canReadLine() ) {
+ timer->start( 300000, TRUE );
process( readLine().stripWhiteSpace() );
+ }
}
void QCopBridgePI::process( const QString& message )
@@ -283,8 +274,8 @@ void QCopBridgePI::process( const QString& message )
// we always respond to QUIT, regardless of state
if ( cmd == "QUIT" ) {
- send( "211 Have a nice day!" );
- delete this;
+ send( "211 Have a nice day!" ); // No tr
+ close();
return;
}
@@ -296,10 +287,10 @@ void QCopBridgePI::process( const QString& message )
if ( Wait_USER == state ) {
if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
- send( "530 Please login with USER and PASS" );
+ send( "530 Please login with USER and PASS" ); // No tr
return;
}
- send( "331 User name ok, need password" );
+ send( "331 User name ok, need password" ); // No tr
state = Wait_PASS;
return;
}
@@ -308,10 +299,10 @@ void QCopBridgePI::process( const QString& message )
if ( Wait_PASS == state ) {
if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
- send( "530 Please login with USER and PASS" );
+ send( "530 Please login with USER and PASS" ); // No tr
return;
}
- send( "230 User logged in, proceed" );
+ send( "230 User logged in, proceed" ); // No tr
state = Ready;
if ( sendSync ) {
sendDesktopMessage( "startSync()" );
@@ -322,8 +313,7 @@ void QCopBridgePI::process( const QString& message )
// noop (NOOP)
else if ( cmd == "NOOP" ) {
- connected = TRUE;
- send( "200 Command okay" );
+ send( "200 Command okay" ); // No tr
}
// call (CALL)
@@ -332,7 +322,7 @@ void QCopBridgePI::process( const QString& message )
// example: call QPE/System execute(QString) addressbook
if ( msg.count() < 3 ) {
- send( "500 Syntax error, command unrecognized" );
+ send( "500 Syntax error, command unrecognized" ); // No tr
}
else {
@@ -343,13 +333,13 @@ void QCopBridgePI::process( const QString& message )
int paren = command.find( "(" );
if ( paren <= 0 ) {
- send( "500 Syntax error, command unrecognized" );
+ send( "500 Syntax error, command unrecognized" ); // No tr
return;
}
QString params = command.mid( paren + 1 );
- if ( params[params.length()-1] != ')' ) {
- send( "500 Syntax error, command unrecognized" );
+ if ( params[(int)params.length()-1] != ')' ) {
+ send( "500 Syntax error, command unrecognized" ); // No tr
return;
}
@@ -361,7 +351,7 @@ void QCopBridgePI::process( const QString& message )
QStringList paramList = QStringList::split( ",", params );
if ( paramList.count() > msg.count() - 3 ) {
- send( "500 Syntax error, command unrecognized" );
+ send( "500 Syntax error, command unrecognized" ); // No tr
return;
}
@@ -381,7 +371,7 @@ void QCopBridgePI::process( const QString& message )
else if ( *it == "bool" )
ds << arg.toInt();
else {
- send( "500 Syntax error, command unrecognized" );
+ send( "500 Syntax error, command unrecognized" ); // No tr
return;
}
msgId++;
@@ -395,28 +385,20 @@ void QCopBridgePI::process( const QString& message )
return;
}
#endif
-
+
#ifndef QT_NO_COP
if ( paramList.count() )
QCopChannel::send( channel.latin1(), command.latin1(), buffer );
else
QCopChannel::send( channel.latin1(), command.latin1() );
- send( "200 Command okay" );
+ send( "200 Command okay" ); // No tr
#endif
}
}
// not implemented
else
- send( "502 Command not implemented" );
+ send( "502 Command not implemented" ); // No tr
}
-
-void QCopBridgePI::timerEvent( QTimerEvent * )
-{
- if ( connected )
- connected = FALSE;
- else
- connectionClosed();
-}