33 #define MAX_CMD_LENGTH 32768 
   42 #include <gpgme++/context.h> 
   45 #include <QStringList> 
   47 #include <gpg-error.h> 
   64   assert( mPatternsToDo.empty() );
 
   66   mPatternsToDo = patterns;
 
   67   if ( mPatternsToDo.empty() )
 
   68     mPatternsToDo.push_back( QLatin1String(
" ") ); 
 
   72   return startAProcess();
 
   75 #if MAX_CMD_LENGTH < 65 + 128 
   76 #error MAX_CMD_LENGTH is too low 
   79 GpgME::Error Kleo::QGpgMERefreshKeysJob::startAProcess() {
 
   80   if ( mPatternsToDo.empty() )
 
   81     return GpgME::Error();
 
   84   mProcess->setObjectName( QLatin1String(
"gpgsm -k --with-validation --force-crl-refresh --enable-crl-checks") );
 
   87   *mProcess << QLatin1String(
"gpgsm") << QLatin1String(
"-k") << QLatin1String(
"--with-validation") << QLatin1String(
"--force-crl-refresh")
 
   88             << QLatin1String(
"--enable-crl-checks");
 
   91     strlen(
"gpgsm") + 1 + strlen(
"-k") + 1 +
 
   92     strlen(
"--with-validation") + 1 + strlen(
"--force-crl-refresh") + 1 +
 
   93     strlen(
"--enable-crl-checks") + 1;
 
   94   while ( !mPatternsToDo.empty() ) {
 
   95     const QByteArray pat = mPatternsToDo.front().toUtf8().trimmed();
 
   96     const unsigned int patLength = pat.length();
 
   97     if ( patLength >= commandLineLength )
 
   99     mPatternsToDo.pop_front();
 
  102     *mProcess << QLatin1String(pat);
 
  103     commandLineLength -= patLength + 1;
 
  106   mProcess->setUseStatusFD( 
true );
 
  108   connect( mProcess, SIGNAL(finished(
int,QProcess::ExitStatus)),
 
  109            SLOT(slotProcessExited(
int,QProcess::ExitStatus)) );
 
  110   connect( mProcess, SIGNAL(readyReadStandardOutput()),
 
  111            SLOT(slotStdout()) );
 
  112   connect( mProcess, SIGNAL(readyReadStandardError()),
 
  113            SLOT(slotStderr()) );
 
  118   mProcess->setOutputChannelMode( KProcess::SeparateChannels );
 
  120   if ( !mProcess->waitForStarted() ) {
 
  121     mError = GpgME::Error::fromCode( GPG_ERR_ENOENT, GPG_ERR_SOURCE_GPGSM ); 
 
  125     return GpgME::Error();
 
  128 void Kleo::QGpgMERefreshKeysJob::slotCancel() {
 
  132   mError = GpgME::Error::fromCode( GPG_ERR_CANCELED, GPG_ERR_SOURCE_GPGSM );
 
  135 void Kleo::QGpgMERefreshKeysJob::slotStatus( GnuPGProcessBase * proc, 
const QString & type, 
const QStringList & args ) {
 
  136   if ( proc != mProcess )
 
  138   QStringList::const_iterator it = args.begin();
 
  141   if ( type == QLatin1String(
"ERROR") ) {
 
  144     if ( args.size() < 2 ) {
 
  145       kDebug( 5150 ) <<
"not recognising ERROR with < 2 args!";
 
  148     const int source = (*++it).toInt( &ok );
 
  150       kDebug( 5150 ) <<
"expected number for first ERROR arg, got something else";
 
  154     const int code = (*++it).toInt( &ok );
 
  156       kDebug( 5150 ) <<
"expected number for second ERROR arg, got something else";
 
  159     mError = GpgME::Error::fromCode( code, source );
 
  162   } 
else if ( type == QLatin1String(
"PROGRESS") ) {
 
  165     if ( args.size() < 4 ) {
 
  166       kDebug( 5150 ) <<
"not recognising PROGRESS with < 4 args!";
 
  171     const int typ = (*++it).toInt( &ok );
 
  173         kDebug( 5150 ) <<
"expected number for \"type\", got something else";
 
  177     const int cur = (*++it).toInt( &ok );
 
  179       kDebug( 5150 ) <<
"expected number for \"cur\", got something else";
 
  183     const int total = (*++it).toInt( &ok );
 
  185       kDebug( 5150 ) <<
"expected number for \"total\", got something else";
 
  194 void Kleo::QGpgMERefreshKeysJob::slotStderr() {
 
  198 void Kleo::QGpgMERefreshKeysJob::slotProcessExited(
int exitCode, QProcess::ExitStatus exitStatus) {
 
  199   if ( !mError && !mPatternsToDo.empty() ) {
 
  200     if ( 
const GpgME::Error err = startAProcess() )
 
  208        ( exitStatus != QProcess::NormalExit || exitCode != 0 ) )
 
  209     mError = GpgME::Error::fromCode( GPG_ERR_GENERAL, GPG_ERR_SOURCE_GPGSM );
 
  210   emit result( mError );
 
  214 #include "qgpgmerefreshkeysjob.moc" 
An abstract base class for asynchronous key refreshers. 
 
GpgME::Error start(const QStringList &patterns)
 
QString map(const char *token, int subtoken)
 
a base class for GPG and GPGSM processes.