Commit 65352d05 authored by ylecollen's avatar ylecollen
Browse files

->Replace 2 spaces tabs by 4 spaces.

->fix the NULL and 0 pointer comparisons mixes
parent b03cdebf
......@@ -335,7 +335,7 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
public OlmMessage encryptMessage(String aClearMsg) {
OlmMessage encryptedMsgRetValue = new OlmMessage();
if(0 != encryptMessageJni(aClearMsg, encryptedMsgRetValue)){
if (0 != encryptMessageJni(aClearMsg, encryptedMsgRetValue)){
encryptedMsgRetValue = null;
}
......
......@@ -19,7 +19,6 @@
using namespace AndroidOlmSdk;
/**
* Init memory allocation for account creation.
* @return valid memory allocation, NULL otherwise
......@@ -43,7 +42,6 @@ OlmAccount* initializeAccountMemory()
return accountPtr;
}
JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(createNewAccountJni)(JNIEnv *env, jobject thiz)
{
LOGD("## createNewAccountJni(): IN");
......@@ -53,7 +51,6 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(createNewAccountJni)(JNIEnv *env, jobject t
return (jlong)(intptr_t)accountPtr;
}
/**
* Release the account allocation made by initializeAccountMemory().<br>
* This method MUST be called when java counter part account instance is done.
......@@ -65,7 +62,7 @@ JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(releaseAccountJni)(JNIEnv *env, jobject thiz
OlmAccount* accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz);
if(!accountPtr)
if (!accountPtr)
{
LOGE(" ## releaseAccountJni(): failure - invalid Account ptr=NULL");
}
......@@ -147,7 +144,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(identityKeysJni)(JNIEnv *env, jobject
jbyteArray byteArrayRetValue = NULL;
OlmAccount* accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz);
if (NULL == accountPtr)
if (!accountPtr)
{
LOGE("## identityKeys(): failure - invalid Account ptr=NULL");
}
......@@ -168,7 +165,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(identityKeysJni)(JNIEnv *env, jobject
// retrieve key pairs in identityKeysBytesPtr
size_t keysResult = olm_account_identity_keys(accountPtr, identityKeysBytesPtr, identityKeysLength);
if(keysResult == olm_error())
if (keysResult == olm_error())
{
LOGE("## identityKeys(): failure - error getting identity keys Msg=%s",(const char *)olm_account_last_error(accountPtr));
}
......@@ -177,7 +174,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(identityKeysJni)(JNIEnv *env, jobject
// allocate the byte array to be returned to java
byteArrayRetValue = env->NewByteArray(identityKeysLength);
if(NULL == byteArrayRetValue)
if (!byteArrayRetValue)
{
LOGE("## identityKeys(): failure - return byte array OOM");
}
......@@ -243,7 +240,7 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(generateOneTimeKeysJni)(JNIEnv *env, jobject
uint8_t *randomBufferPtr = NULL;
if ( (0!=randomLength) && !setRandomInBuffer(env, &randomBufferPtr, randomLength))
if ((0 != randomLength) && !setRandomInBuffer(env, &randomBufferPtr, randomLength))
{
LOGE("## generateOneTimeKeysJni(): failure - random buffer init");
}
......@@ -304,7 +301,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(oneTimeKeysJni)(JNIEnv *env, jobject t
{
// retrieve key pairs in keysBytesPtr
size_t keysResult = olm_account_one_time_keys(accountPtr, keysBytesPtr, keysLength);
if(keysResult == olm_error()) {
if (keysResult == olm_error()) {
LOGE("## oneTimeKeysJni(): failure - error getting one time keys Msg=%s",(const char *)olm_account_last_error(accountPtr));
}
else
......@@ -388,7 +385,7 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env,
{
size_t result = olm_account_mark_keys_as_published(accountPtr);
if(result == olm_error())
if (result == olm_error())
{
LOGW("## markOneTimeKeysAsPublishedJni(): failure - Msg=%s",(const char *)olm_account_last_error(accountPtr));
retCode = ERROR_CODE_KO;
......@@ -417,7 +414,7 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
{
LOGE("## signMessageJni(): failure - invalid aMessage param");
}
else if(NULL == (accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz)))
else if(!(accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz)))
{
LOGE("## signMessageJni(): failure - invalid account ptr");
}
......@@ -490,23 +487,23 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
{
LOGE(" ## serializeDataWithKeyJni(): failure - invalid key");
}
else if(!aErrorMsg)
else if (!aErrorMsg)
{
LOGE(" ## serializeDataWithKeyJni(): failure - invalid error object");
}
else if(!(accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz)))
else if (!(accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz)))
{
LOGE(" ## serializeDataWithKeyJni(): failure - invalid account ptr");
}
else if(!(errorMsgJClass = env->GetObjectClass(aErrorMsg)))
else if (!(errorMsgJClass = env->GetObjectClass(aErrorMsg)))
{
LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error class");
}
else if(!(errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
else if (!(errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
{
LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error method ID");
}
else if(!(keyPtr = env->GetStringUTFChars(aKey, 0)))
else if (!(keyPtr = env->GetStringUTFChars(aKey, 0)))
{
LOGE(" ## serializeDataWithKeyJni(): failure - keyPtr JNI allocation OOM");
}
......@@ -604,7 +601,7 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, j
keyLength,
(void*)pickledPtr,
pickledLength);
if(result == olm_error())
if (result == olm_error())
{
const char *errorMsgPtr = olm_account_last_error(accountPtr);
LOGE(" ## initWithSerializedDataJni(): failure - olm_unpickle_account() Msg=%s",errorMsgPtr);
......
......@@ -26,28 +26,28 @@ using namespace AndroidOlmSdk;
*/
JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz)
{
OlmInboundGroupSession* sessionPtr = NULL;
OlmInboundGroupSession* sessionPtr = NULL;
LOGD("## releaseSessionJni(): InBound group session IN");
LOGD("## releaseSessionJni(): InBound group session IN");
if(NULL == (sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
{
LOGE("## releaseSessionJni(): failure - invalid inbound group session instance");
}
else
{
LOGD(" ## releaseSessionJni(): sessionPtr=%p",sessionPtr);
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
{
LOGE("## releaseSessionJni(): failure - invalid inbound group session instance");
}
else
{
LOGD(" ## releaseSessionJni(): sessionPtr=%p",sessionPtr);
#ifdef ENABLE_JNI_LOG
size_t retCode = olm_clear_inbound_group_session(sessionPtr);
LOGD(" ## releaseSessionJni(): clear_inbound_group_session=%lu",static_cast<long unsigned int>(retCode));
size_t retCode = olm_clear_inbound_group_session(sessionPtr);
LOGD(" ## releaseSessionJni(): clear_inbound_group_session=%lu",static_cast<long unsigned int>(retCode));
#else
olm_clear_inbound_group_session(sessionPtr);
olm_clear_inbound_group_session(sessionPtr);
#endif
LOGD(" ## releaseSessionJni(): free IN");
free(sessionPtr);
LOGD(" ## releaseSessionJni(): free OUT");
}
LOGD(" ## releaseSessionJni(): free IN");
free(sessionPtr);
LOGD(" ## releaseSessionJni(): free OUT");
}
}
/**
......@@ -64,18 +64,18 @@ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *
LOGD("## createNewSessionJni(): inbound group session IN");
sessionSize = olm_inbound_group_session_size();
if(0 == sessionSize)
if (!sessionSize)
{
LOGE(" ## createNewSessionJni(): failure - inbound group session size = 0");
}
else if(NULL != (sessionPtr=(OlmInboundGroupSession*)malloc(sessionSize)))
else if ((sessionPtr = (OlmInboundGroupSession*)malloc(sessionSize)))
{
sessionPtr = olm_inbound_group_session(sessionPtr);
LOGD(" ## createNewSessionJni(): success - inbound group session size=%lu",static_cast<long unsigned int>(sessionSize));
sessionPtr = olm_inbound_group_session(sessionPtr);
LOGD(" ## createNewSessionJni(): success - inbound group session size=%lu",static_cast<long unsigned int>(sessionSize));
}
else
{
LOGE(" ## createNewSessionJni(): failure - inbound group session OOM");
LOGE(" ## createNewSessionJni(): failure - inbound group session OOM");
}
return (jlong)(intptr_t)sessionPtr;
......@@ -95,15 +95,15 @@ JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSes
LOGD("## initInboundGroupSessionWithSessionKeyJni(): inbound group session IN");
if(NULL == (sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
{
LOGE(" ## initInboundGroupSessionWithSessionKeyJni(): failure - invalid inbound group session instance");
}
else if(0 == aSessionKey)
else if (!aSessionKey)
{
LOGE(" ## initInboundGroupSessionWithSessionKeyJni(): failure - invalid aSessionKey");
}
else if(NULL == (sessionKeyPtr = (const uint8_t *)env->GetStringUTFChars(aSessionKey, 0)))
else if (!(sessionKeyPtr = (const uint8_t *)env->GetStringUTFChars(aSessionKey, 0)))
{
LOGE(" ## initInboundSessionFromIdKeyJni(): failure - session key JNI allocation OOM");
}
......@@ -113,7 +113,7 @@ JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSes
LOGD(" ## initInboundSessionFromIdKeyJni(): sessionKeyLength=%lu",static_cast<long unsigned int>(sessionKeyLength));
sessionResult = olm_init_inbound_group_session(sessionPtr, sessionKeyPtr, sessionKeyLength);
if(sessionResult == olm_error()) {
if (sessionResult == olm_error()) {
const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr);
LOGE(" ## initInboundSessionFromIdKeyJni(): failure - init inbound session creation Msg=%s",errorMsgPtr);
}
......@@ -125,7 +125,7 @@ JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSes
}
// free local alloc
if(NULL!= sessionKeyPtr)
if (sessionKeyPtr)
{
env->ReleaseStringUTFChars(aSessionKey, (const char*)sessionKeyPtr);
}
......@@ -140,12 +140,11 @@ JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSes
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz)
{
OlmInboundGroupSession *sessionPtr = NULL;
uint8_t *sessionIdPtr = NULL;
jstring returnValueStr=0;
LOGD("## sessionIdentifierJni(): inbound group session IN");
if(NULL == (sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
{
LOGE(" ## sessionIdentifierJni(): failure - invalid inbound group session instance");
}
......@@ -155,13 +154,16 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEn
size_t lengthSessionId = olm_inbound_group_session_id_length(sessionPtr);
LOGD(" ## sessionIdentifierJni(): inbound group session lengthSessionId=%lu",static_cast<long unsigned int>(lengthSessionId));
if(NULL == (sessionIdPtr = (uint8_t*)malloc((lengthSessionId+1)*sizeof(uint8_t))))
uint8_t *sessionIdPtr = (uint8_t*)malloc((lengthSessionId+1)*sizeof(uint8_t));
if (!sessionIdPtr)
{
LOGE(" ## sessionIdentifierJni(): failure - inbound group session identifier allocation OOM");
}
else
{
size_t result = olm_inbound_group_session_id(sessionPtr, sessionIdPtr, lengthSessionId);
if (result == olm_error())
{
LOGE(" ## sessionIdentifierJni(): failure - get inbound group session identifier failure Msg=%s",(const char *)olm_inbound_group_session_last_error(sessionPtr));
......@@ -402,7 +404,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JN
keyLength,
(void*)pickledPtr,
pickledLength);
if(result == olm_error())
if (result == olm_error())
{
const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr);
LOGE(" ## serializeDataWithKeyJni(): failure - olm_pickle_outbound_group_session() Msg=%s",errorMsgPtr);
......
......@@ -36,7 +36,7 @@ bool setRandomInBuffer(JNIEnv *env, uint8_t **aBuffer2Ptr, size_t aRandomSize)
{
LOGE("## setRandomInBuffer(): failure - aBuffer=NULL");
}
else if(!aRandomSize)
else if (!aRandomSize)
{
LOGE("## setRandomInBuffer(): failure - random size=0");
}
......@@ -113,7 +113,8 @@ bool setRandomInBuffer(JNIEnv *env, uint8_t **aBuffer2Ptr, size_t aRandomSize)
jlong getInstanceId(JNIEnv* aJniEnv, jobject aJavaObject, const char *aCallingClass)
{
jlong instanceId = 0;
if (aJniEnv)
if (aJniEnv)
{
jclass requiredClass = aJniEnv->FindClass(aCallingClass);
jclass loaderClass = 0;
......@@ -227,7 +228,7 @@ jstring javaCStringToUtf8(JNIEnv *env, uint8_t *aCStringMsgPtr, size_t aMsgLengt
{
LOGE("## javaCStringToUtf8(): failure - invalid parameters (null)");
}
else if (!(tempByteArray=env->NewByteArray(aMsgLength)))
else if (!(tempByteArray = env->NewByteArray(aMsgLength)))
{
LOGE("## javaCStringToUtf8(): failure - return byte array OOM");
}
......
......@@ -21,15 +21,15 @@ using namespace AndroidOlmSdk;
JNIEXPORT jstring OLM_MANAGER_FUNC_DEF(getOlmLibVersionJni)(JNIEnv* env, jobject thiz)
{
uint8_t majorVer=0, minorVer=0, patchVer=0;
jstring returnValueStr=0;
char buff[150];
uint8_t majorVer=0, minorVer=0, patchVer=0;
jstring returnValueStr=0;
char buff[150];
olm_get_library_version(&majorVer, &minorVer, &patchVer);
LOGD("## getOlmLibVersionJni(): Major=%d Minor=%d Patch=%d", majorVer, minorVer, patchVer);
olm_get_library_version(&majorVer, &minorVer, &patchVer);
LOGD("## getOlmLibVersionJni(): Major=%d Minor=%d Patch=%d", majorVer, minorVer, patchVer);
snprintf(buff, sizeof(buff), "%d.%d.%d", majorVer, minorVer, patchVer);
returnValueStr = env->NewStringUTF((const char*)buff);
snprintf(buff, sizeof(buff), "%d.%d.%d", majorVer, minorVer, patchVer);
returnValueStr = env->NewStringUTF((const char*)buff);
return returnValueStr;
return returnValueStr;
}
\ No newline at end of file
......@@ -26,29 +26,29 @@ using namespace AndroidOlmSdk;
*/
JNIEXPORT void OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz)
{
OlmOutboundGroupSession* sessionPtr = NULL;
LOGD("## releaseSessionJni(): OutBound group session IN");
LOGD("## releaseSessionJni(): OutBound group session IN");
OlmOutboundGroupSession* sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
if(NULL == (sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
{
LOGE(" ## releaseSessionJni(): failure - invalid outbound group session instance");
}
else
{
LOGD(" ## releaseSessionJni(): sessionPtr=%p",sessionPtr);
if (!sessionPtr)
{
LOGE(" ## releaseSessionJni(): failure - invalid outbound group session instance");
}
else
{
LOGD(" ## releaseSessionJni(): sessionPtr=%p",sessionPtr);
#ifdef ENABLE_JNI_LOG
size_t retCode = olm_clear_outbound_group_session(sessionPtr);
LOGD(" ## releaseSessionJni(): clear_outbound_group_session=%lu",static_cast<long unsigned int>(retCode));
size_t retCode = olm_clear_outbound_group_session(sessionPtr);
LOGD(" ## releaseSessionJni(): clear_outbound_group_session=%lu",static_cast<long unsigned int>(retCode));
#else
olm_clear_outbound_group_session(sessionPtr);
olm_clear_outbound_group_session(sessionPtr);
#endif
LOGD(" ## releaseSessionJni(): free IN");
free(sessionPtr);
LOGD(" ## releaseSessionJni(): free OUT");
}
LOGD(" ## releaseSessionJni(): free IN");
free(sessionPtr);
LOGD(" ## releaseSessionJni(): free OUT");
}
}
/**
......@@ -65,18 +65,18 @@ JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv
LOGD("## createNewSessionJni(): outbound group session IN");
sessionSize = olm_outbound_group_session_size();
if(0 == sessionSize)
if (0 == sessionSize)
{
LOGE(" ## createNewSessionJni(): failure - outbound group session size = 0");
}
else if(NULL != (sessionPtr=(OlmOutboundGroupSession*)malloc(sessionSize)))
else if (!(sessionPtr = (OlmOutboundGroupSession*)malloc(sessionSize)))
{
sessionPtr = olm_outbound_group_session(sessionPtr);
LOGD(" ## createNewSessionJni(): success - outbound group session size=%lu",static_cast<long unsigned int>(sessionSize));
sessionPtr = olm_outbound_group_session(sessionPtr);
LOGD(" ## createNewSessionJni(): success - outbound group session size=%lu",static_cast<long unsigned int>(sessionSize));
}
else
{
LOGE(" ## createNewSessionJni(): failure - outbound group session OOM");
LOGE(" ## createNewSessionJni(): failure - outbound group session OOM");
}
return (jlong)(intptr_t)sessionPtr;
......@@ -89,12 +89,12 @@ JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv
JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(JNIEnv *env, jobject thiz)
{
jint retCode = ERROR_CODE_KO;
OlmOutboundGroupSession *sessionPtr = NULL;
uint8_t *randomBuffPtr = NULL;
LOGD("## initOutboundGroupSessionJni(): IN");
if(NULL == (sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
OlmOutboundGroupSession *sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
if (!sessionPtr)
{
LOGE(" ## initOutboundGroupSessionJni(): failure - invalid outbound group session instance");
}
......@@ -102,20 +102,24 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
{
// compute random buffer
size_t randomLength = olm_init_outbound_group_session_random_length(sessionPtr);
uint8_t *randomBuffPtr = NULL;
LOGW(" ## initOutboundGroupSessionJni(): randomLength=%lu",static_cast<long unsigned int>(randomLength));
if((0!=randomLength) && !setRandomInBuffer(env, &randomBuffPtr, randomLength))
if ((0 != randomLength) && !setRandomInBuffer(env, &randomBuffPtr, randomLength))
{
LOGE(" ## initOutboundGroupSessionJni(): failure - random buffer init");
}
else
{
if(0==randomLength)
if (0 == randomLength)
{
LOGW(" ## initOutboundGroupSessionJni(): random buffer is not required");
}
size_t sessionResult = olm_init_outbound_group_session(sessionPtr, randomBuffPtr, randomLength);
if(sessionResult == olm_error()) {
if (sessionResult == olm_error()) {
LOGE(" ## initOutboundGroupSessionJni(): failure - init outbound session creation Msg=%s",(const char *)olm_outbound_group_session_last_error(sessionPtr));
}
else
......@@ -123,12 +127,9 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
retCode = ERROR_CODE_OK;
LOGD(" ## initOutboundGroupSessionJni(): success - result=%lu", static_cast<long unsigned int>(sessionResult));
}
}
}
if(NULL != randomBuffPtr)
{
free(randomBuffPtr);
free(randomBuffPtr);
}
}
return retCode;
......@@ -139,13 +140,11 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
*/
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz)
{
OlmOutboundGroupSession *sessionPtr = NULL;
uint8_t *sessionIdPtr = NULL;
jstring returnValueStr=0;
LOGD("## sessionIdentifierJni(): outbound group session IN");
OlmOutboundGroupSession *sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
jstring returnValueStr=0;
if(NULL == (sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
if (!sessionPtr)
{
LOGE(" ## sessionIdentifierJni(): failure - invalid outbound group session instance");
}
......@@ -155,13 +154,16 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIE
size_t lengthSessionId = olm_outbound_group_session_id_length(sessionPtr);
LOGD(" ## sessionIdentifierJni(): outbound group session lengthSessionId=%lu",static_cast<long unsigned int>(lengthSessionId));
if(NULL == (sessionIdPtr = (uint8_t*)malloc((lengthSessionId+1)*sizeof(uint8_t))))
uint8_t *sessionIdPtr = (uint8_t*)malloc((lengthSessionId+1)*sizeof(uint8_t));
if (!sessionIdPtr)
{
LOGE(" ## sessionIdentifierJni(): failure - outbound identifier allocation OOM");
}
else
{
size_t result = olm_outbound_group_session_id(sessionPtr, sessionIdPtr, lengthSessionId);
if (result == olm_error())
{
LOGE(" ## sessionIdentifierJni(): failure - outbound group session identifier failure Msg=%s",reinterpret_cast<const char*>(olm_outbound_group_session_last_error(sessionPtr)));
......@@ -196,7 +198,7 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(messageIndexJni)(JNIEnv *env,
LOGD("## messageIndexJni(): IN");
if(NULL == (sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
{
LOGE(" ## messageIndexJni(): failure - invalid outbound group session instance");
}
......@@ -204,24 +206,22 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(messageIndexJni)(JNIEnv *env,
{
indexRetValue = static_cast<jint>(olm_outbound_group_session_message_index(sessionPtr));
}
LOGD(" ## messageIndexJni(): success - index=%d",indexRetValue);
return indexRetValue;
}
/**
* Get the base64-encoded current ratchet key for this session.<br>
*/
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env, jobject thiz)
{
OlmOutboundGroupSession *sessionPtr = NULL;
uint8_t *sessionKeyPtr = NULL;
jstring returnValueStr=0;
LOGD("## sessionKeyJni(): outbound group session IN");
OlmOutboundGroupSession *sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
jstring returnValueStr = 0;
if(NULL == (sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
if (!sessionPtr)
{
LOGE(" ## sessionKeyJni(): failure - invalid outbound group session instance");
}
......@@ -231,13 +231,16 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env
size_t sessionKeyLength = olm_outbound_group_session_key_length(sessionPtr);
LOGD(" ## sessionKeyJni(): sessionKeyLength=%lu",static_cast<long unsigned int>(sessionKeyLength));
if(NULL == (sessionKeyPtr = (uint8_t*)malloc((sessionKeyLength+1)*sizeof(uint8_t))))
uint8_t *sessionKeyPtr = (uint8_t*)malloc((sessionKeyLength+1)*sizeof(uint8_t));
if (!sessionKeyPtr)
{
LOGE(" ## sessionKeyJni(): failure - session key allocation OOM");
}
else
{
size_t result = olm_outbound_group_session_key(sessionPtr, sessionKeyPtr, sessionKeyLength);
if (result == olm_error())
{
LOGE(" ## sessionKeyJni(): failure - session key failure Msg=%s",(const char *)olm_outbound_group_session_last_error(sessionPtr));
......@@ -261,22 +264,21 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jstring aClearMsg)
{
LOGD("## encryptMessageJni(): IN");
jstring encryptedMsgRetValue = 0;
OlmOutboundGroupSession *sessionPtr = NULL;
const char *clearMsgPtr = NULL;
uint8_t *encryptedMsgPtr = NULL;
LOGD("## encryptMessageJni(): IN");
if(NULL == (sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
{
LOGE(" ## encryptMessageJni(): failure - invalid outbound group session ptr=NULL");
}
else if(0 == aClearMsg)
else if (!aClearMsg)
{
LOGE(" ## encryptMessageJni(): failure - invalid clear message");
}
else if(0 == (clearMsgPtr = env->GetStringUTFChars(aClearMsg, 0)))
else if (!(clearMsgPtr = env->GetStringUTFChars(aClearMsg, 0)))
{
LOGE(" ## encryptMessageJni(): failure - clear message JNI allocation OOM");
}
......@@ -288,7 +290,9 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv
// compute max encrypted length
size_t encryptedMsgLength = olm_group_encrypt_message_length(sessionPtr,clearMsgLength);