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

kleopatra

  • sources
  • kde-4.12
  • kdepim
  • kleopatra
  • uiserver
prepsigncommand.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  uiserver/prepsigncommand.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2007 Klarälvdalens Datakonsult AB
6 
7  Kleopatra is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  Kleopatra 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
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 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 #include <config-kleopatra.h>
34 
35 #include "prepsigncommand.h"
36 
37 #include <crypto/newsignencryptemailcontroller.h>
38 
39 #include <utils/kleo_assert.h>
40 
41 #include <kleo/exception.h>
42 
43 #include <KLocale>
44 
45 #include <QPointer>
46 #include <QTimer>
47 
48 using namespace Kleo;
49 using namespace Kleo::Crypto;
50 using namespace boost;
51 
52 class PrepSignCommand::Private : public QObject {
53  Q_OBJECT
54 private:
55  friend class ::Kleo::PrepSignCommand;
56  PrepSignCommand * const q;
57 public:
58  explicit Private( PrepSignCommand * qq )
59  : q( qq ), controller() {}
60 
61 private:
62  void checkForErrors() const;
63 
64 public Q_SLOTS:
65  void slotSignersResolved();
66  void slotError( int, const QString & );
67 
68 private:
69  shared_ptr<NewSignEncryptEMailController> controller;
70 };
71 
72 PrepSignCommand::PrepSignCommand()
73  : AssuanCommandMixin<PrepSignCommand>(), d( new Private( this ) )
74 {
75 
76 }
77 
78 PrepSignCommand::~PrepSignCommand() {}
79 
80 void PrepSignCommand::Private::checkForErrors() const {
81 
82  if ( !q->inputs().empty() || !q->outputs().empty() || !q->messages().empty() )
83  throw Exception( makeError( GPG_ERR_CONFLICT ),
84  i18n( "INPUT/OUTPUT/MESSAGE may only be given after PREP_SIGN" ) );
85 
86  if ( q->numFiles() )
87  throw Exception( makeError( GPG_ERR_CONFLICT ),
88  i18n( "PREP_SIGN is an email mode command, connection seems to be in filemanager mode" ) );
89 
90  if ( q->senders().empty() )
91  throw Exception( makeError( GPG_ERR_CONFLICT ),
92  i18n( "No SENDER given" ) );
93 
94  const shared_ptr<NewSignEncryptEMailController> m = q->mementoContent< shared_ptr<NewSignEncryptEMailController> >( NewSignEncryptEMailController::mementoName() );
95 
96  if ( m && m->isSigning() ) {
97 
98  if ( q->hasOption( "protocol" ) )
99  if ( m->protocol() != q->checkProtocol( EMail ) )
100  throw Exception( makeError( GPG_ERR_CONFLICT ),
101  i18n( "Protocol given conflicts with protocol determined by PREP_ENCRYPT in this session" ) );
102 
103  // ### check that any SENDER here is the same as the one for PREP_ENCRYPT
104 
105  // ### ditto RECIPIENT
106 
107  }
108 
109 }
110 
111 static void connectController( const QObject * controller, const QObject * d ) {
112  QObject::connect( controller, SIGNAL(certificatesResolved()), d, SLOT(slotSignersResolved()) );
113  QObject::connect( controller, SIGNAL(error(int,QString)), d, SLOT(slotError(int,QString)) );
114 }
115 
116 int PrepSignCommand::doStart() {
117 
118  d->checkForErrors();
119 
120  const shared_ptr<NewSignEncryptEMailController> seec = mementoContent< shared_ptr<NewSignEncryptEMailController> >( NewSignEncryptEMailController::mementoName() );
121 
122  if ( seec && seec->isSigning() ) {
123  // reuse the controller from a previous PREP_ENCRYPT --expect-sign, if available:
124  d->controller = seec;
125  connectController( seec.get(), d.get() );
126  seec->setExecutionContext( shared_from_this() );
127  if ( seec->areCertificatesResolved() )
128  QTimer::singleShot( 0, d.get(), SLOT(slotSignersResolved()) );
129  else
130  kleo_assert( seec->isResolvingInProgress() );
131  } else {
132  // use a new controller
133  d->controller.reset( new NewSignEncryptEMailController( shared_from_this() ) );
134 
135  const QString session = sessionTitle();
136  if ( !session.isEmpty() )
137  d->controller->setSubject( session );
138 
139  if ( hasOption( "protocol" ) )
140  // --protocol is optional for PREP_SIGN
141  d->controller->setProtocol( checkProtocol( EMail ) );
142 
143  d->controller->setEncrypting( false );
144  d->controller->setSigning( true );
145  connectController( d->controller.get(), d.get() );
146  d->controller->startResolveCertificates( recipients(), senders() );
147  }
148 
149  return 0;
150 }
151 
152 void PrepSignCommand::Private::slotSignersResolved() {
153  //hold local shared_ptr to member as q->done() deletes *this
154  const shared_ptr<NewSignEncryptEMailController> cont = controller;
155  QPointer<Private> that( this );
156 
157  try {
158 
159  q->sendStatus( "PROTOCOL", QLatin1String(controller->protocolAsString()) );
160  q->registerMemento( NewSignEncryptEMailController::mementoName(),
161  make_typed_memento( controller ) );
162  q->done();
163  return;
164 
165  } catch ( const Exception & e ) {
166  q->done( e.error(), e.message() );
167  } catch ( const std::exception & e ) {
168  q->done( makeError( GPG_ERR_UNEXPECTED ),
169  i18n("Caught unexpected exception in PrepSignCommand::Private::slotRecipientsResolved: %1",
170  QString::fromLocal8Bit( e.what() ) ) );
171  } catch ( ... ) {
172  q->done( makeError( GPG_ERR_UNEXPECTED ),
173  i18n("Caught unknown exception in PrepSignCommand::Private::slotRecipientsResolved") );
174  }
175  if ( that ) // isn't this always deleted here and thus unnecessary?
176  q->removeMemento( NewSignEncryptEMailController::mementoName() );
177  cont->cancel();
178 }
179 
180 void PrepSignCommand::Private::slotError( int err, const QString & details ) {
181  q->done( err, details );
182 }
183 
184 void PrepSignCommand::doCanceled() {
185  if ( d->controller )
186  d->controller->cancel();
187 }
188 
189 #include "prepsigncommand.moc"
connectController
static void connectController(const QObject *controller, const QObject *d)
Definition: prepsigncommand.cpp:111
Kleo::AssuanCommandMixin
Definition: assuancommand.h:367
kleo_assert.h
prepsigncommand.h
boost::shared_ptr< NewSignEncryptEMailController >
d
#define d
Definition: adduseridcommand.cpp:90
newsignencryptemailcontroller.h
kdtools::pimpl_ptr::get
T * get()
Definition: pimpl_ptr.h:39
kleo_assert
#define kleo_assert(cond)
Definition: kleo_assert.h:84
q
#define q
Definition: adduseridcommand.cpp:91
Kleo::PrepSignCommand::PrepSignCommand
PrepSignCommand()
Definition: prepsigncommand.cpp:72
Kleo::PrepSignCommand
Definition: prepsigncommand.h:42
Kleo::PrepSignCommand::~PrepSignCommand
virtual ~PrepSignCommand()
Definition: prepsigncommand.cpp:78
Kleo::Crypto::NewSignEncryptEMailController
Definition: newsignencryptemailcontroller.h:68
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:41 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

Skip menu "kleopatra"
  • 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