Browse Source

Improved retry code / now passphrase from AbstractEngine level.

JNI-114
heck 2 years ago
parent
commit
7c7a8f4121
3 changed files with 34 additions and 14 deletions
  1. +6
    -0
      src/foundation_pEp_jniadapter_AbstractEngine.cc
  2. +19
    -14
      src/gen_cpp_Engine.ysl2
  3. +9
    -0
      src/passphrase_callback.hh

+ 6
- 0
src/foundation_pEp_jniadapter_AbstractEngine.cc View File

@ -9,6 +9,7 @@
#include <pEp/callback_dispatcher.hh>
#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<std::mutex> l(mutex_obj);


+ 19
- 14
src/gen_cpp_Engine.ysl2 View File

@ -14,10 +14,12 @@ tstylesheet {
#include <pEp/key_reset.h>
#include <pEp/Adapter.hh>
#include <pEp/pEpLog.hh>
#include <pEp/passphrase_cache.hh>
#include "foundation_pEp_jniadapter_«@name».h"
#include "throw_pEp_exception.hh"
#include "jniutils.hh"
#include <pEp/passphrase_cache.hh>
#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 {


+ 9
- 0
src/passphrase_callback.hh View File

@ -0,0 +1,9 @@
namespace pEp {
namespace JNIAdapter {
char* passphraseRequiredCallback();
};
};

Loading…
Cancel
Save