diff options
-rw-r--r-- | java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni.h | 9 | ||||
-rw-r--r-- | java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp | 76 |
2 files changed, 80 insertions, 5 deletions
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni.h b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni.h index 2bfb9f8..e1fea02 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni.h +++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni.h @@ -21,7 +21,6 @@ #include <cstdio> #include <string> #include <sstream> -#include <map> #include <jni.h> #include <android/log.h> @@ -53,6 +52,14 @@ static const int ERROR_CODE_KO = -1; // constants static const int ACCOUNT_CREATION_RANDOM_MODULO = 256; + +// strings +static const char *CLASS_OLM_OUTBOUND_GROUP_SESSION = "org/matrix/olm/OlmOutboundGroupSession"; +static const char *CLASS_OLM_INBOUND_GROUP_SESSION = "org/matrix/olm/OlmInboundGroupSession"; +static const char *CLASS_OLM_SESSION = "org/matrix/olm/OlmSession"; +static const char *CLASS_OLM_ACCOUNT = "org/matrix/olm/OlmAccount"; +static const char *CLASS_OLM_UTILITY = "org/matrix/olm/OlmUtility"; + #ifdef __cplusplus extern "C" { #endif diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp index 1d64d75..c518578 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp +++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp @@ -70,10 +70,17 @@ jlong getAccountInstanceId(JNIEnv* aJniEnv, jobject aJavaObject) jlong instanceId=-1; jfieldID instanceIdField; jclass loaderClass; + jclass requiredClass = 0; if(NULL!=aJniEnv) { - if(0 != (loaderClass=aJniEnv->GetObjectClass(aJavaObject))) + requiredClass = aJniEnv->FindClass(CLASS_OLM_ACCOUNT); + + if((0 != requiredClass) && (JNI_TRUE != aJniEnv->IsInstanceOf(aJavaObject, requiredClass))) + { + LOGD("## getAccountInstanceId() failure - invalid instance of"); + } + else if(0 != (loaderClass=aJniEnv->GetObjectClass(aJavaObject))) { if(0 != (instanceIdField=aJniEnv->GetFieldID(loaderClass, "mNativeOlmAccountId", "J"))) { @@ -110,10 +117,17 @@ jlong getSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject) jlong instanceId=-1; jfieldID instanceIdField; jclass loaderClass; + jclass requiredClass = 0; if(NULL!=aJniEnv) { - if(0 != (loaderClass=aJniEnv->GetObjectClass(aJavaObject))) + requiredClass = aJniEnv->FindClass(CLASS_OLM_SESSION); + + if((0 != requiredClass) && (JNI_TRUE != aJniEnv->IsInstanceOf(aJavaObject, requiredClass))) + { + LOGD("## getSessionInstanceId() failure - invalid instance of"); + } + else if(0 != (loaderClass=aJniEnv->GetObjectClass(aJavaObject))) { if(0 != (instanceIdField=aJniEnv->GetFieldID(loaderClass, "mNativeOlmSessionId", "J"))) { @@ -151,10 +165,17 @@ jlong getInboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject) jlong instanceId=-1; jfieldID instanceIdField; jclass loaderClass; + jclass requiredClass = 0; if(NULL!=aJniEnv) { - if(0 != (loaderClass=aJniEnv->GetObjectClass(aJavaObject))) + requiredClass = aJniEnv->FindClass(CLASS_OLM_INBOUND_GROUP_SESSION); + + if((0 != requiredClass) && (JNI_TRUE != aJniEnv->IsInstanceOf(aJavaObject, requiredClass))) + { + LOGD("## getInboundGroupSessionInstanceId() failure - invalid instance of"); + } + else if(0 != (loaderClass=aJniEnv->GetObjectClass(aJavaObject))) { if(0 != (instanceIdField=aJniEnv->GetFieldID(loaderClass, "mNativeOlmInboundGroupSessionId", "J"))) { @@ -191,10 +212,57 @@ jlong getOutboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject) jlong instanceId=-1; jfieldID instanceIdField; jclass loaderClass; + jclass requiredClass = 0; + + if(NULL!=aJniEnv) + { + requiredClass = aJniEnv->FindClass(CLASS_OLM_OUTBOUND_GROUP_SESSION); + + if((0 != requiredClass) && (JNI_TRUE != aJniEnv->IsInstanceOf(aJavaObject, requiredClass))) + { + LOGD("## getOutboundGroupSessionInstanceId() failure - invalid instance of"); + } + else if(0 != (loaderClass=aJniEnv->GetObjectClass(aJavaObject))) + { + if(0 != (instanceIdField=aJniEnv->GetFieldID(loaderClass, "mNativeOlmOutboundGroupSessionId", "J"))) + { + instanceId = aJniEnv->GetLongField(aJavaObject, instanceIdField); + aJniEnv->DeleteLocalRef(loaderClass); + } + else + { + LOGD("## getOutboundGroupSessionInstanceId() ERROR! GetFieldID=null"); + } + } + else + { + LOGD("## getOutboundGroupSessionInstanceId() ERROR! GetObjectClass=null"); + } + } + else + { + LOGD("## getOutboundGroupSessionInstanceId() ERROR! aJniEnv=NULL"); + } + + return instanceId; +} + +jlong getUtilityInstanceId(JNIEnv* aJniEnv, jobject aJavaObject) +{ + jlong instanceId=-1; + jfieldID instanceIdField; + jclass loaderClass; + jclass requiredClass = 0; if(NULL!=aJniEnv) { - if(0 != (loaderClass=aJniEnv->GetObjectClass(aJavaObject))) + requiredClass = aJniEnv->FindClass(CLASS_OLM_UTILITY); + + if((0 != requiredClass) && (JNI_TRUE != aJniEnv->IsInstanceOf(aJavaObject, requiredClass))) + { + LOGD("## getOutboundGroupSessionInstanceId() failure - invalid instance of"); + } + else if(0 != (loaderClass=aJniEnv->GetObjectClass(aJavaObject))) { if(0 != (instanceIdField=aJniEnv->GetFieldID(loaderClass, "mNativeOlmOutboundGroupSessionId", "J"))) { |