[Pkg-gnupg-commit] [gpgme] 307/412: Cpp: Add support for spawn engine

Daniel Kahn Gillmor dkg at fifthhorseman.net
Thu Sep 22 21:27:09 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gpgme.

commit ece8b02a839d6fc566fea7b6e59fabff164f6cf5
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Aug 25 10:42:49 2016 +0200

    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.
---
 lang/cpp/src/context.cpp | 37 +++++++++++++++++++++++++++++++++++++
 lang/cpp/src/context.h   | 28 ++++++++++++++++++++++++++++
 lang/cpp/src/global.h    |  2 +-
 3 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/lang/cpp/src/context.cpp b/lang/cpp/src/context.cpp
index 4e66d3b..2619084 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 6518d4c..f5e2b95 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 508e1d7..fc01d1e 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,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git



More information about the Pkg-gnupg-commit mailing list