summaryrefslogtreecommitdiff
path: root/core/launcher/qcopbridge.cpp
Side-by-side diff
Diffstat (limited to 'core/launcher/qcopbridge.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/launcher/qcopbridge.cpp100
1 files changed, 52 insertions, 48 deletions
diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp
index 2d084fc..85993ee 100644
--- a/core/launcher/qcopbridge.cpp
+++ b/core/launcher/qcopbridge.cpp
@@ -1,8 +1,8 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
@@ -20,25 +20,26 @@
#include "qcopbridge.h"
#include "transferserver.h"
+#ifdef QWS
#include <qpe/qcopenvelope_qws.h>
+#endif
#include <qpe/qpeapplication.h>
+#include <qpe/version.h>
#include <qdir.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qdatastream.h>
#include <qstringlist.h>
#include <qfileinfo.h>
#include <qregexp.h>
+#ifdef QWS
#include <qcopchannel_qws.h>
+#endif
-// actually this is wrong, _XOPEN_SOURCE should get defined on the commandline
-// and it should have a proper value assigned. (Simon)
-#if !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE
-#endif
#include <pwd.h>
#include <sys/types.h>
#include <unistd.h>
@@ -58,29 +59,35 @@ QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent,
{
if ( !ok() )
qWarning( "Failed to bind to port %d", port );
else {
+#ifndef QT_NO_COP
desktopChannel = new QCopChannel( "QPE/Desktop", this );
connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)),
this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
cardChannel = new QCopChannel( "QPE/Card", this );
connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)),
this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
+#endif
}
sendSync = FALSE;
}
QCopBridge::~QCopBridge()
{
+#ifndef QT_NO_COP
delete desktopChannel;
+#endif
}
void QCopBridge::newConnection( int socket )
{
QCopBridgePI *pi = new QCopBridgePI( socket, this );
openConnections.append( pi );
connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) );
+#ifndef QT_NO_COP
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend;
+#endif
if ( sendSync ) {
pi ->startSync();
sendSync = FALSE;
@@ -90,9 +97,11 @@ void QCopBridge::newConnection( int socket )
void QCopBridge::connectionClosed( QCopBridgePI *pi )
{
openConnections.remove( pi );
if ( openConnections.count() == 0 ) {
+#ifndef QT_NO_COP
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
+#endif
}
}
void QCopBridge::closeOpenConnections()
@@ -141,16 +150,34 @@ void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args
int i;
stream >> i;
str = QString::number( i );
} else {
- qDebug(" cannot route the argument type %s through the qcop bridge", (*it).latin1() );
+ qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() );
return;
}
- str.replace( QRegExp("&"), "&amp;" );
- str.replace( QRegExp(" "), "&0x20;" );
- str.replace( QRegExp("\n"), "&0x0d;" );
- str.replace( QRegExp("\r"), "&0x0a;" );
- data += " " + str;
+ 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
@@ -181,9 +208,9 @@ QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name )
peerport = peerPort();
peeraddress = peerAddress();
#ifndef INSECURE
- if ( !accessAuthorized(peeraddress) ) {
+ if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
state = Forbidden;
startTimer( 0 );
} else
#endif
@@ -192,9 +219,14 @@ QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name )
sendSync = FALSE;
connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
- send( "220 Qtopia QCop bridge ready!" );
+ QString intro="220 Qtopia ";
+ intro += QPE_VERSION; intro += ";";
+ intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";";
+ 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 );
@@ -234,39 +266,8 @@ void QCopBridgePI::read()
while ( canReadLine() )
process( readLine().stripWhiteSpace() );
}
-bool QCopBridgePI::checkUser( const QString& user )
-{
- if ( user.isEmpty() ) return FALSE;
-
- struct passwd *pw;
- pw = getpwuid( geteuid() );
- QString euser = QString::fromLocal8Bit( pw->pw_name );
- return user == euser;
-}
-
-bool QCopBridgePI::checkPassword( const QString& password )
-{
- // ### HACK for testing on local host
- return true;
-
- /*
- struct passwd *pw = 0;
- struct spwd *spw = 0;
-
- pw = getpwuid( geteuid() );
- spw = getspnam( pw->pw_name );
-
- QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
- if ( cpwd == "x" && spw )
- cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
-
- QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
- return cpwd == cpassword;
-*/
-}
-
void QCopBridgePI::process( const QString& message )
{
//qDebug( "Command: %s", message.latin1() );
@@ -295,9 +296,9 @@ void QCopBridgePI::process( const QString& message )
// waiting for user name
if ( Wait_USER == state ) {
- if ( cmd != "USER" || msg.count() < 2 || !checkUser( arg ) ) {
+ if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
send( "530 Please login with USER and PASS" );
return;
}
send( "331 User name ok, need password" );
@@ -307,10 +308,9 @@ void QCopBridgePI::process( const QString& message )
// waiting for password
if ( Wait_PASS == state ) {
- if ( cmd != "PASS" || !checkPassword( arg ) ) {
- //if ( cmd != "PASS" || msg.count() < 2 || !checkPassword( arg ) ) {
+ if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
send( "530 Please login with USER and PASS" );
return;
}
send( "230 User logged in, proceed" );
@@ -388,21 +388,25 @@ void QCopBridgePI::process( const QString& message )
}
msgId++;
}
+#ifndef QT_NO_COP
if ( !QCopChannel::isRegistered( channel.latin1() ) ) {
// send message back about it
QString answer = "599 ChannelNotRegistered " + channel;
send( answer );
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" );
+#endif
}
}
// not implemented
else