From 7c7a8f4121efe6ff4636bb2e42849f4b7459e58b Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 8 Jul 2020 03:15:15 +0200 Subject: [PATCH] Improved retry code / now passphrase from AbstractEngine level. --- ...oundation_pEp_jniadapter_AbstractEngine.cc | 6 ++++ src/gen_cpp_Engine.ysl2 | 33 +++++++++++-------- src/passphrase_callback.hh | 9 +++++ 3 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 src/passphrase_callback.hh diff --git a/src/foundation_pEp_jniadapter_AbstractEngine.cc b/src/foundation_pEp_jniadapter_AbstractEngine.cc index 3db137c..bde852c 100644 --- a/src/foundation_pEp_jniadapter_AbstractEngine.cc +++ b/src/foundation_pEp_jniadapter_AbstractEngine.cc @@ -9,6 +9,7 @@ #include #include "throw_pEp_exception.hh" #include "jniutils.hh" +#include "passphrase_callback.hh" namespace pEp { using namespace pEp::JNIAdapter; @@ -91,6 +92,11 @@ void jni_init() { field_value = JNISync::env()->GetFieldID(signalClass, "value", "I"); } +char* JNIAdapter::passphraseRequiredCallback() { + pEpLog("called"); + return "passphrase_alice"; +} + PEP_STATUS messageToSend(message *msg) { std::lock_guard l(mutex_obj); diff --git a/src/gen_cpp_Engine.ysl2 b/src/gen_cpp_Engine.ysl2 index abfa6ac..7dd15d9 100644 --- a/src/gen_cpp_Engine.ysl2 +++ b/src/gen_cpp_Engine.ysl2 @@ -14,10 +14,12 @@ tstylesheet { #include #include #include + #include + #include "foundation_pEp_jniadapter_«@name».h" #include "throw_pEp_exception.hh" #include "jniutils.hh" - #include + #include "passphrase_callback.hh" using pEp::Adapter::session; using pEp::passphrase_cache; @@ -69,29 +71,32 @@ tstylesheet { when "@cached = 'true'" { || pEpLog("cached passphrase mode"); - bool retryAfterCallback = false; + bool retryAgain = false; int maxRetries = 3; int retryCount = 0; PEP_STATUS status; do { // the actual target function + pEpLog("calling passphrase_cache.api(::«@name»())"); status = passphrase_cache.api(::«@name»,session()`apply "parm", mode=call`); - - if(status == PEP_PASSPHRASE_REQUIRED || PEP_WRONG_PASSPHRASE ) { - pEpLog("PassReq OR Wrong"); - // call the app - const char * _passphrase = "passphrase_alice"; - PEP_STATUS status = ::config_passphrase(session(),passphrase_cache.add(_passphrase)); - retryCount++; - if(retryCount > maxRetries) { - retryAfterCallback = false; + pEpLog("PEP_STATUS:" << status); + if(status == PEP_PASSPHRASE_REQUIRED || status == PEP_WRONG_PASSPHRASE ) { + pEpLog("none of the cached passphrases worked"); + if(retryCount < maxRetries) { + // call the app + char* _passphrase = passphraseRequiredCallback(); + pEpLog("callback returned, config_passphrase() with new passphrase"); + PEP_STATUS status = ::config_passphrase(session(),passphrase_cache.add(_passphrase)); + retryAgain = true; + retryCount++; } else { - retryAfterCallback = true; + pEpLog("max retries reached:" << maxRetries); + retryAgain = false; } } else { - retryAfterCallback = false; + retryAgain = false; } - } while (retryAfterCallback); + } while (retryAgain); || } otherwise { diff --git a/src/passphrase_callback.hh b/src/passphrase_callback.hh new file mode 100644 index 0000000..357b2c6 --- /dev/null +++ b/src/passphrase_callback.hh @@ -0,0 +1,9 @@ + + +namespace pEp { + namespace JNIAdapter { + + char* passphraseRequiredCallback(); + + }; +}; \ No newline at end of file