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