Update pstat's device id in case of default
authorYonggoo Kang <ygace.kang@samsung.com>
Wed, 30 Mar 2016 06:40:11 +0000 (15:40 +0900)
committerRandeep Singh <randeep.s@samsung.com>
Wed, 30 Mar 2016 09:52:45 +0000 (09:52 +0000)
Change-Id: Ia7b7b24bbf39a42a761d9a872a62909b78064cae
Signed-off-by: Yonggoo Kang <ygace.kang@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/7459
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Kyungsun Cho <goodsun.cho@samsung.com>
Reviewed-by: Chul Lee <chuls.lee@samsung.com>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
resource/csdk/security/src/pstatresource.c

index 25f143c..5af8afd 100644 (file)
@@ -491,6 +491,7 @@ OCStackResult InitPstatResource()
     // Read Pstat resource from PS
     uint8_t *data = NULL;
     size_t size = 0;
+    OicUuid_t emptyUuid = {.id={0}};
     ret = GetSecureVirtualDatabaseFromPS(OIC_JSON_PSTAT_NAME, &data, &size);
     // If database read failed
     if (OC_STACK_OK != ret)
@@ -499,21 +500,9 @@ OCStackResult InitPstatResource()
     }
     if (data)
     {
-        OicUuid_t emptyUuid = {.id={0}};
-
         // Read ACL resource from PS
         ret = CBORPayloadToPstat(data, size, &gPstat);
         OICFree(data);
-
-        //In case of PStat's device id is empty, fill the device id as doxm's device id.
-        if(memcmp(&gPstat->deviceID, &emptyUuid, sizeof(OicUuid_t)) == 0)
-        {
-            OicUuid_t doxmUuid = {.id={0}};
-            if(OC_STACK_OK == GetDoxmDeviceID(&doxmUuid))
-            {
-                memcpy(&gPstat->deviceID, &doxmUuid, sizeof(OicUuid_t));
-            }
-        }
     }
     /*
      * If SVR database in persistent storage got corrupted or
@@ -526,6 +515,16 @@ OCStackResult InitPstatResource()
     }
     VERIFY_NON_NULL(TAG, gPstat, FATAL);
 
+    //In case of Pstat's device id is empty, fill the device id as doxm's device id.
+    if(0 == memcmp(&gPstat->deviceID, &emptyUuid, sizeof(OicUuid_t)))
+    {
+        OicUuid_t doxmUuid = {.id={0}};
+        if(OC_STACK_OK == GetDoxmDeviceID(&doxmUuid))
+        {
+            memcpy(&gPstat->deviceID, &doxmUuid, sizeof(OicUuid_t));
+        }
+    }
+
     // Instantiate 'oic.sec.pstat'
     ret = CreatePstatResource();