-rw-r--r-- | core/launcher/desktop.cpp | 4 | ||||
-rw-r--r-- | core/launcher/qcopbridge.cpp | 10 | ||||
-rw-r--r-- | core/launcher/transferserver.cpp | 10 |
3 files changed, 14 insertions, 10 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp index 43006f1..d5c16b3 100644 --- a/core/launcher/desktop.cpp +++ b/core/launcher/desktop.cpp @@ -91,98 +91,98 @@ bool Desktop::screenLocked() /* Priority is number of alerts that are needed to pop up alert. */ class DesktopPowerAlerter : public QMessageBox { public: DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) : QMessageBox( tr("Battery Status"), "Low Battery", QMessageBox::Critical, QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton, QMessageBox::NoButton, parent, name, FALSE ) { currentPriority = INT_MAX; alertCount = 0; } void alert( const QString &text, int priority ); void hideEvent( QHideEvent * ); private: int currentPriority; int alertCount; }; void DesktopPowerAlerter::alert( const QString &text, int priority ) { alertCount++; if ( alertCount < priority ) return; if ( priority > currentPriority ) return; currentPriority = priority; setText( text ); show(); } void DesktopPowerAlerter::hideEvent( QHideEvent *e ) { QMessageBox::hideEvent( e ); alertCount = 0; currentPriority = INT_MAX; } -DesktopApplication::DesktopApplication( int& argc, char **argv, Type t ) - : QPEApplication( argc, argv, t ) +DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) + : QPEApplication( argc, argv, appType ) { QTimer *t = new QTimer( this ); connect( t, SIGNAL(timeout()), this, SLOT(psTimeout()) ); t->start( 10000 ); ps = new PowerStatus; pa = new DesktopPowerAlerter( 0 ); channel = new QCopChannel( "QPE/Desktop", this ); connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); } DesktopApplication::~DesktopApplication() { delete ps; delete pa; } void DesktopApplication::receive( const QCString &msg, const QByteArray &data ) { QDataStream stream( data, IO_ReadOnly ); if (msg == "keyRegister(int key, QString channel, QString message)") { int k; QString c, m; stream >> k; stream >> c; stream >> m; qWarning("KeyRegisterRecieved: %i, %s, %s", k, (const char*)c, (const char *)m); keyRegisterList.append(QCopKeyRegister(k,c,m)); } else if (msg == "suspend()"){ emit power(); } } enum MemState { Unknown, VeryLow, Low, Normal } memstate=Unknown; #ifdef Q_WS_QWS bool DesktopApplication::qwsEventFilter( QWSEvent *e ) { qpedesktop->checkMemory(); diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp index c8af919..2d084fc 100644 --- a/core/launcher/qcopbridge.cpp +++ b/core/launcher/qcopbridge.cpp @@ -1,98 +1,102 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of 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 ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "qcopbridge.h" #include "transferserver.h" #include <qpe/qcopenvelope_qws.h> #include <qpe/qpeapplication.h> #include <qdir.h> #include <qfile.h> #include <qtextstream.h> #include <qdatastream.h> #include <qstringlist.h> #include <qfileinfo.h> #include <qregexp.h> #include <qcopchannel_qws.h> +// 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> #if defined(_OS_LINUX_) #include <shadow.h> #endif //#define INSECURE const int block_size = 51200; -QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent = 0, - const char* name = 0) +QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent, + const char* name ) : QServerSocket( port, 1, parent, name ), desktopChannel( 0 ), cardChannel( 0 ) { if ( !ok() ) qWarning( "Failed to bind to port %d", port ); else { 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 &)) ); } sendSync = FALSE; } QCopBridge::~QCopBridge() { delete desktopChannel; } void QCopBridge::newConnection( int socket ) { QCopBridgePI *pi = new QCopBridgePI( socket, this ); openConnections.append( pi ); connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) ); QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; if ( sendSync ) { pi ->startSync(); sendSync = FALSE; } } void QCopBridge::connectionClosed( QCopBridgePI *pi ) { openConnections.remove( pi ); if ( openConnections.count() == 0 ) { QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; } } void QCopBridge::closeOpenConnections() { QCopBridgePI *pi; for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) pi->close(); @@ -124,97 +128,97 @@ void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args 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 through 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 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 ); } QCopBridgePI *pi; for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { pi->sendDesktopMessage( sendCommand ); } } void QCopBridge::timerEvent( QTimerEvent * ) { sendSync = FALSE; killTimers(); } -QCopBridgePI::QCopBridgePI( int socket, QObject *parent = 0, const char* name = 0 ) +QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name ) : QSocket( parent, name ) { setSocket( socket ); peerport = peerPort(); peeraddress = peerAddress(); #ifndef INSECURE if ( !accessAuthorized(peeraddress) ) { state = Forbidden; startTimer( 0 ); } else #endif { state = Connected; sendSync = FALSE; connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); send( "220 Qtopia QCop bridge ready!" ); state = Wait_USER; // idle timer to close connections when not used anymore startTimer( 60000 ); connected = TRUE; } } QCopBridgePI::~QCopBridgePI() { } void QCopBridgePI::connectionClosed() { emit connectionClosed( this ); // qDebug( "Debug: Connection closed" ); delete this; } void QCopBridgePI::sendDesktopMessage( const QString &msg ) { QString str = "CALL QPE/Desktop " + msg; send ( str ); } diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp index 87a49eb..7294f9c 100644 --- a/core/launcher/transferserver.cpp +++ b/core/launcher/transferserver.cpp @@ -1,132 +1,132 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of 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 ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #define _XOPEN_SOURCE #include <pwd.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> #if defined(_OS_LINUX_) #include <shadow.h> #endif #include <qdir.h> #include <qfile.h> #include <qtextstream.h> #include <qdatastream.h> #include <qmessagebox.h> #include <qstringlist.h> #include <qfileinfo.h> #include <qregexp.h> //#include <qpe/qcopchannel_qws.h> -#include <qpe/qprocess.h> #include <qpe/process.h> #include <qpe/config.h> #include <qpe/qcopenvelope_qws.h> #include "transferserver.h" +#include "qprocess.h" const int block_size = 51200; -TransferServer::TransferServer( Q_UINT16 port, QObject *parent = 0, - const char* name = 0) +TransferServer::TransferServer( Q_UINT16 port, QObject *parent, + const char* name ) : QServerSocket( port, 1, parent, name ) { if ( !ok() ) qWarning( "Failed to bind to port %d", port ); } TransferServer::~TransferServer() { } void TransferServer::newConnection( int socket ) { (void) new ServerPI( socket, this ); } bool accessAuthorized(QHostAddress peeraddress) { Config cfg("Security"); cfg.setGroup("Sync"); uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100); uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); bool ok = (peeraddress.ip4Addr() & (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits))) == auth_peer; /* Allows denial-of-service attack. if ( !ok ) { QMessageBox::warning(0,tr("Security"), tr("<p>An attempt to access this device from %1 has been denied.") .arg(peeraddress.toString())); } */ return ok; } -ServerPI::ServerPI( int socket, QObject *parent = 0, const char* name = 0 ) +ServerPI::ServerPI( int socket, QObject *parent, const char* name ) : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) { state = Connected; setSocket( socket ); peerport = peerPort(); peeraddress = peerAddress(); #ifndef INSECURE if ( !accessAuthorized(peeraddress) ) { state = Forbidden; startTimer( 0 ); } else #endif { connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); passiv = FALSE; for( int i = 0; i < 4; i++ ) wait[i] = FALSE; send( "220 Qtopia transfer service ready!" ); state = Wait_USER; dtp = new ServerDTP( this ); connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); directory = QDir::currentDirPath(); static int p = 1024; while ( !serversocket || !serversocket->ok() ) { delete serversocket; serversocket = new ServerSocket( ++p, this ); } connect( serversocket, SIGNAL( newIncomming( int ) ), SLOT( newConnection( int ) ) ); } } ServerPI::~ServerPI() { @@ -807,97 +807,97 @@ void ServerPI::newConnection( int socket ) if ( backupRestoreGzip( waitfile, targets ) ) dtp->sendGzipFile( waitfile, targets ); else dtp->sendFile( waitfile ); dtp->setSocket( socket ); } else if ( wait[RetrieveFile] ) { qDebug("check retrieve file"); if ( backupRestoreGzip( waitfile ) ) dtp->retrieveGzipFile( waitfile ); else dtp->retrieveFile( waitfile ); dtp->setSocket( socket ); } else if ( wait[SendByteArray] ) { dtp->sendByteArray( waitarray ); dtp->setSocket( socket ); } else if ( wait[RetrieveByteArray] ) { qDebug("retrieve byte array"); dtp->retrieveByteArray(); dtp->setSocket( socket ); } else waitsocket = socket; for( int i = 0; i < 4; i++ ) wait[i] = FALSE; } QString ServerPI::absFilePath( const QString& file ) { if ( file.isEmpty() ) return file; QString filepath( file ); if ( file[0] != "/" ) filepath = directory.path() + "/" + file; return filepath; } void ServerPI::timerEvent( QTimerEvent * ) { connectionClosed(); } -ServerDTP::ServerDTP( QObject *parent = 0, const char* name = 0) +ServerDTP::ServerDTP( QObject *parent, const char* name ) : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), retrieveTargzProc( 0 ), gzipProc( 0 ) { connect( this, SIGNAL( connected() ), SLOT( connected() ) ); connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); gzipProc = new QProcess( this, "gzipProc" ); gzipProc->setCommunication( QProcess::Stdin | QProcess::Stdout ); createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); createTargzProc->setCommunication( QProcess::Stdout ); createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); QStringList args = "tar"; args += "-xv"; retrieveTargzProc = new QProcess( args, this, "retrieveTargzProc" ); retrieveTargzProc->setCommunication( QProcess::Stdin ); retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); connect( retrieveTargzProc, SIGNAL( processExited() ), SIGNAL( completed() ) ); connect( retrieveTargzProc, SIGNAL( processExited() ), SLOT( extractTarDone() ) ); } ServerDTP::~ServerDTP() { buf.close(); file.close(); createTargzProc->kill(); } void ServerDTP::extractTarDone() { qDebug("extract done"); QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); e << file.name(); } void ServerDTP::connected() { // send file mode switch ( mode ) { case SendFile : if ( !file.exists() || !file.open( IO_ReadOnly) ) { |