33 #include <config-kleopatra.h>
40 #include <kleo/exception.h>
42 #include <gpg-error.h>
55 using namespace boost;
59 class EchoCommand::Private {
61 Private() : operationsInFlight( 0 ), buffer() {}
63 int operationsInFlight;
72 int EchoCommand::doStart() {
74 const std::vector< shared_ptr<Input> > in = inputs(), msg = messages();
75 const std::vector< shared_ptr<Output> > out = outputs();
77 if ( !in.empty() && out.empty() )
78 return makeError( GPG_ERR_NOT_SUPPORTED );
81 return makeError( GPG_ERR_NOT_SUPPORTED );
84 return makeError( GPG_ERR_NOT_IMPLEMENTED );
87 if ( hasOption(
"inquire" ) ) {
89 keyword =
option(
"inquire").toString().toStdString();
91 const QString tmpStr =
option(
"inquire").toString();
92 const QByteArray asc = tmpStr.toLatin1();
93 keyword =
std::string(asc.constData(), asc.length());
95 if ( keyword.empty() )
96 return makeError( GPG_ERR_INV_ARG );
102 const QString tmpStr =
option(
"text").toString();
103 const QByteArray asc = tmpStr.toLatin1();
110 sendStatus(
"ECHO", output.empty() ? QString() : QLatin1String(output.c_str()) );
113 if ( !keyword.empty() ) {
114 if (
const int err = inquire( keyword.c_str(),
this,
115 SLOT(slotInquireData(
int,QByteArray)) ) )
118 ++d->operationsInFlight;
125 ++d->operationsInFlight;
127 connect( i.get(), SIGNAL(readyRead()),
this, SLOT(slotInputReadyRead()) );
128 connect( o.get(), SIGNAL(bytesWritten(qint64)),
this, SLOT(slotOutputBytesWritten()) );
130 if ( i->bytesAvailable() )
131 slotInputReadyRead();
134 if ( !d->operationsInFlight )
139 void EchoCommand::doCanceled() {
143 void EchoCommand::slotInquireData(
int rc,
const QByteArray & data ) {
145 --d->operationsInFlight;
153 sendStatus(
"ECHOINQ", QLatin1String(data) );
154 if ( !d->operationsInFlight )
156 }
catch (
const Exception & e ) {
157 done( e.error(), e.message() );
158 }
catch (
const std::exception & e ) {
159 done( makeError( GPG_ERR_UNEXPECTED ),
160 i18n(
"Caught unexpected exception in SignCommand::Private::slotMicAlgDetermined: %1",
161 QString::fromLocal8Bit( e.what() ) ) );
163 done( makeError( GPG_ERR_UNEXPECTED ),
164 i18n(
"Caught unknown exception in SignCommand::Private::slotMicAlgDetermined") );
169 void EchoCommand::slotInputReadyRead() {
174 buffer.resize( in->bytesAvailable() );
175 const qint64 read = in->read( buffer.data(), buffer.size() );
177 done( makeError( GPG_ERR_EIO ) );
180 if ( read == 0 || (!in->isSequential() && read == in->size()) )
183 buffer.resize( read );
186 slotOutputBytesWritten();
190 void EchoCommand::slotOutputBytesWritten() {
194 if ( !d->buffer.isEmpty() ) {
196 if ( out->bytesToWrite() )
199 const qint64 written = out->write( d->buffer );
200 if ( written == -1 ) {
201 done( makeError( GPG_ERR_EIO ) );
204 d->buffer.remove( 0, written );
208 if ( out->isOpen() && d->buffer.isEmpty() && !inputs().at(0)->ioDevice()->isOpen() ) {
210 if ( !--d->operationsInFlight )
215 #include "moc_echocommand.cpp"
GnuPG UI Server command for testing.
static const char option_prefix[]