Warning, /sdk/kompare/tests/diff/rcsm.diff is written in an unsupported language. File is not indexed.
0001 diff -nr dcop/client/dcop.cpp dcop2/client/dcop.cpp
0002 d23 1
0003 a23 4
0004 #include <ctype.h>
0005 #include <stdio.h>
0006 #include <stdlib.h>
0007
0008 d25 1
0009 a25 12
0010 #include <qdir.h>
0011 #include <qfile.h>
0012 #include <qfileinfo.h>
0013 #include <qmap.h>
0014 #include <qstringlist.h>
0015 #include <qtextstream.h>
0016 #include <qvariant.h>
0017
0018 // putenv() is not available on all platforms, so make sure the emulation
0019 // wrapper is available in those cases by loading config.h!
0020 #include <config.h>
0021
0022 d28 3
0023 a30 1
0024 #include "../kdatastream.h"
0025 a33 2
0026 typedef QMap<QString, QString> UserList;
0027
0028 a35 14
0029 static QTextStream cout( stdout, IO_WriteOnly );
0030 static QTextStream cerr( stderr, IO_WriteOnly );
0031
0032 /**
0033 * Session to send call to
0034 * DefaultSession - current session. Current KDE session when called without
0035 * --user or --all-users option. Otherwise this value ignores
0036 * all users with more than one active session.
0037 * AllSessions - Send to all sessions found. requires --user or --all-users.
0038 * QuerySessions - Don't call DCOP, return a list of available sessions.
0039 * CustomSession - Use the specified session
0040 */
0041 enum Session { DefaultSession = 0, AllSessions, QuerySessions, CustomSession };
0042
0043 d121 1
0044 a121 1
0045 void callFunction( const char* app, const char* obj, const char* func, const QCStringList args )
0046 d123 1
0047 d139 1
0048 a139 1
0049 if ( !ok && args.isEmpty() )
0050 d156 2
0051 a157 2
0052 uint a = (*it).contains(',');
0053 if ( ( a == 0 && args.isEmpty() ) || ( a > 0 && a + 1 == args.count() ) )
0054 d164 1
0055 a164 2
0056 // exit(1);
0057 return;
0058 d246 5
0059 a250 6
0060 uint i = 0;
0061 for( QStringList::Iterator it = types.begin(); it != types.end(); ++it )
0062 marshall( arg, args, i, *it );
0063
0064 if ( i != args.count() )
0065 {
0066 a268 27
0067 /**
0068 * Show command-line help and exit
0069 */
0070 void showHelp( int exitCode = 0 )
0071 {
0072 cout << "Usage: dcop [options] [application [object [function [arg1] [arg2] ... ] ] ]" << endl
0073 << "" << endl
0074 << "Console DCOP client" << endl
0075 << "" << endl
0076 << "Generic options:" << endl
0077 << " --help Show help about options" << endl
0078 << "" << endl
0079 << "Options:" << endl
0080 << " --pipe Call DCOP for each line read from stdin" << endl
0081 << " --user <user> Connect to the given user's DCOP server. This option will" << endl
0082 << " ignore the values of the environment vars $DCOPSERVER and" << endl
0083 << " $ICEAUTHORITY, even if they are set." << endl
0084 << " If the user has more than one open session, you must also" << endl
0085 << " use one of the --list-sessions, --session or --als-sessions" << endl
0086 << " command-line options." << endl
0087 << " --all-users Send the same DCOP call to all users with a running DCOP" << endl
0088 << " server. Only failed calls to existing DCOP servers will"
0089 << " generate an error message. If no DCOP server is available" << endl
0090 << " at all, no error will be generated." << endl;
0091
0092 exit( exitCode );
0093 }
0094 d270 2
0095 a271 5
0096 /**
0097 * Return a list of all users and their home directories.
0098 * Returns an empty list if /etc/passwd cannot be read for some reason.
0099 */
0100 static UserList userList()
0101 a272 9
0102 UserList result;
0103
0104 QFile f( "/etc/passwd" );
0105
0106 if( !f.open( IO_ReadOnly ) )
0107 {
0108 cerr << "Can't open /etc/passwd for reading!" << endl;
0109 return result;
0110 }
0111 d274 3
0112 a276 6
0113 QStringList l( QStringList::split( '\n', f.readAll() ) );
0114
0115 for( QStringList::ConstIterator it( l.begin() ); it != l.end(); ++it )
0116 {
0117 QStringList userInfo( QStringList::split( ':', *it, true ) );
0118 result[ userInfo[ 0 ] ] = userInfo[ 5 ];
0119 d279 3
0120 a281 42
0121 return result;
0122 }
0123
0124 /**
0125 * Return a list of available DCOP sessions for the specified user
0126 * An empty list means no sessions are available, or an error occurred.
0127 */
0128 QStringList dcopSessionList( const QString &user, const QString &home )
0129 {
0130 if( home.isEmpty() )
0131 {
0132 cerr << "WARNING: Cannot determine home directory for user "
0133 << user << "!" << endl
0134 << "Please check permissions or set the $DCOPSERVER variable manually before" << endl
0135 << "calling dcop." << endl;
0136 return QStringList();
0137 }
0138
0139 QStringList result;
0140 QFileInfo dirInfo( home );
0141 if( !dirInfo.exists() || !dirInfo.isReadable() )
0142 return result;
0143
0144 QDir d( home );
0145 d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
0146 d.setNameFilter( ".DCOPserver*" );
0147
0148 const QFileInfoList *list = d.entryInfoList();
0149 if( !list )
0150 return result;
0151
0152 QFileInfoListIterator it( *list );
0153 QFileInfo *fi;
0154
0155 while ( ( fi = it.current() ) != 0 )
0156 {
0157 if( fi->isReadable() )
0158 result.append( fi->fileName() );
0159 ++it;
0160 }
0161 return result;
0162 }
0163 a282 6
0164 /**
0165 * Do the actual DCOP call
0166 */
0167 void runDCOP( QCStringList args, UserList users, Session session,
0168 const QString sessionName, bool readStdin )
0169 {
0170 d286 2
0171 a287 3
0172 QCStringList params;
0173 DCOPClient *client = 0L;
0174 if ( !args.isEmpty() && args[ 0 ].find( "DCOPRef(" ) == 0 )
0175 d289 16
0176 a304 24
0177 // WARNING: This part (until the closing '}') could very
0178 // well be broken now. As I don't know how to trigger and test
0179 // dcoprefs this code is *not* tested. It compiles and it looks
0180 // ok to me, but that's all I can say - Martijn (2001/12/24)
0181 int delimPos = args[ 0 ].findRev( ',' );
0182 if( delimPos == -1 )
0183 {
0184 cerr << "Error: '" << args[ 0 ]
0185 << "' is not a valid DCOP reference." << endl;
0186 exit( -1 );
0187 }
0188 args[ 0 ][ delimPos ] = 0;
0189 app = args[ 0 ].mid( 8 );
0190 delimPos++;
0191 args[ 0 ][ args[ 0 ].length() - 1 ] = 0;
0192 objid = args[ 0 ].mid( delimPos );
0193 if( args.count() > 1 )
0194 function = args[ 1 ];
0195 if( args.count() > 2 )
0196 {
0197 params = args;
0198 params.remove( params.begin() );
0199 params.remove( params.begin() );
0200 }
0201 d308 31
0202 a338 84
0203 if( !args.isEmpty() )
0204 app = args[ 0 ];
0205 if( args.count() > 1 )
0206 objid = args[ 1 ];
0207 if( args.count() > 2 )
0208 function = args[ 2 ];
0209 if( args.count() > 3)
0210 {
0211 params = args;
0212 params.remove( params.begin() );
0213 params.remove( params.begin() );
0214 params.remove( params.begin() );
0215 }
0216 }
0217
0218 bool firstRun = true;
0219 UserList::Iterator it;
0220 QStringList sessions;
0221 bool presetDCOPServer = false;
0222 // char *dcopStr = 0L;
0223 QString dcopServer;
0224
0225 for( it = users.begin(); it != users.end() || firstRun; it++ )
0226 {
0227 firstRun = false;
0228
0229 //cout << "Iterating '" << it.key() << "'" << endl;
0230
0231 if( session == QuerySessions )
0232 {
0233 QStringList sessions = dcopSessionList( it.key(), it.data() );
0234 if( sessions.isEmpty() )
0235 {
0236 cout << "No active sessions";
0237 if( !( *it ).isEmpty() )
0238 cout << " for user " << *it;
0239 cout << endl;
0240 }
0241 else
0242 {
0243 cout << "Active sessions ";
0244 if( !( *it ).isEmpty() )
0245 cout << "for user " << *it << " ";
0246 cout << ":" << endl;
0247
0248 QStringList::Iterator sIt;
0249 for( sIt = sessions.begin(); sIt != sessions.end(); sIt++ )
0250 cout << " " << *sIt << endl;
0251
0252 cout << endl;
0253 }
0254 continue;
0255 }
0256
0257 if( getenv( "DCOPSERVER" ) )
0258 {
0259 sessions.append( getenv( "DCOPSERVER" ) );
0260 presetDCOPServer = true;
0261 }
0262
0263 if( users.count() > 1 || ( users.count() == 1 &&
0264 ( getenv( "DCOPSERVER" ) == 0 /*&& getenv( "DISPLAY" ) == 0*/ ) ) )
0265 {
0266 sessions = dcopSessionList( it.key(), it.data() );
0267 if( sessions.isEmpty() )
0268 {
0269 if( users.count() > 1 )
0270 continue;
0271 else
0272 {
0273 cerr << "ERROR: No active KDE sessions!" << endl
0274 << "If you are sure there is one, please set the $DCOPSERVER variable manually" << endl
0275 << "before calling dcop." << endl;
0276 exit( -1 );
0277 }
0278 }
0279 else if( sessions.count() > 1 && session != AllSessions )
0280 {
0281 cerr << "ERROR: Multiple available KDE sessions!" << endl
0282 << "Please specify the correct session to use with --session or use the" << endl
0283 << "--all-sessions option to broadcast to all sessions." << endl;
0284 exit( -1 );
0285 }
0286 }
0287 a339 143
0288 if( users.count() > 1 || ( users.count() == 1 &&
0289 ( getenv( "ICEAUTHORITY" ) == 0 || getenv( "DISPLAY" ) == 0 ) ) )
0290 {
0291 // Check for ICE authority file and if the file can be read by us
0292 QString home = it.data();
0293 QString iceFile = it.data() + "/.ICEauthority";
0294 QFileInfo fi( iceFile );
0295 if( iceFile.isEmpty() )
0296 {
0297 cerr << "WARNING: Cannot determine home directory for user "
0298 << it.key() << "!" << endl
0299 << "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl
0300 << "calling dcop." << endl;
0301 }
0302 else if( fi.exists() )
0303 {
0304 if( fi.isReadable() )
0305 {
0306 char *envStr = strdup( ( "ICEAUTHORITY=" + iceFile ).ascii() );
0307 putenv( envStr );
0308 //cerr << "ice: " << envStr << endl;
0309 }
0310 else
0311 {
0312 cerr << "WARNING: ICE authority file " << iceFile
0313 << "is not readable by you!" << endl
0314 << "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl
0315 << "calling dcop." << endl;
0316 }
0317 }
0318 else
0319 {
0320 if( users.count() > 1 )
0321 continue;
0322 else
0323 {
0324 cerr << "WARNING: Cannot find ICE authority file "
0325 << iceFile << "!" << endl
0326 << "Please check permissions or set the $ICEAUTHORITY"
0327 << " variable manually before" << endl
0328 << "calling dcop." << endl;
0329 }
0330 }
0331 }
0332
0333 // Main loop
0334 // If users is an empty list we're calling for the currently logged
0335 // in user. In this case we don't have a session, but still want
0336 // to iterate the loop once.
0337 QStringList::Iterator sIt = sessions.begin();
0338 for( ; sIt != sessions.end() || users.isEmpty(); sIt++ )
0339 {
0340 if( !presetDCOPServer && !users.isEmpty() )
0341 {
0342 QString dcopFile = it.data() + "/" + *sIt;
0343 QFile f( dcopFile );
0344 if( !f.open( IO_ReadOnly ) )
0345 {
0346 cerr << "Can't open " << dcopFile << " for reading!" << endl;
0347 exit( -1 );
0348 }
0349
0350 QStringList l( QStringList::split( '\n', f.readAll() ) );
0351 dcopServer = l.first();
0352
0353 if( dcopServer.isEmpty() )
0354 {
0355 cerr << "WARNING: Unable to determine DCOP server for session "
0356 << *sIt << "!" << endl
0357 << "Please check permissions or set the $DCOPSERVER variable manually before" << endl
0358 << "calling dcop." << endl;
0359 exit( -1 );
0360 }
0361 }
0362
0363 delete client;
0364 client = new DCOPClient;
0365 if( !dcopServer.isEmpty() )
0366 client->setServerAddress( dcopServer.ascii() );
0367 bool success = client->attach();
0368 if( !success )
0369 {
0370 cerr << "ERROR: Couldn't attach to DCOP server!" << endl;
0371 continue;
0372 }
0373 dcop = client;
0374
0375 switch ( args.count() )
0376 {
0377 case 0:
0378 queryApplications("");
0379 break;
0380 case 1:
0381 if (endsWith(app, '*'))
0382 queryApplications(app);
0383 else
0384 queryObjects( app, "" );
0385 break;
0386 case 2:
0387 if (endsWith(objid, '*'))
0388 queryObjects(app, objid);
0389 else
0390 queryFunctions( app, objid );
0391 break;
0392 case 3:
0393 default:
0394 if( readStdin )
0395 {
0396 QCStringList::Iterator replaceArg = args.end();
0397
0398 QCStringList::Iterator it;
0399 for( it = args.begin(); it != args.end(); it++ )
0400 if( *it == "%1" )
0401 replaceArg = it;
0402
0403 // Read from stdin until EOF and call function for each line read
0404 char *buf = new char[ 1000 ];
0405 while ( !feof( stdin ) )
0406 {
0407 fgets( buf, 1000, stdin );
0408
0409 if( replaceArg != args.end() )
0410 *replaceArg = buf;
0411
0412 callFunction( app, objid, function, params );
0413 }
0414 }
0415 else
0416 {
0417 // Just call function
0418 // cout << "call " << app << ", " << objid << ", " << function << ", (params)" << endl;
0419 callFunction( app, objid, function, params );
0420 }
0421 break;
0422 }
0423 // Another sIt++ would make the loop infinite...
0424 if( users.isEmpty() )
0425 break;
0426 }
0427
0428 // Another it++ would make the loop infinite...
0429 if( it == users.end() )
0430 break;
0431 a340 106
0432 }
0433
0434
0435 int main( int argc, char** argv )
0436 {
0437 bool readStdin = false;
0438 int numOptions = 0;
0439 QString user;
0440 Session session = DefaultSession;
0441 QString sessionName;
0442
0443 // Scan for command-line options first
0444 for( int pos = 1 ; pos <= argc - 1 ; pos++ )
0445 {
0446 if( strcmp( argv[ pos ], "--help" ) == 0 )
0447 showHelp( 0 );
0448 else if( strcmp( argv[ pos ], "--pipe" ) == 0 )
0449 {
0450 readStdin = true;
0451 numOptions++;
0452 }
0453 else if( strcmp( argv[ pos ], "--user" ) == 0 )
0454 {
0455 if( pos <= argc - 2 )
0456 {
0457 user = QString::fromLocal8Bit( argv[ pos + 1] );
0458 numOptions +=2;
0459 pos++;
0460 }
0461 else
0462 {
0463 cerr << "Missing username for '--user' option!" << endl << endl;
0464 showHelp( -1 );
0465 }
0466 }
0467 else if( strcmp( argv[ pos ], "--all-users" ) == 0 )
0468 {
0469 user = "*";
0470 numOptions ++;
0471 }
0472 else if( strcmp( argv[ pos ], "--list-sessions" ) == 0 )
0473 {
0474 session = QuerySessions;
0475 numOptions ++;
0476 }
0477 else if( strcmp( argv[ pos ], "--all-sessions" ) == 0 )
0478 {
0479 session = AllSessions;
0480 numOptions ++;
0481 }
0482 else if( argv[ pos ][ 0 ] == '-' )
0483 {
0484 cerr << "Unknown command-line option '" << argv[ pos ]
0485 << "'." << endl << endl;
0486 showHelp( -1 );
0487 }
0488 else
0489 break; // End of options
0490 }
0491
0492 argc -= numOptions;
0493
0494 QCStringList args;
0495 for( int i = numOptions; i < argc + numOptions - 1; i++ )
0496 args.append( argv[ i + 1 ] );
0497
0498 if( readStdin && args.count() < 3 )
0499 {
0500 cerr << "--pipe option only supported for function calls!" << endl << endl;
0501 showHelp( -1 );
0502 }
0503
0504 if( user == "*" && args.count() < 3 && session != QuerySessions )
0505 {
0506 cerr << "ERROR: The --all-users option is only supported for function calls!" << endl << endl;
0507 showHelp( -1 );
0508 }
0509
0510 if( session == QuerySessions && !args.isEmpty() )
0511 {
0512 cerr << "ERROR: The --list-sessions option cannot be used for actual DCOP calls!" << endl << endl;
0513 showHelp( -1 );
0514 }
0515
0516 if( session == QuerySessions && user.isEmpty() )
0517 {
0518 cerr << "ERROR: The --list-sessions option can only be used with the --user or" << endl
0519 << "--all-users options!" << endl << endl;
0520 showHelp( -1 );
0521 }
0522
0523 if( session != DefaultSession && session != QuerySessions &&
0524 args.count() < 3 )
0525 {
0526 cerr << "ERROR: The --session and --all-sessions options are only supported for function" << endl
0527 << "calls!" << endl << endl;
0528 showHelp( -1 );
0529 }
0530
0531 UserList users;
0532 if( user == "*" )
0533 users = userList();
0534 else if( !user.isEmpty() )
0535 users[ user ] = userList()[ user ];
0536
0537 runDCOP( args, users, session, sessionName, readStdin );
0538 a343 3
0539
0540 // vim: set ts=8 sts=4 sw=4 noet:
0541
0542 diff -nr dcop/client/dcopfind.cpp dcop2/client/dcopfind.cpp
0543 d39 1
0544 a39 1
0545 bool findObject( const char* app, const char* obj, const char* func, QCStringList args )
0546 d121 1
0547 a121 1
0548 if ( types.count() != args.count() ) {
0549 d131 1
0550 a131 1
0551 marshall(arg, args, i, *it);
0552 d133 1
0553 a133 1
0554 if ( (uint) i != args.count() ) {
0555 d224 1
0556 a224 5
0557 QCStringList params;
0558 for( int i = 0; i < argc; i++ )
0559 params.append( args[ i ] );
0560
0561 findObject( app, objid, function, params );
0562 diff -nr dcop/client/marshall.cpp dcop2/client/marshall.cpp
0563 d245 1
0564 a245 1
0565 void marshall( QDataStream &arg, QCStringList args, uint &i, QString type )
0566 d247 71
0567 a317 10
0568 if (type == "QStringList")
0569 type = "QValueList<QString>";
0570 if (type == "QCStringList")
0571 type = "QValueList<QCString>";
0572 if( i > args.count() )
0573 {
0574 qWarning("Not enough arguments.");
0575 exit(1);
0576 }
0577 QString s = QString::fromLocal8Bit( args[ i ] );
0578 d319 28
0579 a346 57
0580 if ( type == "int" )
0581 arg << s.toInt();
0582 else if ( type == "uint" )
0583 arg << s.toUInt();
0584 else if ( type == "unsigned" )
0585 arg << s.toUInt();
0586 else if ( type == "unsigned int" )
0587 arg << s.toUInt();
0588 else if ( type == "long" )
0589 arg << s.toLong();
0590 else if ( type == "long int" )
0591 arg << s.toLong();
0592 else if ( type == "unsigned long" )
0593 arg << s.toULong();
0594 else if ( type == "unsigned long int" )
0595 arg << s.toULong();
0596 else if ( type == "float" )
0597 arg << s.toFloat();
0598 else if ( type == "double" )
0599 arg << s.toDouble();
0600 else if ( type == "bool" )
0601 arg << mkBool( s );
0602 else if ( type == "QString" )
0603 arg << s;
0604 else if ( type == "QCString" )
0605 arg << QCString( args[ i ] );
0606 else if ( type == "QColor" )
0607 arg << mkColor( s );
0608 else if ( type == "QPoint" )
0609 arg << mkPoint( s );
0610 else if ( type == "QSize" )
0611 arg << mkSize( s );
0612 else if ( type == "QRect" )
0613 arg << mkRect( s );
0614 else if ( type == "QVariant" ) {
0615 if ( s == "true" || s == "false" )
0616 arg << QVariant( mkBool( s ), 42 );
0617 else if ( s.left( 4 ) == "int(" )
0618 arg << QVariant( s.mid(4, s.length()-5).toInt() );
0619 else if ( s.left( 7 ) == "QPoint(" )
0620 arg << QVariant( mkPoint( s.mid(7, s.length()-8) ) );
0621 else if ( s.left( 6 ) == "QSize(" )
0622 arg << QVariant( mkSize( s.mid(6, s.length()-7) ) );
0623 else if ( s.left( 6 ) == "QRect(" )
0624 arg << QVariant( mkRect( s.mid(6, s.length()-7) ) );
0625 else if ( s.left( 7 ) == "QColor(" )
0626 arg << QVariant( mkColor( s.mid(7, s.length()-8) ) );
0627 else
0628 arg << QVariant( s );
0629 } else if ( type.startsWith("QValueList<")) {
0630 type = type.mid(11, type.length() - 12);
0631 QStringList list;
0632 QString delim = s;
0633 if (delim == "[")
0634 delim = "]";
0635 if (delim == "(")
0636 delim = ")";
0637 a347 34
0638 QByteArray dummy_data;
0639 QDataStream dummy_arg(dummy_data, IO_WriteOnly);
0640
0641 uint j = i;
0642 uint count = 0;
0643 // Parse list to get the count
0644 while (true) {
0645 if( j > args.count() )
0646 {
0647 qWarning("List end-delimiter '%s' not found.", delim.latin1());
0648 exit(1);
0649 }
0650 if( QString::fromLocal8Bit( args[ j ] ) == delim )
0651 break;
0652 marshall( dummy_arg, args, j, type );
0653 count++;
0654 }
0655 arg << (Q_UINT32) count;
0656 // Parse the list for real
0657 while (true) {
0658 if( i > args.count() )
0659 {
0660 qWarning("List end-delimiter '%s' not found.", delim.latin1());
0661 exit(1);
0662 }
0663 if( QString::fromLocal8Bit( args[ i ] ) == delim )
0664 break;
0665 marshall( arg, args, i, type );
0666 }
0667 } else {
0668 qWarning( "cannot handle datatype '%s'", type.latin1() );
0669 exit(1);
0670 }
0671 i++;