33 #include <config-kleopatra.h>
40 #include <kleo/exception.h>
42 #include <gpg-error.h>
44 #include <KLocalizedString>
54 using namespace boost;
58 class EchoCommand::Private {
60 Private() : operationsInFlight( 0 ), buffer() {}
62 int operationsInFlight;
71 int EchoCommand::doStart() {
73 const std::vector< shared_ptr<Input> > in = inputs(), msg = messages();
74 const std::vector< shared_ptr<Output> > out = outputs();
76 if ( !in.empty() && out.empty() )
77 return makeError( GPG_ERR_NOT_SUPPORTED );
80 return makeError( GPG_ERR_NOT_SUPPORTED );
83 return makeError( GPG_ERR_NOT_IMPLEMENTED );
86 if ( hasOption(
"inquire" ) ) {
88 keyword =
option(
"inquire").toString().toStdString();
94 if ( keyword.empty() )
95 return makeError( GPG_ERR_INV_ARG );
112 if ( !keyword.empty() ) {
113 if (
const int err = inquire( keyword.c_str(),
this,
117 ++d->operationsInFlight;
124 ++d->operationsInFlight;
126 connect( i.get(), SIGNAL(readyRead()),
this, SLOT(slotInputReadyRead()) );
127 connect( o.get(), SIGNAL(bytesWritten(qint64)),
this, SLOT(slotOutputBytesWritten()) );
129 if ( i->bytesAvailable() )
130 slotInputReadyRead();
133 if ( !d->operationsInFlight )
138 void EchoCommand::doCanceled() {
142 void EchoCommand::slotInquireData(
int rc,
const QByteArray & data ) {
144 --d->operationsInFlight;
153 if ( !d->operationsInFlight )
155 }
catch (
const Exception & e ) {
156 done( e.error(), e.message() );
157 }
catch (
const std::exception & e ) {
158 done( makeError( GPG_ERR_UNEXPECTED ),
159 i18n(
"Caught unexpected exception in SignCommand::Private::slotMicAlgDetermined: %1",
162 done( makeError( GPG_ERR_UNEXPECTED ),
163 i18n(
"Caught unknown exception in SignCommand::Private::slotMicAlgDetermined") );
168 void EchoCommand::slotInputReadyRead() {
173 buffer.
resize( in->bytesAvailable() );
174 const qint64 read = in->read( buffer.
data(), buffer.
size() );
176 done( makeError( GPG_ERR_EIO ) );
179 if ( read == 0 || (!in->isSequential() && read == in->size()) )
185 slotOutputBytesWritten();
189 void EchoCommand::slotOutputBytesWritten() {
193 if ( !d->buffer.isEmpty() ) {
195 if ( out->bytesToWrite() )
198 const qint64 written = out->write( d->buffer );
199 if ( written == -1 ) {
200 done( makeError( GPG_ERR_EIO ) );
203 d->buffer.remove( 0, written );
207 if ( out->isOpen() && d->buffer.isEmpty() && !inputs().at(0)->ioDevice()->isOpen() ) {
209 if ( !--d->operationsInFlight )
GnuPG UI Server command for testing.
QString fromLocal8Bit(const char *str, int size)
const char * constData() const
static const char option_prefix[]
QByteArray toLatin1() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)