JSON-18 #comment Add function getGpgEnvironment() that returns an object with 3 optional strings (which each might be null).

ENGINE-187
Roker 6 years ago
parent c352ebb132
commit 8a74086b30

@ -32,6 +32,7 @@ libjson-adapter.a: \
json_spirit/json_spirit_reader.o json_spirit/json_spirit_value.o json_spirit/json_spirit_writer.o \
json-adapter.o registry.o nfc.o json_rpc.o \
function_map.o pep-types.o \
gpg_environment.o \
security-token.o \
nfc_sets.o base64.o \
nulllogger.o \

@ -0,0 +1,45 @@
#include "gpg_environment.hh"
#include "function_map.hh"
#include <cstdlib>
#include <pEp/message_api.h> // for get_binary_path()
GpgEnvironment getGpgEnvironment()
{
GpgEnvironment ge{};
const char* gpg_path = nullptr;
const auto status = get_binary_path( PEP_crypt_OpenPGP, &gpg_path);
if(status == PEP_STATUS_OK && gpg_path)
{
ge.gnupg_path = std::string(gpg_path);
}
const char* home = std::getenv("GNUPGHOME");
if(home)
{
ge.gnupg_home = std::string(home);
}
const char* ai = std::getenv("GPG_AGENT_INFO");
if(home)
{
ge.gpg_agent_info = std::string(ai);
}
return ge;
}
template<>
js::Value to_json<GpgEnvironment>(const GpgEnvironment& ge)
{
js::Object obj;
obj.emplace_back("gnupg_path", (ge.gnupg_path ? ge.gnupg_path.get() : js::Value{}) );
obj.emplace_back("gnupg_home", (ge.gnupg_home ? ge.gnupg_home.get() : js::Value{}) );
obj.emplace_back("gpg_agent_info", (ge.gpg_agent_info ? ge.gpg_agent_info.get() : js::Value{}) );
return obj;
}
template<>
js::Value Type2String<GpgEnvironment>::get() { return "GpgEnvironment"; }

@ -0,0 +1,16 @@
#ifndef JSON_GPG_ENVIRONMENT_HH
#define JSON_GPG_ENVIRONMENT_HH
#include <boost/optional.hpp>
#include <string>
struct GpgEnvironment
{
boost::optional<std::string> gnupg_path; // filled by pEpEngine's gnu_gpg_path()
boost::optional<std::string> gnupg_home; // filled by getenv("GNUPGHOME")
boost::optional<std::string> gpg_agent_info; // filled by getenv("GPG_AGENT_INFO")
};
GpgEnvironment getGpgEnvironment();
#endif

@ -20,6 +20,7 @@
#include "nulllogger.hh"
#include "security-token.hh"
#include "pep-utils.hh"
#include "gpg_environment.hh"
#include <pEp/message_api.h>
#include <pEp/blacklist.h>
@ -205,7 +206,8 @@ const FunctionMap functions = {
// my own example function that does something useful. :-)
FP( "—— Other ——", new Separator ),
FP( "version", new Func<std::string>( &JsonAdapter::version ) ),
FP( "apiVersion", new Func<unsigned> ( &JsonAdapter::apiVersion ) ),
FP( "apiVersion", new Func<unsigned> ( &JsonAdapter::apiVersion ) ),
FP( "getGpgEnvironment", new Func<GpgEnvironment>( &getGpgEnvironment ) ),
};

Loading…
Cancel
Save