Warning, /sdk/kompare/tests/cvsdiff/contextm.diff is written in an unsupported language. File is not indexed.
0001 Index: client/dcop.cpp
0002 ===================================================================
0003 RCS file: /home/kde/kdelibs/dcop/client/dcop.cpp,v
0004 retrieving revision 1.26
0005 diff -c -r1.26 dcop.cpp
0006 *** client/dcop.cpp 2001/10/31 01:17:39 1.26
0007 --- client/dcop.cpp 2002/01/16 18:06:24
0008 ***************
0009 *** 20,38 ****
0010
0011 ******************************************************************/
0012
0013 ! #include <qvariant.h>
0014 #include <qcolor.h>
0015 ! #include "../kdatastream.h"
0016 #include "../dcopclient.h"
0017 #include "../dcopref.h"
0018 ! #include <stdlib.h>
0019 ! #include <stdio.h>
0020 ! #include <ctype.h>
0021
0022 #include "marshall.cpp"
0023
0024 static DCOPClient* dcop = 0;
0025
0026 bool startsWith(const QCString &id, const char *str, int n)
0027 {
0028 return !n || (strncmp(id.data(), str, n) == 0);
0029 --- 20,66 ----
0030
0031 ******************************************************************/
0032
0033 ! #include <ctype.h>
0034 ! #include <stdio.h>
0035 ! #include <stdlib.h>
0036 !
0037 #include <qcolor.h>
0038 ! #include <qdir.h>
0039 ! #include <qfile.h>
0040 ! #include <qfileinfo.h>
0041 ! #include <qmap.h>
0042 ! #include <qstringlist.h>
0043 ! #include <qtextstream.h>
0044 ! #include <qvariant.h>
0045 !
0046 ! // putenv() is not available on all platforms, so make sure the emulation
0047 ! // wrapper is available in those cases by loading config.h!
0048 ! #include <config.h>
0049 !
0050 #include "../dcopclient.h"
0051 #include "../dcopref.h"
0052 ! #include "../kdatastream.h"
0053
0054 #include "marshall.cpp"
0055
0056 + typedef QMap<QString, QString> UserList;
0057 +
0058 static DCOPClient* dcop = 0;
0059
0060 + static QTextStream cout( stdout, IO_WriteOnly );
0061 + static QTextStream cerr( stderr, IO_WriteOnly );
0062 +
0063 + /**
0064 + * Session to send call to
0065 + * DefaultSession - current session. Current KDE session when called without
0066 + * --user or --all-users option. Otherwise this value ignores
0067 + * all users with more than one active session.
0068 + * AllSessions - Send to all sessions found. requires --user or --all-users.
0069 + * QuerySessions - Don't call DCOP, return a list of available sessions.
0070 + * CustomSession - Use the specified session
0071 + */
0072 + enum Session { DefaultSession = 0, AllSessions, QuerySessions, CustomSession };
0073 +
0074 bool startsWith(const QCString &id, const char *str, int n)
0075 {
0076 return !n || (strncmp(id.data(), str, n) == 0);
0077 ***************
0078 *** 118,126 ****
0079 }
0080 }
0081
0082 ! void callFunction( const char* app, const char* obj, const char* func, int argc, char** args )
0083 {
0084 -
0085 QString f = func; // Qt is better with unicode strings, so use one.
0086 int left = f.find( '(' );
0087 int right = f.find( ')' );
0088 --- 146,153 ----
0089 }
0090 }
0091
0092 ! void callFunction( const char* app, const char* obj, const char* func, const QCStringList args )
0093 {
0094 QString f = func; // Qt is better with unicode strings, so use one.
0095 int left = f.find( '(' );
0096 int right = f.find( ')' );
0097 ***************
0098 *** 136,142 ****
0099 bool ok = false;
0100 QCStringList funcs = dcop->remoteFunctions( app, obj, &ok );
0101 QCString realfunc;
0102 ! if ( !ok && argc == 0 )
0103 goto doit;
0104 if ( !ok )
0105 {
0106 --- 163,169 ----
0107 bool ok = false;
0108 QCStringList funcs = dcop->remoteFunctions( app, obj, &ok );
0109 QCString realfunc;
0110 ! if ( !ok && args.isEmpty() )
0111 goto doit;
0112 if ( !ok )
0113 {
0114 ***************
0115 *** 153,167 ****
0116
0117 if ( l > 0 && (*it).mid( s, l - s ) == func ) {
0118 realfunc = (*it).mid( s );
0119 ! int a = (*it).contains(',');
0120 ! if ( ( a == 0 && argc == 0) || ( a > 0 && a + 1 == argc ) )
0121 break;
0122 }
0123 }
0124 if ( realfunc.isEmpty() )
0125 {
0126 qWarning("no such function");
0127 ! exit(1);
0128 }
0129 f = realfunc;
0130 left = f.find( '(' );
0131 --- 180,195 ----
0132
0133 if ( l > 0 && (*it).mid( s, l - s ) == func ) {
0134 realfunc = (*it).mid( s );
0135 ! uint a = (*it).contains(',');
0136 ! if ( ( a == 0 && args.isEmpty() ) || ( a > 0 && a + 1 == args.count() ) )
0137 break;
0138 }
0139 }
0140 if ( realfunc.isEmpty() )
0141 {
0142 qWarning("no such function");
0143 ! // exit(1);
0144 ! return;
0145 }
0146 f = realfunc;
0147 left = f.find( '(' );
0148 ***************
0149 *** 243,253 ****
0150 QCString replyType;
0151 QDataStream arg(data, IO_WriteOnly);
0152
0153 ! int i = 0;
0154 ! for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) {
0155 ! marshall(arg, argc, args, i, *it);
0156 ! }
0157 ! if ( i != argc ) {
0158 qWarning( "arguments do not match" );
0159 exit(1);
0160 }
0161 --- 271,282 ----
0162 QCString replyType;
0163 QDataStream arg(data, IO_WriteOnly);
0164
0165 ! uint i = 0;
0166 ! for( QStringList::Iterator it = types.begin(); it != types.end(); ++it )
0167 ! marshall( arg, args, i, *it );
0168 !
0169 ! if ( i != args.count() )
0170 ! {
0171 qWarning( "arguments do not match" );
0172 exit(1);
0173 }
0174 ***************
0175 *** 265,343 ****
0176 }
0177 }
0178 }
0179 -
0180
0181
0182 ! int main( int argc, char** argv )
0183 {
0184
0185 ! if ( argc > 1 && argv[1][0] == '-' ) {
0186 ! fprintf( stderr, "Usage: dcop [ application [object [function [arg1] [arg2] [arg3] ... ] ] ] \n" );
0187 ! exit(0);
0188 }
0189
0190 ! DCOPClient client;
0191 ! client.attach();
0192 ! dcop = &client;
0193
0194 QCString app;
0195 QCString objid;
0196 QCString function;
0197 ! char **args = 0;
0198 ! if ((argc > 1) && (strncmp(argv[1], "DCOPRef(", 8)) == 0)
0199 {
0200 ! char *delim = strchr(argv[1], ',');
0201 ! if (!delim)
0202 ! {
0203 ! fprintf(stderr, "Error: '%s' is not a valid DCOP reference.\n", argv[1]);
0204 ! return 1;
0205 ! }
0206 ! *delim = 0;
0207 ! app = argv[1] + 8;
0208 ! delim++;
0209 ! delim[strlen(delim)-1] = 0;
0210 ! objid = delim;
0211 ! if (argc > 2)
0212 ! function = argv[2];
0213 ! if (argc > 3)
0214 ! args = &argv[3];
0215 ! argc++;
0216 }
0217 else
0218 {
0219 ! if (argc > 1)
0220 ! app = argv[1];
0221 ! if (argc > 2)
0222 ! objid = argv[2];
0223 ! if (argc > 3)
0224 ! function = argv[3];
0225 ! if (argc > 4)
0226 ! args = &argv[4];
0227 ! }
0228 !
0229 ! switch ( argc ) {
0230 ! case 0:
0231 ! case 1:
0232 ! queryApplications("");
0233 ! break;
0234 ! case 2:
0235 ! if (endsWith(app, '*'))
0236 ! queryApplications(app);
0237 ! else
0238 ! queryObjects( app, "" );
0239 ! break;
0240 ! case 3:
0241 ! if (endsWith(objid, '*'))
0242 ! queryObjects(app, objid);
0243 ! else
0244 ! queryFunctions( app, objid );
0245 ! break;
0246 ! case 4:
0247 ! default:
0248 ! callFunction( app, objid, function, argc - 4, args );
0249 ! break;
0250
0251 }
0252
0253 return 0;
0254 }
0255 --- 294,773 ----
0256 }
0257 }
0258 }
0259
0260 + /**
0261 + * Show command-line help and exit
0262 + */
0263 + void showHelp( int exitCode = 0 )
0264 + {
0265 + cout << "Usage: dcop [options] [application [object [function [arg1] [arg2] ... ] ] ]" << endl
0266 + << "" << endl
0267 + << "Console DCOP client" << endl
0268 + << "" << endl
0269 + << "Generic options:" << endl
0270 + << " --help Show help about options" << endl
0271 + << "" << endl
0272 + << "Options:" << endl
0273 + << " --pipe Call DCOP for each line read from stdin" << endl
0274 + << " --user <user> Connect to the given user's DCOP server. This option will" << endl
0275 + << " ignore the values of the environment vars $DCOPSERVER and" << endl
0276 + << " $ICEAUTHORITY, even if they are set." << endl
0277 + << " If the user has more than one open session, you must also" << endl
0278 + << " use one of the --list-sessions, --session or --als-sessions" << endl
0279 + << " command-line options." << endl
0280 + << " --all-users Send the same DCOP call to all users with a running DCOP" << endl
0281 + << " server. Only failed calls to existing DCOP servers will"
0282 + << " generate an error message. If no DCOP server is available" << endl
0283 + << " at all, no error will be generated." << endl;
0284 +
0285 + exit( exitCode );
0286 + }
0287
0288 ! /**
0289 ! * Return a list of all users and their home directories.
0290 ! * Returns an empty list if /etc/passwd cannot be read for some reason.
0291 ! */
0292 ! static UserList userList()
0293 {
0294 + UserList result;
0295 +
0296 + QFile f( "/etc/passwd" );
0297 +
0298 + if( !f.open( IO_ReadOnly ) )
0299 + {
0300 + cerr << "Can't open /etc/passwd for reading!" << endl;
0301 + return result;
0302 + }
0303
0304 ! QStringList l( QStringList::split( '\n', f.readAll() ) );
0305 !
0306 ! for( QStringList::ConstIterator it( l.begin() ); it != l.end(); ++it )
0307 ! {
0308 ! QStringList userInfo( QStringList::split( ':', *it, true ) );
0309 ! result[ userInfo[ 0 ] ] = userInfo[ 5 ];
0310 }
0311
0312 ! return result;
0313 ! }
0314 !
0315 ! /**
0316 ! * Return a list of available DCOP sessions for the specified user
0317 ! * An empty list means no sessions are available, or an error occurred.
0318 ! */
0319 ! QStringList dcopSessionList( const QString &user, const QString &home )
0320 ! {
0321 ! if( home.isEmpty() )
0322 ! {
0323 ! cerr << "WARNING: Cannot determine home directory for user "
0324 ! << user << "!" << endl
0325 ! << "Please check permissions or set the $DCOPSERVER variable manually before" << endl
0326 ! << "calling dcop." << endl;
0327 ! return QStringList();
0328 ! }
0329 !
0330 ! QStringList result;
0331 ! QFileInfo dirInfo( home );
0332 ! if( !dirInfo.exists() || !dirInfo.isReadable() )
0333 ! return result;
0334 !
0335 ! QDir d( home );
0336 ! d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
0337 ! d.setNameFilter( ".DCOPserver*" );
0338 !
0339 ! const QFileInfoList *list = d.entryInfoList();
0340 ! if( !list )
0341 ! return result;
0342 !
0343 ! QFileInfoListIterator it( *list );
0344 ! QFileInfo *fi;
0345 !
0346 ! while ( ( fi = it.current() ) != 0 )
0347 ! {
0348 ! if( fi->isReadable() )
0349 ! result.append( fi->fileName() );
0350 ! ++it;
0351 ! }
0352 ! return result;
0353 ! }
0354
0355 + /**
0356 + * Do the actual DCOP call
0357 + */
0358 + void runDCOP( QCStringList args, UserList users, Session session,
0359 + const QString sessionName, bool readStdin )
0360 + {
0361 QCString app;
0362 QCString objid;
0363 QCString function;
0364 ! QCStringList params;
0365 ! DCOPClient *client = 0L;
0366 ! if ( !args.isEmpty() && args[ 0 ].find( "DCOPRef(" ) == 0 )
0367 {
0368 ! // WARNING: This part (until the closing '}') could very
0369 ! // well be broken now. As I don't know how to trigger and test
0370 ! // dcoprefs this code is *not* tested. It compiles and it looks
0371 ! // ok to me, but that's all I can say - Martijn (2001/12/24)
0372 ! int delimPos = args[ 0 ].findRev( ',' );
0373 ! if( delimPos == -1 )
0374 ! {
0375 ! cerr << "Error: '" << args[ 0 ]
0376 ! << "' is not a valid DCOP reference." << endl;
0377 ! exit( -1 );
0378 ! }
0379 ! args[ 0 ][ delimPos ] = 0;
0380 ! app = args[ 0 ].mid( 8 );
0381 ! delimPos++;
0382 ! args[ 0 ][ args[ 0 ].length() - 1 ] = 0;
0383 ! objid = args[ 0 ].mid( delimPos );
0384 ! if( args.count() > 1 )
0385 ! function = args[ 1 ];
0386 ! if( args.count() > 2 )
0387 ! {
0388 ! params = args;
0389 ! params.remove( params.begin() );
0390 ! params.remove( params.begin() );
0391 ! }
0392 }
0393 else
0394 {
0395 ! if( !args.isEmpty() )
0396 ! app = args[ 0 ];
0397 ! if( args.count() > 1 )
0398 ! objid = args[ 1 ];
0399 ! if( args.count() > 2 )
0400 ! function = args[ 2 ];
0401 ! if( args.count() > 3)
0402 ! {
0403 ! params = args;
0404 ! params.remove( params.begin() );
0405 ! params.remove( params.begin() );
0406 ! params.remove( params.begin() );
0407 ! }
0408 ! }
0409 !
0410 ! bool firstRun = true;
0411 ! UserList::Iterator it;
0412 ! QStringList sessions;
0413 ! bool presetDCOPServer = false;
0414 ! // char *dcopStr = 0L;
0415 ! QString dcopServer;
0416 !
0417 ! for( it = users.begin(); it != users.end() || firstRun; it++ )
0418 ! {
0419 ! firstRun = false;
0420 !
0421 ! //cout << "Iterating '" << it.key() << "'" << endl;
0422 !
0423 ! if( session == QuerySessions )
0424 ! {
0425 ! QStringList sessions = dcopSessionList( it.key(), it.data() );
0426 ! if( sessions.isEmpty() )
0427 ! {
0428 ! cout << "No active sessions";
0429 ! if( !( *it ).isEmpty() )
0430 ! cout << " for user " << *it;
0431 ! cout << endl;
0432 ! }
0433 ! else
0434 ! {
0435 ! cout << "Active sessions ";
0436 ! if( !( *it ).isEmpty() )
0437 ! cout << "for user " << *it << " ";
0438 ! cout << ":" << endl;
0439 !
0440 ! QStringList::Iterator sIt;
0441 ! for( sIt = sessions.begin(); sIt != sessions.end(); sIt++ )
0442 ! cout << " " << *sIt << endl;
0443 !
0444 ! cout << endl;
0445 ! }
0446 ! continue;
0447 ! }
0448 !
0449 ! if( getenv( "DCOPSERVER" ) )
0450 ! {
0451 ! sessions.append( getenv( "DCOPSERVER" ) );
0452 ! presetDCOPServer = true;
0453 ! }
0454 !
0455 ! if( users.count() > 1 || ( users.count() == 1 &&
0456 ! ( getenv( "DCOPSERVER" ) == 0 /*&& getenv( "DISPLAY" ) == 0*/ ) ) )
0457 ! {
0458 ! sessions = dcopSessionList( it.key(), it.data() );
0459 ! if( sessions.isEmpty() )
0460 ! {
0461 ! if( users.count() > 1 )
0462 ! continue;
0463 ! else
0464 ! {
0465 ! cerr << "ERROR: No active KDE sessions!" << endl
0466 ! << "If you are sure there is one, please set the $DCOPSERVER variable manually" << endl
0467 ! << "before calling dcop." << endl;
0468 ! exit( -1 );
0469 ! }
0470 ! }
0471 ! else if( sessions.count() > 1 && session != AllSessions )
0472 ! {
0473 ! cerr << "ERROR: Multiple available KDE sessions!" << endl
0474 ! << "Please specify the correct session to use with --session or use the" << endl
0475 ! << "--all-sessions option to broadcast to all sessions." << endl;
0476 ! exit( -1 );
0477 ! }
0478 ! }
0479
0480 + if( users.count() > 1 || ( users.count() == 1 &&
0481 + ( getenv( "ICEAUTHORITY" ) == 0 || getenv( "DISPLAY" ) == 0 ) ) )
0482 + {
0483 + // Check for ICE authority file and if the file can be read by us
0484 + QString home = it.data();
0485 + QString iceFile = it.data() + "/.ICEauthority";
0486 + QFileInfo fi( iceFile );
0487 + if( iceFile.isEmpty() )
0488 + {
0489 + cerr << "WARNING: Cannot determine home directory for user "
0490 + << it.key() << "!" << endl
0491 + << "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl
0492 + << "calling dcop." << endl;
0493 + }
0494 + else if( fi.exists() )
0495 + {
0496 + if( fi.isReadable() )
0497 + {
0498 + char *envStr = strdup( ( "ICEAUTHORITY=" + iceFile ).ascii() );
0499 + putenv( envStr );
0500 + //cerr << "ice: " << envStr << endl;
0501 + }
0502 + else
0503 + {
0504 + cerr << "WARNING: ICE authority file " << iceFile
0505 + << "is not readable by you!" << endl
0506 + << "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl
0507 + << "calling dcop." << endl;
0508 + }
0509 + }
0510 + else
0511 + {
0512 + if( users.count() > 1 )
0513 + continue;
0514 + else
0515 + {
0516 + cerr << "WARNING: Cannot find ICE authority file "
0517 + << iceFile << "!" << endl
0518 + << "Please check permissions or set the $ICEAUTHORITY"
0519 + << " variable manually before" << endl
0520 + << "calling dcop." << endl;
0521 + }
0522 + }
0523 + }
0524 +
0525 + // Main loop
0526 + // If users is an empty list we're calling for the currently logged
0527 + // in user. In this case we don't have a session, but still want
0528 + // to iterate the loop once.
0529 + QStringList::Iterator sIt = sessions.begin();
0530 + for( ; sIt != sessions.end() || users.isEmpty(); sIt++ )
0531 + {
0532 + if( !presetDCOPServer && !users.isEmpty() )
0533 + {
0534 + QString dcopFile = it.data() + "/" + *sIt;
0535 + QFile f( dcopFile );
0536 + if( !f.open( IO_ReadOnly ) )
0537 + {
0538 + cerr << "Can't open " << dcopFile << " for reading!" << endl;
0539 + exit( -1 );
0540 + }
0541 +
0542 + QStringList l( QStringList::split( '\n', f.readAll() ) );
0543 + dcopServer = l.first();
0544 +
0545 + if( dcopServer.isEmpty() )
0546 + {
0547 + cerr << "WARNING: Unable to determine DCOP server for session "
0548 + << *sIt << "!" << endl
0549 + << "Please check permissions or set the $DCOPSERVER variable manually before" << endl
0550 + << "calling dcop." << endl;
0551 + exit( -1 );
0552 + }
0553 + }
0554 +
0555 + delete client;
0556 + client = new DCOPClient;
0557 + if( !dcopServer.isEmpty() )
0558 + client->setServerAddress( dcopServer.ascii() );
0559 + bool success = client->attach();
0560 + if( !success )
0561 + {
0562 + cerr << "ERROR: Couldn't attach to DCOP server!" << endl;
0563 + continue;
0564 + }
0565 + dcop = client;
0566 +
0567 + switch ( args.count() )
0568 + {
0569 + case 0:
0570 + queryApplications("");
0571 + break;
0572 + case 1:
0573 + if (endsWith(app, '*'))
0574 + queryApplications(app);
0575 + else
0576 + queryObjects( app, "" );
0577 + break;
0578 + case 2:
0579 + if (endsWith(objid, '*'))
0580 + queryObjects(app, objid);
0581 + else
0582 + queryFunctions( app, objid );
0583 + break;
0584 + case 3:
0585 + default:
0586 + if( readStdin )
0587 + {
0588 + QCStringList::Iterator replaceArg = args.end();
0589 +
0590 + QCStringList::Iterator it;
0591 + for( it = args.begin(); it != args.end(); it++ )
0592 + if( *it == "%1" )
0593 + replaceArg = it;
0594 +
0595 + // Read from stdin until EOF and call function for each line read
0596 + char *buf = new char[ 1000 ];
0597 + while ( !feof( stdin ) )
0598 + {
0599 + fgets( buf, 1000, stdin );
0600 +
0601 + if( replaceArg != args.end() )
0602 + *replaceArg = buf;
0603 +
0604 + callFunction( app, objid, function, params );
0605 + }
0606 + }
0607 + else
0608 + {
0609 + // Just call function
0610 + // cout << "call " << app << ", " << objid << ", " << function << ", (params)" << endl;
0611 + callFunction( app, objid, function, params );
0612 + }
0613 + break;
0614 + }
0615 + // Another sIt++ would make the loop infinite...
0616 + if( users.isEmpty() )
0617 + break;
0618 + }
0619 +
0620 + // Another it++ would make the loop infinite...
0621 + if( it == users.end() )
0622 + break;
0623 }
0624 + }
0625 +
0626
0627 + int main( int argc, char** argv )
0628 + {
0629 + bool readStdin = false;
0630 + int numOptions = 0;
0631 + QString user;
0632 + Session session = DefaultSession;
0633 + QString sessionName;
0634 +
0635 + // Scan for command-line options first
0636 + for( int pos = 1 ; pos <= argc - 1 ; pos++ )
0637 + {
0638 + if( strcmp( argv[ pos ], "--help" ) == 0 )
0639 + showHelp( 0 );
0640 + else if( strcmp( argv[ pos ], "--pipe" ) == 0 )
0641 + {
0642 + readStdin = true;
0643 + numOptions++;
0644 + }
0645 + else if( strcmp( argv[ pos ], "--user" ) == 0 )
0646 + {
0647 + if( pos <= argc - 2 )
0648 + {
0649 + user = QString::fromLocal8Bit( argv[ pos + 1] );
0650 + numOptions +=2;
0651 + pos++;
0652 + }
0653 + else
0654 + {
0655 + cerr << "Missing username for '--user' option!" << endl << endl;
0656 + showHelp( -1 );
0657 + }
0658 + }
0659 + else if( strcmp( argv[ pos ], "--all-users" ) == 0 )
0660 + {
0661 + user = "*";
0662 + numOptions ++;
0663 + }
0664 + else if( strcmp( argv[ pos ], "--list-sessions" ) == 0 )
0665 + {
0666 + session = QuerySessions;
0667 + numOptions ++;
0668 + }
0669 + else if( strcmp( argv[ pos ], "--all-sessions" ) == 0 )
0670 + {
0671 + session = AllSessions;
0672 + numOptions ++;
0673 + }
0674 + else if( argv[ pos ][ 0 ] == '-' )
0675 + {
0676 + cerr << "Unknown command-line option '" << argv[ pos ]
0677 + << "'." << endl << endl;
0678 + showHelp( -1 );
0679 + }
0680 + else
0681 + break; // End of options
0682 + }
0683 +
0684 + argc -= numOptions;
0685 +
0686 + QCStringList args;
0687 + for( int i = numOptions; i < argc + numOptions - 1; i++ )
0688 + args.append( argv[ i + 1 ] );
0689 +
0690 + if( readStdin && args.count() < 3 )
0691 + {
0692 + cerr << "--pipe option only supported for function calls!" << endl << endl;
0693 + showHelp( -1 );
0694 + }
0695 +
0696 + if( user == "*" && args.count() < 3 && session != QuerySessions )
0697 + {
0698 + cerr << "ERROR: The --all-users option is only supported for function calls!" << endl << endl;
0699 + showHelp( -1 );
0700 + }
0701 +
0702 + if( session == QuerySessions && !args.isEmpty() )
0703 + {
0704 + cerr << "ERROR: The --list-sessions option cannot be used for actual DCOP calls!" << endl << endl;
0705 + showHelp( -1 );
0706 + }
0707 +
0708 + if( session == QuerySessions && user.isEmpty() )
0709 + {
0710 + cerr << "ERROR: The --list-sessions option can only be used with the --user or" << endl
0711 + << "--all-users options!" << endl << endl;
0712 + showHelp( -1 );
0713 + }
0714 +
0715 + if( session != DefaultSession && session != QuerySessions &&
0716 + args.count() < 3 )
0717 + {
0718 + cerr << "ERROR: The --session and --all-sessions options are only supported for function" << endl
0719 + << "calls!" << endl << endl;
0720 + showHelp( -1 );
0721 + }
0722 +
0723 + UserList users;
0724 + if( user == "*" )
0725 + users = userList();
0726 + else if( !user.isEmpty() )
0727 + users[ user ] = userList()[ user ];
0728 +
0729 + runDCOP( args, users, session, sessionName, readStdin );
0730 +
0731 return 0;
0732 }
0733 +
0734 + // vim: set ts=8 sts=4 sw=4 noet:
0735 +
0736 Index: client/dcopfind.cpp
0737 ===================================================================
0738 RCS file: /home/kde/kdelibs/dcop/client/dcopfind.cpp,v
0739 retrieving revision 1.2
0740 diff -c -r1.2 dcopfind.cpp
0741 *** client/dcopfind.cpp 2001/10/31 01:17:39 1.2
0742 --- client/dcopfind.cpp 2002/01/16 18:06:24
0743 ***************
0744 *** 36,42 ****
0745 static bool bAppIdOnly = 0;
0746 static bool bLaunchApp = 0;
0747
0748 ! bool findObject( const char* app, const char* obj, const char* func, int argc, char** args )
0749 {
0750 QString f = func; // Qt is better with unicode strings, so use one.
0751 int left = f.find( '(' );
0752 --- 36,42 ----
0753 static bool bAppIdOnly = 0;
0754 static bool bLaunchApp = 0;
0755
0756 ! bool findObject( const char* app, const char* obj, const char* func, QCStringList args )
0757 {
0758 QString f = func; // Qt is better with unicode strings, so use one.
0759 int left = f.find( '(' );
0760 ***************
0761 *** 118,124 ****
0762 f = fc;
0763 }
0764
0765 ! if ( (int) types.count() != argc ) {
0766 qWarning( "arguments do not match" );
0767 exit(1);
0768 }
0769 --- 118,124 ----
0770 f = fc;
0771 }
0772
0773 ! if ( types.count() != args.count() ) {
0774 qWarning( "arguments do not match" );
0775 exit(1);
0776 }
0777 ***************
0778 *** 128,136 ****
0779
0780 int i = 0;
0781 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) {
0782 ! marshall(arg, argc, args, i, *it);
0783 }
0784 ! if ( (int) i != argc ) {
0785 qWarning( "arguments do not match" );
0786 exit(1);
0787 }
0788 --- 128,136 ----
0789
0790 int i = 0;
0791 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) {
0792 ! marshall(arg, args, i, *it);
0793 }
0794 ! if ( (uint) i != args.count() ) {
0795 qWarning( "arguments do not match" );
0796 exit(1);
0797 }
0798 ***************
0799 *** 221,227 ****
0800 argc = 0;
0801 }
0802
0803 ! findObject( app, objid, function, argc, args );
0804
0805 return 0;
0806 }
0807 --- 221,231 ----
0808 argc = 0;
0809 }
0810
0811 ! QCStringList params;
0812 ! for( int i = 0; i < argc; i++ )
0813 ! params.append( args[ i ] );
0814 !
0815 ! findObject( app, objid, function, params );
0816
0817 return 0;
0818 }
0819 Index: client/marshall.cpp
0820 ===================================================================
0821 RCS file: /home/kde/kdelibs/dcop/client/marshall.cpp,v
0822 retrieving revision 1.3
0823 diff -c -r1.3 marshall.cpp
0824 *** client/marshall.cpp 2001/10/31 01:17:39 1.3
0825 --- client/marshall.cpp 2002/01/16 18:06:24
0826 ***************
0827 *** 242,349 ****
0828
0829 }
0830
0831 ! void marshall(QDataStream &arg, int argc, char **argv, int &i, QString type)
0832 {
0833 ! if (type == "QStringList")
0834 ! type = "QValueList<QString>";
0835 ! if (type == "QCStringList")
0836 ! type = "QValueList<QCString>";
0837 ! if (i >= argc)
0838 ! {
0839 ! qWarning("Not enough arguments.");
0840 ! exit(1);
0841 ! }
0842 ! QString s = QString::fromLocal8Bit(argv[i]);
0843 !
0844 ! if ( type == "int" )
0845 ! arg << s.toInt();
0846 ! else if ( type == "uint" )
0847 ! arg << s.toUInt();
0848 ! else if ( type == "unsigned" )
0849 ! arg << s.toUInt();
0850 ! else if ( type == "unsigned int" )
0851 ! arg << s.toUInt();
0852 ! else if ( type == "long" )
0853 ! arg << s.toLong();
0854 ! else if ( type == "long int" )
0855 ! arg << s.toLong();
0856 ! else if ( type == "unsigned long" )
0857 ! arg << s.toULong();
0858 ! else if ( type == "unsigned long int" )
0859 ! arg << s.toULong();
0860 ! else if ( type == "float" )
0861 ! arg << s.toFloat();
0862 ! else if ( type == "double" )
0863 ! arg << s.toDouble();
0864 ! else if ( type == "bool" )
0865 ! arg << mkBool( s );
0866 ! else if ( type == "QString" )
0867 ! arg << s;
0868 ! else if ( type == "QCString" )
0869 ! arg << QCString( argv[i] );
0870 ! else if ( type == "QColor" )
0871 ! arg << mkColor( s );
0872 ! else if ( type == "QPoint" )
0873 ! arg << mkPoint( s );
0874 ! else if ( type == "QSize" )
0875 ! arg << mkSize( s );
0876 ! else if ( type == "QRect" )
0877 ! arg << mkRect( s );
0878 ! else if ( type == "QVariant" ) {
0879 ! if ( s == "true" || s == "false" )
0880 ! arg << QVariant( mkBool( s ), 42 );
0881 ! else if ( s.left( 4 ) == "int(" )
0882 ! arg << QVariant( s.mid(4, s.length()-5).toInt() );
0883 ! else if ( s.left( 7 ) == "QPoint(" )
0884 ! arg << QVariant( mkPoint( s.mid(7, s.length()-8) ) );
0885 ! else if ( s.left( 6 ) == "QSize(" )
0886 ! arg << QVariant( mkSize( s.mid(6, s.length()-7) ) );
0887 ! else if ( s.left( 6 ) == "QRect(" )
0888 ! arg << QVariant( mkRect( s.mid(6, s.length()-7) ) );
0889 ! else if ( s.left( 7 ) == "QColor(" )
0890 ! arg << QVariant( mkColor( s.mid(7, s.length()-8) ) );
0891 ! else
0892 ! arg << QVariant( s );
0893 ! } else if ( type.startsWith("QValueList<")) {
0894 ! type = type.mid(11, type.length() - 12);
0895 ! QStringList list;
0896 ! QString delim = s;
0897 ! if (delim == "[")
0898 ! delim = "]";
0899 ! if (delim == "(")
0900 ! delim = ")";
0901 ! i++;
0902 ! QByteArray dummy_data;
0903 ! QDataStream dummy_arg(dummy_data, IO_WriteOnly);
0904
0905 ! int j = i;
0906 ! int count = 0;
0907 ! // Parse list to get the count
0908 ! while (true) {
0909 ! if (j >= argc)
0910 ! {
0911 ! qWarning("List end-delimiter '%s' not found.", delim.latin1());
0912 ! exit(1);
0913 ! }
0914 ! if (argv[j] == delim) break;
0915 ! marshall(dummy_arg, argc, argv, j, type);
0916 ! count++;
0917 ! }
0918 ! arg << (Q_UINT32) count;
0919 ! // Parse the list for real
0920 ! while (true) {
0921 ! if (i >= argc)
0922 ! {
0923 ! qWarning("List end-delimiter '%s' not found.", delim.latin1());
0924 ! exit(1);
0925 ! }
0926 ! if (argv[i] == delim) break;
0927 ! marshall(arg, argc, argv, i, type);
0928 ! }
0929 ! } else {
0930 ! qWarning( "cannot handle datatype '%s'", type.latin1() );
0931 ! exit(1);
0932 ! }
0933 i++;
0934 }
0935
0936 --- 242,351 ----
0937
0938 }
0939
0940 ! void marshall( QDataStream &arg, QCStringList args, uint &i, QString type )
0941 {
0942 ! if (type == "QStringList")
0943 ! type = "QValueList<QString>";
0944 ! if (type == "QCStringList")
0945 ! type = "QValueList<QCString>";
0946 ! if( i > args.count() )
0947 ! {
0948 ! qWarning("Not enough arguments.");
0949 ! exit(1);
0950 ! }
0951 ! QString s = QString::fromLocal8Bit( args[ i ] );
0952
0953 ! if ( type == "int" )
0954 ! arg << s.toInt();
0955 ! else if ( type == "uint" )
0956 ! arg << s.toUInt();
0957 ! else if ( type == "unsigned" )
0958 ! arg << s.toUInt();
0959 ! else if ( type == "unsigned int" )
0960 ! arg << s.toUInt();
0961 ! else if ( type == "long" )
0962 ! arg << s.toLong();
0963 ! else if ( type == "long int" )
0964 ! arg << s.toLong();
0965 ! else if ( type == "unsigned long" )
0966 ! arg << s.toULong();
0967 ! else if ( type == "unsigned long int" )
0968 ! arg << s.toULong();
0969 ! else if ( type == "float" )
0970 ! arg << s.toFloat();
0971 ! else if ( type == "double" )
0972 ! arg << s.toDouble();
0973 ! else if ( type == "bool" )
0974 ! arg << mkBool( s );
0975 ! else if ( type == "QString" )
0976 ! arg << s;
0977 ! else if ( type == "QCString" )
0978 ! arg << QCString( args[ i ] );
0979 ! else if ( type == "QColor" )
0980 ! arg << mkColor( s );
0981 ! else if ( type == "QPoint" )
0982 ! arg << mkPoint( s );
0983 ! else if ( type == "QSize" )
0984 ! arg << mkSize( s );
0985 ! else if ( type == "QRect" )
0986 ! arg << mkRect( s );
0987 ! else if ( type == "QVariant" ) {
0988 ! if ( s == "true" || s == "false" )
0989 ! arg << QVariant( mkBool( s ), 42 );
0990 ! else if ( s.left( 4 ) == "int(" )
0991 ! arg << QVariant( s.mid(4, s.length()-5).toInt() );
0992 ! else if ( s.left( 7 ) == "QPoint(" )
0993 ! arg << QVariant( mkPoint( s.mid(7, s.length()-8) ) );
0994 ! else if ( s.left( 6 ) == "QSize(" )
0995 ! arg << QVariant( mkSize( s.mid(6, s.length()-7) ) );
0996 ! else if ( s.left( 6 ) == "QRect(" )
0997 ! arg << QVariant( mkRect( s.mid(6, s.length()-7) ) );
0998 ! else if ( s.left( 7 ) == "QColor(" )
0999 ! arg << QVariant( mkColor( s.mid(7, s.length()-8) ) );
1000 ! else
1001 ! arg << QVariant( s );
1002 ! } else if ( type.startsWith("QValueList<")) {
1003 ! type = type.mid(11, type.length() - 12);
1004 ! QStringList list;
1005 ! QString delim = s;
1006 ! if (delim == "[")
1007 ! delim = "]";
1008 ! if (delim == "(")
1009 ! delim = ")";
1010 i++;
1011 + QByteArray dummy_data;
1012 + QDataStream dummy_arg(dummy_data, IO_WriteOnly);
1013 +
1014 + uint j = i;
1015 + uint count = 0;
1016 + // Parse list to get the count
1017 + while (true) {
1018 + if( j > args.count() )
1019 + {
1020 + qWarning("List end-delimiter '%s' not found.", delim.latin1());
1021 + exit(1);
1022 + }
1023 + if( QString::fromLocal8Bit( args[ j ] ) == delim )
1024 + break;
1025 + marshall( dummy_arg, args, j, type );
1026 + count++;
1027 + }
1028 + arg << (Q_UINT32) count;
1029 + // Parse the list for real
1030 + while (true) {
1031 + if( i > args.count() )
1032 + {
1033 + qWarning("List end-delimiter '%s' not found.", delim.latin1());
1034 + exit(1);
1035 + }
1036 + if( QString::fromLocal8Bit( args[ i ] ) == delim )
1037 + break;
1038 + marshall( arg, args, i, type );
1039 + }
1040 + } else {
1041 + qWarning( "cannot handle datatype '%s'", type.latin1() );
1042 + exit(1);
1043 + }
1044 + i++;
1045 }
1046