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

kleopatra

  • sources
  • kde-4.14
  • kdepim
  • kleopatra
  • selftest
enginecheck.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  selftest/enginecheck.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2008 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 "enginecheck.h"
36 
37 #include "implementation_p.h"
38 
39 #include <gpgme++/global.h>
40 #include <gpgme++/engineinfo.h>
41 #include <gpgme++/error.h>
42 
43 #include <gpg-error.h>
44 
45 #include <KLocalizedString>
46 #include <KDebug>
47 
48 #include <QFile>
49 #include <QRegExp>
50 
51 #ifndef Q_MOC_RUN
52 #include <boost/shared_ptr.hpp>
53 #include <boost/range.hpp>
54 #endif
55 
56 #include <algorithm>
57 #include <cassert>
58 
59 using namespace Kleo;
60 using namespace Kleo::_detail;
61 using namespace GpgME;
62 using namespace boost;
63 
64 static QString engine_name( GpgME::Engine eng ) {
65  static const char * engines[] = {
66  "gpg", "gpgsm", "gpgconf"
67  };
68  return QString::fromLatin1( engines[eng] );
69 }
70 
71 static QString test_name( GpgME::Engine eng ) {
72  static const char * names[] = {
73  I18N_NOOP2( "@title", "GPG (OpenPGP Backend) installation" ),
74  I18N_NOOP2( "@title", "GpgSM (S/MIME Backend) installation" ),
75  I18N_NOOP2( "@title", "GpgConf (Configuration) installation" ),
76  };
77  return i18nc( "@title", names[eng] );
78 }
79 
80 namespace {
81 
82  class EngineCheck : public SelfTestImplementation {
83  public:
84  explicit EngineCheck( GpgME::Engine eng )
85  : SelfTestImplementation( test_name( eng ) )
86  {
87  runTest( eng );
88  }
89 
90  void runTest( GpgME::Engine eng ) {
91  const Error err = GpgME::checkEngine( eng );
92  assert( !err.code() || err.code() == GPG_ERR_INV_ENGINE );
93 
94  m_passed = !err;
95 
96  if ( m_passed )
97  return;
98 
99  m_explaination = i18nc("@info",
100  "<para>A problem was detected with the <application>%1</application> backend.</para>",
101  engine_name( eng ) );
102 
103  const EngineInfo ei = engineInfo( eng );
104  if ( ei.isNull() ) {
105  m_error = i18n("not supported");
106  m_explaination += i18nc("@info",
107  "<para>It seems that the <icode>gpgme</icode> library was compiled without "
108  "support for this backend.</para>");
109  m_proposedFix += i18nc("@info",
110  "<para>Replace the <icode>gpgme</icode> library with a version compiled "
111  "with <application>%1</application> support.</para>",
112  engine_name( eng ) );
113  } else if ( ei.fileName() && !ei.version() ) {
114  m_error = i18n("not properly installed");
115  m_explaination += i18nc("@info",
116  "<para>Backend <command>%1</command> is not installed properly.</para>", QFile::decodeName( ei.fileName() ) );
117  m_proposedFix += i18nc( "@info",
118  "<para>Please check the output of <command>%1 --version</command> manually.</para>",
119  QFile::decodeName( ei.fileName() ) );
120  } else if ( ei.fileName() && ei.version() && ei.requiredVersion() ) {
121  m_error = i18n("too old");
122  m_explaination += i18nc("@info",
123  "<para>Backend <command>%1</command> is installed in version %2, "
124  "but at least version %3 is required.</para>",
125  QFile::decodeName( ei.fileName() ),
126  QString::fromUtf8( ei.version() ),
127  QString::fromUtf8( ei.requiredVersion() ) );
128  m_proposedFix += i18nc( "@info",
129  "<para>Install <application>%1</application> version %2 or higher.</para>",
130  engine_name( eng ), QString::fromUtf8( ei.requiredVersion() ) );
131  } else {
132  m_error = m_explaination = i18n("unknown problem");
133  m_proposedFix += i18nc( "@info",
134  "<para>Make sure <application>%1</application> is installed and "
135  "in <envar>PATH</envar>.</para>",
136  engine_name( eng ) );
137  }
138  }
139 
140  };
141 }
142 
143 shared_ptr<SelfTest> Kleo::makeGpgEngineCheckSelfTest() {
144  return shared_ptr<SelfTest>( new EngineCheck( GpgME::GpgEngine ) );
145 }
146 
147 shared_ptr<SelfTest> Kleo::makeGpgSmEngineCheckSelfTest() {
148  return shared_ptr<SelfTest>( new EngineCheck( GpgME::GpgSMEngine ) );
149 }
150 
151 shared_ptr<SelfTest> Kleo::makeGpgConfEngineCheckSelfTest() {
152  return shared_ptr<SelfTest>( new EngineCheck( GpgME::GpgConfEngine ) );
153 }
154 
155 //
156 // SelfTestImplementation (parts)
157 //
158 
159 static bool is_version( const char * actual, int major, int minor, int patch ) {
160  QRegExp rx( QLatin1String("(\\d+)\\.(\\d+)\\.(\\d+)(?:-svn\\d+)?.*") );
161  if ( !rx.exactMatch( QString::fromUtf8( actual ) ) ) {
162  kDebug() << "Can't parse version " << actual;
163  return false;
164  }
165  bool ok;
166  int actual_version[3];
167  for ( int i = 0 ; i < 3 ; ++i ) {
168  ok = false;
169  actual_version[i] = rx.cap( i+1 ).toUInt( &ok );
170  assert( ok );
171  }
172 
173  kDebug() << "Parsed" << actual << "as: "
174  << actual_version[0] << '.'
175  << actual_version[1] << '.'
176  << actual_version[2] << '.' ;
177 
178  const int required_version[] = { major, minor, patch };
179 
180  // return ! ( actual_version < required_version )
181  ok = !std::lexicographical_compare( begin( actual_version ), end( actual_version ),
182  begin( required_version ), end( required_version ) );
183  kDebug( ok ) << QString::fromLatin1("%1.%2.%3" ).arg( major ).arg( minor ).arg( patch ) << "<=" << actual ;
184  kDebug( !ok ) << QString::fromLatin1( "%1.%2.%3" ).arg( major ).arg( minor ).arg( patch ) << ">" << actual ;
185  return ok;
186 }
187 
188 bool SelfTestImplementation::ensureEngineVersion( GpgME::Engine engine, int major, int minor, int patch ) {
189  const Error err = GpgME::checkEngine( engine );
190  assert( !err || err.code() == GPG_ERR_INV_ENGINE );
191 
192  const EngineInfo ei = GpgME::engineInfo( engine );
193 
194  m_skipped = err || !is_version( ei.version(), major, minor, patch );
195 
196  if ( !m_skipped )
197  return true;
198 
199  if ( !err && ei.version() ) {
200  // properly installed, but too old
201  m_explaination = i18nc( "@info",
202  "<para><application>%1</application> v%2.%3.%4 is required for this test, but only %5 is installed.</para>",
203  engine_name( engine ), major, minor, patch, QString::fromUtf8( ei.version() ) );
204  m_proposedFix += i18nc( "@info",
205  "<para>Install <application>%1</application> version %2 or higher.</para>",
206  engine_name( engine ), QString::fromLatin1( "%1.%2.%3" ).arg( major ).arg( minor ).arg( patch ) );
207  } else {
208  // not properly installed
209  m_explaination = i18nc( "@info",
210  "<para><application>%1</application> is required for this test, but does not seem available.</para>"
211  "<para>See tests further up for more information.</para>",
212  engine_name( engine ) );
213  m_proposedFix = i18nc( "@info %1: test name",
214  "<para>See \"%1\" above.</para>", test_name( engine ) );
215  }
216 
217  return false;
218 }
219 
QRegExp::cap
QString cap(int nth) const
QRegExp
boost::shared_ptr
Definition: encryptemailcontroller.h:51
QString::fromUtf8
QString fromUtf8(const char *str, int size)
is_version
static bool is_version(const char *actual, int major, int minor, int patch)
Definition: enginecheck.cpp:159
Kleo::makeGpgSmEngineCheckSelfTest
boost::shared_ptr< SelfTest > makeGpgSmEngineCheckSelfTest()
Definition: enginecheck.cpp:147
QString
Kleo::_detail::SelfTestImplementation::ensureEngineVersion
bool ensureEngineVersion(GpgME::Engine, int major, int minor, int patch)
Definition: enginecheck.cpp:188
test_name
static QString test_name(GpgME::Engine eng)
Definition: enginecheck.cpp:71
QLatin1String
enginecheck.h
QString::fromLatin1
QString fromLatin1(const char *str, int size)
implementation_p.h
Kleo::makeGpgConfEngineCheckSelfTest
boost::shared_ptr< SelfTest > makeGpgConfEngineCheckSelfTest()
Definition: enginecheck.cpp:151
Kleo::_detail::SelfTestImplementation
Definition: implementation_p.h:45
engine_name
static QString engine_name(GpgME::Engine eng)
Definition: enginecheck.cpp:64
QRegExp::exactMatch
bool exactMatch(const QString &str) const
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
Kleo::makeGpgEngineCheckSelfTest
boost::shared_ptr< SelfTest > makeGpgEngineCheckSelfTest()
Definition: enginecheck.cpp:143
QFile::decodeName
QString decodeName(const QByteArray &localFileName)
QString::toUInt
uint toUInt(bool *ok, int base) 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

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
  • pimprint

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