aboutsummaryrefslogtreecommitdiffstats
path: root/lang/cpp/src
diff options
context:
space:
mode:
authorAndre Heinecke <[email protected]>2016-08-25 08:42:49 +0000
committerAndre Heinecke <[email protected]>2016-08-25 09:41:57 +0000
commitece8b02a839d6fc566fea7b6e59fabff164f6cf5 (patch)
treeae54aa2cfca996c0751ae31a887981a40711b9c8 /lang/cpp/src
parentcore: Add GPGME_KEYLIST_MODE_WITH_TOFU. (diff)
downloadgpgme-ece8b02a839d6fc566fea7b6e59fabff164f6cf5.tar.gz
gpgme-ece8b02a839d6fc566fea7b6e59fabff164f6cf5.zip
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.
Diffstat (limited to '')
-rw-r--r--lang/cpp/src/context.cpp37
-rw-r--r--lang/cpp/src/context.h28
-rw-r--r--lang/cpp/src/global.h2
3 files changed, 66 insertions, 1 deletions
diff --git a/lang/cpp/src/context.cpp b/lang/cpp/src/context.cpp
index 4e66d3b9..26190842 100644
--- a/lang/cpp/src/context.cpp
+++ b/lang/cpp/src/context.cpp
@@ -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:
;
}
diff --git a/lang/cpp/src/context.h b/lang/cpp/src/context.h
index 6518d4cf..f5e2b958 100644
--- a/lang/cpp/src/context.h
+++ b/lang/cpp/src/context.h
@@ -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
diff --git a/lang/cpp/src/global.h b/lang/cpp/src/global.h
index 508e1d76..fc01d1ea 100644
--- a/lang/cpp/src/global.h
+++ b/lang/cpp/src/global.h
@@ -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,