Cpp: Add support for spawn engine
* lang/cpp/src/context.cpp (Context::spawn, Context::spawnAsync): New. * lang/cpp/src/context.h: Add prototypes. (SpawnFlags): New. * lang/cpp/src/global.h (SpawnEngine): Added.
This commit is contained in:
parent
9ee103957e
commit
ece8b02a83
@ -252,6 +252,15 @@ std::unique_ptr<Context> Context::createForEngine(Engine eng, Error *error)
|
||||
return std::unique_ptr<Context>();
|
||||
}
|
||||
break;
|
||||
case SpawnEngine:
|
||||
if (const gpgme_error_t err = gpgme_set_protocol(ctx, GPGME_PROTOCOL_SPAWN)) {
|
||||
gpgme_release(ctx);
|
||||
if (error) {
|
||||
*error = Error(err);
|
||||
}
|
||||
return std::unique_ptr<Context>();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (error) {
|
||||
*error = Error::fromCode(GPG_ERR_INV_ARG);
|
||||
@ -1311,6 +1320,29 @@ Error Context::setPinentryMode(PinentryMode which)
|
||||
return Error(d->lasterr = gpgme_set_pinentry_mode(d->ctx, mode));
|
||||
}
|
||||
|
||||
// Engine Spawn stuff
|
||||
Error Context::spawn(const char *file, const char *argv[],
|
||||
Data &input, Data &output, Data &err,
|
||||
SpawnFlags flags)
|
||||
{
|
||||
return Error(d->lasterr = gpgme_op_spawn (d->ctx, file, argv,
|
||||
input.impl() ? input.impl()->data : nullptr,
|
||||
output.impl() ? output.impl()->data : nullptr,
|
||||
err.impl() ? err.impl()->data : nullptr,
|
||||
static_cast<int>(flags)));
|
||||
}
|
||||
|
||||
Error Context::spawnAsync(const char *file, const char *argv[],
|
||||
Data &input, Data &output, Data &err,
|
||||
SpawnFlags flags)
|
||||
{
|
||||
return Error(d->lasterr = gpgme_op_spawn_start (d->ctx, file, argv,
|
||||
input.impl() ? input.impl()->data : nullptr,
|
||||
output.impl() ? output.impl()->data : nullptr,
|
||||
err.impl() ? err.impl()->data : nullptr,
|
||||
static_cast<int>(flags)));
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, Protocol proto)
|
||||
{
|
||||
os << "GpgME::Protocol(";
|
||||
@ -1345,6 +1377,9 @@ std::ostream &operator<<(std::ostream &os, Engine eng)
|
||||
case AssuanEngine:
|
||||
os << "AssuanEngine";
|
||||
break;
|
||||
case SpawnEngine:
|
||||
os << "SpawnEngine";
|
||||
break;
|
||||
default:
|
||||
case UnknownEngine:
|
||||
os << "UnknownEngine";
|
||||
@ -1474,6 +1509,8 @@ static gpgme_protocol_t engine2protocol(const GpgME::Engine engine)
|
||||
return GPGME_PROTOCOL_ASSUAN;
|
||||
case GpgME::G13Engine:
|
||||
return GPGME_PROTOCOL_G13;
|
||||
case GpgME::SpawnEngine:
|
||||
return GPGME_PROTOCOL_SPAWN;
|
||||
case GpgME::UnknownEngine:
|
||||
;
|
||||
}
|
||||
|
@ -346,6 +346,34 @@ public:
|
||||
GpgME::Error createVFS(const char *containerFile, const std::vector<Key> &recipients);
|
||||
VfsMountResult mountVFS(const char *containerFile, const char *mountDir);
|
||||
|
||||
// Spawn Engine
|
||||
enum SpawnFlags {
|
||||
SpawnNone = 0,
|
||||
SpawnDetached = 1,
|
||||
SpawnAllowSetFg = 2
|
||||
};
|
||||
/** Spwan the process \a file with arguments \a argv.
|
||||
*
|
||||
* If a data parameter is null the /dev/null will be
|
||||
* used. (Or other platform stuff).
|
||||
*
|
||||
* @param file The executable to start.
|
||||
* @param argv list of arguments file should be argv[0].
|
||||
* @param input The data to be sent through stdin.
|
||||
* @param output The data to be recieve the stdout.
|
||||
* @param err The data to recieve stderr.
|
||||
* @param flags Additional flags.
|
||||
*
|
||||
* @returns An error or empty error.
|
||||
*/
|
||||
GpgME::Error spawn(const char *file, const char *argv[],
|
||||
Data &input, Data &output, Data &err,
|
||||
SpawnFlags flags);
|
||||
/** Async variant of spawn. Immediately returns after starting the
|
||||
* process. */
|
||||
GpgME::Error spawnAsync(const char *file, const char *argv[],
|
||||
Data &input, Data &output,
|
||||
Data &err, SpawnFlags flags);
|
||||
//
|
||||
//
|
||||
// Run Control
|
||||
|
@ -53,7 +53,7 @@ GPGMEPP_EXPORT Error initializeLibrary(int);
|
||||
|
||||
enum Protocol { OpenPGP, CMS, UnknownProtocol };
|
||||
|
||||
enum Engine { GpgEngine, GpgSMEngine, GpgConfEngine, UnknownEngine, AssuanEngine, G13Engine };
|
||||
enum Engine { GpgEngine, GpgSMEngine, GpgConfEngine, UnknownEngine, AssuanEngine, G13Engine, SpawnEngine };
|
||||
|
||||
enum KeyListMode {
|
||||
Local = 0x1,
|
||||
|
Loading…
Reference in New Issue
Block a user