Browse Source

formatting and code style only

jni117 Release_2.2.0-RC1
heck 5 years ago
parent
commit
a255490628
  1. 22
      src/codegen/gen_cpp_Engine.ysl2
  2. 63
      src/codegen/gen_cpp_Message.ysl2
  3. 161
      src/cxx/basic_api.cc
  4. 168
      src/cxx/foundation_pEp_jniadapter_AbstractEngine.cc
  5. 45
      src/cxx/foundation_pEp_jniadapter__Blob.cc
  6. 6
      src/cxx/identity_api.cc
  7. 1535
      src/cxx/jniutils.cc
  8. 231
      src/cxx/jniutils.hh
  9. 9
      src/cxx/passphrase_callback.hh
  10. 68
      src/cxx/passphrase_callback.hxx

22
src/codegen/gen_cpp_Engine.ysl2

@ -51,10 +51,8 @@ tstylesheet {
} }
|| ||
JNIEXPORT «$CretType» JNICALL «$mangled»( JNIEXPORT «$CretType» JNICALL «$mangled»(JNIEnv *env,
JNIEnv *env, jobject obj`apply "parm[in|inout]", mode=sig`)
jobject obj`apply "parm[in|inout]", mode=sig`
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -83,13 +81,11 @@ tstylesheet {
} }
} }
|| ||
if ((status > PEP_STATUS_OK && status < PEP_UNENCRYPTED) |`> |`
status < PEP_STATUS_OK |`> |` if ((status > PEP_STATUS_OK && status < PEP_UNENCRYPTED) |`> |` status < PEP_STATUS_OK |`> |` status >= PEP_TRUSTWORD_NOT_FOUND) {
status >= PEP_TRUSTWORD_NOT_FOUND) {
throw_pEp_Exception(env, status); throw_pEp_Exception(env, status);
return «$CretDefault»; return «$CretDefault»;
} }
|| ||
apply "parm[returns|creates]", mode=return; apply "parm[returns|creates]", mode=return;
@ -188,9 +184,9 @@ tstylesheet {
} }
|| ||
«$jnitype» «$name»_ = NULL; «$jnitype» «$name»_ = NULL;
if (_«$name») if (_«$name») {
«$name»_ = «$from_type»(env, _«$name»); «$name»_ = «$from_type»(env, _«$name»);
}
|| ||
} }
when "ancestor::namespace/child::enum[@name=$type]" { when "ancestor::namespace/child::enum[@name=$type]" {
@ -200,14 +196,12 @@ tstylesheet {
{ {
jclass clazz_«$ljtype» = findClass(env, "foundation/pEp/jniadapter/«$jtype»"); jclass clazz_«$ljtype» = findClass(env, "foundation/pEp/jniadapter/«$jtype»");
assert(clazz_«$ljtype»); assert(clazz_«$ljtype»);
jmethodID method_values = env->GetStaticMethodID(clazz_«$ljtype», "values", jmethodID method_values = env->GetStaticMethodID(clazz_«$ljtype», "values", "()[Lfoundation/pEp/jniadapter/«$jtype»;");
"()[Lfoundation/pEp/jniadapter/«$jtype»;");
assert(method_values); assert(method_values);
jfieldID field_value = env->GetFieldID(clazz_«$ljtype», "value", "I"); jfieldID field_value = env->GetFieldID(clazz_«$ljtype», "value", "I");
assert(field_value); assert(field_value);
jobjectArray values = static_cast<jobjectArray>(env->CallStaticObjectMethod(clazz_«$ljtype», jobjectArray values = static_cast<jobjectArray>(env->CallStaticObjectMethod(clazz_«$ljtype», method_values));
method_values));
assert(values); assert(values);
if (env->ExceptionCheck()) { if (env->ExceptionCheck()) {
return nullptr; // handle exception in Java return nullptr; // handle exception in Java

63
src/codegen/gen_cpp_Message.ysl2

@ -25,28 +25,28 @@ tstylesheet {
using namespace std; using namespace std;
namespace pEp { namespace pEp {
namespace JNIAdapter { namespace JNIAdapter {
static ::«@name» *«@name»_ptr(JNIEnv *env, jobject me) { static ::«@name» *«@name»_ptr(JNIEnv *env, jobject me) {
jfieldID handle; jfieldID handle;
try { try {
handle = getFieldID(env, "foundation/pEp/jniadapter/«$jname»", "handle", "J"); handle = getFieldID(env, "foundation/pEp/jniadapter/«$jname»", "handle", "J");
} } catch (std::exception& ex) {
catch (std::exception& ex) { assert(0);
assert(0); return NULL;
return NULL; }
} return reinterpret_cast<::«@name» *>(env->GetLongField(me, handle));
}
return reinterpret_cast<::«@name» *>(env->GetLongField(me, handle)); };
}
};
}; };
extern "C" { extern "C" {
using namespace pEp::JNIAdapter; using namespace pEp::JNIAdapter;
JNIEXPORT jlong JNICALL Java_foundation_pEp_jniadapter_«$jname»_init(JNIEnv *env, jobject obj) JNIEXPORT jlong JNICALL Java_foundation_pEp_jniadapter_«$jname»_init(JNIEnv *env,
jobject obj)
{ {
pEpLog("called"); pEpLog("called");
::«@name» * _obj = ::new_«@name»(PEP_dir_incoming); ::«@name» * _obj = ::new_«@name»(PEP_dir_incoming);
@ -57,7 +57,9 @@ tstylesheet {
return reinterpret_cast<jlong>(_obj); return reinterpret_cast<jlong>(_obj);
} }
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_«$jname»_release(JNIEnv *env, jobject obj, jlong value) JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_«$jname»_release(JNIEnv *env,
jobject obj,
jlong value)
{ {
pEpLog("called"); pEpLog("called");
if (value) { if (value) {
@ -66,7 +68,9 @@ tstylesheet {
} }
} }
JNIEXPORT jlong JNICALL Java_foundation_pEp_jniadapter_«$jname»__1«$jname»(JNIEnv *env, jobject msg, jbyteArray mime_text) JNIEXPORT jlong JNICALL Java_foundation_pEp_jniadapter_«$jname»__1«$jname»(JNIEnv *env,
jobject msg,
jbyteArray mime_text)
{ {
pEpLog("called"); pEpLog("called");
char *_mime_text = to_string(env, mime_text); char *_mime_text = to_string(env, mime_text);
@ -74,21 +78,26 @@ tstylesheet {
::«@name» *_msg = nullptr; ::«@name» *_msg = nullptr;
PEP_STATUS status = mime_decode_«@name»(_mime_text, _size, &_msg, NULL); PEP_STATUS status = mime_decode_«@name»(_mime_text, _size, &_msg, NULL);
if (status) if (status) {
throw_pEp_Exception(env, status); throw_pEp_Exception(env, status);
}
return reinterpret_cast<jlong>(_msg); return reinterpret_cast<jlong>(_msg);
} }
JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_«$jname»__1encodeMIME(JNIEnv *env, jobject msg) JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_«$jname»__1encodeMIME(JNIEnv *env,
jobject msg)
{ {
pEpLog("called"); pEpLog("called");
«@name» *_obj = «@name»_ptr(env, msg); «@name» *_obj = «@name»_ptr(env, msg);
char *mime_text = nullptr; char *mime_text = nullptr;
PEP_STATUS status = ::mime_encode_«@name»(_obj, false, &mime_text, false); PEP_STATUS status = ::mime_encode_«@name»(_obj, false, &mime_text, false);
if (status) if (status) {
throw_pEp_Exception(env, status); throw_pEp_Exception(env, status);
}
jbyteArray result = from_string(env, mime_text); jbyteArray result = from_string(env, mime_text);
free(mime_text); free(mime_text);
return result; return result;
} }
@ -134,7 +143,8 @@ tstylesheet {
with "name", "concat('set', $jname)"; with "name", "concat('set', $jname)";
} }
|| ||
JNIEXPORT `call "jni_type" with "type", "name(.)"` JNICALL «$getname»(JNIEnv *env, jobject obj) JNIEXPORT `call "jni_type" with "type", "name(.)"` JNICALL «$getname»(JNIEnv *env,
jobject obj)
{ {
pEpLog("called"); pEpLog("called");
«$name» *_obj = «$name»_ptr(env, obj); «$name» *_obj = «$name»_ptr(env, obj);
@ -148,7 +158,10 @@ tstylesheet {
|| ||
} }
JNIEXPORT void JNICALL «$setname»(JNIEnv *env, jobject obj, `call "jni_type" with "type", "name(.)"` value) JNIEXPORT void JNICALL «$setname»(JNIEnv *env,
jobject obj,
`call "jni_type" with "type", "name(.)"`
value)
{ {
pEpLog("called"); pEpLog("called");
«$name» *_obj = «$name»_ptr(env, obj); «$name» *_obj = «$name»_ptr(env, obj);
@ -171,7 +184,7 @@ tstylesheet {
|> free_«$free»(_obj->«$cname»); |> free_«$free»(_obj->«$cname»);
} }
} }
|> if(value){ |> if(value) {
choose { choose {
when "$type = 'string'" { when "$type = 'string'" {
|>> _obj->«$cname» = to_«$type»(env, value); |>> _obj->«$cname» = to_«$type»(env, value);
@ -180,9 +193,9 @@ tstylesheet {
|>> _obj->«$cname» = to_«$type»(env, value); |>> _obj->«$cname» = to_«$type»(env, value);
} }
} }
|> }else{ |> } else {
|> _obj->«$cname» = NULL; |> _obj->«$cname» = NULL;
|> } |> }
} }
} }
|| ||

161
src/cxx/basic_api.cc

@ -12,15 +12,14 @@
#include "passphrase_callback.hh" #include "passphrase_callback.hh"
extern "C" { extern "C" {
using namespace pEp::JNIAdapter;
using pEp::Adapter::session;
using pEp::passphrase_cache;
JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine__1trustwords( using namespace pEp::JNIAdapter;
JNIEnv *env, using pEp::Adapter::session;
using pEp::passphrase_cache;
JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine__1trustwords(JNIEnv *env,
jobject obj, jobject obj,
jobject ident jobject ident)
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -37,10 +36,11 @@ JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine__1trustwords(
PEP_STATUS status = PEP_STATUS_OK; PEP_STATUS status = PEP_STATUS_OK;
if (_ident->fpr == NULL || _ident->fpr[0] == 0) { if (_ident->fpr == NULL || _ident->fpr[0] == 0) {
if (_ident->me) if (_ident->me) {
status = passphraseWrap(::myself, session(), _ident); status = passphraseWrap(::myself, session(), _ident);
else } else {
status = passphraseWrap(::update_identity, session(), _ident); status = passphraseWrap(::update_identity, session(), _ident);
}
} }
if (status != PEP_STATUS_OK) { if (status != PEP_STATUS_OK) {
@ -54,13 +54,13 @@ JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine__1trustwords(
} }
const char *lang; const char *lang;
if (_ident->lang[0]) if (_ident->lang[0]) {
lang = _ident->lang; lang = _ident->lang;
else } else {
lang = "en"; lang = "en";
}
status = passphraseWrap(::trustwords, status = passphraseWrap(::trustwords, session(), static_cast<const char *>(_ident->fpr), lang, &words, &wsize, 10);
session(), static_cast<const char*>(_ident->fpr), lang, &words, &wsize, 10);
if (status != PEP_STATUS_OK) { if (status != PEP_STATUS_OK) {
throw_pEp_Exception(env, status); throw_pEp_Exception(env, status);
@ -70,11 +70,9 @@ JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine__1trustwords(
return from_string(env, words); return from_string(env, words);
} }
JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine__1myself( JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine__1myself(JNIEnv *env,
JNIEnv *env,
jobject obj, jobject obj,
jobject ident jobject ident)
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -96,11 +94,9 @@ JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine__1myself(
return from_identity(env, _ident); return from_identity(env, _ident);
} }
JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine__1updateIdentity( JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine__1updateIdentity(JNIEnv *env,
JNIEnv *env,
jobject obj, jobject obj,
jobject ident jobject ident)
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -111,18 +107,15 @@ JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine__1updateIdentity
std::lock_guard<std::mutex> l(*mutex_local); std::lock_guard<std::mutex> l(*mutex_local);
pEp_identity *_ident = to_identity(env, ident); pEp_identity *_ident = to_identity(env, ident);
passphraseWrap(::update_identity, session(), _ident); passphraseWrap(::update_identity, session(), _ident);
return from_identity(env, _ident); return from_identity(env, _ident);
} }
JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine__1setOwnKey( JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine__1setOwnKey(JNIEnv *env,
JNIEnv *env,
jobject obj, jobject obj,
jobject ident, jobject ident,
jbyteArray fpr jbyteArray fpr)
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -146,11 +139,9 @@ JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine__1setOwnKey(
return from_identity(env, _ident); return from_identity(env, _ident);
} }
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1keyMistrusted( JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1keyMistrusted(JNIEnv *env,
JNIEnv *env,
jobject obj, jobject obj,
jobject ident jobject ident)
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -184,11 +175,9 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1keyMistrusted(
passphraseWrap(::key_mistrusted, session(), _ident); passphraseWrap(::key_mistrusted, session(), _ident);
} }
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1keyResetTrust( JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1keyResetTrust(JNIEnv *env,
JNIEnv *env,
jobject obj, jobject obj,
jobject ident jobject ident)
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -203,10 +192,11 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1keyResetTrust(
PEP_STATUS status = PEP_STATUS_OK; PEP_STATUS status = PEP_STATUS_OK;
if (_ident->fpr == NULL || _ident->fpr[0] == 0) { if (_ident->fpr == NULL || _ident->fpr[0] == 0) {
if (_ident->me) if (_ident->me) {
status = passphraseWrap(::myself, session(), _ident); status = passphraseWrap(::myself, session(), _ident);
else } else {
status = passphraseWrap(::update_identity, session(), _ident); status = passphraseWrap(::update_identity, session(), _ident);
}
} }
if (status != PEP_STATUS_OK) { if (status != PEP_STATUS_OK) {
@ -222,11 +212,9 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1keyResetTrust(
passphraseWrap(::key_reset_trust, session(), _ident); passphraseWrap(::key_reset_trust, session(), _ident);
} }
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1trustPersonalKey( JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1trustPersonalKey(JNIEnv *env,
JNIEnv *env,
jobject obj, jobject obj,
jobject ident jobject ident)
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -241,10 +229,11 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1trustPersonalKey(
PEP_STATUS status = PEP_STATUS_OK; PEP_STATUS status = PEP_STATUS_OK;
if (_ident->fpr == NULL || _ident->fpr[0] == 0) { if (_ident->fpr == NULL || _ident->fpr[0] == 0) {
if (_ident->me) if (_ident->me) {
status = passphraseWrap(::myself, session(), _ident); status = passphraseWrap(::myself, session(), _ident);
else } else {
status = passphraseWrap(::update_identity, session(), _ident); status = passphraseWrap(::update_identity, session(), _ident);
}
} }
if (status != PEP_STATUS_OK) { if (status != PEP_STATUS_OK) {
@ -260,11 +249,9 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1trustPersonalKey(
passphraseWrap(::trust_personal_key, session(), _ident); passphraseWrap(::trust_personal_key, session(), _ident);
} }
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1trustOwnKey( JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1trustOwnKey(JNIEnv *env,
JNIEnv *env,
jobject obj, jobject obj,
jobject ident jobject ident)
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -284,11 +271,9 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1trustOwnKey(
passphraseWrap(::trust_own_key, session(), _ident); passphraseWrap(::trust_own_key, session(), _ident);
} }
JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine__1importKey( JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine__1importKey(JNIEnv *env,
JNIEnv *env,
jobject obj, jobject obj,
jbyteArray key jbyteArray key)
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -301,7 +286,7 @@ JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine__1importKey(
size_t _size = static_cast<size_t>(env->GetArrayLength(key)); size_t _size = static_cast<size_t>(env->GetArrayLength(key));
jbyte* _key = env->GetByteArrayElements(key, NULL); jbyte* _key = env->GetByteArrayElements(key, NULL);
if(_key == NULL){ if(_key == NULL) {
throw_pEp_Exception(env, PEP_OUT_OF_MEMORY); throw_pEp_Exception(env, PEP_OUT_OF_MEMORY);
return NULL; return NULL;
} }
@ -324,11 +309,9 @@ JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine__1importKey(
} }
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1passive_1mode( JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1passive_1mode(JNIEnv *env,
JNIEnv *env,
jobject obj, jobject obj,
jboolean enable jboolean enable)
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -342,11 +325,9 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1passive_1
} }
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1unencrypted_1subject( JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1unencrypted_1subject(JNIEnv *env,
JNIEnv *env,
jobject obj, jobject obj,
jboolean enable jboolean enable)
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -359,8 +340,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1unencrypt
::config_unencrypted_subject(session(), static_cast<bool>(enable)); ::config_unencrypted_subject(session(), static_cast<bool>(enable));
} }
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1blacklist_1add( JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1blacklist_1add(JNIEnv *env,
JNIEnv *env,
jobject obj, jobject obj,
jbyteArray fpr jbyteArray fpr
) )
@ -385,14 +365,11 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1blacklist_1add(
throw_pEp_Exception(env, status); throw_pEp_Exception(env, status);
return; return;
} }
} }
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1blacklist_1delete( JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1blacklist_1delete(JNIEnv *env,
JNIEnv *env,
jobject obj, jobject obj,
jbyteArray fpr jbyteArray fpr)
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -417,11 +394,9 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1blacklist_1delete
} }
JNIEXPORT jboolean JNICALL Java_foundation_pEp_jniadapter_Engine__1blacklist_1is_1listed( JNIEXPORT jboolean JNICALL Java_foundation_pEp_jniadapter_Engine__1blacklist_1is_1listed(JNIEnv *env,
JNIEnv *env,
jobject obj, jobject obj,
jbyteArray fpr jbyteArray fpr)
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -448,12 +423,10 @@ JNIEXPORT jboolean JNICALL Java_foundation_pEp_jniadapter_Engine__1blacklist_1is
return (jboolean)_listed; return (jboolean)_listed;
} }
JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine__1getCrashdumpLog( JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine__1getCrashdumpLog(JNIEnv *env,
JNIEnv *env,
jobject obj, jobject obj,
jint dummy, jint dummy,
jint maxlines jint maxlines)
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -477,40 +450,24 @@ JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine__1getCrashdum
return from_string(env, _logdata); return from_string(env, _logdata);
} }
JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine__1getUserDirectory( JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine__1getUserDirectory(JNIEnv *env,
JNIEnv *env, jobject obj)
jobject obj
)
{ {
pEpLog("called"); pEpLog("called");
return from_string(env, ::per_user_directory()); return from_string(env, ::per_user_directory());
} }
JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine__1getMachineDirectory( JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine__1getMachineDirectory(JNIEnv *env,
JNIEnv *env, jobject obj)
jobject obj
)
{ {
pEpLog("called"); pEpLog("called");
return from_string(env, ::per_machine_directory()); return from_string(env, ::per_machine_directory());
} }
//void logPassphraseCache() {
// try { JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1passphrase(JNIEnv * env,
//// while(true) { jobject obj,
// pEpLog("Cache: '" << cache.latest_passphrase() << "'"); jbyteArray passphrase)
//// }
// } catch(pEp::PassphraseCache::Empty e) {
// pEpLog(e.what());
// } catch(pEp::PassphraseCache::Exhausted ex) {
// pEpLog(ex.what());
// }
//}
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1passphrase
(JNIEnv * env,
jobject obj,
jbyteArray passphrase)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -530,12 +487,10 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1passphras
} }
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1passphrase_1for_1new_1keys( JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1passphrase_1for_1new_1keys(JNIEnv *env,
JNIEnv *env,
jobject obj, jobject obj,
jboolean enable, jboolean enable,
jbyteArray passphrase jbyteArray passphrase)
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -555,8 +510,6 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1passphras
throw_pEp_Exception(env, status); throw_pEp_Exception(env, status);
return ; return ;
} }
} }
} // extern "C" } // extern "C"

168
src/cxx/foundation_pEp_jniadapter_AbstractEngine.cc

@ -15,9 +15,7 @@ using namespace pEp::JNIAdapter;
using namespace utility; // for libpEpAdapter locked queue impl. TODO:rename using namespace utility; // for libpEpAdapter locked queue impl. TODO:rename
bool first = true; bool first = true;
JavaVM *jvm= nullptr; JavaVM *jvm= nullptr;
std::mutex mutex_obj; std::mutex mutex_obj;
jfieldID signal_field_value = nullptr; jfieldID signal_field_value = nullptr;
@ -67,45 +65,60 @@ namespace JNISync {
void jni_init() { void jni_init() {
JNIEnv *_env = JNISync::env(); JNIEnv * _env = JNISync::env();
messageClass = static_cast<jclass>( messageClass = static_cast<jclass>(_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/Message")));
_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/Message"))); identityClass = static_cast<jclass>(_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/_Identity")));
identityClass = static_cast<jclass>( signalClass = static_cast<jclass>(_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/SyncHandshakeSignal")));
_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/_Identity"))); passphraseTypeClass = static_cast<jclass>(_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/PassphraseType")));
signalClass = static_cast<jclass>(
_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/SyncHandshakeSignal")));
passphraseTypeClass = static_cast<jclass>(
_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/PassphraseType")));
engineClass = static_cast<jclass>(_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/Engine"))); engineClass = static_cast<jclass>(_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/Engine")));
messageConstructorMethodID = _env->GetMethodID(messageClass, "<init>", "(J)V"); messageConstructorMethodID = _env->GetMethodID(
messageClass,
"<init>",
"(J)V");
messageToSendMethodID = _env->GetMethodID( messageToSendMethodID = _env->GetMethodID(
engineClass, engineClass,
"messageToSendCallFromC", "messageToSendCallFromC",
"(Lfoundation/pEp/jniadapter/Message;)I"); "(Lfoundation/pEp/jniadapter/Message;)I");
needsFastPollMethodID = _env->GetMethodID( needsFastPollMethodID = _env->GetMethodID(
engineClass, engineClass,
"needsFastPollCallFromC", "needsFastPollCallFromC",
"(Z)I"); "(Z)I");
notifyHandShakeMethodID = _env->GetMethodID( notifyHandShakeMethodID = _env->GetMethodID(
engineClass, engineClass,
"notifyHandshakeCallFromC", "notifyHandshakeCallFromC",
"(Lfoundation/pEp/jniadapter/_Identity;Lfoundation/pEp/jniadapter/_Identity;Lfoundation/pEp/jniadapter/SyncHandshakeSignal;)I"); "(Lfoundation/pEp/jniadapter/_Identity;Lfoundation/pEp/jniadapter/_Identity;Lfoundation/pEp/jniadapter/SyncHandshakeSignal;)I");
passphraseRequiredMethodID = _env->GetMethodID( passphraseRequiredMethodID = _env->GetMethodID(
engineClass, engineClass,
"passphraseRequiredFromC", "passphraseRequiredFromC",
"(Lfoundation/pEp/jniadapter/PassphraseType;)[B"); "(Lfoundation/pEp/jniadapter/PassphraseType;)[B");
sync_handshake_signal_values = JNISync::env()->GetStaticMethodID(signalClass, "values", sync_handshake_signal_values = JNISync::env()->GetStaticMethodID(
"()[Lfoundation/pEp/jniadapter/SyncHandshakeSignal;"); signalClass,
passphrase_status_values = JNISync::env()->GetStaticMethodID(passphraseTypeClass, "values", "values",
"()[Lfoundation/pEp/jniadapter/PassphraseType;"); "()[Lfoundation/pEp/jniadapter/SyncHandshakeSignal;");
signal_field_value = JNISync::env()->GetFieldID(signalClass, "value", "I");
passphrase_type_field_value = JNISync::env()->GetFieldID(passphraseTypeClass, "value", "I"); passphrase_status_values = JNISync::env()->GetStaticMethodID(
passphraseTypeClass,
"values",
"()[Lfoundation/pEp/jniadapter/PassphraseType;");
signal_field_value = JNISync::env()->GetFieldID(
signalClass,
"value",
"I");
passphrase_type_field_value = JNISync::env()->GetFieldID(passphraseTypeClass, "value", "I");
} }
char* JNIAdapter::passphraseRequiredCallback(const PEP_STATUS status) { char* JNIAdapter::passphraseRequiredCallback(
const PEP_STATUS status)
{
pEpLog("called"); pEpLog("called");
jobject status_ = nullptr; jobject status_ = nullptr;
{ {
@ -113,8 +126,7 @@ char* JNIAdapter::passphraseRequiredCallback(const PEP_STATUS status) {
assert(passphrase_status_values); assert(passphrase_status_values);
assert(passphrase_type_field_value); assert(passphrase_type_field_value);
jobjectArray values = static_cast<jobjectArray>(JNISync::env()->CallStaticObjectMethod(passphraseTypeClass, jobjectArray values = static_cast<jobjectArray>(JNISync::env()->CallStaticObjectMethod(passphraseTypeClass, passphrase_status_values));
passphrase_status_values));
if (JNISync::env()->ExceptionCheck()) { if (JNISync::env()->ExceptionCheck()) {
JNISync::env()->ExceptionClear(); JNISync::env()->ExceptionClear();
@ -149,19 +161,21 @@ char* JNIAdapter::passphraseRequiredCallback(const PEP_STATUS status) {
PEP_STATUS messageToSend(message *msg) PEP_STATUS messageToSend(message *msg)
{ {
std::lock_guard<std::mutex> l(mutex_obj); std::lock_guard <std::mutex> l(mutex_obj);
pEpLog("called"); pEpLog("called");
// Passphrase // Passphrase
// When a protocol implementation of the p≡p engine using messageToSend() cannot sign or encrypt with an // When a protocol implementation of the p≡p engine using messageToSend() cannot sign or encrypt with an
// empty passphrase and not with the configured passphrase it is calling messageToSend() with a NULL instead // empty passphrase and not with the configured passphrase it is calling messageToSend() with a NULL instead
// of a struct _message object. // of a struct _message object.
if (Adapter::on_sync_thread() && !msg) if (Adapter::on_sync_thread() && !msg) {
return pEp::PassphraseCache::config_next_passphrase(); return pEp::PassphraseCache::config_next_passphrase();
}
// reset passphrase iterator // reset passphrase iterator
if (Adapter::on_sync_thread()) if (Adapter::on_sync_thread()) {
pEp::PassphraseCache::config_next_passphrase(true); pEp::PassphraseCache::config_next_passphrase(true);
}
jobject msg_ = nullptr; jobject msg_ = nullptr;
assert(messageClass && messageConstructorMethodID && objj && messageToSendMethodID); assert(messageClass && messageConstructorMethodID && objj && messageToSendMethodID);
@ -175,11 +189,12 @@ PEP_STATUS messageToSend(message *msg)
JNISync::env()->ExceptionClear(); JNISync::env()->ExceptionClear();
} }
return status; return status;
} }
PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal) PEP_STATUS notifyHandshake(pEp_identity *me,
pEp_identity *partner,
sync_handshake_signal signal)
{ {
std::lock_guard<std::mutex> l(mutex_obj); std::lock_guard<std::mutex> l(mutex_obj);
pEpLog("called"); pEpLog("called");
@ -196,8 +211,7 @@ PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handsha
assert(sync_handshake_signal_values); assert(sync_handshake_signal_values);
assert(signal_field_value); assert(signal_field_value);
jobjectArray values = static_cast<jobjectArray>(JNISync::env()->CallStaticObjectMethod(signalClass, jobjectArray values = static_cast<jobjectArray>(JNISync::env()->CallStaticObjectMethod(signalClass, sync_handshake_signal_values));
sync_handshake_signal_values));
if (JNISync::env()->ExceptionCheck()) { if (JNISync::env()->ExceptionCheck()) {
JNISync::env()->ExceptionClear(); JNISync::env()->ExceptionClear();
return PEP_UNKNOWN_ERROR; return PEP_UNKNOWN_ERROR;
@ -231,10 +245,8 @@ PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handsha
extern "C" { extern "C" {
using namespace pEp; using namespace pEp;
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_init( JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_init(JNIEnv *env,
JNIEnv *env, jobject obj)
jobject obj
)
{ {
std::lock_guard<std::mutex> l(global_mutex); // global mutex for write access to <unordered_map> std::lock_guard<std::mutex> l(global_mutex); // global mutex for write access to <unordered_map>
pEpLog("called"); pEpLog("called");
@ -253,10 +265,8 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_init(
Adapter::session(); Adapter::session();
} }
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_release( JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_release(JNIEnv *env,
JNIEnv *env, jobject obj)
jobject obj
)
{ {
std::lock_guard<std::mutex> l(global_mutex); // global mutex for write access to <unordered_map> std::lock_guard<std::mutex> l(global_mutex); // global mutex for write access to <unordered_map>
pEpLog("called"); pEpLog("called");
@ -264,10 +274,8 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_release(
Adapter::session(pEp::Adapter::release); Adapter::session(pEp::Adapter::release);
} }
JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1getVersion( JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1getVersion(JNIEnv *env,
JNIEnv *env, jobject obj)
jobject obj
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -280,10 +288,8 @@ JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1getVer
return env->NewStringUTF(::get_engine_version()); return env->NewStringUTF(::get_engine_version());
} }
JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1getProtocolVersion( JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1getProtocolVersion(JNIEnv *env,
JNIEnv *env, jobject obj)
jobject obj
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -296,9 +302,10 @@ JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1getPro
return env->NewStringUTF(::get_protocol_version()); return env->NewStringUTF(::get_protocol_version());
} }
int examine_identity(pEp_identity *ident, void *arg) int examine_identity(pEp_identity *ident,
void *arg)
{ {
locked_queue< pEp_identity * > *queue = static_cast<locked_queue<pEp_identity*>*>(arg); locked_queue < pEp_identity * > *queue = static_cast<locked_queue < pEp_identity * > * > (arg);
queue->push_back(identity_dup(ident)); queue->push_back(identity_dup(ident));
return 0; return 0;
} }
@ -306,10 +313,11 @@ int examine_identity(pEp_identity *ident, void *arg)
pEp_identity *retrieve_next_identity(void *arg) pEp_identity *retrieve_next_identity(void *arg)
{ {
pEpLog("called"); pEpLog("called");
locked_queue< pEp_identity * > *queue = static_cast<locked_queue<pEp_identity*>*>(arg); locked_queue < pEp_identity * > *queue = static_cast<locked_queue < pEp_identity * > * > (arg);
while (!queue->size()) while (!queue->size()) {
usleep(100000); usleep(100000);
}
pEp_identity *ident = queue->front(); pEp_identity *ident = queue->front();
queue->pop_front(); queue->pop_front();
@ -319,7 +327,7 @@ pEp_identity *retrieve_next_identity(void *arg)
static void *keyserver_thread_routine(void *arg) static void *keyserver_thread_routine(void *arg)
{ {
PEP_STATUS status = do_keymanagement(retrieve_next_identity, arg); PEP_STATUS status = do_keymanagement(retrieve_next_identity, arg);
locked_queue< pEp_identity * > *queue = static_cast<locked_queue<pEp_identity*>*>(arg); locked_queue < pEp_identity * > *queue = static_cast<locked_queue < pEp_identity * > * > (arg);
while (queue->size()) { while (queue->size()) {
pEp_identity *ident = queue->front(); pEp_identity *ident = queue->front();
@ -328,13 +336,11 @@ static void *keyserver_thread_routine(void *arg)
} }
delete queue; delete queue;
return reinterpret_cast<void*>(status); return reinterpret_cast<void *>(status);
} }
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1startKeyserverLookup( JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1startKeyserverLookup(JNIEnv *env,
JNIEnv *env, jobject obj)
jobject obj
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -375,10 +381,8 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1startKeys
pthread_create(thread, nullptr, keyserver_thread_routine, static_cast<void*>(queue)); pthread_create(thread, nullptr, keyserver_thread_routine, static_cast<void*>(queue));
} }
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1stopKeyserverLookup( JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1stopKeyserverLookup(JNIEnv *env,
JNIEnv *env, jobject obj)
jobject obj
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -419,10 +423,8 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1stopKeyse
free(thread); free(thread);
} }
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1startSync( JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1startSync(JNIEnv *env,
JNIEnv *env, jobject obj)
jobject obj
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -434,17 +436,14 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1startSync
try { try {
CallbackDispatcher::start_sync(); CallbackDispatcher::start_sync();
// Adapter::startup<JNISync>(messageToSend, notifyHandshake, &o, &JNISync::onSyncStartup, &JNISync::onSyncShutdown);
} catch (RuntimeError& ex) { } catch (RuntimeError& ex) {
throw_pEp_Exception(env, ex.status); throw_pEp_Exception(env, ex.status);
return; return;
} }
} }
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1stopSync( JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1stopSync(JNIEnv *env,
JNIEnv *env, jobject obj)
jobject obj
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {
@ -455,13 +454,10 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1stopSync(
std::lock_guard<std::mutex> l(*mutex_local); std::lock_guard<std::mutex> l(*mutex_local);
CallbackDispatcher::stop_sync(); CallbackDispatcher::stop_sync();
// Adapter::shutdown();
} }
JNIEXPORT jboolean JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1isSyncRunning( JNIEXPORT jboolean JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1isSyncRunning(JNIEnv *env,
JNIEnv *env, jobject obj)
jobject obj
)
{ {
std::mutex *mutex_local = nullptr; std::mutex *mutex_local = nullptr;
{ {

45
src/cxx/foundation_pEp_jniadapter__Blob.cc

@ -8,39 +8,43 @@
#include "foundation_pEp_jniadapter__Blob.h" #include "foundation_pEp_jniadapter__Blob.h"
namespace pEp { namespace pEp {
namespace JNIAdapter { namespace JNIAdapter {
static ::bloblist_t *bloblist_ptr(JNIEnv *env, jobject me) {
jfieldID handle;
try { static ::bloblist_t *bloblist_ptr(JNIEnv *env, jobject me) {
handle = getFieldID(env, "foundation/pEp/jniadapter/Blob", "mime_type", "Ljava/lang/String"); jfieldID handle;
}
catch (std::exception& ex) {
assert(0);
return NULL;
}
return reinterpret_cast<::bloblist_t*>(env->GetLongField(me, handle)); try {
} handle = getFieldID(env, "foundation/pEp/jniadapter/Blob", "mime_type", "Ljava/lang/String");
}; } catch (std::exception &ex) {
}; assert(0);
return NULL;
}
return reinterpret_cast<::bloblist_t *>(env->GetLongField(me, handle));
}
}; //namespace JNIAdapter
}; //namespace pEp
extern "C" { extern "C" {
using namespace std; using namespace std;
using namespace pEp::JNIAdapter; using namespace pEp::JNIAdapter;
JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter__1Blob__1dataToXER(JNIEnv *env, jobject obj)
JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter__1Blob__1dataToXER(JNIEnv *env,
jobject obj)
{ {
pEpLog("called"); pEpLog("called");
bloblist_t *b = to_blob(env, obj); bloblist_t *b = to_blob(env, obj);
char *out = nullptr; char *out = nullptr;
// RFC 1049 / RFC 2045 : The type, subtype, and parameter names are not case sensitive. // RFC 1049 / RFC 2045 : The type, subtype, and parameter names are not case sensitive.
if(strcasecmp(b->mime_type, "application/pEp.sync") == 0) { if (strcasecmp(b->mime_type, "application/pEp.sync") == 0) {
PEP_STATUS status = ::PER_to_XER_Sync_msg(b->value, static_cast<size_t>(b->size), &out); PEP_STATUS status = ::PER_to_XER_Sync_msg(b->value, static_cast<size_t>(b->size), &out);
if (status) if (status) {
throw_pEp_Exception(env, status); throw_pEp_Exception(env, status);
}
jbyteArray result = from_string(env, out); jbyteArray result = from_string(env, out);
free(out); free(out);
@ -48,17 +52,18 @@ JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter__1Blob__1dataToXER(J
} }
// RFC 1049 / RFC 2045 : The type, subtype, and parameter names are not case sensitive. // RFC 1049 / RFC 2045 : The type, subtype, and parameter names are not case sensitive.
if(strcasecmp(b->mime_type, "application/pEp.keyreset") == 0) { if (strcasecmp(b->mime_type, "application/pEp.keyreset") == 0) {
PEP_STATUS status = ::PER_to_XER_Distribution_msg(b->value, static_cast<size_t>(b->size), &out); PEP_STATUS status = ::PER_to_XER_Distribution_msg(b->value, static_cast<size_t>(b->size), &out);
if (status) if (status) {
throw_pEp_Exception(env, status); throw_pEp_Exception(env, status);
}
jbyteArray result = from_string(env, out); jbyteArray result = from_string(env, out);
free(out); free(out);
return result; return result;
} }
return from_string(env,b->value); return from_string(env, b->value);
} }
}; // extern "C" }; // extern "C"

6
src/cxx/identity_api.cc

@ -3,10 +3,12 @@
#include "jniutils.hh" #include "jniutils.hh"
extern "C" { extern "C" {
JNIEXPORT jint JNICALL Java_foundation_pEp_jniadapter_Identity__1getRating(JNIEnv *env, jobject thiz, jint comm_type) JNIEXPORT jint JNICALL Java_foundation_pEp_jniadapter_Identity__1getRating(
JNIEnv *env,
jobject thiz,
jint comm_type)
{ {
pEpLog("called"); pEpLog("called");
return ::rating_from_comm_type(static_cast<PEP_comm_type>(comm_type)); return ::rating_from_comm_type(static_cast<PEP_comm_type>(comm_type));

1535
src/cxx/jniutils.cc

File diff suppressed because it is too large

231
src/cxx/jniutils.hh

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <unordered_map> #include <unordered_map>
#include <thread> #include <thread>
#include <mutex> #include <mutex>
@ -19,112 +20,128 @@
#endif #endif
namespace pEp { namespace pEp {
namespace JNIAdapter { namespace JNIAdapter {
// Global mutex needs to be locked in all constructors which insert their own mutex object // Global mutex needs to be locked in all constructors which insert their own mutex object
// into the unordered_map (which is thread safe for read, but not for write) // into the unordered_map (which is thread safe for read, but not for write)
extern std::mutex global_mutex; extern std::mutex global_mutex;
// Stores mutex per java object // Stores mutex per java object
extern std::unordered_map<long, std::mutex*> engine_objid_mutex; extern std::unordered_map<long, std::mutex *> engine_objid_mutex;
// needs to be called after create_engine_java_object_mutex() // needs to be called after create_engine_java_object_mutex()
// and before release_engine_java_object_mutex() // and before release_engine_java_object_mutex()
// Thread safe // Thread safe
std::mutex* get_engine_java_object_mutex( std::mutex *get_engine_java_object_mutex(JNIEnv *env,
JNIEnv *env, jobject me);
jobject me
); // Needs to be called exactly once per obj, in the constructor of the obj
// You need to lock a global mutex before calling this function (write to unordered_map)
// Needs to be called exactly once per obj, in the constructor of the obj void create_engine_java_object_mutex(JNIEnv *env,
// You need to lock a global mutex before calling this function (write to unordered_map) jobject me);
void create_engine_java_object_mutex(
JNIEnv *env, // Needs to be called exactly once per obj, in the destructor of this obj
jobject me // You need to lock a global mutex before calling this function (write to unordered_map)
); void release_engine_java_object_mutex(JNIEnv *env,
jobject me);
// Needs to be called exactly once per obj, in the destructor of this obj
// You need to lock a global mutex before calling this function (write to unordered_map)
void release_engine_java_object_mutex( jclass findClass(JNIEnv *env,
JNIEnv *env, const char *classname);
jobject me
); jfieldID getFieldID(JNIEnv *env,
const char *classname,
const char *fieldname,
jclass findClass(JNIEnv *env, const char *classname); const char *signature);
jfieldID getFieldID( jfieldID getFieldID(JNIEnv *env,
JNIEnv *env, const char *classname,
const char *classname, const char *fieldname,
const char *fieldname, const char *signature,
const char *signature const jclass clazz);
);
jint callIntMethod(JNIEnv *env,
jfieldID getFieldID( jobject obj,
JNIEnv *env, const char *methodname);
const char *classname,
const char *fieldname, jlong callLongMethod(JNIEnv *env,
const char *signature, jobject obj,
const jclass clazz const char *methodname);
);
jobject callObjectMethod(JNIEnv *env,
jint callIntMethod( jobject obj,
JNIEnv *env, const char *methodname,
jobject obj, jint index);
const char *methodname
); jboolean callBooleanMethod(JNIEnv *env,
jobject obj,
jlong callLongMethod( const char *methodname,
JNIEnv *env, jobject o);
jobject obj,
const char *methodname jint outOfMemory(JNIEnv *env);
);
jobject from_Integer(JNIEnv *env,
jobject callObjectMethod( int val);
JNIEnv *env,
jobject obj, int to_Integer(JNIEnv *env,
const char *methodname, jobject obj);
jint index
); jbyteArray from_string(JNIEnv *env,
const char *str);
jboolean callBooleanMethod(
JNIEnv *env, char *to_string(JNIEnv *env,
jobject obj, jbyteArray str);
const char *methodname,
jobject o jobject from_stringlist(JNIEnv *env,
); stringlist_t *sl);
jint outOfMemory(JNIEnv *env); stringlist_t *to_stringlist(JNIEnv *env,
jobject obj);
jobject from_Integer(JNIEnv *env, int val);
int to_Integer(JNIEnv *env, jobject obj); jobject from_stringpairlist(JNIEnv *env,
stringpair_list_t *sl);
jbyteArray from_string(JNIEnv *env, const char *str);
char *to_string(JNIEnv *env, jbyteArray str); stringpair_list_t *to_stringpairlist(JNIEnv *env,
jobject obj);
jobject from_stringlist(JNIEnv *env, stringlist_t *sl);
stringlist_t *to_stringlist(JNIEnv *env, jobject obj); jobject from_timestamp(JNIEnv *env,
timestamp *ts);
jobject from_stringpairlist(JNIEnv *env, stringpair_list_t *sl);
stringpair_list_t *to_stringpairlist(JNIEnv *env, jobject obj); timestamp *to_timestamp(JNIEnv *env,
jobject date);
jobject from_timestamp(JNIEnv *env, timestamp *ts);
timestamp *to_timestamp(JNIEnv *env, jobject date); jobject from_identity(JNIEnv *env,
pEp_identity *ident);
jobject from_identity(JNIEnv *env, pEp_identity *ident);
jobject from_identity(JNIEnv *env, pEp_identity *ident, jclass identityClass); jobject from_identity(JNIEnv *env,
pEp_identity *to_identity(JNIEnv *env, jobject obj); pEp_identity *ident,
jclass identityClass);
jobject from_identitylist(JNIEnv *env, identity_list *il);
identity_list *to_identitylist(JNIEnv *env, jobject obj); pEp_identity *to_identity(JNIEnv *env,
jobject obj);
jobject from_bloblist(JNIEnv *env, bloblist_t *bl);
bloblist_t *to_blob(JNIEnv *env, jobject obj); jobject from_identitylist(JNIEnv *env,
bloblist_t *to_bloblist(JNIEnv *env, jobject obj); identity_list *il);
PEP_enc_format to_EncFormat(JNIEnv *env, jobject obj); identity_list *to_identitylist(JNIEnv *env,
PEP_CIPHER_SUITE to_CipherSuite(JNIEnv *env, jobject obj); jobject obj);
sync_handshake_result to_SyncHandshakeResult(JNIEnv *env, jobject obj); jobject from_bloblist(JNIEnv *env,
}; bloblist_t *bl);
bloblist_t *to_blob(JNIEnv *env,
jobject obj);
bloblist_t *to_bloblist(JNIEnv *env,
jobject obj);
PEP_enc_format to_EncFormat(JNIEnv *env,
jobject obj);
PEP_CIPHER_SUITE to_CipherSuite(JNIEnv *env,
jobject obj);
sync_handshake_result to_SyncHandshakeResult(JNIEnv *env,
jobject obj);
};
}; };

9
src/cxx/passphrase_callback.hh

@ -1,14 +1,15 @@
#pragma once #pragma once
#include <pEp/passphrase_cache.hh> #include <pEp/passphrase_cache.hh>
namespace pEp { namespace pEp {
namespace JNIAdapter { namespace JNIAdapter {
char* passphraseRequiredCallback(const PEP_STATUS status); char *passphraseRequiredCallback(const PEP_STATUS status);
template<typename... A> PEP_STATUS passphraseWrap(PEP_STATUS f(PEP_SESSION, A...), PEP_SESSION session, A... a);
template<typename... A> PEP_STATUS passphraseWrap(PEP_STATUS f(PEP_SESSION, A...), PEP_SESSION session, A... a); }
}
} }
#include "passphrase_callback.hxx" #include "passphrase_callback.hxx"

68
src/cxx/passphrase_callback.hxx

@ -3,40 +3,40 @@
#include "passphrase_callback.hh" #include "passphrase_callback.hh"
namespace pEp { namespace pEp {
namespace JNIAdapter { namespace JNIAdapter {
template<typename... A> PEP_STATUS passphraseWrap(PEP_STATUS f(PEP_SESSION, A...), PEP_SESSION session, A... a) { template<typename... A> PEP_STATUS passphraseWrap(PEP_STATUS f(PEP_SESSION, A...), PEP_SESSION session, A... a) {
pEpLog("cached passphrase mode"); pEpLog("cached passphrase mode");
bool retryAgain = false; bool retryAgain = false;
int maxRetries = 3; int maxRetries = 3;
int retryCount = 0; int retryCount = 0;
PEP_STATUS status; PEP_STATUS status;
do { do {
// the actual target function // the actual target function
pEpLog("calling passphrase_cache.api from basic_api"); pEpLog("calling passphrase_cache.api from basic_api");
status = passphrase_cache.api(f, session, a...); status = passphrase_cache.api(f, session, a...);
pEpLog("PEP_STATUS:" << status); pEpLog("PEP_STATUS:" << status);
if (status == PEP_PASSPHRASE_REQUIRED || if (status == PEP_PASSPHRASE_REQUIRED ||
status == PEP_WRONG_PASSPHRASE || status == PEP_WRONG_PASSPHRASE ||
status == PEP_PASSPHRASE_FOR_NEW_KEYS_REQUIRED) status == PEP_PASSPHRASE_FOR_NEW_KEYS_REQUIRED)
{ {
pEpLog("none of the cached passphrases worked"); pEpLog("none of the cached passphrases worked");
if (retryCount < maxRetries) { if (retryCount < maxRetries) {
// call the app // call the app
char *_passphrase = passphraseRequiredCallback(status); char *_passphrase = passphraseRequiredCallback(status);
pEpLog("callback returned, config_passphrase() with new passphrase"); pEpLog("callback returned, config_passphrase() with new passphrase");
PEP_STATUS status = ::config_passphrase(session, passphrase_cache.add(_passphrase)); PEP_STATUS status = ::config_passphrase(session, passphrase_cache.add(_passphrase));
retryAgain = true; retryAgain = true;
retryCount++; retryCount++;
} else { } else {
pEpLog("max retries reached:" << maxRetries); pEpLog("max retries reached:" << maxRetries);
retryAgain = false; retryAgain = false;
} }
} else { } else {
retryAgain = false; retryAgain = false;
}
} while (retryAgain);
return status;
} }
} } while (retryAgain);
return status;
}
}
} }
Loading…
Cancel
Save