endif\r
\r
include $(CLEAR_VARS)\r
-ifeq ($(SECURE), 1)\r
- LOCAL_CFLAGS += -D__WITH_DTLS__\r
-endif\r
OIC_SRC_PATH := ../../../resource\r
LOCAL_MODULE := libca-interface\r
LOCAL_SRC_FILES := JniCaInterface.c\r
endif\r
\r
ifeq ($(WITH_TCP), 1)\r
- LOCAL_CPPFLAGS += -DWITH_TCP\r
LOCAL_CPPFLAGS += -D__WITH_TLS__\r
endif\r
\r
-ifeq ($(SECURED), 1)\r
- LOCAL_CPPFLAGS += -D__WITH_DTLS__\r
-endif\r
-\r
MQ_FLAG = 0\r
ifeq ($(WITH_MQ_PUB), 1)\r
LOCAL_CFLAGS += -DWITH_MQ -DMQ_PUBLISHER\r
LOCAL_SRC_FILES += JniOcAccountManager.cpp\r
endif\r
\r
+ifeq ($(WITH_TCP), 1)\r
+ LOCAL_SRC_FILES += JniOcCloudProvisioning.cpp \\r
+ JniOcCloudResultListener.cpp \\r
+ JniGetAclIdByDeviceListener.cpp\r
+endif\r
+\r
+\r
LOCAL_LDLIBS := -llog\r
LOCAL_STATIC_LIBRARIES := android-oc\r
LOCAL_STATIC_LIBRARIES += android-octbstack\r
LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../extlibs/cjson\r
LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../build_common/android/compatibility\r
LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include\r
-LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/cloud\r
-LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/oxm\r
+LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/oxm/\r
LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/internal\r
+LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/cloud/\r
LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/include\r
LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/include/internal\r
LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/connectivity/api\r
--- /dev/null
+/*
+* //******************************************************************
+* //
+* // Copyright 2016 Samsung Electronics All Rights Reserved.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // Licensed under the Apache License, Version 2.0 (the "License");
+* // you may not use this file except in compliance with the License.
+* // You may obtain a copy of the License at
+* //
+* // http://www.apache.org/licenses/LICENSE-2.0
+* //
+* // Unless required by applicable law or agreed to in writing, software
+* // distributed under the License is distributed on an "AS IS" BASIS,
+* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* // See the License for the specific language governing permissions and
+* // limitations under the License.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+*/
+#include "JniGetAclIdByDeviceListener.h"
+
+JniGetAclIdByDeviceListener::JniGetAclIdByDeviceListener(JNIEnv *env, jobject jListener,
+ RemoveCallback removeListener)
+{
+ m_jwListener = env->NewWeakGlobalRef(jListener);
+ m_removeGetAclbyIDListener = removeListener;
+}
+
+JniGetAclIdByDeviceListener::~JniGetAclIdByDeviceListener()
+{
+ LOGI("~JniGetAclIdByDeviceListener()");
+ if (m_jwListener)
+ {
+ jint ret = JNI_ERR;
+ JNIEnv *env = GetJNIEnv(ret);
+ if (nullptr == env)
+ {
+ return;
+ }
+ env->DeleteWeakGlobalRef(m_jwListener);
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+ }
+}
+
+void JniGetAclIdByDeviceListener::GetAclIdByDeviceListenerCB(int result, std::string aclID)
+{
+ jint ret = JNI_ERR;
+ JNIEnv *env = GetJNIEnv(ret);
+ if (nullptr == env)
+ {
+ return;
+ }
+
+ jobject jListener = env->NewLocalRef(m_jwListener);
+ if (!jListener)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+ return;
+ }
+
+ jclass clsL = env->GetObjectClass(jListener);
+
+ if (!clsL)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+ return;
+ }
+
+ jmethodID midL = env->GetMethodID(clsL, "getAclIdByDeviceListener", "(ZLjava/lang/String;)V");
+ if (!midL)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+ return;
+ }
+ jstring jStr = env-> NewStringUTF(aclID.c_str());
+ if (!jStr)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+ return;
+
+ }
+ env->CallVoidMethod(jListener, midL, (jboolean)result, jStr);
+ if (env->ExceptionCheck())
+ {
+ LOGE("Java exception is thrown");
+ }
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+}
+
+void JniGetAclIdByDeviceListener::checkExAndRemoveListener(JNIEnv* env)
+{
+ if (env->ExceptionCheck())
+ {
+ jthrowable ex = env->ExceptionOccurred();
+ env->ExceptionClear();
+ m_removeGetAclbyIDListener(env, m_jwListener);
+ env->Throw((jthrowable)ex);
+ }
+ else
+ {
+ m_removeGetAclbyIDListener(env, m_jwListener);
+ }
+}
--- /dev/null
+/*
+* //******************************************************************
+* //
+* // Copyright 2016 Samsung Electronics All Rights Reserved.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // Licensed under the Apache License, Version 2.0 (the "License");
+* // you may not use this file except in compliance with the License.
+* // You may obtain a copy of the License at
+* //
+* // http://www.apache.org/licenses/LICENSE-2.0
+* //
+* // Unless required by applicable law or agreed to in writing, software
+* // distributed under the License is distributed on an "AS IS" BASIS,
+* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* // See the License for the specific language governing permissions and
+* // limitations under the License.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+*/
+
+#include <jni.h>
+#include "JniOcStack.h"
+
+/* Header for class org_iotivity_base_OcCloudProvisioning_GetAclIdByDeviceListener */
+#ifndef _Included_org_iotivity_base_OcCloudProvisioning_JniGetAclIdByDeviceListener
+#define _Included_org_iotivity_base_OcCloudProvisioning_JniGetAclIdByDeviceListener
+
+typedef std::function<void(JNIEnv* env, jobject jListener)> RemoveCallback;
+
+class JniGetAclIdByDeviceListener
+{
+ public:
+ JniGetAclIdByDeviceListener(JNIEnv *env, jobject jListener,
+ RemoveCallback removeListener);
+ ~JniGetAclIdByDeviceListener();
+
+ void GetAclIdByDeviceListenerCB(int result, std::string aclID);
+
+ private:
+ RemoveCallback m_removeGetAclbyIDListener;
+ jweak m_jwListener;
+ void checkExAndRemoveListener(JNIEnv* env);
+};
+#endif
--- /dev/null
+/*
+* //******************************************************************
+* //
+* // Copyright 2016 Samsung Electronics All Rights Reserved.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // Licensed under the Apache License, Version 2.0 (the "License");
+* // you may not use this file except in compliance with the License.
+* // You may obtain a copy of the License at
+* //
+* // http://www.apache.org/licenses/LICENSE-2.0
+* //
+* // Unless required by applicable law or agreed to in writing, software
+* // distributed under the License is distributed on an "AS IS" BASIS,
+* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* // See the License for the specific language governing permissions and
+* // limitations under the License.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+*/
+
+#include "JniOcCloudProvisioning.h"
+#include "oic_malloc.h"
+
+namespace PH = std::placeholders;
+
+JniOcCloudProvisioning::JniOcCloudProvisioning(std::shared_ptr<OCCloudProvisioning> p)
+ : m_sharedCloudObject(p)
+{}
+
+JniOcCloudProvisioning::~JniOcCloudProvisioning()
+{
+ LOGD("~JniOcCloudProvisioning");
+ m_sharedCloudObject = nullptr;
+}
+
+JniOcCloudResultListener* JniOcCloudProvisioning::AddCloudResultListener(JNIEnv* env,
+ jobject jListener)
+{
+ JniOcCloudResultListener *resultListener = NULL;
+ resultMapLock.lock();
+
+ for (auto it = resultMap.begin(); it != resultMap.end(); ++it)
+ {
+ if (env->IsSameObject(jListener, it->first))
+ {
+ auto refPair = it->second;
+ resultListener = refPair.first;
+ refPair.second++;
+ it->second = refPair;
+ resultMap.insert(*it);
+ LOGD("Cloud Provision resultListener: ref. count incremented");
+ break;
+ }
+ }
+ if (!resultListener)
+ {
+ resultListener = new JniOcCloudResultListener(env, jListener,
+ RemoveCallback(std::bind(&JniOcCloudProvisioning::RemoveCloudResultListener,
+ this, PH::_1, PH::_2)));
+ jobject jgListener = env->NewGlobalRef(jListener);
+
+ resultMap.insert(std::pair < jobject, std::pair < JniOcCloudResultListener*,
+ int >> (jgListener, std::pair<JniOcCloudResultListener*, int>(resultListener, 1)));
+ LOGD("Cloud Provision resultListener: new listener");
+ }
+ resultMapLock.unlock();
+ return resultListener;
+}
+
+void JniOcCloudProvisioning::RemoveCloudResultListener(JNIEnv* env, jobject jListener)
+{
+ resultMapLock.lock();
+
+ for (auto it = resultMap.begin(); it != resultMap.end(); ++it)
+ {
+ if (env->IsSameObject(jListener, it->first))
+ {
+ auto refPair = it->second;
+ if (refPair.second > 1)
+ {
+ refPair.second--;
+ it->second = refPair;
+ resultMap.insert(*it);
+ LOGI("Cloud Provision resultListener: ref. count decremented");
+ }
+ else
+ {
+ env->DeleteGlobalRef(it->first);
+ JniOcCloudResultListener* listener = refPair.first;
+ delete listener;
+ resultMap.erase(it);
+ LOGI("Cloud Provision resultListener removed");
+ }
+ break;
+ }
+ }
+ resultMapLock.unlock();
+}
+
+JniGetAclIdByDeviceListener* JniOcCloudProvisioning::AddGetAclByDeviceListener(JNIEnv* env,
+ jobject jListener)
+{
+ JniGetAclIdByDeviceListener *resultListener = NULL;
+ aclresultMapLock.lock();
+
+ for (auto it = aclresultMap.begin(); it != aclresultMap.end(); ++it)
+ {
+ if (env->IsSameObject(jListener, it->first))
+ {
+ auto refPair = it->second;
+ resultListener = refPair.first;
+ refPair.second++;
+ it->second = refPair;
+ aclresultMap.insert(*it);
+ LOGD("GetACLByDeviceID Listener: ref. count incremented");
+ break;
+ }
+ }
+ if (!resultListener)
+ {
+ resultListener = new JniGetAclIdByDeviceListener(env, jListener,
+ RemoveCallback(std::bind(&JniOcCloudProvisioning::RemoveGetAclByDeviceIdListener,
+ this, PH::_1, PH::_2)));
+ jobject jgListener = env->NewGlobalRef(jListener);
+
+ aclresultMap.insert(std::pair < jobject, std::pair < JniGetAclIdByDeviceListener*,
+ int >> (jgListener, std::pair<JniGetAclIdByDeviceListener*, int>(resultListener, 1)));
+ LOGD("GetACLByDeviceID Listener: new listener");
+ }
+ aclresultMapLock.unlock();
+ return resultListener;
+}
+
+void JniOcCloudProvisioning::RemoveGetAclByDeviceIdListener(JNIEnv* env, jobject jListener)
+{
+ aclresultMapLock.lock();
+
+ for (auto it = aclresultMap.begin(); it != aclresultMap.end(); ++it)
+ {
+ if (env->IsSameObject(jListener, it->first))
+ {
+ auto refPair = it->second;
+ if (refPair.second > 1)
+ {
+ refPair.second--;
+ it->second = refPair;
+ aclresultMap.insert(*it);
+ LOGI("GetACLByDeviceID Listener: ref. count decremented");
+ }
+ else
+ {
+ env->DeleteGlobalRef(it->first);
+ JniGetAclIdByDeviceListener* listener = refPair.first;
+ delete listener;
+ aclresultMap.erase(it);
+ LOGI("GetACLByDeviceID Listener removed");
+ }
+ break;
+ }
+ }
+ aclresultMapLock.unlock();
+}
+JniOcCloudProvisioning * Create_native_object(JNIEnv *env, jobject thiz)
+{
+ jstring jip = (jstring)env->CallObjectMethod(thiz, g_mid_OcCloudProvisioning_getIP);
+ if (!jip || env->ExceptionCheck())
+ {
+ return nullptr;
+ }
+ const char *str = env->GetStringUTFChars(jip, NULL);
+ std::string ipaddress(str);
+ env->ReleaseStringUTFChars(jip, str);
+
+ jint port = env->CallIntMethod(thiz, g_mid_OcCloudProvisioning_getPort);
+ if (env->ExceptionCheck())
+ {
+ return nullptr;
+ }
+ JniOcCloudProvisioning *cloud = new JniOcCloudProvisioning(
+ std::shared_ptr<OCCloudProvisioning>(new OCCloudProvisioning(ipaddress, (uint16_t)port)));
+ SetHandle<JniOcCloudProvisioning>(env, thiz, cloud);
+ return cloud;
+}
+
+JniOcCloudProvisioning* JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(JNIEnv *env, jobject thiz)
+{
+ JniOcCloudProvisioning *cloud = GetHandle<JniOcCloudProvisioning>(env, thiz);
+
+ if (env->ExceptionCheck())
+ {
+ LOGE("Failed to get native handle from OcCloudProvisioning class");
+ }
+
+ return cloud;
+}
+
+OCStackResult JniOcCloudProvisioning::requestCertificate(JNIEnv* env, jobject jListener)
+{
+ JniOcCloudResultListener *resultListener = AddCloudResultListener(env, jListener);
+
+ ResponseCallBack responseCallBack = [resultListener](OCStackResult result, void *data)
+ {
+ resultListener->CloudResultListenerCB(result, data, ListenerFunc::REQUEST_CERTIFICATE);
+ };
+
+ return m_sharedCloudObject->requestCertificate(responseCallBack);
+}
+
+OCStackResult JniOcCloudProvisioning::getIndividualAclInfo(JNIEnv* env, jobject jListener, std::string &aclID)
+{
+ JniOcCloudResultListener *resultListener = AddCloudResultListener(env, jListener);
+
+ ResponseCallBack responseCallBack = [resultListener](OCStackResult result, void *data)
+ {
+ resultListener->CloudResultListenerCB(result, data, ListenerFunc::GET_ACLINFO);
+ };
+
+ return m_sharedCloudObject->getIndividualAclInfo(aclID, responseCallBack);
+}
+
+OCStackResult JniOcCloudProvisioning::getCRL(JNIEnv* env, jobject jListener)
+{
+ JniOcCloudResultListener *resultListener = AddCloudResultListener(env, jListener);
+
+ ResponseCallBack responseCallBack = [resultListener](OCStackResult result, void *data)
+ {
+ resultListener->CloudResultListenerCB(result, data, ListenerFunc::GET_CRL);
+ };
+
+ return m_sharedCloudObject->getCRL(responseCallBack);
+}
+
+OCStackResult JniOcCloudProvisioning::postCRL(JNIEnv* env, const std::string& thisUpdate,
+ const std::string& nextUpdate, const OCByteString *crl,
+ const stringArray_t *serialNumbers, jobject jListener)
+{
+ JniOcCloudResultListener *resultListener = AddCloudResultListener(env, jListener);
+
+ ResponseCallBack responseCallBack = [resultListener](OCStackResult result, void *data)
+ {
+ resultListener->CloudResultListenerCB(result, data, ListenerFunc::POST_CRL);
+ };
+
+ return m_sharedCloudObject->postCRL(thisUpdate, nextUpdate, crl, serialNumbers,
+ responseCallBack);
+}
+
+OCStackResult JniOcCloudProvisioning::getAclIdByDevice(JNIEnv* env, std::string deviceId,
+ jobject jListener)
+{
+ JniGetAclIdByDeviceListener *resultListener = AddGetAclByDeviceListener(env, jListener);
+
+ AclIdResponseCallBack aclIdResponseCallBack = [resultListener](OCStackResult result,
+ std::string aclId)
+ {
+ resultListener->GetAclIdByDeviceListenerCB(result, aclId);
+ };
+
+ return m_sharedCloudObject->getAclIdByDevice(deviceId, aclIdResponseCallBack);
+}
+/*
+ * Class: org_iotivity_base_OcCloudProvisioning
+ * Method: requestCertificate
+ * Signature: (Lorg/iotivity/base/OcCloudProvisioning/RequestCertificateListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_requestCertificate
+ (JNIEnv* env, jobject thiz, jobject jListener)
+{
+ LOGD("OcCloudProvisioning_requestCertificate");
+ if (!jListener)
+ {
+ ThrowOcException(OC_STACK_INVALID_PARAM, "Listener cannot be null");
+ return;
+ }
+
+ JniOcCloudProvisioning *cloud = JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(env, thiz);
+ if (!cloud)
+ {
+ LOGD("OcCloudProvisioning_requestCertificate, No native object, creating now");
+ cloud = Create_native_object(env, thiz);
+ if (!cloud)
+ {
+ ThrowOcException(OC_STACK_ERROR, "OcCloudProvisioning_requestCertificate,"
+ "Can not Create Native object");
+ return;
+ }
+ }
+
+ try
+ {
+ OCStackResult result = cloud->requestCertificate(env, jListener);
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "OcCloudProvisioning_requestCertificate");
+ return;
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ }
+ return;
+}
+
+/*
+ * Class: org_iotivity_base_OcCloudProvisioning
+ * Method: getAclIdByDevice
+ * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcCloudProvisioning/GetAclIdByDeviceListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getAclIdByDevice
+ (JNIEnv *env, jobject thiz, jstring jdeviceId, jobject jListener)
+{
+ LOGD("OcCloudProvisioning_getAclIdByDevice");
+ if (!jListener || !jdeviceId)
+ {
+ ThrowOcException(OC_STACK_INVALID_PARAM, "Listener and deviceID cannot be null");
+ return;
+ }
+
+ JniOcCloudProvisioning *cloud = JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(env, thiz);
+ if (!cloud)
+ {
+ LOGD("OcCloudProvisioning_getAclIdByDevice, No native object, creating now");
+ cloud = Create_native_object(env, thiz);
+ if (!cloud)
+ {
+ ThrowOcException(OC_STACK_ERROR, "OcCloudProvisioning_getAclIdByDevice,"
+ "Can not Create Native object");
+ return;
+ }
+ }
+
+ const char *str = env->GetStringUTFChars(jdeviceId, NULL);
+ if (!str || env->ExceptionCheck())
+ {
+ ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_getAclIdByDevice");
+ return;
+ }
+ std::string deviceId(str);
+ env->ReleaseStringUTFChars(jdeviceId, str);
+
+ try
+ {
+ OCStackResult result = cloud->getAclIdByDevice(env, deviceId, jListener);
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "OcCloudProvisioning_getAclIdByDevice");
+ return;
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ }
+ return;
+}
+
+/*
+ * Class: org_iotivity_base_OcCloudProvisioning
+ * Method: getIndividualAclInfo
+ * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcCloudProvisioning/GetIndividualAclInfoListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getIndividualAclInfo
+ (JNIEnv *env, jobject thiz, jstring jaclID, jobject jListener)
+{
+ LOGD("OcCloudProvisioning_getIndividualAclInfo");
+ if (!jListener || !jaclID)
+ {
+ ThrowOcException(OC_STACK_INVALID_PARAM, "Listener/aclID cannot be null");
+ return;
+ }
+
+ JniOcCloudProvisioning *cloud = JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(env, thiz);
+ if (!cloud)
+ {
+ LOGD("OcCloudProvisioning_getIndividualAclInfo, No native object, creating now");
+ cloud = Create_native_object(env, thiz);
+ if (!cloud)
+ {
+ ThrowOcException(OC_STACK_ERROR, "OcCloudProvisioning_getIndividualAclInfo,"
+ "Can not Create Native object");
+ return;
+ }
+ }
+
+ const char *str = env->GetStringUTFChars(jaclID, NULL);
+ std::string aclID(str);
+ env->ReleaseStringUTFChars(jaclID, str);
+
+ try
+ {
+ OCStackResult result = cloud->getIndividualAclInfo(env, jListener, aclID);
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "OcCloudProvisioning_getIndividualAclInf");
+ return;
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ }
+ return;
+}
+
+/*
+ * Class: org_iotivity_base_OcCloudProvisioning
+ * Method: getCRL
+ * Signature: (Lorg/iotivity/base/OcCloudProvisioning/GetCRLListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getCRL
+ (JNIEnv *env, jobject thiz, jobject jListener)
+{
+ LOGD("OcCloudProvisioning_getCRL");
+ if (!jListener)
+ {
+ ThrowOcException(OC_STACK_INVALID_PARAM, "Listener cannot be null");
+ return;
+ }
+
+ JniOcCloudProvisioning *cloud = JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(env, thiz);
+ if (!cloud)
+ {
+ LOGD("OcCloudProvisioning_getCRL, No native object, creating now");
+ cloud = Create_native_object(env, thiz);
+ if (!cloud)
+ {
+ ThrowOcException(OC_STACK_ERROR, "OcCloudProvisioning_getCRL,"
+ "Can not Create Native object");
+ return;
+ }
+ }
+
+ try
+ {
+ OCStackResult result = cloud->getCRL(env, jListener);
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "OcCloudProvisioning_requestCertificate");
+ return;
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ }
+ return;
+}
+
+/*
+ * Class: org_iotivity_base_OcCloudProvisioning
+ * Method: postCRL0
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/ArrayList;Lorg/iotivity/base/OcCloudProvisioning/PostCRLListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_postCRL0
+ (JNIEnv *env , jobject thiz, jstring jthisUpdate, jstring jnextUpdate, jstring jcrl,
+ jobjectArray jserialnumArray, jobject jListener)
+{
+ LOGD("OcCloudProvisioning_postCRL0");
+ if (!jListener || !jthisUpdate || !jnextUpdate || !jserialnumArray)
+ {
+ ThrowOcException(OC_STACK_INVALID_PARAM, " Invalid parameter (NULL param)");
+ return;
+ }
+
+ JniOcCloudProvisioning *cloud = JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(env, thiz);
+ if (!cloud)
+ {
+ LOGD("OcCloudProvisioning_getCRL, No native object, creating now");
+ cloud = Create_native_object(env, thiz);
+ if (!cloud)
+ {
+ ThrowOcException(OC_STACK_ERROR, "OcCloudProvisioning_PostCRL0,"
+ "Can not Create Native object");
+ return;
+ }
+ }
+
+ const char *str = env->GetStringUTFChars(jthisUpdate, NULL);
+ if (!str || env->ExceptionCheck())
+ {
+ ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_PostCRL0");
+ return;
+ }
+ std::string thisUpdate(str);
+ env->ReleaseStringUTFChars(jthisUpdate, str);
+
+ str = env->GetStringUTFChars(jnextUpdate, NULL);
+ if (!str || env->ExceptionCheck())
+ {
+ ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_PostCRL0");
+ return;
+ }
+ std::string nextUpdate(str);
+ env->ReleaseStringUTFChars(jnextUpdate, str);
+
+ OCByteString *crl = NULL;
+ if (jcrl)
+ {
+ str = env->GetStringUTFChars(jcrl, NULL);
+ if (!str || env->ExceptionCheck())
+ {
+ ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_PostCRL0");
+ return;
+ }
+ crl = (OCByteString*)OICCalloc(1, sizeof(OCByteString));
+ crl->len = (size_t)(strlen(str));
+ crl->bytes = (uint8_t*)OICCalloc(crl->len, sizeof(uint8_t));
+
+ for (size_t i = 0 ; i < crl->len; i++)
+ {
+ crl->bytes[i] = (uint8_t)str[i];
+ }
+ }
+
+ jsize len = env->GetArrayLength(jserialnumArray);
+
+ stringArray_t *serialNumArray = (stringArray_t*)OICCalloc(1, sizeof(stringArray_t));
+ serialNumArray->array = (char**)OICCalloc(len, sizeof(char*));
+ serialNumArray->length = len;
+
+ for (jsize i = 0; i < len; ++i)
+ {
+ jstring jStr = (jstring)env->GetObjectArrayElement(jserialnumArray, i);
+ if (!jStr)
+ {
+ ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_PostCRL0");
+ return;
+ }
+ serialNumArray->array[i] = (char*)env->GetStringUTFChars(jStr, nullptr);
+ if (env->ExceptionCheck())
+ {
+ ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_PostCRL0");
+ return;
+ }
+ env->DeleteLocalRef(jStr);
+ }
+
+ try
+ {
+ OCStackResult result = cloud->postCRL(env, thisUpdate, nextUpdate, crl,
+ serialNumArray, jListener);
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "OcCloudProvisioning_PostCRL0");
+ return;
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ }
+ return;
+}
--- /dev/null
+/*
+* //******************************************************************
+* //
+* // Copyright 2016 Samsung Electronics All Rights Reserved.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // Licensed under the Apache License, Version 2.0 (the "License");
+* // you may not use this file except in compliance with the License.
+* // You may obtain a copy of the License at
+* //
+* // http://www.apache.org/licenses/LICENSE-2.0
+* //
+* // Unless required by applicable law or agreed to in writing, software
+* // distributed under the License is distributed on an "AS IS" BASIS,
+* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* // See the License for the specific language governing permissions and
+* // limitations under the License.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+*/
+
+#include "JniOcStack.h"
+#include "OCCloudProvisioning.h"
+#include "JniOcCloudResultListener.h"
+#include "JniGetAclIdByDeviceListener.h"
+#include <mutex>
+
+
+using namespace OC;
+
+#ifndef _Included_org_iotivity_base_OcCloudProvisioning
+#define _Included_org_iotivity_base_OcCloudProvisioning
+class JniOcCloudProvisioning
+{
+ public:
+ JniOcCloudProvisioning(std::shared_ptr<OCCloudProvisioning> cloudObject);
+ ~JniOcCloudProvisioning();
+
+ static JniOcCloudProvisioning* getJniOcCloudProvisioningPtr(JNIEnv *env, jobject thiz);
+ JniOcCloudResultListener* AddCloudResultListener(JNIEnv* env, jobject jListener);
+ JniGetAclIdByDeviceListener* AddGetAclByDeviceListener(JNIEnv* env, jobject jListener);
+ void RemoveCloudResultListener(JNIEnv* env, jobject jListener);
+ void RemoveGetAclByDeviceIdListener(JNIEnv*, jobject);
+
+ OCStackResult requestCertificate(JNIEnv* env, jobject jListener);
+ OCStackResult getAclIdByDevice(JNIEnv*, std::string, jobject);
+ OCStackResult getIndividualAclInfo(JNIEnv*, jobject, std::string &);
+ OCStackResult getCRL(JNIEnv* env, jobject jListener);
+ OCStackResult postCRL(JNIEnv* env, const std::string& thisUpdate,
+ const std::string& nextUpdate, const OCByteString *crl,
+ const stringArray_t *serialNumbers, jobject jListener);
+
+ private:
+ std::map<jobject, std::pair<JniOcCloudResultListener*, int>> resultMap;
+ std::map<jobject, std::pair<JniGetAclIdByDeviceListener*, int>> aclresultMap;
+ std::mutex resultMapLock;
+ std::mutex aclresultMapLock;
+ std::shared_ptr<OCCloudProvisioning>m_sharedCloudObject;
+};
+
+
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: org_iotivity_base_OcCloudProvisioning
+ * Method: requestCertificate
+ * Signature: (Lorg/iotivity/base/OcCloudProvisioning/RequestCertificateListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_requestCertificate
+ (JNIEnv *, jobject, jobject);
+
+/*
+ * Class: org_iotivity_base_OcCloudProvisioning
+ * Method: getAclIdByDevice
+ * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcCloudProvisioning/GetAclIdByDeviceListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getAclIdByDevice
+ (JNIEnv *, jobject, jstring, jobject);
+
+/*
+ * Class: org_iotivity_base_OcCloudProvisioning
+ * Method: getIndividualAclInfo
+ * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcCloudProvisioning/GetIndividualAclInfoListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getIndividualAclInfo
+ (JNIEnv *, jobject, jstring, jobject);
+
+/*
+ * Class: org_iotivity_base_OcCloudProvisioning
+ * Method: getCRL
+ * Signature: (Lorg/iotivity/base/OcCloudProvisioning/GetCRLListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getCRL
+ (JNIEnv *, jobject, jobject);
+
+/*
+ * Class: org_iotivity_base_OcCloudProvisioning
+ * Method: postCRL0
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/ArrayList;Lorg/iotivity/base/OcCloudProvisioning/PostCRLListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_postCRL0
+ (JNIEnv *, jobject, jstring, jstring, jstring, jobjectArray, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
--- /dev/null
+/*
+* //******************************************************************
+* //
+* // Copyright 2016 Samsung Electronics All Rights Reserved.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // Licensed under the Apache License, Version 2.0 (the "License");
+* // you may not use this file except in compliance with the License.
+* // You may obtain a copy of the License at
+* //
+* // http://www.apache.org/licenses/LICENSE-2.0
+* //
+* // Unless required by applicable law or agreed to in writing, software
+* // distributed under the License is distributed on an "AS IS" BASIS,
+* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* // See the License for the specific language governing permissions and
+* // limitations under the License.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+*/
+#include "JniOcCloudResultListener.h"
+
+JniOcCloudResultListener::JniOcCloudResultListener(JNIEnv *env, jobject jListener,
+ RemoveCallback removeCloudResultListener)
+{
+ m_jwListener = env->NewWeakGlobalRef(jListener);
+ m_removeCloudResultListener = removeCloudResultListener;
+}
+
+JniOcCloudResultListener::~JniOcCloudResultListener()
+{
+ LOGI("~JniOcCloudResultListener()");
+ if (m_jwListener)
+ {
+ jint ret = JNI_ERR;
+ JNIEnv *env = GetJNIEnv(ret);
+ if (nullptr == env)
+ {
+ return;
+ }
+ env->DeleteWeakGlobalRef(m_jwListener);
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+ }
+}
+
+void JniOcCloudResultListener::CloudResultListenerCB(int result, void *data,
+ ListenerFunc func)
+{
+ jint ret = JNI_ERR;
+ JNIEnv *env = GetJNIEnv(ret);
+ if (nullptr == env)
+ {
+ return;
+ }
+
+ jobject jListener = env->NewLocalRef(m_jwListener);
+ if (!jListener)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+ return;
+ }
+
+ jclass clsL = env->GetObjectClass(jListener);
+
+ if (!clsL)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+ return;
+ }
+
+ std::string calledFunc;
+ switch (func)
+ {
+ case ListenerFunc::REQUEST_CERTIFICATE:
+ {
+ calledFunc = "requestCertificateListener";
+ }
+ break;
+ case ListenerFunc::GET_ACLINFO:
+ {
+ calledFunc = "getIndividualAclInfoListener";
+ }
+ break;
+ case ListenerFunc::GET_CRL:
+ {
+ calledFunc = "getCRLListener";
+ }
+ break;
+ case ListenerFunc::POST_CRL:
+ {
+ calledFunc = "postCRLListener";
+ }
+ break;
+ default:
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+ return;
+ }
+ return;
+ }
+
+ jmethodID midL = env->GetMethodID(clsL, calledFunc.c_str(), "(Z)V");
+ if (!midL)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+ return;
+ }
+
+ env->CallVoidMethod(jListener, midL, (jboolean)result);
+ if (env->ExceptionCheck())
+ {
+ LOGE("Java exception is thrown");
+ }
+
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+}
+
+void JniOcCloudResultListener::checkExAndRemoveListener(JNIEnv* env)
+{
+ if (env->ExceptionCheck())
+ {
+ jthrowable ex = env->ExceptionOccurred();
+ env->ExceptionClear();
+ m_removeCloudResultListener(env, m_jwListener);
+ env->Throw((jthrowable)ex);
+ }
+ else
+ {
+ m_removeCloudResultListener(env, m_jwListener);
+ }
+}
--- /dev/null
+/*
+* //******************************************************************
+* //
+* // Copyright 2015 Samsung Electronics All Rights Reserved.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // Licensed under the Apache License, Version 2.0 (the "License");
+* // you may not use this file except in compliance with the License.
+* // You may obtain a copy of the License at
+* //
+* // http://www.apache.org/licenses/LICENSE-2.0
+* //
+* // Unless required by applicable law or agreed to in writing, software
+* // distributed under the License is distributed on an "AS IS" BASIS,
+* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* // See the License for the specific language governing permissions and
+* // limitations under the License.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+*/
+#include <jni.h>
+#include "JniOcStack.h"
+
+#ifndef _Included_org_iotivity_base_OcCloudProvisioning_JniOcCloudResultListener
+#define _Included_org_iotivity_base_OcCloudProvisioning_JniOcCloudResultListener
+
+typedef std::function<void(JNIEnv* env, jobject jListener)> RemoveCallback;
+
+enum class ListenerFunc
+{
+ REQUEST_CERTIFICATE = 1,
+ GET_ACLINFO,
+ GET_CRL,
+ POST_CRL
+};
+
+class JniOcCloudResultListener
+{
+ public:
+ JniOcCloudResultListener(JNIEnv *env, jobject jListener,
+ RemoveCallback removeCloudResultListener);
+ ~JniOcCloudResultListener();
+
+ void CloudResultListenerCB(int result, void *data, ListenerFunc func);
+
+ private:
+ RemoveCallback m_removeCloudResultListener;
+ jweak m_jwListener;
+ void checkExAndRemoveListener(JNIEnv* env);
+};
+#endif
jclass g_cls_OcOicSecAcl_validity = nullptr;
jclass g_cls_OcOicSecPdAcl = nullptr;
jclass g_cls_OcDirectPairDevice = nullptr;
+#ifdef __WITH_TLS__
+jclass g_cls_OcCloudProvisioning = nullptr;
+#endif
#ifdef WITH_CLOUD
jclass g_cls_OcAccountManager = nullptr;
#endif
jmethodID g_mid_OcOicSecAcl_resr_get_interfaceLen = nullptr;
jmethodID g_mid_OcOicSecAcl_get_rownerID = nullptr;
+#ifdef __WITH_TLS__
+jmethodID g_mid_OcCloudProvisioning_getIP = nullptr;
+jmethodID g_mid_OcCloudProvisioning_getPort = nullptr;
+#endif
+
jobject getOcException(JNIEnv* env, const char* file, const char* functionName,
const int line, const int code, const char* message)
{
g_mid_OcOicSecPdAcl_get_recurrences = env->GetMethodID(g_cls_OcOicSecPdAcl, "getRecurrences", "(I)Ljava/lang/String;");
VERIFY_VARIABLE_NULL(g_mid_OcOicSecPdAcl_get_recurrences);
+#ifdef __WITH_TLS__
+ //OcCloudProvisioning
+ clazz = env->FindClass("org/iotivity/base/OcCloudProvisioning");
+ VERIFY_VARIABLE_NULL(clazz);
+ g_cls_OcCloudProvisioning = (jclass)env->NewGlobalRef(clazz);
+ env->DeleteLocalRef(clazz);
+ g_mid_OcCloudProvisioning_getIP = env->GetMethodID(g_cls_OcCloudProvisioning, "getIP", "()Ljava/lang/String;");
+ VERIFY_VARIABLE_NULL(g_mid_OcCloudProvisioning_getIP);
+
+ g_mid_OcCloudProvisioning_getPort = env->GetMethodID(g_cls_OcCloudProvisioning, "getPort", "()I");
+ VERIFY_VARIABLE_NULL(g_mid_OcCloudProvisioning_getPort);
+#endif
return JNI_CURRENT_VERSION;
}
#ifdef WITH_CLOUD
env->DeleteGlobalRef(g_cls_OcAccountManager);
#endif
+#ifdef WITH_CLOUD
+ env->DeleteGlobalRef(g_cls_OcCloudProvisioning);
+#endif
env->DeleteGlobalRef(g_cls_OcOicSecAcl);
env->DeleteGlobalRef(g_cls_OcOicSecAcl_ace);
env->DeleteGlobalRef(g_cls_OcOicSecAcl_resr);
#ifdef WITH_CLOUD
extern jclass g_cls_OcAccountManager;
#endif
+#ifdef __WITH_TLS__
+extern jclass g_cls_OcCloudProvisioning;
+#endif
extern jclass g_cls_OcOicSecAcl_ace;
extern jclass g_cls_OcOicSecAcl_resr;
#ifdef WITH_CLOUD
extern jmethodID g_mid_OcAccountManager_ctor;
#endif
+#ifdef __WITH_TLS__
+extern jmethodID g_mid_OcCloudProvisioning_getIP;
+extern jmethodID g_mid_OcCloudProvisioning_getPort;
+#endif
extern jmethodID g_mid_OcOicSecAcl_get_rownerID;
extern jmethodID g_mid_OcOicSecAcl_get_aces;
* @param cloudPostCRLHandler function called by the stack on completion of request.
* @throws OcException
*/
- public native void postCRL0(String thisUpdate, String nextUpdate, String crl, ArrayList<String> serialNumbers,
+ public void postCRL(String thisUpdate, String nextUpdate, String crl, ArrayList<String> serialNumbers,
+ PostCRLListener cloudPostCRLHandler) throws OcException
+ {
+ String[] serialNums = new String[serialNumbers.size()];
+ serialNums = serialNumbers.toArray(serialNums);
+ this.postCRL0(thisUpdate, nextUpdate, crl, serialNums, cloudPostCRLHandler);
+ }
+ public native void postCRL0(String thisUpdate, String nextUpdate, String crl, String[] serialNumbers,
PostCRLListener cloudPostCRLHandler) throws OcException;
}
\r
private:\r
OCDevAddr m_devAddr;\r
- std::weak_ptr<std::recursive_mutex> m_csdkLock;\r
public:\r
\r
/**\r
memset(&m_devAddr, 0, sizeof(m_devAddr));
memcpy(m_devAddr.addr, ipAddr.c_str(), MAX_ADDR_STR_SIZE);
m_devAddr.port = port;
- m_csdkLock = OCPlatform_impl::Instance().csdkLock();
}
OCCloudProvisioning::~OCCloudProvisioning(void)
}
OCStackResult result;
- auto cLock = m_csdkLock.lock();
+ auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
if (cLock)
{
}
OCStackResult result;
- auto cLock = m_csdkLock.lock();
+ auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
if (cLock)
{
}
OCStackResult result;
- auto cLock = m_csdkLock.lock();
+ auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
if (cLock)
{
}
OCStackResult result;
- auto cLock = m_csdkLock.lock();
+ auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
if (cLock)
{
}
OCStackResult result;
- auto cLock = m_csdkLock.lock();
+ auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
if (cLock)
{