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