-rw-r--r-- | core/launcher/qcopbridge.cpp | 100 |
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,6 +1,6 @@ /********************************************************************** -** 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 @@ -22,6 +22,9 @@ #include "transferserver.h" +#ifdef QWS #include <qpe/qcopenvelope_qws.h> +#endif #include <qpe/qpeapplication.h> +#include <qpe/version.h> #include <qdir.h> @@ -32,11 +35,9 @@ #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> @@ -60,4 +61,5 @@ QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent, 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 &)), @@ -66,4 +68,5 @@ QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent, connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); +#endif } sendSync = FALSE; @@ -72,5 +75,7 @@ QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent, QCopBridge::~QCopBridge() { +#ifndef QT_NO_COP delete desktopChannel; +#endif } @@ -80,5 +85,7 @@ void QCopBridge::newConnection( int socket ) 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 ) { @@ -92,5 +99,7 @@ void QCopBridge::connectionClosed( QCopBridgePI *pi ) openConnections.remove( pi ); if ( openConnections.count() == 0 ) { +#ifndef QT_NO_COP QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; +#endif } } @@ -143,12 +152,30 @@ void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args 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("&"), "&" ); - 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( "&" ); + 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; } } @@ -183,5 +210,5 @@ QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name ) #ifndef INSECURE - if ( !accessAuthorized(peeraddress) ) { + if ( !SyncAuthentication::isAuthorized(peeraddress) ) { state = Forbidden; startTimer( 0 ); @@ -194,5 +221,10 @@ QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name ) 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; @@ -236,35 +268,4 @@ void QCopBridgePI::read() } -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 ) { @@ -297,5 +298,5 @@ void QCopBridgePI::process( const QString& message ) 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; @@ -309,6 +310,5 @@ void QCopBridgePI::process( const QString& message ) 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; @@ -390,4 +390,5 @@ void QCopBridgePI::process( const QString& message ) } +#ifndef QT_NO_COP if ( !QCopChannel::isRegistered( channel.latin1() ) ) { // send message back about it @@ -396,5 +397,7 @@ void QCopBridgePI::process( const QString& message ) return; } +#endif +#ifndef QT_NO_COP if ( paramList.count() ) QCopChannel::send( channel.latin1(), command.latin1(), buffer ); @@ -403,4 +406,5 @@ void QCopBridgePI::process( const QString& message ) send( "200 Command okay" ); +#endif } } |