~ubuntu-branches/ubuntu/precise/konsole/precise-proposed

« back to all changes in this revision

Viewing changes to src/ProcessInfo.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-16 13:14:43 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: package-import@ubuntu.com-20111216131443-rhdplbmmuxntat3k
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <pwd.h>
30
30
 
31
31
// Qt
32
 
#include <KDebug>
33
32
#include <QtCore/QDir>
34
33
#include <QtCore/QFileInfo>
35
34
#include <QtCore/QRegExp>
41
40
#include <KGlobal>
42
41
#include <KSharedConfig>
43
42
#include <KUser>
 
43
#include <KDebug>
44
44
 
45
45
#if defined(Q_OS_MAC)
46
46
#include <sys/sysctl.h>
120
120
   // search for and replace known marker
121
121
   output.replace("%u",userName());
122
122
   output.replace("%n",name(&ok));
123
 
   output.replace("%c",formatCommand(name(&ok),arguments(&ok),ShortCommandFormat));
124
 
   output.replace("%C",formatCommand(name(&ok),arguments(&ok),LongCommandFormat));
125
 
   
 
123
   // TODO: un-comment me when ProcessInfo::formatCommand() is implemented.
 
124
   //output.replace("%c",formatCommand(name(&ok),arguments(&ok),ShortCommandFormat));
 
125
   //output.replace("%C",formatCommand(name(&ok),arguments(&ok),LongCommandFormat));
 
126
 
126
127
   QString dir = validCurrentDir();
127
128
   if (output.contains("%D"))
128
129
   {
137
138
      output.replace("%D", tempDir);
138
139
   }
139
140
   output.replace("%d",formatShortDir(dir));
140
 
   
 
141
 
141
142
   // remove any remaining %[LETTER] sequences
142
143
   // output.replace(QRegExp("%\\w"), QString());
143
144
 
413
414
    if (!ok) return;
414
415
 
415
416
    struct passwd passwdStruct;
416
 
    struct passwd *getpwResult;
417
 
    char *getpwBuffer;
 
417
    struct passwd* getpwResult;
 
418
    char* getpwBuffer;
418
419
    long getpwBufferSize;
419
420
    int getpwStatus;
420
421
 
583
584
 
584
585
            QStringList argList = data.split( QChar('\0') );
585
586
 
586
 
            foreach ( const QString &entry , argList )
 
587
            foreach ( const QString& entry , argList )
587
588
            {
588
589
                if (!entry.isEmpty())
589
590
                    addArgument(entry);
633
634
 
634
635
            QStringList bindingList = data.split( QChar('\0') );
635
636
 
636
 
            foreach( const QString &entry , bindingList )
 
637
            foreach( const QString& entry , bindingList )
637
638
            {
638
639
                QString name;
639
640
                QString value;
996
997
 
997
998
    // SSH options
998
999
    // these are taken from the SSH manual ( accessed via 'man ssh' )
999
 
    
 
1000
 
1000
1001
    // options which take no arguments
1001
 
    static const QString noOptionsArguments("1246AaCfgkMNnqsTtVvXxY"); 
 
1002
    static const QString noArgumentOptions("1246AaCfgkMNnqsTtVvXxY"); 
1002
1003
    // options which take one argument
1003
 
    static const QString singleOptionArguments("bcDeFiLlmOopRSw");
 
1004
    static const QString singleArgumentOptions("bcDeFiLlmOopRSw");
1004
1005
 
1005
1006
    if ( ok )
1006
1007
    {
1018
1019
         // program name ( expected to be 'ssh' in this case )
1019
1020
         for ( int i = 1 ; i < args.count() ; i++ )
1020
1021
         {
1021
 
            // if this argument is an option then skip it, plus any 
1022
 
            // following arguments which refer to this option
 
1022
            // If this one is an option ...
 
1023
            // Most options together with its argument will be skipped.
1023
1024
            if ( args[i].startsWith('-') )
1024
1025
            {
1025
 
                QChar argChar = ( args[i].length() > 1 ) ? args[i][1] : '\0';
 
1026
                QChar optionChar = ( args[i].length() > 1 ) ? args[i][1] : '\0';
 
1027
                // for example: -p2222 or -p 2222 ?
 
1028
                bool optionArgumentCombined =  args[i].length() > 2 ;
1026
1029
 
1027
 
                if ( noOptionsArguments.contains(argChar) )
 
1030
                if ( noArgumentOptions.contains(optionChar) )
 
1031
                {
1028
1032
                    continue;
1029
 
                else if ( singleOptionArguments.contains(argChar) )
 
1033
                }
 
1034
                else if ( singleArgumentOptions.contains(optionChar) )
1030
1035
                {
1031
 
                    i++;
 
1036
                    QString argument ;
 
1037
                    if ( optionArgumentCombined )
 
1038
                    {
 
1039
                        argument = args[i].mid(2);
 
1040
                    }
 
1041
                    else
 
1042
                    {
 
1043
                        argument = args[i+1] ;
 
1044
                        i++;
 
1045
                    }
 
1046
 
 
1047
                    // support using `-l user` to specify username.
 
1048
                    if ( optionChar == 'l' )
 
1049
                        _user = argument;
 
1050
                    // support using `-p port` to specify port.
 
1051
                    else if ( optionChar == 'p' )
 
1052
                        _port = argument;
 
1053
 
1032
1054
                    continue;
1033
1055
                }
1034
1056
            }
1040
1062
                // check to see if only a hostname is specified, or whether
1041
1063
                // both a username and host are specified ( in which case they
1042
1064
                // are separated by an '@' character:  username@host )
1043
 
            
 
1065
 
1044
1066
                int separatorPosition = args[i].indexOf('@');
1045
1067
                if ( separatorPosition != -1 )
1046
1068
                {
1065
1087
    else
1066
1088
    {
1067
1089
        kWarning() << "Could not read arguments";
1068
 
        
 
1090
 
1069
1091
        return;
1070
1092
    }
1071
1093
}
1078
1100
{
1079
1101
    return _host;
1080
1102
}
 
1103
QString SSHProcessInfo::port() const
 
1104
{
 
1105
    return _port;
 
1106
}
1081
1107
QString SSHProcessInfo::command() const
1082
1108
{
1083
1109
    return _command;
1085
1111
QString SSHProcessInfo::format(const QString& input) const
1086
1112
{
1087
1113
    QString output(input);
1088
 
   
 
1114
 
1089
1115
    // test whether host is an ip address
1090
1116
    // in which case 'short host' and 'full host'
1091
1117
    // markers in the input string are replaced with
1092
1118
    // the full address
1093
1119
    bool isIpAddress = false;
1094
 
   
 
1120
 
1095
1121
    struct in_addr address;
1096
1122
    if ( inet_aton(_host.toLocal8Bit().constData(),&address) != 0 )
1097
1123
        isIpAddress = true;
1105
1131
        output.replace("%h",_host);
1106
1132
    else
1107
1133
        output.replace("%h",_host.left(_host.indexOf('.')));
1108
 
    
 
1134
 
1109
1135
    output.replace("%H",_host);
1110
1136
    output.replace("%c",_command);
1111
1137