1 | /* |
2 | gpgagentgetinfoassuantransaction.cpp - Assuan Transaction to get information from gpg-agent |
3 | Copyright (C) 2009 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 <config-gpgme++.h> |
24 | |
25 | #include "gpgagentgetinfoassuantransaction.h" |
26 | #include "error.h" |
27 | #include "data.h" |
28 | #include "util.h" |
29 | |
30 | #include <boost/static_assert.hpp> |
31 | |
32 | #include <sstream> |
33 | |
34 | using namespace GpgME; |
35 | using namespace boost; |
36 | |
37 | GpgAgentGetInfoAssuanTransaction::GpgAgentGetInfoAssuanTransaction( InfoItem item ) |
38 | : AssuanTransaction(), |
39 | m_item( item ), |
40 | m_command(), |
41 | m_data() |
42 | { |
43 | |
44 | } |
45 | |
46 | GpgAgentGetInfoAssuanTransaction::~GpgAgentGetInfoAssuanTransaction() {} |
47 | |
48 | std::string GpgAgentGetInfoAssuanTransaction::version() const { |
49 | if ( m_item == Version ) { |
50 | return m_data; |
51 | } else { |
52 | return std::string(); |
53 | } |
54 | } |
55 | |
56 | unsigned int GpgAgentGetInfoAssuanTransaction::pid() const { |
57 | if ( m_item == Pid ) { |
58 | return to_pid( m_data ); |
59 | } else { |
60 | return 0U; |
61 | } |
62 | } |
63 | |
64 | std::string GpgAgentGetInfoAssuanTransaction::socketName() const { |
65 | if ( m_item == SocketName ) { |
66 | return m_data; |
67 | } else { |
68 | return std::string(); |
69 | } |
70 | } |
71 | |
72 | std::string GpgAgentGetInfoAssuanTransaction::sshSocketName() const { |
73 | if ( m_item == SshSocketName ) { |
74 | return m_data; |
75 | } else { |
76 | return std::string(); |
77 | } |
78 | } |
79 | |
80 | static const char * gpgagent_getinfo_tokens[] = { |
81 | "version" , |
82 | "pid" , |
83 | "socket_name" , |
84 | "ssh_socket_name" , |
85 | "scd_running" , |
86 | }; |
87 | BOOST_STATIC_ASSERT( ( sizeof gpgagent_getinfo_tokens / sizeof *gpgagent_getinfo_tokens == GpgAgentGetInfoAssuanTransaction::LastInfoItem ) ); |
88 | |
89 | void GpgAgentGetInfoAssuanTransaction::makeCommand() const { |
90 | assert( m_item >= 0 ); |
91 | assert( m_item < LastInfoItem ); |
92 | m_command = "GETINFO " ; |
93 | m_command += gpgagent_getinfo_tokens[m_item]; |
94 | } |
95 | |
96 | const char * GpgAgentGetInfoAssuanTransaction::command() const { |
97 | makeCommand(); |
98 | return m_command.c_str(); |
99 | } |
100 | |
101 | Error GpgAgentGetInfoAssuanTransaction::data( const char * data, size_t len ) { |
102 | m_data.append( data, len ); |
103 | return Error(); |
104 | } |
105 | |
106 | Data GpgAgentGetInfoAssuanTransaction::inquire( const char * name, const char * args, Error & err ) { |
107 | (void)name; (void)args; (void)err; |
108 | return Data::null; |
109 | } |
110 | |
111 | Error GpgAgentGetInfoAssuanTransaction::status( const char * status, const char * args ) { |
112 | (void)status; (void)args; |
113 | return Error(); |
114 | } |
115 | |