/** * @todo document this function including why code might need to call this. * The current suspicion is that it's not being called as much as it should. */ static bool UpdatePersistentStorage(OicSecDoxm_t * doxm) { bool bRet = false; if (NULL != doxm) { // Convert Doxm data into JSON for update to persistent storage char *jsonStr = BinToDoxmJSON(doxm); if (jsonStr) { cJSON *jsonDoxm = cJSON_Parse(jsonStr); OICFree(jsonStr); if (jsonDoxm && (OC_STACK_OK == UpdateSVRDatabase(OIC_JSON_DOXM_NAME, jsonDoxm))) { bRet = true; } cJSON_Delete(jsonDoxm); } } return bRet; }
/** * Function to update persistent storage */ static bool UpdatePersistentStorage(OicSecPstat_t * pstat) { bool bRet = false; if (pstat) { // Convert pstat data into JSON for update to persistent storage char *jsonStr = BinToPstatJSON(pstat); if (jsonStr) { cJSON *jsonPstat = cJSON_Parse(jsonStr); OICFree(jsonStr); if (jsonPstat && (OC_STACK_OK == UpdateSVRDatabase(OIC_JSON_PSTAT_NAME, jsonPstat))) { bRet = true; } cJSON_Delete(jsonPstat); } } return bRet; }
/** * The entity handler determines how to process a POST request. * Per the REST paradigm, POST can also be used to update representation of existing * resource or create a new resource. * For pstat, it updates only tm and om. */ static OCEntityHandlerResult HandlePstatPutRequest(const OCEntityHandlerRequest *ehRequest) { OCEntityHandlerResult ehRet = OC_EH_ERROR; cJSON *postJson = NULL; OC_LOG (INFO, TAG, "HandlePstatPutRequest processing PUT request"); if (ehRequest->resource) { postJson = cJSON_Parse(((OCSecurityPayload*)ehRequest->payload)->securityData); VERIFY_NON_NULL(TAG, postJson, INFO); cJSON *commitHashJson = cJSON_GetObjectItem(postJson, OIC_JSON_COMMIT_HASH_NAME); uint16_t commitHash = 0; if (commitHashJson) { commitHash = commitHashJson->valueint; } cJSON *tmJson = cJSON_GetObjectItem(postJson, OIC_JSON_TM_NAME); if (tmJson && gPstat) { gPstat->tm = (OicSecDpm_t)tmJson->valueint; if(0 == tmJson->valueint && gPstat->commitHash == commitHash) { gPstat->isOp = true; gPstat->cm = NORMAL; OC_LOG (INFO, TAG, "CommitHash is valid and isOp is TRUE"); } else { OC_LOG (INFO, TAG, "CommitHash is not valid"); } } cJSON *omJson = cJSON_GetObjectItem(postJson, OIC_JSON_OM_NAME); if (omJson && gPstat) { /* * Check if the operation mode is in the supported provisioning services * operation mode list. */ for(size_t i=0; i< gPstat->smLen; i++) { if(gPstat->sm[i] == (unsigned int)omJson->valueint) { gPstat->om = (OicSecDpom_t)omJson->valueint; break; } } } // Convert pstat data into JSON for update to persistent storage char *jsonStr = BinToPstatJSON(gPstat, true); if (jsonStr) { cJSON *jsonPstat = cJSON_Parse(jsonStr); OICFree(jsonStr); if (OC_STACK_OK == UpdateSVRDatabase(OIC_JSON_PSTAT_NAME, jsonPstat)) { ehRet = OC_EH_OK; } } } exit: //Send payload to request originator if(OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, NULL)) { OC_LOG (ERROR, TAG, "SendSRMResponse failed in HandlePstatPostRequest"); } cJSON_Delete(postJson); return ehRet; }