• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkleo

  • sources
  • kde-4.12
  • kdepim
  • libkleo
  • backends
  • qgpgme
qgpgmerefreshkeysjob.cpp
Go to the documentation of this file.
1 /*
2  qgpgmerefreshkeysjob.cpp
3 
4  This file is part of libkleopatra, the KDE keymanagement library
5  Copyright (c) 2004 Klar�vdalens Datakonsult AB
6 
7  Libkleopatra is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of the
10  License, or (at your option) any later version.
11 
12  Libkleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License along
18  with this program; if not, write to the Free Software Foundation, Inc.,
19  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #define MAX_CMD_LENGTH 32768
34 
35 #include "qgpgmerefreshkeysjob.h"
36 
37 #include "gnupgprocessbase.h"
38 #include "qgpgmeprogresstokenmapper.h"
39 
40 #include <kdebug.h>
41 
42 #include <gpgme++/context.h>
43 
44 #include <QByteArray>
45 #include <QStringList>
46 
47 #include <gpg-error.h>
48 
49 #include <assert.h>
50 
51 Kleo::QGpgMERefreshKeysJob::QGpgMERefreshKeysJob()
52  : RefreshKeysJob( 0 ),
53  mProcess( 0 ),
54  mError( 0 )
55 {
56 
57 }
58 
59 Kleo::QGpgMERefreshKeysJob::~QGpgMERefreshKeysJob() {
60 
61 }
62 
63 GpgME::Error Kleo::QGpgMERefreshKeysJob::start( const QStringList & patterns ) {
64  assert( mPatternsToDo.empty() );
65 
66  mPatternsToDo = patterns;
67  if ( mPatternsToDo.empty() )
68  mPatternsToDo.push_back( QLatin1String(" ") ); // empty list means all -> mae
69  // sure to fail the first
70  // startAProcess() guard clause
71 
72  return startAProcess();
73 }
74 
75 #if MAX_CMD_LENGTH < 65 + 128
76 #error MAX_CMD_LENGTH is too low
77 #endif
78 
79 GpgME::Error Kleo::QGpgMERefreshKeysJob::startAProcess() {
80  if ( mPatternsToDo.empty() )
81  return GpgME::Error();
82  // create and start gpgsm process:
83  mProcess = new GnuPGProcessBase( this );
84  mProcess->setObjectName( QLatin1String("gpgsm -k --with-validation --force-crl-refresh --enable-crl-checks") );
85 
86  // FIXME: obbtain the path to gpgsm from gpgme, so we use the same instance.
87  *mProcess << QLatin1String("gpgsm") << QLatin1String("-k") << QLatin1String("--with-validation") << QLatin1String("--force-crl-refresh")
88  << QLatin1String("--enable-crl-checks");
89  unsigned int commandLineLength = MAX_CMD_LENGTH;
90  commandLineLength -=
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 )
98  break;
99  mPatternsToDo.pop_front();
100  if ( pat.isEmpty() )
101  continue;
102  *mProcess << QLatin1String(pat);
103  commandLineLength -= patLength + 1;
104  }
105 
106  mProcess->setUseStatusFD( true );
107 
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()) );
114 
115  connect( mProcess, SIGNAL(status(Kleo::GnuPGProcessBase*,QString,QStringList)),
116  SLOT(slotStatus(Kleo::GnuPGProcessBase*,QString,QStringList)) );
117 
118  mProcess->setOutputChannelMode( KProcess::SeparateChannels );
119  mProcess->start();
120  if ( !mProcess->waitForStarted() ) {
121  mError = GpgME::Error::fromCode( GPG_ERR_ENOENT, GPG_ERR_SOURCE_GPGSM ); // what else?
122  deleteLater();
123  return mError;
124  } else
125  return GpgME::Error();
126 }
127 
128 void Kleo::QGpgMERefreshKeysJob::slotCancel() {
129  if ( mProcess )
130  mProcess->kill();
131  mProcess = 0;
132  mError = GpgME::Error::fromCode( GPG_ERR_CANCELED, GPG_ERR_SOURCE_GPGSM );
133 }
134 
135 void Kleo::QGpgMERefreshKeysJob::slotStatus( GnuPGProcessBase * proc, const QString & type, const QStringList & args ) {
136  if ( proc != mProcess )
137  return;
138  QStringList::const_iterator it = args.begin();
139  bool ok = false;
140 
141  if ( type == QLatin1String("ERROR") ) {
142 
143 
144  if ( args.size() < 2 ) {
145  kDebug( 5150 ) <<"not recognising ERROR with < 2 args!";
146  return;
147  }
148  const int source = (*++it).toInt( &ok );
149  if ( !ok ) {
150  kDebug( 5150 ) <<"expected number for first ERROR arg, got something else";
151  return;
152  }
153  ok = false;
154  const int code = (*++it).toInt( &ok );
155  if ( !ok ) {
156  kDebug( 5150 ) <<"expected number for second ERROR arg, got something else";
157  return;
158  }
159  mError = GpgME::Error::fromCode( code, source );
160 
161 
162  } else if ( type == QLatin1String("PROGRESS") ) {
163 
164 
165  if ( args.size() < 4 ) {
166  kDebug( 5150 ) <<"not recognising PROGRESS with < 4 args!";
167  return;
168  }
169  const QString what = *++it;
170  ok = false;
171  const int typ = (*++it).toInt( &ok );
172  if ( !ok ) {
173  kDebug( 5150 ) <<"expected number for \"type\", got something else";
174  return;
175  }
176  ok = false;
177  const int cur = (*++it).toInt( &ok );
178  if ( !ok ) {
179  kDebug( 5150 ) <<"expected number for \"cur\", got something else";
180  return;
181  }
182  ok = false;
183  const int total = (*++it).toInt( &ok );
184  if ( !ok ) {
185  kDebug( 5150 ) <<"expected number for \"total\", got something else";
186  return;
187  }
188  emit progress( QGpgMEProgressTokenMapper::map( what, typ ), cur, total );
189 
190 
191  }
192 }
193 
194 void Kleo::QGpgMERefreshKeysJob::slotStderr() {
195  // implement? or not?
196 }
197 
198 void Kleo::QGpgMERefreshKeysJob::slotProcessExited(int exitCode, QProcess::ExitStatus exitStatus) {
199  if ( !mError && !mPatternsToDo.empty() ) {
200  if ( const GpgME::Error err = startAProcess() )
201  mError = err;
202  else
203  return;
204  }
205 
206  emit done();
207  if ( !mError &&
208  ( exitStatus != QProcess::NormalExit || exitCode != 0 ) )
209  mError = GpgME::Error::fromCode( GPG_ERR_GENERAL, GPG_ERR_SOURCE_GPGSM );
210  emit result( mError );
211  deleteLater();
212 }
213 
214 #include "qgpgmerefreshkeysjob.moc"
Kleo::RefreshKeysJob
An abstract base class for asynchronous key refreshers.
Definition: refreshkeysjob.h:62
source
const char * source
Definition: keylistview.cpp:69
Kleo::QGpgMERefreshKeysJob::~QGpgMERefreshKeysJob
~QGpgMERefreshKeysJob()
Definition: qgpgmerefreshkeysjob.cpp:59
QString
Kleo::QGpgMERefreshKeysJob::start
GpgME::Error start(const QStringList &patterns)
Definition: qgpgmerefreshkeysjob.cpp:63
Kleo::QGpgMEProgressTokenMapper::map
QString map(const char *token, int subtoken)
Definition: qgpgmeprogresstokenmapper.cpp:91
gnupgprocessbase.h
MAX_CMD_LENGTH
#define MAX_CMD_LENGTH
Definition: qgpgmerefreshkeysjob.cpp:33
qgpgmeprogresstokenmapper.h
Kleo::QGpgMERefreshKeysJob::QGpgMERefreshKeysJob
QGpgMERefreshKeysJob()
Definition: qgpgmerefreshkeysjob.cpp:51
Kleo::GnuPGProcessBase
a base class for GPG and GPGSM processes.
Definition: gnupgprocessbase.h:49
qgpgmerefreshkeysjob.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:57:49 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkleo

Skip menu "libkleo"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal