Commit 03396102 authored by ylecollen's avatar ylecollen
Browse files

Simplify the function declarations in olm_jni to avoid having to cast the getXXX methods

parent eec8a50c
...@@ -17,10 +17,8 @@ ...@@ -17,10 +17,8 @@
package org.matrix.olm; package org.matrix.olm;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
......
...@@ -60,7 +60,7 @@ JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(releaseAccountJni)(JNIEnv *env, jobject thiz ...@@ -60,7 +60,7 @@ JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(releaseAccountJni)(JNIEnv *env, jobject thiz
{ {
LOGD("## releaseAccountJni(): IN"); LOGD("## releaseAccountJni(): IN");
OlmAccount* accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz); OlmAccount* accountPtr = getAccountInstanceId(env, thiz);
if (!accountPtr) if (!accountPtr)
{ {
...@@ -152,7 +152,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(identityKeysJni)(JNIEnv *env, jobject ...@@ -152,7 +152,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(identityKeysJni)(JNIEnv *env, jobject
{ {
const char* errorMessage = NULL; const char* errorMessage = NULL;
jbyteArray byteArrayRetValue = NULL; jbyteArray byteArrayRetValue = NULL;
OlmAccount* accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz); OlmAccount* accountPtr = getAccountInstanceId(env, thiz);
if (!accountPtr) if (!accountPtr)
{ {
...@@ -220,7 +220,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(identityKeysJni)(JNIEnv *env, jobject ...@@ -220,7 +220,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(identityKeysJni)(JNIEnv *env, jobject
**/ **/
JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(maxOneTimeKeysJni)(JNIEnv *env, jobject thiz) JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(maxOneTimeKeysJni)(JNIEnv *env, jobject thiz)
{ {
OlmAccount* accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz); OlmAccount* accountPtr = getAccountInstanceId(env, thiz);
size_t maxKeys = -1; size_t maxKeys = -1;
if (!accountPtr) if (!accountPtr)
...@@ -244,7 +244,7 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(maxOneTimeKeysJni)(JNIEnv *env, jobject thi ...@@ -244,7 +244,7 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(maxOneTimeKeysJni)(JNIEnv *env, jobject thi
JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(generateOneTimeKeysJni)(JNIEnv *env, jobject thiz, jint aNumberOfKeys) JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(generateOneTimeKeysJni)(JNIEnv *env, jobject thiz, jint aNumberOfKeys)
{ {
const char* errorMessage = NULL; const char* errorMessage = NULL;
OlmAccount *accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz); OlmAccount *accountPtr = getAccountInstanceId(env, thiz);
if (!accountPtr) if (!accountPtr)
{ {
...@@ -304,7 +304,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(oneTimeKeysJni)(JNIEnv *env, jobject t ...@@ -304,7 +304,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(oneTimeKeysJni)(JNIEnv *env, jobject t
{ {
const char* errorMessage = NULL; const char* errorMessage = NULL;
jbyteArray byteArrayRetValue = NULL; jbyteArray byteArrayRetValue = NULL;
OlmAccount* accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz); OlmAccount* accountPtr = getAccountInstanceId(env, thiz);
LOGD("## oneTimeKeysJni(): IN"); LOGD("## oneTimeKeysJni(): IN");
...@@ -380,7 +380,7 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(removeOneTimeKeysJni)(JNIEnv *env, jobject t ...@@ -380,7 +380,7 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(removeOneTimeKeysJni)(JNIEnv *env, jobject t
LOGE("## removeOneTimeKeysJni(): failure - invalid session ptr"); LOGE("## removeOneTimeKeysJni(): failure - invalid session ptr");
errorMessage = "invalid session ptr"; errorMessage = "invalid session ptr";
} }
else if(!(accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz))) else if(!(accountPtr = getAccountInstanceId(env, thiz)))
{ {
LOGE("## removeOneTimeKeysJni(): failure - invalid account ptr"); LOGE("## removeOneTimeKeysJni(): failure - invalid account ptr");
errorMessage = "invalid account ptr"; errorMessage = "invalid account ptr";
...@@ -415,7 +415,7 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(removeOneTimeKeysJni)(JNIEnv *env, jobject t ...@@ -415,7 +415,7 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(removeOneTimeKeysJni)(JNIEnv *env, jobject t
JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env, jobject thiz) JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env, jobject thiz)
{ {
const char* errorMessage = NULL; const char* errorMessage = NULL;
OlmAccount* accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz); OlmAccount* accountPtr = getAccountInstanceId(env, thiz);
if (!accountPtr) if (!accountPtr)
{ {
...@@ -460,7 +460,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject t ...@@ -460,7 +460,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject t
LOGE("## signMessageJni(): failure - invalid aMessage param"); LOGE("## signMessageJni(): failure - invalid aMessage param");
errorMessage = "invalid aMessage param"; errorMessage = "invalid aMessage param";
} }
else if(!(accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz))) else if (!(accountPtr = getAccountInstanceId(env, thiz)))
{ {
LOGE("## signMessageJni(): failure - invalid account ptr"); LOGE("## signMessageJni(): failure - invalid account ptr");
errorMessage = "invalid account ptr"; errorMessage = "invalid account ptr";
...@@ -543,7 +543,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thi ...@@ -543,7 +543,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thi
LOGE(" ## serializeJni(): failure - invalid key"); LOGE(" ## serializeJni(): failure - invalid key");
errorMessage = "invalid key"; errorMessage = "invalid key";
} }
else if (!(accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz))) else if (!(accountPtr = getAccountInstanceId(env, thiz)))
{ {
LOGE(" ## serializeJni(): failure - invalid account ptr"); LOGE(" ## serializeJni(): failure - invalid account ptr");
errorMessage = "invalid account ptr"; errorMessage = "invalid account ptr";
...@@ -625,7 +625,7 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz ...@@ -625,7 +625,7 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz
{ {
LOGE(" ## deserializeJni(): failure - serialized data"); LOGE(" ## deserializeJni(): failure - serialized data");
} }
else if (!(accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz))) else if (!(accountPtr = getAccountInstanceId(env, thiz)))
{ {
LOGE(" ## deserializeJni(): failure - account failure OOM"); LOGE(" ## deserializeJni(): failure - account failure OOM");
} }
......
...@@ -26,11 +26,11 @@ using namespace AndroidOlmSdk; ...@@ -26,11 +26,11 @@ using namespace AndroidOlmSdk;
*/ */
JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz) JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz)
{ {
OlmInboundGroupSession* sessionPtr = NULL; OlmInboundGroupSession* sessionPtr = getInboundGroupSessionInstanceId(env,thiz);
LOGD("## releaseSessionJni(): InBound group session IN"); LOGD("## releaseSessionJni(): InBound group session IN");
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz))) if (!sessionPtr)
{ {
LOGE("## releaseSessionJni(): failure - invalid inbound group session instance"); LOGE("## releaseSessionJni(): failure - invalid inbound group session instance");
} }
...@@ -88,13 +88,13 @@ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv * ...@@ -88,13 +88,13 @@ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *
JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionJni)(JNIEnv *env, jobject thiz, jbyteArray aSessionKeyBuffer) JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionJni)(JNIEnv *env, jobject thiz, jbyteArray aSessionKeyBuffer)
{ {
const char* errorMessage = NULL; const char* errorMessage = NULL;
OlmInboundGroupSession *sessionPtr = NULL; OlmInboundGroupSession *sessionPtr = getInboundGroupSessionInstanceId(env, thiz);
jbyte* sessionKeyPtr = NULL; jbyte* sessionKeyPtr = NULL;
size_t sessionResult; size_t sessionResult;
LOGD("## initInboundGroupSessionJni(): inbound group session IN"); LOGD("## initInboundGroupSessionJni(): inbound group session IN");
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz))) if (!sessionPtr)
{ {
LOGE(" ## initInboundGroupSessionJni(): failure - invalid inbound group session instance"); LOGE(" ## initInboundGroupSessionJni(): failure - invalid inbound group session instance");
errorMessage = "invalid inbound group session instance"; errorMessage = "invalid inbound group session instance";
...@@ -143,12 +143,12 @@ JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionJni)(JN ...@@ -143,12 +143,12 @@ JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionJni)(JN
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz) JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz)
{ {
const char* errorMessage = NULL; const char* errorMessage = NULL;
OlmInboundGroupSession *sessionPtr = NULL; OlmInboundGroupSession *sessionPtr = getInboundGroupSessionInstanceId(env, thiz);
jbyteArray returnValue = 0; jbyteArray returnValue = 0;
LOGD("## sessionIdentifierJni(): inbound group session IN"); LOGD("## sessionIdentifierJni(): inbound group session IN");
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz))) if (!sessionPtr)
{ {
LOGE(" ## sessionIdentifierJni(): failure - invalid inbound group session instance"); LOGE(" ## sessionIdentifierJni(): failure - invalid inbound group session instance");
errorMessage = "invalid inbound group session instance"; errorMessage = "invalid inbound group session instance";
...@@ -202,14 +202,14 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEn ...@@ -202,14 +202,14 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEn
jbyteArray decryptedMsgBuffer = 0; jbyteArray decryptedMsgBuffer = 0;
const char* errorMessage = NULL; const char* errorMessage = NULL;
OlmInboundGroupSession *sessionPtr = NULL; OlmInboundGroupSession *sessionPtr = getInboundGroupSessionInstanceId(env, thiz);
jbyte *encryptedMsgPtr = NULL; jbyte *encryptedMsgPtr = NULL;
jclass indexObjJClass = 0; jclass indexObjJClass = 0;
jfieldID indexMsgFieldId; jfieldID indexMsgFieldId;
LOGD("## decryptMessageJni(): inbound group session IN"); LOGD("## decryptMessageJni(): inbound group session IN");
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz))) if (!sessionPtr)
{ {
LOGE(" ## decryptMessageJni(): failure - invalid inbound group session ptr=NULL"); LOGE(" ## decryptMessageJni(): failure - invalid inbound group session ptr=NULL");
errorMessage = "invalid inbound group session ptr=NULL"; errorMessage = "invalid inbound group session ptr=NULL";
...@@ -337,11 +337,11 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *en ...@@ -337,11 +337,11 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *en
jbyteArray pickledDataRet = 0; jbyteArray pickledDataRet = 0;
jbyte* keyPtr = NULL; jbyte* keyPtr = NULL;
OlmInboundGroupSession* sessionPtr = NULL; OlmInboundGroupSession* sessionPtr = getInboundGroupSessionInstanceId(env, thiz);
LOGD("## inbound group session serializeJni(): IN"); LOGD("## inbound group session serializeJni(): IN");
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz))) if (!sessionPtr)
{ {
LOGE(" ## serializeJni(): failure - invalid session ptr"); LOGE(" ## serializeJni(): failure - invalid session ptr");
errorMessage = "invalid session ptr"; errorMessage = "invalid session ptr";
...@@ -411,14 +411,14 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *en ...@@ -411,14 +411,14 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *en
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer) JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
{ {
OlmInboundGroupSession* sessionPtr = NULL; OlmInboundGroupSession* sessionPtr = getInboundGroupSessionInstanceId(env, thiz);
jstring errorMessageRetValue = 0; jstring errorMessageRetValue = 0;
jbyte* keyPtr = NULL; jbyte* keyPtr = NULL;
jbyte* pickledPtr = NULL; jbyte* pickledPtr = NULL;
LOGD("## deserializeJni(): IN"); LOGD("## deserializeJni(): IN");
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz))) if (!sessionPtr)
{ {
LOGE(" ## deserializeJni(): failure - session failure OOM"); LOGE(" ## deserializeJni(): failure - session failure OOM");
} }
......
...@@ -68,11 +68,12 @@ extern "C" { ...@@ -68,11 +68,12 @@ extern "C" {
// internal helper functions // internal helper functions
bool setRandomInBuffer(JNIEnv *env, uint8_t **aBuffer2Ptr, size_t aRandomSize); bool setRandomInBuffer(JNIEnv *env, uint8_t **aBuffer2Ptr, size_t aRandomSize);
jlong getSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
jlong getAccountInstanceId(JNIEnv* aJniEnv, jobject aJavaObject); struct OlmSession* getSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
jlong getInboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject); struct OlmAccount* getAccountInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
jlong getOutboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject); struct OlmInboundGroupSession* getInboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
jlong getUtilityInstanceId(JNIEnv* aJniEnv, jobject aJavaObject); struct OlmOutboundGroupSession* getOutboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
struct OlmUtility* getUtilityInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -111,8 +111,8 @@ bool setRandomInBuffer(JNIEnv *env, uint8_t **aBuffer2Ptr, size_t aRandomSize) ...@@ -111,8 +111,8 @@ bool setRandomInBuffer(JNIEnv *env, uint8_t **aBuffer2Ptr, size_t aRandomSize)
* Read the instance ID of the calling object. * Read the instance ID of the calling object.
* @param aJniEnv pointer pointing on the JNI function table * @param aJniEnv pointer pointing on the JNI function table
* @param aJavaObject reference to the object on which the method is invoked * @param aJavaObject reference to the object on which the method is invoked
* @param aCallingClass java calling clas name * @param aCallingClass java calling class name
* @return the instance ID if operation succeed, -1 if instance ID was not found. * @return the related instance ID
**/ **/
jlong getInstanceId(JNIEnv* aJniEnv, jobject aJavaObject, const char *aCallingClass) jlong getInstanceId(JNIEnv* aJniEnv, jobject aJavaObject, const char *aCallingClass)
{ {
...@@ -125,7 +125,7 @@ jlong getInstanceId(JNIEnv* aJniEnv, jobject aJavaObject, const char *aCallingCl ...@@ -125,7 +125,7 @@ jlong getInstanceId(JNIEnv* aJniEnv, jobject aJavaObject, const char *aCallingCl
if (requiredClass && (JNI_TRUE != aJniEnv->IsInstanceOf(aJavaObject, requiredClass))) if (requiredClass && (JNI_TRUE != aJniEnv->IsInstanceOf(aJavaObject, requiredClass)))
{ {
LOGE("## getAccountInstanceId() failure - invalid instance of"); LOGE("## getInstanceId() failure - invalid instance of");
} }
else if ((loaderClass = aJniEnv->GetObjectClass(aJavaObject))) else if ((loaderClass = aJniEnv->GetObjectClass(aJavaObject)))
{ {
...@@ -162,58 +162,53 @@ jlong getInstanceId(JNIEnv* aJniEnv, jobject aJavaObject, const char *aCallingCl ...@@ -162,58 +162,53 @@ jlong getInstanceId(JNIEnv* aJniEnv, jobject aJavaObject, const char *aCallingCl
* Read the account instance ID of the calling object. * Read the account instance ID of the calling object.
* @param aJniEnv pointer pointing on the JNI function table * @param aJniEnv pointer pointing on the JNI function table
* @param aJavaObject reference to the object on which the method is invoked * @param aJavaObject reference to the object on which the method is invoked
* @return the instance ID if operation succeed, -1 if instance ID was not found. * @return the related OlmAccount.
**/ **/
jlong getAccountInstanceId(JNIEnv* aJniEnv, jobject aJavaObject) struct OlmAccount* getAccountInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
{ {
jlong instanceId = getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_ACCOUNT); return (struct OlmAccount*)getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_ACCOUNT);
return instanceId;
} }
/** /**
* Read the session instance ID of the calling object (aJavaObject).<br> * Read the session instance ID of the calling object (aJavaObject).<br>
* @param aJniEnv pointer pointing on the JNI function table * @param aJniEnv pointer pointing on the JNI function table
* @param aJavaObject reference to the object on which the method is invoked * @param aJavaObject reference to the object on which the method is invoked
* @return the instance ID if read succeed, -1 otherwise. * @return the related OlmSession.
**/ **/
jlong getSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject) struct OlmSession* getSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
{ {
jlong instanceId = getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_SESSION); return (struct OlmSession*)getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_SESSION);
return instanceId;
} }
/** /**
* Read the inbound group session instance ID of the calling object (aJavaObject).<br> * Read the inbound group session instance ID of the calling object (aJavaObject).<br>
* @param aJniEnv pointer pointing on the JNI function table * @param aJniEnv pointer pointing on the JNI function table
* @param aJavaObject reference to the object on which the method is invoked * @param aJavaObject reference to the object on which the method is invoked
* @return the instance ID if read succeed, -1 otherwise. * @return the related OlmInboundGroupSession.
**/ **/
jlong getInboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject) struct OlmInboundGroupSession* getInboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
{ {
jlong instanceId = getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_INBOUND_GROUP_SESSION); return (struct OlmInboundGroupSession*)getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_INBOUND_GROUP_SESSION);
return instanceId;
} }
/** /**
* Read the outbound group session instance ID of the calling object (aJavaObject).<br> * Read the outbound group session instance ID of the calling object (aJavaObject).<br>
* @param aJniEnv pointer pointing on the JNI function table * @param aJniEnv pointer pointing on the JNI function table
* @param aJavaObject reference to the object on which the method is invoked * @param aJavaObject reference to the object on which the method is invoked
* @return the instance ID if read succeed, -1 otherwise. * @return the related OlmOutboundGroupSession
**/ **/
jlong getOutboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject) struct OlmOutboundGroupSession* getOutboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
{ {
jlong instanceId = getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_OUTBOUND_GROUP_SESSION); return (struct OlmOutboundGroupSession*)getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_OUTBOUND_GROUP_SESSION);
return instanceId;
} }
/** /**
* Read the utility instance ID of the calling object (aJavaObject).<br> * Read the utility instance ID of the calling object (aJavaObject).<br>
* @param aJniEnv pointer pointing on the JNI function table * @param aJniEnv pointer pointing on the JNI function table
* @param aJavaObject reference to the object on which the method is invoked * @param aJavaObject reference to the object on which the method is invoked
* @return the instance ID if read succeed, -1 otherwise. * @return the related OlmUtility
**/ **/
jlong getUtilityInstanceId(JNIEnv* aJniEnv, jobject aJavaObject) struct OlmUtility* getUtilityInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
{ {
jlong instanceId = getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_UTILITY); return (struct OlmUtility*)getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_UTILITY);
return instanceId;
} }
...@@ -55,7 +55,7 @@ JNIEXPORT jlong OLM_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject t ...@@ -55,7 +55,7 @@ JNIEXPORT jlong OLM_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject t
JNIEXPORT void OLM_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz) JNIEXPORT void OLM_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz)
{ {
LOGD("## releaseSessionJni(): IN"); LOGD("## releaseSessionJni(): IN");
OlmSession* sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz); OlmSession* sessionPtr = getSessionInstanceId(env, thiz);
if (!sessionPtr) if (!sessionPtr)
{ {
...@@ -108,11 +108,11 @@ JNIEXPORT jlong OLM_SESSION_FUNC_DEF(initNewSessionJni)(JNIEnv *env, jobject thi ...@@ -108,11 +108,11 @@ JNIEXPORT jlong OLM_SESSION_FUNC_DEF(initNewSessionJni)(JNIEnv *env, jobject thi
**/ **/
JNIEXPORT void OLM_SESSION_FUNC_DEF(initOutboundSessionJni)(JNIEnv *env, jobject thiz, jlong aOlmAccountId, jbyteArray aTheirIdentityKeyBuffer, jbyteArray aTheirOneTimeKeyBuffer) JNIEXPORT void OLM_SESSION_FUNC_DEF(initOutboundSessionJni)(JNIEnv *env, jobject thiz, jlong aOlmAccountId, jbyteArray aTheirIdentityKeyBuffer, jbyteArray aTheirOneTimeKeyBuffer)
{ {
OlmSession* sessionPtr = getSessionInstanceId(env, thiz);
const char* errorMessage = NULL; const char* errorMessage = NULL;
OlmSession* sessionPtr = NULL;
OlmAccount* accountPtr = NULL; OlmAccount* accountPtr = NULL;
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz))) if (!sessionPtr)
{ {
LOGE("## initOutboundSessionJni(): failure - invalid Session ptr=NULL"); LOGE("## initOutboundSessionJni(): failure - invalid Session ptr=NULL");
errorMessage = "invalid Session ptr=NULL"; errorMessage = "invalid Session ptr=NULL";
...@@ -215,11 +215,11 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(initOutboundSessionJni)(JNIEnv *env, jobject ...@@ -215,11 +215,11 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(initOutboundSessionJni)(JNIEnv *env, jobject
JNIEXPORT void OLM_SESSION_FUNC_DEF(initInboundSessionJni)(JNIEnv *env, jobject thiz, jlong aOlmAccountId, jbyteArray aOneTimeKeyMsgBuffer) JNIEXPORT void OLM_SESSION_FUNC_DEF(initInboundSessionJni)(JNIEnv *env, jobject thiz, jlong aOlmAccountId, jbyteArray aOneTimeKeyMsgBuffer)
{ {
const char* errorMessage = NULL; const char* errorMessage = NULL;
OlmSession *sessionPtr = NULL; OlmSession *sessionPtr = getSessionInstanceId(env,thiz);
OlmAccount *accountPtr = NULL; OlmAccount *accountPtr = NULL;
size_t sessionResult; size_t sessionResult;
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz))) if (!sessionPtr)
{ {
LOGE("## initInboundSessionJni(): failure - invalid Session ptr=NULL"); LOGE("## initInboundSessionJni(): failure - invalid Session ptr=NULL");
errorMessage = "invalid Session ptr=NULL"; errorMessage = "invalid Session ptr=NULL";
...@@ -282,13 +282,13 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(initInboundSessionFromIdKeyJni)(JNIEnv *env, ...@@ -282,13 +282,13 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(initInboundSessionFromIdKeyJni)(JNIEnv *env,
{ {
const char* errorMessage = NULL; const char* errorMessage = NULL;
OlmSession *sessionPtr = NULL; OlmSession *sessionPtr = getSessionInstanceId(env, thiz);
OlmAccount *accountPtr = NULL; OlmAccount *accountPtr = NULL;
jbyte *messagePtr = NULL; jbyte *messagePtr = NULL;
jbyte *theirIdentityKeyPtr = NULL; jbyte *theirIdentityKeyPtr = NULL;
size_t sessionResult; size_t sessionResult;
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz))) if (!sessionPtr)
{ {
LOGE("## initInboundSessionFromIdKeyJni(): failure - invalid Session ptr=NULL"); LOGE("## initInboundSessionFromIdKeyJni(): failure - invalid Session ptr=NULL");
errorMessage = "invalid Session ptr=NULL"; errorMessage = "invalid Session ptr=NULL";
...@@ -363,10 +363,10 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(initInboundSessionFromIdKeyJni)(JNIEnv *env, ...@@ -363,10 +363,10 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(initInboundSessionFromIdKeyJni)(JNIEnv *env,
JNIEXPORT jint OLM_SESSION_FUNC_DEF(matchesInboundSessionJni)(JNIEnv *env, jobject thiz, jbyteArray aOneTimeKeyMsgBuffer) JNIEXPORT jint OLM_SESSION_FUNC_DEF(matchesInboundSessionJni)(JNIEnv *env, jobject thiz, jbyteArray aOneTimeKeyMsgBuffer)
{ {
jint retCode = ERROR_CODE_KO; jint retCode = ERROR_CODE_KO;
OlmSession *sessionPtr = NULL; OlmSession *sessionPtr = getSessionInstanceId(env, thiz);
jbyte *messagePtr = NULL; jbyte *messagePtr = NULL;
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz))) if (!sessionPtr)
{ {
LOGE("## matchesInboundSessionJni(): failure - invalid Session ptr=NULL"); LOGE("## matchesInboundSessionJni(): failure - invalid Session ptr=NULL");
} }
...@@ -415,11 +415,11 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(matchesInboundSessionJni)(JNIEnv *env, jobje ...@@ -415,11 +415,11 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(matchesInboundSessionJni)(JNIEnv *env, jobje
JNIEXPORT jint JNICALL OLM_SESSION_FUNC_DEF(matchesInboundSessionFromIdKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aTheirIdentityKeyBuffer, jbyteArray aOneTimeKeyMsgBuffer) JNIEXPORT jint JNICALL OLM_SESSION_FUNC_DEF(matchesInboundSessionFromIdKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aTheirIdentityKeyBuffer, jbyteArray aOneTimeKeyMsgBuffer)
{ {
jint retCode = ERROR_CODE_KO; jint retCode = ERROR_CODE_KO;
OlmSession *sessionPtr = NULL; OlmSession *sessionPtr = getSessionInstanceId(env, thiz);
jbyte *messagePtr = NULL; jbyte *messagePtr = NULL;
jbyte *theirIdentityKeyPtr = NULL; jbyte *theirIdentityKeyPtr = NULL;
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz))) if (!sessionPtr)
{ {
LOGE("## matchesInboundSessionFromIdKeyJni(): failure - invalid Session ptr=NULL"); LOGE("## matchesInboundSessionFromIdKeyJni(): failure - invalid Session ptr=NULL");
} }
...@@ -482,7 +482,7 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz ...@@ -482,7 +482,7 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz
{ {
const char* errorMessage = NULL; const char* errorMessage = NULL;
OlmSession *sessionPtr = NULL; OlmSession *sessionPtr = getSessionInstanceId(env, thiz);
jbyte *clearMsgPtr = NULL; jbyte *clearMsgPtr = NULL;
jclass encryptedMsgJClass = 0;