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

libkleo

chiasmuslibrary.cpp

Go to the documentation of this file.
00001 /*
00002     chiasmuslibrary.cpp
00003 
00004     This file is part of libkleopatra, the KDE keymanagement library
00005     Copyright (c) 2005 Klarälvdalens Datakonsult AB
00006 
00007     Libkleopatra is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU General Public License as
00009     published by the Free Software Foundation; either version 2 of the
00010     License, or (at your option) any later version.
00011 
00012     Libkleopatra is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021     In addition, as a special exception, the copyright holders give
00022     permission to link the code of this program with any edition of
00023     the Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), and distribute linked
00025     combinations including the two.  You must obey the GNU General
00026     Public License in all respects for all of the code used other than
00027     Qt.  If you modify this file, you may extend this exception to
00028     your version of the file, but you are not obligated to do so.  If
00029     you do not wish to do so, delete this exception statement from
00030     your version.
00031 */
00032 
00033 
00034 #include "chiasmuslibrary.h"
00035 
00036 #include "chiasmusbackend.h"
00037 
00038 #include "kleo/cryptoconfig.h"
00039 
00040 #include <klibloader.h>
00041 #include <kdebug.h>
00042 #include <klocale.h>
00043 
00044 #include <QFile>
00045 //Added by qt3to4:
00046 #include <QByteArray>
00047 
00048 #include <vector>
00049 #include <algorithm>
00050 
00051 #include <cassert>
00052 #include <cstdlib>
00053 #include <cstring>
00054 
00055 Kleo::ChiasmusLibrary * Kleo::ChiasmusLibrary::self = 0;
00056 
00057 Kleo::ChiasmusLibrary::ChiasmusLibrary() : mXiaLibrary( 0 ) {
00058   self = this;
00059 }
00060 
00061 Kleo::ChiasmusLibrary::~ChiasmusLibrary() {
00062   //delete mXiaLibrary; // hmm, how to get rid of it, then?
00063 }
00064 
00065 Kleo::ChiasmusLibrary::main_func Kleo::ChiasmusLibrary::chiasmus( QString * reason ) const {
00066   assert( ChiasmusBackend::instance() );
00067   assert( ChiasmusBackend::instance()->config() );
00068   const CryptoConfigEntry * lib = ChiasmusBackend::instance()->config()->entry( "Chiasmus", "General", "lib" );
00069   assert( lib );
00070   const QString libfile = lib->urlValue().path();
00071   if ( !mXiaLibrary )
00072     mXiaLibrary = KLibLoader::self()->library( libfile );
00073   if ( !mXiaLibrary ) {
00074     if ( reason )
00075       *reason = i18n( "Failed to load %1: %2",
00076                       libfile, KLibLoader::self()->lastErrorMessage() );
00077     kDebug(5150) <<"ChiasmusLibrary: loading \"" << libfile
00078                   << "\" failed:" << KLibLoader::self()->lastErrorMessage();
00079     return 0;
00080   }
00081   KLibrary::void_function_ptr symbol = mXiaLibrary->resolveFunction( "Chiasmus" );
00082   if ( !symbol ) {
00083     if ( reason )
00084       *reason = i18n( "Failed to load %1: %2",
00085                       libfile, i18n( "Library does not contain the symbol \"Chiasmus\"." ) );
00086     kDebug(5150) <<"ChiasmusLibrary: loading \"" << libfile
00087                   << "\" failed: " << "Library does not contain the symbol \"Chiasmus\".";
00088     return 0;
00089   }
00090 
00091   assert( symbol );
00092   return ( main_func )symbol;
00093 }
00094 
00095 namespace {
00096   class ArgvProvider {
00097     char ** mArgv;
00098     int mArgc;
00099   public:
00100     ArgvProvider( const QVector<QByteArray> & args ) {
00101       mArgv = new char * [args.size()];
00102       for ( int i = 0 ; i < args.size() ; ++i )
00103         mArgv[i] = strdup( args[i].data() );
00104     }
00105     ~ArgvProvider() {
00106       std::for_each( mArgv, mArgv + mArgc, std::free );
00107       delete[] mArgv;
00108     }
00109     char ** argv() const { return mArgv; }
00110   };
00111 }
00112 
00113 int Kleo::ChiasmusLibrary::perform( const QVector<QByteArray> & args ) const {
00114   if ( main_func func = chiasmus() )
00115     return func( args.size(), ArgvProvider( args ).argv() );
00116   else
00117     return -1;
00118 }

libkleo

Skip menu "libkleo"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal