diff options
author | Sven Gothel <[email protected]> | 2022-08-28 05:36:05 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-08-28 05:36:05 +0200 |
commit | b8d0cd9007c1db8a97b7026151a95c5b91bc1a69 (patch) | |
tree | 8efecccbd619acff51d9f9a22303e62d97172d86 /java/jni | |
parent | 113e141794c795c915cd19407ff1504240664a6b (diff) |
Revise CipherpackListener: Simplify notify semantics; notifyError() handles & reports all errors; Allow to abort process via notifyHeader() and notifyProgress() return value
Simplify notify semantics
- notifyError() handles & reports all errors
- notifyHeader() is only called on verified valid header, drop 'verified' argument
- notifyEnd() is only called on success, drop 'success' argument
Allow to abort process via notifyHeader() and notifyProgress() return value
- a user process abort @ notifyHeader(), notifyProgress() and contentProcessed() is no error
- fully tested in C++ and Java test case
- Using concurrently processed ByteInStream_{URL,Feeder}
are properly unblocked and closed via ByteInStream_{URL,Feeder}::close()
Implementation Details:
- Added notifyError() calls with actual message, dropping ERR_PRINT*()
- Properly detect CipherpackListener abort while processing content etc
- Only call notifyProgress() if contentProcessed() wasn't called or returned true (no abort)
Unit Tests (C++, Java):
- Using a LoggingCipherpackListener instance to
- log notifyError() messages
- count all notify messages per types
- validate all notify counts after processing
- optionally allow abort processing @ header, progress or content
- Fully test CipherpackListener incl process abort
Diffstat (limited to 'java/jni')
-rw-r--r-- | java/jni/cipherpack/CipherpackListener.cxx | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/java/jni/cipherpack/CipherpackListener.cxx b/java/jni/cipherpack/CipherpackListener.cxx index a4b85f4..c776928 100644 --- a/java/jni/cipherpack/CipherpackListener.cxx +++ b/java/jni/cipherpack/CipherpackListener.cxx @@ -33,10 +33,10 @@ // static const std::string _contentTypeClassName("org/cipherpack/CipherpackListener/ContentType"); // static const std::string _contentTypeClazzGetArgs("(B)Lorg/cipherpack/CipherpackListener/ContentType;"); -static const std::string _notifyErrorMethodArgs("(ZLjava/lang/String;)V"); -static const std::string _notifyHeaderMethodArgs("(ZLorg/cipherpack/PackHeader;Z)V"); -static const std::string _notifyProgressMethodArgs("(ZJJ)V"); -static const std::string _notifyEndMethodArgs("(ZLorg/cipherpack/PackHeader;Z)V"); +static const std::string _notifyErrorMethodArgs("(ZLorg/cipherpack/PackHeader;Ljava/lang/String;)V"); +static const std::string _notifyHeaderMethodArgs("(ZLorg/cipherpack/PackHeader;)Z"); +static const std::string _notifyProgressMethodArgs("(ZJJ)Z"); +static const std::string _notifyEndMethodArgs("(ZLorg/cipherpack/PackHeader;)V"); static const std::string _getSendContentMethodArgs("(Z)Z"); static const std::string _contentProcessedImplMethodArgs("(ZZ[BZ)Z"); @@ -87,54 +87,53 @@ class JNICipherpackListener : public cipherpack::CipherpackListener { mContentProcessedImpl = jau::jni::search_method(env, cpListenerClazz, "contentProcessedImpl", _contentProcessedImplMethodArgs.c_str(), false); } - void notifyError(const bool decrypt_mode, const std::string& msg) noexcept override { + void notifyError(const bool decrypt_mode, const cipherpack::PackHeader& header, const std::string& msg) noexcept override { JNIEnv *env = *jau::jni::jni_env; jau::jni::JavaAnonRef asl_java = getJavaObject(); // hold until done! jau::jni::JavaGlobalObj::check(asl_java, E_FILE_LINE); + jobject jph = jcipherpack::to_jPackHeader(env, header); jstring jmsg = jau::jni::from_string_to_jstring(env, msg); - env->CallVoidMethod(jau::jni::JavaGlobalObj::GetObject(asl_java), mNotifyError, decrypt_mode ? JNI_TRUE : JNI_FALSE, jmsg); + env->CallVoidMethod(jau::jni::JavaGlobalObj::GetObject(asl_java), mNotifyError, + decrypt_mode ? JNI_TRUE : JNI_FALSE, + jph, + jmsg); jau::jni::java_exception_check_and_throw(env, E_FILE_LINE); env->DeleteLocalRef(jmsg); } - private: - - - public: - - void notifyHeader(const bool decrypt_mode, const cipherpack::PackHeader& header, const bool verified) noexcept override { + bool notifyHeader(const bool decrypt_mode, const cipherpack::PackHeader& header) noexcept override { JNIEnv *env = *jau::jni::jni_env; jau::jni::JavaAnonRef asl_java = getJavaObject(); // hold until done! jau::jni::JavaGlobalObj::check(asl_java, E_FILE_LINE); jobject jph = jcipherpack::to_jPackHeader(env, header); - env->CallVoidMethod(jau::jni::JavaGlobalObj::GetObject(asl_java), mNotifyHeader, + jboolean res = env->CallBooleanMethod(jau::jni::JavaGlobalObj::GetObject(asl_java), mNotifyHeader, decrypt_mode ? JNI_TRUE : JNI_FALSE, - jph, - verified ? JNI_TRUE : JNI_FALSE); + jph); jau::jni::java_exception_check_and_throw(env, E_FILE_LINE); env->DeleteLocalRef(jph); + return JNI_TRUE == res; } - void notifyProgress(const bool decrypt_mode, const uint64_t plaintext_size, const uint64_t bytes_processed) noexcept override { + bool notifyProgress(const bool decrypt_mode, const uint64_t plaintext_size, const uint64_t bytes_processed) noexcept override { JNIEnv *env = *jau::jni::jni_env; jau::jni::JavaAnonRef asl_java = getJavaObject(); // hold until done! jau::jni::JavaGlobalObj::check(asl_java, E_FILE_LINE); - env->CallVoidMethod(jau::jni::JavaGlobalObj::GetObject(asl_java), mNotifyProgress, + jboolean res = env->CallBooleanMethod(jau::jni::JavaGlobalObj::GetObject(asl_java), mNotifyProgress, decrypt_mode ? JNI_TRUE : JNI_FALSE, static_cast<jlong>(plaintext_size), static_cast<jlong>(bytes_processed)); jau::jni::java_exception_check_and_throw(env, E_FILE_LINE); + return JNI_TRUE == res; } - void notifyEnd(const bool decrypt_mode, const cipherpack::PackHeader& header, const bool success) noexcept override { + void notifyEnd(const bool decrypt_mode, const cipherpack::PackHeader& header) noexcept override { JNIEnv *env = *jau::jni::jni_env; jau::jni::JavaAnonRef asl_java = getJavaObject(); // hold until done! jau::jni::JavaGlobalObj::check(asl_java, E_FILE_LINE); jobject jph = jcipherpack::to_jPackHeader(env, header); env->CallVoidMethod(jau::jni::JavaGlobalObj::GetObject(asl_java), mNotifyEnd, decrypt_mode ? JNI_TRUE : JNI_FALSE, - jph, - success ? JNI_TRUE : JNI_FALSE); + jph); jau::jni::java_exception_check_and_throw(env, E_FILE_LINE); env->DeleteLocalRef(jph); } |