+ OIC_LOG_V(INFO, TAG, "In %s", __func__);
+
+ FILE *fp = NULL;
+ OCStackResult ret = OC_STACK_SVR_DB_NOT_EXIST;
+ OicSecDoxm_t* doxm = NULL;
+ OicSecPstat_t* pstat = NULL;
+ uint8_t *data = NULL;
+ size_t size = 0;
+
+ if (NULL == ps)
+ {
+ OIC_LOG(ERROR, TAG, "NULL PersistentStorage Parameter");
+ ret = OC_STACK_INVALID_PARAM;
+ goto exit;
+ }
+
+ // Check whether the DB file exists
+ fp = ps->open(SVR_DB_DAT_FILE_NAME, "r+b");
+ if (NULL == fp)
+ {
+ OIC_LOG(ERROR, TAG, "DB file cannot be opened");
+ ret = OC_STACK_SVR_DB_NOT_EXIST;
+ SetPSStatus(PS_OPEN_FAIL);
+ goto exit;
+ }
+ ps->close(fp);
+
+ OIC_LOG(INFO, TAG, "Checking doxm resource...");
+ //Check DOXM resource
+ ret = GetSecureVirtualDatabaseFromPS2(ps, OIC_JSON_DOXM_NAME, &data, &size);
+ // If database read failed
+ if (OC_STACK_OK != ret)
+ {
+ OIC_LOG (ERROR, TAG, "Can not find the DOXM Resource in SVR DB.");
+ ret = OC_STACK_INCONSISTENT_DB;
+ SetPSStatus(PS_PARSE_FAIL);
+ goto exit;
+ }
+ if (data && 0 < size)
+ {
+ // Read DOXM resource from PS
+ ret = CBORPayloadToDoxm(data, size, &doxm);
+ if (OC_STACK_OK != ret)
+ {
+ OIC_LOG_V(ERROR, TAG, "Failed to Convert CBOR to Doxm bin : %d", ret);
+ ret = OC_STACK_INCONSISTENT_DB;
+ SetPSStatus(PS_PARSE_FAIL);
+ goto exit;
+ }
+ }
+ else
+ {
+ ret = OC_STACK_INCONSISTENT_DB;
+ SetPSStatus(PS_PARSE_FAIL);
+ goto exit;
+ }
+ if (data)
+ {
+ OICFree(data);
+ data = NULL;
+ }
+
+ OIC_LOG(INFO, TAG, "Checking pstat resource...");
+ //Check PSTAT resource
+ ret = GetSecureVirtualDatabaseFromPS2(ps, OIC_JSON_PSTAT_NAME, &data, &size);
+ // If database read failed
+ if (OC_STACK_OK != ret)
+ {
+ OIC_LOG (ERROR, TAG, "Can not find the PSTAT Resource in SVR DB.");
+ ret = OC_STACK_INCONSISTENT_DB;
+ SetPSStatus(PS_PARSE_FAIL);
+ goto exit;
+ }
+ if (data && 0 < size)
+ {
+ // Read ACL resource from PS
+ ret = CBORPayloadToPstat(data, size, &pstat);
+ if (OC_STACK_OK != ret)
+ {
+ OIC_LOG_V(ERROR, TAG, "Failed to Convert CBOR to PSTAT bin : %d", ret);
+ ret = OC_STACK_INCONSISTENT_DB;
+ SetPSStatus(PS_PARSE_FAIL);
+ goto exit;
+ }
+ }
+ else
+ {
+ ret = OC_STACK_INCONSISTENT_DB;
+ SetPSStatus(PS_PARSE_FAIL);
+ goto exit;
+ }
+ if (data)
+ {
+ OICFree(data);
+ data = NULL;
+ }
+
+ SetPSStatus(PS_NORMAL);
+
+ ret = OC_STACK_OK;
+ OIC_LOG(INFO, TAG, "All Secure Virtual Resources are fine.");
+
+exit:
+ if (data)
+ {
+ OICFree(data);
+ }
+ if (doxm)
+ {
+ DeleteDoxmBinData(doxm);
+ }
+ if (pstat)
+ {
+ DeletePstatBinData(pstat);
+ }
+
+ OIC_LOG_V(INFO, TAG, "Out %s", __func__);
+
+ return ret;