From: Chul Lee Date: Thu, 3 Nov 2016 09:24:52 +0000 (+0900) Subject: Update the cred's POST request handler to accept rowner update request. X-Git-Tag: 1.2.1~179 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=210bfd947e151abaa37c80fd1bdad0c5b731a768;p=platform%2Fupstream%2Fiotivity.git Update the cred's POST request handler to accept rowner update request. This update can handle the following payload : {"rowneruuid":"28516ab8-b35a-4726-a082-ee7685c33c8c"} Change-Id: Ibee20c99ff05409fdaf44c2bdac209b871bde043 Signed-off-by: Chul Lee Reviewed-on: https://gerrit.iotivity.org/gerrit/13993 Tested-by: jenkins-iotivity Reviewed-by: Jongmin Choi Reviewed-by: Randeep Singh --- diff --git a/resource/csdk/security/src/credresource.c b/resource/csdk/security/src/credresource.c old mode 100755 new mode 100644 index fb273fa..74126f6 --- a/resource/csdk/security/src/credresource.c +++ b/resource/csdk/security/src/credresource.c @@ -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__ /*