[IOT-2642] DELETE /roles succeeds if no entry 13/22113/2
authorNathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Thu, 24 Aug 2017 16:35:18 +0000 (09:35 -0700)
committerRandeep Singh <randeep.s@samsung.com>
Tue, 29 Aug 2017 05:22:03 +0000 (05:22 +0000)
The DELETE request to /roles is meant to remove all /roles entries
corresponding to the current peer.  In the case of no /roles entries
existing, IoTivity was returning error, but should return "deleted"
instead.

Change-Id: Ib98c64822fe77eb7457bd734b168f1b26efd0d61
Signed-off-by: Nathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Signed-off-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/22113
Reviewed-by: Alex Kelley <alexke@microsoft.com>
Reviewed-by: Ibrahim Esmat <iesmat@microsoft.com>
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
resource/csdk/security/src/rolesresource.c

index 95097d0..4e9d511 100644 (file)
@@ -76,7 +76,7 @@ static RolesEntry_t         *gRoles             = NULL;
 static SymmetricRoleEntry_t *gSymmetricRoles    = NULL;
 static uint32_t             gIdCounter          = 1;
 
-/** 
+/**
  * Default cbor payload size. This value is increased in case of CborErrorOutOfMemory.
  * The value of payload size is increased until reaching max cbor size.
  */
@@ -323,7 +323,7 @@ exit:
 static bool RoleCertChainContains(RoleCertChain_t *chain, const RoleCertChain_t* roleCert)
 {
     RoleCertChain_t *temp = NULL;
-    
+
     LL_FOREACH(chain, temp)
     {
         if (IsSameSecKey(&temp->certificate, &roleCert->certificate) &&
@@ -943,7 +943,7 @@ static OCEntityHandlerResult HandleDeleteRequest(OCEntityHandlerRequest *ehReque
     if (OC_STACK_OK != res)
     {
         OIC_LOG_V(ERROR, TAG, "Could not get peer's public key: %d", res);
-        ehRet = OC_EH_ERROR;
+        ehRet = OC_EH_RESOURCE_DELETED;
         goto exit;
     }
 
@@ -961,8 +961,9 @@ static OCEntityHandlerResult HandleDeleteRequest(OCEntityHandlerRequest *ehReque
     if (NULL == entry)
     {
         /* No entry for this peer. */
-        OIC_LOG(ERROR, TAG, "No entry for this peer's public key");
-        ehRet = OC_EH_ERROR;
+        OIC_LOG(WARNING, TAG, "No roles for this peer's public key");
+        // if no entry, the request is successful by definition
+        ehRet = OC_EH_RESOURCE_DELETED;
         goto exit;
     }
 
@@ -977,7 +978,7 @@ static OCEntityHandlerResult HandleDeleteRequest(OCEntityHandlerRequest *ehReque
         {
             LL_DELETE(entry->chains, curr1);
             FreeRoleCertChain(curr1);
-            ehRet = OC_EH_OK;
+            ehRet = OC_EH_RESOURCE_DELETED;
             break;
         }
     }
@@ -1151,7 +1152,7 @@ OCStackResult GetEndpointRoles(const CAEndpoint_t *endpoint, OicSecRole_t **role
         SymmetricRoleEntry_t *curr = NULL;
         LL_FOREACH(gSymmetricRoles, curr)
         {
-            if ((UUID_LENGTH == sep.identity.id_length) && 
+            if ((UUID_LENGTH == sep.identity.id_length) &&
                 (0 == memcmp(curr->subject.id, sep.identity.id, sizeof(curr->subject.id))))
             {
                 *roles = (OicSecRole_t *)OICCalloc(1, sizeof(OicSecRole_t));