37 #include "qgpgmerefreshkeysjob.h"
39 #include "gnupgprocessbase.h"
40 #include "qgpgmeprogresstokenmapper.h"
44 #include <gpgmepp/context.h>
46 #include <qgpgme/eventloopinteractor.h>
48 #include <tqstringlist.h>
50 #include <gpg-error.h>
54 Kleo::QGpgMERefreshKeysJob::QGpgMERefreshKeysJob()
55 : RefreshKeysJob( QGpgME::EventLoopInteractor::instance(),
"Kleo::QGpgMERefreshKeysJob" ),
62 Kleo::QGpgMERefreshKeysJob::~QGpgMERefreshKeysJob() {
66 GpgME::Error Kleo::QGpgMERefreshKeysJob::start(
const TQStringList & patterns ) {
67 assert( mPatternsToDo.empty() );
69 mPatternsToDo = patterns;
70 if ( mPatternsToDo.empty() )
71 mPatternsToDo.push_back(
" " );
75 return startAProcess();
78 #if MAX_CMD_LENGTH < 65 + 128
79 #error MAX_CMD_LENGTH is too low
82 GpgME::Error Kleo::QGpgMERefreshKeysJob::startAProcess() {
83 if ( mPatternsToDo.empty() )
86 mProcess =
new GnuPGProcessBase(
this,
"gpgsm -k --with-validation --force-crl-refresh --enable-crl-checks" );
89 *mProcess <<
"gpgsm" <<
"-k" <<
"--with-validation" <<
"--force-crl-refresh"
90 <<
"--enable-crl-checks";
91 unsigned int commandLineLength = MAX_CMD_LENGTH;
93 strlen(
"gpgsm") + 1 + strlen(
"-k") + 1 +
94 strlen(
"--with-validation") + 1 + strlen(
"--force-crl-refresh") + 1 +
95 strlen(
"--enable-crl-checks") + 1;
96 while ( !mPatternsToDo.empty() ) {
97 const TQCString pat = mPatternsToDo.front().utf8().stripWhiteSpace();
98 const unsigned int patLength = pat.length();
99 if ( patLength >= commandLineLength )
101 mPatternsToDo.pop_front();
105 commandLineLength -= patLength + 1;
108 mProcess->setUsetStatusFD(
true );
110 connect( mProcess, TQ_SIGNAL(processExited(TDEProcess*)),
111 TQ_SLOT(slotProcessExited(TDEProcess*)) );
112 connect( mProcess, TQ_SIGNAL(receivedStderr(TDEProcess*,
char*,
int)),
113 TQ_SLOT(slotStderr(TDEProcess*,
char*,
int)) );
117 if ( !mProcess->start( TDEProcess::NotifyOnExit, TDEProcess::Stderr ) ) {
118 mError = gpg_err_make( GPG_ERR_SOURCE_GPGSM, GPG_ERR_ENOENT );
125 void Kleo::QGpgMERefreshKeysJob::slotCancel() {
129 mError = gpg_err_make( GPG_ERR_SOURCE_GPGSM, GPG_ERR_CANCELED );
132 void Kleo::QGpgMERefreshKeysJob::slotStatus( GnuPGProcessBase * proc,
const TQString & type,
const TQStringList & args ) {
133 if ( proc != mProcess )
135 TQStringList::const_iterator it = args.begin();
138 if ( type ==
"ERROR" ) {
141 if ( args.size() < 2 ) {
142 kdDebug( 5150 ) <<
"Kleo::QGpgMERefreshKeysJob::slotStatus() not recognising ERROR with < 2 args!" << endl;
145 const int source = (*++it).toInt( &ok );
147 kdDebug( 5150 ) <<
"Kleo::QGpgMERefreshKeysJob::slotStatus() expected number for first ERROR arg, got something else" << endl;
151 const int code = (*++it).toInt( &ok );
153 kdDebug( 5150 ) <<
"Kleo::QGpgMERefreshKeysJob::slotStatus() expected number for second ERROR arg, got something else" << endl;
156 mError = gpg_err_make( (gpg_err_source_t)source, (gpg_err_code_t)code );
159 }
else if ( type ==
"PROGRESS" ) {
162 if ( args.size() < 4 ) {
163 kdDebug( 5150 ) <<
"Kleo::QGpgMERefreshKeysJob::slotStatus() not recognising PROGRESS with < 4 args!" << endl;
166 const TQString what = *++it;
168 const int cur = (*++it).toInt( &ok );
170 kdDebug( 5150 ) <<
"Kleo::QGpgMERefreshKeysJob::slotStatus() expected number for \"cur\", got something else" << endl;
174 const int total = (*++it).toInt( &ok );
176 kdDebug( 5150 ) <<
"Kleo::QGpgMERefreshKeysJob::slotStatus() expected number for \"total\", got something else" << endl;
179 emit progress( QGpgMEProgressTokenMapper::instance()->map( what, 0, cur, total ), cur, total );
185 void Kleo::QGpgMERefreshKeysJob::slotStderr( TDEProcess *,
char *,
int ) {
189 void Kleo::QGpgMERefreshKeysJob::slotProcessExited( TDEProcess * proc ) {
190 if ( proc != mProcess )
193 if ( !mError && !mPatternsToDo.empty() ) {
194 if (
const GpgME::Error err = startAProcess() ) {
204 ( !mProcess->normalExit() || mProcess->exitStatus() != 0 ) )
205 mError = gpg_err_make( GPG_ERR_SOURCE_GPGSM, GPG_ERR_GENERAL );
206 emit result( mError );
210 #include "qgpgmerefreshkeysjob.moc"
a base class for GPG and GPGSM processes.