libkdenetwork Library API Documentation

gpgmepp/util.h

00001 /* util.h - some inline helper functions
00002    Copyright (C) 2004 Klarälvdalens Datakonsult AB
00003 
00004    This file is part of GPGME++.
00005  
00006    GPGME++ is free software; you can redistribute it and/or modify it
00007    under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010  
00011    GPGME++ is distributed in the hope that it will be useful, but
00012    WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with GPGME; if not, write to the Free Software Foundation,
00018    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA.  */
00019 
00020 // -*- c++ -*-
00021 #ifndef __GPGMEPP_UTIL_H__
00022 #define __GPGMEPP_UTIL_H__
00023 
00024 #include <gpgme.h>
00025 #include <context.h>
00026 
00027 #ifndef NDEBUG
00028 #include <iostream>
00029 #endif
00030 
00031 static inline gpgme_keylist_mode_t add_to_gpgme_keylist_mode_t( unsigned int oldmode, unsigned int newmodes ) {
00032   if ( newmodes & GpgME::Context::Local ) oldmode |= GPGME_KEYLIST_MODE_LOCAL;
00033   if ( newmodes & GpgME::Context::Extern ) oldmode |= GPGME_KEYLIST_MODE_EXTERN;
00034   if ( newmodes & GpgME::Context::Signatures ) oldmode |= GPGME_KEYLIST_MODE_SIGS;
00035   if ( newmodes & GpgME::Context::Validate ) {
00036 #ifdef HAVE_GPGME_KEYLIST_MODE_VALIDATE
00037     oldmode |= GPGME_KEYLIST_MODE_VALIDATE;
00038 #elif !defined(NDEBUG)
00039     std::cerr << "GpgME::Context: ignoring Valdidate keylist flag (gpgme too old)." << std::endl;
00040 #endif
00041   }
00042 #ifndef NDEBUG
00043   if ( newmodes & ~(GpgME::Context::Local|GpgME::Context::Extern|GpgME::Context::Signatures|GpgME::Context::Validate) )
00044     std::cerr << "GpgME::Context: keylist mode must be one of Local, "
00045       "Extern, Signatures, or Validate, or a combination thereof!" << std::endl;
00046 #endif
00047   return static_cast<gpgme_keylist_mode_t>( oldmode );
00048 }
00049 
00050 static inline unsigned int convert_from_gpgme_keylist_mode_t( unsigned int mode ) {
00051   unsigned int result = 0;
00052   if ( mode & GPGME_KEYLIST_MODE_LOCAL ) result |= GpgME::Context::Local;
00053   if ( mode & GPGME_KEYLIST_MODE_EXTERN ) result |= GpgME::Context::Extern;
00054   if ( mode & GPGME_KEYLIST_MODE_SIGS ) result |= GpgME::Context::Signatures;
00055 #ifdef HAVE_GPGME_KEYLIST_MODE_VALIDATE
00056   if ( mode & GPGME_KEYLIST_MODE_VALIDATE ) result |= GpgME::Context::Validate;
00057 #endif
00058 #ifndef NDEBUG
00059   if ( mode & ~(GPGME_KEYLIST_MODE_LOCAL|
00060         GPGME_KEYLIST_MODE_EXTERN|
00061 #ifdef HAVE_GPGME_KEYLIST_MODE_VALIDATE
00062         GPGME_KEYLIST_MODE_VALIDATE|
00063 #endif
00064         GPGME_KEYLIST_MODE_SIGS) )
00065     std::cerr << "GpgME::Context: WARNING: gpgme_get_keylist_mode() returned an unknown flag!" << std::endl;
00066 #endif // NDEBUG
00067   return result;
00068 }
00069 
00070 
00071 #endif // __GPGMEPP_UTIL_H__
KDE Logo
This file is part of the documentation for libkdenetwork Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 4 14:39:11 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003