Fix tabulations mix and split block of variables when it is possible.

This commit is contained in:
ylecollen 2017-01-02 15:32:14 +01:00
parent f4ae0d86c9
commit 8f3d5bed72

View file

@ -26,11 +26,12 @@ using namespace AndroidOlmSdk;
**/ **/
OlmAccount* initializeAccountMemory() OlmAccount* initializeAccountMemory()
{ {
OlmAccount* accountPtr = NULL;
size_t accountSize = olm_account_size(); size_t accountSize = olm_account_size();
OlmAccount* accountPtr = (OlmAccount*)malloc(accountSize);
if(NULL != (accountPtr=(OlmAccount*)malloc(accountSize))) if (accountPtr)
{ // init account object {
// init account object
accountPtr = olm_account(accountPtr); accountPtr = olm_account(accountPtr);
LOGD("## initializeAccountMemory(): success - OLM account size=%lu",static_cast<long unsigned int>(accountSize)); LOGD("## initializeAccountMemory(): success - OLM account size=%lu",static_cast<long unsigned int>(accountSize));
} }
@ -60,11 +61,11 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(createNewAccountJni)(JNIEnv *env, jobject t
*/ */
JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(releaseAccountJni)(JNIEnv *env, jobject thiz) JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(releaseAccountJni)(JNIEnv *env, jobject thiz)
{ {
OlmAccount* accountPtr = NULL;
LOGD("## releaseAccountJni(): IN"); LOGD("## releaseAccountJni(): IN");
if(NULL == (accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz))) OlmAccount* accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz);
if(!accountPtr)
{ {
LOGE(" ## releaseAccountJni(): failure - invalid Account ptr=NULL"); LOGE(" ## releaseAccountJni(): failure - invalid Account ptr=NULL");
} }
@ -88,22 +89,23 @@ JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(releaseAccountJni)(JNIEnv *env, jobject thiz
**/ **/
JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(initNewAccountJni)(JNIEnv *env, jobject thiz) JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(initNewAccountJni)(JNIEnv *env, jobject thiz)
{ {
OlmAccount *accountPtr = NULL; OlmAccount *accountPtr = initializeAccountMemory();
uint8_t *randomBuffPtr = NULL;
size_t accountRetCode;
size_t randomSize;
// init account memory allocation // init account memory allocation
if(NULL == (accountPtr = initializeAccountMemory())) if (!accountPtr)
{ {
LOGE("## initNewAccount(): failure - init account OOM"); LOGE("## initNewAccount(): failure - init account OOM");
} }
else else
{ {
// get random buffer size // get random buffer size
randomSize = olm_create_account_random_length(accountPtr); size_t randomSize = olm_create_account_random_length(accountPtr);
LOGD("## initNewAccount(): randomSize=%lu", static_cast<long unsigned int>(randomSize)); LOGD("## initNewAccount(): randomSize=%lu", static_cast<long unsigned int>(randomSize));
uint8_t *randomBuffPtr = NULL;
size_t accountRetCode;
// allocate random buffer // allocate random buffer
if ((0 != randomSize) && !setRandomInBuffer(env, &randomBuffPtr, randomSize)) if ((0 != randomSize) && !setRandomInBuffer(env, &randomBuffPtr, randomSize))
{ {
@ -113,25 +115,25 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(initNewAccountJni)(JNIEnv *env, jobject thi
{ {
// create account // create account
accountRetCode = olm_create_account(accountPtr, (void*)randomBuffPtr, randomSize); accountRetCode = olm_create_account(accountPtr, (void*)randomBuffPtr, randomSize);
if(accountRetCode == olm_error()) {
if (accountRetCode == olm_error())
{
LOGE("## initNewAccount(): failure - account creation failed Msg=%s", olm_account_last_error(accountPtr)); LOGE("## initNewAccount(): failure - account creation failed Msg=%s", olm_account_last_error(accountPtr));
} }
LOGD("## initNewAccount(): success - OLM account created"); LOGD("## initNewAccount(): success - OLM account created");
LOGD("## initNewAccount(): success - accountPtr=%p (jlong)(intptr_t)accountPtr=%lld",accountPtr,(jlong)(intptr_t)accountPtr); LOGD("## initNewAccount(): success - accountPtr=%p (jlong)(intptr_t)accountPtr=%lld",accountPtr,(jlong)(intptr_t)accountPtr);
} }
}
if(NULL != randomBuffPtr) if (randomBuffPtr)
{ {
free(randomBuffPtr); free(randomBuffPtr);
} }
}
return (jlong)(intptr_t)accountPtr; return (jlong)(intptr_t)accountPtr;
} }
// ********************************************************************* // *********************************************************************
// ************************* IDENTITY KEYS API ************************* // ************************* IDENTITY KEYS API *************************
// ********************************************************************* // *********************************************************************
@ -142,34 +144,40 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(initNewAccountJni)(JNIEnv *env, jobject thi
**/ **/
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(identityKeysJni)(JNIEnv *env, jobject thiz) JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(identityKeysJni)(JNIEnv *env, jobject thiz)
{ {
OlmAccount* accountPtr = NULL;
size_t identityKeysLength;
uint8_t *identityKeysBytesPtr;
size_t keysResult;
jbyteArray byteArrayRetValue = NULL; jbyteArray byteArrayRetValue = NULL;
OlmAccount* accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz);
if(NULL == (accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz))) if (NULL == accountPtr)
{ {
LOGE("## identityKeys(): failure - invalid Account ptr=NULL"); LOGE("## identityKeys(): failure - invalid Account ptr=NULL");
} }
else else
{ {
LOGD("## identityKeys(): accountPtr =%p", accountPtr); LOGD("## identityKeys(): accountPtr =%p", accountPtr);
// identity keys allocation // identity keys allocation
identityKeysLength = olm_account_identity_keys_length(accountPtr); size_t identityKeysLength = olm_account_identity_keys_length(accountPtr);
if(NULL == (identityKeysBytesPtr=(uint8_t*)malloc(identityKeysLength))) uint8_t *identityKeysBytesPtr = (uint8_t*)malloc(identityKeysLength);
if (!identityKeysBytesPtr)
{ {
LOGE("## identityKeys(): failure - identity keys array OOM"); LOGE("## identityKeys(): failure - identity keys array OOM");
} }
else else
{ // retrieve key pairs in identityKeysBytesPtr {
keysResult = olm_account_identity_keys(accountPtr, identityKeysBytesPtr, identityKeysLength); // retrieve key pairs in identityKeysBytesPtr
if(keysResult == olm_error()) { size_t keysResult = olm_account_identity_keys(accountPtr, identityKeysBytesPtr, identityKeysLength);
if(keysResult == olm_error())
{
LOGE("## identityKeys(): failure - error getting identity keys Msg=%s",(const char *)olm_account_last_error(accountPtr)); LOGE("## identityKeys(): failure - error getting identity keys Msg=%s",(const char *)olm_account_last_error(accountPtr));
} }
else else
{ // allocate the byte array to be returned to java {
if(NULL == (byteArrayRetValue=env->NewByteArray(identityKeysLength))) // allocate the byte array to be returned to java
byteArrayRetValue = env->NewByteArray(identityKeysLength);
if(NULL == byteArrayRetValue)
{ {
LOGE("## identityKeys(): failure - return byte array OOM"); LOGE("## identityKeys(): failure - return byte array OOM");
} }
@ -196,10 +204,10 @@ 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 = NULL; OlmAccount* accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz);
size_t maxKeys = -1; size_t maxKeys = -1;
if(NULL == (accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz))) if (!accountPtr)
{ {
LOGE("## maxOneTimeKey(): failure - invalid Account ptr=NULL"); LOGE("## maxOneTimeKey(): failure - invalid Account ptr=NULL");
} }
@ -207,6 +215,7 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(maxOneTimeKeysJni)(JNIEnv *env, jobject thi
{ {
maxKeys = olm_account_max_number_of_one_time_keys(accountPtr); maxKeys = olm_account_max_number_of_one_time_keys(accountPtr);
} }
LOGD("## maxOneTimeKey(): Max keys=%lu", static_cast<long unsigned int>(maxKeys)); LOGD("## maxOneTimeKey(): Max keys=%lu", static_cast<long unsigned int>(maxKeys));
return (jlong)maxKeys; return (jlong)maxKeys;
@ -219,22 +228,21 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(maxOneTimeKeysJni)(JNIEnv *env, jobject thi
**/ **/
JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(generateOneTimeKeysJni)(JNIEnv *env, jobject thiz, jint aNumberOfKeys) JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(generateOneTimeKeysJni)(JNIEnv *env, jobject thiz, jint aNumberOfKeys)
{ {
OlmAccount *accountPtr = NULL; OlmAccount *accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz);
uint8_t *randomBufferPtr = NULL;
jint retCode = ERROR_CODE_KO; jint retCode = ERROR_CODE_KO;
size_t randomLength;
size_t result;
if (!accountPtr)
if(NULL == (accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz)))
{ {
LOGE("## generateOneTimeKeysJni(): failure - invalid Account ptr"); LOGE("## generateOneTimeKeysJni(): failure - invalid Account ptr");
} }
else else
{ // keys memory allocation {
randomLength = olm_account_generate_one_time_keys_random_length(accountPtr, (size_t)aNumberOfKeys); // keys memory allocation
size_t randomLength = olm_account_generate_one_time_keys_random_length(accountPtr, (size_t)aNumberOfKeys);
LOGD("## generateOneTimeKeysJni(): randomLength=%lu", static_cast<long unsigned int>(randomLength)); LOGD("## generateOneTimeKeysJni(): randomLength=%lu", static_cast<long unsigned int>(randomLength));
uint8_t *randomBufferPtr = NULL;
if ( (0!=randomLength) && !setRandomInBuffer(env, &randomBufferPtr, randomLength)) if ( (0!=randomLength) && !setRandomInBuffer(env, &randomBufferPtr, randomLength))
{ {
LOGE("## generateOneTimeKeysJni(): failure - random buffer init"); LOGE("## generateOneTimeKeysJni(): failure - random buffer init");
@ -244,7 +252,8 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(generateOneTimeKeysJni)(JNIEnv *env, jobject
LOGD("## generateOneTimeKeysJni(): accountPtr =%p aNumberOfKeys=%d",accountPtr, aNumberOfKeys); LOGD("## generateOneTimeKeysJni(): accountPtr =%p aNumberOfKeys=%d",accountPtr, aNumberOfKeys);
// retrieve key pairs in keysBytesPtr // retrieve key pairs in keysBytesPtr
result = olm_account_generate_one_time_keys(accountPtr, (size_t)aNumberOfKeys, (void*)randomBufferPtr, randomLength); size_t result = olm_account_generate_one_time_keys(accountPtr, (size_t)aNumberOfKeys, (void*)randomBufferPtr, randomLength);
if (result == olm_error()) { if (result == olm_error()) {
LOGE("## generateOneTimeKeysJni(): failure - error generating one time keys Msg=%s",(const char *)olm_account_last_error(accountPtr)); LOGE("## generateOneTimeKeysJni(): failure - error generating one time keys Msg=%s",(const char *)olm_account_last_error(accountPtr));
} }
@ -254,12 +263,13 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(generateOneTimeKeysJni)(JNIEnv *env, jobject
LOGD("## generateOneTimeKeysJni(): success - result=%lu", static_cast<long unsigned int>(result)); LOGD("## generateOneTimeKeysJni(): success - result=%lu", static_cast<long unsigned int>(result));
} }
} }
}
if(NULL != randomBufferPtr)
if (randomBufferPtr)
{ {
free(randomBufferPtr); free(randomBufferPtr);
} }
}
return retCode; return retCode;
} }
@ -271,34 +281,38 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(generateOneTimeKeysJni)(JNIEnv *env, jobject
**/ **/
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(oneTimeKeysJni)(JNIEnv *env, jobject thiz) JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(oneTimeKeysJni)(JNIEnv *env, jobject thiz)
{ {
OlmAccount* accountPtr = NULL;
size_t keysLength;
uint8_t *keysBytesPtr;
size_t keysResult;
jbyteArray byteArrayRetValue = NULL; jbyteArray byteArrayRetValue = NULL;
OlmAccount* accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz);
LOGD("## oneTimeKeysJni(): IN"); LOGD("## oneTimeKeysJni(): IN");
if(NULL == (accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz))) if (!accountPtr)
{ {
LOGE("## oneTimeKeysJni(): failure - invalid Account ptr"); LOGE("## oneTimeKeysJni(): failure - invalid Account ptr");
} }
else else
{ // keys memory allocation {
keysLength = olm_account_one_time_keys_length(accountPtr); // keys memory allocation
if(NULL == (keysBytesPtr=(uint8_t *)malloc(keysLength*sizeof(uint8_t)))) size_t keysLength = olm_account_one_time_keys_length(accountPtr);
uint8_t *keysBytesPtr = (uint8_t *)malloc(keysLength*sizeof(uint8_t));
if (!keysBytesPtr)
{ {
LOGE("## oneTimeKeysJni(): failure - one time keys array OOM"); LOGE("## oneTimeKeysJni(): failure - one time keys array OOM");
} }
else else
{ // retrieve key pairs in keysBytesPtr {
keysResult = olm_account_one_time_keys(accountPtr, keysBytesPtr, keysLength); // 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)); LOGE("## oneTimeKeysJni(): failure - error getting one time keys Msg=%s",(const char *)olm_account_last_error(accountPtr));
} }
else else
{ // allocate the byte array to be returned to java {
if(NULL == (byteArrayRetValue=env->NewByteArray(keysLength))) // allocate the byte array to be returned to java
byteArrayRetValue = env->NewByteArray(keysLength);
if (!byteArrayRetValue)
{ {
LOGE("## oneTimeKeysJni(): failure - return byte array OOM"); LOGE("## oneTimeKeysJni(): failure - return byte array OOM");
} }
@ -327,19 +341,19 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(removeOneTimeKeysForSessionJni)(JNIEnv *env,
jint retCode = ERROR_CODE_KO; jint retCode = ERROR_CODE_KO;
OlmAccount* accountPtr = NULL; OlmAccount* accountPtr = NULL;
OlmSession* sessionPtr = (OlmSession*)aNativeOlmSessionId; OlmSession* sessionPtr = (OlmSession*)aNativeOlmSessionId;
size_t result;
if(NULL == sessionPtr) if (!sessionPtr)
{ {
LOGE("## removeOneTimeKeysForSessionJni(): failure - invalid session ptr"); LOGE("## removeOneTimeKeysForSessionJni(): failure - invalid session ptr");
} }
else if(NULL == (accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz))) else if(!(accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz)))
{ {
LOGE("## removeOneTimeKeysForSessionJni(): failure - invalid account ptr"); LOGE("## removeOneTimeKeysForSessionJni(): failure - invalid account ptr");
} }
else else
{ {
result = olm_remove_one_time_keys(accountPtr, sessionPtr); size_t result = olm_remove_one_time_keys(accountPtr, sessionPtr);
if (result == olm_error()) if (result == olm_error())
{ // the account doesn't have any matching "one time keys".. { // the account doesn't have any matching "one time keys"..
LOGW("## removeOneTimeKeysForSessionJni(): failure - removing one time keys Msg=%s",(const char *)olm_account_last_error(accountPtr)); LOGW("## removeOneTimeKeysForSessionJni(): failure - removing one time keys Msg=%s",(const char *)olm_account_last_error(accountPtr));
@ -363,17 +377,17 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(removeOneTimeKeysForSessionJni)(JNIEnv *env,
JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env, jobject thiz) JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env, jobject thiz)
{ {
jint retCode = ERROR_CODE_OK; jint retCode = ERROR_CODE_OK;
OlmAccount* accountPtr = NULL; OlmAccount* accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz);
size_t result;
if(NULL == (accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz))) if (!accountPtr)
{ {
LOGE("## markOneTimeKeysAsPublishedJni(): failure - invalid account ptr"); LOGE("## markOneTimeKeysAsPublishedJni(): failure - invalid account ptr");
retCode = ERROR_CODE_KO; retCode = ERROR_CODE_KO;
} }
else else
{ {
result = olm_account_mark_keys_as_published(accountPtr); 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)); LOGW("## markOneTimeKeysAsPublishedJni(): failure - Msg=%s",(const char *)olm_account_last_error(accountPtr));
@ -397,12 +411,9 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env,
JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aMessage) JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aMessage)
{ {
OlmAccount* accountPtr = NULL; OlmAccount* accountPtr = NULL;
size_t signatureLength;
void* signedMsgPtr;
size_t resultSign;
jstring signedMsgRetValue = NULL; jstring signedMsgRetValue = NULL;
if(NULL == aMessage) if (!aMessage)
{ {
LOGE("## signMessageJni(): failure - invalid aMessage param"); LOGE("## signMessageJni(): failure - invalid aMessage param");
} }
@ -416,20 +427,22 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
jbyte* messageToSign = env->GetByteArrayElements(aMessage, NULL); jbyte* messageToSign = env->GetByteArrayElements(aMessage, NULL);
// signature memory allocation // signature memory allocation
signatureLength = olm_account_signature_length(accountPtr); size_t signatureLength = olm_account_signature_length(accountPtr);
void* signedMsgPtr = malloc((signatureLength+1)*sizeof(uint8_t));
if(NULL == (signedMsgPtr = (void*)malloc((signatureLength+1)*sizeof(uint8_t)))) if (!signedMsgPtr)
{ {
LOGE("## signMessageJni(): failure - signature allocation OOM"); LOGE("## signMessageJni(): failure - signature allocation OOM");
} }
else else
{ {
// sign message // sign message
resultSign = olm_account_sign(accountPtr, size_t resultSign = olm_account_sign(accountPtr,
(void*)messageToSign, (void*)messageToSign,
(size_t)messageLength, (size_t)messageLength,
signedMsgPtr, signedMsgPtr,
signatureLength); signatureLength);
if (resultSign == olm_error()) if (resultSign == olm_error())
{ {
LOGE("## signMessageJni(): failure - error signing message Msg=%s",(const char *)olm_account_last_error(accountPtr)); LOGE("## signMessageJni(): failure - error signing message Msg=%s",(const char *)olm_account_last_error(accountPtr));
@ -464,45 +477,36 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
**/ **/
JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jstring aKey, jobject aErrorMsg) JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jstring aKey, jobject aErrorMsg)
{ {
/*jstring pickledDataRetValue = serializeDataWithKey(env,thiz,
aKey,
aErrorMsg,
olm_pickle_account_length,
olm_pickle_account,
olm_account_last_error);
return pickledDataRetValue;*/
jstring pickledDataRetValue = 0; jstring pickledDataRetValue = 0;
jclass errorMsgJClass = 0; jclass errorMsgJClass = 0;
jmethodID errorMsgMethodId = 0; jmethodID errorMsgMethodId = 0;
jstring errorJstring = 0; jstring errorJstring = 0;
const char *keyPtr = NULL; const char *keyPtr = NULL;
void *pickledPtr = NULL;
OlmAccount* accountPtr = NULL; OlmAccount* accountPtr = NULL;
LOGD("## serializeDataWithKeyJni(): IN"); LOGD("## serializeDataWithKeyJni(): IN");
if(NULL == (accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz))) if (!aKey)
{
LOGE(" ## serializeDataWithKeyJni(): failure - invalid account ptr");
}
else if(0 == aKey)
{ {
LOGE(" ## serializeDataWithKeyJni(): failure - invalid key"); LOGE(" ## serializeDataWithKeyJni(): failure - invalid key");
} }
else if(0 == aErrorMsg) else if(!aErrorMsg)
{ {
LOGE(" ## serializeDataWithKeyJni(): failure - invalid error object"); LOGE(" ## serializeDataWithKeyJni(): failure - invalid error object");
} }
else if(0 == (errorMsgJClass = env->GetObjectClass(aErrorMsg))) else if(!(accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz)))
{
LOGE(" ## serializeDataWithKeyJni(): failure - invalid account ptr");
}
else if(!(errorMsgJClass = env->GetObjectClass(aErrorMsg)))
{ {
LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error class"); LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error class");
} }
else if(0 == (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"); LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error method ID");
} }
else if(NULL == (keyPtr = env->GetStringUTFChars(aKey, 0))) else if(!(keyPtr = env->GetStringUTFChars(aKey, 0)))
{ {
LOGE(" ## serializeDataWithKeyJni(): failure - keyPtr JNI allocation OOM"); LOGE(" ## serializeDataWithKeyJni(): failure - keyPtr JNI allocation OOM");
} }
@ -513,7 +517,9 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
LOGD(" ## serializeDataWithKeyJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength)); LOGD(" ## serializeDataWithKeyJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
LOGD(" ## serializeDataWithKeyJni(): key=%s",(char const *)keyPtr); LOGD(" ## serializeDataWithKeyJni(): key=%s",(char const *)keyPtr);
if(NULL == (pickledPtr = (void*)malloc((pickledLength+1)*sizeof(uint8_t)))) void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
if (!pickledPtr)
{ {
LOGE(" ## serializeDataWithKeyJni(): failure - pickledPtr buffer OOM"); LOGE(" ## serializeDataWithKeyJni(): failure - pickledPtr buffer OOM");
} }
@ -541,20 +547,17 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
pickledDataRetValue = env->NewStringUTF((const char*)pickledPtr); pickledDataRetValue = env->NewStringUTF((const char*)pickledPtr);
LOGD(" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr)); LOGD(" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
} }
free(pickledPtr);
} }
} }
// free alloc // free alloc
if(NULL != keyPtr) if (keyPtr)
{ {
env->ReleaseStringUTFChars(aKey, keyPtr); env->ReleaseStringUTFChars(aKey, keyPtr);
} }
if(NULL != pickledPtr)
{
free(pickledPtr);
}
return pickledDataRetValue; return pickledDataRetValue;
} }
@ -568,24 +571,23 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, j
LOGD("## initWithSerializedDataJni(): IN"); LOGD("## initWithSerializedDataJni(): IN");
if(NULL == (accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz))) if (!aKey)
//if(NULL == (accountPtr = initializeAccountMemory()))
{
LOGE(" ## initWithSerializedDataJni(): failure - account failure OOM");
}
else if(0 == aKey)
{ {
LOGE(" ## initWithSerializedDataJni(): failure - invalid key"); LOGE(" ## initWithSerializedDataJni(): failure - invalid key");
} }
else if(0 == aSerializedData) else if (!aSerializedData)
{ {
LOGE(" ## initWithSerializedDataJni(): failure - serialized data"); LOGE(" ## initWithSerializedDataJni(): failure - serialized data");
} }
else if(NULL == (keyPtr = env->GetStringUTFChars(aKey, 0))) else if (!(accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz)))
{
LOGE(" ## initWithSerializedDataJni(): failure - account failure OOM");
}
else if (!(keyPtr = env->GetStringUTFChars(aKey, 0)))
{ {
LOGE(" ## initWithSerializedDataJni(): failure - keyPtr JNI allocation OOM"); LOGE(" ## initWithSerializedDataJni(): failure - keyPtr JNI allocation OOM");
} }
else if(NULL == (pickledPtr = env->GetStringUTFChars(aSerializedData, 0))) else if (!(pickledPtr = env->GetStringUTFChars(aSerializedData, 0)))
{ {
LOGE(" ## initWithSerializedDataJni(): failure - pickledPtr JNI allocation OOM"); LOGE(" ## initWithSerializedDataJni(): failure - pickledPtr JNI allocation OOM");
} }
@ -615,12 +617,12 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, j
} }
// free alloc // free alloc
if(NULL != keyPtr) if (keyPtr)
{ {
env->ReleaseStringUTFChars(aKey, keyPtr); env->ReleaseStringUTFChars(aKey, keyPtr);
} }
if(NULL != pickledPtr) if (pickledPtr)
{ {
env->ReleaseStringUTFChars(aSerializedData, pickledPtr); env->ReleaseStringUTFChars(aSerializedData, pickledPtr);
} }