Blame lang/cpp/src/gpgagentgetinfoassuantransaction.cpp

Packit Service 672cf4
/*
Packit Service 672cf4
  gpgagentgetinfoassuantransaction.cpp - Assuan Transaction to get information from gpg-agent
Packit Service 672cf4
  Copyright (C) 2009 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
#ifdef HAVE_CONFIG_H
Packit Service 672cf4
 #include "config.h"
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
#include "gpgagentgetinfoassuantransaction.h"
Packit Service 672cf4
#include "error.h"
Packit Service 672cf4
#include "data.h"
Packit Service 672cf4
#include "util.h"
Packit Service 672cf4
Packit Service 672cf4
#include <assert.h>
Packit Service 672cf4
Packit Service 672cf4
#include <sstream>
Packit Service 672cf4
Packit Service 672cf4
using namespace GpgME;
Packit Service 672cf4
Packit Service 672cf4
GpgAgentGetInfoAssuanTransaction::GpgAgentGetInfoAssuanTransaction(InfoItem item)
Packit Service 672cf4
    : AssuanTransaction(),
Packit Service 672cf4
      m_item(item),
Packit Service 672cf4
      m_command(),
Packit Service 672cf4
      m_data()
Packit Service 672cf4
{
Packit Service 672cf4
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
GpgAgentGetInfoAssuanTransaction::~GpgAgentGetInfoAssuanTransaction() {}
Packit Service 672cf4
Packit Service 672cf4
std::string GpgAgentGetInfoAssuanTransaction::version() const
Packit Service 672cf4
{
Packit Service 672cf4
    if (m_item == Version) {
Packit Service 672cf4
        return m_data;
Packit Service 672cf4
    } else {
Packit Service 672cf4
        return std::string();
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
unsigned int GpgAgentGetInfoAssuanTransaction::pid() const
Packit Service 672cf4
{
Packit Service 672cf4
    if (m_item == Pid) {
Packit Service 672cf4
        return to_pid(m_data);
Packit Service 672cf4
    } else {
Packit Service 672cf4
        return 0U;
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::string GpgAgentGetInfoAssuanTransaction::socketName() const
Packit Service 672cf4
{
Packit Service 672cf4
    if (m_item == SocketName) {
Packit Service 672cf4
        return m_data;
Packit Service 672cf4
    } else {
Packit Service 672cf4
        return std::string();
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::string GpgAgentGetInfoAssuanTransaction::sshSocketName() const
Packit Service 672cf4
{
Packit Service 672cf4
    if (m_item == SshSocketName) {
Packit Service 672cf4
        return m_data;
Packit Service 672cf4
    } else {
Packit Service 672cf4
        return std::string();
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
static const char *const gpgagent_getinfo_tokens[] = {
Packit Service 672cf4
    "version",
Packit Service 672cf4
    "pid",
Packit Service 672cf4
    "socket_name",
Packit Service 672cf4
    "ssh_socket_name",
Packit Service 672cf4
    "scd_running",
Packit Service 672cf4
};
Packit Service 672cf4
Packit Service 672cf4
void GpgAgentGetInfoAssuanTransaction::makeCommand() const
Packit Service 672cf4
{
Packit Service 672cf4
    assert(m_item >= 0);
Packit Service 672cf4
    assert(m_item < LastInfoItem);
Packit Service 672cf4
    m_command = "GETINFO ";
Packit Service 672cf4
    m_command += gpgagent_getinfo_tokens[m_item];
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
const char *GpgAgentGetInfoAssuanTransaction::command() const
Packit Service 672cf4
{
Packit Service 672cf4
    makeCommand();
Packit Service 672cf4
    return m_command.c_str();
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error GpgAgentGetInfoAssuanTransaction::data(const char *data, size_t len)
Packit Service 672cf4
{
Packit Service 672cf4
    m_data.append(data, len);
Packit Service 672cf4
    return Error();
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Data GpgAgentGetInfoAssuanTransaction::inquire(const char *name, const char *args, Error &err)
Packit Service 672cf4
{
Packit Service 672cf4
    (void)name; (void)args; (void)err;
Packit Service 672cf4
    return Data::null;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error GpgAgentGetInfoAssuanTransaction::status(const char *status, const char *args)
Packit Service 672cf4
{
Packit Service 672cf4
    (void)status; (void)args;
Packit Service 672cf4
    return Error();
Packit Service 672cf4
}