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