|
@ -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; |
|
|
{ |
|
|
{ |
|
|