[git] GpgOL - branch, async-enc, updated. gpgol-2.0.6-30-gab69aab
by Andre Heinecke
cvs at cvs.gnupg.org
Wed Feb 14 19:58:32 CET 2018
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG extension for MS Outlook".
The branch, async-enc has been updated
via ab69aab5ea815d377236f02f207ebb0aaaf6406a (commit)
from 594b9eadcc1539e01e5539f51834c085fb477a19 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit ab69aab5ea815d377236f02f207ebb0aaaf6406a
Author: Andre Heinecke <aheinecke at intevation.de>
Date: Wed Feb 14 19:55:01 2018 +0100
Use overlayer tool for "encrypting..." overlay
* src/cryptcontroller.cpp (CryptController::~CryptController):
Ensure overlay is stopped.
(vector_to_charArray): New helper.
(CryptController::lookup_fingerprints): User helper.
(CryptController::resolve_keys): Start crypto overlay.
(CryptController::stop_crypto_overlay),
(CryptController::start_crypto_overlay): New.
* src/cryptcontroller.h: Update accordingly.
* src/mail.cpp (Mail::reset_crypter): New.
(do_crypt): Reset crypter on error.
* src/mail.h: Update accordingly.
--
This is basically nice. If spawning takes a long time the
mail window is not overlayed for a bit. But that should
be ok.
diff --git a/src/cryptcontroller.cpp b/src/cryptcontroller.cpp
index c018f10..2920544 100644
--- a/src/cryptcontroller.cpp
+++ b/src/cryptcontroller.cpp
@@ -77,6 +77,7 @@ CryptController::CryptController (Mail *mail, bool encrypt, bool sign,
CryptController::~CryptController()
{
+ stop_crypto_overlay();
log_debug ("%s:%s:%p",
SRCNAME, __func__, m_mail);
}
@@ -180,6 +181,18 @@ rtrim(std::string &s) {
}).base(), s.end());
}
+char **
+vector_to_charArray(const std::vector<std::string> &vec)
+{
+ char ** ret = (char**) xmalloc (sizeof (char*) * (vec.size() + 1));
+ for (size_t i = 0; i < vec.size(); i++)
+ {
+ ret[i] = strdup (vec[i].c_str());
+ }
+ ret[vec.size()] = NULL;
+ return ret;
+}
+
int
CryptController::lookup_fingerprints (const std::string &sigFpr,
const std::vector<std::string> recpFprs)
@@ -219,12 +232,7 @@ CryptController::lookup_fingerprints (const std::string &sigFpr,
}
// Convert recipient fingerprints
- char **cRecps = (char**) xmalloc (sizeof (char*) * (recpFprs.size() + 1));
- for (size_t i = 0; i < recpFprs.size(); i++)
- {
- cRecps[i] = strdup (recpFprs[i].c_str());
- }
- cRecps[recpFprs.size()] = NULL;
+ char **cRecps = vector_to_charArray (recpFprs);
err = ctx->startKeyListing (const_cast<const char **> (cRecps));
@@ -400,12 +408,7 @@ CryptController::resolve_keys ()
// Convert our collected vector to c strings
// It's a bit overhead but should be quick for such small
// data.
- char **cargs = (char**) xmalloc (sizeof (char*) * (args.size() + 1));
- for (size_t i = 0; i < args.size(); i++)
- {
- cargs[i] = strdup (args[i].c_str());
- }
- cargs[args.size()] = NULL;
+ char **cargs = vector_to_charArray (args);
// Args are prepared. Spawn the resolver.
auto ctx = GpgME::Context::createForEngine (GpgME::SpawnEngine);
@@ -437,6 +440,9 @@ CryptController::resolve_keys ()
// So we do it manually.
bring_to_front (wnd);
+ // We need to create an overlay while encrypting as pinentry can take a while
+ start_crypto_overlay();
+
#ifdef DEBUG_RESOLVER
log_debug ("Resolver stdout:\n'%s'", mystdout.toString ().c_str ());
log_debug ("Resolver stderr:\n'%s'", mystderr.toString ().c_str ());
@@ -630,6 +636,7 @@ CryptController::do_crypto ()
log_debug ("%s:%s: Crypto done sucessfuly.",
SRCNAME, __func__);
m_crypto_success = true;
+
return 0;
}
@@ -934,3 +941,77 @@ CryptController::parse_micalg (const GpgME::SigningResult &result)
log_debug ("%s:%s: micalg is: '%s'.",
SRCNAME, __func__, m_micalg.c_str ());
}
+
+void
+CryptController::stop_crypto_overlay ()
+{
+ if (m_overlayCtx)
+ {
+ log_debug ("%s:%s: Stopping crypto overlay.",
+ SRCNAME, __func__);
+ m_overlayStdin.write ("quit\n", 5);
+ m_overlayCtx = nullptr;
+ }
+}
+
+void
+CryptController::start_crypto_overlay ()
+{
+ std::vector<std::string> args;
+
+ // Collect the arguments
+ char *gpg4win_dir = get_gpg4win_dir ();
+ if (!gpg4win_dir)
+ {
+ TRACEPOINT;
+ return;
+ }
+ const auto overlayer = std::string (gpg4win_dir) + "\\bin\\overlayer.exe";
+ args.push_back (overlayer);
+
+ auto wnd = m_mail->get_window ();
+ if (wnd)
+ {
+ // Pass the handle of the active window for raise / overlay.
+ args.push_back (std::string ("--hwnd"));
+ args.push_back (std::to_string ((int) wnd));
+ }
+
+ args.push_back (std::string ("--overlayText"));
+ if (m_encrypt)
+ {
+ args.push_back (std::string (_("Encrypting...")));
+ }
+ else if (m_sign)
+ {
+ args.push_back (std::string (_("Signing...")));
+ }
+ char **cargs = vector_to_charArray (args);
+
+ m_overlayCtx = GpgME::Context::createForEngine (GpgME::SpawnEngine);
+
+ if (!m_overlayCtx)
+ {
+ // can't happen
+ release_carray (cargs);
+ TRACEPOINT;
+ return;
+ }
+
+ GpgME::Data mystderr(GpgME::Data::null);
+ GpgME::Data mystdout(GpgME::Data::null);
+
+ GpgME::Error err = m_overlayCtx->spawnAsync (cargs[0], const_cast <const char**> (cargs),
+ m_overlayStdin, mystdout, mystderr,
+ (GpgME::Context::SpawnFlags) (
+ GpgME::Context::SpawnAllowSetFg |
+ GpgME::Context::SpawnShowWindow));
+#ifdef DEBUG_RESOLVER
+ log_debug ("Overlayer args:");
+ for (size_t i = 0; cargs && cargs[i]; i++)
+ {
+ log_debug ("%i: '%s'", i, cargs[i]);
+ }
+#endif
+ release_carray (cargs);
+}
diff --git a/src/cryptcontroller.h b/src/cryptcontroller.h
index 1540978..4178a2c 100644
--- a/src/cryptcontroller.h
+++ b/src/cryptcontroller.h
@@ -71,14 +71,19 @@ private:
void parse_micalg (const GpgME::SigningResult &sResult);
+ void start_crypto_overlay ();
+ void stop_crypto_overlay ();
+
private:
Mail *m_mail;
GpgME::Data m_input, m_bodyInput, m_signedData, m_output;
+ GpgME::Data m_overlayStdin;
std::string m_micalg;
bool m_encrypt, m_sign, m_inline, m_crypto_success;
GpgME::Protocol m_proto;
GpgME::Key m_signer_key;
std::vector<GpgME::Key> m_recipients;
+ std::unique_ptr<GpgME::Context> m_overlayCtx;
};
#endif
diff --git a/src/mail.cpp b/src/mail.cpp
index c5e6946..c86eac5 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -789,6 +789,7 @@ do_crypt (LPVOID arg)
log_debug ("%s:%s: crypto failed for: %p with: %i",
SRCNAME, __func__, arg, rc);
mail->set_crypt_state (Mail::NoCryptMail);
+ mail->reset_crypter ();
gpgrt_lock_unlock (&dtor_lock);
return rc;
}
@@ -2577,7 +2578,7 @@ Mail::update_crypt_mapi()
m_crypt_state = WantsSendMIME;
}
// We don't need the crypter anymore.
- m_crypter = nullptr;
+ reset_crypter ();
}
void
diff --git a/src/mail.h b/src/mail.h
index 08450d9..acc783b 100644
--- a/src/mail.h
+++ b/src/mail.h
@@ -417,6 +417,10 @@ public:
*/
HWND get_window () { return m_window; }
+ /** Cleanup any attached crypter object. Useful
+ on error. */
+ void reset_crypter () { m_crypter = nullptr; }
+
private:
void update_categories ();
void update_body ();
-----------------------------------------------------------------------
Summary of changes:
src/cryptcontroller.cpp | 105 ++++++++++++++++++++++++++++++++++++++++++------
src/cryptcontroller.h | 5 +++
src/mail.cpp | 3 +-
src/mail.h | 4 ++
4 files changed, 104 insertions(+), 13 deletions(-)
hooks/post-receive
--
GnuPG extension for MS Outlook
http://git.gnupg.org
More information about the Gnupg-commits
mailing list