Update the cred's POST request handler to accept rowner update request.
authorChul Lee <chuls.lee@samsung.com>
Thu, 3 Nov 2016 09:24:52 +0000 (18:24 +0900)
committerRandeep Singh <randeep.s@samsung.com>
Mon, 7 Nov 2016 05:49:02 +0000 (05:49 +0000)
This update can handle the following payload :
   {"rowneruuid":"28516ab8-b35a-4726-a082-ee7685c33c8c"}

Change-Id: Ibee20c99ff05409fdaf44c2bdac209b871bde043
Signed-off-by: Chul Lee <chuls.lee@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13993
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jongmin Choi <jminl.choi@samsung.com>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
resource/csdk/security/src/credresource.c [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index fb273fa..74126f6
@@ -171,6 +171,24 @@ exit:
     return false;
 }
 
+static bool IsEmptyCred(const OicSecCred_t* cred)
+{
+    OicUuid_t emptyUuid = {.id={0}};
+
+    VERIFY_SUCCESS(TAG, (0 == memcmp(cred->subject.id, emptyUuid.id, sizeof(emptyUuid))), ERROR);
+    VERIFY_SUCCESS(TAG, (0 == cred->credId), ERROR);
+    VERIFY_SUCCESS(TAG, (0 == cred->credType), ERROR);
+#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
+    VERIFY_SUCCESS(TAG, (NULL == cred->privateData.data), ERROR);
+    VERIFY_SUCCESS(TAG, (NULL == cred->publicData.data), ERROR);
+    VERIFY_SUCCESS(TAG, (NULL == cred->optionalData.data), ERROR);
+    VERIFY_SUCCESS(TAG, (NULL == cred->credUsage), ERROR);
+#endif
+    return true;
+exit:
+    return false;
+}
+
 /**
  * This function frees OicSecCred_t object's fields and object itself.
  */
@@ -1836,7 +1854,6 @@ static OCEntityHandlerResult HandlePostRequest(const OCEntityHandlerRequest * eh
                          */
                         if(OIC_RANDOM_DEVICE_PIN == doxm->oxmSel)
                         {
-                            OicUuid_t emptyUuid = { .id={0}};
                             SetUuidForPinBasedOxm(&emptyUuid);
 
 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
@@ -1969,13 +1986,37 @@ static OCEntityHandlerResult HandlePostRequest(const OCEntityHandlerRequest * eh
 #endif //_ENABLE_MULTIPLE_OWNER_
         else
         {
-            /*
-             * If the post request credential has credId, it will be
-             * discarded and the next available credId will be assigned
-             * to it before getting appended to the existing credential
-             * list and updating svr database.
-             */
-            ret = (OC_STACK_OK == AddCredential(cred))? OC_EH_CHANGED : OC_EH_ERROR;
+            if(IsEmptyCred(cred))
+            {
+                OicUuid_t emptyUuid = {.id={0}};
+                if(memcmp(cred->rownerID.id, emptyUuid.id, sizeof(emptyUuid.id)) != 0)
+                {
+                    OIC_LOG(INFO, TAG, "CRED's rowner will be updated.");
+                    memcpy(gCred->rownerID.id, cred->rownerID.id, sizeof(cred->rownerID.id));
+                    if (UpdatePersistentStorage(gCred))
+                    {
+                        ret = OC_EH_CHANGED;
+                    }
+                    else
+                    {
+                        ret = OC_EH_ERROR;
+                    }
+                }
+                else
+                {
+                    ret = OC_EH_ERROR;
+                }
+            }
+            else
+            {
+                /*
+                 * If the post request credential has credId, it will be
+                 * discarded and the next available credId will be assigned
+                 * to it before getting appended to the existing credential
+                 * list and updating svr database.
+                 */
+                ret = (OC_STACK_OK == AddCredential(cred))? OC_EH_CHANGED : OC_EH_ERROR;
+            }
         }
 #else //not __WITH_DTLS__
         /*