Blame lang/cpp/src/importresult.cpp

Packit Service 672cf4
/*
Packit Service 672cf4
  importresult.cpp - wraps a gpgme import result
Packit Service 672cf4
  Copyright (C) 2004 Klarälvdalens Datakonsult AB
Packit Service 672cf4
  2016 Bundesamt für Sicherheit in der Informationstechnik
Packit Service 672cf4
  Software engineering by Intevation GmbH
Packit Service 672cf4
Packit Service 672cf4
  This file is part of GPGME++.
Packit Service 672cf4
Packit Service 672cf4
  GPGME++ is free software; you can redistribute it and/or
Packit Service 672cf4
  modify it under the terms of the GNU Library General Public
Packit Service 672cf4
  License as published by the Free Software Foundation; either
Packit Service 672cf4
  version 2 of the License, or (at your option) any later version.
Packit Service 672cf4
Packit Service 672cf4
  GPGME++ is distributed in the hope that it will be useful,
Packit Service 672cf4
  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 672cf4
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 672cf4
  GNU Library General Public License for more details.
Packit Service 672cf4
Packit Service 672cf4
  You should have received a copy of the GNU Library General Public License
Packit Service 672cf4
  along with GPGME++; see the file COPYING.LIB.  If not, write to the
Packit Service 672cf4
  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Packit Service 672cf4
  Boston, MA 02110-1301, USA.
Packit Service 672cf4
*/
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
#ifdef HAVE_CONFIG_H
Packit Service 672cf4
 #include "config.h"
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
#include <importresult.h>
Packit Service 672cf4
#include "result_p.h"
Packit Service 672cf4
Packit Service 672cf4
#include <gpgme.h>
Packit Service 672cf4
#include <cstdlib>
Packit Service 672cf4
#include <cstring>
Packit Service 672cf4
Packit Service 672cf4
#include <string.h>
Packit Service 672cf4
Packit Service 672cf4
class GpgME::ImportResult::Private
Packit Service 672cf4
{
Packit Service 672cf4
public:
Packit Service 672cf4
    Private(const _gpgme_op_import_result &r) : res(r)
Packit Service 672cf4
    {
Packit Service 672cf4
        // copy recursively, using compiler-generated copy ctor.
Packit Service 672cf4
        // We just need to handle the pointers in the structs:
Packit Service 672cf4
        for (gpgme_import_status_t is = r.imports ; is ; is = is->next) {
Packit Service 672cf4
            gpgme_import_status_t copy = new _gpgme_import_status(*is);
Packit Service 672cf4
            copy->fpr = strdup(is->fpr);
Packit Service 6c01f9
            copy->next = 0;
Packit Service 672cf4
            imports.push_back(copy);
Packit Service 672cf4
        }
Packit Service 6c01f9
        res.imports = 0;
Packit Service 672cf4
    }
Packit Service 672cf4
    ~Private()
Packit Service 672cf4
    {
Packit Service 672cf4
        for (std::vector<gpgme_import_status_t>::iterator it = imports.begin() ; it != imports.end() ; ++it) {
Packit Service 672cf4
            std::free((*it)->fpr);
Packit Service 6c01f9
            delete *it; *it = 0;
Packit Service 672cf4
        }
Packit Service 672cf4
    }
Packit Service 672cf4
Packit Service 672cf4
    _gpgme_op_import_result res;
Packit Service 672cf4
    std::vector<gpgme_import_status_t> imports;
Packit Service 672cf4
};
Packit Service 672cf4
Packit Service 672cf4
GpgME::ImportResult::ImportResult(gpgme_ctx_t ctx, int error)
Packit Service 672cf4
    : GpgME::Result(error), d()
Packit Service 672cf4
{
Packit Service 672cf4
    init(ctx);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
GpgME::ImportResult::ImportResult(gpgme_ctx_t ctx, const Error &error)
Packit Service 672cf4
    : GpgME::Result(error), d()
Packit Service 672cf4
{
Packit Service 672cf4
    init(ctx);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
void GpgME::ImportResult::init(gpgme_ctx_t ctx)
Packit Service 672cf4
{
Packit Service 672cf4
    if (!ctx) {
Packit Service 672cf4
        return;
Packit Service 672cf4
    }
Packit Service 672cf4
    gpgme_import_result_t res = gpgme_op_import_result(ctx);
Packit Service 672cf4
    if (!res) {
Packit Service 672cf4
        return;
Packit Service 672cf4
    }
Packit Service 672cf4
    d.reset(new Private(*res));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
make_standard_stuff(ImportResult)
Packit Service 672cf4
Packit Service 672cf4
int GpgME::ImportResult::numConsidered() const
Packit Service 672cf4
{
Packit Service 672cf4
    return d ? d->res.considered : 0 ;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
int GpgME::ImportResult::numKeysWithoutUserID() const
Packit Service 672cf4
{
Packit Service 672cf4
    return d ? d->res.no_user_id : 0 ;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
int GpgME::ImportResult::numImported() const
Packit Service 672cf4
{
Packit Service 672cf4
    return d ? d->res.imported : 0 ;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
int GpgME::ImportResult::numRSAImported() const
Packit Service 672cf4
{
Packit Service 672cf4
    return d ? d->res.imported_rsa : 0 ;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
int GpgME::ImportResult::numUnchanged() const
Packit Service 672cf4
{
Packit Service 672cf4
    return d ? d->res.unchanged : 0 ;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
int GpgME::ImportResult::newUserIDs() const
Packit Service 672cf4
{
Packit Service 672cf4
    return d ? d->res.new_user_ids : 0 ;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
int GpgME::ImportResult::newSubkeys() const
Packit Service 672cf4
{
Packit Service 672cf4
    return d ? d->res.new_sub_keys : 0 ;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
int GpgME::ImportResult::newSignatures() const
Packit Service 672cf4
{
Packit Service 672cf4
    return d ? d->res.new_signatures : 0 ;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
int GpgME::ImportResult::newRevocations() const
Packit Service 672cf4
{
Packit Service 672cf4
    return d ? d->res.new_revocations : 0 ;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
int GpgME::ImportResult::numSecretKeysConsidered() const
Packit Service 672cf4
{
Packit Service 672cf4
    return d ? d->res.secret_read : 0 ;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
int GpgME::ImportResult::numSecretKeysImported() const
Packit Service 672cf4
{
Packit Service 672cf4
    return d ? d->res.secret_imported : 0 ;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
int GpgME::ImportResult::numSecretKeysUnchanged() const
Packit Service 672cf4
{
Packit Service 672cf4
    return d ? d->res.secret_unchanged : 0 ;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
int GpgME::ImportResult::notImported() const
Packit Service 672cf4
{
Packit Service 672cf4
    return d ? d->res.not_imported : 0 ;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
GpgME::Import GpgME::ImportResult::import(unsigned int idx) const
Packit Service 672cf4
{
Packit Service 672cf4
    return Import(d, idx);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::vector<GpgME::Import> GpgME::ImportResult::imports() const
Packit Service 672cf4
{
Packit Service 672cf4
    if (!d) {
Packit Service 672cf4
        return std::vector<Import>();
Packit Service 672cf4
    }
Packit Service 672cf4
    std::vector<Import> result;
Packit Service 672cf4
    result.reserve(d->imports.size());
Packit Service 672cf4
    for (unsigned int i = 0 ; i < d->imports.size() ; ++i) {
Packit Service 672cf4
        result.push_back(Import(d, i));
Packit Service 672cf4
    }
Packit Service 672cf4
    return result;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
GpgME::Import::Import(const std::shared_ptr<ImportResult::Private> &parent, unsigned int i)
Packit Service 672cf4
    : d(parent), idx(i)
Packit Service 672cf4
{
Packit Service 672cf4
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
GpgME::Import::Import() : d(), idx(0) {}
Packit Service 672cf4
Packit Service 672cf4
bool GpgME::Import::isNull() const
Packit Service 672cf4
{
Packit Service 672cf4
    return !d || idx >= d->imports.size() ;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
const char *GpgME::Import::fingerprint() const
Packit Service 672cf4
{
Packit Service 6c01f9
    return isNull() ? 0 : d->imports[idx]->fpr ;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
GpgME::Error GpgME::Import::error() const
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(isNull() ? 0 : d->imports[idx]->result);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
GpgME::Import::Status GpgME::Import::status() const
Packit Service 672cf4
{
Packit Service 672cf4
    if (isNull()) {
Packit Service 672cf4
        return Unknown;
Packit Service 672cf4
    }
Packit Service 672cf4
    const unsigned int s = d->imports[idx]->status;
Packit Service 672cf4
    unsigned int result = Unknown;
Packit Service 672cf4
    if (s & GPGME_IMPORT_NEW) {
Packit Service 672cf4
        result |= NewKey;
Packit Service 672cf4
    }
Packit Service 672cf4
    if (s & GPGME_IMPORT_UID) {
Packit Service 672cf4
        result |= NewUserIDs;
Packit Service 672cf4
    }
Packit Service 672cf4
    if (s & GPGME_IMPORT_SIG) {
Packit Service 672cf4
        result |= NewSignatures;
Packit Service 672cf4
    }
Packit Service 672cf4
    if (s & GPGME_IMPORT_SUBKEY) {
Packit Service 672cf4
        result |= NewSubkeys;
Packit Service 672cf4
    }
Packit Service 672cf4
    if (s & GPGME_IMPORT_SECRET) {
Packit Service 672cf4
        result |= ContainedSecretKey;
Packit Service 672cf4
    }
Packit Service 672cf4
    return static_cast<Status>(result);
Packit Service 672cf4
}