aboutsummaryrefslogtreecommitdiff
path: root/java/android/OlmLibSdk/olm-sdk/src/main/jni
diff options
context:
space:
mode:
authorylecollen <ylecollen@amdocs.com>2017-01-09 13:55:58 +0100
committerylecollen <ylecollen@amdocs.com>2017-01-09 13:55:58 +0100
commit7bf7a7e4158df882028df510e8d76009f2640d96 (patch)
tree6ec2ed94daa7a8fbc645f049979a9a0bf36ca33a /java/android/OlmLibSdk/olm-sdk/src/main/jni
parent13d3f4a1c78282c2ba3fcb3c0e29fe9e045c9e4e (diff)
use the same way to name the creation method i.e. createNewXX. Avoid the initWithXX.
Diffstat (limited to 'java/android/OlmLibSdk/olm-sdk/src/main/jni')
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp66
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.h1
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp8
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp36
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.h1
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp9
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.h2
7 files changed, 52 insertions, 71 deletions
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
index 7441da4..4da0d67 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
@@ -42,49 +42,13 @@ OlmAccount* initializeAccountMemory()
return accountPtr;
}
-JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(createNewAccountJni)(JNIEnv *env, jobject thiz)
-{
- LOGD("## createNewAccountJni(): IN");
- OlmAccount* accountPtr = initializeAccountMemory();
-
- LOGD(" ## createNewAccountJni(): success - accountPtr=%p (jlong)(intptr_t)accountPtr=%lld",accountPtr,(jlong)(intptr_t)accountPtr);
- 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.
- *
- */
-JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(releaseAccountJni)(JNIEnv *env, jobject thiz)
-{
- LOGD("## releaseAccountJni(): IN");
-
- OlmAccount* accountPtr = getAccountInstanceId(env, thiz);
-
- if (!accountPtr)
- {
- LOGE(" ## releaseAccountJni(): failure - invalid Account ptr=NULL");
- }
- else
- {
- LOGD(" ## releaseAccountJni(): accountPtr=%p",accountPtr);
- olm_clear_account(accountPtr);
-
- LOGD(" ## releaseAccountJni(): IN");
- // even if free(NULL) does not crash, logs are performed for debug purpose
- free(accountPtr);
- LOGD(" ## releaseAccountJni(): OUT");
- }
-}
-
/**
-* Initialize a new account and return it to JAVA side.<br>
+* Create a new account and return it to JAVA side.<br>
* Since a C prt is returned as a jlong, special care will be taken
* to make the cast (OlmAccount* => jlong) platform independent.
* @return the initialized OlmAccount* instance
**/
-JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(initNewAccountJni)(JNIEnv *env, jobject thiz)
+JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(createNewAccountJni)(JNIEnv *env, jobject thiz)
{
const char* errorMessage = NULL;
OlmAccount *accountPtr = initializeAccountMemory();
@@ -139,6 +103,32 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(initNewAccountJni)(JNIEnv *env, jobject thi
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.
+ *
+ */
+JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(releaseAccountJni)(JNIEnv *env, jobject thiz)
+{
+ LOGD("## releaseAccountJni(): IN");
+
+ OlmAccount* accountPtr = getAccountInstanceId(env, thiz);
+
+ if (!accountPtr)
+ {
+ LOGE(" ## releaseAccountJni(): failure - invalid Account ptr=NULL");
+ }
+ else
+ {
+ LOGD(" ## releaseAccountJni(): accountPtr=%p",accountPtr);
+ olm_clear_account(accountPtr);
+
+ LOGD(" ## releaseAccountJni(): IN");
+ // even if free(NULL) does not crash, logs are performed for debug purpose
+ free(accountPtr);
+ LOGD(" ## releaseAccountJni(): OUT");
+ }
+}
// *********************************************************************
// ************************* IDENTITY KEYS API *************************
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.h b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.h
index 5b73acd..2bfb39c 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.h
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.h
@@ -30,7 +30,6 @@ extern "C" {
// account creation/destruction
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(createNewAccountJni)(JNIEnv *env, jobject thiz);
// identity keys
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp
index dd3e0a9..7dd250b 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp
@@ -58,6 +58,7 @@ JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env
**/
JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz)
{
+ const char* errorMessage = NULL;
OlmInboundGroupSession* sessionPtr = NULL;
size_t sessionSize = 0;
@@ -67,6 +68,7 @@ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *
if (!sessionSize)
{
LOGE(" ## createNewSessionJni(): failure - inbound group session size = 0");
+ errorMessage = "inbound group session size = 0";
}
else if ((sessionPtr = (OlmInboundGroupSession*)malloc(sessionSize)))
{
@@ -76,6 +78,12 @@ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *
else
{
LOGE(" ## createNewSessionJni(): failure - inbound group session OOM");
+ errorMessage = "inbound group session OOM";
+ }
+
+ if (errorMessage)
+ {
+ env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
}
return (jlong)(intptr_t)sessionPtr;
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp
index d1459ae..6e26071 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp
@@ -48,7 +48,16 @@ JNIEXPORT jlong OLM_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject t
LOGD("## createNewSessionJni(): IN");
OlmSession* accountPtr = initializeSessionMemory();
- LOGD(" ## createNewSessionJni(): success - accountPtr=%p (jlong)(intptr_t)accountPtr=%lld",accountPtr,(jlong)(intptr_t)accountPtr);
+ if (!accountPtr)
+ {
+ LOGE("## initNewAccount(): failure - init session OOM");
+ env->ThrowNew(env->FindClass("java/lang/Exception"), "init session OOM");
+ }
+ else
+ {
+ LOGD(" ## createNewSessionJni(): success - accountPtr=%p (jlong)(intptr_t)accountPtr=%lld",accountPtr,(jlong)(intptr_t)accountPtr);
+ }
+
return (jlong)(intptr_t)accountPtr;
}
@@ -70,31 +79,6 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz
}
}
-/**
-* Initialize a new session and return it to JAVA side.<br>
-* Since a C prt is returned as a jlong, special care will be taken
-* to make the cast (OlmSession* => jlong) platform independent.
-* @return the initialized OlmSession* instance if init succeed, NULL otherwise
-**/
-JNIEXPORT jlong OLM_SESSION_FUNC_DEF(initNewSessionJni)(JNIEnv *env, jobject thiz)
-{
- LOGD("## initNewSessionJni(): OlmSession IN");
-
- OlmSession* sessionPtr = initializeSessionMemory();
-
- // init account memory allocation
- if (!sessionPtr)
- {
- LOGE(" ## initNewSessionJni(): failure - init session OOM");
- }
- else
- {
- LOGD(" ## initNewSessionJni(): success - OLM session created");
- }
-
- return (jlong)(intptr_t)sessionPtr;
-}
-
// *********************************************************************
// ********************** OUTBOUND SESSION *****************************
// *********************************************************************
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.h b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.h
index ef92395..76f59c5 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.h
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.h
@@ -29,7 +29,6 @@ extern "C" {
// session creation/destruction
JNIEXPORT void OLM_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz);
-JNIEXPORT jlong OLM_SESSION_FUNC_DEF(initNewSessionJni)(JNIEnv *env, jobject thiz);
JNIEXPORT jlong OLM_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz);
// outbound session
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp
index c4e6811..b26cfae 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp
@@ -37,20 +37,21 @@ OlmUtility* initializeUtilityMemory()
return utilityPtr;
}
-JNIEXPORT jlong OLM_UTILITY_FUNC_DEF(initUtilityJni)(JNIEnv *env, jobject thiz)
+JNIEXPORT jlong OLM_UTILITY_FUNC_DEF(createUtilityJni)(JNIEnv *env, jobject thiz)
{
OlmUtility* utilityPtr = initializeUtilityMemory();
- LOGD("## initUtilityJni(): IN");
+ LOGD("## createUtilityJni(): IN");
// init account memory allocation
if (!utilityPtr)
{
- LOGE(" ## initUtilityJni(): failure - init OOM");
+ LOGE(" ## createUtilityJni(): failure - init OOM");
+ env->ThrowNew(env->FindClass("java/lang/Exception"), "init OOM");
}
else
{
- LOGD(" ## initUtilityJni(): success");
+ LOGD(" ## createUtilityJni(): success");
}
return (jlong)(intptr_t)utilityPtr;
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.h b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.h
index 16d9e7a..de4b290 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.h
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.h
@@ -27,7 +27,7 @@
#ifdef __cplusplus
extern "C" {
#endif
-JNIEXPORT jlong OLM_UTILITY_FUNC_DEF(initUtilityJni)(JNIEnv *env, jobject thiz);
+JNIEXPORT jlong OLM_UTILITY_FUNC_DEF(createUtilityJni)(JNIEnv *env, jobject thiz);
JNIEXPORT void OLM_UTILITY_FUNC_DEF(releaseUtilityJni)(JNIEnv *env, jobject thiz);
JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(verifyEd25519SignatureJni)(JNIEnv *env, jobject thiz, jbyteArray aSignature, jbyteArray aKey, jbyteArray aMessage);
JNIEXPORT jbyteArray OLM_UTILITY_FUNC_DEF(sha256Jni)(JNIEnv *env, jobject thiz, jbyteArray aMessageToHash);