- cJSON *jsonPstat = NULL;
- cJSON *jsonObj = NULL;
-
- unsigned char base64Buff[sizeof(((OicUuid_t*) 0)->id)] = {};
- uint32_t outLen = 0;
- B64Result b64Ret = B64_OK;
-
- cJSON *jsonRoot = cJSON_Parse(jsonStr);
- VERIFY_NON_NULL(TAG, jsonRoot, INFO);
-
- jsonPstat = cJSON_GetObjectItem(jsonRoot, OIC_JSON_PSTAT_NAME);
- VERIFY_NON_NULL(TAG, jsonPstat, INFO);
-
- pstat = (OicSecPstat_t*)OICCalloc(1, sizeof(OicSecPstat_t));
- VERIFY_NON_NULL(TAG, pstat, INFO);
- jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_ISOP_NAME);
- VERIFY_NON_NULL(TAG, jsonObj, ERROR);
- VERIFY_SUCCESS(TAG, (cJSON_True == jsonObj->type || cJSON_False == jsonObj->type) , ERROR);
- pstat->isOp = jsonObj->valueint;
-
- jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_DEVICE_ID_NAME);
- VERIFY_NON_NULL(TAG, jsonObj, ERROR);
- VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR);
- b64Ret = b64Decode(jsonObj->valuestring, strlen(jsonObj->valuestring), base64Buff,
- sizeof(base64Buff), &outLen);
- VERIFY_SUCCESS(TAG, (b64Ret == B64_OK && outLen <= sizeof(pstat->deviceID.id)), ERROR);
- memcpy(pstat->deviceID.id, base64Buff, outLen);
-
- jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_COMMIT_HASH_NAME);
- VERIFY_NON_NULL(TAG, jsonObj, ERROR);
- VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
- pstat->commitHash = jsonObj->valueint;
-
- jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_CM_NAME);
- VERIFY_NON_NULL(TAG, jsonObj, ERROR);
- VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
- pstat->cm = (OicSecDpm_t)jsonObj->valueint;
-
- jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_OM_NAME);
- VERIFY_NON_NULL(TAG, jsonObj, ERROR);
- VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
- pstat->om = (OicSecDpom_t)jsonObj->valueint;
-
- jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_SM_NAME);
- VERIFY_NON_NULL(TAG, jsonObj, ERROR);
- if (cJSON_Array == jsonObj->type)
- {
- pstat->smLen = cJSON_GetArraySize(jsonObj);
- size_t idxx = 0;
- VERIFY_SUCCESS(TAG, pstat->smLen != 0, ERROR);
+ cborFindResult = cbor_value_enter_container(&pstatCbor, &pstatMap);
+ VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding PSTAT Map.");
+
+ pstat = (OicSecPstat_t *)OICCalloc(1, sizeof(OicSecPstat_t));
+ VERIFY_NON_NULL(TAG, pstat, ERROR);
+
+ cborFindResult = cbor_value_map_find_value(&pstatCbor, OIC_JSON_ISOP_NAME, &pstatMap);
+ if (CborNoError == cborFindResult && cbor_value_is_boolean(&pstatMap))
+ {
+ cborFindResult = cbor_value_get_boolean(&pstatMap, &pstat->isOp);
+ VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding isOp Value.");
+ }
+ else
+ {
+ pstat->isOp = gPstat->isOp;
+ cborFindResult = CborNoError;
+ }
+
+ cborFindResult = cbor_value_map_find_value(&pstatCbor, OIC_JSON_DEVICE_ID_NAME, &pstatMap);
+ if (CborNoError == cborFindResult && cbor_value_is_text_string(&pstatMap))
+ {
+ cborFindResult = cbor_value_dup_text_string(&pstatMap, &strUuid , &len, NULL);
+ VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Device Id Value.");
+ ret = ConvertStrToUuid(strUuid , &pstat->deviceID);
+ VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
+ OICFree(strUuid );
+ strUuid = NULL;
+
+ }
+ else
+ {
+ memcpy(&pstat->deviceID, &gPstat->deviceID, sizeof(OicUuid_t));
+ cborFindResult = CborNoError;
+ }
+
+ cborFindResult = cbor_value_map_find_value(&pstatCbor, OIC_JSON_CM_NAME, &pstatMap);
+ if (CborNoError == cborFindResult && cbor_value_is_integer(&pstatMap))
+ {
+ int cm;
+
+ cborFindResult = cbor_value_get_int(&pstatMap, &cm);
+ VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding CM.");
+ pstat->cm = (OicSecDpm_t)cm;
+ }
+ else
+ {
+ pstat->cm = gPstat->cm;
+ cborFindResult = CborNoError;
+ }
+
+ cborFindResult = cbor_value_map_find_value(&pstatCbor, OIC_JSON_TM_NAME, &pstatMap);
+ if (CborNoError == cborFindResult && cbor_value_is_integer(&pstatMap))
+ {
+ int tm;
+
+ cborFindResult = cbor_value_get_int(&pstatMap, &tm);
+ VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding TM.");
+ pstat->tm = (OicSecDpm_t)tm;
+ }
+ else
+ {
+ pstat->tm = gPstat->tm;
+ cborFindResult = CborNoError;
+ }
+
+ cborFindResult = cbor_value_map_find_value(&pstatCbor, OIC_JSON_OM_NAME, &pstatMap);
+ if (CborNoError == cborFindResult && cbor_value_is_integer(&pstatMap))
+ {
+ int om;
+
+ cborFindResult = cbor_value_get_int(&pstatMap, &om);
+ VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding OM.");
+ pstat->om = (OicSecDpom_t)om;
+ }
+ else
+ {
+ pstat->om = gPstat->om;
+ cborFindResult = CborNoError;
+ }
+
+ cborFindResult = cbor_value_map_find_value(&pstatCbor, OIC_JSON_SM_NAME, &pstatMap);
+ if (CborNoError == cborFindResult && cbor_value_is_integer(&pstatMap))
+ {
+ int sm;
+
+ pstat->smLen = 1;