importresult.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024
00025 #include <gpgmepp/importresult.h>
00026 #include "shared.h"
00027 #include "result_p.h"
00028
00029 #include <gpgme.h>
00030
00031 class GpgME::ImportResult::Private : public GpgME::Shared {
00032 public:
00033 Private( const _gpgme_op_import_result & r ) : Shared(), res( r ) {
00034
00035
00036 for ( gpgme_import_status_t is = r.imports ; is ; is = is->next ) {
00037 gpgme_import_status_t copy = new _gpgme_import_status( *is );
00038 copy->fpr = strdup( is->fpr );
00039 copy->next = 0;
00040 imports.push_back( copy );
00041 }
00042 res.imports = 0;
00043 }
00044 ~Private() {
00045 for ( std::vector<gpgme_import_status_t>::iterator it = imports.begin() ; it != imports.end() ; ++it ) {
00046 std::free( (*it)->fpr );
00047 delete *it; *it = 0;
00048 }
00049 }
00050
00051 _gpgme_op_import_result res;
00052 std::vector<gpgme_import_status_t> imports;
00053 };
00054
00055 GpgME::ImportResult::ImportResult( gpgme_ctx_t ctx, int error )
00056 : GpgME::Result( error ), d( 0 )
00057 {
00058 if ( error || !ctx )
00059 return;
00060 gpgme_import_result_t res = gpgme_op_import_result( ctx );
00061 if ( !res )
00062 return;
00063 d = new Private( *res );
00064 d->ref();
00065 }
00066
00067 make_standard_stuff(ImportResult)
00068
00069 int GpgME::ImportResult::numConsidered() const {
00070 return d ? d->res.considered : 0 ;
00071 }
00072
00073 int GpgME::ImportResult::numKeysWithoutUserID() const {
00074 return d ? d->res.no_user_id : 0 ;
00075 }
00076
00077 int GpgME::ImportResult::numImported() const {
00078 return d ? d->res.imported : 0 ;
00079 }
00080
00081 int GpgME::ImportResult::numRSAImported() const {
00082 return d ? d->res.imported_rsa : 0 ;
00083 }
00084
00085 int GpgME::ImportResult::numUnchanged() const {
00086 return d ? d->res.unchanged : 0 ;
00087 }
00088
00089 int GpgME::ImportResult::newUserIDs() const {
00090 return d ? d->res.new_user_ids : 0 ;
00091 }
00092
00093 int GpgME::ImportResult::newSubkeys() const {
00094 return d ? d->res.new_sub_keys : 0 ;
00095 }
00096
00097 int GpgME::ImportResult::newSignatures() const {
00098 return d ? d->res.new_signatures : 0 ;
00099 }
00100
00101 int GpgME::ImportResult::newRevocations() const {
00102 return d ? d->res.new_revocations : 0 ;
00103 }
00104
00105 int GpgME::ImportResult::numSecretKeysConsidered() const {
00106 return d ? d->res.secret_read : 0 ;
00107 }
00108
00109 int GpgME::ImportResult::numSecretKeysImported() const {
00110 return d ? d->res.secret_imported : 0 ;
00111 }
00112
00113 int GpgME::ImportResult::numSecretKeysUnchanged() const {
00114 return d ? d->res.secret_unchanged : 0 ;
00115 }
00116
00117 int GpgME::ImportResult::notImported() const {
00118 return d ? d->res.not_imported : 0 ;
00119 }
00120
00121 GpgME::Import GpgME::ImportResult::import( unsigned int idx ) const {
00122 return Import( d, idx );
00123 }
00124
00125 std::vector<GpgME::Import> GpgME::ImportResult::imports() const {
00126 if ( !d )
00127 return std::vector<Import>();
00128 std::vector<Import> result;
00129 result.reserve( d->imports.size() );
00130 for ( unsigned int i = 0 ; i < d->imports.size() ; ++i )
00131 result.push_back( Import( d, i ) );
00132 return result;
00133 }
00134
00135
00136
00137
00138
00139
00140 GpgME::Import::Import( ImportResult::Private * parent, unsigned int i )
00141 : d( parent ), idx( i )
00142 {
00143 if ( d )
00144 d->ref();
00145 }
00146
00147 GpgME::Import::Import() : d( 0 ), idx( 0 ) {}
00148
00149 GpgME::Import::Import( const Import & other )
00150 : d( other.d ), idx( other.idx )
00151 {
00152 if ( d )
00153 d->ref();
00154 }
00155
00156 GpgME::Import::~Import() {
00157 if ( d )
00158 d->unref();
00159 }
00160
00161 const GpgME::Import & GpgME::Import::operator=( const Import & other ) {
00162 if ( this->d != other.d ) {
00163 if ( other.d )
00164 other.d->ref();
00165 if ( this->d )
00166 this->d->unref();
00167 this->d = other.d;
00168 }
00169
00170 this->idx = other.idx;
00171 return *this;
00172 }
00173
00174
00175 bool GpgME::Import::isNull() const {
00176 return !d || idx >= d->imports.size() ;
00177 }
00178
00179
00180
00181
00182 const char * GpgME::Import::fingerprint() const {
00183 return isNull() ? 0 : d->imports[idx]->fpr ;
00184 }
00185
00186 GpgME::Error GpgME::Import::error() const {
00187 return isNull() ? 0 : d->imports[idx]->result ;
00188 }
00189
00190 GpgME::Import::Status GpgME::Import::status() const {
00191 if ( isNull() )
00192 return Unknown;
00193 unsigned int s = d->imports[idx]->status;
00194 unsigned int result = Unknown;
00195 if ( s & GPGME_IMPORT_NEW ) result |= NewKey;
00196 if ( s & GPGME_IMPORT_UID ) result |= NewUserIDs;
00197 if ( s & GPGME_IMPORT_SIG ) result |= NewSignatures;
00198 if ( s & GPGME_IMPORT_SUBKEY ) result |= NewSubkeys;
00199 if ( s & GPGME_IMPORT_SECRET ) result |= ContainedSecretKey;
00200 return static_cast<Status>( result );
00201 }
This file is part of the documentation for libkdenetwork Library Version 3.3.0.