1/*
2 keylistresult.cpp - wraps a gpgme keylist result
3 Copyright (C) 2004 Klarälvdalens Datakonsult AB
4
5 This file is part of GPGME++.
6
7 GPGME++ is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 GPGME++ 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
15 GNU Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with GPGME++; see the file COPYING.LIB. If not, write to the
19 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*/
22
23#include <gpgme++/config-gpgme++.h>
24
25#include <gpgme++/keylistresult.h>
26#include "result_p.h"
27
28#include <gpgme.h>
29
30#include <cstring>
31#include <cassert>
32
33class GpgME::KeyListResult::Private {
34public:
35 Private( const _gpgme_op_keylist_result & r ) : res( r ) {}
36 Private( const Private & other ) : res( other.res ) {}
37
38 _gpgme_op_keylist_result res;
39};
40
41GpgME::KeyListResult::KeyListResult( gpgme_ctx_t ctx, int error )
42 : GpgME::Result( error ), d()
43{
44 init( ctx );
45}
46
47GpgME::KeyListResult::KeyListResult( gpgme_ctx_t ctx, const Error & error )
48 : GpgME::Result( error ), d()
49{
50 init( ctx );
51}
52
53void GpgME::KeyListResult::init( gpgme_ctx_t ctx ) {
54 if ( !ctx ) {
55 return;
56 }
57 gpgme_keylist_result_t res = gpgme_op_keylist_result( ctx );
58 if ( !res ) {
59 return;
60 }
61 d.reset( new Private( *res ) );
62}
63
64GpgME::KeyListResult::KeyListResult( const Error & error, const _gpgme_op_keylist_result & res )
65 : GpgME::Result( error ), d( new Private( res ) )
66{
67
68}
69
70make_standard_stuff(KeyListResult)
71
72void GpgME::KeyListResult::detach() {
73 if ( !d || d.unique() ) {
74 return;
75 }
76 d.reset( new Private( *d ) );
77}
78
79void GpgME::KeyListResult::mergeWith( const KeyListResult & other ) {
80 if ( other.isNull() ) {
81 return;
82 }
83 if ( isNull() ) { // just assign
84 operator=( other );
85 return;
86 }
87 // merge the truncated flag (try to keep detaching to a minimum):
88 if ( other.isTruncated() && !this->isTruncated() ) {
89 assert( other.d );
90 detach();
91 if ( !d ) {
92 d.reset( new Private( *other.d ) );
93 } else {
94 d->res.truncated = true;
95 }
96 }
97 if ( ! bool(error() ) ) { // only merge the error when there was none yet.
98 Result::operator=( other );
99 }
100}
101
102bool GpgME::KeyListResult::isTruncated() const {
103 return d && d->res.truncated;
104}
105