kleopatra
assuanserverconnection.cpp
Go to the documentation of this file.
133 explicit AssuanContext( assuan_context_t ctx ) : AssuanContextBase( ctx, &assuan_deinit_server ) {}
135 explicit AssuanContext( assuan_context_t ctx ) : AssuanContextBase( ctx, &my_assuan_release ) {}
139 void reset( assuan_context_t ctx=0 ) { AssuanContextBase::reset( ctx, &assuan_deinit_server ); }
145 static inline gpg_error_t assuan_process_done_msg( assuan_context_t ctx, gpg_error_t err, const char * err_msg ) {
149 static inline gpg_error_t assuan_process_done_msg( assuan_context_t ctx, gpg_error_t err, const std::string & err_msg ) {
153 static inline gpg_error_t assuan_process_done_msg( assuan_context_t ctx, gpg_error_t err, const QString & err_msg ) {
157 static std::map<std::string,std::string> upcase_option( const char * option, std::map<std::string,std::string> options ) {
185 result[ std::string( begin, lastEQ - begin ) ] = hexdecode( std::string( lastEQ+1, line - (lastEQ+1) ) );
203 result[ std::string( begin, lastEQ - begin ) ] = hexdecode( std::string( lastEQ+1, line - (lastEQ+1 ) ) );
251 Private( assuan_fd_t fd_, const std::vector< shared_ptr<AssuanCommandFactory> > & factories_, AssuanServerConnection * qq );
328 AssuanServerConnection::Private & conn = *static_cast<AssuanServerConnection::Private*>( assuan_get_pointer( ctx_ ) );
340 static gpg_error_t option_handler( assuan_context_t ctx_, const char * key, const char * value ) {
344 AssuanServerConnection::Private & conn = *static_cast<AssuanServerConnection::Private*>( assuan_get_pointer( ctx_ ) );
360 AssuanServerConnection::Private & conn = *static_cast<AssuanServerConnection::Private*>( assuan_get_pointer( ctx_ ) );
400 return assuan_process_done( ctx_, assuan_send_data( ctx_, capabilities, sizeof capabilities - 1 ) );
409 AssuanServerConnection::Private & conn = *static_cast<AssuanServerConnection::Private*>( assuan_get_pointer( ctx_ ) );
442 AssuanServerConnection::Private & conn = *static_cast<AssuanServerConnection::Private*>( assuan_get_pointer( ctx_ ) );
460 AssuanServerConnection::Private & conn = *static_cast<AssuanServerConnection::Private*>( assuan_get_pointer( ctx_ ) );
482 AssuanServerConnection::Private & conn = *static_cast<AssuanServerConnection::Private*>( assuan_get_pointer( ctx_ ) );
495 /*const*/ std::map<std::string,std::string> options = upcase_option( "FD", upcase_option( "FILE", parse_commandline( line_ ) ) );
521 io = Input_or_Output<in>::type::createFromPipeDevice( fd, in ? i18n( "Message #%1", (conn.*which).size() + 1 ) : QString() );
537 throw Exception( gpg_error( GPG_ERR_INV_ARG ), i18n("Only files are allowed in INPUT/OUTPUT FILE") );
564 return assuan_process_done_msg( conn.ctx.get(), e.error().encodedError(), e.message().c_str() );
570 return assuan_process_done_msg( conn.ctx.get(), gpg_error( GPG_ERR_UNEXPECTED ), "unknown exception caught" );
605 AssuanServerConnection::Private & conn = *static_cast<AssuanServerConnection::Private*>( assuan_get_pointer( ctx_ ) );
620 return assuan_process_done_msg( conn.ctx.get(), e.error().encodedError(), e.message().toUtf8().constData() );
624 return assuan_process_done_msg( conn.ctx.get(), gpg_error( GPG_ERR_UNEXPECTED ), i18n("unknown exception caught").toUtf8().constData() );
667 static int recipient_sender_handler( T_memptr mp, T_memptr2 info, assuan_context_t ctx, char * line, bool sender=false ) {
669 static gpg_error_t recipient_sender_handler( T_memptr mp, T_memptr2 info, assuan_context_t ctx, char * line, bool sender=false ) {
672 AssuanServerConnection::Private & conn = *static_cast<AssuanServerConnection::Private*>( assuan_get_pointer( ctx ) );
694 (void)assuan_write_line( conn.ctx.get(), qPrintable( QString().sprintf( "# ok, parsed as \"%s\"", qPrintable( email ) ) ) );
706 return recipient_sender_handler( &Private::recipients, &Private::informativeRecipients, ctx, line );
714 return recipient_sender_handler( &Private::senders, &Private::informativeSenders, ctx, line, true );
719 for ( std::map<std::string,QVariant>::const_iterator it = options.begin(), end = options.end() ; it != end ; ++it )
754 for ( std::map< QByteArray, shared_ptr<AssuanCommand::Memento> >::const_iterator it = mementos.begin(), end = mementos.end() ; it != end ; ++it ) {
802 std::vector< shared_ptr<AssuanCommandFactory> > factories; // sorted: _detail::ByName<std::less>
824 AssuanServerConnection::Private::Private( assuan_fd_t fd_, const std::vector< shared_ptr<AssuanCommandFactory> > & factories_, AssuanServerConnection * qq )
839 assert( __gnu_cxx::is_sorted( factories_.begin(), factories_.end(), _detail::ByName<std::less>() ) );
847 if ( const gpg_error_t err = assuan_init_socket_server_ext( &naked_ctx, fd, INIT_SOCKET_FLAGS ) )
875 const shared_ptr<QSocketNotifier> sn( new QSocketNotifier( (intptr_t)fd, QSocketNotifier::Read ), mem_fn( &QObject::deleteLater ) );
882 const shared_ptr<QSocketNotifier> sn( new QSocketNotifier( (intptr_t)fds[i], QSocketNotifier::Read ), mem_fn( &QObject::deleteLater ) );
898 if ( const gpg_error_t err = assuan_register_command( ctx.get(), "MESSAGE", message_handler, "" ) )
904 if ( const gpg_error_t err = assuan_register_command( ctx.get(), "OUTPUT", output_handler, "" ) )
918 if ( const gpg_error_t err = assuan_register_command( ctx.get(), fac->name(), fac->_handler() ) )
920 if ( const gpg_error_t err = assuan_register_command( ctx.get(), fac->name(), fac->_handler(), "" ) )
927 if ( const gpg_error_t err = assuan_register_command( ctx.get(), "GETINFO", getinfo_handler, "" ) )
931 if ( const gpg_error_t err = assuan_register_command( ctx.get(), "START_KEYMANAGER", start_keymanager_handler ) )
933 if ( const gpg_error_t err = assuan_register_command( ctx.get(), "START_KEYMANAGER", start_keymanager_handler, "" ) )
937 if ( const gpg_error_t err = assuan_register_command( ctx.get(), "START_CONFDIALOG", start_confdialog_handler ) )
939 if ( const gpg_error_t err = assuan_register_command( ctx.get(), "START_CONFDIALOG", start_confdialog_handler, "" ) )
943 if ( const gpg_error_t err = assuan_register_command( ctx.get(), "RECIPIENT", recipient_handler ) )
945 if ( const gpg_error_t err = assuan_register_command( ctx.get(), "RECIPIENT", recipient_handler, "" ) )
951 if ( const gpg_error_t err = assuan_register_command( ctx.get(), "SENDER", sender_handler, "" ) )
957 if ( const gpg_error_t err = assuan_register_command( ctx.get(), "SESSION", session_handler, "" ) )
961 if ( const gpg_error_t err = assuan_register_command( ctx.get(), "CAPABILITIES", capabilities_handler ) )
963 if ( const gpg_error_t err = assuan_register_command( ctx.get(), "CAPABILITIES", capabilities_handler, "" ) )
967 assuan_set_hello_line( ctx.get(), "GPG UI server (Kleopatra/" KLEOPATRA_VERSION_STRING ") ready to serve" );
968 //assuan_set_hello_line( ctx.get(), GPG UI server (qApp->applicationName() + " v" + kapp->applicationVersion() + "ready to serve" )
988 AssuanServerConnection::AssuanServerConnection( assuan_fd_t fd, const std::vector< shared_ptr<AssuanCommandFactory> > & factories, QObject * p )
1033 static gpg_error_t handler( void * cb_data, gpg_error_t rc, unsigned char * buffer, size_t buflen )
1038 emit this_->signal( rc, QByteArray::fromRawData( reinterpret_cast<const char*>(buffer), buflen ), this_->keyword );
1048 emit this_->signal( rc, QByteArray::fromRawData( reinterpret_cast<const char*>(this_->buffer), this_->buflen ), this_->keyword );
1123 done( makeError( GPG_ERR_INTERNAL ), i18n("Caught unexpected exception: %1", QString::fromLocal8Bit( e.what() ) ) );
1127 done( makeError( GPG_ERR_INTERNAL ), i18n("Caught unknown exception - please report this error to the developers." ) );
1163 for ( typename std::map<U,V>::const_iterator it = map.begin(), end = map.end() ; it != end ; ++it )
1169 const std::map< QByteArray, shared_ptr<AssuanCommand::Memento> > & AssuanCommand::mementos() const {
1172 const AssuanServerConnection::Private & conn = *static_cast<AssuanServerConnection::Private*>( assuan_get_pointer( d->ctx.get() ) );
1178 return SessionDataHandler::instance()->sessionData(id)->mementos.count( tag ) || mementos().count( tag ) ;
1187 const std::map< QByteArray, shared_ptr<Memento> >::const_iterator it = sd->mementos.find( tag );
1203 QByteArray AssuanCommand::registerMemento( const QByteArray & tag, const shared_ptr<Memento> & mem ) {
1206 AssuanServerConnection::Private & conn = *static_cast<AssuanServerConnection::Private*>( assuan_get_pointer( d->ctx.get() ) );
1218 AssuanServerConnection::Private & conn = *static_cast<AssuanServerConnection::Private*>( assuan_get_pointer( d->ctx.get() ) );
1266 int AssuanCommand::inquire( const char * keyword, QObject * receiver, const char * slot, unsigned int maxSize ) {
1325 AssuanServerConnection::Private & conn = *static_cast<AssuanServerConnection::Private*>( assuan_get_pointer( d->ctx.get() ) );
1380 int AssuanCommandFactory::_handle( assuan_context_t ctx, char * line, const char * commandName ) {
1382 gpg_error_t AssuanCommandFactory::_handle( assuan_context_t ctx, char * line, const char * commandName ) {
1385 AssuanServerConnection::Private & conn = *static_cast<AssuanServerConnection::Private*>( assuan_get_pointer( ctx ) );
1390 = std::lower_bound( conn.factories.begin(), conn.factories.end(), commandName, _detail::ByName<std::less>() );
1413 for ( std::map<std::string,std::string>::const_iterator it = cmdline_options.begin(), end = cmdline_options.end() ; it != end ; ++it )
1419 return assuan_process_done_msg( conn.ctx.get(), gpg_error( GPG_ERR_ASS_PARAMETER ), "--nohup takes no argument" );
1436 return assuan_process_done_msg( conn.ctx.get(), gpg_error( GPG_ERR_UNEXPECTED ), i18n("Caught unknown exception") );
1471 return assuan_process_done_msg( ctx.get(), 0, "Command put in the background to continue executing after connection end." );
1482 return assuan_process_done_msg( ctx.get(), gpg_error( GPG_ERR_UNEXPECTED ), i18n("Caught unknown exception") );
1503 throw Exception( makeError( GPG_ERR_MISSING_VALUE ), i18n( "Required --mode option missing" ) );
1531 throw Exception( makeError( GPG_ERR_MISSING_VALUE ), i18n( "Required --protocol option missing" ) );
1543 throw Exception( makeError( GPG_ERR_INV_ARG ), i18n( "invalid protocol \"%1\"", protocolString ) );
shared_ptr< remove_pointer< assuan_context_t >::type > AssuanContextBase
Definition: assuanserverconnection.cpp:129
virtual ~AssuanCommand()
Definition: assuanserverconnection.cpp:1103
static void apply_window_id(QWidget *widget, const QString &winIdStr)
Definition: assuanserverconnection.cpp:222
~AssuanServerConnection()
Definition: assuanserverconnection.cpp:994
bool hasMemento(const QByteArray &tag) const
Definition: assuanserverconnection.cpp:1176
virtual void finalize()=0
static std::map< std::string, std::string > parse_commandline(const char *line)
Definition: assuanserverconnection.cpp:174
static gpg_error_t assuan_process_done_msg(assuan_context_t ctx, gpg_error_t err, const char *err_msg)
Definition: assuanserverconnection.cpp:145
void sendStatusEncoded(const char *keyword, const std::string &text)
Definition: assuanserverconnection.cpp:1249
Definition: assuancommand.h:249
boost::shared_ptr< Memento > memento(const QByteArray &tag) const
Definition: assuanserverconnection.cpp:1183
QByteArray fromRawData(const char *data, int size)
static std::map< std::string, std::string > upcase_option(const char *option, std::map< std::string, std::string > options)
Definition: assuanserverconnection.cpp:157
void removeMemento(const QByteArray &tag)
Definition: assuanserverconnection.cpp:1215
QString join(const QString &separator) const
static const unsigned int INIT_SOCKET_FLAGS
Definition: assuanserverconnection.cpp:116
QStringList fileNames() const
Definition: assuanserverconnection.cpp:1237
void setParent(QWidget *parent)
const std::vector< KMime::Types::Mailbox > & senders() const
Definition: assuanserverconnection.cpp:1375
void sendData(const QByteArray &data, bool moreToCome=false)
Definition: assuanserverconnection.cpp:1256
static WId wid_from_string(const QString &winIdStr, bool *ok=0)
Definition: assuanserverconnection.cpp:212
static boost::shared_ptr< SessionDataHandler > instance()
Definition: sessiondata.cpp:61
void resize(int size)
int inquire(const char *keyword, QObject *receiver, const char *slot, unsigned int maxSize=0)
Definition: assuanserverconnection.cpp:1266
QString fromLocal8Bit(const char *str, int size)
const std::vector< boost::shared_ptr< Output > > & outputs() const
Definition: assuanserverconnection.cpp:1233
QString fromUtf8(const char *str, int size)
Definition: classify.h:49
bool isEmpty() const
QByteArray number(int n, int base)
const char * constData() const
QVariant option(const char *opt) const
Definition: assuanserverconnection.cpp:1146
QString sessionTitle() const
Definition: assuanserverconnection.cpp:1355
Definition: output.h:73
Definition: classify.h:48
void enableCryptoCommands(bool enable=true)
Definition: assuanserverconnection.cpp:996
void deleteLater()
qulonglong toULongLong(bool *ok, int base) const
void sendStatus(const char *keyword, const QString &text)
Definition: assuanserverconnection.cpp:1245
const std::vector< KMime::Types::Mailbox > & recipients() const
Definition: assuanserverconnection.cpp:1371
static int _handle(assuan_context_s *, char *, const char *)
Definition: assuanserverconnection.cpp:1380
virtual void setBinaryOpt(bool value)=0
static int makeError(int code)
Definition: assuanserverconnection.cpp:1138
unsigned int numFiles() const
Definition: assuanserverconnection.cpp:1241
windowFlags
const std::vector< boost::shared_ptr< Input > > & inputs() const
Definition: assuanserverconnection.cpp:1225
void done(const GpgME::Error &err=GpgME::Error())
Definition: assuanserverconnection.cpp:1300
QWidget * find(WId id)
bool hasOption(const char *opt) const
Definition: assuanserverconnection.cpp:1142
Definition: detail_p.h:54
QByteArray registerMemento(const boost::shared_ptr< Memento > &mem)
Definition: assuanserverconnection.cpp:1198
QString fromLatin1(const char *str, int size)
GpgME::Protocol checkProtocol(Mode mode, int options=0) const
Definition: assuanserverconnection.cpp:1526
unsigned int sessionId() const
Definition: assuanserverconnection.cpp:1359
bool informativeSenders() const
Definition: assuanserverconnection.cpp:1363
int size() const
bool informativeRecipients() const
Definition: assuanserverconnection.cpp:1367
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
const std::map< std::string, QVariant > & options() const
Definition: assuanserverconnection.cpp:1154
QString decodeName(const QByteArray &localFileName)
const std::vector< boost::shared_ptr< Input > > & messages() const
Definition: assuanserverconnection.cpp:1229
singleShot
QByteArray toUtf8() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.