summaryrefslogtreecommitdiff
authorzecke <zecke>2005-03-02 19:23:54 (UTC)
committer zecke <zecke>2005-03-02 19:23:54 (UTC)
commitaf157881a6265b1ea9e74d61853c2d3d865a6080 (patch) (side-by-side diff)
tree6d10df4742bf4c53beefe7b67744dadce6393750
parent0a4dabaa72dda35694445345ebb4d9d80921a5a2 (diff)
downloadopie-af157881a6265b1ea9e74d61853c2d3d865a6080.zip
opie-af157881a6265b1ea9e74d61853c2d3d865a6080.tar.gz
opie-af157881a6265b1ea9e74d61853c2d3d865a6080.tar.bz2
Merge HEAD with QTOPIA_2_1_1 vendor branch
The new qcop tool can change the user and wait for repsonses on the channel it sent data
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/qcop/main.cpp84
-rw-r--r--core/apps/qcop/qcop.pro4
-rw-r--r--core/apps/qcop/qcopimpl.cpp10
-rw-r--r--core/apps/qcop/qcopimpl.h10
4 files changed, 18 insertions, 90 deletions
diff --git a/core/apps/qcop/main.cpp b/core/apps/qcop/main.cpp
index 9306cbf..0f5cb2c 100644
--- a/core/apps/qcop/main.cpp
+++ b/core/apps/qcop/main.cpp
@@ -1,83 +1,31 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2004 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
+**
+** This program is free software; you can redistribute it and/or modify it
+** under the terms of the GNU General Public License as published by the
+** Free Software Foundation; either version 2 of the License, or (at your
+** option) any later version.
+**
+** A copy of the GNU GPL license version 2 is included in this package as
+** LICENSE.GPL.
**
-** 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.
+** This program is distributed in the hope that it will be useful, but
+** WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+** See the GNU General Public License for more details.
**
** 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 <qpe/qcopenvelope_qws.h>
-
-#include <qapplication.h>
-#include <qtimer.h>
-
-#include <stdlib.h>
-#include <stdio.h>
-
-static void usage()
-{
- fprintf( stderr, "Usage: qcop channel command [parameters]\n" );
-}
-
-static void syntax( const QString &where, const QString &what )
-{
- fprintf( stderr, "Syntax error in %s: %s\n", where.latin1(), what.latin1() );
- exit(1);
-}
+#include "qcopimpl.h"
int main( int argc, char *argv[] )
{
- QApplication app( argc, argv );
-
- if ( argc < 3 ) {
- usage();
- exit(1);
- }
-
- QString channel = argv[1];
- QString command = argv[2];
- command.stripWhiteSpace();
-
- int paren = command.find( "(" );
- if ( paren <= 0 )
- syntax( "command", command );
-
- QString params = command.mid( paren + 1 );
- if ( params[params.length()-1] != ')' )
- syntax( "command", command );
-
- params.truncate( params.length()-1 );
- QCopEnvelope env(channel.latin1(), command.latin1());
-
- int argIdx = 3;
-
- QStringList paramList = QStringList::split( ",", params );
- QStringList::Iterator it;
- for ( it = paramList.begin(); it != paramList.end(); ++it ) {
- QString arg = argv[argIdx];
- if ( *it == "QString" ) {
- env << arg;
- } else if ( *it == "int" ) {
- env << arg.toInt();
- } else {
- syntax( "paramter type", *it );
- }
- argIdx++;
- }
-
- QTimer::singleShot( 0, &app, SLOT(quit()) );
- return app.exec();
+ return doqcopimpl(argc,argv);
}
-
diff --git a/core/apps/qcop/qcop.pro b/core/apps/qcop/qcop.pro
index 8cb1b55..6276bee 100644
--- a/core/apps/qcop/qcop.pro
+++ b/core/apps/qcop/qcop.pro
@@ -1,12 +1,12 @@
TEMPLATE = app
CONFIG = qt warn_on
DESTDIR = $(OPIEDIR)/bin
-HEADERS =
-SOURCES = main.cpp
+HEADERS = qcopimpl.h
+SOURCES = qcopimpl.cpp main.cpp
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe
INTERFACES =
TARGET = qcop
include( $(OPIEDIR)/include.pro )
diff --git a/core/apps/qcop/qcopimpl.cpp b/core/apps/qcop/qcopimpl.cpp
index c018aea..43863bb 100644
--- a/core/apps/qcop/qcopimpl.cpp
+++ b/core/apps/qcop/qcopimpl.cpp
@@ -1,220 +1,210 @@
/**********************************************************************
** Copyright (C) 2000-2005 Trolltech AS. All rights reserved.
**
** This file is part of the Qtopia Environment.
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
** Free Software Foundation; either version 2 of the License, or (at your
** option) any later version.
**
** A copy of the GNU GPL license version 2 is included in this package as
** LICENSE.GPL.
**
** This program is distributed in the hope that it will be useful, but
** WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU General Public License for more details.
**
-** In addition, as a special exception Trolltech gives permission to link
-** the code of this program with Qtopia applications copyrighted, developed
-** and distributed by Trolltech under the terms of the Qtopia Personal Use
-** License Agreement. You must comply with the GNU General Public License
-** in all respects for all of the code used other than the applications
-** licensed under the Qtopia Personal Use License Agreement. If you modify
-** this file, you may extend this exception to your version of the file,
-** but you are not obligated to do so. If you do not wish to do so, delete
-** this exception statement from your version.
-**
** 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 "qcopimpl.h"
#include <qtopia/timeconversion.h>
void doqcopusage()
{
fprintf( stderr, "Usage: qcop [-l username] channel command [parameters] [-w channel command [timeout]]\n" );
}
void doqcopsyntax( const QString &where, const QString &what )
{
fprintf( stderr, "Syntax error in %s: %s\n", where.latin1(), what.latin1() );
exit(1);
}
void disableqdebug( QtMsgType type, const char *msg )
{
// Ignore messages that are sent via qDebug.
Q_UNUSED( type );
Q_UNUSED( msg );
}
int doqcopimpl (int argc, char *argv[])
{
qInstallMsgHandler( disableqdebug );
if ( argc > 1 ) {
QString opt = argv[1];
if ( opt == "-l" ) {
if ( argc < 5 ) {
doqcopusage();
exit(1);
}
#ifndef Q_OS_WIN32
const char *username = argv[2];
struct passwd *pwd = getpwnam( username );
if ( !pwd ) {
fprintf( stderr, "Unknown user %s\n", username );
exit(1);
}
int uid = pwd->pw_uid;
int gid = pwd->pw_gid;
if ( initgroups( username, gid ) != 0 ) {
fprintf( stderr, "Could not chg group for user:%s\n", username );
exit(1);
}
if ( setuid( uid ) != 0 ) {
fprintf( stderr, "Could not run as user %s\n", username );
exit(1);
}
setenv( "LOGNAME", username, 1 );
#else
setenv("LOGNAME", argv[2], 1);
#endif
argc -= 2;
for ( int i = 1; i < argc; i++ ) {
argv[i] = argv[i+2];
}
}
}
if ( argc < 3 ) {
doqcopusage();
exit(1);
}
QApplication app( argc, argv );
QString channel = argv[1];
QString command = argv[2];
command.stripWhiteSpace();
int paren = command.find( "(" );
if ( paren <= 0 )
doqcopsyntax( "command", command );
QString params = command.mid( paren + 1 );
if ( params[(int)params.length()-1] != ')' )
doqcopsyntax( "command", command );
params.truncate( params.length()-1 );
#ifndef QT_NO_COP
int argIdx = 3;
{
QCopEnvelope env(channel.latin1(), command.latin1());
QStringList paramList = QStringList::split( ",", params );
QStringList::Iterator it;
for ( it = paramList.begin(); it != paramList.end(); ++it ) {
QString arg = argv[argIdx];
if ( *it == "QString" ) {
env << arg;
} else if ( *it == "int" ) {
env << arg.toInt();
} else if ( *it == "QDateTime") {
env << TimeConversion::fromISO8601(QCString(arg));
} else if ( *it == "bool") {
if (arg.lower() == "false")
env << (int)false;
else if (arg.lower() == "true")
env << (int)true;
else
doqcopsyntax( "parameter value for bool should be either 'true' or 'false'", arg );
} else {
doqcopsyntax( "parameter type", *it );
}
argIdx++;
}
// send env
}
// Check for a "-w" option, which indicates that we should
// wait for a QCop command before exiting.
if ( argIdx < argc && QString(argv[argIdx]) == "-w" ) {
if ( ( argIdx + 3 ) > argc ) {
doqcopusage();
exit(1);
}
channel = argv[argIdx + 1];
command = argv[argIdx + 2];
QCopWatcher *watcher = new QCopWatcher( &app, command );
QCopChannel *chan = new QCopChannel( QCString(channel), &app );
QObject::connect
( chan, SIGNAL(received(const QCString&,const QByteArray&)),
watcher, SLOT(received(const QCString&,const QByteArray&)) );
QObject::connect
( watcher, SIGNAL(done()), &app, SLOT(quit()) );
if ( ( argIdx + 3 ) < argc ) {
QTimer::singleShot( QString(argv[argIdx + 3]).toInt(),
watcher, SLOT(timeout()) );
}
return app.exec();
}
#endif
QTimer::singleShot( 0, &app, SLOT(quit()) );
return app.exec();
}
QCopWatcher::QCopWatcher( QObject *parent, const QString& msg )
: QObject( parent )
{
this->msg = msg;
}
QCopWatcher::~QCopWatcher()
{
}
void QCopWatcher::received( const QCString& msg, const QByteArray& data )
{
if ( msg != this->msg )
return;
QString command = msg;
QDataStream stream( data, IO_ReadOnly );
int paren = command.find( "(" );
if ( paren <= 0 )
doqcopsyntax( "wait-command", command );
QString params = command.mid( paren + 1 );
if ( params[(int)params.length()-1] != ')' )
doqcopsyntax( "wait-command", command );
params.truncate( params.length()-1 );
QStringList paramList = QStringList::split( ",", params );
QStringList::Iterator it;
for ( it = paramList.begin(); it != paramList.end(); ++it ) {
if ( *it == "QString" ) {
QString value;
stream >> value;
puts( value.latin1() );
} else if ( *it == "int" ) {
int value;
stream >> value;
printf( "%d\n", value );
diff --git a/core/apps/qcop/qcopimpl.h b/core/apps/qcop/qcopimpl.h
index dfda063..dc847f1 100644
--- a/core/apps/qcop/qcopimpl.h
+++ b/core/apps/qcop/qcopimpl.h
@@ -1,82 +1,72 @@
/**********************************************************************
** Copyright (C) 2000-2005 Trolltech AS. All rights reserved.
**
** This file is part of the Qtopia Environment.
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
** Free Software Foundation; either version 2 of the License, or (at your
** option) any later version.
**
** A copy of the GNU GPL license version 2 is included in this package as
** LICENSE.GPL.
**
** This program is distributed in the hope that it will be useful, but
** WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU General Public License for more details.
**
-** In addition, as a special exception Trolltech gives permission to link
-** the code of this program with Qtopia applications copyrighted, developed
-** and distributed by Trolltech under the terms of the Qtopia Personal Use
-** License Agreement. You must comply with the GNU General Public License
-** in all respects for all of the code used other than the applications
-** licensed under the Qtopia Personal Use License Agreement. If you modify
-** this file, you may extend this exception to your version of the file,
-** but you are not obligated to do so. If you do not wish to do so, delete
-** this exception statement from your version.
-**
** 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.
**
**********************************************************************/
#ifndef QCOPIMPL_H
#define QCOPIMPL_H
#ifdef QWS
#include <qtopia/qcopenvelope_qws.h>
#endif
#include <qtopia/qpeapplication.h>
#include <qstringlist.h>
#include <qdatastream.h>
#include <qtimer.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#ifndef Q_OS_WIN32
#include <pwd.h>
#include <unistd.h>
#include <grp.h>
#endif
// No tr() anywhere in this file
void doqcopusage();
void doqcopsyntax( const QString &where, const QString &what );
int doqcopimpl (int argc, char *argv[]);
class QCopWatcher : public QObject
{
Q_OBJECT
public:
QCopWatcher( QObject *parent, const QString& msg );
~QCopWatcher();
signals:
void done();
public slots:
void received( const QCString& msg, const QByteArray& data );
void timeout();
private:
QCString msg;
};
#endif