[IOT-3121] Fix rts values of Collection Resource 37/27637/1 feat-atomicmeasurement feat-linkupdate-and-collection-access-control master otgc-dekra-changes
authorMushfiqul Islam Antu <i.mushfiq@samsung.com>
Fri, 30 Nov 2018 09:13:51 +0000 (15:13 +0600)
committerMushfiqul Islam <mmiantu@gmail.com>
Tue, 4 Dec 2018 03:55:51 +0000 (03:55 +0000)
For baseline response of collection, value of rt & rts
are same for current implementation, which is wrong.
rts should reflect the resource types of the chlidren
of the collection.

Change-Id: Ib4e768c7401247dc9dd4917ff5a611396e8e07a2
Signed-off-by: Mushfiqul Islam Antu <i.mushfiq@samsung.com>
resource/csdk/stack/src/occollection.c

index 081f10c..ad1f2e4 100644 (file)
 #include "cainterface.h"
 #define TAG "OIC_RI_COLLECTION"
 
-static bool AddRTSBaselinePayload(OCRepPayload **linkArray, int size, OCRepPayload **colPayload)
+static bool AddRTSBaselinePayload(const OCResource* collResource, OCRepPayload **colPayload)
 {
     size_t arraySize = 0;
-    for (int j = 0; j < size; j++)
+    for (OCChildResource *tempChildResource = collResource->rsrcChildResourcesHead;
+        tempChildResource; tempChildResource = tempChildResource->next)
     {
-        size_t rtDim[MAX_REP_ARRAY_DEPTH] = {0};
-        char **rt = NULL;
-        OCRepPayloadGetStringArray(linkArray[j], OC_RSRVD_RESOURCE_TYPE, &rt, rtDim);
-        arraySize += rtDim[0];
-        for (size_t l = 0; l < rtDim[0]; l++)
+        OCResource* currentResource = tempChildResource->rsrcResource;
+        OCResourceType* currentType = currentResource->rsrcType;
+        while(currentType)
         {
-            OICFree(rt[l]);
+            arraySize++;
+            currentType = currentType->next;
         }
-        OICFree(rt);
     }
 
-    for (OCStringLL *rsrcType = (*colPayload)->types; rsrcType; rsrcType = rsrcType->next, arraySize++);
-
     OIC_LOG_V(DEBUG, TAG, "Number of RTS elements : %zd", arraySize);
     size_t dim[MAX_REP_ARRAY_DEPTH] = {arraySize, 0, 0};
     char **rts = (char **)OICMalloc(sizeof(char *) * arraySize);
@@ -64,21 +61,16 @@ static bool AddRTSBaselinePayload(OCRepPayload **linkArray, int size, OCRepPaylo
         return OC_STACK_NO_MEMORY;
     }
     int k = 0;
-    for (int j = 0; j < size; j++)
+    for (OCChildResource *tempChildResource = collResource->rsrcChildResourcesHead;
+        tempChildResource; tempChildResource = tempChildResource->next)
     {
-        size_t rtDim[MAX_REP_ARRAY_DEPTH] = {0};
-        char **rt = NULL;
-        OCRepPayloadGetStringArray(linkArray[j], OC_RSRVD_RESOURCE_TYPE, &rt, rtDim);
-        for (size_t l = 0; l < rtDim[0]; l++)
+        OCResource* currentResource = tempChildResource->rsrcResource;
+        OCResourceType* currentType = currentResource->rsrcType;
+        while(currentType)
         {
-            rts[k++] = OICStrdup(rt[l]);
-            OICFree(rt[l]);
+            rts[k++] = OICStrdup(currentType->resourcetypename);
+            currentType = currentType->next;
         }
-        OICFree(rt);
-    }
-    for (OCStringLL *rsrcType = (*colPayload)->types; rsrcType; rsrcType = rsrcType->next, size++)
-    {
-        rts[k++] = OICStrdup(rsrcType->value);
     }
 
     bool b = OCRepPayloadSetStringArrayAsOwner(*colPayload, OC_RSRVD_RTS, rts, dim);
@@ -184,7 +176,7 @@ static OCStackResult HandleLinkedListInterface(OCEntityHandlerRequest *ehRequest
             {
                 OCRepPayloadAddInterface(colPayload, itf->name);
             }
-            AddRTSBaselinePayload(linkArr, size, &colPayload);
+            AddRTSBaselinePayload(collResource, &colPayload);
         }
         OCRepPayloadSetPropObjectArrayAsOwner(colPayload, OC_RSRVD_LINKS, linkArr, dim);
         ret = OC_STACK_OK;