[IOT-2928] Account/Tokens 71/24271/25
authorOleksii Beketov <ol.beketov@samsung.com>
Fri, 16 Mar 2018 16:37:05 +0000 (18:37 +0200)
committerOleksii Beketov <ol.beketov@samsung.com>
Fri, 16 Mar 2018 16:37:05 +0000 (18:37 +0200)
The new cloud provisioning(CR1698v24)

Change-Id: I31873dc510455bc36905a35ea4f629dfdec33fd6
Signed-off-by: Oleksandr Dmytrenko <o.dmytrenko@samsung.com>
Signed-off-by: Oleksii Beketov <ol.beketov@samsung.com>
38 files changed:
resource/csdk/include/octypes.h
resource/csdk/security/include/internal/srmresourcestrings.h
resource/csdk/security/provisioning/include/cloud/auth.h [new file with mode: 0644]
resource/csdk/security/provisioning/include/cloud/cloudresource.h [new file with mode: 0644]
resource/csdk/security/provisioning/include/cloud/occloudprovisioning.h
resource/csdk/security/provisioning/include/internal/secureresourceprovider.h
resource/csdk/security/provisioning/sample/SConscript
resource/csdk/security/provisioning/sample/cloud/cloudAuth.c [deleted file]
resource/csdk/security/provisioning/sample/cloud/cloudAuth.h [deleted file]
resource/csdk/security/provisioning/sample/cloud/cloudCommon.c
resource/csdk/security/provisioning/sample/cloud/cloudWrapper.c
resource/csdk/security/provisioning/sample/cloud/cloudWrapper.h
resource/csdk/security/provisioning/sample/provisioningclient.c
resource/csdk/security/provisioning/sample/sampleserver_justworks.cpp
resource/csdk/security/provisioning/sample/sampleserver_mfg.cpp
resource/csdk/security/provisioning/sample/sampleserver_mvjustworks.cpp
resource/csdk/security/provisioning/sample/sampleserver_preconfpin.cpp
resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp
resource/csdk/security/provisioning/src/SConscript
resource/csdk/security/provisioning/src/cloud/aclgroup.c
resource/csdk/security/provisioning/src/cloud/aclid.c
resource/csdk/security/provisioning/src/cloud/aclinvite.c
resource/csdk/security/provisioning/src/cloud/auth.c [new file with mode: 0644]
resource/csdk/security/provisioning/src/cloud/cloudresource.c [new file with mode: 0644]
resource/csdk/security/provisioning/src/cloud/config.c [new file with mode: 0644]
resource/csdk/security/provisioning/src/cloud/crl.c
resource/csdk/security/provisioning/src/cloud/csr.c
resource/csdk/security/provisioning/src/secureresourceprovider.c
resource/csdk/security/provisioning/unittest/SConscript
resource/csdk/security/provisioning/unittest/cloudresource.cpp [new file with mode: 0644]
resource/csdk/security/provisioning/unittest/otmunittest.cpp
resource/csdk/security/src/srmresourcestrings.c
resource/include/OCCloudProvisioning.hpp
resource/provisioning/examples/cloudAuth.cpp
resource/provisioning/examples/cloudAuth.h
resource/provisioning/examples/cloudClient.cpp
resource/provisioning/examples/cloudWrapper.cpp
resource/provisioning/src/OCCloudProvisioning.cpp

index 85b6458..d4e1d2c 100644 (file)
@@ -462,16 +462,16 @@ extern "C" {
 /** Cloud Account */
 
 /** Account URI.*/
-#define OC_RSRVD_ACCOUNT_URI               "/oic/account"
+#define OC_RSRVD_ACCOUNT_URI               "/oic/sec/account"
 
 /** Account user URI.*/
 #define OC_RSRVD_ACCOUNT_SEARCH_URI        "/oic/account/search"
 
 /** Account session URI.*/
-#define OC_RSRVD_ACCOUNT_SESSION_URI       "/oic/account/session"
+#define OC_RSRVD_ACCOUNT_SESSION_URI       "/oic/sec/session"
 
 /** Account token refresh URI.*/
-#define OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI "/oic/account/tokenrefresh"
+#define OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI "/oic/sec/tokenrefresh"
 
 /** ACL group URI.*/
 #define OC_RSRVD_ACL_GROUP_URI             "/oic/acl/group"
index ad30aa6..bdb463f 100644 (file)
@@ -96,6 +96,9 @@ extern const char * OIC_RSRC_TYPE_SEC_VER;
 extern const char * OIC_RSRC_VER_URI;
 extern const char * OIC_JSON_VER_NAME;
 
+//cloud conf
+extern const char * OIC_RSRC_CLOUD_CONF_URI;
+
 //reset profile
 extern const char * OIC_JSON_RESET_PF_NAME;
 extern const char * OIC_JSON_SUBJECTID_NAME;
diff --git a/resource/csdk/security/provisioning/include/cloud/auth.h b/resource/csdk/security/provisioning/include/cloud/auth.h
new file mode 100644 (file)
index 0000000..cec87ba
--- /dev/null
@@ -0,0 +1,168 @@
+/* *****************************************************************
+ *
+ * Copyright 2018 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.
+ *
+ * *****************************************************************/
+#ifndef CLOUD_AUTH_H
+#define CLOUD_AUTH_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "octhread.h"
+
+/**
+ * Cloud status/error
+ */
+typedef enum
+{
+    OC_CLOUD_OK = 0,
+    OC_CLOUD_PROV = 1,
+    OC_CLOUD_SIGNUP = 2,
+    OC_CLOUD_SIGNIN = 3,
+    OC_CLOUD_SIGNOUT = 4,
+    OC_CLOUD_TOKEN_REFRESH0 = 5,
+    OC_CLOUD_TOKEN_REFRESH1 = 6,
+    OC_CLOUD_TOKEN_REFRESH2 = 7,
+    OC_CLOUD_TOKEN_REFRESH3 = 8,
+    OC_CLOUD_TOKEN_REFRESH4 = 9,
+    /* Error codes */
+    OC_CLOUD_ERROR_SIGNOUT = 249,
+    OC_CLOUD_ERROR_SIGNIN = 250,
+    OC_CLOUD_ERROR_CREATE_SESSION = 251,
+    OC_CLOUD_ERROR_CHECK_SESSION = 252,
+    OC_CLOUD_ERROR_SIGNUP = 253,
+    OC_CLOUD_ERROR = 254,
+    OC_CLOUD_EXIT = 255
+} CloudStatus;
+
+typedef struct
+{
+    char        *authProvider;
+    char        *accessToken;
+    char        *refreshToken;
+    long        expireSin;
+    char        *uid;
+#if !defined(__MANDATORY__)
+    char        *redirectUri;
+#endif // __MANDATORY__
+} session_t;
+
+typedef struct OicCloud OicCloud_t;
+
+/**
+ * /oic/cloudconf
+ * Data used by the device to connect to the OCF Cloud.
+ */
+struct OicCloud
+{
+    char        *apn;   // Authorization Provider Name
+    char        *cis;   // OCF Cloud URL
+    char        *at;    // Access Token
+    CloudStatus stat;
+    oc_thread   pid;
+    session_t   *session;
+    OicCloud_t  *next;
+};
+
+#define OIC_JSON_CLOUDS_NAME    "clouds"
+#define OIC_JSON_CLOUD_APN      "apn"
+#define OIC_JSON_CLOUD_CIS      "cis"
+#define OIC_JSON_CLOUD_AT       "at"
+#define OIC_JSON_CLOUD_ATT      "att"
+
+/**
+ * Sends Sign UP request to cloud
+ *
+ * @param[in] cloud
+ * @return  OCStackResult application result
+ */
+OCStackResult OCCloudSignUp(OicCloud_t *cloud);
+
+/**
+ * Sends Sign IN request to cloud
+ *
+ * @param[in] cloud
+ * @return  OCStackResult application result
+ */
+OCStackResult OCCloudSignIn(OicCloud_t *cloud);
+
+/**
+ * Sends Sign OUT request to cloud
+ *
+ * @param[in] cloud
+ * @return  OCStackResult application result
+ */
+OCStackResult OCCloudSignOut(OicCloud_t *cloud);
+
+/**
+ * Session free function
+ * @param[in] cloud
+ */
+void FreeCloud(OicCloud_t *cloud);
+
+/**
+ * Cloud to CBOR
+ *
+ * @param[in] cloud
+ * @param[out] payload
+ * @param[out] size
+ * @return  OCStackResult application result
+ */
+OCStackResult CloudToCBORPayload(const OicCloud_t *clouds, uint8_t **payload, size_t *size);
+
+/**
+ * CBOR to Cloud
+ *
+ * @param[in] payload
+ * @param[out] cloud
+ * @return  OCStackResult application result
+ */
+OCStackResult CBORPayloadToCloud(const uint8_t *cborPayload, size_t size, OicCloud_t **clouds);
+
+/**
+ * The Cloud thread
+ *
+ * @param[in] data      OicCloud_t
+ * @return  NULL
+ */
+void *CloudStart(void *data);
+
+/**
+ * Cloud find
+ *
+ * @param[in] cloud list
+ * @param[in] cloud to find
+ * @return  NULL
+ */
+bool CloudFind(OicCloud_t *list, const OicCloud_t *cloud);
+
+/**
+ * Cloud status
+ *
+ * @param[in] cloud
+ * @return const char * status
+ */
+const char *GetCloudStatus(const OicCloud_t *cloud);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // CLOUD_AUTH_H
diff --git a/resource/csdk/security/provisioning/include/cloud/cloudresource.h b/resource/csdk/security/provisioning/include/cloud/cloudresource.h
new file mode 100644 (file)
index 0000000..5705f5f
--- /dev/null
@@ -0,0 +1,72 @@
+/* *****************************************************************
+ *
+ * Copyright 2018 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.
+ *
+ * *****************************************************************/
+
+#ifndef OC_CLOUD_RESOURCE_TYPES_H
+#define OC_CLOUD_RESOURCE_TYPES_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define OIC_RSRC_TYPE_SEC_CLOUDCONF             "oic.r.coapcloudconf"
+#define OIC_RSRC_CLOUDCONF_URI                  "/oic/cloudconf"
+#define OIC_JSON_CLOUDCONF_NAME                 "cloudconf"
+#define OIC_RSRC_CLOUDCONF_TOKEN_REFRESH        "/oic/sec/tokenrefresh"
+#define OC_RSRVD_ACCESS_TOKENTYPE               "tokentype"
+
+/**
+ * Perform cleanup for Cloud resources.
+ *
+ * @return ::OC_STACK_OK for Success, otherwise some error value.
+ */
+OCStackResult DeInitCloudResource();
+
+/**
+ * Initialize Cloud resource by loading data from persistent storage.
+ *
+ * @return ::OC_STACK_OK for Success, otherwise some error value.
+ */
+OCStackResult InitCloudResource();
+
+/**
+* The method is used to create '/oic/cloudconf' resource.
+*/
+OCStackResult CreateCloudResource();
+
+/**
+* Update the persistent storage
+*/
+bool UpdateCloudPersistentStorage();
+
+/**
+ * Parse GET cloudconf payload
+ *
+ * @param[in] cborPayload       payload to parse
+ * @param[in] size              payload size
+ * @param[out] cloudState       cloud state
+ * @return ::OC_STACK_OK for Success, otherwise some error value.
+ */
+OCStackResult CloudGetRequestPayloadParse(const uint8_t *cborPayload, size_t size, int *cloudState);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // OC_CLOUD_RESOURCE_TYPES_H
index 12f19d8..15e22b0 100644 (file)
@@ -21,7 +21,9 @@
 #define OC_CLOUD_PROVISIONING_H
 
 #include "octypes.h"
+#include "ocprovisioningmanager.h"
 #include "experimental/securevirtualresourcetypes.h"
+#include "auth.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -60,24 +62,24 @@ typedef struct {
  * Certificate-Issue request function
  *
  * @param[in] ctx               user-defined context
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
 OCStackResult OCCloudCertificateIssueRequest(void* ctx,
-                                             const OCDevAddr *endPoint,
+                                             const char *cloudUri,
                                              OCCloudResponseCB callback);
 
 /**
  * CRL GET request function
  *
  * @param[in] ctx               user-defined context
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
 OCStackResult OCCloudGetCRL(void* ctx,
-                            const OCDevAddr *endPoint,
+                            const char *cloudUri,
                             OCCloudResponseCB callback);
 
 /**
@@ -88,7 +90,7 @@ OCStackResult OCCloudGetCRL(void* ctx,
  * @param[in] nextUpdate        mandatory parameter nextUpdate
  * @param[in] crl               optional parameter crl
  * @param[in] serialNumbers     optional parameter serial numbers
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
@@ -97,7 +99,7 @@ OCStackResult OCCloudPostCRL(void* ctx,
                              const char *nextUpdate,
                              const OCByteString *crl,
                              const stringArray_t *serialNumbers,
-                             const OCDevAddr *endPoint,
+                             const char *cloudUri,
                              OCCloudResponseCB callback);
 
 /**
@@ -105,13 +107,13 @@ OCStackResult OCCloudPostCRL(void* ctx,
  *
  * @param[in] ctx               user-defined context
  * @param[in] deviceId          mandatory parameter device id
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
 OCStackResult OCCloudGetAclIdByDevice(void* ctx,
                                       const char *deviceId,
-                                      const OCDevAddr *endPoint,
+                                      const char *cloudUri,
                                       OCCloudResponseCB callback);
 
 /**
@@ -120,14 +122,14 @@ OCStackResult OCCloudGetAclIdByDevice(void* ctx,
  * @param[in] ctx               user-defined context
  * @param[in] ownerId           mandatory parameter owner id
  * @param[in] deviceId          mandatory parameter device id
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
 OCStackResult OCCloudAclIdCreate(void* ctx,
                                  const char *ownerId,
                                  const char *deviceId,
-                                 const OCDevAddr *endPoint,
+                                 const char *cloudUri,
                                  OCCloudResponseCB callback);
 
 /**
@@ -135,13 +137,13 @@ OCStackResult OCCloudAclIdCreate(void* ctx,
  *
  * @param[in] ctx               user-defined context
  * @param[in] aclId             mandatory parameter acl id
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
 OCStackResult OCCloudAclIdDelete(void* ctx,
                                  const char *aclId,
-                                 const OCDevAddr *endPoint,
+                                 const char *cloudUri,
                                  OCCloudResponseCB callback);
 
 /**
@@ -149,13 +151,13 @@ OCStackResult OCCloudAclIdDelete(void* ctx,
  *
  * @param[in] ctx               user-defined context
  * @param[in] aclId             mandatory parameter acl id
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
 OCStackResult OCCloudAclIndividualGetInfo(void* ctx,
                                           const char *aclId,
-                                          const OCDevAddr *endPoint,
+                                          const char *cloudUri,
                                           OCCloudResponseCB callback);
 
 /**
@@ -164,14 +166,14 @@ OCStackResult OCCloudAclIndividualGetInfo(void* ctx,
  * @param[in] ctx               user-defined context
  * @param[in] aclId             mandatory parameter acl id
  * @param[in] aces              mandatory parameter aces
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
 OCStackResult OCCloudAclIndividualAclUpdate(void* ctx,
                                             const char *aclId,
                                             const cloudAce_t *aces,
-                                            const OCDevAddr *endPoint,
+                                            const char *cloudUri,
                                             OCCloudResponseCB callback);
 
 /**
@@ -181,7 +183,7 @@ OCStackResult OCCloudAclIndividualAclUpdate(void* ctx,
  * @param[in] aclId             mandatory parameter acl id
  * @param[in] aceId             mandatory parameter target ace id
  * @param[in] aces              mandatory parameter aces
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
@@ -189,7 +191,7 @@ OCStackResult OCCloudAclIndividualAceUpdate(void* ctx,
                                             const char *aclId,
                                             const char *aceId,
                                             const cloudAce_t *aces,
-                                            const OCDevAddr *endPoint,
+                                            const char *cloudUri,
                                             OCCloudResponseCB callback);
 
 /**
@@ -197,13 +199,13 @@ OCStackResult OCCloudAclIndividualAceUpdate(void* ctx,
  *
  * @param[in] ctx               user-defined context
  * @param[in] aclId             mandatory parameter acl id
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
 OCStackResult OCCloudAclAcesDelete(void* ctx,
                                          const char *aclId,
-                                         const OCDevAddr *endPoint,
+                                         const char *cloudUri,
                                          OCCloudResponseCB callback);
 
 /**
@@ -212,14 +214,14 @@ OCStackResult OCCloudAclAcesDelete(void* ctx,
  * @param[in] ctx               user-defined context
  * @param[in] aclId             mandatory parameter acl id
  * @param[in] aceId             target ace id
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
 OCStackResult OCCloudAclIndividualAceDelete(void* ctx,
                                          const char *aclId,
                                          const char *aceId,
-                                         const OCDevAddr *endPoint,
+                                         const char *cloudUri,
                                          OCCloudResponseCB callback);
 
 /**
@@ -228,14 +230,14 @@ OCStackResult OCCloudAclIndividualAceDelete(void* ctx,
  * @param[in] ctx               user-defined context
  * @param[in] groupType         mandatory parameter group type
  * @param[in] groupMasterId     optional parameter group master id
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
 OCStackResult OCCloudAclCreateGroup(void* ctx,
                                     const char *groupType,
                                     const char *groupMasterId,
-                                    const OCDevAddr *endPoint,
+                                    const char *cloudUri,
                                     OCCloudResponseCB callback);
 
 /**
@@ -243,13 +245,13 @@ OCStackResult OCCloudAclCreateGroup(void* ctx,
  *
  * @param[in] ctx               user-defined context
  * @param[in] memberId          member id
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
 OCStackResult OCCloudAclFindMyGroup(void* ctx,
                                     const char *memberId,
-                                    const OCDevAddr *endPoint,
+                                    const char *cloudUri,
                                     OCCloudResponseCB callback);
 
 /**
@@ -258,14 +260,14 @@ OCStackResult OCCloudAclFindMyGroup(void* ctx,
  * @param[in] ctx               user-defined context
  * @param[in] groupId           mandatory parameter group id
  * @param[in] groupMasterId     optional parameter group master id
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
 OCStackResult OCCloudAclDeleteGroup(void* ctx,
                                     const char *groupId,
                                     const char *groupMasterId,
-                                    const OCDevAddr *endPoint,
+                                    const char *cloudUri,
                                     OCCloudResponseCB callback);
 
 /**
@@ -273,13 +275,13 @@ OCStackResult OCCloudAclDeleteGroup(void* ctx,
  *
  * @param[in] ctx               user-defined context
  * @param[in] groupId           mandatory parameter group id
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
 OCStackResult OCCloudAclJoinToInvitedGroup(void* ctx,
                                            const char *groupId,
-                                           const OCDevAddr *endPoint,
+                                           const char *cloudUri,
                                            OCCloudResponseCB callback);
 
 /**
@@ -287,13 +289,13 @@ OCStackResult OCCloudAclJoinToInvitedGroup(void* ctx,
  *
  * @param[in] ctx               user-defined context
  * @param[in] groupId           mandatory parameter group id
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
 OCStackResult OCCloudAclObserveGroup(void* ctx,
                                      const char *groupId,
-                                     const OCDevAddr *endPoint,
+                                     const char *cloudUri,
                                      OCCloudResponseCB callback);
 
 /**
@@ -303,7 +305,7 @@ OCStackResult OCCloudAclObserveGroup(void* ctx,
  * @param[in] groupId           mandatory parameter group id
  * @param[in] memberIds         mandatory parameter members list
  * @param[in] deviceIds         mandatory parameter devices list
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
@@ -311,7 +313,7 @@ OCStackResult OCCloudAclShareDeviceIntoGroup(void* ctx,
                                              const char *groupId,
                                              const stringArray_t *memberIds,
                                              const stringArray_t *deviceIds,
-                                             const OCDevAddr *endPoint,
+                                             const char *cloudUri,
                                              OCCloudResponseCB callback);
 
 /**
@@ -321,7 +323,7 @@ OCStackResult OCCloudAclShareDeviceIntoGroup(void* ctx,
  * @param[in] groupId           mandatory parameter group id
  * @param[in] memberIds         mandatory parameter members list
  * @param[in] deviceIds         mandatory parameter devices list
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
@@ -329,7 +331,7 @@ OCStackResult OCCloudAclDeleteDeviceFromGroup(void* ctx,
                                               const char *groupId,
                                               const stringArray_t *memberIds,
                                               const stringArray_t *deviceIds,
-                                              const OCDevAddr *endPoint,
+                                              const char *cloudUri,
                                               OCCloudResponseCB callback);
 
 /**
@@ -338,14 +340,14 @@ OCStackResult OCCloudAclDeleteDeviceFromGroup(void* ctx,
  * @param[in] ctx               user-defined context
  * @param[in] groupId           mandatory parameter group id
  * @param[in] memberId          optional parameter member id
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
 OCStackResult OCCloudAclGroupGetInfo(void* ctx,
                                      const char *groupId,
                                      const char *memberId,
-                                     const OCDevAddr *endPoint,
+                                     const char *cloudUri,
                                      OCCloudResponseCB callback);
 
 /**
@@ -355,7 +357,7 @@ OCStackResult OCCloudAclGroupGetInfo(void* ctx,
  * @param[in] userId            optional parameter user id
  * @param[in] groupIds          mandatory parameter groups list
  * @param[in] memberIds         mandatory parameter members list
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
@@ -363,7 +365,7 @@ OCStackResult OCCloudAclInviteUser(void* ctx,
                                    const char *userId,
                                    const stringArray_t *groupIds,
                                    const stringArray_t *memberIds,
-                                   const OCDevAddr *endPoint,
+                                   const char *cloudUri,
                                    OCCloudResponseCB callback);
 
 /**
@@ -371,13 +373,13 @@ OCStackResult OCCloudAclInviteUser(void* ctx,
  *
  * @param[in] ctx               user-defined context
  * @param[in] userId            optional parameter user id
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
 OCStackResult OCCloudAclGetInvitation(void* ctx,
                                       const char *userId,
-                                      const OCDevAddr *endPoint,
+                                      const char *cloudUri,
                                       OCCloudResponseCB callback);
 
 /**
@@ -386,14 +388,14 @@ OCStackResult OCCloudAclGetInvitation(void* ctx,
  * @param[in] ctx               user-defined context
  * @param[in] userId            optional parameter user id
  * @param[in] groupId           mandatory parameter group id
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
 OCStackResult OCCloudAclDeleteInvitation(void* ctx,
                                          const char *userId,
                                          const char *groupId,
-                                         const OCDevAddr *endPoint,
+                                         const char *cloudUri,
                                          OCCloudResponseCB callback);
 
 /**
@@ -403,7 +405,7 @@ OCStackResult OCCloudAclDeleteInvitation(void* ctx,
  * @param[in] userId            optional parameter user id
  * @param[in] groupId           mandatory parameter group id
  * @param[in] memberId          mandatory parameter member id
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
@@ -411,7 +413,7 @@ OCStackResult OCCloudAclCancelInvitation(void* ctx,
                                          const char *userId,
                                          const char *groupId,
                                          const char *memberId,
-                                         const OCDevAddr *endPoint,
+                                         const char *cloudUri,
                                          OCCloudResponseCB callback);
 
 /**
@@ -422,7 +424,7 @@ OCStackResult OCCloudAclCancelInvitation(void* ctx,
  * @param[in] deviceId          mandatory parameter device id
  * @param[in] method            mandatory parameter method
  * @param[in] uri               mandatory parameter uri
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          optional result callback, can be NULL if not required
  * @return  OCStackResult application result
  */
@@ -431,9 +433,23 @@ OCStackResult OCCloudAclPolicyCheck(void* ctx,
                                     const char *deviceId,
                                     const char *method,
                                     const char *uri,
-                                    const OCDevAddr *endPoint,
+                                    const char *cloudUri,
                                     OCCloudResponseCB callback);
 
+/**
+ * Provision cloud configuration
+ *
+ * @param[in] ctx               user-defined context
+ * @param[in] pDev              provision device
+ * @param[in] cloud             provisioned parameters
+ * @param[in] resultCallback    optional result callback, can be NULL if not required
+ * @return  OCStackResult application result
+ */
+OCStackResult OCProvisionCloudConfig(void *ctx,
+                                     const OCProvisionDev_t *pDev,
+                                     const OicCloud_t *cloud,
+                                     OCClientResponseHandler resultCallback);
+
 #ifdef __cplusplus
 }
 #endif // __cplusplus
index 94fc9a5..f5cdea3 100644 (file)
@@ -25,6 +25,7 @@
 #include "experimental/securevirtualresourcetypes.h"
 #include "pmtypes.h"
 #include "octypes.h"
+#include "occloudprovisioning.h"
 
 // Enum type index for data types.
 typedef enum
@@ -45,6 +46,7 @@ typedef struct Data
     DataType_t type;                             /**< Data type of the context.**/
 } Data_t;
 
+#define DEFAULT_URI_LENGTH (MAX_URI_LENGTH + MAX_QUERY_LENGTH)
 
 #ifdef __cplusplus
 extern "C"
@@ -376,6 +378,24 @@ OCStackResult SRPProvisionCertificate(void *ctx, const OCProvisionDev_t *pDev,
 OCStackResult SetDOS(const Data_t *data, OicSecDeviceOnboardingState_t dos,
                             OCClientResponseHandler resultCallback);
 
+/**
+ * Callback handler for handling callback of posting DOS_RFNOP.
+ *
+ * @param[in] ctx             ctx value passed to callback from calling function.
+ * @param[in] UNUSED          handle to an invocation
+ * @param[in] clientResponse  Response from queries to remote servers.
+ * @return  OC_STACK_DELETE_TRANSACTION to delete the transaction
+ *          and  OC_STACK_KEEP_TRANSACTION to keep it.
+ */
+OCStackApplicationResult SetReadyForNormalOperationCB(void *ctx, OCDoHandle handler,
+        OCClientResponse *clientResponse);
+
+/**
+ * Restores pstat after provisioning.
+ */
+OCStackApplicationResult ProvisionCB(void *ctx, OCDoHandle handle,
+        OCClientResponse *clientResponse);
+
 void FreeData(Data_t *data);
 
 #ifdef __cplusplus
index 22a6d99..f29a7af 100644 (file)
@@ -31,7 +31,8 @@ target_os = provisioning_sample_env.get('TARGET_OS')
 provisioning_sample_env.AppendUnique(CPPPATH=[
     '#/resource/csdk/include',
     '#/extlibs/base64',
-    '#/resource/csdk/security/provisioning/sample/cloud'
+    '#/resource/csdk/security/provisioning/sample/cloud',
+    '#resource/csdk/security/provisioning/include/cloud'
 ])
 
 target_os = env.get('TARGET_OS')
@@ -106,7 +107,6 @@ if provisioning_sample_env.get('MULTIPLE_OWNER') == '1':
 if target_os not in ['msys_nt', 'windows']:
     if provisioning_sample_env.get('WITH_TCP') == True and provisioning_sample_env.get('WITH_CLOUD') == True:
         cloud_src = [
-            'cloud/cloudAuth.c',
             'cloud/cloudCommon.c',
             'cloud/cloudWrapper.c',
             'cloud/cloudDiscovery.c'
diff --git a/resource/csdk/security/provisioning/sample/cloud/cloudAuth.c b/resource/csdk/security/provisioning/sample/cloud/cloudAuth.c
deleted file mode 100644 (file)
index 77deed2..0000000
+++ /dev/null
@@ -1,317 +0,0 @@
-/* *****************************************************************
- *
- * 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 "octypes.h"
-#include "experimental/logger.h"
-#include "experimental/payload_logging.h"
-#include "ocstack.h"
-#include "ocpayload.h"
-#include "psinterface.h"
-#include "experimental/securevirtualresourcetypes.h"
-#include "experimental/doxmresource.h"
-#include "oic_malloc.h"
-#include "oic_string.h"
-#include "pmutility.h"
-#include "credresource.h"
-#include "experimental/payload_logging.h"
-#include "cacommonutil.h"
-
-#include "utils.h"
-#include "cloudAuth.h"
-#include "cloudCommon.h"
-
-#define TAG "cloudAuth"
-
-#define LOGIN_OK 4
-
-#define MAX_URI_QUERY MAX_URI_LENGTH + MAX_QUERY_LENGTH
-
-typedef struct
-{
-    char *accesstoken;
-    char *refreshtoken;
-    char *tokentype;
-    int64_t  expiresin;
-    char *uid;
-    char *redirecturi;
-    char *certificate;
-    char *sid;
-} sessionObject_t;
-
-static sessionObject_t sessionObject = {NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL};
-
-/**
- * Session free function
- *
- * @return  OCStackResult application result
- */
-static void SessionFree(void)
-{
-    OICFree(sessionObject.accesstoken);
-    OICFree(sessionObject.refreshtoken);
-    OICFree(sessionObject.tokentype);
-    OICFree(sessionObject.uid);
-    OICFree(sessionObject.redirecturi);
-    OICFree(sessionObject.certificate);
-    OICFree(sessionObject.sid);
-
-    memset(&sessionObject, 0, sizeof(sessionObject_t));
-}
-
-/**
- * Session parse payload
- *
- * @param[in] payload
- * @param[in] sessionObject session data
- * @return  OCStackResult application result
- */
-static OCStackResult SessionParsePayload(OCRepPayload *payload)
-{
-    VERIFY_NON_NULL_RET(payload, TAG, "NULL payload", OC_STACK_ERROR);
-
-    SessionFree();
-
-    if (!OCRepPayloadGetPropString(payload, OC_RSRVD_ACCESS_TOKEN,
-                                   &sessionObject.accesstoken))
-    {
-        OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_ACCESS_TOKEN);
-    }
-    if (!OCRepPayloadGetPropString(payload, OC_RSRVD_REFRESH_TOKEN,
-                                   &sessionObject.refreshtoken))
-    {
-        OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_REFRESH_TOKEN);
-    }
-    if (!OCRepPayloadGetPropString(payload, OC_RSRVD_TOKEN_TYPE,
-                                   &sessionObject.tokentype))
-    {
-        OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_TOKEN_TYPE);
-    }
-    if (!OCRepPayloadGetPropInt(payload, OC_RSRVD_EXPIRES_IN, &(sessionObject.expiresin)))
-    {
-        OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_EXPIRES_IN);
-    }
-    if (!OCRepPayloadGetPropString(payload, OC_RSRVD_USER_UUID,
-                                   &sessionObject.uid))
-    {
-        OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_USER_UUID);
-    }
-    if (!OCRepPayloadGetPropString(payload, OC_RSRVD_REDIRECT_URI,
-                                   &sessionObject.redirecturi))
-    {
-        OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_REDIRECT_URI);
-    }
-    if (!OCRepPayloadGetPropString(payload, OC_RSRVD_CERTIFICATE,
-                                   &sessionObject.certificate))
-    {
-        OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_CERTIFICATE);
-    }
-    if (!OCRepPayloadGetPropString(payload, OC_RSRVD_SUBJECT_ID,
-                                   &sessionObject.sid))
-    {
-        OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_SUBJECT_ID);
-    }
-
-    return OC_STACK_OK;
-}
-
-/**
- * Sends Sign Up request to cloud
- *
- * @param[in] ctx                    context
- * @param[in] handle                 handle
- * @param[in] response               response from peer
- * @return  OCStackApplicationResult application result
- */
-static OCStackApplicationResult handleCloudSignUpResponse(void *ctx,
-                                                          OCDoHandle handle,
-                                                          OCClientResponse *response)
-{
-    OC_UNUSED(ctx);
-    OC_UNUSED(handle);
-
-    VERIFY_NON_NULL_RET(response, TAG, "Received NULL response", OC_STACK_DELETE_TRANSACTION);
-
-    if (response->payload)
-    {
-        OIC_LOG(INFO, TAG, "Payload received");
-        OIC_LOG_PAYLOAD(DEBUG, response->payload);
-    }
-
-    if (response->result != LOGIN_OK)
-    {
-        OIC_LOG_V(ERROR, TAG, "Login error: %d",response->result);
-    }
-    else
-    {
-        SessionParsePayload((OCRepPayload*)response->payload);
-        OIC_LOG(INFO, TAG, "Sign Up OK");
-    }
-
-    return OC_STACK_DELETE_TRANSACTION;
-}
-
-OCStackResult CloudSignUp(const OCDevAddr *endPoint,
-                          const char *authProvider,
-                          const char *authToken)
-{
-    char uri[MAX_URI_LENGTH] = { 0 };
-
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endPoint", OC_STACK_INVALID_PARAM);
-    VERIFY_NON_NULL_RET(authProvider, TAG, "NULL endPoint", OC_STACK_INVALID_PARAM);
-    VERIFY_NON_NULL_RET(authToken, TAG, "NULL endPoint", OC_STACK_INVALID_PARAM);
-
-    char *deviceId = getDeviceId();
-    VERIFY_NON_NULL_RET(deviceId, TAG, "Can't get the device id", OC_STACK_ERROR);
-
-    snprintf(uri, MAX_URI_LENGTH, DEFAULT_QUERY,
-             endPoint->addr, endPoint->port, OC_RSRVD_ACCOUNT_URI);
-
-    OCCallbackData cbData;
-    memset(&cbData, 0, sizeof(OCCallbackData));
-    cbData.cb = handleCloudSignUpResponse;
-    cbData.cd = unlockMenu;
-
-    OCRepPayload *payload = OCRepPayloadCreate();
-    VERIFY_NON_NULL_RET(payload, TAG, "Failed to allocate payload", OC_STACK_NO_MEMORY);
-
-    OCRepPayloadSetPropString(payload, OC_RSRVD_DEVICE_ID, deviceId);
-    OCRepPayloadSetPropString(payload, OC_RSRVD_AUTHPROVIDER, authProvider);
-    OCRepPayloadSetPropString(payload, OC_RSRVD_AUTHCODE, authToken);
-
-    return OCDoResource(NULL, OC_REST_POST, uri, NULL, (OCPayload *)payload,
-                        CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
-}
-
-/**
- * Sends Sign In request to cloud
- *
- * @param[in] ctx                    context
- * @param[in] handle                 handle
- * @param[in] response               response from peer
- * @return  OCStackApplicationResult application result
- */
-static OCStackApplicationResult handleCloudSignInResponse(void *ctx,
-                                                          OCDoHandle handle,
-                                                          OCClientResponse *response)
-{
-    OC_UNUSED(ctx);
-    OC_UNUSED(handle);
-
-    VERIFY_NON_NULL_RET(response, TAG, "Received NULL response", OC_STACK_DELETE_TRANSACTION);
-
-    if (response->payload)
-    {
-        OIC_LOG(INFO, TAG, "Payload received");
-        OIC_LOG_PAYLOAD(DEBUG, response->payload);
-    }
-
-    if (response->result != LOGIN_OK)
-    {
-        OIC_LOG_V(ERROR, TAG, "Sign In error: result: %d", response->result);
-        return OC_STACK_DELETE_TRANSACTION;
-    }
-
-    sessionObject.expiresin = 0;
-    if (!OCRepPayloadGetPropInt((OCRepPayload*)response->payload, OC_RSRVD_EXPIRES_IN, &(sessionObject.expiresin)))
-    {
-        OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_EXPIRES_IN);
-    }
-
-    OIC_LOG(INFO, TAG, "Sign In OK");
-
-    return OC_STACK_DELETE_TRANSACTION;
-}
-
-static OCStackApplicationResult handleCloudSignOutResponse(void *ctx,
-                                                           OCDoHandle handle,
-                                                           OCClientResponse *response)
-{
-    OC_UNUSED(ctx);
-    OC_UNUSED(handle);
-
-    VERIFY_NON_NULL_RET(response, TAG, "Received NULL response", OC_STACK_DELETE_TRANSACTION);
-
-    if (response->payload)
-    {
-        OIC_LOG(INFO, TAG, "Payload received");
-        OIC_LOG_PAYLOAD(DEBUG, response->payload);
-    }
-
-    if (response->result != LOGIN_OK)
-    {
-        OIC_LOG(ERROR, TAG, "Sign Out error");
-        return OC_STACK_DELETE_TRANSACTION;
-    }
-
-    OIC_LOG(INFO, TAG, "Sign Out OK");
-
-    return OC_STACK_DELETE_TRANSACTION;
-}
-
-/**
- * Sends Sign In/Out request to cloud
- *
- * @param[in] endPoint               peer endPoint
- * @param[in] signIn                 is it Sign In or Sign Out request
- * @return  OCStackApplicationResult application result
- */
-static OCStackResult CloudSign(const OCDevAddr *endPoint, bool signIn)
-{
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endPoint", OC_STACK_INVALID_PARAM);
-    VERIFY_NON_NULL_RET(sessionObject.uid, TAG,
-                        "UID is missing. Please run Sign Up first", OC_STACK_ERROR);
-    VERIFY_NON_NULL_RET(sessionObject.accesstoken, TAG,
-                        "accesstoken is missing. Please run Sign Up first", OC_STACK_ERROR);
-
-    char *deviceId = getDeviceId();
-    VERIFY_NON_NULL_RET(deviceId, TAG, "Can't get the device id", OC_STACK_ERROR);
-
-    OCRepPayload* payload = OCRepPayloadCreate();
-    VERIFY_NON_NULL_RET(payload, TAG, "Failed to allocate payload", OC_STACK_NO_MEMORY);
-
-    OCRepPayloadSetPropString(payload, OC_RSRVD_USER_UUID, sessionObject.uid);
-    OCRepPayloadSetPropString(payload, OC_RSRVD_DEVICE_ID, deviceId);
-    OCRepPayloadSetPropString(payload, OC_RSRVD_ACCESS_TOKEN, sessionObject.accesstoken);
-    OCRepPayloadSetPropBool(payload, OC_RSRVD_LOGIN, signIn);
-
-    char uri[MAX_URI_QUERY] = { 0 };
-    snprintf(uri, MAX_URI_QUERY, DEFAULT_QUERY,
-             endPoint->addr, endPoint->port,
-             OC_RSRVD_ACCOUNT_SESSION_URI);
-
-    OCCallbackData cbData;
-    memset(&cbData, 0, sizeof(OCCallbackData));
-    cbData.cb = signIn? handleCloudSignInResponse : handleCloudSignOutResponse;
-    cbData.cd = unlockMenu;
-
-    return OCDoResource(NULL, OC_REST_POST, uri, NULL, (OCPayload *)payload,
-                        CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
-}
-
-OCStackResult CloudSignIn(const OCDevAddr *endPoint)
-{
-    return CloudSign(endPoint, true);
-}
-
-OCStackResult CloudSignOut(const OCDevAddr *endPoint)
-{
-    return CloudSign(endPoint, false);
-}
-
diff --git a/resource/csdk/security/provisioning/sample/cloud/cloudAuth.h b/resource/csdk/security/provisioning/sample/cloud/cloudAuth.h
deleted file mode 100644 (file)
index cc84050..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/* *****************************************************************
- *
- * 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.
- *
- * *****************************************************************/
-#ifndef CLOUD_AUTH_H
-#define CLOUD_AUTH_H
-
-/**
- * Sends Sign UP request to cloud
- *
- * @param[in] endPoint         peer endpoint
- * @param[in] authProvider     authentication provider
- * @param[in] authToken        authentication token
- * @param[in] response         response callback
- * @return  OCStackResult application result
- */
-OCStackResult CloudSignUp(const OCDevAddr  *endPoint,
-                          const char *authProvider,
-                          const char *authToken);
-
-/**
- * Sends Sign IN request to cloud
- *
- * @param[in] endPoint         peer endpoint
- * @param[in] response         response callback
- * @return  OCStackResult application result
- */
-OCStackResult CloudSignIn(const OCDevAddr  *endPoint);
-
-/**
- * Sends Sign OUT request to cloud
- *
- * @param[in] endPoint         peer endpoint
- * @param[in] response         response callback
- * @return  OCStackResult application result
- */
-OCStackResult CloudSignOut(const OCDevAddr  *endPoint);
-
-#endif // CLOUD_AUTH_H
index bc10f49..8da1aac 100644 (file)
@@ -36,7 +36,7 @@
 #include "mbedtls/ssl_ciphersuites.h"
 
 #include "utils.h"
-#include "cloudAuth.h"
+#include "cloud/auth.h"
 #include "cloudCommon.h"
 #include "cloudWrapper.h"
 #include "cloudDiscovery.h"
@@ -64,9 +64,6 @@
 static bool fExit = false;
 
 static oc_thread g_requestsThread = NULL;
-static OCDevAddr endPoint;
-static char token[1024] = "";
-static char authProvider[1024] = DEFAULT_AUTH_PROVIDER;
 static char *fname = DEFAULT_DB_FILE;
 static uint64_t timeout;
 static uint16_t g_credId = 0;
@@ -422,13 +419,40 @@ static void *userRequests(void *data)
 
     OCMode mode = *(OCMode*)data;
 
-    memset(&endPoint, 0, sizeof(endPoint));
-    strncpy(endPoint.addr, DEFAULT_HOST, sizeof(endPoint.addr));
-    endPoint.port = DEFAULT_PORT;
-
     mutex = oc_mutex_new();
     cond = oc_cond_new();
 
+    OicCloud_t *cloud = (OicCloud_t *)OICCalloc(1,sizeof(OicCloud_t));
+    if (NULL == cloud)
+    {
+        OIC_LOG(ERROR, TAG, "cloud calloc failed");
+        return NULL;
+    }
+    cloud->cis = (char *)OICCalloc(1,1024 * 4);
+    if (NULL == cloud)
+    {
+        OIC_LOG(ERROR, TAG, "cloud->cis calloc failed");
+        OICFree(cloud);
+        return NULL;
+    }
+    cloud->apn = (char *)OICCalloc(1,512);
+    if (NULL == cloud->apn)
+    {
+        OIC_LOG(ERROR, TAG, "cloud->apn calloc failed");
+        OICFree(cloud->cis);
+        OICFree(cloud);
+        return NULL;
+    }
+    cloud->at = (char *)OICCalloc(1,1024);
+    if (NULL == cloud->at)
+    {
+        OIC_LOG(ERROR, TAG, "cloud->at calloc failed");
+        OICFree(cloud->apn);
+        OICFree(cloud->cis);
+        OICFree(cloud);
+        return NULL;
+    }
+
     while (false == fExit)
     {
         OCStackResult res = OC_STACK_ERROR;
@@ -436,10 +460,8 @@ static void *userRequests(void *data)
         timeout = DEFAULT_RESPONSE_WAIT_TIME;
         //startup report
         printf("-----------------------------------------------------------\n");
-        printf("Connecting to: %s:%d\n", endPoint.addr, endPoint.port);
-        printf("via auth provider: %s\n", authProvider);
+        printf("Connecting to: %s\n", cloud->cis);
         printf("srv file: %s\n", fname);
-        printf("CoAP prefix: %s\n", DEFAULT_PREFIX);
         printf("-----------------------------------------------------------\n");
 
         printMenu(mode);
@@ -450,106 +472,96 @@ static void *userRequests(void *data)
         switch (request)
         {
         case SIGN_UP:
-            if (0 == strncmp(authProvider, DEFAULT_AUTH_PROVIDER, sizeof(authProvider)))
+            if (0 == strcmp(cloud->at, DEFAULT_AUTH_PROVIDER))
             {
                 printf("Paste to browser %s and get auth code\n", GITHUB_AUTH_LINK);
             }
-            readString(token, sizeof(token), "auth token", "check link above");
-            res = CloudSignUp(&endPoint, authProvider, token);
+            readString(cloud->at, 1024, "auth token", "check link above");
+            res = OCCloudSignUp(cloud);
             break;
         case SIGN_IN:
-            res = CloudSignIn(&endPoint);
+            res = OCCloudSignIn(cloud);
             break;
         case SIGN_OUT:
-            res = CloudSignOut(&endPoint);
+            res = OCCloudSignOut(cloud);
             break;
         case HOST:
-            readString(endPoint.addr, sizeof(endPoint.addr), "host ip address", DEFAULT_HOST);
+            readString(cloud->cis, 1024 * 4, "cloud uri(coaps+tcp://ip:port)", DEFAULT_HOST);
             sendDataToServer = false;
             break;
-        case PORT:
-        {
-            char example[8];
-            snprintf(example, sizeof(example), "%d", DEFAULT_PORT);
-            uint16_t tmp = 0;
-            readUInt16(&tmp, "port number", example);
-            endPoint.port = tmp;
-            sendDataToServer = false;
-        }
-        break;
         case CRL_GET:
-            res = OCWrapperGetCRL(&endPoint, handleGetCrlCB);
+            res = OCWrapperGetCRL(cloud->cis, handleGetCrlCB);
             break;
         case CRL_POST:
-            res = OCWrapperPostCRL(&endPoint, handleCB);
+            res = OCWrapperPostCRL(cloud->cis, handleCB);
             break;
 #ifndef DISABLE_50_83_REQUESTS_FOR_1_3_REL
         case ACL_GROUP_CREATE:
-            res = OCWrapperAclCreateGroup(&endPoint, handleAclCreateGroupCB);
+            res = OCWrapperAclCreateGroup(cloud->cis, handleAclCreateGroupCB);
             break;
         case ACL_GROUP_FIND:
-            res = OCWrapperAclFindMyGroup(&endPoint, handleAclFindMyGroupCB);
+            res = OCWrapperAclFindMyGroup(cloud->cis, handleAclFindMyGroupCB);
             break;
         case ACL_GROUP_DELETE:
-            res = OCWrapperAclDeleteGroup(&endPoint, handleCB);
+            res = OCWrapperAclDeleteGroup(cloud->cis, handleCB);
             break;
         case ACL_GROUP_JOIN:
-            res = OCWrapperAclJoinToInvitedGroup(&endPoint, handleCB);
+            res = OCWrapperAclJoinToInvitedGroup(cloud->cis, handleCB);
             break;
         case ACL_GROUP_OBSERVE:
-            res = OCWrapperAclObserveGroup(&endPoint, handleCB);
+            res = OCWrapperAclObserveGroup(cloud->cis, handleCB);
             break;
         case ACL_GROUP_SHARE_DEVICE:
-            res = OCWrapperAclShareDeviceIntoGroup(&endPoint, handleCB);
+            res = OCWrapperAclShareDeviceIntoGroup(cloud->cis, handleCB);
             break;
         case ACL_GROUP_DELETE_DEVICE:
-            res = OCWrapperAclDeleteDeviceFromGroup(&endPoint, handleCB);
+            res = OCWrapperAclDeleteDeviceFromGroup(cloud->cis, handleCB);
             break;
         case ACL_GROUP_GET_INFO:
-            res = OCWrapperAclGroupGetInfo(&endPoint, handleCB);
+            res = OCWrapperAclGroupGetInfo(cloud->cis, handleCB);
             break;
         case ACL_GROUP_INVITE_USER:
-            res = OCWrapperAclInviteUser(&endPoint, handleCB);
+            res = OCWrapperAclInviteUser(cloud->cis, handleCB);
             break;
         case ACL_GROUP_GET_INVITE:
-            res = OCWrapperAclGetInvitation(&endPoint, handleAclGetInvitationCB);
+            res = OCWrapperAclGetInvitation(cloud->cis, handleAclGetInvitationCB);
             break;
         case ACL_GROUP_DELETE_INVITE:
-            res = OCWrapperAclDeleteInvitation(&endPoint, handleCB);
+            res = OCWrapperAclDeleteInvitation(cloud->cis, handleCB);
             break;
         case ACL_GROUP_CANCEL_INVITE:
-            res = OCWrapperAclCancelInvitation(&endPoint, handleCB);
+            res = OCWrapperAclCancelInvitation(cloud->cis, handleCB);
             break;
         case ACL_POLICY_CHECK_REQUEST:
-            res = OCWrapperAclPolicyCheck(&endPoint, handleAclPolicyCheckCB);
+            res = OCWrapperAclPolicyCheck(cloud->cis, handleAclPolicyCheckCB);
             break;
 #endif
         case ACL_ID_GET_BY_DEVICE:
-            res = OCWrapperAclIdGetByDevice(&endPoint, handleAclIdCB);
+            res = OCWrapperAclIdGetByDevice(cloud->cis, handleAclIdCB);
             break;
         case ACL_ID_CREATE:
-            res = OCWrapperAclIdCreate(&endPoint, handleAclIdCB);
+            res = OCWrapperAclIdCreate(cloud->cis, handleAclIdCB);
             break;
         case ACL_ID_DELETE:
-            res = OCWrapperAclIdDelete(&endPoint, handleCB);
+            res = OCWrapperAclIdDelete(cloud->cis, handleCB);
             break;
         case ACL_INDIVIDUAL_GET_INFO:
-            res = OCWrapperAclIndividualGetInfo(&endPoint, handleAclIndividualGetInfoCB);
+            res = OCWrapperAclIndividualGetInfo(cloud->cis, handleAclIndividualGetInfoCB);
             break;
         case ACL_INDIVIDUAL_UPDATE_ACE:
-            res = OCWrapperAclIndividualUpdateAce(&endPoint, handleCB);
+            res = OCWrapperAclIndividualUpdateAce(cloud->cis, handleCB);
             break;
         case ACL_INDIVIDUAL_UPDATE:
-            res = OCWrapperAclIndividualUpdate(&endPoint, handleCB);
+            res = OCWrapperAclIndividualUpdate(cloud->cis, handleCB);
             break;
         case ACL_INDIVIDUAL_DELETE:
-            res = OCWrapperAclIndividualDelete(&endPoint, handleCB);
+            res = OCWrapperAclIndividualDelete(cloud->cis, handleCB);
             break;
         case ACL_INDIVIDUAL_DELETE_ACE:
-            res = OCWrapperAclIndividualDeleteAce(&endPoint, handleCB);
+            res = OCWrapperAclIndividualDeleteAce(cloud->cis, handleCB);
             break;
         case CSR_SIGN:
-            res = OCWrapperCertificateIssueRequest(&endPoint, handleCB);
+            res = OCWrapperCertificateIssueRequest(cloud->cis, handleCB);
             break;
         case DISCOVERY:
             CLIENT_ONLY(mode);
@@ -623,7 +635,7 @@ static void *userRequests(void *data)
             }
         }
     }
-
+    OICFree(cloud);
     return NULL;
 }
 
index ab079be..96a01ae 100644 (file)
@@ -361,17 +361,17 @@ static void deleteCloudAceList(cloudAce_t *aces)
     }
 }
 
-OCStackResult OCWrapperCertificateIssueRequest(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperCertificateIssueRequest(const char *cloudUri, OCCloudResponseCB callback)
 {
-    return OCCloudCertificateIssueRequest(NULL, endPoint, callback);
+    return OCCloudCertificateIssueRequest(NULL, cloudUri, callback);
 }
 
-OCStackResult OCWrapperGetCRL(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperGetCRL(const char *cloudUri, OCCloudResponseCB callback)
 {
-    return OCCloudGetCRL(NULL, endPoint, callback);
+    return OCCloudGetCRL(NULL, cloudUri, callback);
 }
 
-OCStackResult OCWrapperPostCRL(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperPostCRL(const char *cloudUri, OCCloudResponseCB callback)
 {
     OCStackResult result = OC_STACK_ERROR;
     OCByteString crlData = {0, 0};
@@ -399,7 +399,7 @@ OCStackResult OCWrapperPostCRL(const OCDevAddr *endPoint, OCCloudResponseCB call
     OCByteString *crl = crlData.bytes? &crlData : NULL;
 
     result = OCCloudPostCRL(NULL, thisUpdate, nextUpdate, crl, rcsn,
-                            endPoint, callback);
+                            cloudUri, callback);
 exit:
     clearStringArray(&serialNumbers);
     OICFree(crlData.bytes);
@@ -407,16 +407,16 @@ exit:
     return result;
 }
 
-OCStackResult OCWrapperAclIdGetByDevice(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclIdGetByDevice(const char *cloudUri, OCCloudResponseCB callback)
 {
     char di[MAX_ID_LENGTH] = { 0 };
 
     readString(di, sizeof(di), "device id", UUID_EXAMPLE_1);
 
-    return OCCloudGetAclIdByDevice(NULL, di, endPoint, callback);
+    return OCCloudGetAclIdByDevice(NULL, di, cloudUri, callback);
 }
 
-OCStackResult OCWrapperAclIdCreate(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclIdCreate(const char *cloudUri, OCCloudResponseCB callback)
 {
     char oid[MAX_ID_LENGTH]  = { 0 };
     char di[MAX_ID_LENGTH]   = { 0 };
@@ -424,28 +424,28 @@ OCStackResult OCWrapperAclIdCreate(const OCDevAddr *endPoint, OCCloudResponseCB
     readString(oid, sizeof(oid), "owner id", UUID_EXAMPLE_2);
     readString(di, sizeof(di), "device id", UUID_EXAMPLE_1);
 
-    return OCCloudAclIdCreate(NULL, oid, di, endPoint, callback);
+    return OCCloudAclIdCreate(NULL, oid, di, cloudUri, callback);
 }
 
-OCStackResult OCWrapperAclIdDelete(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclIdDelete(const char *cloudUri, OCCloudResponseCB callback)
 {
     char aclid[MAX_ID_LENGTH] = { 0 };
 
     readString(aclid, sizeof(aclid), "acl id", ACL_ID_EXAMPLE);
 
-    return OCCloudAclIdDelete(NULL, aclid, endPoint, callback);
+    return OCCloudAclIdDelete(NULL, aclid, cloudUri, callback);
 }
 
-OCStackResult OCWrapperAclIndividualGetInfo(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclIndividualGetInfo(const char *cloudUri, OCCloudResponseCB callback)
 {
     char aclid[MAX_ID_LENGTH] = { 0 };
 
     readString(aclid, sizeof(aclid), "acl id", ACL_ID_EXAMPLE);
 
-    return OCCloudAclIndividualGetInfo(NULL, aclid, endPoint, callback);
+    return OCCloudAclIndividualGetInfo(NULL, aclid, cloudUri, callback);
 }
 
-OCStackResult OCWrapperAclIndividualUpdateAce(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclIndividualUpdateAce(const char *cloudUri, OCCloudResponseCB callback)
 {
     OCStackResult result = OC_STACK_NO_MEMORY;
 
@@ -514,13 +514,13 @@ OCStackResult OCWrapperAclIndividualUpdateAce(const OCDevAddr *endPoint, OCCloud
         }
     }
 
-    result = OCCloudAclIndividualAclUpdate(NULL, aclid, aces, endPoint, callback);
+    result = OCCloudAclIndividualAclUpdate(NULL, aclid, aces, cloudUri, callback);
 exit:
     deleteCloudAceList(aces);
     return result;
 }
 
-OCStackResult OCWrapperAclIndividualUpdate(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclIndividualUpdate(const char *cloudUri, OCCloudResponseCB callback)
 {
     OCStackResult result = OC_STACK_NO_MEMORY;
 
@@ -581,21 +581,21 @@ OCStackResult OCWrapperAclIndividualUpdate(const OCDevAddr *endPoint, OCCloudRes
     }
 
 
-    result = OCCloudAclIndividualAceUpdate(NULL, aclid,aceid, ace, endPoint, callback);
+    result = OCCloudAclIndividualAceUpdate(NULL, aclid,aceid, ace, cloudUri, callback);
 exit:
     return result;
 }
 
-OCStackResult OCWrapperAclIndividualDelete(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclIndividualDelete(const char *cloudUri, OCCloudResponseCB callback)
 {
     char aclid[MAX_ID_LENGTH] = { 0 };
 
     readString(aclid, sizeof(aclid), "acl id", ACL_ID_EXAMPLE);
 
-    return OCCloudAclAcesDelete(NULL, aclid, endPoint, callback);
+    return OCCloudAclAcesDelete(NULL, aclid, cloudUri, callback);
 }
 
-OCStackResult OCWrapperAclIndividualDeleteAce(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclIndividualDeleteAce(const char *cloudUri, OCCloudResponseCB callback)
 {
     char aclid[MAX_ID_LENGTH] = { 0 };
     char aceid[MAX_ID_LENGTH] = { 0 };
@@ -603,10 +603,10 @@ OCStackResult OCWrapperAclIndividualDeleteAce(const OCDevAddr *endPoint, OCCloud
     readString(aclid, sizeof(aclid), "acl id", ACL_ID_EXAMPLE);
     readString(aceid, sizeof(aceid), "ace id", ACE_ID_EXAMPLE);
 
-    return OCCloudAclIndividualAceDelete(NULL, aclid, aceid, endPoint, callback);
+    return OCCloudAclIndividualAceDelete(NULL, aclid, aceid, cloudUri, callback);
 }
 
-OCStackResult OCWrapperAclCreateGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclCreateGroup(const char *cloudUri, OCCloudResponseCB callback)
 {
     char gtype[16] = { 0 };
     char gmid[MAX_ID_LENGTH] = { 0 };
@@ -614,19 +614,19 @@ OCStackResult OCWrapperAclCreateGroup(const OCDevAddr *endPoint, OCCloudResponse
     readString(gtype, sizeof(gtype), "Group type value", "Public");
     readOptionalString(gmid, sizeof(gmid), "group member id value", UUID_EXAMPLE_2);
 
-    return OCCloudAclCreateGroup(NULL, gtype, OPTIONAL_PARAM(gmid), endPoint, callback);
+    return OCCloudAclCreateGroup(NULL, gtype, OPTIONAL_PARAM(gmid), cloudUri, callback);
 }
 
-OCStackResult OCWrapperAclFindMyGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclFindMyGroup(const char *cloudUri, OCCloudResponseCB callback)
 {
     char mid[MAX_ID_LENGTH]  = { 0 };
 
     readOptionalString(mid, sizeof(mid), "member id value", UUID_EXAMPLE_2);
 
-    return OCCloudAclFindMyGroup(NULL, OPTIONAL_PARAM(mid), endPoint, callback);
+    return OCCloudAclFindMyGroup(NULL, OPTIONAL_PARAM(mid), cloudUri, callback);
 }
 
-OCStackResult OCWrapperAclDeleteGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclDeleteGroup(const char *cloudUri, OCCloudResponseCB callback)
 {
     char gid[MAX_ID_LENGTH]  = { 0 };
     char gmid[MAX_ID_LENGTH] = { 0 };
@@ -635,28 +635,28 @@ OCStackResult OCWrapperAclDeleteGroup(const OCDevAddr *endPoint, OCCloudResponse
 
     readOptionalString(gmid, sizeof(gmid), "group member id value", UUID_EXAMPLE_2);
 
-    return OCCloudAclDeleteGroup(NULL, gid, OPTIONAL_PARAM(gmid), endPoint, callback);
+    return OCCloudAclDeleteGroup(NULL, gid, OPTIONAL_PARAM(gmid), cloudUri, callback);
 }
 
-OCStackResult OCWrapperAclJoinToInvitedGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclJoinToInvitedGroup(const char *cloudUri, OCCloudResponseCB callback)
 {
     char gid[MAX_ID_LENGTH]  = { 0 };
 
     readString(gid, sizeof(gid), "Group id value", ID_EXAMPLE_1);
 
-    return OCCloudAclJoinToInvitedGroup(NULL, gid, endPoint, callback);
+    return OCCloudAclJoinToInvitedGroup(NULL, gid, cloudUri, callback);
 }
 
-OCStackResult OCWrapperAclObserveGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclObserveGroup(const char *cloudUri, OCCloudResponseCB callback)
 {
     char gid[MAX_ID_LENGTH]  = { 0 };
 
     readString(gid, sizeof(gid), "Group id value", ID_EXAMPLE_1);
 
-    return OCCloudAclObserveGroup(NULL, gid, endPoint, callback);
+    return OCCloudAclObserveGroup(NULL, gid, cloudUri, callback);
 }
 
-OCStackResult OCWrapperAclShareDeviceIntoGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclShareDeviceIntoGroup(const char *cloudUri, OCCloudResponseCB callback)
 {
     OCStackResult result = OC_STACK_NO_MEMORY;
     char gid[MAX_ID_LENGTH]  = { 0 };
@@ -669,7 +669,7 @@ OCStackResult OCWrapperAclShareDeviceIntoGroup(const OCDevAddr *endPoint, OCClou
 
     readStringArray(&dilist, MAX_ID_LENGTH, "device list", UUID_EXAMPLE_1);
 
-    result = OCCloudAclShareDeviceIntoGroup(NULL, gid, &midlist, &dilist, endPoint, callback);
+    result = OCCloudAclShareDeviceIntoGroup(NULL, gid, &midlist, &dilist, cloudUri, callback);
 
     clearStringArray(&midlist);
     clearStringArray(&dilist);
@@ -677,7 +677,7 @@ OCStackResult OCWrapperAclShareDeviceIntoGroup(const OCDevAddr *endPoint, OCClou
     return result;
 }
 
-OCStackResult OCWrapperAclDeleteDeviceFromGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclDeleteDeviceFromGroup(const char *cloudUri, OCCloudResponseCB callback)
 {
     OCStackResult result = OC_STACK_NO_MEMORY;
     char gid[MAX_ID_LENGTH]  = { 0 };
@@ -690,7 +690,7 @@ OCStackResult OCWrapperAclDeleteDeviceFromGroup(const OCDevAddr *endPoint, OCClo
 
     readStringArray(&dilist, MAX_ID_LENGTH, "device list", UUID_EXAMPLE_1);
 
-    result = OCCloudAclDeleteDeviceFromGroup(NULL, gid, &midlist, &dilist, endPoint, callback);
+    result = OCCloudAclDeleteDeviceFromGroup(NULL, gid, &midlist, &dilist, cloudUri, callback);
 
     clearStringArray(&midlist);
     clearStringArray(&dilist);
@@ -698,7 +698,7 @@ OCStackResult OCWrapperAclDeleteDeviceFromGroup(const OCDevAddr *endPoint, OCClo
     return result;
 }
 
-OCStackResult OCWrapperAclGroupGetInfo(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclGroupGetInfo(const char *cloudUri, OCCloudResponseCB callback)
 {
     char gid[MAX_ID_LENGTH]  = { 0 };
     char mid[MAX_ID_LENGTH]  = { 0 };
@@ -707,10 +707,10 @@ OCStackResult OCWrapperAclGroupGetInfo(const OCDevAddr *endPoint, OCCloudRespons
 
     readOptionalString(mid, sizeof(mid), "member id value", UUID_EXAMPLE_2);
 
-    return OCCloudAclGroupGetInfo(NULL, gid, OPTIONAL_PARAM(mid), endPoint, callback);
+    return OCCloudAclGroupGetInfo(NULL, gid, OPTIONAL_PARAM(mid), cloudUri, callback);
 }
 
-OCStackResult OCWrapperAclInviteUser(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclInviteUser(const char *cloudUri, OCCloudResponseCB callback)
 {
     OCStackResult result = OC_STACK_NO_MEMORY;
     char uid[MAX_ID_LENGTH]  = { 0 };
@@ -723,7 +723,7 @@ OCStackResult OCWrapperAclInviteUser(const OCDevAddr *endPoint, OCCloudResponseC
 
     readStringArray(&midlist, MAX_ID_LENGTH, "member id list", UUID_EXAMPLE_2);
 
-    result = OCCloudAclInviteUser(NULL, OPTIONAL_PARAM(uid), &gidlist, &midlist, endPoint, callback);
+    result = OCCloudAclInviteUser(NULL, OPTIONAL_PARAM(uid), &gidlist, &midlist, cloudUri, callback);
 
     clearStringArray(&midlist);
     clearStringArray(&gidlist);
@@ -731,16 +731,16 @@ OCStackResult OCWrapperAclInviteUser(const OCDevAddr *endPoint, OCCloudResponseC
     return result;
 }
 
-OCStackResult OCWrapperAclGetInvitation(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclGetInvitation(const char *cloudUri, OCCloudResponseCB callback)
 {
     char uid[MAX_ID_LENGTH]  = { 0 };
 
     readOptionalString(uid, sizeof(uid), "user uuid value", UUID_EXAMPLE_2);
 
-    return OCCloudAclGetInvitation(NULL, OPTIONAL_PARAM(uid), endPoint, callback);
+    return OCCloudAclGetInvitation(NULL, OPTIONAL_PARAM(uid), cloudUri, callback);
 }
 
-OCStackResult OCWrapperAclDeleteInvitation(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclDeleteInvitation(const char *cloudUri, OCCloudResponseCB callback)
 {
     char uid[MAX_ID_LENGTH]  = { 0 };
     char gid[MAX_ID_LENGTH]  = { 0 };
@@ -748,10 +748,10 @@ OCStackResult OCWrapperAclDeleteInvitation(const OCDevAddr *endPoint, OCCloudRes
     readOptionalString(uid, sizeof(uid), "user uuid value", UUID_EXAMPLE_2);
     readString(gid, sizeof(gid), "Group id value", ID_EXAMPLE_1);
 
-    return OCCloudAclDeleteInvitation(NULL, OPTIONAL_PARAM(uid), gid, endPoint, callback);
+    return OCCloudAclDeleteInvitation(NULL, OPTIONAL_PARAM(uid), gid, cloudUri, callback);
 }
 
-OCStackResult OCWrapperAclCancelInvitation(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclCancelInvitation(const char *cloudUri, OCCloudResponseCB callback)
 {
     char uid[MAX_ID_LENGTH]  = { 0 };
     char gid[MAX_ID_LENGTH]  = { 0 };
@@ -762,10 +762,10 @@ OCStackResult OCWrapperAclCancelInvitation(const OCDevAddr *endPoint, OCCloudRes
     readString(gid, sizeof(gid), "Group id value", ID_EXAMPLE_1);
     readString(mid, sizeof(mid), "member id value", ID_EXAMPLE_1);
 
-    return OCCloudAclCancelInvitation(NULL, OPTIONAL_PARAM(uid), gid, mid, endPoint, callback);
+    return OCCloudAclCancelInvitation(NULL, OPTIONAL_PARAM(uid), gid, mid, cloudUri, callback);
 }
 
-OCStackResult OCWrapperAclPolicyCheck(const OCDevAddr *endPoint, OCCloudResponseCB callback)
+OCStackResult OCWrapperAclPolicyCheck(const char *cloudUri, OCCloudResponseCB callback)
 {
     char sid[MAX_ID_LENGTH] = { 0 };
     char di[MAX_ID_LENGTH]  = { 0 };
@@ -777,5 +777,5 @@ OCStackResult OCWrapperAclPolicyCheck(const OCDevAddr *endPoint, OCCloudResponse
     readString(rm, sizeof(rm), "request method", "GET or POST or DELETE");
     readString(user_uri, sizeof(user_uri), "request uri", RESOURCE_URI_EXAMPLE);
 
-    return OCCloudAclPolicyCheck(NULL, sid, di, rm, user_uri, endPoint, callback);
+    return OCCloudAclPolicyCheck(NULL, sid, di, rm, user_uri, cloudUri, callback);
 }
index 584fbb8..5a63742 100644 (file)
 /**
  * Certificate-Issue request function
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperCertificateIssueRequest(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperCertificateIssueRequest(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * CRL GET request function
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperGetCRL(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperGetCRL(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * CRL POST request function (with Serial Numbers list to revoke)
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperPostCRL(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperPostCRL(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL id retrieve by device id
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclIdGetByDevice(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclIdGetByDevice(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL id create
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclIdCreate(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclIdCreate(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL id delete
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclIdDelete(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclIdDelete(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL individual get info
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclIndividualGetInfo(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclIndividualGetInfo(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL individual update ACE
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclIndividualUpdateAce(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclIndividualUpdateAce(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL individual update. Replaces an existing ACE with a new one
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclIndividualUpdate(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclIndividualUpdate(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL individual delete
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclIndividualDelete(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclIndividualDelete(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL individual delete ACE
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclIndividualDeleteAce(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclIndividualDeleteAce(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL post group request function
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclCreateGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclCreateGroup(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL get group request function
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclFindMyGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclFindMyGroup(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL delete group request function
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclDeleteGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclDeleteGroup(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL join to invited group request function
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclJoinToInvitedGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclJoinToInvitedGroup(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL observe group request function
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclObserveGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclObserveGroup(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL share device into group request function
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclShareDeviceIntoGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclShareDeviceIntoGroup(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL delete device from group request function
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclDeleteDeviceFromGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclDeleteDeviceFromGroup(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL get group info request function
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclGroupGetInfo(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclGroupGetInfo(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL invite user to group request function
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclInviteUser(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclInviteUser(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL get invitation request function
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclGetInvitation(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclGetInvitation(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL delete invitation request function (by receiver)
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclDeleteInvitation(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclDeleteInvitation(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL cancel invitation request function (by sender)
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclCancelInvitation(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclCancelInvitation(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * ACL check that given request can be applied to resource
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @param[in] callback          result callback
  * @return  OCStackResult application result
  */
-OCStackResult OCWrapperAclPolicyCheck(const OCDevAddr *endPoint, OCCloudResponseCB callback);
+OCStackResult OCWrapperAclPolicyCheck(const char *cloudUri, OCCloudResponseCB callback);
 
 /**
  * Read user input (expect string value)
index 6e402d2..4e96b3a 100644 (file)
@@ -41,6 +41,8 @@
 #include "mbedtls/x509_csr.h"
 #include "occertutility.h"
 #include "pmutility.h"
+#include "occloudprovisioning.h"
+#include "auth.h"
 
 #ifdef _MSC_VER
 #include <io.h>
@@ -71,6 +73,9 @@ extern "C"
 #define _33_CHECK_LINK_STATUS_      33
 #define _34_SAVE_ACL_               34
 #define _35_PROVIS_CERT_            35
+#ifdef WITH_CLOUD
+#define _36_PROVIS_CLOUD_CONF_      36
+#endif //WITH_CLOUD
 #define _40_UNLINK_PAIR_DEVS_       40
 #define _50_REMOVE_SELEC_DEV_       50
 #define _51_REMOVE_DEV_WITH_UUID_   51
@@ -208,6 +213,22 @@ void provisionTrustChainCB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool
     g_doneCB = true;
 }
 
+#ifdef WITH_CLOUD
+static void provisionCloudConfigCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError)
+{
+    if(!hasError)
+    {
+        OIC_LOG_V(INFO, TAG, "Provision Pairwise SUCCEEDED - ctx: %s", (char*) ctx);
+    }
+    else
+    {
+        OIC_LOG_V(ERROR, TAG, "Provision Pairwise FAILED - ctx: %s", (char*) ctx);
+        printResultList((const OCProvisionResult_t*) arr, nOfRes);
+    }
+    g_doneCB = true;
+}
+#endif //WITH_CLOUD
+
 static void provisionAclCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError)
 {
     if(!hasError)
@@ -1258,6 +1279,179 @@ static int provisionCert(void)
     return 0;
 }
 
+#ifdef WITH_CLOUD
+static int provisionCloudConfig(void)
+{
+    // make sure we own at least one device to provision
+    if (!g_own_list || g_own_cnt == 0)
+    {
+        printf("   > Owned Device List, to Provision Credentials, is Empty\n");
+        printf("   > Please Register Unowned Devices first, with [20] Menu\n");
+        return 0;  // normal case
+    }
+
+    // select device for provisioning certificate
+    int dev_num = 0;
+    if (g_own_cnt == 1)
+    {
+        dev_num = 1;
+    }
+    else
+    {
+        for (; ; )
+        {
+            printf("   > Enter Device Number, for certificate provisioning: ");
+            for (int ret = 0; 1 != ret; )
+            {
+                ret = scanf("%d", &dev_num);
+                for (; 0x20 <= getchar(); );  // for removing overflow garbages
+                                          // '0x20<=code' is character region
+            }
+            if (0<dev_num && g_own_cnt >= dev_num)
+            {
+                break;
+            }
+            printf("     Entered Wrong Number. Please Enter Again\n");
+        }
+    }
+
+    OCProvisionDev_t* targetDevice = getDevInst((const OCProvisionDev_t*)g_own_list, dev_num);
+    if (targetDevice == NULL)
+    {
+        OIC_LOG(ERROR, TAG, "Error, invalid device %d");
+        return -1;
+    }
+
+    // Install the CA trust anchor
+    FILE *F;
+    F = fopen("rootca.crt", "rb");
+    fseek (F , 0 , SEEK_END);
+    int certsize = ftell (F);
+    rewind (F);
+    uint8_t* cert = (uint8_t*) malloc (sizeof(char)*certsize);
+    int res = fread (cert, 1, certsize, F);
+    /* Set our own trust anchor so that we trust certs we've issued. */
+    res = OCSaveTrustCertChain((uint8_t*) cert, certsize, OIC_ENCODING_PEM, &g_caCredId);
+    if (OC_STACK_OK != res)
+    {
+        printf("     Failed to setup CA\n");
+        return -1;
+    }
+
+    // Provision the CA root cert to the target device
+    printf("   > Saving root certificate (trust anchor) to selected device..\n");
+    g_doneCB = false;
+    OicSecCredType_t type = SIGNED_ASYMMETRIC_KEY;
+
+    OCStackResult rst = OCProvisionTrustCertChain((void*)g_ctx, type, g_caCredId, targetDevice, (OCProvisionResultCB)&provisionTrustChainCB);
+    if (OC_STACK_OK != rst)
+    {
+        OIC_LOG_V(ERROR, TAG, "OCProvisionTrustCertChain returned error: %d", rst);
+        return -1;
+    }
+
+    if (waitCallbackRet())  // input |g_doneCB| flag implicitly
+    {
+        OIC_LOG(ERROR, TAG, "OCProvisionTrustCertChain callback error");
+        return -1;
+    }
+    if (!g_successCB)
+    {
+        return -1;
+    }
+
+    OicCloud_t *cloud = OICCalloc(1,sizeof(OicCloud_t));
+    if (NULL == cloud)
+    {
+        OIC_LOG(ERROR, TAG, "Error, invalid cloud");
+        return -1;
+    }
+    cloud->apn = (char*)OICCalloc(1,1024);
+    if (NULL == cloud->apn)
+    {
+        OICFree(cloud);
+        OIC_LOG(ERROR, TAG, "Error, invalid cloud->apn");
+        return -1;
+    }
+    cloud->cis = (char*)OICCalloc(1,1024);
+    if (NULL == cloud->cis)
+    {
+        OICFree(cloud->apn);
+        OICFree(cloud);
+        OIC_LOG(ERROR, TAG, "Error, invalid cloud->cis");
+        return -1;
+    }
+    cloud->at = (char*)OICCalloc(1,1024);
+    if (NULL == cloud->at)
+    {
+        OICFree(cloud->cis);
+        OICFree(cloud->apn);
+        OICFree(cloud);
+        OIC_LOG(ERROR, TAG, "Error, invalid cloud->at");
+        return -1;
+    }
+
+    printf("   > cloud uri (coaps+tcp://ip:port): ");
+    for(int ret=0; 1!=ret; )
+    {
+        ret = scanf("%32s", cloud->cis);
+        for( ; 0x20<=getchar(); );  // for removing overflow garbages
+                                    // '0x20<=code' is character region
+    }
+
+    printf("   > oauth provider: ");
+    for(int ret=0; 1!=ret; )
+    {
+        ret = scanf("%32s", cloud->apn);
+        for( ; 0x20<=getchar(); );  // for removing overflow garbages
+                                    // '0x20<=code' is character region
+    }
+
+    printf("   > access token: ");
+    for(int ret=0; 1!=ret; )
+    {
+        ret = scanf("%32s", cloud->at);
+        for( ; 0x20<=getchar(); );  // for removing overflow garbages
+                                    // '0x20<=code' is character region
+    }
+
+    //Provision the new cert
+    printf("   > Provisioning certificate credential to selected device..\n");
+    g_doneCB = false;
+    rst = OCProvisionCloudConfig((void*)g_ctx, targetDevice, cloud, (OCClientResponseHandler)provisionCloudConfigCB);
+    if (OC_STACK_OK != rst)
+    {
+        OIC_LOG_V(ERROR, TAG, "OCProvisionCertificate returned error: %d", rst);
+        OICFree(cloud->at);
+        OICFree(cloud->cis);
+        OICFree(cloud->apn);
+        OICFree(cloud);
+        return -1;
+    }
+    if (waitCallbackRet())  // input |g_doneCB| flag implicitly
+    {
+        OIC_LOG(ERROR, TAG, "OCProvisionCertificate callback error");
+        OICFree(cloud->at);
+        OICFree(cloud->cis);
+        OICFree(cloud->apn);
+        OICFree(cloud);
+        return -1;
+    }
+    if (!g_successCB)
+    {
+        OICFree(cloud->at);
+        OICFree(cloud->cis);
+        OICFree(cloud->apn);
+        OICFree(cloud);
+        return -1;
+    }
+
+    printf("   > Provisioned cloud crendentials\n");
+
+    return 0;
+}
+#endif //WITH_CLOUD
+
 static int provisionAcl(void)
 {
     // check |own_list| for provisioning access control list
@@ -2746,7 +2940,8 @@ static void printMenu(void)
     printf("** 32. Provision the Selected Access Control List(ACL)\n");
     printf("** 33. Check Linked Status of the Selected Device on PRVN DB\n");
     printf("** 34. Save the Selected Access Control List(ACL) into local SVR DB\n");
-    printf("** 35. Provision certificate credential\n\n");
+    printf("** 35. Provision certificate credential\n");
+    printf("** 36. Provision cloud credential\n\n");
 
 
     printf("** [D] UNLINK PAIRWISE THINGS\n");
@@ -2928,6 +3123,14 @@ int main()
                 OIC_LOG(ERROR, TAG, "_36_PROVIS_CERT_: error");
             }
             break;
+#ifdef WITH_CLOUD
+        case _36_PROVIS_CLOUD_CONF_:
+            if (provisionCloudConfig())
+            {
+                OIC_LOG(ERROR, TAG, "_36_PROVIS_CLOUD_CONF_: error");
+            }
+            break;
+#endif //WITH_CLOUD
         case _40_UNLINK_PAIR_DEVS_:
             if(unlinkPairwise())
             {
index f9746a0..003f553 100644 (file)
@@ -34,6 +34,9 @@
 #include "ocstack.h"
 #include "ocpayload.h"
 #include "pinoxmcommon.h"
+#if defined(__WITH_TLS__) && defined(WITH_CLOUD)
+#include "cloud/cloudresource.h"
+#endif // __WITH_TLS__ && WITH_CLOUD
 
 #ifdef HAVE_WINDOWS_H
 #include <windows.h>
@@ -434,7 +437,12 @@ int main()
         return 0;
     }
     OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, (void*) specVersion);
-
+#if defined(__WITH_TLS__) && defined(WITH_CLOUD)
+    if (OC_STACK_OK != InitCloudResource())
+    {
+        OIC_LOG(ERROR, TAG, "Cloud init error");
+    }
+#endif // __WITH_TLS__ && WITH_CLOUD
     /*
      * Declare and create the example resource: LED
      */
@@ -457,7 +465,9 @@ int main()
     }
 
     OIC_LOG(INFO, TAG, "Exiting ocserver main loop...");
-
+#if defined(__WITH_TLS__) && defined(WITH_CLOUD)
+    DeInitCloudResource();
+#endif // __WITH_TLS__ && WITH_CLOUD
     if (OCStop() != OC_STACK_OK)
     {
         OIC_LOG(ERROR, TAG, "OCStack process error");
index f06976a..ae6d905 100644 (file)
@@ -34,6 +34,9 @@
 #include "ocstack.h"
 #include "ocpayload.h"
 #include "ocprovisioningmanager.h"
+#if defined(__WITH_TLS__) && defined(WITH_CLOUD)
+#include "cloud/cloudresource.h"
+#endif // __WITH_TLS__ && WITH_CLOUD
 
 #ifdef HAVE_WINDOWS_H
 #include <windows.h>
@@ -449,6 +452,12 @@ int main()
         OIC_LOG(ERROR, TAG, "OCStack init error");
         return 0;
     }
+#if defined(__WITH_TLS__) && defined(WITH_CLOUD)
+    if (OC_STACK_OK != InitCloudResource())
+    {
+        OIC_LOG(ERROR, TAG, "Cloud init error");
+    }
+#endif // __WITH_TLS__ && WITH_CLOUD
     OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, (void*) specVersion);
 
     /*
@@ -473,6 +482,9 @@ int main()
     }
 
     OIC_LOG(INFO, TAG, "Exiting ocserver main loop...");
+#if defined(__WITH_TLS__) && defined(WITH_CLOUD)
+    DeInitCloudResource();
+#endif // __WITH_TLS__ && WITH_CLOUD
 
     if (OCStop() != OC_STACK_OK)
     {
index 9fba187..f01f032 100644 (file)
 #include "ocpayload.h"
 #include "pinoxmcommon.h"
 #include "oxmverifycommon.h"
+#if defined(__WITH_TLS__) && defined(WITH_CLOUD)
+#include "cloud/cloudresource.h"
+#endif // __WITH_TLS__ && WITH_CLOUD
+
 
 #ifdef HAVE_WINDOWS_H
 #include <windows.h>
@@ -484,6 +488,13 @@ int main()
         OIC_LOG(ERROR, TAG, "OCStack init error");
         return 0;
     }
+#if defined(__WITH_TLS__) && defined(WITH_CLOUD)
+    if (OC_STACK_OK != InitCloudResource())
+    {
+        OIC_LOG(ERROR, TAG, "Cloud init error");
+    }
+#endif // __WITH_TLS__ && WITH_CLOUD
+
     OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, (void*) specVersion);
 
     /*
@@ -508,6 +519,9 @@ int main()
     }
 
     OIC_LOG(INFO, TAG, "Exiting ocserver main loop...");
+#if defined(__WITH_TLS__) && defined(WITH_CLOUD)
+    DeInitCloudResource();
+#endif // __WITH_TLS__ && WITH_CLOUD
 
     if (OCStop() != OC_STACK_OK)
     {
index 60a5d2e..771e5df 100644 (file)
@@ -34,6 +34,9 @@
 #include "ocstack.h"
 #include "ocpayload.h"
 #include "pinoxmcommon.h"
+#if defined(__WITH_TLS__) && defined(WITH_CLOUD)
+#include "cloud/cloudresource.h"
+#endif // __WITH_TLS__ && WITH_CLOUD
 
 #ifdef HAVE_WINDOWS_H
 #include <windows.h>
@@ -433,6 +436,12 @@ int main()
         OIC_LOG(ERROR, TAG, "OCStack init error");
         return 0;
     }
+#if defined(__WITH_TLS__) && defined(WITH_CLOUD)
+    if (OC_STACK_OK != InitCloudResource())
+    {
+        OIC_LOG(ERROR, TAG, "Cloud init error");
+    }
+#endif // __WITH_TLS__ && WITH_CLOUD
     OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, (void*) specVersion);
 
     /*
@@ -457,6 +466,9 @@ int main()
     }
 
     OIC_LOG(INFO, TAG, "Exiting ocserver main loop...");
+#if defined(__WITH_TLS__) && defined(WITH_CLOUD)
+    DeInitCloudResource();
+#endif // __WITH_TLS__ && WITH_CLOUD
 
     if (OCStop() != OC_STACK_OK)
     {
index d9d7e35..c927356 100644 (file)
@@ -34,6 +34,9 @@
 #include "ocstack.h"
 #include "ocpayload.h"
 #include "pinoxmcommon.h"
+#if defined(__WITH_TLS__) && defined(WITH_CLOUD)
+#include "cloud/cloudresource.h"
+#endif // __WITH_TLS__ && WITH_CLOUD
 
 #ifdef HAVE_WINDOWS_H
 #include <windows.h>
@@ -494,6 +497,12 @@ int main()
         OIC_LOG(ERROR, TAG, "OCStack init error");
         return 0;
     }
+#if defined(__WITH_TLS__) && defined(WITH_CLOUD)
+    if (OC_STACK_OK != InitCloudResource())
+    {
+        OIC_LOG(ERROR, TAG, "Cloud init error");
+    }
+#endif // __WITH_TLS__ && WITH_CLOUD
 
    /**
      * If the server supports random pin based ownership transfer, the callback
@@ -566,6 +575,9 @@ int main()
 #endif //MULTIPLE_OWNER
 
     OIC_LOG(INFO, TAG, "Exiting ocserver main loop...");
+#if defined(__WITH_TLS__) && defined(WITH_CLOUD)
+    DeInitCloudResource();
+#endif // __WITH_TLS__ && WITH_CLOUD
 
     if (OCStop() != OC_STACK_OK)
     {
index 47b186b..1dd304c 100644 (file)
@@ -24,6 +24,8 @@ Import('provisioning_env')
 provisioning_lib_env = provisioning_env.Clone()
 target_os = provisioning_lib_env.get('TARGET_OS')
 
+provisioning_lib_env.AppendUnique(CPPPATH=['#resource/csdk/security/include/experimental'])
+
 provisioning_lib_env.PrependUnique(LIBS=['coap'])
 
 if target_os not in ['msys_nt', 'windows']:
@@ -77,7 +79,10 @@ if provisioning_lib_env.get('WITH_TCP') == True and provisioning_lib_env.get('WI
         'cloud/aclgroup.c',
         'cloud/aclinvite.c',
         'cloud/aclid.c',
-        'cloud/csr.c'
+        'cloud/csr.c',
+        'cloud/auth.c',
+        'cloud/cloudresource.c',
+        'cloud/config.c'
     ]
 
 if target_os in ['linux', 'tizen']:
index db9efb2..fa72b16 100644 (file)
@@ -40,7 +40,8 @@
  * @param[in] response  peer response
  * @return  OCStackResult application result
  */
-static OCStackResult handleAclCreateGroupResponse(void *ctx, void **data, OCClientResponse *response)
+static OCStackResult handleAclCreateGroupResponse(void *ctx, void **data,
+        OCClientResponse *response)
 {
     OC_UNUSED(ctx);
     if (NULL == response->payload)
@@ -69,7 +70,8 @@ static OCStackResult handleAclCreateGroupResponse(void *ctx, void **data, OCClie
  * @param[in] response  peer response
  * @return  OCStackResult application result
  */
-static OCStackResult handleAclFindMyGroupResponse(void *ctx, void **data, OCClientResponse *response)
+static OCStackResult handleAclFindMyGroupResponse(void *ctx, void **data,
+        OCClientResponse *response)
 {
     OC_UNUSED(ctx);
     if (NULL == response->payload)
@@ -101,19 +103,18 @@ static OCStackResult handleAclFindMyGroupResponse(void *ctx, void **data, OCClie
     return OC_STACK_OK;
 }
 
-OCStackResult OCCloudAclCreateGroup(voidctx,
+OCStackResult OCCloudAclCreateGroup(void *ctx,
                                     const char *groupType,
                                     const char *groupMasterId,
-                                    const OCDevAddr *endPoint,
+                                    const char *cloudUri,
                                     OCCloudResponseCB callback)
 {
     char uri[MAX_URI_LENGTH] = { 0 };
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(groupType, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_GROUP_URL);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s", cloudUri, OC_RSRVD_ACL_GROUP_URL);
 
     OCCallbackData cbData;
     fillCallbackData(&cbData, ctx, callback, handleAclCreateGroupResponse, NULL);
@@ -133,17 +134,16 @@ OCStackResult OCCloudAclCreateGroup(void* ctx,
                         CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 }
 
-OCStackResult OCCloudAclFindMyGroup(voidctx,
+OCStackResult OCCloudAclFindMyGroup(void *ctx,
                                     const char *memberId,
-                                    const OCDevAddr *endPoint,
+                                    const char *cloudUri,
                                     OCCloudResponseCB callback)
 {
     char uri[MAX_URI_LENGTH] = { 0 };
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_GROUP_URL);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s", cloudUri, OC_RSRVD_ACL_GROUP_URL);
 
     if (memberId)
     {
@@ -158,19 +158,19 @@ OCStackResult OCCloudAclFindMyGroup(void* ctx,
                         CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 }
 
-OCStackResult OCCloudAclDeleteGroup(voidctx,
+OCStackResult OCCloudAclDeleteGroup(void *ctx,
                                     const char *groupId,
                                     const char *groupMasterId,
-                                    const OCDevAddr *endPoint,
+                                    const char *cloudUri,
                                     OCCloudResponseCB callback)
 {
     char uri[MAX_URI_LENGTH] = { 0 };
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(groupId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s?%s=%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_GROUP_URL, OC_RSRVD_GROUP_ID, groupId);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s?%s=%s", cloudUri,
+             OC_RSRVD_ACL_GROUP_URL, OC_RSRVD_GROUP_ID, groupId);
 
     if (groupMasterId)
     {
@@ -185,18 +185,18 @@ OCStackResult OCCloudAclDeleteGroup(void* ctx,
                         CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 }
 
-OCStackResult OCCloudAclJoinToInvitedGroup(voidctx,
+OCStackResult OCCloudAclJoinToInvitedGroup(void *ctx,
                                            const char *groupId,
-                                           const OCDevAddr *endPoint,
+                                           const char *cloudUri,
                                            OCCloudResponseCB callback)
 {
     char uri[MAX_URI_LENGTH] = { 0 };
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(groupId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s/%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_GROUP_URL, groupId);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s/%s", cloudUri,
+             OC_RSRVD_ACL_GROUP_URL, groupId);
 
     OCCallbackData cbData;
     fillCallbackData(&cbData, ctx, callback, NULL, NULL);
@@ -205,18 +205,18 @@ OCStackResult OCCloudAclJoinToInvitedGroup(void* ctx,
                         CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 }
 
-OCStackResult OCCloudAclObserveGroup(voidctx,
+OCStackResult OCCloudAclObserveGroup(void *ctx,
                                      const char *groupId,
-                                     const OCDevAddr *endPoint,
+                                     const char *cloudUri,
                                      OCCloudResponseCB callback)
 {
     char uri[MAX_URI_LENGTH] = { 0 };
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(groupId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s/%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_GROUP_URL, groupId);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s/%s", cloudUri,
+             OC_RSRVD_ACL_GROUP_URL, groupId);
 
     OCCallbackData cbData;
     fillCallbackData(&cbData, ctx, callback, NULL, NULL);
@@ -225,23 +225,23 @@ OCStackResult OCCloudAclObserveGroup(void* ctx,
                         CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 }
 
-OCStackResult OCCloudAclShareDeviceIntoGroup(voidctx,
+OCStackResult OCCloudAclShareDeviceIntoGroup(void *ctx,
                                              const char *groupId,
                                              const stringArray_t *memberIds,
                                              const stringArray_t *deviceIds,
-                                             const OCDevAddr *endPoint,
+                                             const char *cloudUri,
                                              OCCloudResponseCB callback)
 {
     size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 };
     char uri[MAX_URI_LENGTH] = { 0 };
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(groupId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(memberIds, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(deviceIds, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s/%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_GROUP_URL, groupId);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s/%s", cloudUri,
+             OC_RSRVD_ACL_GROUP_URL, groupId);
 
     OCCallbackData cbData;
     fillCallbackData(&cbData, ctx, callback, NULL, NULL);
@@ -263,38 +263,37 @@ OCStackResult OCCloudAclShareDeviceIntoGroup(void* ctx,
                         CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 }
 
-OCStackResult OCCloudAclDeleteDeviceFromGroup(voidctx,
+OCStackResult OCCloudAclDeleteDeviceFromGroup(void *ctx,
                                               const char *groupId,
                                               const stringArray_t *memberIds,
                                               const stringArray_t *deviceIds,
-                                              const OCDevAddr *endPoint,
+                                              const char *cloudUri,
                                               OCCloudResponseCB callback)
 
 {
     char uri[MAX_URI_LENGTH * 4] = { 0 };
     int max_size = sizeof(uri);
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(groupId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(memberIds, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(deviceIds, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, max_size, "%s%s:%d%s/%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_GROUP_URL, groupId);
+    snprintf(uri, max_size, "%s%s/%s", cloudUri, OC_RSRVD_ACL_GROUP_URL, groupId);
 
     for (size_t i = 0; i < memberIds->length; i++)
     {
         size_t len = strlen(uri);
-        snprintf(uri + len, max_size - len, "%c%s=%s", (0 == i)?'?':'&',
-                OC_RSRVD_MEMBER_ID_LIST, memberIds->array[i]);
+        snprintf(uri + len, max_size - len, "%c%s=%s", (0 == i) ? '?' : '&',
+                 OC_RSRVD_MEMBER_ID_LIST, memberIds->array[i]);
     }
 
     for (size_t i = 0; i < deviceIds->length; i++)
     {
         size_t len = strlen(uri);
         snprintf(uri + len, max_size - len, "%c%s=%s",
-                (0 == i && 0 == memberIds->length)?'?':'&',
-                OC_RSRVD_DEVICE_ID_LIST, deviceIds->array[i]);
+                 (0 == i && 0 == memberIds->length) ? '?' : '&',
+                 OC_RSRVD_DEVICE_ID_LIST, deviceIds->array[i]);
     }
 
     OCCallbackData cbData;
@@ -304,19 +303,19 @@ OCStackResult OCCloudAclDeleteDeviceFromGroup(void* ctx,
                         CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 }
 
-OCStackResult OCCloudAclGroupGetInfo(voidctx,
+OCStackResult OCCloudAclGroupGetInfo(void *ctx,
                                      const char *groupId,
                                      const char *memberId,
-                                     const OCDevAddr *endPoint,
+                                     const char *cloudUri,
                                      OCCloudResponseCB callback)
 {
     char uri[MAX_URI_LENGTH] = { 0 };
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(groupId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s/%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_GROUP_URL, groupId);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s/%s", cloudUri,
+             OC_RSRVD_ACL_GROUP_URL, groupId);
 
     if (memberId)
     {
index 8b546cb..f9a012e 100644 (file)
@@ -74,7 +74,7 @@ static OCStackResult getAclIdFromResponse(void *ctx, void **data, OCClientRespon
  * @return  OCStackResult application result
  */
 static OCStackResult handleGetAclIdByDeviceResponse(void *ctx, void **data,
-                                                    OCClientResponse *response)
+        OCClientResponse *response)
 {
     return getAclIdFromResponse(ctx, data, response);
 }
@@ -92,18 +92,18 @@ static OCStackResult handleAclIdCreateResponse(void *ctx, void **data, OCClientR
     return getAclIdFromResponse(ctx, data, response);
 }
 
-OCStackResult OCCloudGetAclIdByDevice(voidctx,
+OCStackResult OCCloudGetAclIdByDevice(void *ctx,
                                       const char *deviceId,
-                                      const OCDevAddr *endPoint,
+                                      const char *cloudUri,
                                       OCCloudResponseCB callback)
 {
     char uri[MAX_URI_LENGTH] = { 0 };
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(deviceId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s?%s=%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_ID_URL, OC_RSRVD_DEVICE_ID, deviceId);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s?%s=%s", cloudUri, OC_RSRVD_ACL_ID_URL, OC_RSRVD_DEVICE_ID,
+             deviceId);
 
     OCCallbackData cbData;
     fillCallbackData(&cbData, ctx, callback, handleGetAclIdByDeviceResponse, NULL);
@@ -112,21 +112,21 @@ OCStackResult OCCloudGetAclIdByDevice(void* ctx,
                         CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 }
 
-OCStackResult OCCloudAclIdCreate(voidctx,
+OCStackResult OCCloudAclIdCreate(void *ctx,
                                  const char *ownerId,
                                  const char *deviceId,
-                                 const OCDevAddr *endPoint,
+                                 const char *cloudUri,
                                  OCCloudResponseCB callback)
 {
     char uri[MAX_URI_LENGTH] = { 0 };
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(ownerId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(deviceId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s?%s=%s&%s=%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_ID_URL,
-            OC_RSRVD_OWNER_ID, ownerId, OC_RSRVD_DEVICE_ID, deviceId);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s?%s=%s&%s=%s",
+             cloudUri, OC_RSRVD_ACL_ID_URL,
+             OC_RSRVD_OWNER_ID, ownerId, OC_RSRVD_DEVICE_ID, deviceId);
 
     OCCallbackData cbData;
     fillCallbackData(&cbData, ctx, callback, handleAclIdCreateResponse, NULL);
@@ -135,18 +135,17 @@ OCStackResult OCCloudAclIdCreate(void* ctx,
                         CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 }
 
-OCStackResult OCCloudAclIdDelete(voidctx,
+OCStackResult OCCloudAclIdDelete(void *ctx,
                                  const char *aclId,
-                                 const OCDevAddr *endPoint,
+                                 const char *cloudUri,
                                  OCCloudResponseCB callback)
 {
     char uri[MAX_URI_LENGTH]  = { 0 };
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(aclId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s?%s=%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_ID_URL, OC_RSRVD_ACL_ID, aclId);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s?%s=%s", cloudUri, OC_RSRVD_ACL_ID_URL, OC_RSRVD_ACL_ID, aclId);
 
     OCCallbackData cbData;
     fillCallbackData(&cbData, ctx, callback, NULL, NULL);
@@ -185,7 +184,7 @@ static OCStackResult handleAclGetInfoResponse(void *ctx, void **data, OCClientRe
         goto exit;
     }
 
-    OicSecAcl_tacl = CBORPayloadToCloudAcl(cbor, size);
+    OicSecAcl_t *acl = CBORPayloadToCloudAcl(cbor, size);
     if (NULL == acl)
     {
         OIC_LOG(ERROR, TAG, "Can't parse CBOR payload");
@@ -213,18 +212,17 @@ exit:
     return result;
 }
 
-OCStackResult OCCloudAclIndividualGetInfo(voidctx,
+OCStackResult OCCloudAclIndividualGetInfo(void *ctx,
                                           const char *aclId,
-                                          const OCDevAddr *endPoint,
+                                          const char *cloudUri,
                                           OCCloudResponseCB callback)
 {
     char uri[MAX_URI_LENGTH]  = { 0 };
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(aclId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s/%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_ID_URL, aclId);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s/%s", cloudUri, OC_RSRVD_ACL_ID_URL, aclId);
 
     OCCallbackData cbData;
     fillCallbackData(&cbData, ctx, callback, handleAclGetInfoResponse, NULL);
@@ -233,10 +231,10 @@ OCStackResult OCCloudAclIndividualGetInfo(void* ctx,
                         CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 }
 
-OCStackResult OCCloudAclIndividualAclUpdate(voidctx,
+OCStackResult OCCloudAclIndividualAclUpdate(void *ctx,
                                             const char *aclId,
                                             const cloudAce_t *aces,
-                                            const OCDevAddr *endPoint,
+                                            const char *cloudUri,
                                             OCCloudResponseCB callback)
 {
     size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 };
@@ -247,12 +245,11 @@ OCStackResult OCCloudAclIndividualAclUpdate(void* ctx,
     OCRepPayload **helperPayload  = NULL;
     OCRepPayload **helperPayload2 = NULL;
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(aclId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(aces, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s/%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_ID_URL, aclId);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s/%s", cloudUri, OC_RSRVD_ACL_ID_URL, aclId);
 
     OCRepPayload *payload = OCRepPayloadCreate();
     if (!payload)
@@ -264,7 +261,7 @@ OCStackResult OCCloudAclIndividualAclUpdate(void* ctx,
     size_t acllist_count = 0;
     //code below duplicates LL_COUNT, implemented in newer version of utlist.h
     {
-        cloudAce_t *ace = (cloudAce_t*)aces;
+        cloudAce_t *ace = (cloudAce_t *)aces;
         while (ace)
         {
             ace = ace->next;
@@ -282,7 +279,7 @@ OCStackResult OCCloudAclIndividualAclUpdate(void* ctx,
     i = 0;
     cloudAce_t *ace = NULL;
 
-    LL_FOREACH((cloudAce_t*)aces, ace)
+    LL_FOREACH((cloudAce_t *)aces, ace)
     {
         OCRepPayload *acePayload = OCRepPayloadCreate();
         if (!acePayload)
@@ -346,11 +343,11 @@ OCStackResult OCCloudAclIndividualAclUpdate(void* ctx,
         }
         dimensions[0] = reslist_count;
         OCRepPayloadSetPropObjectArray(acePayload, OC_RSRVD_RESOURCES,
-                (const OCRepPayload **)helperPayload2, dimensions);
+                                       (const OCRepPayload **)helperPayload2, dimensions);
     }
     dimensions[0] = acllist_count;
     OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_ACCESS_CONTROL_LIST,
-            (const OCRepPayload **)helperPayload, dimensions);
+                                   (const OCRepPayload **)helperPayload, dimensions);
 
     OCCallbackData cbData;
     fillCallbackData(&cbData, ctx, callback, NULL, NULL);
@@ -375,12 +372,12 @@ no_memory:
     return OC_STACK_NO_MEMORY;
 }
 
-OCStackResult OCCloudAclIndividualAceUpdate(voidctx,
-                                            const char *aclId,
-                                            const char *aceId,
-                                            const cloudAce_t *aces,
-                                            const OCDevAddr *endPoint,
-                                            OCCloudResponseCB callback)
+OCStackResult OCCloudAclIndividualAceUpdate(void *ctx,
+        const char *aclId,
+        const char *aceId,
+        const cloudAce_t *aces,
+        const char *cloudUri,
+        OCCloudResponseCB callback)
 {
     size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 };
     char uri[MAX_URI_LENGTH]  = { 0 };
@@ -390,14 +387,13 @@ OCStackResult OCCloudAclIndividualAceUpdate(void* ctx,
     OCRepPayload **helperPayload  = NULL;
     OCRepPayload **helperPayload2 = NULL;
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(aclId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(aceId, TAG, "NULL aceId", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(aces, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s/%s?%s=%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_ID_URL, aclId,
-            OC_RSRVD_ACE_ID, aceId);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s/%s?%s=%s", cloudUri, OC_RSRVD_ACL_ID_URL, aclId,
+             OC_RSRVD_ACE_ID, aceId);
 
     OCRepPayload *payload = OCRepPayloadCreate();
     if (!payload)
@@ -418,7 +414,7 @@ OCStackResult OCCloudAclIndividualAceUpdate(void* ctx,
     i = 0;
     cloudAce_t *ace = NULL;
 
-    LL_FOREACH((cloudAce_t*)aces, ace)
+    LL_FOREACH((cloudAce_t *)aces, ace)
     {
         OCRepPayload *acePayload = OCRepPayloadCreate();
         if (!acePayload)
@@ -482,11 +478,11 @@ OCStackResult OCCloudAclIndividualAceUpdate(void* ctx,
         }
         dimensions[0] = reslist_count;
         OCRepPayloadSetPropObjectArray(acePayload, OC_RSRVD_RESOURCES,
-                (const OCRepPayload **)helperPayload2, dimensions);
+                                       (const OCRepPayload **)helperPayload2, dimensions);
     }
     dimensions[0] = acllist_count;
     OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_ACCESS_CONTROL_LIST,
-            (const OCRepPayload **)helperPayload, dimensions);
+                                   (const OCRepPayload **)helperPayload, dimensions);
 
     OCCallbackData cbData;
     fillCallbackData(&cbData, ctx, callback, NULL, NULL);
@@ -513,18 +509,17 @@ no_memory:
 
 
 
-OCStackResult OCCloudAclAcesDelete(voidctx,
-                                         const char *aclId,
-                                         const OCDevAddr *endPoint,
-                                         OCCloudResponseCB callback)
+OCStackResult OCCloudAclAcesDelete(void *ctx,
+                                   const char *aclId,
+                                   const char *cloudUri,
+                                   OCCloudResponseCB callback)
 {
     char uri[MAX_URI_LENGTH]  = { 0 };
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(aclId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s/%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_ID_URL, aclId);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s/%s", cloudUri, OC_RSRVD_ACL_ID_URL, aclId);
 
     OCCallbackData cbData;
     fillCallbackData(&cbData, ctx, callback, NULL, NULL);
@@ -533,21 +528,20 @@ OCStackResult OCCloudAclAcesDelete(void* ctx,
                         CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 }
 
-OCStackResult OCCloudAclIndividualAceDelete(voidctx,
-                                         const char *aclId,
-                                         const char *aceId,
-                                         const OCDevAddr *endPoint,
-                                         OCCloudResponseCB callback)
+OCStackResult OCCloudAclIndividualAceDelete(void *ctx,
+                                            const char *aclId,
+                                            const char *aceId,
+                                            const char *cloudUri,
+                                            OCCloudResponseCB callback)
 {
     char uri[MAX_URI_LENGTH]  = { 0 };
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(aclId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(aceId, TAG, "NULL aceId", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s/%s?%s=%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_ID_URL, aclId,
-            OC_RSRVD_ACE_ID, aceId);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s/%s?%s=%s", cloudUri, OC_RSRVD_ACL_ID_URL, aclId,
+             OC_RSRVD_ACE_ID, aceId);
 
     OCCallbackData cbData;
     fillCallbackData(&cbData, ctx, callback, NULL, NULL);
index 47cc033..5ad349e 100644 (file)
@@ -41,7 +41,8 @@
  * @param[out] out        string array pair to fill
  * @return  OCStackResult application result
  */
-static OCStackResult parseInvitePayload(const OCRepPayload *payload, const char *name, stringArrayPair_t *out)
+static OCStackResult parseInvitePayload(const OCRepPayload *payload, const char *name,
+                                        stringArrayPair_t *out)
 {
     OCStackResult result = OC_STACK_NO_MEMORY;
     size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 };
@@ -121,7 +122,8 @@ exit:
  * @param[in] response  peer response
  * @return  OCStackResult application result
  */
-static OCStackResult handleAclGetInvitationResponse(void *ctx, void **data, OCClientResponse *response)
+static OCStackResult handleAclGetInvitationResponse(void *ctx, void **data,
+        OCClientResponse *response)
 {
     OC_UNUSED(ctx);
     OCStackResult result = OC_STACK_OK;
@@ -166,7 +168,8 @@ exit:
  * @param[in] response  peer response
  * @return  OCStackResult application result
  */
-static OCStackResult handleAclPolicyCheckResponse(void *ctx, void **data, OCClientResponse *response)
+static OCStackResult handleAclPolicyCheckResponse(void *ctx, void **data,
+                                                  OCClientResponse *response)
 {
     OC_UNUSED(ctx);
 
@@ -178,7 +181,8 @@ static OCStackResult handleAclPolicyCheckResponse(void *ctx, void **data, OCClie
 
     char *gp = NULL;
 
-    if (!OCRepPayloadGetPropString((const OCRepPayload *)response->payload, OC_RSRVD_GROUP_PERMISSION, &gp))
+    if (!OCRepPayloadGetPropString((const OCRepPayload *)response->payload, OC_RSRVD_GROUP_PERMISSION,
+                                   &gp))
     {
         OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_GROUP_PERMISSION);
         return OC_STACK_MALFORMED_RESPONSE;
@@ -188,18 +192,18 @@ static OCStackResult handleAclPolicyCheckResponse(void *ctx, void **data, OCClie
     return OC_STACK_OK;
 }
 
-OCStackResult OCCloudAclInviteUser(voidctx,
+OCStackResult OCCloudAclInviteUser(void *ctx,
                                    const char *userId,
                                    const stringArray_t *groupIds,
                                    const stringArray_t *memberIds,
-                                   const OCDevAddr *endPoint,
+                                   const char *cloudUri,
                                    OCCloudResponseCB callback)
 {
     OCStackResult result = OC_STACK_ERROR;
     char uri[MAX_URI_LENGTH] = { 0 };
     size_t i = 0;
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(groupIds, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(memberIds, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
@@ -209,8 +213,7 @@ OCStackResult OCCloudAclInviteUser(void* ctx,
         return OC_STACK_INVALID_PARAM;
     }
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_INVITE_URL);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s", cloudUri, OC_RSRVD_ACL_INVITE_URL);
 
     OCCallbackData cbData;
     fillCallbackData(&cbData, ctx, callback, NULL, NULL);
@@ -246,7 +249,7 @@ OCStackResult OCCloudAclInviteUser(void* ctx,
     size_t dimensions[MAX_REP_ARRAY_DEPTH] = {0, 0, 0};
     dimensions[0] = groupIds->length;
     OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_INVITE,
-            (const struct OCRepPayload **)heplerPayload, dimensions);
+                                   (const struct OCRepPayload **)heplerPayload, dimensions);
 
     return OCDoResource(NULL, OC_REST_POST, uri, NULL, (OCPayload *)payload,
                         CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
@@ -260,22 +263,21 @@ no_memory:
     return result;
 }
 
-OCStackResult OCCloudAclGetInvitation(voidctx,
+OCStackResult OCCloudAclGetInvitation(void *ctx,
                                       const char *userId,
-                                      const OCDevAddr *endPoint,
+                                      const char *cloudUri,
                                       OCCloudResponseCB callback)
 {
     char uri[MAX_URI_LENGTH] = { 0 };
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_INVITE_URL);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s", cloudUri, OC_RSRVD_ACL_INVITE_URL);
 
     if (userId)
     {
         size_t len = strlen(uri);
-        snprintf(uri + len, MAX_URI_LENGTH -len, "?%s=%s", OC_RSRVD_USER_UUID, userId);
+        snprintf(uri + len, MAX_URI_LENGTH - len, "?%s=%s", OC_RSRVD_USER_UUID, userId);
     }
 
     OCCallbackData cbData;
@@ -285,19 +287,18 @@ OCStackResult OCCloudAclGetInvitation(void* ctx,
                         CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 }
 
-OCStackResult OCCloudAclDeleteInvitation(voidctx,
+OCStackResult OCCloudAclDeleteInvitation(void *ctx,
                                          const char *userId,
                                          const char *groupId,
-                                         const OCDevAddr *endPoint,
+                                         const char *cloudUri,
                                          OCCloudResponseCB callback)
 {
     char uri[MAX_URI_LENGTH] = { 0 };
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(groupId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_INVITE_URL);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s", cloudUri, OC_RSRVD_ACL_INVITE_URL);
 
     if (userId)
     {
@@ -306,7 +307,8 @@ OCStackResult OCCloudAclDeleteInvitation(void* ctx,
     }
 
     size_t len = strlen(uri);
-    snprintf(uri + len, MAX_URI_LENGTH - len, "%c%s=%s", userId?'&':'?', OC_RSRVD_GROUP_ID, groupId);
+    snprintf(uri + len, MAX_URI_LENGTH - len, "%c%s=%s", userId ? '&' : '?', OC_RSRVD_GROUP_ID,
+             groupId);
 
     OCCallbackData cbData;
     fillCallbackData(&cbData, ctx, callback, NULL, NULL);
@@ -315,22 +317,21 @@ OCStackResult OCCloudAclDeleteInvitation(void* ctx,
                         CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 }
 
-OCStackResult OCCloudAclCancelInvitation(voidctx,
+OCStackResult OCCloudAclCancelInvitation(void *ctx,
                                          const char *userId,
                                          const char *groupId,
                                          const char *memberId,
-                                         const OCDevAddr *endPoint,
+                                         const char *cloudUri,
                                          OCCloudResponseCB callback)
 {
     char uri[MAX_URI_LENGTH] = { 0 };
     size_t len = 0 ;
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(groupId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(memberId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_INVITE_URL);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s", cloudUri, OC_RSRVD_ACL_INVITE_URL);
 
     if (userId)
     {
@@ -339,7 +340,8 @@ OCStackResult OCCloudAclCancelInvitation(void* ctx,
     }
 
     len = strlen(uri);
-    snprintf(uri + len, MAX_URI_LENGTH - len, "%c%s=%s", userId?'&':'?', OC_RSRVD_GROUP_ID, groupId);
+    snprintf(uri + len, MAX_URI_LENGTH - len, "%c%s=%s", userId ? '&' : '?', OC_RSRVD_GROUP_ID,
+             groupId);
     len = strlen(uri);
     snprintf(uri + len, MAX_URI_LENGTH - len, "&%s=%s", OC_RSRVD_MEMBER_ID, memberId);
 
@@ -350,25 +352,24 @@ OCStackResult OCCloudAclCancelInvitation(void* ctx,
                         CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 }
 
-OCStackResult OCCloudAclPolicyCheck(voidctx,
+OCStackResult OCCloudAclPolicyCheck(void *ctx,
                                     const char *subjectId,
                                     const char *deviceId,
                                     const char *method,
                                     const char *user_uri,
-                                    const OCDevAddr *endPoint,
+                                    const char *cloudUri,
                                     OCCloudResponseCB callback)
 {
     char uri[MAX_URI_LENGTH] = { 0 };
     size_t len = 0;
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(subjectId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(deviceId, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(method, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(user_uri, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_ACL_VERIFY_URL);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s", cloudUri, OC_RSRVD_ACL_VERIFY_URL);
 
     len = strlen(uri);
     snprintf(uri + len, MAX_URI_LENGTH - len, "?%s=%s", OC_RSRVD_SUBJECT_ID, subjectId);
diff --git a/resource/csdk/security/provisioning/src/cloud/auth.c b/resource/csdk/security/provisioning/src/cloud/auth.c
new file mode 100644 (file)
index 0000000..e214eb4
--- /dev/null
@@ -0,0 +1,1004 @@
+/* *****************************************************************
+ *
+ * Copyright 2018 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 "octypes.h"
+#include "experimental/logger.h"
+#include "experimental/payload_logging.h"
+#include "ocstack.h"
+#include "ocpayload.h"
+#include "psinterface.h"
+#include "experimental/securevirtualresourcetypes.h"
+#include "experimental/doxmresource.h"
+#include "oic_malloc.h"
+#include "oic_string.h"
+#include "pmutility.h"
+#include "credresource.h"
+#include "experimental/payload_logging.h"
+#include "cacommonutil.h"
+#include "srmutility.h"
+
+#include "coap/utlist.h"
+
+#include "utils.h"
+#include "cloud/auth.h"
+#include "cloud/cloudresource.h"
+
+#include <time.h>
+
+#define TAG "OIC_CLOUD_RESOURCE_AUTH"
+
+#define LOGIN_OK 4
+
+static const int TIME_OUT_SHIFT = 3;
+
+
+#define CBOR_CLOUD_MAP_SIZE 3
+#define MAX_STR_LEN 2048
+
+const char *OIC_JSON_CLOUD_SESSION_ACCESS_TOKEN = "accesstoken";
+const char *OIC_JSON_CLOUD_SESSION_REFRESH_TOKEN = "refreshtoken";
+const char *OIC_JSON_CLOUD_SESSION_UID = "uid";
+
+#if !defined(__MANDATORY__)
+#define SESSION_CBOR_CLOUD_MAP_SIZE 4
+const char *OIC_JSON_CLOUD_SESSION_TOKEN_TYPE = "tokentype";
+const char *OIC_JSON_CLOUD_SESSION_REDIRECT_URL = "redirecturl";
+#else
+#define SESSION_CBOR_CLOUD_MAP_SIZE 3
+#endif // __MANDATORY__
+
+static const size_t CBOR_DEFAULT_SIZE = MAX_STR_LEN * (CBOR_CLOUD_MAP_SIZE +
+                                        SESSION_CBOR_CLOUD_MAP_SIZE);
+
+#define MAX_URI_QUERY MAX_URI_LENGTH + MAX_QUERY_LENGTH
+
+void SessionFree(session_t *session)
+{
+    if (NULL == session)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: session is NULL", __func__);
+        return;
+    }
+
+    OICFree(session->accessToken);
+    OICFree(session->refreshToken);
+    OICFree(session->uid);
+#if !defined(__MANDATORY__)
+    OICFree(session->redirectUri);
+#endif // __MANDATORY__
+}
+
+void FreeCloud(OicCloud_t *cloud)
+{
+    cloud->stat = OC_CLOUD_PROV;
+
+
+    if (cloud->pid)
+    {
+        OCThreadResult_t res = oc_thread_wait(cloud->pid);
+
+        if (OC_THREAD_SUCCESS != res)
+        {
+            OIC_LOG_V(ERROR, TAG, "oc_thread_wait failed - error %u", res);
+        }
+
+        res = oc_thread_free(cloud->pid);
+
+        if (OC_THREAD_SUCCESS != res)
+        {
+            OIC_LOG_V(ERROR, TAG, "oc_thread_free failed - error %u", res);
+        }
+    }
+
+    OICFree(cloud->apn);
+    OICFree(cloud->cis);
+    OICFree(cloud->at);
+
+    if (cloud->session)
+    {
+        SessionFree(cloud->session);
+    }
+
+    OICFree(cloud);
+}
+
+bool CloudFind(OicCloud_t *list, const OicCloud_t *cloud)
+{
+    if (!list || !cloud)
+    {
+        return false;
+    }
+
+    OicCloud_t *p1 = NULL, *p2 = NULL;
+    LL_FOREACH_SAFE(list, p1, p2)
+    {
+        if (0 == strcmp(p1->cis, cloud->cis))
+        {
+            return true;
+        }
+    }
+    return false;
+}
+
+
+static size_t CloudsCount(const OicCloud_t *clouds)
+{
+    size_t size = 0;
+    for (const OicCloud_t *cloud = clouds; cloud; cloud = cloud->next)
+    {
+        size++;
+    }
+    return size;
+}
+
+OCStackResult CloudSessionToCBORPayload(const session_t *session, CborEncoder *map)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+    VERIFY_NOT_NULL_RETURN(TAG, session, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, map, ERROR, OC_STACK_INVALID_PARAM);
+
+    OCStackResult ret = OC_STACK_ERROR;
+
+    CborError cborError = CborNoError;
+
+    cborError = cbor_encode_text_string(map, OIC_JSON_CLOUD_SESSION_ACCESS_TOKEN,
+                                        sizeof(OIC_JSON_CLOUD_SESSION_ACCESS_TOKEN) + 1);
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add tag: access token");
+    cborError = cbor_encode_text_string(map, session->accessToken, strnlen(session->accessToken,
+                                        MAX_STR_LEN));
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add value: access token");
+
+    cborError = cbor_encode_text_string(map, OIC_JSON_CLOUD_SESSION_REFRESH_TOKEN,
+                                        sizeof(OIC_JSON_CLOUD_SESSION_REFRESH_TOKEN) + 1);
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add tag: refresh token");
+    cborError = cbor_encode_text_string(map, session->refreshToken, strnlen(session->refreshToken,
+                                        MAX_STR_LEN));
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add value: refresh token");
+
+    cborError = cbor_encode_text_string(map, OIC_JSON_CLOUD_SESSION_UID,
+                                        sizeof(OIC_JSON_CLOUD_SESSION_UID) + 1);
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add tag: uid");
+    cborError = cbor_encode_text_string(map, session->uid, strnlen(session->uid, MAX_STR_LEN));
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add value: uid");
+
+#if !defined(__MANDATORY__)
+    cbor_encode_text_string(map, OIC_JSON_CLOUD_SESSION_REDIRECT_URL,
+                            sizeof(OIC_JSON_CLOUD_SESSION_REDIRECT_URL) + 1);
+    cbor_encode_text_string(map, session->redirectUri, strnlen(session->redirectUri, MAX_STR_LEN));
+#endif // __MANDATORY__
+
+    ret = OC_STACK_OK;
+exit:
+    if (CborNoError != cborError)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Failed", __func__);
+        ret = OC_STACK_ERROR;
+    }
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+    return ret;
+}
+
+OCStackResult CloudToCBORPayload(const OicCloud_t *clouds, uint8_t **payload, size_t *size)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    VERIFY_NOT_NULL_RETURN(TAG, clouds, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, size, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, payload, ERROR, OC_STACK_INVALID_PARAM);
+
+    if ( NULL != *payload)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: *payload is not NULL", __func__);
+        return OC_STACK_INVALID_PARAM;
+    }
+
+    size_t cborLen = *size;
+    if (0 == cborLen)
+    {
+        cborLen = CBOR_DEFAULT_SIZE;
+    }
+    *payload = NULL;
+    *size = 0;
+    OicCloud_t *cloud = (OicCloud_t *)clouds;
+
+    OCStackResult ret = OC_STACK_ERROR;
+
+    CborError cborError = CborNoError;
+
+    uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen);
+    VERIFY_NOT_NULL_RETURN(TAG, outPayload, ERROR, OC_STACK_ERROR);
+
+    CborEncoder encoder;
+    cbor_encoder_init(&encoder, outPayload, cborLen, 0);
+
+    CborEncoder rootMap;
+    cborError = cbor_encoder_create_map(&encoder, &rootMap, 1);
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add root map");
+
+    cborError = cbor_encode_text_string(&rootMap, OIC_JSON_CLOUDS_NAME,
+                                        sizeof(OIC_JSON_CLOUDS_NAME) + 1);
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add tag clouds");
+
+    CborEncoder cloudArray;
+    cborError = cbor_encoder_create_array(&rootMap, &cloudArray, CloudsCount(clouds));
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add array");
+
+    while (cloud)
+    {
+        CborEncoder map;
+        size_t mapSize = CBOR_CLOUD_MAP_SIZE + SESSION_CBOR_CLOUD_MAP_SIZE;
+        cborError = cbor_encoder_create_map(&cloudArray, &map, mapSize);
+        VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add map");
+
+        cborError = cbor_encode_text_string(&map, OIC_JSON_CLOUD_APN,
+                                            sizeof(OIC_JSON_CLOUD_APN) + 1);
+        VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add tag: apn");
+        cborError = cbor_encode_text_string(&map, cloud->apn, strnlen(cloud->apn, MAX_STR_LEN));
+        VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add value: apn");
+
+        cborError = cbor_encode_text_string(&map, OIC_JSON_CLOUD_CIS,
+                                            sizeof(OIC_JSON_CLOUD_CIS) + 1);
+        VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add tag: cis");
+        cborError = cbor_encode_text_string(&map, cloud->cis, strnlen(cloud->cis, MAX_STR_LEN));
+        VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add value: cis");
+
+        cborError = cbor_encode_text_string(&map, OIC_JSON_CLOUD_AT,
+                                            sizeof(OIC_JSON_CLOUD_AT) + 1);
+        VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add tag: at");
+        cborError = cbor_encode_text_string(&map, cloud->at, strnlen(cloud->at, MAX_STR_LEN));
+        VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add value: at");
+
+        if (cloud->session)
+        {
+            ret = CloudSessionToCBORPayload(cloud->session, &map);
+            if (OC_STACK_OK != ret)
+            {
+                OIC_LOG_V(ERROR, TAG, "%s: Failed convert session to cbor", __func__);
+                goto exit;
+            }
+        }
+
+        cborError = cbor_encoder_close_container(&cloudArray, &map);
+        VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed close cloud map");
+
+        cloud = cloud->next;
+    }
+    cborError = cbor_encoder_close_container(&rootMap, &cloudArray);
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed close array");
+
+    cborError = cbor_encoder_close_container(&encoder, &rootMap);
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed close root map");
+
+    if (CborNoError == cborError)
+    {
+        *size = cbor_encoder_get_buffer_size(&encoder, outPayload);
+        *payload = outPayload;
+        ret = OC_STACK_OK;
+    }
+exit:
+    if ((CborNoError != cborError) || (OC_STACK_OK != ret))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Failed", __func__);
+        OICFree(outPayload);
+        outPayload = NULL;
+        *payload = NULL;
+        *size = 0;
+        ret = OC_STACK_ERROR;
+    }
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+    return ret;
+}
+
+OCStackResult CBORPayloadToCloud(const uint8_t *cborPayload, size_t size, OicCloud_t **clouds)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    VERIFY_NOT_NULL_RETURN(TAG, cborPayload, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, clouds, ERROR, OC_STACK_INVALID_PARAM);
+
+    if (NULL != *clouds)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: *payload is not NULL", __func__);
+        return OC_STACK_INVALID_PARAM;
+    }
+
+    if (0 == size)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: zero size", __func__);
+        return OC_STACK_INVALID_PARAM;
+    }
+
+    OCStackResult ret = OC_STACK_ERROR;
+    CborValue cloudCbor = { NULL, NULL, 0, 0, 0, 0};
+    CborParser parser = { NULL, 0 };
+    CborError cborError = CborNoError;
+    char *mainSecName = NULL;
+    size_t len = 0;
+
+    cbor_parser_init(cborPayload, size, 0, &parser, &cloudCbor);
+
+    if (!cbor_value_is_container(&cloudCbor))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: it's not container", __func__);
+        return OC_STACK_ERROR;
+    }
+
+    CborValue rootMap = { NULL, NULL, 0, 0, 0, 0 };
+    cborError = cbor_value_enter_container(&cloudCbor, &rootMap);
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Cant't find root map");
+
+    while (cbor_value_is_valid(&rootMap))
+    {
+        CborType type = cbor_value_get_type(&rootMap);
+        if (type == CborTextStringType && cbor_value_is_text_string(&rootMap))
+        {
+            cborError = cbor_value_dup_text_string(&rootMap, &mainSecName, &len, NULL);
+            VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed find name root map");
+            cborError = cbor_value_advance(&rootMap);
+            VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed get value in root map");
+        }
+        else
+        {
+            OIC_LOG_V(ERROR, TAG, "%s: it's not string type", __func__);
+        }
+
+        if (0 == len || !mainSecName || strcmp(mainSecName, OIC_JSON_CLOUDS_NAME) != 0)
+        {
+            OIC_LOG_V(ERROR, TAG, "%s: Failed get main section", __func__);
+            continue;
+        }
+
+        CborValue cloudArray = { NULL, NULL, 0, 0, 0, 0 };
+        cborError = cbor_value_enter_container(&rootMap, &cloudArray);
+        VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed find cloud array");
+
+        while (cbor_value_is_valid(&cloudArray))
+        {
+
+            CborValue map = { NULL, NULL, 0, 0, 0, 0 };
+            cborError = cbor_value_enter_container(&cloudArray, &map);
+            VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed find cloud map");
+
+            OicCloud_t *cloud = (OicCloud_t *) OICCalloc(1, sizeof(OicCloud_t));
+            VERIFY_NOT_NULL(TAG, cloud, ERROR);
+
+            cloud->session = (session_t *) OICCalloc(1, sizeof(session_t));
+            VERIFY_NOT_NULL(TAG, cloud->session, ERROR);
+
+            LL_APPEND(*clouds, cloud);
+
+            char *name = NULL;
+            while (cbor_value_is_valid(&map) && cbor_value_is_text_string(&map))
+            {
+                CborType cmType = cbor_value_get_type(&map);
+                if (cmType == CborTextStringType)
+                {
+                    cborError = cbor_value_dup_text_string(&map, &name, &len, NULL);
+                    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed find name in map");
+                    cborError = cbor_value_advance(&map);
+                    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed advance map");
+                }
+
+                if (!name)
+                {
+                    if (cbor_value_is_valid(&map))
+                    {
+                        cborError = cbor_value_advance(&map);
+                        VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed find root map");
+                    }
+                    continue;
+                }
+
+                if (strncmp(name, OIC_JSON_CLOUD_APN, len)  == 0)
+                {
+                    cborError = cbor_value_dup_text_string(&map, &cloud->apn, &len, NULL);
+                    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed get apn value");
+                    goto next;
+                }
+                else if (strncmp(name, OIC_JSON_CLOUD_CIS, len)  == 0)
+                {
+                    cborError = cbor_value_dup_text_string(&map, &cloud->cis, &len, NULL);
+                    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed get cis value");
+                    goto next;
+                }
+                else if (strncmp(name, OIC_JSON_CLOUD_AT, len)  == 0)
+                {
+                    cborError = cbor_value_dup_text_string(&map, &cloud->at, &len, NULL);
+                    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed get at value");
+                    goto next;
+                }
+                else if (strncmp(name, OIC_JSON_CLOUD_SESSION_ACCESS_TOKEN, len)  == 0)
+                {
+                    cborError = cbor_value_dup_text_string(&map, &cloud->session->accessToken, &len, NULL);
+                    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed get access token value");
+                    goto next;
+                }
+                else if (strncmp(name, OIC_JSON_CLOUD_SESSION_REFRESH_TOKEN, len)  == 0)
+                {
+                    cborError = cbor_value_dup_text_string(&map, &cloud->session->refreshToken, &len, NULL);
+                    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed get refresh token value");
+                    goto next;
+                }
+                else if (strncmp(name, OIC_JSON_CLOUD_SESSION_UID, len)  == 0)
+                {
+                    cborError = cbor_value_dup_text_string(&map, &cloud->session->uid, &len, NULL);
+                    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed get uid value");
+                    goto next;
+                }
+#if !defined(__MANDATORY__)
+                else if (strncmp(name, OIC_JSON_CLOUD_SESSION_REDIRECT_URL, len)  == 0 && cloud->session)
+                {
+                    cbor_value_dup_text_string(&map, &cloud->session->redirectUri, &len, NULL);
+                    goto next;
+                }
+#endif // __MANDATORY__
+                else
+                {
+                    OIC_LOG_V(ERROR, TAG, "%s: not found: %s", __func__, name);
+                }
+
+next:
+                if (cbor_value_is_valid(&map))
+                {
+                    cborError = cbor_value_advance(&map);
+                    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed find map");
+                }
+                free(name);
+                name = NULL;
+            }
+
+            cloud->next = NULL;
+            if (cbor_value_is_valid(&cloudArray))
+            {
+                cborError = cbor_value_advance(&cloudArray);
+                VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed advance cloud array");
+            }
+        }
+
+        if (cbor_value_is_valid(&rootMap))
+        {
+            cborError = cbor_value_advance(&rootMap);
+            VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed advance root map");
+        }
+    }
+    ret = OC_STACK_OK;
+exit:
+    if ((CborNoError != cborError) || (OC_STACK_OK != ret))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Failed", __func__);
+        FreeCloud(*clouds);
+        *clouds = NULL;
+    }
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+    return ret;
+}
+
+
+extern OCStackResult OCCloudTokenRefresh(OicCloud_t *cloud);
+/**
+ * Sends token refreshto cloud
+ *
+ * @param[in] ctx                    context
+ * @param[in] handle                 handle
+ * @param[in] response               response from peer
+ * @return  OCStackApplicationResult application result
+ */
+static OCStackApplicationResult handleCloudTokenRefreshResponse(void *ctx,
+        OCDoHandle handle,
+        OCClientResponse *response)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    OC_UNUSED(handle);
+
+    VERIFY_NOT_NULL_RETURN(TAG, response, ERROR, OC_STACK_DELETE_TRANSACTION);
+    VERIFY_NOT_NULL_RETURN(TAG, response->payload, ERROR, OC_STACK_DELETE_TRANSACTION);
+#if !defined(NDEBUG)
+    OIC_LOG_PAYLOAD(DEBUG, response->payload);
+#endif
+
+    OicCloud_t *cloud = (OicCloud_t *)ctx;
+    VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR, OC_STACK_DELETE_TRANSACTION);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->session, ERROR, OC_STACK_DELETE_TRANSACTION);
+//TODO clarify response result code from cloud
+    /*
+        if (response->result)
+        {
+            OIC_LOG_V(ERROR, TAG, "%s: result response: %d", __func__, response->result);
+            SessionFree(cloud->session);
+            cloud->session = NULL;
+        }
+    */
+    if (!OCRepPayloadGetPropString((OCRepPayload *)response->payload, OC_RSRVD_REFRESH_TOKEN,
+                                   &cloud->session->refreshToken))
+    {
+        OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_REFRESH_TOKEN);
+    }
+    if (!OCRepPayloadGetPropString((OCRepPayload *)response->payload, OC_RSRVD_ACCESS_TOKEN,
+                                   &cloud->session->accessToken))
+    {
+        OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_ACCESS_TOKEN);
+    }
+    if (!OCRepPayloadGetPropInt((OCRepPayload *)response->payload, OC_RSRVD_EXPIRES_IN,
+                                &cloud->session->expireSin))
+    {
+        OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_EXPIRES_IN);
+    }
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+    return OC_STACK_DELETE_TRANSACTION;
+}
+
+OCStackResult OCCloudTokenRefresh(OicCloud_t *cloud)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    char uri[MAX_URI_LENGTH] = { 0 };
+    OCStackResult ret = OC_STACK_OK;
+
+    VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->cis, ERROR, OC_STACK_DELETE_TRANSACTION);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->session, ERROR, OC_STACK_DELETE_TRANSACTION);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->session->uid, ERROR, OC_STACK_DELETE_TRANSACTION);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->session->refreshToken, ERROR, OC_STACK_DELETE_TRANSACTION);
+
+    char *deviceId = getDeviceId();
+    VERIFY_NON_NULL_RET(deviceId, TAG, "Can't get the device id", OC_STACK_ERROR);
+
+    snprintf(uri, MAX_URI_LENGTH, "%s%s", cloud->cis, OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI);
+
+    OCRepPayload *payload = OCRepPayloadCreate();
+    VERIFY_NON_NULL_RET(payload, TAG, "Failed to allocate payload", OC_STACK_NO_MEMORY);
+
+    OCRepPayloadSetPropString(payload, OC_RSRVD_USER_UUID, cloud->session->uid);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_DEVICE_ID, deviceId);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ACCESS_TOKEN, cloud->session->refreshToken);
+
+    OCCallbackData cbData =
+    {
+        .context = (void *)cloud,
+        .cb = handleCloudTokenRefreshResponse,
+        .cd = NULL
+    };
+
+    ret = OCDoResource(NULL, OC_REST_POST, uri, NULL, (OCPayload *)payload,
+                       CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+
+    return ret;
+}
+
+static void *CloudTokenRefresh(void *data)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    OicCloud_t *cloud = (OicCloud_t *)data;
+    VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR, NULL);
+
+    OIC_LOG_V(INFO, TAG, "%s: cloud(%s) refresh start", __func__, cloud->cis);
+
+    cloud->stat = OC_CLOUD_TOKEN_REFRESH0;
+
+    while (OC_CLOUD_TOKEN_REFRESH4 > cloud->stat)
+    {
+        struct timespec timeout;
+        timeout.tv_sec  = cloud->session->expireSin - TIME_OUT_SHIFT;
+        timeout.tv_nsec = 0;
+
+        nanosleep(&timeout, NULL);
+
+        if (OC_STACK_OK != OCCloudTokenRefresh(cloud))
+        {
+            OIC_LOG_V(ERROR, TAG, "%s: token refresh", __func__);
+            cloud->stat++;
+        }
+    }
+
+    if (cloud->session)
+    {
+        SessionFree(cloud->session);
+        cloud->session = NULL;
+    }
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+    return NULL;
+}
+
+/**
+ * Sign In request to cloud handle
+ *
+ * @param[in] ctx                    context
+ * @param[in] handle                 handle
+ * @param[in] response               response from peer
+ * @return  OCStackApplicationResult application result
+ */
+static OCStackApplicationResult handleCloudSignInResponse(void *ctx,
+        OCDoHandle handle,
+        OCClientResponse *response)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    OC_UNUSED(handle);
+
+    VERIFY_NOT_NULL_RETURN(TAG, response, ERROR, OC_STACK_DELETE_TRANSACTION);
+
+    if (LOGIN_OK != response->result)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Sign In error: result: %d", __func__, response->result);
+        return OC_STACK_DELETE_TRANSACTION;
+    }
+
+    VERIFY_NOT_NULL_RETURN(TAG, response->payload, ERROR, OC_STACK_DELETE_TRANSACTION);
+
+#if !defined(NDEBUG)
+    OIC_LOG_PAYLOAD(DEBUG, response->payload);
+#endif
+
+    OicCloud_t *cloud = (OicCloud_t *)ctx;
+
+    VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR, OC_STACK_DELETE_TRANSACTION);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->session, ERROR, OC_STACK_DELETE_TRANSACTION);
+
+    if (!OCRepPayloadGetPropInt((OCRepPayload *)response->payload, OC_RSRVD_EXPIRES_IN,
+                                &cloud->session->expireSin))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Can't get: %s", __func__, OC_RSRVD_EXPIRES_IN);
+    }
+
+    OIC_LOG(INFO, TAG, "Sign In OK");
+
+    if (!UpdateCloudPersistentStorage())
+    {
+        OIC_LOG_V(WARNING, TAG, "%s: update cloud's persistent storage", __func__);
+    }
+
+    if (OC_CLOUD_SIGNIN == cloud->stat)
+    {
+        OCThreadResult_t res = OC_THREAD_SUCCESS;
+        res = oc_thread_new(&cloud->pid, CloudTokenRefresh, cloud);
+        if (OC_THREAD_SUCCESS != res)
+        {
+            OIC_LOG_V(ERROR, TAG, "%s: create thread: %d", __func__, res);
+        }
+    }
+    else
+    {
+        cloud->stat = OC_CLOUD_ERROR_SIGNIN;
+        OIC_LOG_V(ERROR, TAG, "%s: cloud status: %s", __func__, GetCloudStatus(cloud));
+    }
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+    return OC_STACK_DELETE_TRANSACTION;
+}
+
+/**
+ * Sign Out request to cloud handle
+ *
+ * @param[in] ctx                    context
+ * @param[in] handle                 handle
+ * @param[in] response               response from peer
+ * @return  OCStackApplicationResult application result
+ */
+static OCStackApplicationResult handleCloudSignOutResponse(void *ctx,
+        OCDoHandle handle,
+        OCClientResponse *response)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    OC_UNUSED(handle);
+
+    OicCloud_t *cloud = (OicCloud_t *)ctx;
+
+    OCStackApplicationResult ret = OC_STACK_DELETE_TRANSACTION;
+
+    VERIFY_NOT_NULL_RETURN(TAG, response, ERROR, OC_STACK_DELETE_TRANSACTION);
+    VERIFY_NOT_NULL_RETURN(TAG, response->payload, ERROR, OC_STACK_DELETE_TRANSACTION);
+
+//TODO clarify response result code from cloud
+    /*    if (response->result != LOGIN_OK)
+        {
+            OIC_LOG(ERROR, TAG, "Sign Out error");
+            cloud->stat = OC_CLOUD_ERROR_SIGNOUT;
+        }
+    */
+    OIC_LOG(INFO, TAG, "Sign Out OK");
+    SessionFree(cloud->session);
+    cloud->session = NULL;
+    cloud->stat = OC_CLOUD_PROV;
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+
+    return ret;
+}
+
+/**
+ * Sends Sign In/Out request to cloud
+ *
+ * @param[in] cloud
+ * @param[in] signIn                 is it Sign In or Sign Out request
+ * @return  OCStackApplicationResult application result
+ */
+static OCStackResult CloudSign(OicCloud_t *cloud, bool signIn)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->cis, ERROR, OC_STACK_DELETE_TRANSACTION);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->session, ERROR, OC_STACK_DELETE_TRANSACTION);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->session->uid, ERROR, OC_STACK_DELETE_TRANSACTION);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->session->accessToken, ERROR, OC_STACK_DELETE_TRANSACTION);
+
+    OCStackResult ret = OC_STACK_OK;
+    char uri[MAX_URI_QUERY] = { 0 };
+
+    char *deviceId = getDeviceId();
+    VERIFY_NOT_NULL_RETURN(TAG, deviceId, ERROR, OC_STACK_DELETE_TRANSACTION);
+
+    OCRepPayload *payload = OCRepPayloadCreate();
+    VERIFY_NOT_NULL_RETURN(TAG, payload, ERROR, OC_STACK_DELETE_TRANSACTION);
+
+    OCRepPayloadSetPropString(payload, OC_RSRVD_DEVICE_ID, deviceId);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_USER_UUID, cloud->session->uid);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ACCESS_TOKEN, cloud->session->accessToken);
+    OCRepPayloadSetPropBool(payload, OC_RSRVD_LOGIN, signIn);
+
+    snprintf(uri, MAX_URI_QUERY, "%s/%s", cloud->cis, OC_RSRVD_ACCOUNT_SESSION_URI);
+
+    OCCallbackData cbData =
+    {
+        .context = (void *)cloud,
+        .cb = signIn ? handleCloudSignInResponse : handleCloudSignOutResponse,
+        .cd = NULL
+    };
+
+    if (signIn && OC_CLOUD_SIGNUP != cloud->stat)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: cloud status: %s", __func__, GetCloudStatus(cloud));
+        cloud->stat = OC_CLOUD_ERROR_SIGNIN;
+        return OC_STACK_ERROR;
+    }
+
+    cloud->stat = signIn ? OC_CLOUD_SIGNIN : OC_CLOUD_SIGNOUT;
+
+    ret = OCDoResource(NULL, OC_REST_POST, uri, NULL, (OCPayload *)payload,
+                       CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+    return ret;
+}
+
+OCStackResult OCCloudSignIn(OicCloud_t *cloud)
+{
+    return CloudSign(cloud, true);
+}
+
+OCStackResult OCCloudSignOut(OicCloud_t *cloud)
+{
+    return CloudSign(cloud, false);
+}
+
+/**
+ * Session parse payload
+ *
+ * @param[in] payload
+ * @param[in] session session data
+ * @return  OCStackResult application result
+ */
+static bool SessionParsePayload(OCRepPayload *payload, session_t *session)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+    bool ret = true;
+    VERIFY_NOT_NULL_RETURN(TAG, payload, ERROR, OC_STACK_DELETE_TRANSACTION);
+
+    if (!OCRepPayloadGetPropString(payload, OC_RSRVD_ACCESS_TOKEN,
+                                   &session->accessToken))
+    {
+        OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_ACCESS_TOKEN);
+        ret = false;
+    }
+    if (!OCRepPayloadGetPropString(payload, OC_RSRVD_REFRESH_TOKEN,
+                                   &session->refreshToken))
+    {
+        OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_REFRESH_TOKEN);
+        ret = false;
+    }
+    if (!OCRepPayloadGetPropInt(payload, OC_RSRVD_EXPIRES_IN, &session->expireSin))
+    {
+        OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_EXPIRES_IN);
+        ret = false;
+    }
+    if (!OCRepPayloadGetPropString(payload, OC_RSRVD_USER_UUID,
+                                   &session->uid))
+    {
+        OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_USER_UUID);
+        ret = false;
+    }
+#if defined(__MANDATORY__)
+    if (!OCRepPayloadGetPropString(payload, OC_RSRVD_REDIRECT_URI,
+                                   &session->redirectUri))
+    {
+        OIC_LOG_V(WARNING, TAG, "Can't get: %s", OC_RSRVD_REDIRECT_URI);
+    }
+#endif // __MANDATORY__
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+    return ret;
+}
+
+/**
+ * Sends Sign Up request to cloud
+ *
+ * @param[in] ctx                    context
+ * @param[in] handle                 handle
+ * @param[in] response               response from peer
+ * @return  OCStackApplicationResult application result
+ */
+static OCStackApplicationResult handleCloudSignUpResponse(void *ctx,
+        OCDoHandle handle,
+        OCClientResponse *response)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    OC_UNUSED(handle);
+    OCStackApplicationResult ret = OC_STACK_DELETE_TRANSACTION;
+    OicCloud_t *cloud = (OicCloud_t *)ctx;
+
+    VERIFY_NOT_NULL_RETURN(TAG, response, ERROR, OC_STACK_DELETE_TRANSACTION);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR, OC_STACK_DELETE_TRANSACTION);
+
+    if (LOGIN_OK != response->result)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Login error: %d", __func__, response->result);
+        cloud->stat = OC_CLOUD_ERROR_SIGNUP;
+        goto exit;
+    }
+
+    if (NULL == response->payload)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Paylod is NULL", __func__);
+        cloud->stat = OC_CLOUD_ERROR_SIGNUP;
+        goto exit;
+    }
+
+#if !defined(NDEBUG)
+    OIC_LOG_PAYLOAD(DEBUG, response->payload);
+#endif
+
+    if (NULL != cloud->session)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: session is run", __func__);
+        cloud->stat = OC_CLOUD_ERROR_CHECK_SESSION;
+        goto exit;
+    }
+
+    cloud->session = (session_t *)OICCalloc(1, sizeof(session_t));
+
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->session, ERROR, OC_STACK_DELETE_TRANSACTION);
+
+    if (!SessionParsePayload((OCRepPayload *)response->payload, cloud->session))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: parse payload", __func__);
+        SessionFree(cloud->session);
+        cloud->stat = OC_CLOUD_ERROR_CREATE_SESSION;
+        goto exit;
+    }
+
+    OIC_LOG_V(INFO, TAG, "%s: Sign Up OK", __func__);
+    OCCloudSignIn(cloud);
+exit:
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+    return ret;
+}
+
+OCStackResult OCCloudSignUp(OicCloud_t *cloud)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    char uri[MAX_URI_LENGTH] = { 0 };
+    OCStackResult ret = OC_STACK_OK;
+
+    VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->cis, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->apn, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->at, ERROR, OC_STACK_INVALID_PARAM);
+
+    if (OC_CLOUD_PROV != cloud->stat)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: cloud state: %s", __func__, GetCloudStatus(cloud));
+        return OC_STACK_ERROR;
+    }
+
+    char *deviceId = getDeviceId();
+    VERIFY_NON_NULL_RET(deviceId, TAG, "Can't get the device id", OC_STACK_ERROR);
+
+    snprintf(uri, MAX_URI_LENGTH, "%s%s", cloud->cis, OC_RSRVD_ACCOUNT_URI);
+
+    OCRepPayload *payload = OCRepPayloadCreate();
+    VERIFY_NON_NULL_RET(payload, TAG, "Failed to allocate payload", OC_STACK_NO_MEMORY);
+
+    OCRepPayloadSetPropString(payload, OC_RSRVD_DEVICE_ID, deviceId);
+#if !defined(__MANDATORY__)
+    OCRepPayloadSetPropString(payload, OC_RSRVD_AUTHPROVIDER, cloud->apn);
+#endif // __MANDATORY__
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ACCESS_TOKEN, cloud->at);
+
+    OCCallbackData cbData =
+    {
+        .context = (void *)cloud,
+        .cb = handleCloudSignUpResponse,
+        .cd = NULL
+    };
+
+    cloud->stat = OC_CLOUD_SIGNUP;
+
+    ret = OCDoResource(NULL, OC_REST_POST, uri, NULL, (OCPayload *)payload,
+                       CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
+
+    OIC_LOG_V(INFO, TAG, "%s: cloud(%s) sign in", __func__, cloud->cis);
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+
+    return ret;
+}
+
+const char *GetCloudStatus(const OicCloud_t *cloud)
+{
+    switch (cloud->stat)
+    {
+        case OC_CLOUD_OK:
+            return "Ok";
+        case OC_CLOUD_PROV:
+            return "Cloud provisioned";
+        case OC_CLOUD_SIGNUP:
+            return "Sign up";
+        case OC_CLOUD_SIGNIN:
+            return "Sign in";
+        case OC_CLOUD_SIGNOUT:
+            return "Sign out";
+        case OC_CLOUD_TOKEN_REFRESH0:
+            return "Token refresh 0";
+        case OC_CLOUD_TOKEN_REFRESH1:
+            return "Token refresh 1";
+        case OC_CLOUD_TOKEN_REFRESH2:
+            return "Token refresh 2";
+        case OC_CLOUD_TOKEN_REFRESH3:
+            return "Token refresh 3";
+        case OC_CLOUD_TOKEN_REFRESH4:
+            return "Token refresh 4";
+        case OC_CLOUD_ERROR_SIGNOUT:
+            return "Error sign out";
+        case OC_CLOUD_ERROR_SIGNIN:
+            return "Error sign in";
+        case OC_CLOUD_ERROR_CREATE_SESSION:
+            return "Error create session";
+        case OC_CLOUD_ERROR_CHECK_SESSION:
+            return "Error check session";
+        case OC_CLOUD_ERROR_SIGNUP:
+            return "Error sign up";
+        case OC_CLOUD_ERROR:
+            return "Error";
+        case OC_CLOUD_EXIT:
+            return "Exit";
+        default:
+            return "unknown";
+    }
+}
diff --git a/resource/csdk/security/provisioning/src/cloud/cloudresource.c b/resource/csdk/security/provisioning/src/cloud/cloudresource.c
new file mode 100644 (file)
index 0000000..4b47cad
--- /dev/null
@@ -0,0 +1,672 @@
+/* *****************************************************************
+ *
+ * Copyright 2018 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 "iotivity_config.h"
+#include "iotivity_debug.h"
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "octypes.h"
+#include "oic_malloc.h"
+#include "utlist.h"
+#include "experimental/logger.h"
+#include "ocpayload.h"
+#include "ocpayloadcbor.h"
+#include "srmutility.h"
+#include "psinterface.h"
+#include "deviceonboardingstate.h"
+#include "srmresourcestrings.h"
+#include "resourcemanager.h"
+#include "cloud/cloudresource.h"
+#include "cloud/auth.h"
+
+#define TAG  "OIC_CLOUD_RESOURCE"
+
+static OicCloud_t           *gCloud = NULL;
+static OCResourceHandle     gCloudHandle = NULL;
+
+static oc_mutex     gCloudMutex;
+
+#define OC_CLOUD_PROVISIONING_APN   "apn"
+#define OC_CLOUD_PROVISIONING_CIS   "cis"
+#define OC_CLOUD_PROVISIONING_AT    "at"
+
+#define OIC_JSON_CLOUD_CLEC         "clec"
+
+static const size_t CBOR_DEFAULT_SIZE = 512;
+
+static OicCloud_t gDefaultCloud =
+{
+    NULL,
+    NULL,
+    NULL,
+    OC_CLOUD_OK,
+    NULL,
+    NULL,
+    NULL
+};
+
+static bool ValidCloud(OicCloud_t *cloud)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR, false);
+
+    bool ret = true;
+
+    if (!cloud->apn)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Authorization Provider Name validate: %s", __func__,
+                  cloud->apn ? cloud->apn : "NULL");
+        ret = false;
+    }
+    if (!cloud->cis || 0 != strncmp(cloud->cis, "coaps+tcp://", 11))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: OCF Cloud URL validate: %s", __func__, cloud->cis ? cloud->cis : "NULL");
+        ret = false;
+    }
+    if (!cloud->at)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Access token validate: %s", __func__, cloud->at ? cloud->at : "NULL");
+        ret = false;
+    }
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+    return ret;
+}
+
+static void DeleteCloudList(OicCloud_t *clouds)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    if (!clouds)
+    {
+        OIC_LOG_V(WARNING, TAG, "%s: cloud is NULL", __func__);
+        return;
+    }
+
+    OicCloud_t *p1 = NULL, *p2 = NULL;
+    oc_mutex_lock(gCloudMutex);
+    LL_FOREACH_SAFE(clouds, p1, p2)
+    {
+        LL_DELETE(clouds, p1);
+        FreeCloud(p1);
+        p1 = NULL;
+    }
+    oc_mutex_unlock(gCloudMutex);
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+}
+
+static void *CloudWaitForRFPRO(void *data)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+    OicSecDostype_t dos;
+
+    OicCloud_t *cloud = (OicCloud_t *)data;
+    VERIFY_NOT_NULL(TAG, cloud, ERROR);
+
+    VERIFY_SUCCESS(TAG, OC_STACK_OK == GetDos(&dos), ERROR);
+
+    while (DOS_RFPRO != dos.state && OC_CLOUD_EXIT != cloud->stat)
+    {
+        VERIFY_SUCCESS(TAG, OC_STACK_OK == GetDos(&dos), ERROR);
+        sleep(1);
+    }
+
+    if (OC_STACK_OK != OCCloudSignUp(cloud))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: cloud sign up", __func__);
+    }
+exit:
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+    return NULL;
+}
+
+static OCEntityHandlerResult HandleCloudPostRequest(OCEntityHandlerRequest *ehRequest)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+    OCEntityHandlerResult ehRet = OC_EH_INTERNAL_SERVER_ERROR;
+    OicSecDostype_t dos;
+    OicCloud_t *newCloud = NULL;
+    OCRepPayload *payload = NULL;
+    bool isDeviceOwned = false;
+
+    VERIFY_NOT_NULL(TAG, ehRequest, ERROR);
+    VERIFY_NOT_NULL(TAG, ehRequest->payload, ERROR);
+
+    VERIFY_SUCCESS(TAG, OC_STACK_OK == GetDos(&dos), ERROR);
+
+    if (DOS_RFNOP != dos.state && DOS_RFPRO != dos.state)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s %s resource is read-only in not RFNOP or DOS_RFPRO", __func__,
+                  OIC_RSRC_TYPE_SEC_CLOUDCONF);
+        ehRet = OC_EH_NOT_ACCEPTABLE;
+        goto exit;
+    }
+
+    OCGetDeviceOwnedState(&isDeviceOwned);
+
+    if (!isDeviceOwned)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: device is not owned", __func__);
+        ehRet = OC_EH_NOT_ACCEPTABLE;
+        goto exit;
+    }
+
+    newCloud = (OicCloud_t *) OICCalloc(1, sizeof(OicCloud_t));
+    VERIFY_NOT_NULL(TAG, newCloud, ERROR);
+
+    payload = (OCRepPayload *)ehRequest->payload;
+
+    if (!OCRepPayloadGetPropString(payload, OC_CLOUD_PROVISIONING_APN, &newCloud->apn))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Can't get: %s", __func__, OC_CLOUD_PROVISIONING_APN);
+        goto exit;
+    }
+    if (!OCRepPayloadGetPropString(payload, OC_CLOUD_PROVISIONING_CIS, &newCloud->cis))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Can't get: %s", __func__, OC_CLOUD_PROVISIONING_CIS);
+        goto exit;
+    }
+    if (!OCRepPayloadGetPropString(payload, OC_CLOUD_PROVISIONING_AT, &newCloud->at))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Can't get: %s", __func__, OC_CLOUD_PROVISIONING_AT);
+        goto exit;
+    }
+
+    if (!ValidCloud(newCloud))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Error validate the new cloud", __func__);
+        goto exit;
+    }
+
+    if (CloudFind(gCloud, newCloud))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: cloud: %s exist", __func__, newCloud->cis);
+        goto exit;
+    }
+
+    newCloud->stat = OC_CLOUD_PROV;
+
+    oc_mutex_lock(gCloudMutex);
+    LL_APPEND(gCloud, newCloud);
+    oc_mutex_unlock(gCloudMutex);
+
+    if (DOS_RFNOP == dos.state)
+    {
+        if (OC_STACK_OK != OCCloudSignUp(newCloud))
+        {
+            OIC_LOG_V(ERROR, TAG, "%s: cloud sign up", __func__);
+        }
+    }
+    else
+    {
+        OCThreadResult_t res = OC_THREAD_SUCCESS;
+        res = oc_thread_new(&newCloud->pid, CloudWaitForRFPRO, newCloud);
+        if (OC_THREAD_SUCCESS != res)
+        {
+            OIC_LOG_V(ERROR, TAG, "%s: create thread: %d", __func__, res);
+        }
+    }
+
+    ehRet = OC_EH_OK;
+exit:
+    ehRet = ((SendSRMResponse(ehRequest, ehRet, NULL, 0)) == OC_STACK_OK) ?
+            OC_EH_OK : OC_EH_ERROR;
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+
+    return ehRet;
+}
+
+OCStackResult CloudGetRequestPayloadCreate(int cloudState, uint8_t **payload, size_t *size)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    VERIFY_NOT_NULL_RETURN(TAG, size, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, payload, ERROR, OC_STACK_INVALID_PARAM);
+
+    if ( NULL != *payload)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: *payload is not NULL", __func__);
+        return OC_STACK_INVALID_PARAM;
+    }
+
+    size_t cborLen = *size;
+    if (0 == cborLen)
+    {
+        cborLen = CBOR_DEFAULT_SIZE;
+    }
+    *payload = NULL;
+    *size = 0;
+
+    OCStackResult ret = OC_STACK_ERROR;
+
+    CborError cborError = CborNoError;
+
+    uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen);
+    VERIFY_NOT_NULL_RETURN(TAG, outPayload, ERROR, OC_STACK_ERROR);
+
+    CborEncoder encoder;
+    cbor_encoder_init(&encoder, outPayload, cborLen, 0);
+
+    CborEncoder rootMap;
+    cborError = cbor_encoder_create_map(&encoder, &rootMap, 1);
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add root map");
+
+    cborError = cbor_encode_text_string(&rootMap, OIC_JSON_CLOUD_CLEC,
+                                        sizeof(OIC_JSON_CLOUD_CLEC) + 1);
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add tag: clec");
+
+    cborError = cbor_encode_int(&rootMap, cloudState);
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add value: clec");
+
+    cborError = cbor_encoder_close_container(&encoder, &rootMap);
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed close root map");
+
+    if (CborNoError == cborError)
+    {
+        *size = cbor_encoder_get_buffer_size(&encoder, outPayload);
+        *payload = outPayload;
+        ret = OC_STACK_OK;
+    }
+exit:
+    if ((CborNoError != cborError) || (OC_STACK_OK != ret))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Failed", __func__);
+        OICFree(outPayload);
+        outPayload = NULL;
+        *payload = NULL;
+        *size = 0;
+        ret = OC_STACK_ERROR;
+    }
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+    return ret;
+}
+
+OCStackResult CloudGetRequestPayloadParse(const uint8_t *cborPayload, size_t size, int *cloudState)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    VERIFY_NOT_NULL_RETURN(TAG, cborPayload, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, cloudState, ERROR, OC_STACK_INVALID_PARAM);
+
+    if (0 == size)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: zero size", __func__);
+        return OC_STACK_INVALID_PARAM;
+    }
+
+    OCStackResult ret = OC_STACK_ERROR;
+    CborValue cloudCbor = { NULL, NULL, 0, 0, 0, 0};
+    CborParser parser = { NULL, 0 };
+    CborError cborError = CborNoError;
+    char *name = NULL;
+    size_t len = 0;
+
+    cbor_parser_init(cborPayload, size, 0, &parser, &cloudCbor);
+
+    if (!cbor_value_is_container(&cloudCbor))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: it's not container", __func__);
+        return OC_STACK_ERROR;
+    }
+
+    CborValue map = { NULL, NULL, 0, 0, 0, 0 };
+    cborError = cbor_value_enter_container(&cloudCbor, &map);
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Cant't find root map");
+
+    cborError = cbor_value_dup_text_string(&map, &name, &len, NULL);
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed find name in map");
+
+    if (0 == len || NULL == name || 0 != strncmp(name, OIC_JSON_CLOUD_CLEC, len))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: wrong name", __func__);
+        goto exit;
+    }
+
+    cborError = cbor_value_advance(&map);
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed move");
+
+    cborError = cbor_value_get_int(&map, cloudState);
+    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed get cloud state");
+
+    ret = OC_STACK_OK;
+exit:
+    if ((CborNoError != cborError) || (OC_STACK_OK != ret))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Failed", __func__);
+    }
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+    return ret;
+}
+
+
+static OCEntityHandlerResult HandleCloudGetRequest(OCEntityHandlerRequest *ehRequest)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+    OCEntityHandlerResult ehRet = OC_EH_INTERNAL_SERVER_ERROR;
+    OicCloud_t *newCloud = NULL;
+    OCRepPayload *payload = NULL;
+    bool isDeviceOwned = false;
+    uint8_t *payloadResponse = NULL;
+    size_t sizeResponse = 0;
+    OicCloud_t *p1 = NULL, *p2 = NULL;
+
+    VERIFY_NOT_NULL(TAG, ehRequest, ERROR);
+    VERIFY_NOT_NULL(TAG, ehRequest->payload, ERROR);
+
+    OCGetDeviceOwnedState(&isDeviceOwned);
+
+    if (!isDeviceOwned)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: device is not owned", __func__);
+        ehRet = OC_EH_NOT_ACCEPTABLE;
+        goto exit;
+    }
+
+    newCloud = (OicCloud_t *) OICCalloc(1, sizeof(OicCloud_t));
+    VERIFY_NOT_NULL(TAG, newCloud, ERROR);
+
+    payload = (OCRepPayload *)ehRequest->payload;
+
+    if (!OCRepPayloadGetPropString(payload, OC_CLOUD_PROVISIONING_CIS, &newCloud->cis))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Can't get: %s", __func__, OC_CLOUD_PROVISIONING_CIS);
+        goto exit;
+    }
+    if (!OCRepPayloadGetPropString(payload, OC_CLOUD_PROVISIONING_APN, &newCloud->apn))
+    {
+        OIC_LOG_V(WARNING, TAG, "%s: Can't get: %s", __func__, OC_CLOUD_PROVISIONING_APN);
+    }
+    if (!OCRepPayloadGetPropString(payload, OC_CLOUD_PROVISIONING_AT, &newCloud->at))
+    {
+        OIC_LOG_V(WARNING, TAG, "%s: Can't get: %s", __func__, OC_CLOUD_PROVISIONING_AT);
+    }
+
+    LL_FOREACH_SAFE(gCloud, p1, p2)
+    {
+        if (0 == strcmp(p1->cis, newCloud->cis))
+        {
+            if (OC_STACK_OK != CloudGetRequestPayloadCreate(p1->stat, &payloadResponse, &sizeResponse))
+            {
+                OIC_LOG_V(ERROR, TAG, "%s: Error create cbor", __func__);
+                goto exit;
+            }
+            break;
+        }
+    }
+
+    if (0 == sizeResponse)
+    {
+        ehRet = OC_EH_RESOURCE_NOT_FOUND;
+    }
+    else
+    {
+        ehRet = OC_EH_OK;
+    }
+exit:
+    ehRet = ((SendSRMResponse(ehRequest, ehRet, payloadResponse, sizeResponse)) == OC_STACK_OK) ?
+            OC_EH_OK : OC_EH_ERROR;
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+
+    return ehRet;
+}
+
+static OCEntityHandlerResult HandleCloudDeleteRequest(OCEntityHandlerRequest *ehRequest)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+    OCEntityHandlerResult ehRet = OC_EH_INTERNAL_SERVER_ERROR;
+    OicCloud_t *newCloud = NULL;
+    OCRepPayload *payload = NULL;
+    bool isDeviceOwned = false;
+    OicCloud_t *p1 = NULL, *p2 = NULL;
+
+    VERIFY_NOT_NULL(TAG, ehRequest, ERROR);
+    VERIFY_NOT_NULL(TAG, ehRequest->payload, ERROR);
+
+    OCGetDeviceOwnedState(&isDeviceOwned);
+
+    if (!isDeviceOwned)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: device is not owned", __func__);
+        ehRet = OC_EH_NOT_ACCEPTABLE;
+        goto exit;
+    }
+
+    newCloud = (OicCloud_t *) OICCalloc(1, sizeof(OicCloud_t));
+    VERIFY_NOT_NULL(TAG, newCloud, ERROR);
+
+    payload = (OCRepPayload *)ehRequest->payload;
+
+    if (!OCRepPayloadGetPropString(payload, OC_CLOUD_PROVISIONING_CIS, &newCloud->cis))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Can't get: %s", __func__, OC_CLOUD_PROVISIONING_CIS);
+        goto exit;
+    }
+    if (!OCRepPayloadGetPropString(payload, OC_CLOUD_PROVISIONING_APN, &newCloud->apn))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Can't get: %s", __func__, OC_CLOUD_PROVISIONING_APN);
+    }
+    if (!OCRepPayloadGetPropString(payload, OC_CLOUD_PROVISIONING_AT, &newCloud->at))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Can't get: %s", __func__, OC_CLOUD_PROVISIONING_AT);
+    }
+
+    LL_FOREACH_SAFE(gCloud, p1, p2)
+    {
+        if (0 == strcmp(p1->cis, newCloud->cis))
+        {
+            OIC_LOG_V(INFO, TAG, "%s: delete cloud: %s", __func__, p1->cis);
+            p1->stat = OC_CLOUD_EXIT;
+            LL_DELETE(gCloud, p1);
+            break;
+        }
+    }
+
+    ehRet = OC_EH_OK;
+exit:
+    ehRet = ((SendSRMResponse(ehRequest, ehRet, NULL, 0)) == OC_STACK_OK) ?
+            OC_EH_OK : OC_EH_ERROR;
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+
+    return ehRet;
+}
+
+
+OCEntityHandlerResult CloudEntityHandler(OCEntityHandlerFlag flag,
+        OCEntityHandlerRequest *ehRequest, void *callbackParam)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    OC_UNUSED(callbackParam);
+
+    VERIFY_NOT_NULL_RETURN(TAG, ehRequest, ERROR, OC_EH_ERROR);
+
+    OCEntityHandlerResult ehRet = OC_EH_ERROR;
+
+    if (flag & OC_REQUEST_FLAG)
+    {
+        switch (ehRequest->method)
+        {
+            case OC_REST_POST:
+                ehRet = HandleCloudPostRequest(ehRequest);
+                break;
+            case OC_REST_GET:
+                ehRet = HandleCloudGetRequest(ehRequest);
+                break;
+            case OC_REST_DELETE:
+                ehRet = HandleCloudDeleteRequest(ehRequest);
+                break;
+            default:
+                OIC_LOG_V(WARNING, TAG, "%s: Unknow request: %d", __func__, ehRequest->method);
+                usleep(300000);
+                ehRet = ((SendSRMResponse(ehRequest, ehRet, NULL, 0)) == OC_STACK_OK) ?
+                        OC_EH_OK : OC_EH_ERROR;
+                break;
+        }
+    }
+    else
+    {
+        OIC_LOG_V(WARNING, TAG, "%s: Flag  does not includes OC_REQUEST_FLAG", __func__);
+    }
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+    return ehRet;
+}
+
+OCStackResult CreateCloudResource()
+{
+    OCStackResult ret = OCCreateResource(&gCloudHandle,
+                                         OIC_RSRC_TYPE_SEC_CLOUDCONF,
+                                         OC_RSRVD_INTERFACE_DEFAULT,
+                                         OIC_RSRC_CLOUDCONF_URI,
+                                         CloudEntityHandler,
+                                         NULL,
+                                         OC_SECURE | OC_NONSECURE |
+                                         OC_DISCOVERABLE);
+
+    if (OC_STACK_OK != ret)
+    {
+        OIC_LOG (FATAL, TAG, "Unable to create cloud config resource");
+        DeInitCloudResource();
+    }
+    return ret;
+}
+
+OCStackResult DeInitCloudResource()
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    OCStackResult ret = OCDeleteResource(gCloudHandle);
+    if (gCloud  != &gDefaultCloud)
+    {
+        DeleteCloudList(gCloud);
+    }
+
+    oc_mutex_free(gCloudMutex);
+
+    gCloud = NULL;
+
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    if (OC_STACK_OK == ret)
+    {
+        return OC_STACK_OK;
+    }
+    else
+    {
+        return OC_STACK_ERROR;
+    }
+}
+
+static void StartClouds()
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+    bool isDeviceOwned = false;
+
+    OCGetDeviceOwnedState(&isDeviceOwned);
+
+    if (!isDeviceOwned)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: device is not owned", __func__);
+        return;
+    }
+
+    OicCloud_t *p1 = NULL, *p2 = NULL;
+    LL_FOREACH_SAFE(gCloud, p1, p2)
+    {
+        if (OC_CLOUD_PROV == p1->stat)
+        {
+            if (OC_STACK_OK != OCCloudSignUp(p1))
+            {
+                OIC_LOG_V(ERROR, TAG, "%s: cloud sign up", __func__);
+            }
+        }
+    }
+
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+}
+
+OCStackResult InitCloudResource()
+{
+    uint8_t *data = NULL;
+    size_t size = 0;
+
+    gCloudMutex = oc_mutex_new();
+
+    if (OC_STACK_OK != GetSecureVirtualDatabaseFromPS(OIC_JSON_CLOUDS_NAME, &data, &size))
+    {
+        OIC_LOG (WARNING, TAG, "There is no cloud data in database");
+    }
+    else
+    {
+        if (data)
+        {
+            oc_mutex_lock(gCloudMutex);
+            if (OC_STACK_OK != CBORPayloadToCloud(data, size, &gCloud))
+            {
+                OIC_LOG (WARNING, TAG, "There is no cloud data in database");
+            }
+            else
+            {
+                StartClouds();
+            }
+            oc_mutex_unlock(gCloudMutex);
+        }
+    }
+
+    return CreateCloudResource();
+}
+
+bool UpdateCloudPersistentStorage()
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    VERIFY_NOT_NULL_RETURN(TAG, gCloud, ERROR, false);
+
+    bool ret = false;
+    uint8_t *payload = NULL;
+    size_t size = 0;
+    oc_mutex_lock(gCloudMutex);
+    if (OC_STACK_OK != CloudToCBORPayload(gCloud, &payload, &size))
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: cloud to cbor", __func__);
+        goto exit;
+    }
+
+    VERIFY_NOT_NULL(TAG, payload, ERROR);
+
+    if (OC_STACK_OK == UpdateSecureResourceInPS(OIC_JSON_CLOUDS_NAME, payload, size))
+    {
+        ret = true;
+    }
+
+    OICFree(payload);
+exit:
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+    oc_mutex_unlock(gCloudMutex);
+    return ret;
+}
diff --git a/resource/csdk/security/provisioning/src/cloud/config.c b/resource/csdk/security/provisioning/src/cloud/config.c
new file mode 100644 (file)
index 0000000..aa3eff7
--- /dev/null
@@ -0,0 +1,95 @@
+/* *****************************************************************
+ *
+ * Copyright 2018 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 <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "utils.h"
+
+#include "experimental/logger.h"
+#include "ocstack.h"
+#include "ocpayload.h"
+#include "pmutility.h"
+#include "oic_malloc.h"
+#include "crlresource.h"
+#include "ocpayloadcbor.h"
+#include "experimental/payload_logging.h"
+#include "cacommonutil.h"
+#include "secureresourceprovider.h"
+#include "srmutility.h"
+#include "occloudprovisioning.h"
+#include "cloudresource.h"
+
+#define TAG "OIC_CLOUD_CONFIG"
+
+OCStackResult OCProvisionCloudConfig(void *ctx,
+                                    const OCProvisionDev_t *pDev,
+                                    const OicCloud_t *cloud,
+                                    OCClientResponseHandler resultCallback)
+{
+    OIC_LOG_V(INFO, TAG, "IN %s", __func__);
+    OCStackResult ret = OC_STACK_ERROR;
+    char *query = NULL;
+
+    VERIFY_NOT_NULL_RETURN(TAG, ctx, ERROR,  OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, pDev, ERROR,  OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR,  OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->cis, ERROR,  OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->apn, ERROR,  OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->at, ERROR,  OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, resultCallback, ERROR,  OC_STACK_INVALID_PARAM);
+
+    OCRepPayload* payload = OCRepPayloadCreate();
+    VERIFY_NOT_NULL(TAG, payload, ERROR);
+
+    OCRepPayloadSetPropString(payload, OIC_JSON_CLOUD_CIS, cloud->cis);
+    OCRepPayloadSetPropString(payload, OIC_JSON_CLOUD_APN, cloud->apn);
+    OCRepPayloadSetPropString(payload, OIC_JSON_CLOUD_AT, cloud->at);
+
+    query = OICCalloc(1, DEFAULT_URI_LENGTH);
+    VERIFY_NOT_NULL(TAG, query, ERROR);
+
+    VERIFY_SUCCESS(TAG, PMGenerateQuery(true,
+                             pDev->endpoint.addr,
+                             pDev->securePort,
+                             pDev->connType,
+                             query, DEFAULT_URI_LENGTH, OIC_RSRC_CLOUDCONF_URI), ERROR);
+
+    OCCallbackData cbData =  {.context = ctx, .cb = resultCallback, .cd = NULL};
+    OCDoHandle lHandle = NULL;
+
+    ret = OCDoResource(&lHandle, OC_REST_POST, query,
+                                &pDev->endpoint, (OCPayload *)payload,
+                                pDev->connType, OC_HIGH_QOS, &cbData, NULL, 0);
+    OIC_LOG_V(DEBUG, TAG, "POST:%s ret:%d", query, ret);
+exit:
+    OICFree(query);
+    if (OC_STACK_OK != ret)
+    {
+        if(NULL != payload)
+        {
+            OCPayloadDestroy((OCPayload *)payload);
+        }
+    }
+
+    OIC_LOG_V(INFO, TAG, "OUT %s", __func__);
+
+    return ret;
+}
index b029b6e..1afb0be 100644 (file)
@@ -85,20 +85,19 @@ exit:
     return result;
 }
 
-OCStackResult OCCloudGetCRL(voidctx,
-                            const OCDevAddr *endPoint,
+OCStackResult OCCloudGetCRL(void *ctx,
+                            const char *cloudUri,
                             OCCloudResponseCB callback)
 {
     char uri[MAX_URI_LENGTH] = { 0 };
     char *lastUpdate = NULL;
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
 
     getLastUpdateFromDB(&lastUpdate);
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s?%s=%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port,
-            OC_RSRVD_PROV_CRL_URL, OC_RSRVD_LAST_UPDATE, lastUpdate);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s?%s=%s", cloudUri, OC_RSRVD_PROV_CRL_URL, OC_RSRVD_LAST_UPDATE,
+             lastUpdate);
 
     OICFree(lastUpdate);
 
@@ -109,12 +108,12 @@ OCStackResult OCCloudGetCRL(void* ctx,
                         CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 }
 
-OCStackResult OCCloudPostCRL(voidctx,
+OCStackResult OCCloudPostCRL(void *ctx,
                              const char *thisUpdate,
                              const char *nextUpdate,
                              const OCByteString *crl,
                              const stringArray_t *serialNumbers,
-                             const OCDevAddr *endPoint,
+                             const char *cloudUri,
                              OCCloudResponseCB callback)
 {
     OCStackResult result = OC_STACK_ERROR;
@@ -125,7 +124,7 @@ OCStackResult OCCloudPostCRL(void* ctx,
     size_t cbor_len = 0;
     OicSecKey_t crl1;
 
-    VERIFY_NON_NULL_RET(endPoint, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(cloudUri, TAG, "NULL endpoint", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(thisUpdate, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL_RET(nextUpdate, TAG, "NULL input param", OC_STACK_INVALID_PARAM);
 
@@ -136,8 +135,7 @@ OCStackResult OCCloudPostCRL(void* ctx,
         crl1.encoding = OIC_ENCODING_DER;
     }
 
-    snprintf(uri, MAX_URI_LENGTH, "%s%s:%d%s", DEFAULT_PREFIX,
-            endPoint->addr, endPoint->port, OC_RSRVD_PROV_CRL_URL);
+    snprintf(uri, MAX_URI_LENGTH, "%s%s", cloudUri, OC_RSRVD_PROV_CRL_URL);
 
     OCCallbackData cbData;
     fillCallbackData(&cbData, ctx, callback, NULL, NULL);
@@ -158,7 +156,7 @@ OCStackResult OCCloudPostCRL(void* ctx,
         size_t dimensions[MAX_REP_ARRAY_DEPTH] = {0, 0, 0};
         dimensions[0] = serialNumbers->length;
         OCRepPayloadSetStringArray(payload, OC_RSRVD_SERIAL_NUMBERS,
-                                   (const char**)serialNumbers->array, dimensions);
+                                   (const char **)serialNumbers->array, dimensions);
 
     }
     if (crl) OCRepPayloadSetPropPubDataType(payload, OC_RSRVD_CRL, &crl1);
@@ -186,7 +184,7 @@ OCStackResult OCCloudPostCRL(void* ctx,
     secPayload->payloadSize = cbor_len;
 
     result = OCDoResource(NULL, OC_REST_POST, uri, NULL, (OCPayload *)secPayload,
-                        CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
+                          CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 exit:
     OCPayloadDestroy((OCPayload *)payload);
     return result;
index 203a6e6..d894acf 100644 (file)
@@ -82,16 +82,17 @@ typedef struct
  * @param[in] subj              the subject
  */
 static void CSRMakeSubject(char *subject, const char *countryCode, const char *organisation,
-                    const char *organizationalUnitName, const char *deviceId)
+                           const char *organizationalUnitName, const char *deviceId)
 {
     OIC_LOG_V(DEBUG, TAG, "IN: %s", __func__);
 
     if (!deviceId)
     {
-        OIC_LOG_V(ERROR, TAG, "%s: The device id is NULL",__func__);
+        OIC_LOG_V(ERROR, TAG, "%s: The device id is NULL", __func__);
         return;
     }
-    snprintf(subject, MAX_STRING_LEN, "C=%s, O=%s, OU=%s, CN=uuid:%s", countryCode, organisation, organizationalUnitName, deviceId);
+    snprintf(subject, MAX_STRING_LEN, "C=%s, O=%s, OU=%s, CN=uuid:%s", countryCode, organisation,
+             organizationalUnitName, deviceId);
 
     OIC_LOG_V(DEBUG, TAG, "OUT: %s", __func__);
 }
@@ -102,7 +103,7 @@ static void CSRMakeSubject(char *subject, const char *countryCode, const char *o
  *
  * @return  0 on success or -1 on error
  */
-static int ecdsaGenKeypair(mbedtls_pk_context * pk)
+static int ecdsaGenKeypair(mbedtls_pk_context *pk)
 {
     OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
     mbedtls_entropy_context entropy;
@@ -114,7 +115,7 @@ static int ecdsaGenKeypair(mbedtls_pk_context * pk)
     mbedtls_ctr_drbg_init(&ctr_drbg);
     mbedtls_entropy_init(&entropy);
     if (0 != mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func,
-                                   &entropy, (const unsigned char*)PERSONALIZATION_STRING, sizeof(PERSONALIZATION_STRING)))
+                                   &entropy, (const unsigned char *)PERSONALIZATION_STRING, sizeof(PERSONALIZATION_STRING)))
     {
         OIC_LOG(ERROR, TAG, "Seed initialization failed!");
         OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
@@ -174,10 +175,10 @@ static int GenerateCSR(char *subject, OCByteString *csr)
 
     int len = 0;
     int bufsize = 1024;
-    unsigned char * buf = NULL;
+    unsigned char *buf = NULL;
     mbedtls_entropy_context entropy;
     mbedtls_ctr_drbg_context ctr_drbg;
-    mbedtls_pk_context * key = NULL;
+    mbedtls_pk_context *key = NULL;
     mbedtls_x509write_csr req;
 
     // Initialize keypair context
@@ -213,7 +214,7 @@ static int GenerateCSR(char *subject, OCByteString *csr)
     mbedtls_entropy_init(&entropy);
 
     result = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func,
-             &entropy, (const unsigned char*)PERSONALIZATION_STRING, sizeof(PERSONALIZATION_STRING));
+                                   &entropy, (const unsigned char *)PERSONALIZATION_STRING, sizeof(PERSONALIZATION_STRING));
     if (result < 0)
     {
         OIC_LOG(ERROR, TAG, "Seed initialization failed!");
@@ -265,7 +266,7 @@ static int GenerateCSR(char *subject, OCByteString *csr)
     memcpy(g_privateKey.bytes, buf + bufsize - len, len * sizeof(uint8_t));
     g_privateKey.len = len;
 
-    exit:
+exit:
     mbedtls_entropy_free(&entropy);
     mbedtls_ctr_drbg_free(&ctr_drbg);
     mbedtls_x509write_csr_free(&req);
@@ -289,7 +290,8 @@ static int GenerateCSR(char *subject, OCByteString *csr)
  * @param[in] response  peer response
  * @return  OCStackResult application result
  */
-static OCStackResult HandleCertificateIssueRequest(void *ctx, void **data, OCClientResponse *response)
+static OCStackResult HandleCertificateIssueRequest(void *ctx, void **data,
+        OCClientResponse *response)
 {
     OCStackResult result = OC_STACK_OK;
 
@@ -298,7 +300,7 @@ static OCStackResult HandleCertificateIssueRequest(void *ctx, void **data, OCCli
 
     if (!response)
     {
-        OIC_LOG_V(ERROR, TAG, "%s: Client response is null",__func__);
+        OIC_LOG_V(ERROR, TAG, "%s: Client response is null", __func__);
         return OC_STACK_INVALID_PARAM;
     }
 
@@ -321,7 +323,7 @@ static OCStackResult HandleCertificateIssueRequest(void *ctx, void **data, OCCli
 
     OicSecKey_t cert;
     if (!OCRepPayloadGetPropPubDataType((OCRepPayload *)response->payload,
-                                   OC_RSRVD_CERT, &cert))
+                                        OC_RSRVD_CERT, &cert))
     {
         OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_CERT);
         return OC_STACK_ERROR;
@@ -352,7 +354,7 @@ static OCStackResult HandleCertificateIssueRequest(void *ctx, void **data, OCCli
     //get cacert
     OicSecKey_t caCert;
     if (!OCRepPayloadGetPropPubDataType((OCRepPayload *)response->payload,
-                                   OC_RSRVD_CACERT, &caCert))
+                                        OC_RSRVD_CACERT, &caCert))
     {
         OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_CACERT);
         return OC_STACK_ERROR;
@@ -373,18 +375,18 @@ static OCStackResult HandleCertificateIssueRequest(void *ctx, void **data, OCCli
 /**
  * Certificate-Issue request function
  *
- * @param[in] endPoint          cloud host and port
+ * @param[in] cloudUri          cloud host and port
  * @return  OCStackResult application result
  */
-OCStackResult OCCloudCertificateIssueRequest(voidctx,
-                                             const OCDevAddr *endPoint,
-                                             OCCloudResponseCB callback)
+OCStackResult OCCloudCertificateIssueRequest(void *ctx,
+        const char *cloudUri,
+        OCCloudResponseCB callback)
 {
     OCStackResult ret = OC_STACK_OK;
 
     OIC_LOG_V(DEBUG, TAG, "IN: %s", __func__);
 
-    if (NULL == endPoint)
+    if (NULL == cloudUri)
     {
         OIC_LOG(ERROR, TAG, "Input parameter endpoint is NULL");
         return OC_STACK_INVALID_PARAM;
@@ -410,7 +412,7 @@ OCStackResult OCCloudCertificateIssueRequest(void* ctx,
     OIC_LOG(DEBUG, TAG, "Private Key:");
     OIC_LOG_BUFFER(DEBUG, TAG, g_privateKey.bytes, g_privateKey.len);
 
-    OCRepPayloadpayload = OCRepPayloadCreate();
+    OCRepPayload *payload = OCRepPayloadCreate();
     if (!payload)
     {
         OIC_LOG(ERROR, TAG, "Failed to memory allocation");
@@ -431,9 +433,7 @@ OCStackResult OCCloudCertificateIssueRequest(void* ctx,
     OIC_LOG_PAYLOAD(DEBUG, (OCPayload *)payload);
 
     char uri[MAX_URI_QUERY] = { 0 };
-    snprintf(uri, MAX_URI_QUERY, DEFAULT_QUERY,
-             endPoint->addr, endPoint->port,
-             OC_RSRVD_PROV_CERT_URI);
+    snprintf(uri, MAX_URI_QUERY, "%s%s", cloudUri, OC_RSRVD_PROV_CERT_URI);
     OIC_LOG_V(DEBUG, TAG, "Certificate Request Query: %s", uri);
 
     OCCallbackData cbData;
index 98c19ec..c51d746 100644 (file)
@@ -54,8 +54,6 @@
 #include "crlresource.h"
 #endif
 
-#define DEFAULT_URI_LENGTH (MAX_URI_LENGTH + MAX_QUERY_LENGTH)
-
 #define TAG "OIC_SRPAPI"
 
 trustCertChainContext_t g_trustCertChainNotifier;
@@ -720,16 +718,8 @@ static OCStackResult ProvisionLocalCredential(void *ctx, OicSecCred_t *cred)
  */
 static OCStackResult RegisterProvResult(const OCProvisionDev_t *targetDev, OCProvisionResult_t *resArr,
                                int *numOfResults, OCStackResult stackResult);
-/**
- * Callback handler for handling callback of posting DOS_RFNOP.
- *
- * @param[in] ctx             ctx value passed to callback from calling function.
- * @param[in] UNUSED          handle to an invocation
- * @param[in] clientResponse  Response from queries to remote servers.
- * @return  OC_STACK_DELETE_TRANSACTION to delete the transaction
- *          and  OC_STACK_KEEP_TRANSACTION to keep it.
- */
-static OCStackApplicationResult SetReadyForNormalOperationCB(void *ctx, OCDoHandle handler,
+
+OCStackApplicationResult SetReadyForNormalOperationCB(void *ctx, OCDoHandle handler,
         OCClientResponse *clientResponse)
 {
     OIC_LOG_V(DEBUG, TAG, "IN %s", __func__);
@@ -968,10 +958,7 @@ error:
     return res;
 }
 
-/**
- * Restores pstat after provisioning.
- */
-static OCStackApplicationResult ProvisionCB(void *ctx, OCDoHandle handle,
+OCStackApplicationResult ProvisionCB(void *ctx, OCDoHandle handle,
         OCClientResponse *clientResponse)
 {
     OIC_LOG_V(DEBUG, TAG, "IN %s", __func__);
index 8cdeb2c..18b1ff3 100644 (file)
@@ -160,6 +160,7 @@ sptest_env.PrependUnique(CPPPATH=[
     '../../../ocrandom/include',
     '../../../logger/include',
     '../../../stack/include',
+    '../../../stack/include/internal',
     '../../../security/include',
     '../../../security/include/internal',
     '../../../security/provisioning/include/internal',
@@ -169,7 +170,9 @@ sptest_env.PrependUnique(CPPPATH=[
     '../../../connectivity/inc',
     '../../../connectivity/inc/pkix',
     '../../../connectivity/common/inc',
-    '../../../connectivity/api'
+    '../../../connectivity/api',
+    '#resource/csdk/security/provisioning/src/cloud',
+    '#resource/csdk/security/provisioning/include/cloud/'
 ])
 
 sptest_env.PrependUnique(LIBS=[
@@ -216,6 +219,11 @@ unittest_src = [
     'otmunittest.cpp',
 ]
 
+if sptest_env.get('WITH_TCP') == True and sptest_env.get('WITH_CLOUD') == True:
+    unittest_src = unittest_src + [
+        'cloudresource.cpp',
+    ]
+
 tests = sptest_env.Program(unittest_bin, unittest_src)
 server = sptest_env.Program(server_bin, ['sampleserver.cpp'])
 
diff --git a/resource/csdk/security/provisioning/unittest/cloudresource.cpp b/resource/csdk/security/provisioning/unittest/cloudresource.cpp
new file mode 100644 (file)
index 0000000..1a3c6df
--- /dev/null
@@ -0,0 +1,188 @@
+/* *****************************************************************
+ *
+ * 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 <stdlib.h>
+#include <gtest/gtest.h>
+
+extern "C" {
+#include "octypes.h"
+#include "psinterface.h"
+}
+
+#include "../src/cloud/cloudresource.c"
+
+#ifdef TAG
+#undef TAG
+#endif
+#define TAG  "CLOUD_UNITTEST"
+
+#define STR_LEN 512
+static const char *sample =
+    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.-#'?!:/";
+
+void sessionInit(session_t *ses)
+{
+    ses->accessToken = (char *)OICCalloc(STR_LEN, sizeof(char));
+    ses->refreshToken = (char *)OICCalloc(STR_LEN, sizeof(char));
+    ses->uid = (char *)OICCalloc(STR_LEN, sizeof(char));
+#if !defined(__MANDATORY__)
+    ses->redirectUri = (char *)OICCalloc(STR_LEN, sizeof(char));
+#endif // __MANDATORY__
+    for (int i = 0; i < STR_LEN; i++)
+    {
+        ses->accessToken[i] = sample[rand() % STR_LEN];
+        ses->refreshToken[i] = sample[rand() % STR_LEN];
+        ses->uid[i] = sample[rand() % STR_LEN];
+#if !defined(__MANDATORY__)
+        ses->redirectUri[i] = sample[rand() % STR_LEN];
+#endif // __MANDATORY__
+    }
+}
+
+OicCloud_t *getCloud()
+{
+
+    OicCloud_t *cloud = (OicCloud_t *)OICCalloc(1, sizeof(OicCloud_t));
+    VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR, NULL);
+
+
+    cloud->apn = (char *)OICCalloc(STR_LEN, sizeof(char));
+    cloud->cis = (char *)OICCalloc(STR_LEN, sizeof(char));
+    cloud->at = (char *)OICCalloc(STR_LEN, sizeof(char));
+
+    for (int i = 0; i < STR_LEN; i++)
+    {
+        cloud->apn[i] = sample[rand() % STR_LEN];
+        cloud->cis[i] = sample[rand() % STR_LEN];
+        cloud->at[i] = sample[rand() % STR_LEN];
+    }
+
+    cloud->session = (session_t *)OICCalloc(STR_LEN, sizeof(session_t));
+    sessionInit(cloud->session);
+
+    return cloud;
+}
+
+TEST(CloudResourceTest, InitCloudResource)
+{
+    EXPECT_EQ(OC_STACK_OK, InitCloudResource());
+}
+
+TEST(CloudResourceTest, DeInitCloudResource)
+{
+    EXPECT_EQ(OC_STACK_OK, DeInitCloudResource());
+}
+
+TEST(CloudResourceTest, CreateCloudResource)
+{
+    EXPECT_EQ(OC_STACK_OK, CreateCloudResource());
+}
+
+TEST(CloudResourceTest, CloudToCBORPayloadNULL)
+{
+    OicCloud_t *cloud =  getCloud();
+    size_t size = 10;
+    uint8_t *payload = NULL;
+
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, CloudToCBORPayload(NULL, NULL, 0));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, CloudToCBORPayload(cloud, NULL, &size));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, CloudToCBORPayload(cloud, &payload, NULL));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, CloudToCBORPayload(NULL, &payload, &size));
+    FreeCloud(cloud);
+}
+
+TEST(CloudResourceTest, CloudToCBORPayloadVALID)
+{
+    OicCloud_t *cloud = getCloud();
+
+    uint8_t *payload = NULL;
+    size_t size = 0;
+    EXPECT_EQ(OC_STACK_OK, CloudToCBORPayload(cloud, &payload, &size));
+    EXPECT_TRUE(payload != NULL);
+
+    FreeCloud(cloud);
+    OICFree(payload);
+}
+
+TEST(CloudResourceTest, CBORPayloadToCloudNULL)
+{
+    OicCloud_t *cloud = NULL;
+    uint8_t *cborPayload = (uint8_t *)OICCalloc(1, sizeof(uint8_t));
+    size_t size = 10;
+    ASSERT_TRUE(NULL != cborPayload);
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, CBORPayloadToCloud(NULL, 0, NULL));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, CBORPayloadToCloud(NULL, size, &cloud));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, CBORPayloadToCloud(cborPayload, size, NULL));
+    OICFree(cborPayload);
+}
+
+TEST(CloudResourceTest, CBORPayloadToCloudFULL)
+{
+    OicCloud_t *cloud =  getCloud();
+    uint8_t *payload = NULL;
+    size_t size = 0;
+    EXPECT_EQ(OC_STACK_OK, CloudToCBORPayload(cloud, &payload, &size));
+    EXPECT_TRUE(payload != NULL);
+
+    OicCloud_t *cloudX = NULL;
+    EXPECT_EQ(OC_STACK_OK, CBORPayloadToCloud(payload, size, &cloudX));
+    ASSERT_TRUE(cloudX != NULL);
+    ASSERT_STREQ(cloudX->apn, cloud->apn);
+    ASSERT_STREQ(cloudX->cis, cloud->cis);
+    ASSERT_STREQ(cloudX->at, cloud->at);
+
+    if (cloud->session && cloudX->session)
+    {
+        ASSERT_STREQ(cloudX->session->authProvider, cloud->session->authProvider);
+        ASSERT_STREQ(cloudX->session->accessToken, cloud->session->accessToken);
+        ASSERT_STREQ(cloudX->session->refreshToken, cloud->session->refreshToken);
+        ASSERT_EQ(cloudX->session->expireSin, cloud->session->expireSin);
+        ASSERT_STREQ(cloudX->session->uid, cloud->session->uid);
+#if !defined(__MANDATORY__)
+        ASSERT_STREQ(cloudX->session->redirectUri, cloud->session->redirectUri);
+#endif // __MANDATORY__
+    }
+
+    FreeCloud(cloudX);
+    FreeCloud(cloud);
+    OICFree(payload);
+}
+
+TEST(CloudResourceTest, ValidCloudFULL)
+{
+    OicCloud_t *cloud =  getCloud();
+    ASSERT_TRUE(false == ValidCloud(cloud));
+    sprintf(cloud->cis, "coaps+tcp://");
+    ASSERT_TRUE(true == ValidCloud(cloud));
+    FreeCloud(cloud);
+}
+
+TEST(CloudResourceGetTest, PayloadFULL)
+{
+    int cloudState = rand();
+    int cloudStateX;
+    uint8_t *payload = NULL;
+    size_t size = 0;
+
+    ASSERT_TRUE(OC_STACK_OK == CloudGetRequestPayloadCreate(cloudState, &payload, &size));
+    ASSERT_TRUE(OC_STACK_OK == CloudGetRequestPayloadParse(payload, size, &cloudStateX));
+    ASSERT_TRUE(cloudState == cloudStateX);
+}
+
index 0f6189c..e09a883 100644 (file)
 static OCPersistentStorage gPst;
 static bool g_doneCB;
 static bool g_callbackResult;
-static const charg_otmCtx = "Test User Context";
-static OCProvisionDev_tg_unownedDevices = NULL;
-static OCProvisionDev_tg_ownedDevices = NULL;
-static int gNumOfUnownDevice = 0;
-static int gNumOfOwnDevice = 0;
+static const char *g_otmCtx = "Test User Context";
+static OCProvisionDev_t *g_unownedDevices = NULL;
+static OCProvisionDev_t *g_ownedDevices = NULL;
+static size_t gNumOfUnownDevice = 0;
+static size_t gNumOfOwnDevice = 0;
 
 using namespace std;
 
@@ -60,7 +60,7 @@ using namespace std;
 
 TEST(JustWorksOxMTest, NullParam)
 {
-    OTMContext_totmCtx = NULL;
+    OTMContext_t *otmCtx = NULL;
     OCStackResult res = OC_STACK_ERROR;
     uint8_t *payloadRes = NULL;
     size_t size = 0;
@@ -97,7 +97,7 @@ TEST(JustWorksOxMTest, NullParam)
 
 TEST(RandomPinOxMTest, NullParam)
 {
-    OTMContext_totmCtx = NULL;
+    OTMContext_t *otmCtx = NULL;
     OCStackResult res = OC_STACK_ERROR;
     uint8_t *payloadRes = NULL;
     size_t size = 0;
@@ -134,7 +134,7 @@ TEST(RandomPinOxMTest, NullParam)
 
 TEST(ManufacturerCertOxMTest, NullParam)
 {
-    OTMContext_totmCtx = NULL;
+    OTMContext_t *otmCtx = NULL;
     OCStackResult res = OC_STACK_ERROR;
     uint8_t *payloadRes = NULL;
     size_t size = 0;
@@ -170,30 +170,31 @@ TEST(ManufacturerCertOxMTest, NullParam)
 /****************************************
  * Test the OTM modules with sample server
  ****************************************/
-static FILE* fopen_prvnMng(const char* path, const char* mode)
+static FILE *fopen_prvnMng(const char *path, const char *mode)
 {
     if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
     {
-      return fopen(SVR_DB_FILE_NAME, mode);
+        return fopen(SVR_DB_FILE_NAME, mode);
     }
     OIC_LOG_V(DEBUG, TAG, "use db: %s", path);
     return fopen(path, mode);
 }
 
 // callback function(s) for provisioning client using C-level provisioning API
-static void ownershipTransferCB(void* ctx, size_t UNUSED1, OCProvisionResult_t* UNUSED2, bool hasError)
+static void ownershipTransferCB(void *ctx, size_t UNUSED1, OCProvisionResult_t *UNUSED2,
+                                bool hasError)
 {
     OC_UNUSED(UNUSED1);
     OC_UNUSED(UNUSED2);
     OC_UNUSED(ctx);
 
-    if(!hasError)
+    if (!hasError)
     {
-        OIC_LOG_V(DEBUG, TAG, "Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
+        OIC_LOG_V(DEBUG, TAG, "Ownership Transfer SUCCEEDED - ctx: %s", (char *) ctx);
     }
     else
     {
-        OIC_LOG_V(FATAL, TAG, "Ownership Transfer FAILED - ctx: %s", (char*) ctx);
+        OIC_LOG_V(FATAL, TAG, "Ownership Transfer FAILED - ctx: %s", (char *) ctx);
     }
     g_callbackResult = !hasError;
     g_doneCB = true;
@@ -202,19 +203,19 @@ static void ownershipTransferCB(void* ctx, size_t UNUSED1, OCProvisionResult_t*
 }
 
 // callback function(s) for provisioning client using C-level provisioning API
-static void removeDeviceCB(void* ctx, size_t UNUSED1, OCProvisionResult_t* UNUSED2, bool hasError)
+static void removeDeviceCB(void *ctx, size_t UNUSED1, OCProvisionResult_t *UNUSED2, bool hasError)
 {
     OC_UNUSED(UNUSED1);
     OC_UNUSED(UNUSED2);
     OC_UNUSED(ctx);
 
-    if(!hasError)
+    if (!hasError)
     {
-        OIC_LOG_V(DEBUG, TAG, "Remove device request SUCCEEDED - ctx: %s", (char*) ctx);
+        OIC_LOG_V(DEBUG, TAG, "Remove device request SUCCEEDED - ctx: %s", (char *) ctx);
     }
     else
     {
-        OIC_LOG_V(FATAL, TAG, "Remove device request FAILED - ctx: %s", (char*) ctx);
+        OIC_LOG_V(FATAL, TAG, "Remove device request FAILED - ctx: %s", (char *) ctx);
     }
     g_callbackResult = !hasError;
     g_doneCB = true;
@@ -222,10 +223,10 @@ static void removeDeviceCB(void* ctx, size_t UNUSED1, OCProvisionResult_t* UNUSE
 
 static int waitCallbackRet(void)
 {
-    for(int i = 0; !g_doneCB && OTM_TIMEOUT > i; ++i)
+    for (int i = 0; !g_doneCB && OTM_TIMEOUT > i; ++i)
     {
         sleep(1);
-        if(OC_STACK_OK != OCProcess())
+        if (OC_STACK_OK != OCProcess())
         {
             OIC_LOG(FATAL, TAG, "OCStack process error");
             return -1;
@@ -238,32 +239,6 @@ static int waitCallbackRet(void)
 #define UUID_TEMPLATE "11111111-1234-1234-1234-12345678901"
 #define UUID_TEMPLATE_LEN 35
 
-static void RemoveUnknownDeviceFromDevList(OCProvisionDev_t* devList)
-{
-    OCProvisionDev_t* unknowDev = NULL;
-    OCProvisionDev_t* tempDev1 = NULL;
-    OCProvisionDev_t* tempDev2 =NULL;
-
-    LL_FOREACH_SAFE(devList, tempDev1, tempDev2)
-    {
-        char *uuidString = NULL;
-        EXPECT_EQ(OC_STACK_OK, ConvertUuidToStr((const OicUuid_t*) &tempDev1->doxm->deviceID, &uuidString));
-
-        if (strncmp(UUID_TEMPLATE, uuidString, UUID_TEMPLATE_LEN) != 0)
-        {
-            OIC_LOG_V(DEBUG, TAG, "%s: delete from list id:%s ip:%s:%d",__func__,
-            uuidString ? uuidString :"unknow id",
-            tempDev1->endpoint.addr,tempDev1->endpoint.port);
-
-            LL_DELETE(devList, tempDev1);
-            LL_APPEND(unknowDev, tempDev1);
-        }
-        OICFree(uuidString);
-    }
-
-    OCDeleteDiscoveredDevices(unknowDev);
-}
-
 TEST(InitForOTM, NullParam)
 {
     OCStackResult result = OC_STACK_ERROR;
@@ -337,26 +312,33 @@ TEST(OCDiscoverUnownedDevices, Simple)
     EXPECT_EQ(OC_STACK_OK, OCInitPM(PM_DB_FILE_NAME));
     EXPECT_EQ(OC_STACK_OK, OCDiscoverUnownedDevices(DISCOVERY_TIMEOUT, &g_unownedDevices));
 
-    RemoveUnknownDeviceFromDevList(g_unownedDevices);
-
-    OCProvisionDev_t* tempDev = g_unownedDevices;
-    while(tempDev)
+    OCProvisionDev_t *tempDev1 = NULL;
+    OCProvisionDev_t *tempDev2 = NULL;
+    gNumOfUnownDevice = 0;
+    LL_FOREACH_SAFE(g_unownedDevices, tempDev1, tempDev2)
     {
-        gNumOfUnownDevice++;
-
         char *uuidString = NULL;
-        EXPECT_EQ(OC_STACK_OK, ConvertUuidToStr((const OicUuid_t*) &tempDev->doxm->deviceID, &uuidString));
+        EXPECT_EQ(OC_STACK_OK, ConvertUuidToStr((const OicUuid_t *) &tempDev1->doxm->deviceID,
+                                                &uuidString));
 
-        OIC_LOG_V(DEBUG, TAG, "%d: id:%s ip:%s:%d", gNumOfUnownDevice,
-        uuidString ? uuidString :"unknow id",
-        tempDev->endpoint.addr,tempDev->endpoint.port);
+        OIC_LOG_V(DEBUG, TAG, "%s: id:%s ip:%s:%d", __func__,
+                      uuidString ? uuidString : "unknow id",
+                      tempDev1->endpoint.addr, tempDev1->endpoint.port);
 
+        if (0 != strncmp(UUID_TEMPLATE, uuidString, UUID_TEMPLATE_LEN))
+        {
+            LL_DELETE(g_unownedDevices,tempDev1);
+        }
+        else
+        {
+            OIC_LOG_V(DEBUG, TAG, "%s: append in list", __func__);
+            gNumOfUnownDevice++;
+        }
         OICFree(uuidString);
-
-        tempDev = tempDev->next;
     }
 
     EXPECT_EQ(true, gNumOfUnownDevice > 0);
+
     // close Provisioning DB
     EXPECT_EQ(OC_STACK_OK, OCClosePM());
 }
@@ -368,9 +350,10 @@ TEST(OCDoOwnershipTransfer, Simple)
     ASSERT_EQ(true, gNumOfUnownDevice > 0);
 
     g_doneCB = false;
-    EXPECT_EQ(OC_STACK_OK, OCDoOwnershipTransfer((void*)g_otmCtx, g_unownedDevices, ownershipTransferCB));
+    EXPECT_EQ(OC_STACK_OK, OCDoOwnershipTransfer((void *)g_otmCtx, g_unownedDevices,
+              ownershipTransferCB));
 
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
+    if (waitCallbackRet()) // input |g_doneCB| flag implicitly
     {
         OIC_LOG(FATAL, TAG, "OCProvisionCredentials callback error");
         return;
@@ -386,58 +369,18 @@ TEST(OCDiscoverOwnedDevices, Simple)
 {
     //initialize Provisioning DB Manager
     EXPECT_EQ(OC_STACK_OK, OCInitPM(PM_DB_FILE_NAME));
-    OCStackResult result = OC_STACK_ERROR;
-    gNumOfOwnDevice = 0;
 
     EXPECT_EQ(OC_STACK_OK, OCDiscoverOwnedDevices(DISCOVERY_TIMEOUT, &g_ownedDevices));
 
-    RemoveUnknownDeviceFromDevList(g_ownedDevices);
+    gNumOfOwnDevice = 0;
 
-    OCProvisionDev_ttempDev = g_ownedDevices;
-    while(tempDev)
+    OCProvisionDev_t *tempDev = g_ownedDevices;
+    while (tempDev)
     {
         gNumOfOwnDevice++;
         tempDev = tempDev->next;
     }
 
-    if (gNumOfUnownDevice > gNumOfOwnDevice)
-    {
-        OIC_LOG(DEBUG, TAG, "Discovering unowned devices on");
-
-        if(g_unownedDevices)
-        {
-            OCDeleteDiscoveredDevices(g_unownedDevices);
-            g_unownedDevices = NULL;
-        }
-
-        result = OCDiscoverUnownedDevices(DISCOVERY_TIMEOUT, &g_unownedDevices);
-        EXPECT_EQ(OC_STACK_OK, result);
-
-        RemoveUnknownDeviceFromDevList(g_unownedDevices);
-
-        tempDev = g_unownedDevices;
-        while(tempDev)
-        {
-            gNumOfUnownDevice++;
-            tempDev = tempDev->next;
-        }
-
-        if (gNumOfUnownDevice)
-        {
-            g_doneCB = false;
-            EXPECT_EQ(OC_STACK_OK, OCDoOwnershipTransfer((void*)g_otmCtx, g_unownedDevices, ownershipTransferCB));
-
-            if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-            {
-                OIC_LOG(FATAL, TAG, "OCProvisionCredentials callback error");
-                return;
-            }
-
-            EXPECT_EQ(true, g_callbackResult);
-            EXPECT_EQ(true, g_doneCB);
-        }
-    }
-
     EXPECT_EQ(true, gNumOfOwnDevice > 0);
     // close Provisioning DB
     EXPECT_EQ(OC_STACK_OK, OCClosePM());
@@ -448,7 +391,7 @@ TEST(PerformLinkDevices, NullParam)
     if (gNumOfOwnDevice < 2)
     {
         OIC_LOG(WARNING, TAG, "Link can only pair owned devices");
-        OIC_LOG_V(DEBUG, TAG, "Number of owned devices: %d",gNumOfOwnDevice);
+        OIC_LOG_V(DEBUG, TAG, "Number of owned devices: %lu", gNumOfOwnDevice);
         return;
     }
 
@@ -458,19 +401,19 @@ TEST(PerformLinkDevices, NullParam)
     EXPECT_EQ(OC_STACK_OK, result);
 
     //Extract target device except PT to perform link devices.
-    OCProvisionDev_tdev1 = NULL;
-    OCProvisionDev_tdev2 = NULL;
-    OCProvisionDev_ttempDev = g_ownedDevices;
+    OCProvisionDev_t *dev1 = NULL;
+    OCProvisionDev_t *dev2 = NULL;
+    OCProvisionDev_t *tempDev = g_ownedDevices;
 
-    while(tempDev)
+    while (tempDev)
     {
-        if(memcmp(tempDev->doxm->deviceID.id, myUuid.id, UUID_LENGTH) != 0)
+        if (memcmp(tempDev->doxm->deviceID.id, myUuid.id, UUID_LENGTH) != 0)
         {
-            if(NULL == dev1)
+            if (NULL == dev1)
             {
                 dev1 = tempDev;
             }
-            else if(NULL == dev2)
+            else if (NULL == dev2)
             {
                 dev2 = tempDev;
                 break;
@@ -501,38 +444,39 @@ TEST(PerformUnlinkDevices, NullParam)
 //TODO will fix after IOT-2106
 #if 0
 //#ifdef MULTIPLE_OWNER
-static OCProvisionDev_tg_motEnabledDevices = NULL;
-static OCProvisionDev_tg_multiplOwnedDevices = NULL;
+static OCProvisionDev_t *g_motEnabledDevices = NULL;
+static OCProvisionDev_t *g_multiplOwnedDevices = NULL;
 
-static void updateDoxmForMOTCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError)
+static void updateDoxmForMOTCB(void *ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError)
 {
     OC_UNUSED(nOfRes);
     OC_UNUSED(arr);
 
-    if(!hasError)
+    if (!hasError)
     {
-        OIC_LOG_V(DEBUG, TAG, "POST 'doxm' SUCCEEDED - ctx: %s", (char*) ctx);
+        OIC_LOG_V(DEBUG, TAG, "POST 'doxm' SUCCEEDED - ctx: %s", (char *) ctx);
     }
     else
     {
-        OIC_LOG_V(FATAL, TAG, "POST 'doxm'  FAILED - ctx: %s", (char*) ctx);
+        OIC_LOG_V(FATAL, TAG, "POST 'doxm'  FAILED - ctx: %s", (char *) ctx);
     }
     g_callbackResult = !hasError;
     g_doneCB = true;
 }
 
-static void provisionPreconfiguredPinCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError)
+static void provisionPreconfiguredPinCB(void *ctx, size_t nOfRes, OCProvisionResult_t *arr,
+                                        bool hasError)
 {
     OC_UNUSED(nOfRes);
     OC_UNUSED(arr);
 
-    if(!hasError)
+    if (!hasError)
     {
-        OIC_LOG_V(DEBUG, TAG, "Provision Preconfigured-PIN SUCCEEDED - ctx: %s", (char*) ctx);
+        OIC_LOG_V(DEBUG, TAG, "Provision Preconfigured-PIN SUCCEEDED - ctx: %s", (char *) ctx);
     }
     else
     {
-        OIC_LOG_V(FATAL, TAG, "Provision Preconfigured-PIN FAILED - ctx: %s", (char*) ctx);
+        OIC_LOG_V(FATAL, TAG, "Provision Preconfigured-PIN FAILED - ctx: %s", (char *) ctx);
     }
     g_callbackResult = !hasError;
     g_doneCB = true;
@@ -542,7 +486,7 @@ TEST(EnableMOT, NullParam)
 {
     OCStackResult result = OC_STACK_OK;
 
-    if(NULL == g_ownedDevices)
+    if (NULL == g_ownedDevices)
     {
         OIC_LOG(DEBUG, TAG, "Discovering Only Owned Devices on Network..");
         result = OCDiscoverOwnedDevices(DISCOVERY_TIMEOUT, &g_ownedDevices);
@@ -550,11 +494,12 @@ TEST(EnableMOT, NullParam)
         RemoveUnknownDeviceFromDevList(g_ownedDevices);
     }
 
-    EXPECT_NE((OCProvisionDev_t*)NULL, g_ownedDevices);
+    EXPECT_NE((OCProvisionDev_t *)NULL, g_ownedDevices);
 
     g_doneCB = false;
-    ASSERT_EQ(OC_STACK_OK, OCChangeMOTMode(NULL, g_ownedDevices, OIC_MULTIPLE_OWNER_ENABLE, updateDoxmForMOTCB));
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
+    ASSERT_EQ(OC_STACK_OK, OCChangeMOTMode(NULL, g_ownedDevices, OIC_MULTIPLE_OWNER_ENABLE,
+                                           updateDoxmForMOTCB));
+    if (waitCallbackRet()) // input |g_doneCB| flag implicitly
     {
         OIC_LOG(FATAL, TAG, "OCChangeMOTMode callback error");
         return;
@@ -565,12 +510,13 @@ TEST(EnableMOT, NullParam)
 
 TEST(DiscoverMOTEnabledDevices, NullParam)
 {
-    if(g_motEnabledDevices)
+    if (g_motEnabledDevices)
     {
         PMDeleteDeviceList(g_motEnabledDevices);
     }
 
-    ASSERT_EQ(OC_STACK_OK, OCDiscoverMultipleOwnerEnabledDevices(DISCOVERY_TIMEOUT, &g_motEnabledDevices));
+    ASSERT_EQ(OC_STACK_OK, OCDiscoverMultipleOwnerEnabledDevices(DISCOVERY_TIMEOUT,
+              &g_motEnabledDevices));
 
     RemoveUnknownDeviceFromDevList(g_motEnabledDevices);
 
@@ -589,9 +535,10 @@ TEST(ProvisonPreconfiguredPIN, NullParam)
     OCStackResult result = OC_STACK_OK;
 
     g_doneCB = false;
-    result = OCProvisionPreconfigPin(NULL, g_motEnabledDevices, "12341234", strlen("12341234"), provisionPreconfiguredPinCB);
+    result = OCProvisionPreconfigPin(NULL, g_motEnabledDevices, "12341234", strlen("12341234"),
+                                     provisionPreconfiguredPinCB);
     ASSERT_EQ(OC_STACK_OK, result);
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
+    if (waitCallbackRet()) // input |g_doneCB| flag implicitly
     {
         OIC_LOG(FATAL, TAG, "OCProvisionPreconfigPin callback error");
         return;
@@ -608,7 +555,7 @@ TEST(SelectMOTMethod, NullParam)
     g_doneCB = false;
     result = OCSelectMOTMethod(NULL, g_motEnabledDevices, OIC_PRECONFIG_PIN, updateDoxmForMOTCB);
     ASSERT_EQ(OC_STACK_OK, result);
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
+    if (waitCallbackRet()) // input |g_doneCB| flag implicitly
     {
         OIC_LOG(FATAL, TAG, "OCSelectMOTMethod callback error");
         return;
@@ -626,7 +573,7 @@ TEST(PerformMOT, NullParam)
     g_doneCB = false;
     result = OCDoMultipleOwnershipTransfer(NULL, g_motEnabledDevices, ownershipTransferCB);
     ASSERT_EQ(OC_STACK_OK, result);
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
+    if (waitCallbackRet()) // input |g_doneCB| flag implicitly
     {
         OIC_LOG(FATAL, TAG, "OCDoMultipleOwnershipTransfer callback error");
         return;
@@ -638,7 +585,7 @@ TEST(DiscoverMultipleOwnedDevices, NullParam)
 {
     OCStackResult result = OC_STACK_OK;
 
-    if(g_multiplOwnedDevices)
+    if (g_multiplOwnedDevices)
     {
         PMDeleteDeviceList(g_multiplOwnedDevices);
     }
@@ -646,7 +593,7 @@ TEST(DiscoverMultipleOwnedDevices, NullParam)
     OIC_LOG(DEBUG, TAG, "Discovering MOT Enabled Devices on Network..");
     result = OCDiscoverMultipleOwnedDevices(DISCOVERY_TIMEOUT, &g_multiplOwnedDevices);
     ASSERT_EQ(OC_STACK_OK, result);
-    RemoveUnknownDeviceFromDevList(g_multiplOwnedDevices);
+    RemoveUnknownDeviceFromDevList(&g_multiplOwnedDevices);
     EXPECT_TRUE(NULL != g_multiplOwnedDevices);
 }
 #endif //MULTIPLE_OWNER
@@ -663,10 +610,10 @@ TEST(OCRemoveDevice, Simple)
     EXPECT_EQ(OC_STACK_OK, result);
 
     //Extract target device except PT to perform remove device.
-    OCProvisionDev_tremoveDev = g_ownedDevices;
-    while(removeDev)
+    OCProvisionDev_t *removeDev = g_ownedDevices;
+    while (removeDev)
     {
-        if(memcmp(removeDev->doxm->deviceID.id, myUuid.id, UUID_LENGTH) != 0)
+        if (memcmp(removeDev->doxm->deviceID.id, myUuid.id, UUID_LENGTH) != 0)
         {
             break;
         }
@@ -677,7 +624,7 @@ TEST(OCRemoveDevice, Simple)
     g_doneCB = false;
     g_callbackResult = false;
 
-    result = OCRemoveDevice((void*)g_otmCtx, DISCOVERY_TIMEOUT, removeDev, removeDeviceCB);
+    result = OCRemoveDevice((void *)g_otmCtx, DISCOVERY_TIMEOUT, removeDev, removeDeviceCB);
     EXPECT_EQ(OC_STACK_OK, result);
     EXPECT_EQ(true, g_callbackResult);
     EXPECT_EQ(true, g_doneCB);
index aa3a1b1..17ea2a1 100644 (file)
@@ -90,6 +90,11 @@ const char * OIC_RSRC_TYPE_SEC_VER = "oic.r.ver";
 const char * OIC_RSRC_VER_URI =  "/oic/sec/ver";
 const char * OIC_JSON_VER_NAME = "ver";
 
+//cloud conf
+const char * OIC_RSRC_TYPE_CLOUD_CONF = "oic.r.coapcloudconf";
+const char * OIC_RSRC_CLOUD_CONF_URI = "/oic/r/coapcloudconf";
+const char * OIC_JSON_CLOUD_CONF_NAME = "coapcloudconf";
+
 //reset profile
 const char * OIC_JSON_RESET_PF_NAME = "resetpf";
 
index b5b1034..a962fd7 100644 (file)
@@ -53,7 +53,7 @@ namespace OC
     {
 
         private:
-            OCDevAddr  m_devAddr;
+            std::string  m_devAddr;
         public:
 
             /**
@@ -66,12 +66,7 @@ namespace OC
 
             void setIpAddr(std::string& ipAddr)
             {
-                memcpy(m_devAddr.addr, ipAddr.c_str(), MAX_ADDR_STR_SIZE);
-            }
-
-            void setPort(uint16_t port)
-            {
-                m_devAddr.port = port;
+                m_devAddr = ipAddr;
             }
 
             /**
index 1b252f8..8ebb1a3 100644 (file)
@@ -197,8 +197,7 @@ exit:
 OCStackResult
 CloudSignUp(OCDevAddr *endPoint,
            const char *authProvider,
-           const char *authToken,
-           OCClientResponseHandler response)
+           const char *authToken)
 {
     char uri[MAX_URI_LENGTH] = { 0 };
 
@@ -224,8 +223,7 @@ CloudSignUp(OCDevAddr *endPoint,
 
     OCCallbackData cbData;
     memset(&cbData, 0, sizeof(OCCallbackData));
-    cbData.cb = response;
-    cbData.context = (void*)handleCloudSignUpResponse;
+    cbData.cb = handleCloudSignUpResponse;
 
     OCRepPayload *payload = OCRepPayloadCreate();
     if (!payload)
@@ -295,7 +293,7 @@ exit:
  * @param[in] endPoint          cloud host and port
  * @return  OCStackResult application result
  */
-OCStackResult CloudSignIn(OCDevAddr  *endPoint, OCClientResponseHandler response)
+OCStackResult CloudSignIn(OCDevAddr  *endPoint)
 {
     OIC_LOG_V(DEBUG, TAG, "IN: %s", __func__);
 
@@ -344,8 +342,7 @@ OCStackResult CloudSignIn(OCDevAddr  *endPoint, OCClientResponseHandler response
 
     OCCallbackData cbData;
     memset(&cbData, 0, sizeof(OCCallbackData));
-    cbData.cb = response;
-    cbData.context = (void*)handleCloudSignInResponse;
+    cbData.cb = handleCloudSignInResponse;
 
     return OCDoResource(NULL, OC_REST_POST, uri, NULL,
                        (OCPayload *)payload,
@@ -395,7 +392,7 @@ exit:
  * @param[in] endPoint          cloud host and port
  * @return  OCStackResult application result
  */
-OCStackResult CloudSignOut(OCDevAddr  *endPoint, OCClientResponseHandler response)
+OCStackResult CloudSignOut(OCDevAddr  *endPoint)
 {
     OIC_LOG_V(DEBUG, TAG, "IN: %s", __func__);
 
@@ -431,8 +428,7 @@ OCStackResult CloudSignOut(OCDevAddr  *endPoint, OCClientResponseHandler respons
 
     OCCallbackData cbData;
     memset(&cbData, 0, sizeof(OCCallbackData));
-    cbData.cb = response;
-    cbData.context = (void*)handleCloudSignOutResponse;
+    cbData.cb = handleCloudSignOutResponse;
 
     return OCDoResource(NULL, OC_REST_POST, uri, NULL,
                        (OCPayload *)payload,
index 6a578ba..af40d0e 100644 (file)
 #ifndef CLOUD_AUTH_H
 #define CLOUD_AUTH_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /**
  * Sends Sign UP request to cloud
  *
  * @param[in] endPoint         peer endpoint
  * @param[in] authProvider     authentication provider
  * @param[in] authToken        authentication token
- * @param[in] response         response callback
  * @return  OCStackResult application result
  */
-OCStackResult CloudSignUp(OCDevAddr  *endPoint, const char *authProvider, const char *authToken,
-                          OCClientResponseHandler response);
+OCStackResult CloudSignUp(OCDevAddr  *endPoint, const char *authProvider, const char *authToken);
 
 /**
  * Sends Sign IN request to cloud
  *
  * @param[in] endPoint         peer endpoint
- * @param[in] response         response callback
  * @return  OCStackResult application result
  */
-OCStackResult CloudSignIn(OCDevAddr  *endPoint, OCClientResponseHandler response);
+OCStackResult CloudSignIn(OCDevAddr  *endPoint);
 
 /**
  * Sends Sign IN request to cloud
  *
  * @param[in] endPoint         peer endpoint
- * @param[in] response         response callback
  * @return  OCStackResult application result
  */
-OCStackResult CloudSignOut(OCDevAddr  *endPoint, OCClientResponseHandler response);
+OCStackResult CloudSignOut(OCDevAddr  *endPoint);
 
 /**
  * Sends Sign Up request to cloud
  *
  * @param[in] ctx                    context
  * @param[in] handle                 handle
- * @param[in] response               response from peer
  * @return  OCStackApplicationResult application result
  */
 OCStackApplicationResult handleCloudSignUpResponse(void *ctx,
@@ -87,4 +86,8 @@ OCStackApplicationResult handleCloudSignOutResponse(void *ctx,
                                                     OCClientResponse *response);
 
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif // CLOUD_AUTH_H
index aa98f60..39786ff 100644 (file)
@@ -242,6 +242,10 @@ static int saveTrustCert(void)
     return res;
 }
 
+extern OCStackResult CloudSignUp(OCDevAddr  *endPoint, const char *authProvider, const char *authToken);
+extern OCStackResult CloudSignIn(OCDevAddr  *endPoint);
+extern OCStackResult CloudSignOut(OCDevAddr  *endPoint);
+
 static void userRequests(void *data)
 {
     (void) data;
@@ -285,13 +289,13 @@ static void userRequests(void *data)
                 printf("Paste to browser %s and get auth code\n", GITHUB_AUTH_LINK);
             }
             readString(token, sizeof(token), "auth token", "check link above");
-            res = CloudSignUp(&endPoint, authProvider, token, handleCloudSignUpResponse);
+            res = CloudSignUp(&endPoint, authProvider, token);
             break;
         case SIGN_IN:
-            res = CloudSignIn(&endPoint, handleCloudSignInResponse);
+            res = CloudSignIn(&endPoint);
             break;
         case SIGN_OUT:
-            res = CloudSignOut(&endPoint, handleCloudSignOutResponse);
+            res = CloudSignOut(&endPoint);
             break;
         case HOST:
             {
@@ -307,7 +311,6 @@ static void userRequests(void *data)
             int tmp = 0;
             readInteger(&tmp, "port number", example);
             endPoint.port = tmp;
-            g_cloudProv.setPort((uint16_t)tmp);
         }
         break;
         case CRL_GET:
index 9edd35e..a19285b 100644 (file)
@@ -348,6 +348,13 @@ OCStackResult OCWrapperAclIdGetByDevice(OCCloudProvisioning& ptr, AclIdResponseC
     return ptr.getAclIdByDevice(di, callback);
 }
 
+const char *getUri(const OCDevAddr *ep)
+{
+    char *uri = (char *)OICCalloc(1,1024);
+    snprintf(uri,1024,"%s:%d",ep->addr, ep->port);
+    return uri;
+}
+
 OCStackResult OCWrapperAclIdCreate(const OCDevAddr *endPoint, OCCloudResponseCB callback)
 {
     char oid[MAX_ID_LENGTH]  = { 0 };
@@ -356,7 +363,7 @@ OCStackResult OCWrapperAclIdCreate(const OCDevAddr *endPoint, OCCloudResponseCB
     readString(oid, sizeof(oid), "owner id", UUID_EXAMPLE_2);
     readString(di, sizeof(di), "device id", UUID_EXAMPLE_1);
 
-    return OCCloudAclIdCreate(NULL, oid, di, endPoint, callback);
+    return OCCloudAclIdCreate(NULL, oid, di, getUri(endPoint), callback);
 }
 
 OCStackResult OCWrapperAclIdDelete(const OCDevAddr *endPoint, OCCloudResponseCB callback)
@@ -365,7 +372,7 @@ OCStackResult OCWrapperAclIdDelete(const OCDevAddr *endPoint, OCCloudResponseCB
 
     readString(aclid, sizeof(aclid), "acl id", ACL_ID_EXAMPLE);
 
-    return OCCloudAclIdDelete(NULL, aclid, endPoint, callback);
+    return OCCloudAclIdDelete(NULL, aclid, getUri(endPoint), callback);
 }
 
 OCStackResult OCWrapperAclIndividualGetInfo(OCCloudProvisioning& ptr, ResponseCallBack callback)
@@ -453,7 +460,7 @@ OCStackResult OCWrapperAclIndividualUpdateAce(const OCDevAddr *endPoint, OCCloud
         }
     }
 
-    result = OCCloudAclIndividualAclUpdate(NULL, aclid, aces, endPoint, callback);
+    result = OCCloudAclIndividualAclUpdate(NULL, aclid, aces, getUri(endPoint), callback);
 exit:
     if (aces)
     {
@@ -488,7 +495,7 @@ OCStackResult OCWrapperAclIndividualDelete(const OCDevAddr *endPoint, OCCloudRes
 
     readString(aclid, sizeof(aclid), "acl id", ACL_ID_EXAMPLE);
 
-    return OCCloudAclAcesDelete(NULL, aclid, endPoint, callback);
+    return OCCloudAclAcesDelete(NULL, aclid, getUri(endPoint), callback);
 }
 
 OCStackResult OCWrapperAclCreateGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
@@ -499,7 +506,7 @@ OCStackResult OCWrapperAclCreateGroup(const OCDevAddr *endPoint, OCCloudResponse
     readString(gtype, sizeof(gtype), "Group type value", "Public");
     readOptionalString(gmid, sizeof(gmid), "group member id value", UUID_EXAMPLE_2);
 
-    return OCCloudAclCreateGroup(NULL, gtype, OPTIONAL(gmid), endPoint, callback);
+    return OCCloudAclCreateGroup(NULL, gtype, OPTIONAL(gmid), getUri(endPoint), callback);
 }
 
 OCStackResult OCWrapperAclFindMyGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
@@ -508,7 +515,7 @@ OCStackResult OCWrapperAclFindMyGroup(const OCDevAddr *endPoint, OCCloudResponse
 
     readOptionalString(mid, sizeof(mid), "member id value", UUID_EXAMPLE_2);
 
-    return OCCloudAclFindMyGroup(NULL, OPTIONAL(mid), endPoint, callback);
+    return OCCloudAclFindMyGroup(NULL, OPTIONAL(mid), getUri(endPoint), callback);
 }
 
 OCStackResult OCWrapperAclDeleteGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
@@ -520,7 +527,7 @@ OCStackResult OCWrapperAclDeleteGroup(const OCDevAddr *endPoint, OCCloudResponse
 
     readOptionalString(gmid, sizeof(gmid), "group member id value", UUID_EXAMPLE_2);
 
-    return OCCloudAclDeleteGroup(NULL, gid, OPTIONAL(gmid), endPoint, callback);
+    return OCCloudAclDeleteGroup(NULL, gid, OPTIONAL(gmid), getUri(endPoint), callback);
 }
 
 OCStackResult OCWrapperAclJoinToInvitedGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
@@ -529,7 +536,7 @@ OCStackResult OCWrapperAclJoinToInvitedGroup(const OCDevAddr *endPoint, OCCloudR
 
     readString(gid, sizeof(gid), "Group id value", ID_EXAMPLE_1);
 
-    return OCCloudAclJoinToInvitedGroup(NULL, gid, endPoint, callback);
+    return OCCloudAclJoinToInvitedGroup(NULL, gid, getUri(endPoint), callback);
 }
 
 OCStackResult OCWrapperAclObserveGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
@@ -538,7 +545,7 @@ OCStackResult OCWrapperAclObserveGroup(const OCDevAddr *endPoint, OCCloudRespons
 
     readString(gid, sizeof(gid), "Group id value", ID_EXAMPLE_1);
 
-    return OCCloudAclObserveGroup(NULL, gid, endPoint, callback);
+    return OCCloudAclObserveGroup(NULL, gid, getUri(endPoint), callback);
 }
 
 OCStackResult OCWrapperAclShareDeviceIntoGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
@@ -554,7 +561,7 @@ OCStackResult OCWrapperAclShareDeviceIntoGroup(const OCDevAddr *endPoint, OCClou
 
     readStringArray(&dilist, MAX_ID_LENGTH, "device list", UUID_EXAMPLE_1);
 
-    result = OCCloudAclShareDeviceIntoGroup(NULL, gid, &midlist, &dilist, endPoint, callback);
+    result = OCCloudAclShareDeviceIntoGroup(NULL, gid, &midlist, &dilist, getUri(endPoint), callback);
 
     clearStringArray(&midlist);
     clearStringArray(&dilist);
@@ -575,7 +582,7 @@ OCStackResult OCWrapperAclDeleteDeviceFromGroup(const OCDevAddr *endPoint, OCClo
 
     readStringArray(&dilist, MAX_ID_LENGTH, "device list", UUID_EXAMPLE_1);
 
-    result = OCCloudAclDeleteDeviceFromGroup(NULL, gid, &midlist, &dilist, endPoint, callback);
+    result = OCCloudAclDeleteDeviceFromGroup(NULL, gid, &midlist, &dilist, getUri(endPoint), callback);
 
     clearStringArray(&midlist);
     clearStringArray(&dilist);
@@ -592,7 +599,7 @@ OCStackResult OCWrapperAclGroupGetInfo(const OCDevAddr *endPoint, OCCloudRespons
 
     readOptionalString(mid, sizeof(mid), "member id value", UUID_EXAMPLE_2);
 
-    return OCCloudAclGroupGetInfo(NULL, gid, OPTIONAL(mid), endPoint, callback);
+    return OCCloudAclGroupGetInfo(NULL, gid, OPTIONAL(mid), getUri(endPoint), callback);
 }
 
 OCStackResult OCWrapperAclInviteUser(const OCDevAddr *endPoint, OCCloudResponseCB callback)
@@ -608,7 +615,7 @@ OCStackResult OCWrapperAclInviteUser(const OCDevAddr *endPoint, OCCloudResponseC
 
     readStringArray(&midlist, MAX_ID_LENGTH, "member id list", UUID_EXAMPLE_2);
 
-    result = OCCloudAclInviteUser(NULL, OPTIONAL(uid), &gidlist, &midlist, endPoint, callback);
+    result = OCCloudAclInviteUser(NULL, OPTIONAL(uid), &gidlist, &midlist, getUri(endPoint), callback);
 
     clearStringArray(&midlist);
     clearStringArray(&gidlist);
@@ -622,7 +629,7 @@ OCStackResult OCWrapperAclGetInvitation(const OCDevAddr *endPoint, OCCloudRespon
 
     readOptionalString(uid, sizeof(uid), "user uuid value", UUID_EXAMPLE_2);
 
-    return OCCloudAclGetInvitation(NULL, OPTIONAL(uid), endPoint, callback);
+    return OCCloudAclGetInvitation(NULL, OPTIONAL(uid), getUri(endPoint), callback);
 }
 
 OCStackResult OCWrapperAclDeleteInvitation(const OCDevAddr *endPoint, OCCloudResponseCB callback)
@@ -633,7 +640,7 @@ OCStackResult OCWrapperAclDeleteInvitation(const OCDevAddr *endPoint, OCCloudRes
     readOptionalString(uid, sizeof(uid), "user uuid value", UUID_EXAMPLE_2);
     readString(gid, sizeof(gid), "Group id value", ID_EXAMPLE_1);
 
-    return OCCloudAclDeleteInvitation(NULL, OPTIONAL(uid), gid, endPoint, callback);
+    return OCCloudAclDeleteInvitation(NULL, OPTIONAL(uid), gid, getUri(endPoint), callback);
 }
 
 OCStackResult OCWrapperAclCancelInvitation(const OCDevAddr *endPoint, OCCloudResponseCB callback)
@@ -647,7 +654,7 @@ OCStackResult OCWrapperAclCancelInvitation(const OCDevAddr *endPoint, OCCloudRes
     readString(gid, sizeof(gid), "Group id value", ID_EXAMPLE_1);
     readString(mid, sizeof(mid), "member id value", ID_EXAMPLE_1);
 
-    return OCCloudAclCancelInvitation(NULL, OPTIONAL(uid), gid, mid, endPoint, callback);
+    return OCCloudAclCancelInvitation(NULL, OPTIONAL(uid), gid, mid, getUri(endPoint), callback);
 }
 
 OCStackResult OCWrapperAclPolicyCheck(const OCDevAddr *endPoint, OCCloudResponseCB callback)
@@ -662,5 +669,5 @@ OCStackResult OCWrapperAclPolicyCheck(const OCDevAddr *endPoint, OCCloudResponse
     readString(rm, sizeof(rm), "request method", "GET or POST or DELETE");
     readString(user_uri, sizeof(user_uri), "request uri", RESOURCE_URI_EXAMPLE);
 
-    return OCCloudAclPolicyCheck(NULL, sid, di, rm, user_uri, endPoint, callback);
+    return OCCloudAclPolicyCheck(NULL, sid, di, rm, user_uri, getUri(endPoint), callback);
 }
index d1f2a47..9264e3e 100644 (file)
@@ -54,9 +54,7 @@ namespace OC
 
     OCCloudProvisioning::OCCloudProvisioning(std::string& ipAddr, uint16_t port)
     {
-        memset(&m_devAddr, 0, sizeof(m_devAddr));
-        memcpy(m_devAddr.addr, ipAddr.c_str(), MAX_ADDR_STR_SIZE);
-        m_devAddr.port = port;
+        m_devAddr = ipAddr + ":" + std::to_string(port);
     }
 
     OCCloudProvisioning::~OCCloudProvisioning(void)
@@ -79,7 +77,7 @@ namespace OC
             CloudProvisionContext *context = new CloudProvisionContext(callback);
 
             std::lock_guard<std::recursive_mutex> lock(*cLock);
-            result = OCCloudCertificateIssueRequest(static_cast<void*>(context), &m_devAddr,
+            result = OCCloudCertificateIssueRequest(static_cast<void*>(context), m_devAddr.c_str(),
                     &OCCloudProvisioning::callbackWrapper);
         }
         else
@@ -108,7 +106,7 @@ namespace OC
 
             std::lock_guard<std::recursive_mutex> lock(*cLock);
             result = OCCloudAclIndividualGetInfo(static_cast<void*>(context), aclId.c_str(),
-                    &m_devAddr,
+                    m_devAddr.c_str(),
                     &OCCloudProvisioning::callbackWrapper);
         }
         else
@@ -137,7 +135,7 @@ namespace OC
 
             std::lock_guard<std::recursive_mutex> lock(*cLock);
             result = OCCloudGetAclIdByDevice(static_cast<void*>(context), deviceId.c_str(),
-                    &m_devAddr,
+                    m_devAddr.c_str(),
                     &OCCloudProvisioning::aclIdResponseWrapper);
         }
         else
@@ -166,7 +164,7 @@ namespace OC
 
             std::lock_guard<std::recursive_mutex> lock(*cLock);
             result = OCCloudAclIdCreate(static_cast<void*>(context), ownerId.c_str(),
-                                        deviceId.c_str(), &m_devAddr,
+                                        deviceId.c_str(), m_devAddr.c_str(),
                                         &OCCloudProvisioning::aclIdResponseWrapper);
         }
         else
@@ -193,7 +191,7 @@ namespace OC
             CloudProvisionContext *context = new CloudProvisionContext(callback);
 
             std::lock_guard<std::recursive_mutex> lock(*cLock);
-            result = OCCloudGetCRL(static_cast<void*>(context), &m_devAddr,
+            result = OCCloudGetCRL(static_cast<void*>(context), m_devAddr.c_str(),
                     &OCCloudProvisioning::callbackWrapper);
         }
         else
@@ -225,7 +223,7 @@ namespace OC
 
             std::lock_guard<std::recursive_mutex> lock(*cLock);
             result = OCCloudAclIndividualAclUpdate(static_cast<void*>(context), aclId.c_str(),
-                    aces, &m_devAddr, &OCCloudProvisioning::callbackWrapper);
+                    aces, m_devAddr.c_str(), &OCCloudProvisioning::callbackWrapper);
         }
         else
         {
@@ -256,7 +254,7 @@ namespace OC
 
             std::lock_guard<std::recursive_mutex> lock(*cLock);
             result = OCCloudPostCRL(static_cast<void*>(context), thisUpdate.c_str(),
-                    nextUpdate.c_str(), crl, serialNumbers, &m_devAddr,
+                    nextUpdate.c_str(), crl, serialNumbers, m_devAddr.c_str(),
                     &OCCloudProvisioning::callbackWrapper);
         }
         else