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