Merge branch '1.1-rel'
[platform/upstream/iotivity.git] / resource / csdk / security / src / aclresource.c
index 4369e7b..d2b9f4b 100644 (file)
@@ -141,10 +141,10 @@ OCStackResult AclToCBORPayload(const OicSecAcl_t *secAcl, uint8_t **payload, siz
     OCStackResult ret = OC_STACK_ERROR;
     CborError cborEncoderResult = CborNoError;
     OicSecAcl_t *acl = (OicSecAcl_t *)secAcl;
-    CborEncoder encoder = { {.ptr = NULL }, .end = 0 };
-    CborEncoder aclMap = { {.ptr = NULL }, .end = 0 };
-    CborEncoder aclListMap = { {.ptr = NULL }, .end = 0 };
-    CborEncoder acesArray = { {.ptr = NULL }, .end = 0 };
+    CborEncoder encoder;
+    CborEncoder aclMap;
+    CborEncoder aclListMap;
+    CborEncoder acesArray;
     uint8_t *outPayload = NULL;
     size_t cborLen = *size;
     *size = 0;
@@ -181,7 +181,7 @@ OCStackResult AclToCBORPayload(const OicSecAcl_t *secAcl, uint8_t **payload, siz
 
     while (acl)
     {
-        CborEncoder oicSecAclMap = { {.ptr = NULL }, .end = 0, .added = 0, .flags = 0 };
+        CborEncoder oicSecAclMap;
         // ACL Map size - Number of mandatory items
         uint8_t aclMapSize = ACL_ACES_MAP_SIZE;
         size_t inLen = 0;
@@ -223,7 +223,7 @@ OCStackResult AclToCBORPayload(const OicSecAcl_t *secAcl, uint8_t **payload, siz
 
         // Resources
         {
-            CborEncoder resources = { {.ptr = NULL }, .end = 0, .added = 0, .flags = 0 };
+            CborEncoder resources;
             cborEncoderResult = cbor_encode_text_string(&oicSecAclMap, OIC_JSON_RESOURCES_NAME,
                 strlen(OIC_JSON_RESOURCES_NAME));
             VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding Resource Name Tag.");
@@ -234,7 +234,7 @@ OCStackResult AclToCBORPayload(const OicSecAcl_t *secAcl, uint8_t **payload, siz
             for (size_t i = 0; i < acl->resourcesLen; i++)
             {
 
-                CborEncoder rMap = { {.ptr = NULL }, .end = 0 };
+                CborEncoder rMap;
                 cborEncoderResult = cbor_encoder_create_map(&resources, &rMap, ACL_RESOURCE_MAP_SIZE);
                 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding Resource Map.");
 
@@ -399,7 +399,7 @@ exit:
 // note: This function is used in unit test hence not declared static,
 OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size)
 {
-    if (NULL == cborPayload)
+    if (NULL == cborPayload || 0 == size)
     {
         return NULL;
     }
@@ -950,7 +950,12 @@ exit:
     ehRet = (payload ? OC_EH_OK : OC_EH_ERROR);
 
     // Send response payload to request originator
-    SendSRMCBORResponse(ehRequest, ehRet, payload, size);
+    if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, payload, size))
+    {
+        ehRet = OC_EH_ERROR;
+        OIC_LOG(ERROR, TAG, "SendSRMResponse failed for HandleACLGetRequest");
+    }
+    OICFree(payload);
 
     OIC_LOG_V(DEBUG, TAG, "%s RetVal %d", __func__, ehRet);
     return ehRet;
@@ -962,7 +967,7 @@ static OCEntityHandlerResult HandleACLPostRequest(const OCEntityHandlerRequest *
     OCEntityHandlerResult ehRet = OC_EH_ERROR;
 
     // Convert CBOR into ACL data and update to SVR buffers. This will also validate the ACL data received.
-    uint8_t *payload = ((OCSecurityPayload *) ehRequest->payload)->securityData1;
+    uint8_t *payload = ((OCSecurityPayload *) ehRequest->payload)->securityData;
     size_t size = ((OCSecurityPayload *) ehRequest->payload)->payloadSize;
     if (payload)
     {
@@ -994,7 +999,11 @@ static OCEntityHandlerResult HandleACLPostRequest(const OCEntityHandlerRequest *
     }
 
     // Send payload to request originator
-    SendSRMCBORResponse(ehRequest, ehRet, NULL, 0);
+    if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, NULL, 0))
+    {
+        ehRet = OC_EH_ERROR;
+        OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandleACLPostRequest");
+    }
 
     OIC_LOG_V(DEBUG, TAG, "%s RetVal %d", __func__, ehRet);
     return ehRet;
@@ -1021,7 +1030,11 @@ static OCEntityHandlerResult HandleACLDeleteRequest(const OCEntityHandlerRequest
 
 exit:
     // Send payload to request originator
-    SendSRMCBORResponse(ehRequest, ehRet, NULL, 0);
+    if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, NULL, 0))
+    {
+        ehRet = OC_EH_ERROR;
+        OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandleACLDeleteRequest");
+    }
 
     return ehRet;
 }
@@ -1058,7 +1071,7 @@ OCEntityHandlerResult ACLEntityHandler(OCEntityHandlerFlag flag, OCEntityHandler
 
             default:
                 ehRet = OC_EH_ERROR;
-                SendSRMCBORResponse(ehRequest, ehRet, NULL, 0);
+                SendSRMResponse(ehRequest, ehRet, NULL, 0);
         }
     }
 
@@ -1486,3 +1499,14 @@ exit:
     memcpy(gAcl->rownerID.id, prevId.id, sizeof(prevId.id));
     return ret;
 }
+
+OCStackResult GetAclRownerId(OicUuid_t *rowneruuid)
+{
+    OCStackResult retVal = OC_STACK_ERROR;
+    if (gAcl)
+    {
+        *rowneruuid = gAcl->rownerID;
+        retVal = OC_STACK_OK;
+    }
+    return retVal;
+}