1 | /* |
2 | vfsmountresult.cpp - wraps a gpgme vfs mount result |
3 | Copyright (C) 2009 Klarälvdalens Datakonsult AB <info@kdab.com> |
4 | Author: Marc Mutz <marc@kdab.com>, Volker Krause <volker@kdab.com> |
5 | |
6 | This file is part of GPGME++. |
7 | |
8 | GPGME++ is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU Library General Public |
10 | License as published by the Free Software Foundation; either |
11 | version 2 of the License, or (at your option) any later version. |
12 | |
13 | GPGME++ is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU Library General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Library General Public License |
19 | along with GPGME++; see the file COPYING.LIB. If not, write to the |
20 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | Boston, MA 02110-1301, USA. |
22 | */ |
23 | |
24 | #include <gpgme++/config-gpgme++.h> |
25 | |
26 | #include <gpgme++/vfsmountresult.h> |
27 | #include "result_p.h" |
28 | |
29 | #include <gpgme.h> |
30 | |
31 | #include <istream> |
32 | #include <string.h> |
33 | |
34 | using namespace GpgME; |
35 | |
36 | #ifdef HAVE_GPGME_G13_VFS |
37 | class VfsMountResult::Private { |
38 | public: |
39 | explicit Private( const gpgme_vfs_mount_result_t r ) : mountDir( 0 ) { |
40 | if ( r && r->mount_dir ) { |
41 | mountDir = strdup( r->mount_dir ); |
42 | } |
43 | } |
44 | |
45 | ~Private() { |
46 | std::free( mountDir ); |
47 | } |
48 | |
49 | char* mountDir; |
50 | }; |
51 | #endif |
52 | |
53 | VfsMountResult::VfsMountResult( gpgme_ctx_t ctx, const Error & error, const Error &opError ) |
54 | : Result( error ? error : opError ), d() |
55 | { |
56 | init( ctx ); |
57 | } |
58 | |
59 | void VfsMountResult::init( gpgme_ctx_t ctx ) { |
60 | (void)ctx; |
61 | #ifdef HAVE_GPGME_G13_VFS |
62 | if ( !ctx ) { |
63 | return; |
64 | } |
65 | gpgme_vfs_mount_result_t res = gpgme_op_vfs_mount_result( ctx ); |
66 | if ( !res ) { |
67 | return; |
68 | } |
69 | d.reset( new Private( res ) ); |
70 | #endif |
71 | } |
72 | |
73 | make_standard_stuff(VfsMountResult) |
74 | |
75 | const char* VfsMountResult::mountDir() const { |
76 | #ifdef HAVE_GPGME_G13_VFS |
77 | if ( d ) { |
78 | return d->mountDir; |
79 | } |
80 | #endif |
81 | return 0; |
82 | } |
83 | |
84 | |
85 | std::ostream & GpgME::operator<<( std::ostream & os, const VfsMountResult & result ) { |
86 | os << "GpgME::VfsMountResult(" ; |
87 | if ( !result.isNull() ) { |
88 | os << "\n error: " << result.error() |
89 | << "\n mount dir: " << result.mountDir() |
90 | << "\n" ; |
91 | } |
92 | return os << ')'; |
93 | } |
94 | |
95 | |